def mtv
import bendtorch@1.3.0.0/spec.bend as Specimport Base
44# Mᵀ·g: the rows weighted by g and summed (a linear layer's backward pass to its input, dx = Wᵀ·dy)
45def mtv(rows: List<&2, List<&2, Nat>>, g: List<&2, Nat>) -> List<&2, Nat>:
46 match rows g:
47 case Con{r, rt} Con{gi, gt}:
48 vadd(vscale(gi, r), mtv(rt, gt))
49 case _ _:
50 Nil{}