def total_factors

bendtorch-core@0.1.0.0 · src/tensor/contracts/dot_proof.bend:29

import bendtorch-core@0.1.0.0/src/tensor/contracts/dot_proof.bend as DotProof
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/dot_fold.bend as DotFold
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/dot.bend as Dot
import bendtorch-core@0.1.0.0/src/tensor/contracts/LAWS.bend as Laws

29def total_factors(+row: Nat, +column: Nat, +inner: Nat, +columns: Nat,
30  +left: Shape.Shape, +left_fill: F32, +left_ops: List<&2, StorageLaws.Op>,
31  +right: Shape.Shape, +right_fill: F32, +right_ops: List<&2, StorageLaws.Op>, +count: Nat) ->
32  {Fold.pair_total(~Unit, ~Dot.multiply_add, ~Dot.Cell, ~Dot.left_index, ~Dot.right_index, Unit{}, Dot.Cell{row, column, inner, columns},
33    left, left_fill, left_ops, right, right_fill, right_ops, count) ==
34    DotFold.dot_fold(Laws.factors(row, column, inner, columns, left, left_fill, left_ops, right, right_fill, right_ops, count), 0.0) : F32}:
35  match count:
36    case 0n:
37      {==}
38    case 1n+previous:
39      +x = Replayed.value(left, left_fill, left_ops, U32.from_nat(Nat.add(Nat.mul(row, inner), previous)))
40      +y = Replayed.value(right, right_fill, right_ops, U32.from_nat(Nat.add(Nat.mul(previous, columns), column)))
41      +before = Laws.factors(row, column, inner, columns, left, left_fill, left_ops, right, right_fill, right_ops, previous)
42      %Equal.sym(F32, DotFold.dot_fold(List.append(&2, DotFold.Factors, before, [DotFold.Factors{x, y}]), 0.0),
43        F32.add(DotFold.dot_fold(before, 0.0), F32.mul(x, y)), dot_snoc(before, x, y, 0.0)) :
44        {F32.add(Fold.pair_total(~Unit, ~Dot.multiply_add, ~Dot.Cell, ~Dot.left_index, ~Dot.right_index, Unit{},
45          Dot.Cell{row, column, inner, columns}, left, left_fill, left_ops, right, right_fill, right_ops, previous), F32.mul(x, y)) == _ : F32}
46      Equal.cong(F32, F32, total => F32.add(total, F32.mul(x, y)),
47        Fold.pair_total(~Unit, ~Dot.multiply_add, ~Dot.Cell, ~Dot.left_index, ~Dot.right_index, Unit{},
48          Dot.Cell{row, column, inner, columns}, left, left_fill, left_ops, right, right_fill, right_ops, previous),
49        DotFold.dot_fold(before, 0.0),
50        total_factors(row, column, inner, columns, left, left_fill, left_ops, right, right_fill, right_ops, previous))

Uses (24)

Used by (1)