feature request more numpy like dot
robbiemu opened this issue · comments
Robert Collins commented
I'd love to reduce this example:
import Surge
let inputs = [1.0, 2.0, 3.0, 2.5]
let weights = [[0.2, 0.8, -0.5, 1.0],
[0.5, -0.91, 0.26, -0.5],
[-0.26, -0.27, 0.17, 0.87]]
let biases = [2.0, 3.0, 0.5]
let output = weights.enumerated().map { (index, weight) in
inputs • weight + biases[index]
}
print(output)
to this one:
import Surge
let inputs = [1.0, 2.0, 3.0, 2.5]
let weights = [[0.2, 0.8, -0.5, 1.0],
[0.5, -0.91, 0.26, -0.5],
[-0.26, -0.27, 0.17, 0.87]]
let biases = [2.0, 3.0, 0.5]
let output = weights • inputs + biases
print(output)
but it is only implemented on Vectors:
error: p003.xcplaygroundpage:18:22: error: operator function '•' requires the types '[Double]' and 'Double' be equivalent
let output = weights • inputs + biases
`
``