def linear_bwd
import bend-ml-autograd@0.1.1.0/main.bend as BendMlAutogradimport Base
import bend-ml-tensor@0.1.0.0/main.bend as T
215# Given the gradient dy arriving at y, returns (dx, (dW, db)):
216# dx = dy · Wᵀ (n x o)·(o x i) = n x i
217# dW = xᵀ · dy (i x n)·(n x o) = i x o
218# db = sum of the rows of dy
219# If any of these products had the wrong dimensions, the program would not compile.
220def linear_bwd(+n: Nat, +i: Nat, +o: Nat, x: T.Mat<n, i>, w: T.Mat<i, o>, +dy: T.Mat<n, o>) -> T.Mat<n, i> & (T.Mat<i, o> & T.Vec<o>):
221 (T.Mat.matmul(n, o, i, dy, T.Mat.transpose(i, o, w)), (T.Mat.matmul(i, n, o, T.Mat.transpose(n, i, x), dy), T.Mat.col_sums(n, o, dy)))
Uses (8)
Used by (0)
No other definition uses this definition.