hzfan commented on a change in pull request #15258: Numpy Trace
URL: https://github.com/apache/incubator-mxnet/pull/15258#discussion_r296432827
 
 

 ##########
 File path: tests/python/unittest/test_numpy_op.py
 ##########
 @@ -948,6 +948,85 @@ def hybrid_forward(self, F, x):
             assert same(ret_mx.asnumpy(), ret_np)
 
 
+@with_seed()
[email protected]_np_shape
+def test_np_trace():
+  class TestTrace(HybridBlock):
+    def __init__(self, axis1, axis2, offset):
+      super(TestTrace, self).__init__()
+      self._axis1 = axis1
+      self._axis2 = axis2
+      self._offset = offset
+      # necessary initializations
+          
+    def hybrid_forward(self, F, data):
+      return F.np.trace(data, axis1=self._axis1, axis2=self._axis2, 
offset=self._offset)
+    
+  def g(data, axis1, axis2, offset):
+    idx = _np.indices(data.shape)
+    ret = _np.zeros_like(data)
+    ret[idx[axis1] + offset == idx[axis2]] = 1.0
+    return ret
+
+  shapes = [(3, 3),
+            (3, 4),
+            (0, 0),
+            (3, 3, 3),
+            (0, 0, 0),
+            (2, 2, 4, 3),
+            (2, 2, 4, 3),
+            (2, 0, 3, 0),
+            (2, 0, 2, 3)]
 
 Review comment:
   fixed

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