Tensor.grad2: def of bendtorch@1.3.0.0 Import: import bendtorch@1.3.0.0/tensor.bend as Tensor Lines 368-372 of bendtorch@1.3.0.0/tensor.bend: https://jend.leeeet.dev/read.txt?path=bendtorch@1.3.0.0/tensor.bend&start_line=368&end_line=372 import Base # g + the gradient, through f, of the operand of shape gs (a or b) of z = op(x, y): f(dz, x, y) at each position of o def grad2(~f: @+d: F32 -> @+p: F32 -> @+q: F32 -> F32, +a: List<&2, Nat>, +b: List<&2, Nat>, +o: List<&2, Nat>, +gs: List<&2, Nat>, dz: Tensor, x: Tensor, y: Tensor, g: Tensor) -> G2: match dz x y g: case Tensor{dd} Tensor{dx} Tensor{dy} Tensor{dg}: g2_of(a, b, o, gs, grad2_l(~f, numel(o), 0, bmap(gs, o), bmap(a, o), bmap(b, o), Array.get(F32, dd, 0), Array.get(F32, dx, imap(bmap(a, o), 0)), Array.get(F32, dy, imap(bmap(b, o), 0)), Array.get(F32, dg, imap(bmap(gs, o), 0)))) Uses (11): https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Array.get https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=F32 https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=List https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Nat https://jend.leeeet.dev/definition.txt?path=bendtorch@1.3.0.0/tensor.bend&name=G2 https://jend.leeeet.dev/definition.txt?path=bendtorch@1.3.0.0/tensor.bend&name=Tensor https://jend.leeeet.dev/definition.txt?path=bendtorch@1.3.0.0/tensor.bend&name=bmap https://jend.leeeet.dev/definition.txt?path=bendtorch@1.3.0.0/tensor.bend&name=g2_of https://jend.leeeet.dev/definition.txt?path=bendtorch@1.3.0.0/tensor.bend&name=grad2_l https://jend.leeeet.dev/definition.txt?path=bendtorch@1.3.0.0/tensor.bend&name=imap https://jend.leeeet.dev/definition.txt?path=bendtorch@1.3.0.0/tensor.bend&name=numel