You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@singa.apache.org by GitBox <gi...@apache.org> on 2019/08/14 13:45:12 UTC

[GitHub] [incubator-singa] pinpom commented on a change in pull request #499: SINGA -475 add Div operator

pinpom commented on a change in pull request #499: SINGA -475 add Div operator
URL: https://github.com/apache/incubator-singa/pull/499#discussion_r313881460
 
 

 ##########
 File path: test/python/test_operation.py
 ##########
 @@ -791,69 +791,23 @@ def test_Sub_cpu(self):
         x1.to_device(cpu_dev)
         dy.to_device(cpu_dev)
 
-        result = autograd.sub(x0, x1)
+        result = autograd.div(x0, x1)
         dx0, dx1 = result.creator.backward(dy.data)
 
-        DX0 = np.multiply(DY, 1.0)
-        DX1 = np.multiply(DY, -1.0)
+        G0 = 1.0 / X1
+        DX0 = np.multiply(G0, DY)
+        G1 = np.divide(-X0, np.square(X1))
+        DX1 = np.multiply(G1, DY)
 
         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(dx0)), DX0, decimal=5)
         np.testing.assert_array_almost_equal(tensor.to_numpy(tensor.from_raw_tensor(dx1)), DX1, decimal=5)
-
-    def test_Sub_gpu(self):
+    
+    def test_Div_gpu(self):
         X0 = np.array([7, -5, 0.2, -0.1, 0.3, 4]).reshape(3, 2).astype(np.float32)
         X1 = np.array([0.6, -1.3, 0.1, -0.1, 0.4, 0.3]).reshape(3, 2).astype(np.float32)
-        XT = np.subtract(X0, X1)
-        
-        DY = np.ones((3, 2), dtype = np.float32)
-        x0 = tensor.from_numpy(X0)
-        x1 = tensor.from_numpy(X1)
-        dy = tensor.from_numpy(DY)
-        x0.to_device(gpu_dev)
-        x1.to_device(gpu_dev)
-        dy.to_device(gpu_dev)
+        XT = np.divide(X0, X1)
 
-
-        result = autograd.sub(x0, x1)
-        dx0, dx1 = result.creator.backward(dy.data)
-        DX0 = np.multiply(DY, 1.0)
-        DX1 = np.multiply(DY, -1.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(dx0)), DX0, decimal=5)
-        np.testing.assert_array_almost_equal(tensor.to_numpy(tensor.from_raw_tensor(dx1)), DX1, decimal=5)
-        
-    def test_Pow_cpu(self):
 
 Review comment:
   i guess i misused git command so some functions were accidently deleted. I'll create a new branch from latest master branch and create new PR for this operator

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


With regards,
Apache Git Services