access2rohit commented on a change in pull request #19302:
URL: https://github.com/apache/incubator-mxnet/pull/19302#discussion_r500644524
##########
File path: tests/nightly/test_np_large_array.py
##########
@@ -665,6 +665,84 @@ def test_subtract():
assert B.grad.shape == (INT_OVERFLOW, 2)
assert B.grad[0][0] == -1
+@use_np
+def test_diag():
+ # test diag extraction
+ inp = np.zeros((2, INT_OVERFLOW+2))
+ inp[-1, -1] = 1
+ inp.attach_grad()
+ with mx.autograd.record():
+ out = np.diag(inp, k=INT_OVERFLOW)
+ out.backward()
+ assert out.shape == (2, )
+ assert out[1] == 1
+ assert inp.grad.shape == inp.shape
+ assert inp.grad[1, -1] == 1 and inp.grad[0, -2] == 1
+ # now test mat generation
+ N = 2**16
+ inp = np.ones((N))
+ inp[-1] = 2
+ inp.attach_grad()
+ with mx.autograd.record():
+ out = np.diag(inp)
+ out.backward()
+ assert out.shape == (N, N)
+ assert out[-1, -1] == 2 and out[0, 0] == 1
+ assert inp.grad.shape == inp.shape
+ assert inp.grad[-1] == 1
+
+@use_np
+def test_diag_indices_from():
+ N = 2**16
+ inp = np.zeros((N, N))
+ inp.attach_grad()
+ with mx.autograd.record():
+ dim1, dim2 = np.diag_indices_from(inp)
+ dim1.backward()
+ assert dim1.shape == (N, ) and dim2.shape == (N, )
+ assert dim1[-1] == N-1 and dim2[-1] == N-1
+ assert inp.grad.shape == inp.shape
+ assert inp[0, 0] == 0
+
+@use_np
+def test_diagflat():
+ N = 2**16
+ inp = np.ones((2, N))
+ inp[-1, -1] = 2
+ inp.attach_grad()
+ with mx.autograd.record():
+ out = np.diagflat(inp)
+ out.backward()
+ assert out.shape == (N*2, N*2)
+ assert out[-1, -1] == 2
Review comment:
can you add a zero check for any other element too ?
----------------------------------------------------------------
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]