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 : pow; auto p = 2.0f; auto hfunc = Pow!(float, 2)(p); 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, 1e-3, 1e-3); assert(approxEqual(hy.sliced, hx.sliced.map!(a => pow(a, p)))); version (grain_cuda) { auto dfunc = Pow!(float, 2)(p); 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 = pow x