Skip to content

Fused assignation shortcut #18

Open
@mratsim

Description

@mratsim

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions