def product_compatible

bendtorch-core@0.1.0.0 · src/tensor/matmul.bend:771

import bendtorch-core@0.1.0.0/src/tensor/matmul.bend as Matmul
import Base
import bendtorch-core@0.1.0.0/src/shape/core.bend as Shape
import bendtorch-core@0.1.0.0/src/tensor/lifecycle.bend as Lifecycle

771def product_compatible(-lo: Order, -ro: Order, -left: Shape.Shape, -right: Shape.Shape, +rows: U32, +inner: U32,
772  +right_inner: U32, +columns: U32,
773  -le: {Shape.dimensions(left) == arranged(lo, rows, inner) : List<&2, U32>},
774  -re: {Shape.dimensions(right) == arranged(ro, columns, right_inner) : List<&2, U32>},
775  decision: Shape.BoolCase<Nat.is_eq(U32.to_nat(inner), U32.to_nat(right_inner))>) ->
776  Result<&2, &2, Error, Product<lo, ro, left, right>>:
777  match decision:
778    case Shape.BFalse{equal}:
779      Fail{InnerDimensionMismatch{}}
780    case Shape.BTrue{equal}:
781      product_output(lo, ro, left, right, rows, inner, right_inner, columns, le, re,
782        Lifecycle.natural_equal(U32.to_nat(inner), U32.to_nat(right_inner), equal),
783        Shape.construct([rows, columns]))

Uses (15)

Used by (2)