type MatmulContract

bendtorch-core@0.1.0.0 · src/tensor/contracts/fold_records.bend:63

import bendtorch-core@0.1.0.0/src/tensor/contracts/fold_records.bend as FoldRecords
import Base
import bendtorch-core@0.1.0.0/src/shape/core.bend as Shape
import bendtorch-core@0.1.0.0/src/tensor/core.bend as Core
import bendtorch-core@0.1.0.0/src/tensor/matmul.bend as Matrix

63# What a matrix product promises, stated only through the result: it
64# succeeds with a rows x columns output whose cell (row, column), at index
65# row * columns + column, holds `cell(row, column)`, and both returned inputs
66# still hold every word.
67type MatmulContract<-left: Shape.Shape, -right: Shape.Shape, -rows: Nat, -columns: Nat, -cell: Nat -> Nat -> F32,
68  -left_word: U32 -> F32, -right_word: U32 -> F32,
69  -result: Result<&2, &1, Matrix.Error, Core.Dynamic & Core.Dynamic & Core.Dynamic>> is Type:
70  MatmulContract{
71    successful: {product_succeeded(result) == True{} : Bool},
72    extents: {product_extents(result) == Some{[rows, columns]} : Maybe<&2, List<&2, Nat>>},
73    value: @+row: Nat -> @row_below: {Nat.is_lt(row, rows) == True{} : Bool} ->
74      @+column: Nat -> @column_below: {Nat.is_lt(column, columns) == True{} : Bool} ->
75      {product_point(result, U32.from_nat(Nat.add(Nat.mul(row, columns), column))) == Some{cell(row, column)} : Maybe<&2, F32>},
76    left_kept: @+other: U32 -> @inside: {Nat.is_lt(U32.to_nat(other), Shape.logical_numel(Shape.dimensions(left))) == True{} : Bool} ->
77      {product_left_point(result, other) == Some{left_word(other)} : Maybe<&2, F32>},
78    right_kept: @+other: U32 -> @inside: {Nat.is_lt(U32.to_nat(other), Shape.logical_numel(Shape.dimensions(right))) == True{} : Bool} ->
79      {product_right_point(result, other) == Some{right_word(other)} : Maybe<&2, F32>}}

Uses (23)

Used by (8)