def MatT.max_rows_upto

bend-tensors@0.0.0.2 · bend_tensors.bend:1288

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

1288# each row's largest among its first cols columns; a padding row answers 0.0
1289def MatT.max_rows_upto(+r: Nat, +c: Nat, m: MatT(r, c), +j0: Nat, +cols: Nat) -> VecT(r):
1290  match r c:
1291    case 0n 0n:
1292      MatB{b} = m
1293      VecL{Blk.max_rows_upto(Nat.sub(cols, j0), b)}
1294    case 1n+p 0n:
1295      MatR{t, b} = m
1296      x y = MatT.max_rows_upto(p, 0n, t, j0, cols) MatT.max_rows_upto(p, 0n, b, j0, cols)
1297      VecN{x, y}
1298    case 0n 1n+q:
1299      MatC{l, rt} = m
1300      +h = Nat.add(j0, VecT.size(q))
1301      x y = MatT.max_rows_upto(0n, q, l, j0, cols) MatT.max_rows_upto(0n, q, rt, h, cols)
1302      +x2 = x
1303      Bool.pick(VecT(0n), Nat.is_lt(h, cols), VecT.zip(~F32.max.of, 0n, x2, y), x2)
1304    case 1n+p 1n+q:
1305      MatQ{a, b, c2, d} = m
1306      +h = Nat.add(j0, VecT.size(q))
1307      p0 q0 p1 q1 = MatT.max_rows_upto(p, q, a, j0, cols) MatT.max_rows_upto(p, q, b, h, cols) MatT.max_rows_upto(p, q, c2, j0, cols) MatT.max_rows_upto(p, q, d, h, cols)
1308      +p2 = p0
1309      +p3 = p1
1310      +lt = Nat.is_lt(h, cols)
1311      VecN{Bool.pick(VecT(p), lt, VecT.zip(~F32.max.of, p, p2, q0), p2), Bool.pick(VecT(p), lt, VecT.zip(~F32.max.of, p, p3, q1), p3)}

Uses (17)

Used by (1)