You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by GitBox <gi...@apache.org> on 2022/05/12 23:43:55 UTC

[GitHub] [tvm] areusch commented on a diff in pull request #11303: Fix json serialization for NDArray

areusch commented on code in PR #11303:
URL: https://github.com/apache/tvm/pull/11303#discussion_r871895680


##########
tests/python/unittest/test_node_reflection.py:
##########
@@ -160,14 +162,35 @@ def test_dict():
     assert set(dir(x.__class__)) <= set(dir(x))
 
 
+def test_ndarray():
+    dev = tvm.cpu(0)
+    tvm_arr = tvm.nd.array(np.random.rand(4), device=dev)
+    tvm_arr2 = tvm.ir.load_json(tvm.ir.save_json(tvm_arr))
+    tvm.ir.assert_structural_equal(tvm_arr, tvm_arr2)
+    np.testing.assert_array_equal(tvm_arr.numpy(), tvm_arr2.numpy())
+
+
+def test_ndarray_dict():
+    dev = tvm.cpu(0)
+    m1 = {
+        "key1": tvm.nd.array(np.random.rand(4), device=dev),
+        "key2": tvm.nd.array(np.random.rand(4), device=dev),
+    }
+    m2 = tvm.ir.load_json(tvm.ir.save_json(m1))
+    tvm.ir.assert_structural_equal(m1, m2)
+
+
+def test_alloc_const():
+    dev = tvm.cpu(0)
+    dtype = "float32"
+    shape = (16,)
+    buf = tvm.tir.decl_buffer(shape, dtype)
+    data = tvm.nd.array(np.random.rand(*shape).astype(dtype), device=dev)
+    body = tvm.tir.Evaluate(0)
+    stmt = tvm.tir.AllocateConst(buf.data, dtype, shape, data, body)
+    stmt2 = tvm.ir.load_json(tvm.ir.save_json(stmt))

Review Comment:
   could you double-check that you're actually exporting an NDArray into JSON here? i think this might fix it , but it would be great if we could prove it through e.g. non-empty b64ndarray key



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

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org