Skip to content
This repository was archived by the owner on Nov 17, 2023. It is now read-only.

Commit cfb474b

Browse files
authored
add alias for np.__version__, np._NoValue and np.dtype (#17777)
1 parent 48e9e2c commit cfb474b

File tree

3 files changed

+42
-4
lines changed

3 files changed

+42
-4
lines changed

python/mxnet/numpy/fallback.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@
2020

2121
import numpy as onp
2222

23+
2324
__all__ = [
25+
'__version__',
26+
'_NoValue',
2427
'allclose',
2528
'alltrue',
2629
'apply_along_axis',
@@ -37,6 +40,7 @@
3740
'cov',
3841
'digitize',
3942
'divmod',
43+
'dtype',
4044
'extract',
4145
'float_power',
4246
'frexp',
@@ -106,6 +110,8 @@
106110
'vander',
107111
]
108112

113+
__version__ = onp.__version__
114+
_NoValue = onp._NoValue
109115
allclose = onp.allclose
110116
alltrue = onp.alltrue
111117
apply_along_axis = onp.apply_along_axis
@@ -122,6 +128,7 @@
122128
cov = onp.cov
123129
digitize = onp.digitize
124130
divmod = onp.divmod
131+
dtype = onp.dtype
125132
extract = onp.extract
126133
float_power = onp.float_power
127134
frexp = onp.frexp

python/mxnet/numpy/multiarray.py

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2241,6 +2241,7 @@ def empty(shape, dtype=_np.float32, order='C', ctx=None): # pylint: disable=red
22412241
return ndarray(handle=_new_alloc_handle(shape, ctx, False, dtype))
22422242

22432243

2244+
# pylint: disable=redefined-outer-name
22442245
@set_module('mxnet.numpy')
22452246
def array(object, dtype=None, ctx=None):
22462247
"""
@@ -2297,6 +2298,7 @@ def array(object, dtype=None, ctx=None):
22972298
else:
22982299
ret[:] = object
22992300
return ret
2301+
# pylint: enable=redefined-outer-name
23002302

23012303

23022304
@set_module('mxnet.numpy')
@@ -2508,6 +2510,7 @@ def full(shape, fill_value, dtype=None, order='C', ctx=None, out=None):
25082510
# pylint: enable=too-many-arguments, redefined-outer-name
25092511

25102512

2513+
# pylint: disable=redefined-outer-name
25112514
@set_module('mxnet.numpy')
25122515
def empty_like(prototype, dtype=None, order='C', subok=False, shape=None): # pylint: disable=W0621
25132516
"""
@@ -2565,8 +2568,10 @@ def empty_like(prototype, dtype=None, order='C', subok=False, shape=None): # pyl
25652568
[2.0e-323, 2.5e-323, 3.0e-323]])
25662569
"""
25672570
return _mx_nd_np.empty_like(prototype, dtype=dtype, order=order, subok=subok, shape=shape)
2571+
# pylint: enable=redefined-outer-name
25682572

25692573

2574+
# pylint: disable=redefined-outer-name
25702575
@set_module('mxnet.numpy')
25712576
def identity(n, dtype=None, ctx=None):
25722577
"""
@@ -2599,6 +2604,7 @@ def identity(n, dtype=None, ctx=None):
25992604
[0., 0., 1.]])
26002605
"""
26012606
return _mx_nd_np.identity(n, dtype, ctx)
2607+
# pylint: enable=redefined-outer-name
26022608

26032609

26042610
# pylint: disable=redefined-outer-name
@@ -5018,6 +5024,7 @@ def histogram(a, bins=10, range=None, normed=None, weights=None, density=None):
50185024
return _mx_nd_np.histogram(a, bins=bins, range=range, normed=normed, weights=weights, density=density)
50195025

50205026

5027+
# pylint: disable=redefined-outer-name
50215028
@set_module('mxnet.numpy')
50225029
def eye(N, M=None, k=0, dtype=_np.float32, **kwargs):
50235030
"""
@@ -5053,8 +5060,10 @@ def eye(N, M=None, k=0, dtype=_np.float32, **kwargs):
50535060
[0., 0., 0.]])
50545061
"""
50555062
return _mx_nd_np.eye(N, M, k, dtype, **kwargs)
5063+
# pylint: enable=redefined-outer-name
50565064

50575065

5066+
# pylint: disable=redefined-outer-name
50585067
@set_module('mxnet.numpy')
50595068
def linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None, axis=0, ctx=None): # pylint: disable=too-many-arguments
50605069
r"""
@@ -5140,9 +5149,10 @@ def linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None, axis
51405149
GPU.
51415150
"""
51425151
return _mx_nd_np.linspace(start, stop, num, endpoint, retstep, dtype, axis, ctx)
5152+
# pylint: enable=redefined-outer-name
51435153

51445154

5145-
# pylint: disable=too-many-arguments
5155+
# pylint: disable=too-many-arguments, redefined-outer-name
51465156
@set_module('mxnet.numpy')
51475157
def logspace(start, stop, num=50, endpoint=True, base=10.0, dtype=None, axis=0, ctx=None):
51485158
r"""Return numbers spaced evenly on a log scale.
@@ -5217,7 +5227,7 @@ def logspace(start, stop, num=50, endpoint=True, base=10.0, dtype=None, axis=0,
52175227
array([ 100. , 215.44347, 464.15887, 1000. ], ctx=gpu(0))
52185228
"""
52195229
return _mx_nd_np.logspace(start, stop, num, endpoint, base, dtype, axis, ctx=ctx)
5220-
# pylint: enable=too-many-arguments
5230+
# pylint: enable=too-many-arguments, redefined-outer-name
52215231

52225232

52235233
@set_module('mxnet.numpy')
@@ -5377,6 +5387,7 @@ def tril(m, k=0):
53775387
return _mx_nd_np.tril(m, k)
53785388

53795389

5390+
# pylint: disable=redefined-outer-name
53805391
@set_module('mxnet.numpy')
53815392
def arange(start, stop=None, step=1, dtype=None, ctx=None):
53825393
"""Return evenly spaced values within a given interval.
@@ -5428,6 +5439,7 @@ def arange(start, stop=None, step=1, dtype=None, ctx=None):
54285439
array([3., 5.])
54295440
"""
54305441
return _mx_nd_np.arange(start, stop, step, dtype, ctx)
5442+
# pylint: enable=redefined-outer-name
54315443

54325444

54335445
@set_module('mxnet.numpy')
@@ -6415,6 +6427,7 @@ def average(a, axis=None, weights=None, returned=False, out=None):
64156427
return _mx_nd_np.average(a, axis=axis, weights=weights, returned=returned, out=out)
64166428

64176429

6430+
# pylint: disable=redefined-outer-name
64186431
@set_module('mxnet.numpy')
64196432
def mean(a, axis=None, dtype=None, out=None, keepdims=False): # pylint: disable=arguments-differ
64206433
"""
@@ -6472,9 +6485,10 @@ def mean(a, axis=None, dtype=None, out=None, keepdims=False): # pylint: disable
64726485
array(0.55)
64736486
"""
64746487
return _npi.mean(a, axis=axis, dtype=dtype, keepdims=keepdims, out=out)
6488+
# pylint: enable=redefined-outer-name
64756489

64766490

6477-
6491+
# pylint: disable=redefined-outer-name
64786492
@set_module('mxnet.numpy')
64796493
def std(a, axis=None, dtype=None, out=None, ddof=0, keepdims=False): # pylint: disable=too-many-arguments
64806494
"""
@@ -6540,6 +6554,7 @@ def std(a, axis=None, dtype=None, out=None, ddof=0, keepdims=False): # pylint:
65406554
array(0.45, dtype=float64)
65416555
"""
65426556
return _npi.std(a, axis=axis, dtype=dtype, ddof=ddof, keepdims=keepdims, out=out)
6557+
# pylint: enable=redefined-outer-name
65436558

65446559

65456560
@set_module('mxnet.numpy')
@@ -6591,6 +6606,7 @@ def delete(arr, obj, axis=None):
65916606
return _mx_nd_np.delete(arr, obj, axis=axis)
65926607

65936608

6609+
# pylint: disable=redefined-outer-name
65946610
@set_module('mxnet.numpy')
65956611
def var(a, axis=None, dtype=None, out=None, ddof=0, keepdims=False): # pylint: disable=too-many-arguments
65966612
"""
@@ -6929,6 +6945,7 @@ def diag_indices_from(arr):
69296945
return _mx_nd_np.diag_indices_from(arr)
69306946

69316947

6948+
# pylint: disable=redefined-outer-name
69326949
@set_module('mxnet.numpy')
69336950
def hanning(M, dtype=_np.float32, ctx=None):
69346951
r"""Return the Hanning window.
@@ -7007,8 +7024,10 @@ def hanning(M, dtype=_np.float32, ctx=None):
70077024
>>> plt.show()
70087025
"""
70097026
return _mx_nd_np.hanning(M, dtype=dtype, ctx=ctx)
7027+
# pylint: enable=redefined-outer-name
70107028

70117029

7030+
# pylint: disable=redefined-outer-name
70127031
@set_module('mxnet.numpy')
70137032
def hamming(M, dtype=_np.float32, ctx=None):
70147033
r"""Return the hamming window.
@@ -7085,8 +7104,10 @@ def hamming(M, dtype=_np.float32, ctx=None):
70857104
>>> plt.show()
70867105
"""
70877106
return _mx_nd_np.hamming(M, dtype=dtype, ctx=ctx)
7107+
# pylint: enable=redefined-outer-name
70887108

70897109

7110+
# pylint: disable=redefined-outer-name
70907111
@set_module('mxnet.numpy')
70917112
def blackman(M, dtype=_np.float32, ctx=None):
70927113
r"""Return the Blackman window.
@@ -7161,6 +7182,7 @@ def blackman(M, dtype=_np.float32, ctx=None):
71617182
>>> plt.show()
71627183
"""
71637184
return _mx_nd_np.blackman(M, dtype=dtype, ctx=ctx)
7185+
# pylint: enable=redefined-outer-name
71647186

71657187

71667188
@set_module('mxnet.numpy')
@@ -8932,6 +8954,7 @@ def resize(a, new_shape):
89328954
return _mx_nd_np.resize(a, new_shape)
89338955

89348956

8957+
# pylint: disable=redefined-outer-name
89358958
@set_module('mxnet.numpy')
89368959
def full_like(a, fill_value, dtype=None, order='C', ctx=None, out=None): # pylint: disable=too-many-arguments
89378960
"""
@@ -8984,8 +9007,10 @@ def full_like(a, fill_value, dtype=None, order='C', ctx=None, out=None): # pylin
89849007
array([0.1, 0.1, 0.1, 0.1, 0.1, 0.1])
89859008
"""
89869009
return _mx_nd_np.full_like(a, fill_value=fill_value, dtype=dtype, order=order, ctx=ctx, out=out)
9010+
# pylint: enable=redefined-outer-name
89879011

89889012

9013+
# pylint: disable=redefined-outer-name
89899014
@set_module('mxnet.numpy')
89909015
def zeros_like(a, dtype=None, order='C', ctx=None, out=None):
89919016
"""
@@ -9040,8 +9065,10 @@ def zeros_like(a, dtype=None, order='C', ctx=None, out=None):
90409065
array([0., 0., 0.], dtype=float64)
90419066
"""
90429067
return _mx_nd_np.full_like(a, fill_value=0, dtype=dtype, order=order, ctx=ctx, out=ctx)
9068+
# pylint: enable=redefined-outer-name
90439069

90449070

9071+
# pylint: disable=redefined-outer-name
90459072
@set_module('mxnet.numpy')
90469073
def ones_like(a, dtype=None, order='C', ctx=None, out=None):
90479074
"""
@@ -9096,6 +9123,7 @@ def ones_like(a, dtype=None, order='C', ctx=None, out=None):
90969123
array([1., 1., 1.], dtype=float64)
90979124
"""
90989125
return _mx_nd_np.full_like(a, fill_value=1, dtype=dtype, order=order, ctx=ctx, out=out)
9126+
# pylint: enable=redefined-outer-name
90999127

91009128

91019129
@set_module('mxnet.numpy')
@@ -9701,6 +9729,7 @@ def pad(x, pad_width=None, mode="constant", **kwargs): # pylint: disable=too-man
97019729
return _mx_nd_np.pad(x, pad_width, mode, **kwargs)
97029730

97039731

9732+
# pylint: disable=redefined-outer-name
97049733
@set_module('mxnet.numpy')
97059734
def cumsum(a, axis=None, dtype=None, out=None):
97069735
"""
@@ -9751,3 +9780,4 @@ def cumsum(a, axis=None, dtype=None, out=None):
97519780
[ 4, 9, 15]])
97529781
"""
97539782
return _mx_nd_np.cumsum(a, axis=axis, dtype=dtype, out=out)
9783+
# pylint: enable=redefined-outer-name

tests/python/unittest/test_numpy_interoperability.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3031,7 +3031,8 @@ def check_interoperability(op_list):
30313031
for name in op_list:
30323032
if name in _TVM_OPS and not is_op_runnable():
30333033
continue
3034-
if name in ['shares_memory', 'may_share_memory', 'empty_like']: # skip list
3034+
if name in ['shares_memory', 'may_share_memory', 'empty_like',
3035+
'__version__', 'dtype', '_NoValue']: # skip list
30353036
continue
30363037
if name in ['full_like', 'zeros_like', 'ones_like'] and \
30373038
StrictVersion(platform.python_version()) < StrictVersion('3.0.0'):

0 commit comments

Comments
 (0)