store grain.autograd.BackProp object in returned variables from forward function
type-erased version of backward function used in grain.autograd.BackProp object
import mir.ndslice; import mir.math; auto x = [1f, 2f, 3f, 4f].sliced(2, 2).variable; Sum!("fast", float, 2) func; auto y = func.forward(x); assert(y == 10f.variable); assert(func.backward(1.2f.variable) == [1.2f, 1.2f, 1.2f, 1.2f].sliced(2, 2).variable); version (grain_cuda) { auto cx = x.to!DeviceStorage; auto cy = func.forward(cx).to!HostStorage; assert(cy == 10f.variable); auto cgx = func.backward(1.2f.variable.to!DeviceStorage).to!HostStorage; assert(cgx.sliced == [1.2f, 1.2f, 1.2f, 1.2f].sliced(2, 2)); }
sum to scalar. mode is similar to mir.math.sum