def allocated_source

bendtorch-core@0.1.0.0 · src/tensor/matmul_PROOF.bend:1580

import bendtorch-core@0.1.0.0/src/tensor/matmul_PROOF.bend as MatmulPROOF
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
import bendtorch-core@0.1.0.0/src/tensor/matmul_LAWS.bend as Laws
import bendtorch-core@0.1.0.0/src/storage/arith.bend as Arith
import bendtorch-core@0.1.0.0/src/storage/main.bend as Storage
import bendtorch-core@0.1.0.0/src/tensor/elementwise.bend as Elementwise

1580def allocated_source(+left: Shape.Shape, +right: Shape.Shape, +output: Shape.Shape, +rows: U32, +inner: U32, +right_inner: U32, +columns: U32,
1581  -le: {Shape.dimensions(left) == [rows, inner] : List<&2, U32>}, -re: {Shape.dimensions(right) == [right_inner, columns] : List<&2, U32>},
1582  -oe: {Shape.dimensions(output) == [rows, columns] : List<&2, U32>}, -compatible: {U32.to_nat(inner) == U32.to_nat(right_inner) : Nat},
1583  a: Core.Tensor<left>, b: Core.Tensor<right>, result: Result<&2, &1, Core.Error, Core.Tensor<output>>) ->
1584  Laws.SourceMatmul<Core.Packed{left, a}, Core.Packed{right, b},
1585    Matrix.parallel_allocated(left, right, output, U32.to_nat(inner), U32.to_nat(columns), a, b, result)>:
1586  match result:
1587    case Fail{error}:
1588      Laws.SourceMatmul{unit => Unit{}}
1589    case Done{Core.TTensor{storage, exact}}:
1590      match storage:
1591        case Storage.Empty{}:
1592          Laws.SourceMatmul{unit => Laws.MatmulSuccess{left, right, Matrix.Plan{output, rows, inner, right_inner, columns, le, re, oe, compatible},
1593            a, b, a, b, Core.TTensor{Storage.Empty{}, exact}, {==}, {==}, {==}, {==}, {==},
1594            Laws.ProductPrefix{other => {==}, other => {==}, position => earlier =>
1595              Empty.absurd(Laws.ProductCell<inner, left, right, a, b, output, Core.TTensor{Storage.Empty{}, exact}, position>,
1596                Arith.lt_zero(position,
1597                  %Equal.sym(Nat, 0n, Shape.logical_numel(Shape.dimensions(output)), exact) : {Nat.is_lt(position, _) == True{} : Bool}
1598                  earlier))}}}
1599        case Storage.Owned{+depth, +length, array, balanced, valid}:
1600          take_lift(left, a, taken => Laws.SourceMatmul<Core.Packed{left, a}, Core.Packed{right, b},
1601              Matrix.parallel_output(output, U32.to_nat(inner), U32.to_nat(columns), depth, length, valid, exact, taken, Elementwise.take(Core.pack(right, b)))>,
1602            kept_left => copy_left => taken_left =>
1603              take_lift(right, b, taken => Laws.SourceMatmul<Core.Packed{left, a}, Core.Packed{right, b},
1604                  Matrix.parallel_output(output, U32.to_nat(inner), U32.to_nat(columns), depth, length, valid, exact,
1605                    (Core.Packed{left, kept_left}, copy_left), taken)>,
1606                kept_right => copy_right => taken_right =>
1607                  output_source(left, right, output, rows, inner, right_inner, columns, le, re, oe, compatible, depth, length, valid, exact,
1608                    a, b, kept_left, copy_left, taken_left, kept_right, copy_right, taken_right)))

Uses (30)

Used by (1)