def tensor_sum
bendtorch-core@0.1.0.0 · src/tensor/reduction.bend:151
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/storage/main.bend as Storage
import bendtorch-core@0.1.0.0/src/tensor/core.bend as Core
151
152
153def tensor_sum(-shape: Shape.Shape, +count: Nat, tensor: Core.Tensor<shape>) -> Result<&2, &1, Core.Error, Core.Tensor<shape> & F32>:
154 Core.TTensor{storage, exact} = tensor
155 match storage:
156 case Storage.Empty{}:
157 Done{(Core.TTensor{Storage.Empty{}, exact}, 0.0)}
158 case Storage.Owned{+depth, +length, array, balanced, valid}:
159 owned_sum(shape, depth, length, array, balanced, valid, exact, array_sum(count, 0n, 0.0, array),
160 array_sum_keeps(depth, array, balanced, count, 0n, 0.0, array, {==}))