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 2018/09/29 00:04:00 UTC
[GitHub] anirudh2290 closed pull request #12358: Fix flaky test :
test_ndarray.test_order
anirudh2290 closed pull request #12358: Fix flaky test : test_ndarray.test_order
URL: https://github.com/apache/incubator-mxnet/pull/12358
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/tests/python/unittest/test_ndarray.py b/tests/python/unittest/test_ndarray.py
index a1c178f8234..38d9429003b 100644
--- a/tests/python/unittest/test_ndarray.py
+++ b/tests/python/unittest/test_ndarray.py
@@ -639,7 +639,6 @@ def test_arange():
assert_almost_equal(pred, gt)
@with_seed()
-@unittest.skip("Flaky test https://github.com/apache/incubator-mxnet/issues/12310")
def test_order():
ctx = default_context()
dat_size = 5
@@ -703,29 +702,33 @@ def get_large_matrix():
return data
large_matrix_npy = get_large_matrix()
- large_matrix_nd = mx.nd.array(large_matrix_npy, ctx=ctx)
+ large_matrix_nd = mx.nd.array(large_matrix_npy, ctx=ctx, dtype=large_matrix_npy.dtype)
nd_ret_topk = mx.nd.topk(large_matrix_nd, axis=1, ret_typ="indices", k=5, is_ascend=False).asnumpy()
gt = gt_topk(large_matrix_npy, axis=1, ret_typ="indices", k=5, is_ascend=False)
assert_almost_equal(nd_ret_topk, gt)
- for dtype in [np.int16, np.int32, np.int64, np.float32, np.float64]:
+ for dtype in [ np.int32, np.int64, np.float32, np.float64]:
a_npy = get_values(ensure_unique=True, dtype=dtype)
- a_nd = mx.nd.array(a_npy, ctx=ctx)
+ a_nd = mx.nd.array(a_npy, ctx=ctx, dtype=dtype)
# test for ret_typ=indices
nd_ret_topk = mx.nd.topk(a_nd, axis=1, ret_typ="indices", k=3, is_ascend=True).asnumpy()
+ assert nd_ret_topk.dtype == np.float32 # Test the default dtype
gt = gt_topk(a_npy, axis=1, ret_typ="indices", k=3, is_ascend=True)
assert_almost_equal(nd_ret_topk, gt)
- nd_ret_topk = mx.nd.topk(a_nd, axis=3, ret_typ="indices", k=2, is_ascend=False).asnumpy()
+ nd_ret_topk = mx.nd.topk(a_nd, axis=3, ret_typ="indices", k=2, is_ascend=False, dtype=np.float64).asnumpy()
+ assert nd_ret_topk.dtype == np.float64
gt = gt_topk(a_npy, axis=3, ret_typ="indices", k=2, is_ascend=False)
assert_almost_equal(nd_ret_topk, gt)
- nd_ret_topk = mx.nd.topk(a_nd, axis=None, ret_typ="indices", k=21, is_ascend=False).asnumpy()
+ nd_ret_topk = mx.nd.topk(a_nd, axis=None, ret_typ="indices", k=21, is_ascend=False, dtype=np.int32).asnumpy()
+ assert nd_ret_topk.dtype == np.int32
gt = gt_topk(a_npy, axis=None, ret_typ="indices", k=21, is_ascend=False)
assert_almost_equal(nd_ret_topk, gt)
# test for ret_typ=value
nd_ret_topk = mx.nd.topk(a_nd, axis=1, ret_typ="value", k=3, is_ascend=True).asnumpy()
+ assert nd_ret_topk.dtype == dtype
gt = gt_topk(a_npy, axis=1, ret_typ="value", k=3, is_ascend=True)
assert_almost_equal(nd_ret_topk, gt)
nd_ret_topk = mx.nd.topk(a_nd, axis=3, ret_typ="value", k=2, is_ascend=False).asnumpy()
@@ -736,7 +739,11 @@ def get_large_matrix():
assert_almost_equal(nd_ret_topk, gt)
# test for ret_typ=mask
+ # test needs to be re-enabled once flaky topk gets fixed
+ # tracked in https://github.com/apache/incubator-mxnet/pull/12446
+ '''
nd_ret_topk = mx.nd.topk(a_nd, axis=1, ret_typ="mask", k=3, is_ascend=True).asnumpy()
+ assert nd_ret_topk.dtype == dtype
gt = gt_topk(a_npy, axis=1, ret_typ="mask", k=3, is_ascend=True)
assert_almost_equal(nd_ret_topk, gt)
nd_ret_topk = mx.nd.topk(a_nd, axis=1, ret_typ="mask", k=2, is_ascend=False).asnumpy()
@@ -745,17 +752,20 @@ def get_large_matrix():
nd_ret_topk = mx.nd.topk(a_nd, axis=None, ret_typ="mask", k=21, is_ascend=False).asnumpy()
gt = gt_topk(a_npy, axis=None, ret_typ="mask", k=21, is_ascend=False)
assert_almost_equal(nd_ret_topk, gt)
-
+ '''
# test for ret_typ=both
nd_ret_topk_val, nd_ret_topk_ind = mx.nd.topk(a_nd, axis=1, ret_typ="both", k=3, is_ascend=True)
nd_ret_topk_val = nd_ret_topk_val.asnumpy()
nd_ret_topk_ind = nd_ret_topk_ind.asnumpy()
+ assert nd_ret_topk_val.dtype == dtype
+ assert nd_ret_topk_ind.dtype == np.float32
gt_val = gt_topk(a_npy, axis=1, ret_typ="value", k=3, is_ascend=True)
gt_ind = gt_topk(a_npy, axis=1, ret_typ="indices", k=3, is_ascend=True)
assert_almost_equal(nd_ret_topk_val, gt_val)
assert_almost_equal(nd_ret_topk_ind, gt_ind)
# test for kNullOp
- _, nd_ret_topk_ind = mx.nd.topk(a_nd, axis=1, ret_typ="both", k=3, is_ascend=True)
+ _, nd_ret_topk_ind = mx.nd.topk(a_nd, axis=1, ret_typ="both", k=3, is_ascend=True, dtype=np.float64)
+ assert nd_ret_topk_ind.dtype == np.float64
nd_ret_topk_ind = nd_ret_topk_ind.asnumpy()
assert_almost_equal(nd_ret_topk_ind, gt_ind)
# test for kNullOp
@@ -778,6 +788,7 @@ def get_large_matrix():
gt = gt_topk(a_npy, axis=3, ret_typ="indices", k=dat_size, is_ascend=True)
assert_almost_equal(nd_ret_argsort, gt)
nd_ret_argsort = mx.nd.argsort(a_nd, axis=None, is_ascend=False, dtype=idtype).asnumpy()
+ assert nd_ret_argsort.dtype == idtype
gt = gt_topk(a_npy, axis=None, ret_typ="indices",
k=dat_size*dat_size*dat_size*dat_size, is_ascend=False)
assert_almost_equal(nd_ret_argsort, gt)
@@ -786,7 +797,7 @@ def get_large_matrix():
# duplicated input data values (over many repeated runs with different random seeds,
# this will be tested).
a_npy = get_values(ensure_unique=False, dtype=dtype)
- a_nd = mx.nd.array(a_npy, ctx=ctx)
+ a_nd = mx.nd.array(a_npy, ctx=ctx, dtype=dtype)
# test for ret_typ=value
nd_ret_topk = mx.nd.topk(a_nd, axis=1, ret_typ="value", k=3, is_ascend=True).asnumpy()
@@ -837,9 +848,9 @@ def get_large_matrix():
# Repeat those tests that don't involve indices. These should pass even with
# duplicated input data values (over many repeated runs with different random seeds,
# this will be tested).
- for dtype in [np.int16, np.int32, np.int64, np.float32, np.float64]:
+ for dtype in [ np.int32, np.int64, np.float32, np.float64]:
a_npy = get_values(ensure_unique=False, dtype=dtype)
- a_nd = mx.nd.array(a_npy, ctx=ctx)
+ a_nd = mx.nd.array(a_npy, ctx=ctx, dtype=dtype)
# test for ret_typ=value
nd_ret_topk = mx.nd.topk(a_nd, axis=1, ret_typ="value", k=3, is_ascend=True).asnumpy()
----------------------------------------------------------------
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:
users@infra.apache.org
With regards,
Apache Git Services