def MatmulWith
bendtorch-core@0.1.0.0 · src/tensor/contracts/LAWS.bend:172
import bendtorch-core@0.1.0.0/src/tensor/contracts/LAWS.bend as LAWS
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/matmul.bend as Matrix
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
172
173
174
175
176def MatmulWith(+left: Shape.Shape, +right: Shape.Shape, +plan: Matrix.Plan<left, right>,
177 +left_fill: F32, +left_ops: List<&2, StorageLaws.Op>, +right_fill: F32, +right_ops: List<&2, StorageLaws.Op>,
178 -P: Result<&2, &1, Matrix.Error, Core.Dynamic & Core.Dynamic & Core.Dynamic> -> Type) -> Type:
179 @+left_kept: List<&2, StorageLaws.Op> ->
180 @left_words: {words(left, left_fill, left_kept, Shape.logical_numel(Shape.dimensions(left))) ==
181 words(left, left_fill, left_ops, Shape.logical_numel(Shape.dimensions(left))) : List<&2, F32>} ->
182 @-left_fits: {Lifecycle.logical_length(Replayed.storage(left, left_fill, left_kept)) == Shape.logical_numel(Shape.dimensions(left)) : Nat} ->
183 @+right_kept: List<&2, StorageLaws.Op> ->
184 @right_words: {words(right, right_fill, right_kept, Shape.logical_numel(Shape.dimensions(right))) ==
185 words(right, right_fill, right_ops, Shape.logical_numel(Shape.dimensions(right))) : List<&2, F32>} ->
186 @-right_fits: {Lifecycle.logical_length(Replayed.storage(right, right_fill, right_kept)) == Shape.logical_numel(Shape.dimensions(right)) : Nat} ->
187 @+output_ops: List<&2, StorageLaws.Op> ->
188 @cells: (@+row: Nat -> @row_below: {Nat.is_lt(row, matrix_rows(left, right, plan)) == True{} : Bool} ->
189 @+column: Nat -> @column_below: {Nat.is_lt(column, matrix_columns(left, right, plan)) == True{} : Bool} ->
190 {Replayed.value(Matrix.output_shape(left, right, plan), 0.0, output_ops,
191 U32.from_nat(Nat.add(Nat.mul(row, matrix_columns(left, right, plan)), column))) ==
192 DotFold.dot_fold(factors(row, column, matrix_inner(left, right, plan), matrix_columns(left, right, plan),
193 left, left_fill, left_ops, right, right_fill, right_ops, matrix_inner(left, right, plan)), 0.0) : F32}) ->
194 @-output_fits: {Lifecycle.logical_length(Replayed.storage(Matrix.output_shape(left, right, plan), 0.0, output_ops)) ==
195 Shape.logical_numel(Shape.dimensions(Matrix.output_shape(left, right, plan))) : Nat} ->
196 P(Done{(Core.Packed{left, Core.TTensor{Replayed.storage(left, left_fill, left_kept), left_fits}},
197 Core.Packed{right, Core.TTensor{Replayed.storage(right, right_fill, right_kept), right_fits}},
198 Core.Packed{Matrix.output_shape(left, right, plan),
199 Core.TTensor{Replayed.storage(Matrix.output_shape(left, right, plan), 0.0, output_ops), output_fits}})})