BendTensors.MatT.matmul.any: def of bend-tensors@0.0.0.2 Import: import bend-tensors@0.0.0.2/bend_tensors.bend as BendTensors Lines 842-886 of bend-tensors@0.0.0.2/bend_tensors.bend: https://jend.leeeet.dev/read.txt?path=bend-tensors@0.0.0.2/bend_tensors.bend&start_line=842&end_line=886 import Base # a * b for any shapes: MatT(r, k) times MatT(k, c) is MatT(r, c). A node # forks its whole burst of products at once (eight at a quadrant), then # joins them with a fork of adds. Both operands are shared through +, # never copied. Three depths ride every call, which is what the square # path below avoids. def MatT.matmul.any(+r: Nat, +k: Nat, +c: Nat, +a: MatT(r, k), +b: MatT(k, c)) -> MatT(r, c): match r k c: case 0n 0n 0n: # the leaf goes through the square path on purpose: compiled # without MatT.matmul.sq reachable, this recursion fails at runtime # from depth 2 on (a bend 2.0.16 bug, see README); with it, it runs MatT.matmul.sq(0n, a, b) case 1n+p 0n 0n: MatR{at, ab} = a x y = MatT.matmul.any(p, 0n, 0n, at, b) MatT.matmul.any(p, 0n, 0n, ab, b) MatR{x, y} case 0n 0n 1n+s: MatC{bl, br} = b x y = MatT.matmul.any(0n, 0n, s, a, bl) MatT.matmul.any(0n, 0n, s, a, br) MatC{x, y} case 0n 1n+q 0n: MatC{al, ar} = a MatR{bt, bb} = b x y = MatT.matmul.any(0n, q, 0n, al, bt) MatT.matmul.any(0n, q, 0n, ar, bb) MatT.add(0n, 0n, x, y) case 1n+p 1n+q 0n: MatQ{a0, a1, a2, a3} = a MatR{bt, bb} = b p0 q0 p1 q1 = MatT.matmul.any(p, q, 0n, a0, bt) MatT.matmul.any(p, q, 0n, a1, bb) MatT.matmul.any(p, q, 0n, a2, bt) MatT.matmul.any(p, q, 0n, a3, bb) MatT.add2r(p, p0, q0, p1, q1) case 0n 1n+q 1n+s: MatC{al, ar} = a MatQ{b0, b1, b2, b3} = b p0 q0 p1 q1 = MatT.matmul.any(0n, q, s, al, b0) MatT.matmul.any(0n, q, s, ar, b2) MatT.matmul.any(0n, q, s, al, b1) MatT.matmul.any(0n, q, s, ar, b3) MatT.add2c(s, p0, q0, p1, q1) case 1n+p 0n 1n+s: MatR{at, ab} = a MatC{bl, br} = b w x y z = MatT.matmul.any(p, 0n, s, at, bl) MatT.matmul.any(p, 0n, s, at, br) MatT.matmul.any(p, 0n, s, ab, bl) MatT.matmul.any(p, 0n, s, ab, br) MatQ{w, x, y, z} case 1n+p 1n+q 1n+s: MatQ{a0, a1, a2, a3} = a MatQ{b0, b1, b2, b3} = b p0 q0 p1 q1 p2 q2 p3 q3 = MatT.matmul.any(p, q, s, a0, b0) MatT.matmul.any(p, q, s, a1, b2) MatT.matmul.any(p, q, s, a0, b1) MatT.matmul.any(p, q, s, a1, b3) MatT.matmul.any(p, q, s, a2, b0) MatT.matmul.any(p, q, s, a3, b2) MatT.matmul.any(p, q, s, a2, b1) MatT.matmul.any(p, q, s, a3, b3) MatT.add4(p, s, p0, q0, p1, q1, p2, q2, p3, q3) Uses (10): https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Nat https://jend.leeeet.dev/definition.txt?path=bend-tensors@0.0.0.2/bend_tensors.bend&name=MatT https://jend.leeeet.dev/definition.txt?path=bend-tensors@0.0.0.2/bend_tensors.bend&name=MatT.Cols https://jend.leeeet.dev/definition.txt?path=bend-tensors@0.0.0.2/bend_tensors.bend&name=MatT.Quad https://jend.leeeet.dev/definition.txt?path=bend-tensors@0.0.0.2/bend_tensors.bend&name=MatT.Rows https://jend.leeeet.dev/definition.txt?path=bend-tensors@0.0.0.2/bend_tensors.bend&name=MatT.add https://jend.leeeet.dev/definition.txt?path=bend-tensors@0.0.0.2/bend_tensors.bend&name=MatT.add2c https://jend.leeeet.dev/definition.txt?path=bend-tensors@0.0.0.2/bend_tensors.bend&name=MatT.add2r https://jend.leeeet.dev/definition.txt?path=bend-tensors@0.0.0.2/bend_tensors.bend&name=MatT.add4 https://jend.leeeet.dev/definition.txt?path=bend-tensors@0.0.0.2/bend_tensors.bend&name=MatT.matmul.sq