You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2019/09/12 03:49:49 UTC

[GitHub] [incubator-mxnet] xiezhq-hermann commented on a change in pull request #15906: [Numpy] Numpy operator diff

xiezhq-hermann commented on a change in pull request #15906: [Numpy] Numpy operator diff
URL: https://github.com/apache/incubator-mxnet/pull/15906#discussion_r323545625
 
 

 ##########
 File path: tests/python/unittest/test_numpy_op.py
 ##########
 @@ -1519,6 +1519,58 @@ def hybrid_forward(self, F, a):
                         assert_almost_equal(mx_out.asnumpy(), np_out, rtol=1e-3, atol=1e-5)
 
 
+@with_seed()
+@use_np
+def test_np_diff():
+    def np_diff_backward(ograd, n, axis):
+        res = ograd
+        for i in range(n):
+            res = _np.negative(_np.diff(res, n=1, axis=axis, prepend=0, append=0))
+        return res
+
+    class TestDiff(HybridBlock):
+        def __init__(self, n=1, axis=-1):
+            super(TestDiff, self).__init__()
+            self._n = n
+            self._axis = axis
+
+        def hybrid_forward(self, F, a):
+            return F.np.diff(a, n=self._n, axis=self._axis)
+
+    shapes = [tuple(random.randrange(10) for i in range(random.randrange(6))) for j in range(5)]
 
 Review comment:
   Hi, the random shape generator should have covered the corner cases, including zero dim, 1d to 5d input shape. Actually, the codes have been tested by static shapes and the random generator here is for shorter testing time.
   Do you think it's necessary to change back still? If yes, I'll do it.

----------------------------------------------------------------
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