Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fused assignation shortcut #18

Open
mratsim opened this issue Jan 28, 2019 · 0 comments
Open

Fused assignation shortcut #18

mratsim opened this issue Jan 28, 2019 · 0 comments
Labels
enhancement New feature or request

Comments

@mratsim
Copy link
Owner

mratsim commented Jan 28, 2019

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.
@mratsim mratsim added the enhancement New feature or request label Jan 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant