FunctionCommon

common components (typecheck and backprop wrappers) for autograd functions

mixin template FunctionCommon () {
DeviceArgs _mixin_dargs;
HostArgs _mixin_hargs;
}

Postblit

Copying this object is disabled.

A postblit is present on this object, but not explicitly documented in the source.

Members

Functions

applyBackward
void applyBackward(UntypedVariable[] ugradOutputs)

type-erased version of backward function used in grain.autograd.BackProp object

applyForward
auto applyForward(Args args)

store grain.autograd.BackProp object in returned variables from forward function

Examples

test NG functions

1 alias F1H = Variable!(float, 1, HostStorage);
2 version (grain_cuda) alias F1D = Variable!(float, 1, HostStorage);
3 struct A(DelayInstantiation) {
4     mixin FunctionCommon;
5     // mismatch of args
6     F1H forward(F1H x) { return x; };
7     F1H backward(F1H x, F1H y) { return x; };
8 }
9 static assert(!__traits(compiles, A!void));
10 
11 version (grain_cuda) {
12     struct B(DelayInstantiation) {
13         mixin FunctionCommon;
14         F1H forward(F1H x) { return x; };
15         F1H backward(F1H x) { return x; };
16         // mismatch of args in device
17         version (grain_cuda) {
18             F1D forward(F1D x) { return x; };
19             F1D backward(F1D x, F1D y) { return x; };
20         }
21     }
22     static assert(!__traits(compiles, B!void));
23 }

Meta