def vjp
bendtorch-core@0.1.0.0 · src/autograd/backward.bend:107
import bendtorch-core@0.1.0.0/src/autograd/backward.bend as Backward
import Base
107
108
109def vjp(node: Node, +g: F32) -> List<&2, Contribution>:
110 match node:
111 case Leaf{}:
112 []
113 case Add{a, b}:
114 [Contribution{a, g}, Contribution{b, g}]
115 case Sub{a, b}:
116 [Contribution{a, g}, Contribution{b, F32.neg(g)}]
117 case Mul{a, b, left, right}:
118 [Contribution{a, F32.mul(g, right)}, Contribution{b, F32.mul(g, left)}]
119 case Neg{a}:
120 [Contribution{a, F32.neg(g)}]