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

Function relu_gradient

dlib/cuda/cpu_dlib.cpp:1914–1941  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1912 }
1913
1914 void relu_gradient (
1915 tensor& grad,
1916 const tensor& dest,
1917 const tensor& gradient_input
1918 )
1919 {
1920 const float* gi = gradient_input.host();
1921 const float* in = dest.host();
1922 float* out = grad.host();
1923 if (is_same_object(grad, gradient_input))
1924 {
1925 for (size_t i = 0; i < dest.size(); ++i)
1926 {
1927 if (in[i] > 0)
1928 out[i] = gi[i];
1929 else
1930 out[i] = 0;
1931 }
1932 }
1933 else
1934 {
1935 for (size_t i = 0; i < dest.size(); ++i)
1936 {
1937 if (in[i] > 0)
1938 out[i] += gi[i];
1939 }
1940 }
1941 }
1942
1943 // ----------------------------------------------------------------------------------------
1944

Callers 1

backward_inplaceMethod · 0.50

Calls 3

is_same_objectFunction · 0.50
hostMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected