def sum_ordered

bendtorch-core@0.1.0.0 · src/tensor/contracts/sum_proof.bend:61

import bendtorch-core@0.1.0.0/src/tensor/contracts/sum_proof.bend as SumProof
import Base
import bendtorch-core@0.1.0.0/src/shape/core.bend as Shape
import bendtorch-core@0.1.0.0/src/storage/LAWS.bend as StorageLaws
import bendtorch-core@0.1.0.0/src/tensor/core.bend as Core
import bendtorch-core@0.1.0.0/src/tensor/lifecycle.bend as Lifecycle
import bendtorch-core@0.1.0.0/src/tensor/reduction.bend as Reduction
import bendtorch-core@0.1.0.0/src/tensor/contracts/replayed.bend as Replayed
import bendtorch-core@0.1.0.0/src/tensor/contracts/fold.bend as Fold
import bendtorch-core@0.1.0.0/src/tensor/contracts/fold_records.bend as Records
import bendtorch-core@0.1.0.0/src/tensor/contracts/fold_proof.bend as Proof
import bendtorch-core@0.1.0.0/src/tensor/contracts/sum.bend as Sum
import bendtorch-core@0.1.0.0/src/tensor/contracts/LAWS.bend as Laws

61def sum_ordered(+shape: Shape.Shape, +fill: F32, +ops: List<&2, StorageLaws.Op>,
62  -fits: {Lifecycle.logical_length(Replayed.storage(shape, fill, ops)) == Shape.logical_numel(Shape.dimensions(shape)) : Nat}) ->
63  Records.FoldContract<shape, Reduction.sequential_sum(Laws.words(shape, fill, ops, Shape.logical_numel(Shape.dimensions(shape))), 0.0),
64    other => Replayed.value(shape, fill, ops, other),
65    Sum.sum(Core.Packed{shape, Core.TTensor{Replayed.storage(shape, fill, ops), fits}})>:
66  +count = Shape.elements(shape)
67  %Shape.elements_exact(shape) :
68    Records.FoldContract<shape, Reduction.sequential_sum(Laws.words(shape, fill, ops, _), 0.0),
69      other => Replayed.value(shape, fill, ops, other),
70      Fold.run(~Unit, ~Sum.add, ~Unit, ~Sum.position, ~Sum.every, Unit{}, Unit{}, count,
71        Core.Packed{shape, Core.TTensor{Replayed.storage(shape, fill, ops), fits}})>
72  %total_words(shape, fill, ops, count) :
73    Records.FoldContract<shape, _,
74      other => Replayed.value(shape, fill, ops, other),
75      Fold.run(~Unit, ~Sum.add, ~Unit, ~Sum.position, ~Sum.every, Unit{}, Unit{}, count,
76        Core.Packed{shape, Core.TTensor{Replayed.storage(shape, fill, ops), fits}})>
77  Proof.contract(~Unit, ~Sum.add, ~Unit, ~Sum.position, ~Sum.every, Unit{}, Unit{}, shape, fill, ops, count,
78    position_inside(count, Shape.logical_numel(Shape.dimensions(shape)), elements_room(shape)), fits)

Uses (27)

Used by (1)