sxjscience commented on a change in pull request #18342:
URL: https://github.com/apache/incubator-mxnet/pull/18342#discussion_r426198566



##########
File path: tests/python/unittest/test_numpy_ndarray.py
##########
@@ -1327,3 +1327,28 @@ def test_np_ndarray_pickle():
             a_load = pickle.load(f)
         same(a.asnumpy(), a_load.asnumpy())
 
[email protected]('dtype', [np.float32, np.int32])
[email protected]('size', [
+    (3, 4, 5, 6),
+    (2, 10),
+    (15,),
+    ()
+])
+@use_np
+def test_dlpack(dtype, size):
+    a = mx.np.random.uniform(size=size)
+    a_np = a.copy()
+    a += 1
+
+    pack = mx.npx.to_dlpack_for_read(a)
+    b = mx.npx.from_dlpack(pack)
+
+    a_copy = a.copy()
+    pack2 = mx.npx.to_dlpack_for_write(a_copy)
+    c = mx.npx.from_dlpack(pack2)
+    c += 1
+
+    del a, pack, pack2
+
+    same(a_np+1, b)
+    same(a_np+2, c)

Review comment:
       How about also testing for `same(a_np + 2, a_copy)`? This ensures that 
the behavior of `to_dlpack_for_write` is correct and is different from 
`to_dlpack_for_read`.




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


Reply via email to