src/tensor/contracts/sum.bend
bendtorch-core@0.1.0.0 · 20 lines · 4 definitions
1import Base
2import bendtorch-core@0.1.0.0/src/shape/core.bend as Shape
3import bendtorch-core@0.1.0.0/src/tensor/core.bend as Core
4import bendtorch-core@0.1.0.0/src/tensor/contracts/fold.bend as Fold
5
6
7
8
9def add(operation: Unit, accumulator: F32, word: F32) -> F32:
10 F32.add(accumulator, word)
11
12def position(plan: Unit, index: Nat) -> Nat:
13 index
14
15def every(plan: Unit, index: Nat) -> Bool:
16 True{}
17
18def sum(input: Core.Dynamic) -> Core.Dynamic & Result<&2, &1, Core.Error, F32>:
19 Core.Packed{+shape, tensor} = input
20 Fold.run(~Unit, ~add, ~Unit, ~position, ~every, Unit{}, Unit{}, Shape.elements(shape), Core.Packed{shape, tensor})