This is an automated email from the ASF dual-hosted git repository.

dickjc123 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-mxnet.git


The following commit(s) were added to refs/heads/master by this push:
     new 95a6a54  [v2.0] [BUGFIX] Port #20940 (Upgrade numpy to <1.20.0 ...) 
from v1.9.x (#20957)
95a6a54 is described below

commit 95a6a54adf8b9dfbabe8d558109896e0b88fb9e4
Author: Dick Carter <[email protected]>
AuthorDate: Fri Mar 18 16:41:44 2022 -0700

    [v2.0] [BUGFIX] Port #20940 (Upgrade numpy to <1.20.0 ...) from v1.9.x 
(#20957)
    
    * Stop skipping tests mentioned in issue 18600
    
    * Reenable test_np_random_chisquare also
    
    * [v1.9.x] [BUGFIX] Upgrade numpy to <1.20.0 to avoid security 
vulnerabilities affecting numpy<1.19.1 (#20940)
    
    * Pin numpy==1.19.1 to demonstrate issues
    
    * Relax min numpy version
    
    * Make test_np_array_function_protocol delete() testing work with 
numpy>=1.19
    
    * Fix test_np_delete to also work with numpy>=1.19
    
    * Pip install python module 'packaging'
    
    * More pip-install 'packaging'
    
    * Update windows requirements.txt
    
    * Allow numpy as advanced as 1.19.5
    
    * Fix test_np_random_{beta,f,chisquare}
---
 ci/docker/install/requirements                     |  1 +
 .../python/unittest/test_numpy_interoperability.py | 10 +++----
 tests/python/unittest/test_numpy_op.py             | 32 +++++++++++++---------
 3 files changed, 25 insertions(+), 18 deletions(-)

diff --git a/ci/docker/install/requirements b/ci/docker/install/requirements
index de6882d..62452aa 100644
--- a/ci/docker/install/requirements
+++ b/ci/docker/install/requirements
@@ -45,6 +45,7 @@ pytest-rerunfailures==10.2
 flaky==3.7.0
 setuptools==49.6.0  # https://github.com/pypa/setuptools/issues/2352
 wheel
+packaging
 
 # TVM dependencies
 decorator==4.4.0
diff --git a/tests/python/unittest/test_numpy_interoperability.py 
b/tests/python/unittest/test_numpy_interoperability.py
index b4dcf0b..a148748 100644
--- a/tests/python/unittest/test_numpy_interoperability.py
+++ b/tests/python/unittest/test_numpy_interoperability.py
@@ -1299,10 +1299,12 @@ def _add_workload_delete():
                 s = slice(start, stop, step)
                 OpArgMngr.add_workload('delete', a, s)
                 OpArgMngr.add_workload('delete', nd_a, s, axis=1)
-    OpArgMngr.add_workload('delete', a, np.array([]), axis=0)
+    # mxnet.numpy arrays, even 0-sized, have a float32 dtype.  Starting with 
numpy 1.19, the
+    # index array's of delete() must be of integer or boolean type, so we 
force that below.
+    OpArgMngr.add_workload('delete', a, np.array([], dtype='int32'), axis=0)
     OpArgMngr.add_workload('delete', a, 0)
-    OpArgMngr.add_workload('delete', a, np.array([]))
-    OpArgMngr.add_workload('delete', a, np.array([0, 1]))
+    OpArgMngr.add_workload('delete', a, np.array([], dtype='int32'))
+    OpArgMngr.add_workload('delete', a, np.array([0, 1], dtype='int32'))
     OpArgMngr.add_workload('delete', a, slice(1, 2))
     OpArgMngr.add_workload('delete', a, slice(1, -2))
     k = np.arange(10).reshape(2, 5)
@@ -3345,8 +3347,6 @@ def check_interoperability(op_list):
         if name in ['shares_memory', 'may_share_memory', 'empty_like',
                     '__version__', 'dtype', '_NoValue']:  # skip list
             continue
-        if name in ['delete']: # 
https://github.com/apache/incubator-mxnet/issues/18600
-            continue
         if name in ['full_like', 'zeros_like', 'ones_like'] and \
                 StrictVersion(platform.python_version()) < 
StrictVersion('3.0.0'):
             continue
diff --git a/tests/python/unittest/test_numpy_op.py 
b/tests/python/unittest/test_numpy_op.py
index e3a2fd8..c2c3341 100644
--- a/tests/python/unittest/test_numpy_op.py
+++ b/tests/python/unittest/test_numpy_op.py
@@ -30,6 +30,7 @@ import scipy.special as scipy_special
 import pytest
 import mxnet.ndarray.numpy._internal as _npi
 from functools import reduce
+from packaging.version import parse
 from mxnet import np, npx
 from mxnet.gluon import HybridBlock
 from mxnet.base import MXNetError
@@ -4488,7 +4489,6 @@ def test_np_swapaxes():
 
 
 @use_np
[email protected](reason='https://github.com/apache/incubator-mxnet/issues/18600')
 def test_np_delete():
     class TestDelete(HybridBlock):
         def __init__(self, obj, axis=None):
@@ -4537,6 +4537,12 @@ def test_np_delete():
             if type(obj) == list:
                 obj_mxnp = np.array(obj, dtype=objtype)
                 obj_onp = onp.array(obj, dtype=objtype)
+                # To match mxnet.numpy's behavior of ignoring out-of-bounds 
indices,
+                # we may need to filter out indices that this numpy would not 
ignore.
+                onp_ignores_oob_indices = parse(onp.version.version) < 
parse('1.19')
+                if not onp_ignores_oob_indices:
+                    dim_size = GetDimSize(arr_shape,axis)
+                    obj_onp = obj_onp[((obj_onp>=0) & (obj_onp<dim_size))]
             elif type(obj) == slice:
                 obj_mxnp = obj
                 obj_onp = obj
@@ -5095,7 +5101,6 @@ def test_gamma_grad(shape, a, b):
 
 
 @use_np
[email protected](reason='https://github.com/apache/incubator-mxnet/issues/18600')
 def test_np_random_beta():
     class TestRandomBeta(HybridBlock):
         def __init__(self, size=None, dtype=None, device=None):
@@ -5112,7 +5117,8 @@ def test_np_random_beta():
         smaller_than_one = onp.all(output < 1)
         return bigger_than_zero and smaller_than_one
 
-    shape_list = [(), (1,), (2, 3), (4, 0, 5), 6, (7, 8), None]
+    # Starting with numpy 1.19.0, output shape of () is no longer supported
+    shape_list = [(0,), (1,), (2, 3), (4, 0, 5), 6, (7, 8), None]
     # since fp16 might incur precision issue, the corresponding test is skipped
     dtype_list = [np.float32, np.float64]
     hybridize_list = [False, True]
@@ -5128,8 +5134,8 @@ def test_np_random_beta():
         mx_out = test_random_beta(mx_data, mx_data)
         mx_out_imperative = mx.np.random.beta(mx_data, mx_data, 
size=param_shape, dtype=out_dtype)
 
-        assert_almost_equal(np_out.shape, mx_out.shape)
-        assert_almost_equal(np_out.shape, mx_out_imperative.shape)
+        assert np_out.shape == mx_out.shape
+        assert np_out.shape == mx_out_imperative.shape
         assert _test_random_beta_range(mx_out.asnumpy()) == True
         assert _test_random_beta_range(mx_out_imperative.asnumpy()) == True
 
@@ -5139,7 +5145,6 @@ def test_np_random_beta():
 
 
 @use_np
[email protected](reason='https://github.com/apache/incubator-mxnet/issues/18600')
 def test_np_random_f():
     class TestRandomF(HybridBlock):
         def __init__(self, size=None):
@@ -5149,7 +5154,8 @@ def test_np_random_f():
         def forward(self, dfnum, dfden):
             return np.random.f(dfnum, dfden, size=self._size)
 
-    shape_list = [(), (1,), (2, 3), (4, 0, 5), 6, (7, 8), None]
+    # Starting with numpy 1.19.0, output shape of () is no longer supported
+    shape_list = [(0,), (1,), (2, 3), (4, 0, 5), 6, (7, 8), None]
     hybridize_list = [False, True]
     df = np.array([1])
     for [param_shape, hybridize] in itertools.product(shape_list,
@@ -5165,12 +5171,11 @@ def test_np_random_f():
         mx_out = test_random_f(mx_df, mx_df)
         mx_out_imperative = mx.np.random.f(mx_df, mx_df, size=param_shape)
 
-        assert_almost_equal(np_out.shape, mx_out.shape)
-        assert_almost_equal(np_out.shape, mx_out_imperative.shape)
+        assert np_out.shape == mx_out.shape
+        assert np_out.shape == mx_out_imperative.shape
 
 
 @use_np
[email protected](reason='https://github.com/apache/incubator-mxnet/issues/18600')
 def test_np_random_chisquare():
     class TestRandomChisquare(HybridBlock):
         def __init__(self, size=None, dtype=None, device=None):
@@ -5182,7 +5187,8 @@ def test_np_random_chisquare():
         def forward(self, df):
             return np.random.chisquare(df, size=self._size, dtype=self._dtype, 
device=self._device)
 
-    shape_list = [(), (1,), (2, 3), (4, 0, 5), 6, (7, 8), None]
+    # Starting with numpy 1.19.0, output shape of () is no longer supported
+    shape_list = [(0,), (1,), (2, 3), (4, 0, 5), 6, (7, 8), None]
 
     dtype_list = [np.float16, np.float32, np.float64]
     hybridize_list = [False, True]
@@ -5200,8 +5206,8 @@ def test_np_random_chisquare():
         mx_out = test_random_chisquare(mx_df)
         mx_out_imperative = mx.np.random.chisquare(mx_df, size=param_shape, 
dtype=out_dtype)
 
-        assert_almost_equal(np_out.shape, mx_out.shape)
-        assert_almost_equal(np_out.shape, mx_out_imperative.shape)
+        assert np_out.shape == mx_out.shape
+        assert np_out.shape == mx_out_imperative.shape
 
 
 @use_np

Reply via email to