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

Method _Atanh_helper

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

Source from the content-addressed store, hash-verified

1099 self._Atan_helper(gpu_dev)
1100
1101 def _Atanh_helper(self, dev):
1102 X = np.array([-0.9, -0.3, -0.1, 0.1, 0.5,
1103 0.9]).reshape(3, 2).astype(np.float32)
1104 XT = np.arctanh(X)
1105 DY = np.ones((3, 2), dtype=np.float32)
1106
1107 x = tensor.from_numpy(X)
1108 dy = tensor.from_numpy(DY)
1109 x.to_device(dev)
1110 dy.to_device(dev)
1111
1112 result = autograd.atanh(x)
1113 dx = result.creator.backward(dy.data)
1114
1115 G = 1.0 / (1.0 - np.square(X))
1116 DX = np.multiply(G, DY)
1117
1118 np.testing.assert_array_almost_equal(tensor.to_numpy(result),
1119 XT,
1120 decimal=5)
1121 np.testing.assert_array_almost_equal(tensor.to_numpy(
1122 tensor.from_raw_tensor(dx)),
1123 DX,
1124 decimal=5)
1125
1126 def test_Atanh_cpu(self):
1127 self._Atanh_helper(cpu_dev)

Callers 2

test_Atanh_cpuMethod · 0.95
test_Atanh_gpuMethod · 0.95

Calls 3

reshapeMethod · 0.45
to_deviceMethod · 0.45
backwardMethod · 0.45

Tested by

no test coverage detected