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

Method _Tan_helper

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

Source from the content-addressed store, hash-verified

1003 self._Asinh_helper(gpu_dev)
1004
1005 def _Tan_helper(self, dev):
1006 X = np.array([0.8, -1.2, 3.3, -3.6, -0.5,
1007 0.5]).reshape(3, 2).astype(np.float32)
1008 XT = np.tan(X)
1009 DY = np.ones((3, 2), dtype=np.float32)
1010
1011 x = tensor.from_numpy(X)
1012 dy = tensor.from_numpy(DY)
1013 x.to_device(dev)
1014 dy.to_device(dev)
1015
1016 result = autograd.tan(x)
1017 dx = result.creator.backward(dy.data)
1018
1019 G = 1.0 / np.square(np.cos(X))
1020 DX = np.multiply(G, DY)
1021
1022 np.testing.assert_array_almost_equal(tensor.to_numpy(result),
1023 XT,
1024 decimal=5)
1025 np.testing.assert_array_almost_equal(tensor.to_numpy(
1026 tensor.from_raw_tensor(dx)),
1027 DX,
1028 decimal=5)
1029
1030 def test_Tan_cpu(self):
1031 self._Tan_helper(cpu_dev)

Callers 2

test_Tan_cpuMethod · 0.95
test_Tan_gpuMethod · 0.95

Calls 3

reshapeMethod · 0.45
to_deviceMethod · 0.45
backwardMethod · 0.45

Tested by

no test coverage detected