diff --git a/docs/python_docs/python/tutorials/packages/np/cheat-sheet.md b/docs/python_docs/python/tutorials/packages/np/cheat-sheet.md index 238b0b985b21..22174ecf6adf 100644 --- a/docs/python_docs/python/tutorials/packages/np/cheat-sheet.md +++ b/docs/python_docs/python/tutorials/packages/np/cheat-sheet.md @@ -108,7 +108,7 @@ npx.load('my_arrays') # np.int64 # Signed 64-bit integer types # np.float32 # Standard double-precision floating point # np.complex # Complex numbers represented by 128 floats -# np.bool # Boolean type storing TRUE and FALSE values +# bool # Boolean type storing TRUE and FALSE values (formerly `np.bool`) # np.object # Python object type # np.string_ # Fixed-length string type # np.unicode_ # Fixed-length unicode type diff --git a/python/mxnet/ndarray/ndarray.py b/python/mxnet/ndarray/ndarray.py index 25f0fba3e6b2..699f7284ad7f 100644 --- a/python/mxnet/ndarray/ndarray.py +++ b/python/mxnet/ndarray/ndarray.py @@ -3078,7 +3078,7 @@ def indexing_key_expand_implicit_axes(key, shape): (slice(None, 2, None), None, 0, slice(None, None, None)) >>> bool_array = np.array([[True, False, True, False], [False, True, False, True], - [True, False, True, False]], dtype=np.bool) + [True, False, True, False]], dtype=bool) >>> indexing_key_expand_implicit_axes(np.s_[bool_array, None, 0:2], shape) (array([0, 0, 1, 1, 2, 2], dtype=int64), array([0, 2, 1, 3, 0, 2], dtype=int64), None, slice(None, 2, None)) """ @@ -3109,7 +3109,7 @@ def indexing_key_expand_implicit_axes(key, shape): ) ell_idx = i else: - # convert primitive type boolean value to mx.np.bool type + # convert primitive type boolean value to bool (formerly mx.np.bool) type # otherwise will be treated as 1/0 if isinstance(idx, bool): idx = array(idx, dtype=np.bool_) diff --git a/python/mxnet/ndarray/numpy/_op.py b/python/mxnet/ndarray/numpy/_op.py index 1c42723b6459..f915d8c01247 100644 --- a/python/mxnet/ndarray/numpy/_op.py +++ b/python/mxnet/ndarray/numpy/_op.py @@ -391,7 +391,7 @@ def full(shape, fill_value, dtype=None, order='C', device=None, out=None): # py device = str(device) if isinstance(fill_value, bool): fill_value = int(fill_value) - dtype = _np.bool if dtype is None else dtype + dtype = bool if dtype is None else dtype elif isinstance(fill_value, numeric_types): if dtype is None or dtype is float: dtype = dtype_from_number(fill_value) @@ -526,7 +526,7 @@ def empty_like(prototype, dtype=None, order='C', subok=False, shape=None): # pyl dtype_list = {_np.float16: 'float16', _np.float32: 'float32', _np.float64: 'float64', float: 'float64', _np.int8: 'int8', _np.int16: 'int16', _np.int32: 'int32', _np.int64: 'int64', int:'int64', _np.uint8: 'uint8', _np.uint16: 'uint16', - _np.uint32: 'uint32', _np.uint64: 'uint64', _np.bool: 'bool', + _np.uint32: 'uint32', _np.uint64: 'uint64', bool: 'bool', _np.bool_: 'bool_', bool: 'bool', None: 'None'} if order != 'C': raise NotImplementedError("Only support C-order at this moment") @@ -8969,7 +8969,7 @@ def isposinf(x, out=None, **kwargs): >>> np.isposinf(np.array([-np.inf, 0., np.inf])) array([False, False, True]) >>> x = np.array([-np.inf, 0., np.inf]) - >>> y = np.array([True, True, True], dtype=np.bool) + >>> y = np.array([True, True, True], dtype=bool) >>> np.isposinf(x, y) array([False, False, True]) >>> y @@ -9015,7 +9015,7 @@ def isneginf(x, out=None, **kwargs): >>> np.isneginf(np.array([-np.inf, 0., np.inf])) array([ True, False, False]) >>> x = np.array([-np.inf, 0., np.inf]) - >>> y = np.array([True, True, True], dtype=np.bool) + >>> y = np.array([True, True, True], dtype=bool) >>> np.isneginf(x, y) array([ True, False, False]) >>> y @@ -9070,7 +9070,7 @@ def isfinite(x, out=None, **kwargs): >>> np.isfinite(np.array([np.log(-1.),1.,np.log(0)])) array([False, True, False]) >>> x = np.array([-np.inf, 0., np.inf]) - >>> y = np.array([True, True, True], dtype=np.bool) + >>> y = np.array([True, True, True], dtype=bool) >>> np.isfinite(x, y) array([False, True, False]) >>> y diff --git a/python/mxnet/numpy/multiarray.py b/python/mxnet/numpy/multiarray.py index ed96795fface..9930e3965766 100644 --- a/python/mxnet/numpy/multiarray.py +++ b/python/mxnet/numpy/multiarray.py @@ -192,7 +192,7 @@ def _as_mx_np_array(object, device=None, zero_copy=False): return from_numpy(object, zero_copy and object.flags['C_CONTIGUOUS']) elif isinstance(object, (integer_types, numeric_types)): return object - elif isinstance(object, (_np.bool_, _np.bool)): + elif isinstance(object, (_np.bool_, bool)): return array(object, dtype=_np.bool_, device=device) elif isinstance(object, (list, tuple)): tmp = [_as_mx_np_array(arr, device=device, zero_copy=zero_copy) for arr in object] @@ -782,7 +782,7 @@ def __getitem__(self, key): ndim = self.ndim # pylint: disable=redefined-outer-name shape = self.shape # pylint: disable=redefined-outer-name if isinstance(key, bool): # otherwise will be treated as 0 and 1 - key = array(key, dtype=_np.bool, device=self.device) + key = array(key, dtype=bool, device=self.device) if isinstance(key, list): try: new_key = _np.array(key) @@ -966,13 +966,13 @@ def __setitem__(self, key, value): if isinstance(value, NDArray) and not isinstance(value, ndarray): raise TypeError('Cannot assign mx.nd.NDArray to mxnet.numpy.ndarray') if isinstance(key, bool): # otherwise will be treated as 0 and 1 - key = array(key, dtype=_np.bool) + key = array(key, dtype=bool) # Handle single boolean assign of matching dimensionality and size first for higher speed # If the boolean array is mixed with other idices, it is instead expanded into (multiple) # integer array indices and will be handled by advanced assign. # Come before the check self.dim == 0 as it also handle the 0-dim case. - if isinstance(key, ndarray) and key.dtype == _np.bool: + if isinstance(key, ndarray) and key.dtype == bool: return self._set_np_boolean_indexing(key, value) # handle basic and advanced indexing @@ -12123,7 +12123,7 @@ def isposinf(x, out=None, **kwargs): >>> np.isposinf(np.array([-np.inf, 0., np.inf])) array([False, False, True]) >>> x = np.array([-np.inf, 0., np.inf]) - >>> y = np.array([True, True, True], dtype=np.bool) + >>> y = np.array([True, True, True], dtype=bool) >>> np.isposinf(x, y) array([False, False, True]) >>> y @@ -12169,7 +12169,7 @@ def isneginf(x, out=None, **kwargs): >>> np.isneginf(np.array([-np.inf, 0., np.inf])) array([ True, False, False]) >>> x = np.array([-np.inf, 0., np.inf]) - >>> y = np.array([True, True, True], dtype=np.bool) + >>> y = np.array([True, True, True], dtype=bool) >>> np.isneginf(x, y) array([ True, False, False]) >>> y @@ -12224,7 +12224,7 @@ def isfinite(x, out=None, **kwargs): >>> np.isfinite(np.array([np.log(-1.),1.,np.log(0)])) array([False, True, False]) >>> x = np.array([-np.inf, 0., np.inf]) - >>> y = np.array([True, True, True], dtype=np.bool) + >>> y = np.array([True, True, True], dtype=bool) >>> np.isfinite(x, y) array([False, True, False]) >>> y diff --git a/python/mxnet/numpy/utils.py b/python/mxnet/numpy/utils.py index 21fe1e299d2e..4c75498714ae 100644 --- a/python/mxnet/numpy/utils.py +++ b/python/mxnet/numpy/utils.py @@ -38,7 +38,7 @@ int8 = onp.dtype(onp.int8) int64 = onp.dtype(onp.int64) bool_ = onp.dtype(onp.bool_) -bool = onp.dtype(onp.bool) +bool = onp.dtype(bool) int16 = onp.dtype(onp.int16) uint16 = onp.dtype(onp.uint16) uint32 = onp.dtype(onp.uint32) diff --git a/python/mxnet/symbol/numpy/_symbol.py b/python/mxnet/symbol/numpy/_symbol.py index d88746ce0ea0..060876fd6c1e 100644 --- a/python/mxnet/symbol/numpy/_symbol.py +++ b/python/mxnet/symbol/numpy/_symbol.py @@ -1334,7 +1334,7 @@ def full(shape, fill_value, dtype=None, order='C', ctx=None, out=None): # pylin return ret if isinstance(fill_value, bool): fill_value = int(fill_value) - dtype = _np.bool if dtype is None else dtype + dtype = bool if dtype is None else dtype return _npi.full(shape=shape, value=fill_value, ctx=ctx, dtype=dtype, out=out) diff --git a/python/mxnet/test_utils.py b/python/mxnet/test_utils.py index c647af5743fa..877bd3b8080f 100644 --- a/python/mxnet/test_utils.py +++ b/python/mxnet/test_utils.py @@ -77,7 +77,7 @@ def default_rtols(): return {np.dtype(np.float16): 1e-2, np.dtype(np.float32): 1e-4, np.dtype(np.float64): 1e-5, - np.dtype(np.bool): 0, + np.dtype(bool): 0, np.dtype(np.int8): 0, np.dtype(np.uint8): 0, np.dtype(np.int32): 0, @@ -90,7 +90,7 @@ def default_atols(): return {np.dtype(np.float16): 1e-1, np.dtype(np.float32): 1e-3, np.dtype(np.float64): 1e-20, - np.dtype(np.bool): 0, + np.dtype(bool): 0, np.dtype(np.int8): 0, np.dtype(np.uint8): 0, np.dtype(np.int32): 0, diff --git a/tests/python/dnnl/subgraphs/test_matmul_subgraph.py b/tests/python/dnnl/subgraphs/test_matmul_subgraph.py index 938d49444f9c..6ac59dbbf565 100644 --- a/tests/python/dnnl/subgraphs/test_matmul_subgraph.py +++ b/tests/python/dnnl/subgraphs/test_matmul_subgraph.py @@ -51,7 +51,7 @@ def forward(self, x, mask): value = mx.np.reshape(value, (-2, -2, self._num_heads, -1)) scores = mx.npx.batch_dot(mx.np.swapaxes(query, 1, 2), mx.np.swapaxes(key, 1, 2), transpose_b=True) - mask = mx.np.expand_dims(mask, axis=1).astype(np.bool) + mask = mx.np.expand_dims(mask, axis=1).astype(bool) attn_weights = mx.npx.masked_softmax(scores, mask=mask, axis=-1, temperature=self._scale) attn_weights = mx.npx.dropout(attn_weights, p=0.1) context_vec = mx.npx.batch_dot(attn_weights, diff --git a/tests/python/gpu/test_fusion.py b/tests/python/gpu/test_fusion.py index 6e72a38b5ecb..58e370799206 100644 --- a/tests/python/gpu/test_fusion.py +++ b/tests/python/gpu/test_fusion.py @@ -289,7 +289,7 @@ def forward(self, valid_length): foo = Foo() foo.hybridize(static_alloc=True) - out = foo(mx.np.ones((10,), ctx=mx.gpu(), dtype=np.bool)) + out = foo(mx.np.ones((10,), ctx=mx.gpu(), dtype=bool)) mx.npx.waitall() @use_np diff --git a/tests/python/unittest/test_numpy_interoperability.py b/tests/python/unittest/test_numpy_interoperability.py index a148748f0bf3..920009f60cf8 100644 --- a/tests/python/unittest/test_numpy_interoperability.py +++ b/tests/python/unittest/test_numpy_interoperability.py @@ -1497,8 +1497,8 @@ def _add_workload_gcd(): def _add_workload_bitwise_or(): - OpArgMngr.add_workload('bitwise_or', np.array([False, False, True, True], dtype=np.bool), - np.array([False, True, False, True], dtype=np.bool)) + OpArgMngr.add_workload('bitwise_or', np.array([False, False, True, True], dtype=bool), + np.array([False, True, False, True], dtype=bool)) for dtype in [np.int8, np.int32, np.int64]: zeros = np.array([0], dtype=dtype) ones = np.array([-1], dtype=dtype) @@ -1509,8 +1509,8 @@ def _add_workload_bitwise_or(): def _add_workload_bitwise_and(): - OpArgMngr.add_workload('bitwise_and', np.array([False, False, True, True], dtype=np.bool), - np.array([False, True, False, True], dtype=np.bool)) + OpArgMngr.add_workload('bitwise_and', np.array([False, False, True, True], dtype=bool), + np.array([False, True, False, True], dtype=bool)) for dtype in [np.int8, np.int32, np.int64]: zeros = np.array([0], dtype=dtype) ones = np.array([-1], dtype=dtype) @@ -1521,8 +1521,8 @@ def _add_workload_bitwise_and(): def _add_workload_bitwise_xor(): - OpArgMngr.add_workload('bitwise_xor', np.array([False, False, True, True], dtype=np.bool), - np.array([False, True, False, True], dtype=np.bool)) + OpArgMngr.add_workload('bitwise_xor', np.array([False, False, True, True], dtype=bool), + np.array([False, True, False, True], dtype=bool)) for dtype in [np.int8, np.int32, np.int64]: zeros = np.array([0], dtype=dtype) ones = np.array([-1], dtype=dtype) @@ -1834,11 +1834,11 @@ def _add_workload_floor(array_pool): def _add_workload_logical_not(array_pool): OpArgMngr.add_workload('logical_not', np.ones(10, dtype=np.int32)) OpArgMngr.add_workload('logical_not', array_pool['4x1']) - OpArgMngr.add_workload('logical_not', np.array([True, False, True, False], dtype=np.bool)) + OpArgMngr.add_workload('logical_not', np.array([True, False, True, False], dtype=bool)) def _add_workload_bitwise_not(): - OpArgMngr.add_workload('bitwise_not', np.array([True, False, True, False], dtype=np.bool)) + OpArgMngr.add_workload('bitwise_not', np.array([True, False, True, False], dtype=bool)) for dtype in [np.int8, np.int32, np.int64]: zeros = np.array([0], dtype=dtype) ones = np.array([-1], dtype=dtype) @@ -1847,7 +1847,7 @@ def _add_workload_bitwise_not(): def _add_workload_invert(): - OpArgMngr.add_workload('invert', np.array([True, False, True, False], dtype=np.bool)) + OpArgMngr.add_workload('invert', np.array([True, False, True, False], dtype=bool)) for dtype in [np.int8, np.int32, np.int64]: zeros = np.array([0], dtype=dtype) ones = np.array([-1], dtype=dtype) @@ -2045,19 +2045,19 @@ def _add_workload_less_equal(array_pool): def _add_workload_logical_and(array_pool): OpArgMngr.add_workload('logical_and', np.array([0, 1, 2, 4, 2], dtype=np.float32), np.array([-2, 5, 1, 4, 3], dtype=np.float32)) - OpArgMngr.add_workload('logical_and', np.array([False, False, True, True], dtype=np.bool), - np.array([False, True, False, True], dtype=np.bool)) + OpArgMngr.add_workload('logical_and', np.array([False, False, True, True], dtype=bool), + np.array([False, True, False, True], dtype=bool)) def _add_workload_logical_or(array_pool): - OpArgMngr.add_workload('logical_or', np.array([0, 1, 2, 4, 2], dtype=np.bool), np.array([-2, 5, 1, 4, 3], dtype=np.bool)) - OpArgMngr.add_workload('logical_or', np.array([False, False, True, True], dtype=np.bool), - np.array([False, True, False, True], dtype=np.bool)) + OpArgMngr.add_workload('logical_or', np.array([0, 1, 2, 4, 2], dtype=bool), np.array([-2, 5, 1, 4, 3], dtype=bool)) + OpArgMngr.add_workload('logical_or', np.array([False, False, True, True], dtype=bool), + np.array([False, True, False, True], dtype=bool)) def _add_workload_logical_xor(array_pool): OpArgMngr.add_workload('logical_xor', np.array([0, 1, 2, 4, 2], dtype=np.float32), np.array([-2, 5, 1, 4, 3], dtype=np.float32)) - OpArgMngr.add_workload('logical_xor', np.array([False, False, True, True], dtype=np.bool), - np.array([False, True, False, True], dtype=np.bool)) + OpArgMngr.add_workload('logical_xor', np.array([False, False, True, True], dtype=bool), + np.array([False, True, False, True], dtype=bool)) def _add_workload_where(): @@ -2910,7 +2910,7 @@ def _add_workload_select(): condlist = np.array([[ True, True, True, False, False, False, False, False, False, False], [ False, False, False, False, False, - False, True, True, True, True]], dtype=np.bool) + False, True, True, True, True]], dtype=bool) choicelist = np.array([[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [ 0, 1, 4, 9, 16, 25, 36, 49, 64, 81]]) OpArgMngr.add_workload('select', condlist, choicelist) diff --git a/tests/python/unittest/test_numpy_ndarray.py b/tests/python/unittest/test_numpy_ndarray.py index 11df34b91ef7..4ed284d692da 100644 --- a/tests/python/unittest/test_numpy_ndarray.py +++ b/tests/python/unittest/test_numpy_ndarray.py @@ -43,7 +43,7 @@ def test_np_empty(): (np.float32, np.float32), (np.float64, np.float64), (np.bool_, np.bool_), - (np.bool, np.bool_), + (bool, np.bool_), ('int8', np.int8), ('int32', np.int32), ('float16', np.float16), @@ -80,7 +80,7 @@ def test_np_empty(): @use_np def test_np_array_creation(): - dtypes = [_np.int8, _np.int32, _np.float16, _np.float32, _np.float64, _np.bool, _np.bool_, + dtypes = [_np.int8, _np.int32, _np.float16, _np.float32, _np.float64, bool, _np.bool_, 'int8', 'int32', 'float16', 'float32', 'float64', 'bool', None] objects = [ [], @@ -154,7 +154,7 @@ def check_zero_array_creation(shape, dtype): assert type(y[1]) == np.ndarray for shape in shapes: - for dtype in [_np.bool, bool, _np.bool, 'bool']: + for dtype in [bool, 'bool']: check_zero_array_creation(shape, dtype) @@ -207,7 +207,7 @@ def check_ones_array_creation(shape, dtype): assert type(y[1]) == np.ndarray for shape in shapes: - for dtype in [_np.bool, bool, _np.bool, 'bool']: + for dtype in [bool, 'bool']: check_ones_array_creation(shape, dtype) @@ -575,7 +575,7 @@ def check_astype_equal(itype, otype, copy, expect_zero_copy=False, hybridize=Fal assert id(mx_ret) == id(mx_data) assert id(np_ret) == id(np_data) - dtypes = [np.int8, np.uint8, np.int32, np.float16, np.float32, np.float64, np.bool, np.bool_, + dtypes = [np.int8, np.uint8, np.int32, np.float16, np.float32, np.float64, bool, np.bool_, 'int8', 'uint8', 'int32', 'float16', 'float32', 'float64', 'bool'] for itype, otype in itertools.product(dtypes, dtypes): @@ -1218,7 +1218,7 @@ def test_boolean_index_tuple(): [[4, 5], [6, 7]]], dtype=np.int32) b = np.array([[False,True], - [True,False]],dtype=np.bool) + [True,False]],dtype=bool) _np_a = a.asnumpy() _np_b = b.asnumpy() assert same(a[:, b].asnumpy(), _np_a[:, _np_b]) @@ -1252,7 +1252,7 @@ def test_boolean_index_assign(): # test boolean indexing assign shape = (3, 2, 3) mx_data = np.random.uniform(size=shape) - mx_mask = np.array([[False,True], [True,False], [True,False]],dtype=np.bool) + mx_mask = np.array([[False,True], [True,False], [True,False]],dtype=bool) np_data = mx_data.asnumpy() np_mask = mx_mask.asnumpy() @@ -1271,7 +1271,7 @@ def test_boolean_index_assign(): mx_data[mx_mask, :] = 3 assert_almost_equal(mx_data.asnumpy(), np_data, rtol=1e-3, atol=1e-5, use_broadcast=False) - mx_mask = np.array([[False,True, True],[False, True,False]],dtype=np.bool) + mx_mask = np.array([[False,True, True],[False, True,False]],dtype=bool) np_mask = mx_mask.asnumpy() np_data[0, np_mask] = 5 @@ -1310,7 +1310,7 @@ def test_boolean_index_autograd(): @use_np def test_np_get_dtype(): - dtypes = [_np.int8, _np.int32, _np.float16, _np.float32, _np.float64, _np.bool, _np.bool_, + dtypes = [_np.int8, _np.int32, _np.float16, _np.float32, _np.float64, bool, _np.bool_, 'int8', 'int32', 'float16', 'float32', 'float64', 'bool', None] objects = [ [], diff --git a/tests/python/unittest/test_numpy_op.py b/tests/python/unittest/test_numpy_op.py index 1fcef46660d6..4619fa939f08 100644 --- a/tests/python/unittest/test_numpy_op.py +++ b/tests/python/unittest/test_numpy_op.py @@ -763,7 +763,7 @@ def is_int(dtype): @pytest.mark.parametrize('axis', [True, False]) @pytest.mark.parametrize('hybridize', [True, False]) @pytest.mark.parametrize('keepdim', [True, False]) -@pytest.mark.parametrize('dtype', [np.int8, np.uint8, np.int32, np.int64, np.float16, np.float32, np.float64, np.bool]) +@pytest.mark.parametrize('dtype', [np.int8, np.uint8, np.int32, np.int64, np.float16, np.float32, np.float64, bool]) def test_np_bool_agg(bool_agg, shape, axis, keepdim, dtype, hybridize): class TestOp(HybridBlock): def __init__(self, axis=None, keepdims=False) : @@ -2090,11 +2090,11 @@ def forward(self, a, mask, value): test_data = np.random.uniform(size=dshape) valid_num = 0 while valid_num == 0: - mx_mask = np.random.choice(np.array([False, True], dtype=np.bool), size=mshape) + mx_mask = np.random.choice(np.array([False, True], dtype=bool), size=mshape) if test_data.size == 0: break valid_num = int(mx_mask.asnumpy().sum()) - np_mask = mx_mask.asnumpy().astype(onp.bool) + np_mask = mx_mask.asnumpy().astype(bool) vshape = [] vshape_broadcast = [] for i in range(len(dshape)): @@ -3263,7 +3263,7 @@ def forward(self, a, b, *args, **kwargs): @use_np def test_np_mixed_precision_binary_funcs(): - itypes = [np.bool, np.int8, np.int32, np.int64] + itypes = [bool, np.int8, np.int32, np.int64] ftypes = [np.float16, np.float32, np.float64] def check_mixed_precision_binary_func(func, low, high, lshape, rshape, lgrad, rgrad, ltype, rtype): class TestMixedBinary(HybridBlock): @@ -3371,7 +3371,7 @@ def forward(self, a, b, *args, **kwargs): ((2, 3), ()), ((), (2, 3))] - itypes = [np.bool, np.int8, np.int32, np.int64] + itypes = [bool, np.int8, np.int32, np.int64] ftypes = [np.float16, np.float32, np.float64] for func, func_data in funcs.items(): low, high, lgrad, rgrad = func_data @@ -4101,7 +4101,7 @@ def get_new_shape(shape, axis): hybridizes = [True, False] axes = [0, 1, -1, None] grad_reqs = ['write', 'add', 'null'] - dtypes = [np.float32, np.float64, np.bool] + dtypes = [np.float32, np.float64, bool] combinations = itertools.product(shapes, hybridizes, axes, grad_reqs, dtypes) for shape, hybridize, axis, grad_req, dtype in combinations: @@ -5587,7 +5587,7 @@ def forward(self, a): for shape in shapes: for axis in [None] + [i for i in range(0, len(shape))]: for otype in [None, onp.int32, onp.int64]: - for itype in [onp.bool, onp.int8, onp.int32, onp.int64]: + for itype in [bool, onp.int8, onp.int32, onp.int64]: x = rand_ndarray(shape).astype(itype).as_np_ndarray() np_out = onp.cumsum(x.asnumpy(), axis=axis, dtype=otype) mx_out = np.cumsum(x, axis=axis, dtype=otype) @@ -9212,14 +9212,14 @@ def test_np_true_divide(): [(2, 3, 1), (1, 4)], [(2, 1, 4, 1), (3, 1, 5)], ] - dtypes = [np.bool, np.int8, np.uint8, np.int32, np.int64, np.float16, np.float32, np.float64] - itypes = [np.bool, np.int8, np.uint8, np.int32, np.int64] + dtypes = [bool, np.int8, np.uint8, np.int32, np.int64, np.float16, np.float32, np.float64] + itypes = [bool, np.int8, np.uint8, np.int32, np.int64] ftypes = [np.float16, np.float32, np.float64] for shape_pair, dtype in itertools.product(shapes, dtypes): a = np.random.uniform(3, 50, size=shape_pair[0]).astype(dtype) b = np.random.uniform(3, 50, size=shape_pair[-1]).astype(dtype) out_mx = a / b - if onp.issubdtype(dtype, onp.integer) or (dtype is np.bool): + if onp.issubdtype(dtype, onp.integer) or (dtype is bool): assert out_mx.dtype == np.float32 else: assert out_mx.dtype == dtype @@ -10104,8 +10104,8 @@ def forward(self, a): # test imperative mx_out_imperative = getattr(mx.np, func)(mx_data) assert_almost_equal(mx_out_imperative.asnumpy(), np_out, rtol, atol) - # if `out` is given and dtype == np.bool - mx_x = np.ones_like(mx_data).astype(np.bool) + # if `out` is given and dtype == bool + mx_x = np.ones_like(mx_data).astype(bool) np_x = mx_x.asnumpy() getattr(mx.np, func)(mx_data, mx_x) np_func(np_data, np_x) @@ -10224,7 +10224,7 @@ def __init__(self): def forward(self, cond, x, y): return np.where(cond, x, y) - dtypes = [np.int8, np.uint8, np.int32, np.int64, np.float16, np.float32, np.float64, np.bool] + dtypes = [np.int8, np.uint8, np.int32, np.int64, np.float16, np.float32, np.float64, bool] shape_configs = [ [(), (2, 3), (4, 1, 3)], [(), (4, 1, 3), (2, 3)], @@ -10305,7 +10305,7 @@ def __init__(self, axis): def forward(self, x): return np.expand_dims(x, self._axis) - dtypes = [np.int8, np.uint8, np.int32, np.int64, np.float16, np.float32, np.float64, np.bool] + dtypes = [np.int8, np.uint8, np.int32, np.int64, np.float16, np.float32, np.float64, bool] shapes = [ (), (0,), diff --git a/tests/python/unittest/test_operator.py b/tests/python/unittest/test_operator.py index a27efbe55b07..cf611d2b23bd 100644 --- a/tests/python/unittest/test_operator.py +++ b/tests/python/unittest/test_operator.py @@ -5075,7 +5075,7 @@ def test_masked_softmax(dtype, axis, ndims, n_broadcast_axis, temperature, norma np_data = mx_data.asnumpy() np_mask = np.random.randint(0, 2, shape_mask) - mx_mask = mx.nd.array(np_mask, dtype=np.bool) + mx_mask = mx.nd.array(np_mask, dtype=bool) mx_grad = rand_ndarray(shape, dtype=dtype) np_grad = mx_grad.asnumpy() @@ -5094,7 +5094,7 @@ def test_masked_softmax(dtype, axis, ndims, n_broadcast_axis, temperature, norma check_symbolic_forward(mx_sym, location, [np_out], rtol=rtol, atol=atol, dtype="asnumpy", equal_nan=True) check_symbolic_backward(mx_sym, location, [mx_grad], - [np_grad_out, np.zeros(shape, dtype=np.bool)], + [np_grad_out, np.zeros(shape, dtype=bool)], rtol=1e-2, atol=2e-3 if dtype == np.float16 else 1e-3, dtype="asnumpy", equal_nan=True) @@ -5107,7 +5107,7 @@ def test_masked_log_softmax(dtype, ndims): mx_data = rand_ndarray(shape, dtype=dtype) np_data = mx_data.asnumpy() np_mask = np.random.randint(0, 2, shape) - mx_mask = mx.nd.array(np_mask, dtype=np.bool) + mx_mask = mx.nd.array(np_mask, dtype=bool) mx_grad = rand_ndarray(shape, dtype=dtype) np_grad = mx_grad.asnumpy() np_out = np.log(np_masked_softmax(np_data, np_mask, axis)+1e-20) * np_mask @@ -5121,7 +5121,7 @@ def test_masked_log_softmax(dtype, ndims): atol = 1e-4 if dtype == np.float16 else 1e-5 check_symbolic_forward(mx_sym, location, [np_out_inf], rtol=rtol, atol=atol, dtype="asnumpy") check_symbolic_backward(mx_sym, location, [mx_grad], - [np_grad_out, np.zeros(shape, dtype=np.bool)], + [np_grad_out, np.zeros(shape, dtype=bool)], rtol=1e-2, atol=2e-3 if dtype == np.float16 else 1e-3, dtype="asnumpy", equal_nan=True)