nudles commented on a change in pull request #478: SINGA-473 (Implement ONNX 
Operators in Autograd: Trigonometry functions)
URL: https://github.com/apache/incubator-singa/pull/478#discussion_r308032764
 
 

 ##########
 File path: test/python/test_operation.py
 ##########
 @@ -322,6 +322,294 @@ def test_LeakyRelu(self):
         np.testing.assert_array_almost_equal(tensor.to_numpy(result), XT)
         self.check_shape(dx.shape(), (3, 2))
 
+    def test_Cos_cpu(self):
+        X = np.array([0.8, -1.2, 3.3, -3.6, -0.5, 0.5]).reshape(3, 
2).astype(np.float32)
+        XT = np.cos(X)
+        x = tensor.from_numpy(X)
+        x.to_device(cpu_dev)
+
+        result = autograd.cos(x)
+        dx = result.creator.backward(x.data)
+
+        np.testing.assert_array_almost_equal(tensor.to_numpy(result), XT, 
decimal=5)
+        self.check_shape(dx.shape(), (3, 2))
+
+    def test_Cos_gpu(self):
+        X = np.array([0.8, -1.2, 3.3, -3.6, -0.5, 0.5]).reshape(3, 
2).astype(np.float32)
+        XT = np.cos(X)
+        x = tensor.from_numpy(X)
+        x.to_device(gpu_dev)
+
+        result = autograd.cos(x)
+        dx = result.creator.backward(x.data)
+
+        np.testing.assert_array_almost_equal(tensor.to_numpy(result), XT, 
decimal=5)
+        self.check_shape(dx.shape(), (3, 2))
+
+    def test_Cosh_cpu(self):
+        X = np.array([0.8, -1.2, 3.3, -3.6, -0.5, 0.5]).reshape(3, 
2).astype(np.float32)
+        XT = np.cosh(X)
+        x = tensor.from_numpy(X)
+        x.to_device(cpu_dev)
+
+        result = autograd.cosh(x)
+        dx = result.creator.backward(x.data)
+
+        np.testing.assert_array_almost_equal(tensor.to_numpy(result), XT, 
decimal=5)
 
 Review comment:
   the backward results are not tested..

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to