store grain.autograd.BackProp object in returned variables from forward function
type-erased version of backward function used in grain.autograd.BackProp object
// test CPU import grain.testing; import std.math : tanh; import numir; auto func = new Sigmoid!(float, 1); auto hx = [-1.0f, 1.0f, 0.0f].variable; gradCheck(func, hx, [0.1f, 0.1f, 0.1f].variable); auto hy = func.forward(hx); // assert(hy.data == [tanh(-1.0f), tanh(1.0f), tanh(0.0f)]); auto hgy = [1.0f, 2.0f, 3.0f].variable; auto hgx = func.backward(hgy); // test CUDA version (grain_cuda) { auto dfunc = new Sigmoid!(float, 1); auto dx = hx.to!DeviceStorage; auto dy = dfunc.forward(dx); assert(approxEqual(dy.to!HostStorage.sliced, hy.sliced)); auto dgx = dfunc.backward(hgy.to!DeviceStorage); assert(approxEqual(dgx.to!HostStorage.sliced, hgx.sliced)); }
sigmoid function