def natural_sum_loop
bendtorch-core@0.1.0.0 · src/tensor/reduction.bend:39
import bendtorch-core@0.1.0.0/src/tensor/reduction.bend as Reduction
import Base
import bendtorch-core@0.1.0.0/src/shape/core.bend as Shape
import bendtorch-core@0.1.0.0/src/tensor/core.bend as Core
39def natural_sum_loop(fuel: Nat, -shape: Shape.Shape, tensor: Core.Tensor<shape>, +cursor: Nat,
40 accumulator: F32) -> Result<&2, &1, Core.Error, Core.Tensor<shape> & F32>:
41 match fuel:
42 case 0n:
43 Done{(tensor, accumulator)}
44 case 1n+tail:
45 +index = U32.from_nat(cursor)
46 sum_decided(shape, tensor => value => natural_sum_loop(tail, shape, tensor, 1n+cursor, value), tensor, cursor, index, accumulator,
47 Shape.bool_case(Nat.is_eq(U32.to_nat(index), cursor)))