Currently the way to implement fast sigmoid would be:
var x = randomTensor([1000, 1000], 1.0)
var output = newTensor[float64](x.shape)
forEach o in output, xi in x:
o = 1 / (1 + exp(-x))
which is quite wordy.
Reusing the Arraymancer syntax for broacasting would be:
let output = 1 ./ (1 .+ exp(-x))
but this would allocate for:
x0 = -x
x1 = exp(x0)
x2 = 1 .+ x1
x3 = 1/x2
Unfortunately we cannot use anything over than = in a let/var statement like let x .= 1 / (1 + exp(-x))
But we can use let x = fuse: 1 / (1 + exp(-x)) to request the code to generate forEach automatically.
Currently the way to implement fast sigmoid would be:
which is quite wordy.
Reusing the Arraymancer syntax for broacasting would be:
but this would allocate for:
Unfortunately we cannot use anything over than
=
in a let/var statement likelet x .= 1 / (1 + exp(-x))
But we can uselet x = fuse: 1 / (1 + exp(-x))
to request the code to generateforEach
automatically.