pinpom commented on a change in pull request #488: SINGA -475 add Sign operator 
to singa
URL: https://github.com/apache/incubator-singa/pull/488#discussion_r311832839
 
 

 ##########
 File path: test/python/test_operation.py
 ##########
 @@ -610,6 +610,42 @@ def test_Atanh_gpu(self):
         np.testing.assert_array_almost_equal(tensor.to_numpy(result), XT, 
decimal=5)
         self.check_shape(dx.shape(), (3, 2))
 
+    def test_Sign_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.sign(X)
+        DY = np.ones((3, 2), dtype = np.float32)
+
+        x = tensor.from_numpy(X)
+        dy = tensor.from_numpy(DY)
+        x.to_device(cpu_dev)
+        dy.to_device(cpu_dev)
+
+        result = autograd.sign(x)
+        dx = result.creator.backward(dy.data)
+        #dx = [x/|x|]'
+        DX = np.multiply(DY,0)
+
+        np.testing.assert_array_almost_equal(tensor.to_numpy(result), XT, 
decimal=5)
+        
np.testing.assert_array_almost_equal(tensor.to_numpy(tensor.from_raw_tensor(dx)),
 DX, decimal=5)
+
+    
+    def test_Sign_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.sign(X)
+        DY = np.ones((3, 2), dtype = np.float32)
+
+        x = tensor.from_numpy(X)
+        dy = tensor.from_numpy(DY)
+        x.to_device(gpu_dev)
+        dy.to_device(gpu_dev)
+
+        result = autograd.sign(x)
+        dx = result.creator.backward(dy.data)
+        #dx = [x/|x|]'
 
 Review comment:
   fix the code

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to