1 import grain.testing; 2 import std.typecons; 3 import numir; 4 import mir.ndslice; 5 import std.math : tan; 6 7 Tan!(float, 2) hfunc; 8 auto hx = uniform!float(2, 3).slice.variable; 9 auto hy = hfunc.forward(hx); 10 auto hgy = uniform!float(2, 3).slice.variable; 11 auto hgx = hfunc.backward(hgy); 12 gradCheck(hfunc, hx, hgy); 13 assert(approxEqual(hy.sliced, hx.sliced.map!tan)); 14 15 version (grain_cuda) { 16 Tan!(float, 2) dfunc; 17 auto dy = dfunc.forward(hx.to!DeviceStorage); 18 assert(approxEqual(dy.to!HostStorage.sliced, hy.sliced)); 19 auto dgx = dfunc.backward(hgy.to!DeviceStorage); 20 assert(approxEqual(dgx.to!HostStorage.sliced, hgx.sliced)); 21 }
y = tan x