def MatT.from_rows

bend-tensors@0.0.0.2 · bend_tensors.bend:1117

import bend-tensors@0.0.0.2/bend_tensors.bend as BendTensors
import Base

1117# a MatT(r, c) from its rows, row-major; short or missing rows pad with 0.0
1118def MatT.from_rows(+r: Nat, +c: Nat, +rows: List<&2, List<&2, F32>>) -> MatT(r, c):
1119  match r c:
1120    case 0n 0n:
1121      MatB{MatT.from_rows.leaf(rows)}
1122    case 1n+p 0n:
1123      +h = VecT.size(p)
1124      t b = MatT.from_rows(p, 0n, List.take(&2, List<&2, F32>, rows, h)) MatT.from_rows(p, 0n, List.drop(&2, List<&2, F32>, rows, h))
1125      MatR{t, b}
1126    case 0n 1n+q:
1127      +w = VecT.size(q)
1128      l r2 = MatT.from_rows(0n, q, MatT.rows_take(w, rows)) MatT.from_rows(0n, q, MatT.rows_drop(w, rows))
1129      MatC{l, r2}
1130    case 1n+p 1n+q:
1131      +h = VecT.size(p)
1132      +w = VecT.size(q)
1133      +top = List.take(&2, List<&2, F32>, rows, h)
1134      +bot = List.drop(&2, List<&2, F32>, rows, h)
1135      a b c2 d = MatT.from_rows(p, q, MatT.rows_take(w, top)) MatT.from_rows(p, q, MatT.rows_drop(w, top)) MatT.from_rows(p, q, MatT.rows_take(w, bot)) MatT.from_rows(p, q, MatT.rows_drop(w, bot))
1136      MatQ{a, b, c2, d}

Uses (14)

Used by (3)