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 : sin; Sin!(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); assert(approxEqual(hy.sliced, hx.sliced.map!sin)); version (grain_cuda) { Sin!(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 = sin x