zhreshold commented on a change in pull request #11643: Added the diag() 
operator
URL: https://github.com/apache/incubator-mxnet/pull/11643#discussion_r201872980
 
 

 ##########
 File path: tests/python/unittest/test_operator.py
 ##########
 @@ -6977,6 +6977,109 @@ def test_roi_align_autograd(sampling_ratio=0):
     test_roi_align_value(2)
     test_roi_align_autograd()
 
+@with_seed()
+def test_diag():
+
+    # test 2d input
+    h = np.random.randint(2,9)
+    w = np.random.randint(2,9)
+    a_np = np.random.random((h, w))
+    a = mx.nd.array(a_np)
+    
+    # k == 0
+    r = mx.nd.diag(a)
+
+    for i in range(r.shape[0]):
+        assert r[i] == a[i][i]
 
 Review comment:
   you can use numpy for consistency check. It's more stable than manually 
setting the desired values

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on 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