src/tensor/contracts/fold_records.bend checks
raw source on the hub · import bendtorch-core@0.1.0.0/src/tensor/contracts/fold_records.bend as Fold_records
5 imports
import Base import ../../shape/core.bend as Shape import ../core.bend as Core import ../matmul.bend as Matrix import ./fold.bend as Fold
Types
type FoldContract source · line 10 · raw
@-input:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @-total:F32 -> @-word:(@_:U32 -> F32) -> @-result:Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, Result<&2, &1, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Error, F32>) -> Type
What a fold result promises, stated only through the result: it succeeds
with total, and the returned input still holds every word. total and
word are the specification; an instance fills them in.
FoldContract@-input:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @-total:F32 -> @-word:(@_:U32 -> F32) -> @-result:Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, Result<&2, &1, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Error, F32>) -> @value:{0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/contracts/fold.value(result) == Some{total} : Maybe<&2, F32>} -> @kept:(@+other:U32 -> @inside:{Nat.is_lt(U32.to_nat(other), 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.logical_numel(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.dimensions(input))) == True{} : Bool} -> {0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/contracts/fold.input_point(result, other) == Some{word(other)} : Maybe<&2, F32>}) -> FoldContract<input, total, word, result>
type PairFoldContract source · line 18 · raw
@-left:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @-right:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @-total:F32 -> @-left_word:(@_:U32 -> F32) -> @-right_word:(@_:U32 -> F32) -> @-result:Pair(Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic), Result<&2, &1, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Error, F32>) -> Type
The same for a pair fold: the total, and every word of both returned inputs.
PairFoldContract@-left:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @-right:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @-total:F32 -> @-left_word:(@_:U32 -> F32) -> @-right_word:(@_:U32 -> F32) -> @-result:Pair(Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic), Result<&2, &1, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Error, F32>) -> @value:{0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/contracts/fold.pair_value(result) == Some{total} : Maybe<&2, F32>} -> @left_kept:(@+other:U32 -> @inside:{Nat.is_lt(U32.to_nat(other), 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.logical_numel(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.dimensions(left))) == True{} : Bool} -> {0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/contracts/fold.left_point(result, other) == Some{left_word(other)} : Maybe<&2, F32>}) -> @right_kept:(@+other:U32 -> @inside:{Nat.is_lt(U32.to_nat(other), 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.logical_numel(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.dimensions(right))) == True{} : Bool} -> {0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/contracts/fold.right_point(result, other) == Some{right_word(other)} : Maybe<&2, F32>}) -> PairFoldContract<left, right, total, left_word, right_word, result>
type MatmulContract source · line 67 · raw
@-left:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @-right:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @-rows:Nat -> @-columns:Nat -> @-cell:(@_:Nat -> @_:Nat -> F32) -> @-left_word:(@_:U32 -> F32) -> @-right_word:(@_:U32 -> F32) -> @-result:Result<&2, &1, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/matmul.Error, Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic))> -> Type
What a matrix product promises, stated only through the result: it
succeeds with a rows x columns output whose cell (row, column), at index
row * columns + column, holds cell(row, column), and both returned inputs
still hold every word.
MatmulContract@-left:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @-right:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @-rows:Nat -> @-columns:Nat -> @-cell:(@_:Nat -> @_:Nat -> F32) -> @-left_word:(@_:U32 -> F32) -> @-right_word:(@_:U32 -> F32) -> @-result:Result<&2, &1, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/matmul.Error, Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic))> -> @successful:{product_succeeded(result) == True{} : Bool} -> @extents:{product_extents(result) == Some{[rows, columns]} : Maybe<&2, List<&2, Nat>>} -> @value:(@+row:Nat -> @row_below:{Nat.is_lt(row, rows) == True{} : Bool} -> @+column:Nat -> @column_below:{Nat.is_lt(column, columns) == True{} : Bool} -> {product_point(result, U32.from_nat(Nat.add(Nat.mul(row, columns), column))) == Some{cell(row, column)} : Maybe<&2, F32>}) -> @left_kept:(@+other:U32 -> @inside:{Nat.is_lt(U32.to_nat(other), 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.logical_numel(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.dimensions(left))) == True{} : Bool} -> {product_left_point(result, other) == Some{left_word(other)} : Maybe<&2, F32>}) -> @right_kept:(@+other:U32 -> @inside:{Nat.is_lt(U32.to_nat(other), 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.logical_numel(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.dimensions(right))) == True{} : Bool} -> {product_right_point(result, other) == Some{right_word(other)} : Maybe<&2, F32>}) -> MatmulContract<left, right, rows, columns, cell, left_word, right_word, result>
Definitions
def product_succeeded source · line 27 · raw
@result:Result<&2, &1, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/matmul.Error, Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic))> -> Bool
def product_extents source · line 30 · raw
@result:Result<&2, &1, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/matmul.Error, Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic))> -> Maybe<&2, List<&2, Nat>>
def product_point source · line 39 · raw
@result:Result<&2, &1, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/matmul.Error, Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic))> -> @+index:U32 -> Maybe<&2, F32>
def product_left_point source · line 47 · raw
@result:Result<&2, &1, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/matmul.Error, Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic))> -> @+index:U32 -> Maybe<&2, F32>
def product_right_point source · line 55 · raw
@result:Result<&2, &1, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/matmul.Error, Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic))> -> @+index:U32 -> Maybe<&2, F32>