store grain.autograd.BackProp object in returned variables from forward function
type-erased version of backward function used in grain.autograd.BackProp object
import grain.testing; import std.typecons; import numir; import mir.ndslice; import mir.math : log; Log!(float, 2) hfunc; auto hx = uniform!float(2, 3).slice.variable; auto hy = hfunc.forward(hx); auto hgy = uniform!float(2, 3).slice.variable; auto hgx = hfunc.backward(hgy); gradCheck(hfunc, hx, hgy, 1e-3, 5e-2, 5e-2); assert(approxEqual(hy.sliced, hx.sliced.map!log)); version (grain_cuda) { Log!(float, 2) dfunc; auto dy = dfunc.forward(hx.to!DeviceStorage); assert(approxEqual(dy.to!HostStorage.sliced, hy.sliced)); auto dgx = dfunc.backward(hgy.to!DeviceStorage); assert(approxEqual(dgx.to!HostStorage.sliced, hgx.sliced)); }
y = exp x