MCPcopy Create free account
hub / github.com/davisking/dlib / tanh_gradient

Function tanh_gradient

dlib/cuda/cpu_dlib.cpp:2056–2075  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2054 }
2055
2056 void tanh_gradient (
2057 tensor& grad,
2058 const tensor& dest,
2059 const tensor& gradient_input
2060 )
2061 {
2062 const auto g = grad.host();
2063 const auto d = dest.host();
2064 const auto in = gradient_input.host();
2065 if (is_same_object(grad, gradient_input))
2066 {
2067 for (size_t i = 0; i < dest.size(); ++i)
2068 g[i] = in[i]*(1-d[i]*d[i]);
2069 }
2070 else
2071 {
2072 for (size_t i = 0; i < dest.size(); ++i)
2073 g[i] += in[i]*(1-d[i]*d[i]);
2074 }
2075 }
2076
2077 // ----------------------------------------------------------------------------------------
2078

Callers 2

test_tanhFunction · 0.50
backward_inplaceMethod · 0.50

Calls 3

is_same_objectFunction · 0.50
hostMethod · 0.45
sizeMethod · 0.45

Tested by 1

test_tanhFunction · 0.40