Abs

y = abs x

Members

Functions

backward
auto backward(Variable!(T, dim, HostStorage) gy)
Undocumented in source. Be warned that the author may not have intended to support it.
backward
auto backward(Variable!(T, dim, DeviceStorage) gy)
Undocumented in source. Be warned that the author may not have intended to support it.
forward
auto forward(Variable!(T, dim, DeviceStorage) x)
Undocumented in source. Be warned that the author may not have intended to support it.
forward
auto forward(Variable!(T, dim, HostStorage) x)
Undocumented in source. Be warned that the author may not have intended to support it.

Mixins

__anonymous
mixin FunctionCommon
Undocumented in source.

Variables

dx
Variable!(T, dim, DeviceStorage) dx;
Undocumented in source.
hx
Variable!(T, dim, HostStorage) hx;
Undocumented in source.

Mixed In Members

From mixin FunctionCommon

this(this)
this(this)
Undocumented in source.
DeviceRets
alias DeviceRets = Tuple!(Parameters!backward)
Undocumented in source.
DeviceArgs
alias DeviceArgs = Tuple!(Parameters!forward)
Undocumented in source.
__anonymous
mixin TypeChecker!(forward, backward)
Undocumented in source.
_mixin_dargs
DeviceArgs _mixin_dargs;
Undocumented in source.
HostRets
alias HostRets = Tuple!(Parameters!backward)
Undocumented in source.
HostArgs
alias HostArgs = Tuple!(Parameters!forward)
Undocumented in source.
__anonymous
mixin TypeChecker!(forward, backward)
Undocumented in source.
_mixin_hargs
HostArgs _mixin_hargs;
Undocumented in source.
applyForward
auto applyForward(Args args)

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

applyBackward
void applyBackward(UntypedVariable[] ugradOutputs)

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

Examples

test abs simple case, gradcheck and cpu/cuda equality

import grain.testing;
import std.typecons;
import numir;
import mir.ndslice;

auto xs = [[-1.0f, 2.0f, -3.0f], [1.0f, 0.0f, 0.0f]].nparray;
auto ys = [[1.0f, 2.0f, 3.0f], [1.0f, 0.0f, 0.0f]].nparray;
auto hfunc = Abs!(float, 2)();
auto hx = xs.variable;
auto hy = hfunc.forward(hx);
assert(approxEqual(hy.sliced, ys));

auto gxs = [[-0.1f, 0.2f, -0.3f], [0.5f, 0.0f, 0.0f]].nparray;
auto gys = [[0.1f, 0.2f, 0.3f], [0.5f, 0.6f, 0.7f]].nparray;
auto hgy = gys.variable;
auto hgx = hfunc.backward(hgy);
assert(approxEqual(hgx.sliced, gxs));

version (grain_cuda) {
    auto dfunc = Abs!(float, 2)();
    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));
}

Meta