You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2019/12/20 19:36:43 UTC

[GitHub] [incubator-mxnet] sxjscience commented on a change in pull request #17123: refactor gluon.utils.split_data() following np.array_split()

sxjscience commented on a change in pull request #17123: refactor gluon.utils.split_data() following np.array_split()
URL: https://github.com/apache/incubator-mxnet/pull/17123#discussion_r360541344
 
 

 ##########
 File path: tests/python/unittest/test_gluon.py
 ##########
 @@ -958,11 +961,30 @@ def check_split_data(x, num_slice, batch_axis, **kwargs):
     mx.test_utils.assert_almost_equal(mx.nd.concat(*res, dim=batch_axis).asnumpy(),
                                       x.asnumpy())
 
+    np_res = np.array_split(x.asnumpy(), num_slice, axis=batch_axis)
+    res_asnp = [s.asnumpy() for s in res]
+    for r1, r2 in zip(np_res, res_asnp):
+        assert all(r1.reshape(-1) == r2.reshape(-1))
+
+
+def check_split_data(x, num_slice, batch_axis, **kwargs):
+    res = gluon.utils.split_data(x, num_slice, batch_axis, **kwargs)
+    assert len(res) == num_slice
+    if not is_np_array():
+        mx.test_utils.assert_almost_equal(mx.nd.concat(*res, dim=batch_axis).asnumpy(),
+                                          x.asnumpy())
+    else:
+        mx.test_utils.assert_almost_equal(_mx_np.concatenate(res, axis=batch_axis).asnumpy(),
+                                          x.asnumpy())
+    np_res = np.array_split(x.asnumpy(), num_slice, axis=batch_axis)
+    res_asnp = [s.asnumpy() for s in res]
+    for r1, r2 in zip(np_res, res_asnp):
+        assert all(r1.reshape(-1) == r2.reshape(-1))
 
-@with_seed()
-def test_split_data():
-    x = mx.nd.random.uniform(shape=(128, 33, 64))
 
 Review comment:
   You will need to name it as `test_split_data()` otherwise it will not be recognized by nosetests.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services