MCPcopy Create free account
hub / github.com/apache/singa / _Tanh_helper

Method _Tanh_helper

test/python/test_operation.py:1037–1060  ·  view source on GitHub ↗
(self, dev)

Source from the content-addressed store, hash-verified

1035 self._Tan_helper(gpu_dev)
1036
1037 def _Tanh_helper(self, dev):
1038 X = np.array([0.8, -1.2, 3.3, -3.6, -0.5,
1039 0.5]).reshape(3, 2).astype(np.float32)
1040 XT = np.tanh(X)
1041 DY = np.ones((3, 2), dtype=np.float32)
1042
1043 x = tensor.from_numpy(X)
1044 dy = tensor.from_numpy(DY)
1045 x.to_device(dev)
1046 dy.to_device(dev)
1047
1048 result = autograd.tanh(x)
1049 dx = result.creator.backward(dy.data)
1050
1051 G = 1.0 / np.square(np.cosh(X))
1052 DX = np.multiply(G, DY)
1053
1054 np.testing.assert_array_almost_equal(tensor.to_numpy(result),
1055 XT,
1056 decimal=5)
1057 np.testing.assert_array_almost_equal(tensor.to_numpy(
1058 tensor.from_raw_tensor(dx)),
1059 DX,
1060 decimal=5)
1061
1062 def test_Tanh_cpu(self):
1063 self._Tanh_helper(cpu_dev)

Callers 2

test_Tanh_cpuMethod · 0.95
test_Tanh_gpuMethod · 0.95

Calls 3

reshapeMethod · 0.45
to_deviceMethod · 0.45
backwardMethod · 0.45

Tested by

no test coverage detected