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

Method _Cos_helper

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

Source from the content-addressed store, hash-verified

747 self._Relu_helper(gpu_dev)
748
749 def _Cos_helper(self, dev):
750 X = np.array([0.8, -1.2, 3.3, -3.6, -0.5,
751 0.5]).reshape(3, 2).astype(np.float32)
752 XT = np.cos(X)
753 DY = np.ones((3, 2), dtype=np.float32)
754
755 x = tensor.from_numpy(X)
756 dy = tensor.from_numpy(DY)
757 x.to_device(dev)
758 dy.to_device(dev)
759
760 result = autograd.cos(x)
761 dx = result.creator.backward(dy.data)
762
763 G = -np.sin(X)
764 DX = np.multiply(G, DY)
765
766 np.testing.assert_array_almost_equal(tensor.to_numpy(result),
767 XT,
768 decimal=5)
769 np.testing.assert_array_almost_equal(tensor.to_numpy(
770 tensor.from_raw_tensor(dx)),
771 DX,
772 decimal=5)
773
774 def test_Cos_cpu(self):
775 self._Cos_helper(cpu_dev)

Callers 2

test_Cos_cpuMethod · 0.95
test_Cos_gpuMethod · 0.95

Calls 3

reshapeMethod · 0.45
to_deviceMethod · 0.45
backwardMethod · 0.45

Tested by

no test coverage detected