From 0076bc7bbe62833797cca8619396743c8ad54781 Mon Sep 17 00:00:00 2001 From: Dick Carter Date: Wed, 30 Sep 2020 17:15:15 -0700 Subject: [PATCH] Fix test_numpy_op.py:test_np_mixed_precision_binary_funcs with portion of (#18660) --- tests/python/unittest/test_numpy_op.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/python/unittest/test_numpy_op.py b/tests/python/unittest/test_numpy_op.py index 20da12b12f48..4bdaf5203ef1 100644 --- a/tests/python/unittest/test_numpy_op.py +++ b/tests/python/unittest/test_numpy_op.py @@ -2528,6 +2528,27 @@ def __init__(self, func): def hybrid_forward(self, F, a, b, *args, **kwargs): return getattr(F.np, self._func)(a, b) + if (func in ['multiply', 'mod', 'equal', 'not_equal', 'greater', + 'greater_equal', 'less', 'less_equal']) and \ + (lshape == () or rshape == ()) : + # the behaviors of infer type in dealing with the input shape of '()' are different between np and onp + # for example, + # mx_test_x1 = np.random.uniform(-2, 2, (2,3)).astype(np.float32) + # mx_test_x2 = np.random.uniform(-2, 2, ()).astype(np.float16) + # np_out = _np.mod(mx_test_x1.asnumpy(), mx_test_x2.asnumpy()) # float16 + # mx_out = np.mod(mx_test_x1, mx_test_x2) # float32 + + # logcial ops: when two numbers are only different in precision, NumPy also has a weird behavior + # for example, + # a = np.array([[1.441]], dtype = np.float16) + # b = np.array(1.4413278, dtype = np.float32) + # c = np.array([1.4413278], dtype = np.float32) + # np.greater(a,b), np.greater(a,c) # True True + # _np.greater(a.asnumpy(),b.asnumpy()), _np.greater(a.asnumpy(),c.asnumpy()) # False True + + # thus, skip the tests + return + np_func = getattr(_np, func) mx_func = TestMixedBinary(func) np_test_x1 = _np.random.uniform(low, high, lshape).astype(ltype)