src/tensor/dot_fold.bend

bendtorch-core@0.1.0.0 · 14 lines · 2 definitions

1import Base
2
3# The specification of one matrix-product cell: fold the factor pairs in
4# list order, adding each product to the accumulator. It holds no law, so
5# modules that state totals with it do not import the matmul proofs.
6type Factors is Data:
7  Factors{left: F32, right: F32}
8
9def dot_fold(values: List<&2, Factors>, accumulator: F32) -> F32:
10  match values:
11    case Nil{}:
12      accumulator
13    case Factors{left, right} <> tail:
14      dot_fold(tail, F32.add(accumulator, F32.mul(left, right)))