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

Commit c742ef1

Browse files
gyshihaojin2
authored andcommitted
add numpy operator remainder (#16080)
1 parent 07b4470 commit c742ef1

File tree

3 files changed

+60
-5
lines changed

3 files changed

+60
-5
lines changed

python/mxnet/ndarray/numpy/_op.py

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
from . import _internal as _npi
2828
from ..ndarray import NDArray
2929

30-
__all__ = ['zeros', 'ones', 'full', 'add', 'subtract', 'multiply', 'divide', 'mod', 'power', 'sin',
31-
'cos', 'tan', 'sinh', 'cosh', 'tanh', 'log10', 'sqrt', 'cbrt', 'abs', 'absolute',
30+
__all__ = ['zeros', 'ones', 'full', 'add', 'subtract', 'multiply', 'divide', 'mod', 'remainder', 'power',
31+
'sin', 'cos', 'tan', 'sinh', 'cosh', 'tanh', 'log10', 'sqrt', 'cbrt', 'abs', 'absolute',
3232
'exp', 'expm1', 'arcsin', 'arccos', 'arctan', 'sign', 'log', 'degrees', 'log2', 'log1p',
3333
'rint', 'radians', 'reciprocal', 'square', 'negative', 'fix', 'ceil', 'floor',
3434
'trunc', 'logical_not', 'arcsinh', 'arccosh', 'arctanh', 'tensordot',
@@ -384,6 +384,31 @@ def mod(x1, x2, out=None):
384384
return _ufunc_helper(x1, x2, _npi.mod, _np.mod, _npi.mod_scalar, _npi.rmod_scalar, out)
385385

386386

387+
@set_module('mxnet.ndarray.numpy')
388+
def remainder(x1, x2, out=None):
389+
"""Return element-wise remainder of division.
390+
391+
Parameters
392+
----------
393+
x1 : ndarray or scalar
394+
Dividend array.
395+
396+
x2 : ndarray or scalar
397+
Divisor array.
398+
399+
out : ndarray
400+
A location into which the result is stored. If provided, it must have a shape
401+
that the inputs broadcast to. If not provided or None, a freshly-allocated array
402+
is returned.
403+
404+
Returns
405+
-------
406+
out : ndarray or scalar
407+
This is a scalar if both x1 and x2 are scalars.
408+
"""
409+
return _ufunc_helper(x1, x2, _npi.mod, _np.mod, _npi.mod_scalar, _npi.rmod_scalar, out)
410+
411+
387412
@set_module('mxnet.ndarray.numpy')
388413
def power(x1, x2, out=None):
389414
"""First array elements raised to powers from second array, element-wise.

python/mxnet/numpy/multiarray.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
from ..ndarray.numpy import _internal as _npi
4848

4949
__all__ = ['ndarray', 'empty', 'array', 'zeros', 'ones', 'full', 'add', 'subtract', 'multiply', 'divide',
50-
'mod', 'power', 'sin', 'cos', 'tan', 'sinh', 'cosh', 'tanh', 'log10', 'sqrt', 'cbrt',
50+
'mod', 'remainder', 'power', 'sin', 'cos', 'tan', 'sinh', 'cosh', 'tanh', 'log10', 'sqrt', 'cbrt',
5151
'abs', 'absolute', 'exp', 'expm1', 'arcsin', 'arccos', 'arctan', 'sign', 'log',
5252
'degrees', 'log2', 'log1p', 'rint', 'radians', 'reciprocal', 'square', 'negative',
5353
'fix', 'ceil', 'floor', 'trunc', 'logical_not', 'arcsinh', 'arccosh', 'arctanh',
@@ -1855,6 +1855,31 @@ def mod(x1, x2, out=None):
18551855
return _mx_nd_np.mod(x1, x2, out=out)
18561856

18571857

1858+
@set_module('mxnet.numpy')
1859+
def remainder(x1, x2, out=None):
1860+
"""Return element-wise remainder of division.
1861+
1862+
Parameters
1863+
----------
1864+
x1 : ndarray or scalar
1865+
Dividend array.
1866+
1867+
x2 : ndarray or scalar
1868+
Divisor array.
1869+
1870+
out : ndarray
1871+
A location into which the result is stored. If provided, it must have a shape
1872+
that the inputs broadcast to. If not provided or None, a freshly-allocated array
1873+
is returned.
1874+
1875+
Returns
1876+
-------
1877+
out : ndarray or scalar
1878+
This is a scalar if both x1 and x2 are scalars.
1879+
"""
1880+
return _mx_nd_np.remainder(x1, x2, out=out)
1881+
1882+
18581883
@set_module('mxnet.numpy')
18591884
def power(x1, x2, out=None):
18601885
"""First array elements raised to powers from second array, element-wise.

python/mxnet/symbol/numpy/_symbol.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
from .._internal import _set_np_symbol_class
3030
from . import _internal as _npi
3131

32-
__all__ = ['zeros', 'ones', 'add', 'subtract', 'multiply', 'divide', 'mod', 'power', 'sin', 'cos',
33-
'tan', 'sinh', 'cosh', 'tanh', 'log10', 'sqrt', 'cbrt', 'abs', 'absolute', 'exp',
32+
__all__ = ['zeros', 'ones', 'add', 'subtract', 'multiply', 'divide', 'mod', 'remainder', 'power', 'sin',
33+
'cos', 'tan', 'sinh', 'cosh', 'tanh', 'log10', 'sqrt', 'cbrt', 'abs', 'absolute', 'exp',
3434
'expm1', 'arcsin', 'arccos', 'arctan', 'sign', 'log', 'degrees', 'log2', 'log1p',
3535
'rint', 'radians', 'reciprocal', 'square', 'negative', 'fix', 'ceil', 'floor',
3636
'trunc', 'logical_not', 'arcsinh', 'arccosh', 'arctanh', 'tensordot',
@@ -1071,6 +1071,11 @@ def mod(x1, x2, out=None):
10711071
return _ufunc_helper(x1, x2, _npi.mod, _np.mod, _npi.mod_scalar, _npi.rmod_scalar, out)
10721072

10731073

1074+
@set_module('mxnet.symbol.numpy')
1075+
def remainder(x1, x2, out=None):
1076+
return _ufunc_helper(x1, x2, _npi.mod, _np.mod, _npi.mod_scalar, _npi.rmod_scalar, out)
1077+
1078+
10741079
@set_module('mxnet.symbol.numpy')
10751080
def power(x1, x2, out=None):
10761081
return _ufunc_helper(x1, x2, _npi.power, _np.power, _npi.power_scalar, _npi.rpower_scalar, out)

0 commit comments

Comments
 (0)