Skip to content

Commit 79ceaa7

Browse files
committed
Revert "Numpy Operators: Inner, Outer, vdot (apache#15846)"
This reverts commit 2df3282.
1 parent c915877 commit 79ceaa7

File tree

4 files changed

+11
-651
lines changed

4 files changed

+11
-651
lines changed

python/mxnet/ndarray/numpy/_op.py

Lines changed: 8 additions & 155 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
'linspace', 'expand_dims', 'tile', 'arange', 'split', 'concatenate', 'stack', 'vstack', 'mean',
3636
'maximum', 'minimum', 'swapaxes', 'clip', 'argmax', 'std', 'var', 'indices', 'copysign',
3737
'ravel', 'hanning', 'hamming', 'blackman', 'flip', 'around', 'hypot', 'rad2deg', 'deg2rad',
38-
'unique', 'lcm', 'tril', 'identity', 'take', 'ldexp', 'vdot', 'inner', 'outer',
38+
'unique', 'lcm', 'tril', 'identity', 'take', 'ldexp',
3939
'equal', 'not_equal', 'greater', 'less', 'greater_equal', 'less_equal']
4040

4141

@@ -1904,7 +1904,7 @@ def tan(x, out=None, where=True, **kwargs):
19041904
19051905
Parameters:
19061906
----------
1907-
x : ndarray
1907+
x : array_like
19081908
Input array.
19091909
out : ndarray, None, or tuple of ndarray and None, optional
19101910
A location into which the result is stored. If provided,
@@ -2324,7 +2324,7 @@ def concatenate(seq, axis=0, out=None):
23242324
"""Join a sequence of arrays along an existing axis.
23252325
Parameters
23262326
----------
2327-
a1, a2, ... : sequence of ndarray
2327+
a1, a2, ... : sequence of array_like
23282328
The arrays must have the same shape, except in the dimension
23292329
corresponding to `axis` (the first, by default).
23302330
axis : int, optional
@@ -2349,7 +2349,7 @@ def stack(arrays, axis=0, out=None):
23492349
For example, if `axis=0` it will be the first dimension and if `axis=-1` it will be the last dimension.
23502350
Parameters
23512351
----------
2352-
arrays : sequence of ndarray
2352+
arrays : sequence of array_like
23532353
Each array must have the same shape.
23542354
axis : int, optional
23552355
The axis in the result array along which the input arrays are stacked.
@@ -2511,7 +2511,7 @@ def clip(a, a_min, a_max, out=None):
25112511
25122512
Notes
25132513
-----
2514-
ndarray `a_min` and `a_max` are not supported.
2514+
array_like `a_min` and `a_max` are not supported.
25152515
25162516
Examples
25172517
--------
@@ -2670,7 +2670,7 @@ def std(a, axis=None, dtype=None, out=None, ddof=0, keepdims=False): # pylint:
26702670
26712671
Parameters
26722672
----------
2673-
a : ndarray
2673+
a : array_like
26742674
Calculate the standard deviation of these values.
26752675
axis : None or int or tuple of ints, optional
26762676
Axis or axes along which the standard deviation is computed. The
@@ -2737,7 +2737,7 @@ def var(a, axis=None, dtype=None, out=None, ddof=0, keepdims=False): # pylint:
27372737
27382738
Parameters
27392739
----------
2740-
a : ndarray
2740+
a : array_like
27412741
Array containing numbers whose variance is desired. If `a` is not an
27422742
array, a conversion is attempted.
27432743
axis : None or int or tuple of ints, optional
@@ -3431,7 +3431,7 @@ def hypot(x1, x2, out=None):
34313431
34323432
Parameters
34333433
----------
3434-
x1, x2 : ndarray
3434+
x1, x2 : array_like
34353435
Leg of the triangle(s).
34363436
out : ndarray, None, or tuple of ndarray and None, optional
34373437
A location into which the result is stored. If provided, it must have
@@ -3505,153 +3505,6 @@ def ldexp(x1, x2, out=None):
35053505
return _ufunc_helper(x1, x2, _npi.ldexp, _np.ldexp, _npi.ldexp_scalar, _npi.rldexp_scalar, out)
35063506

35073507

3508-
@set_module('mxnet.ndarray.numpy')
3509-
def inner(a, b):
3510-
r"""
3511-
Inner product of two arrays.
3512-
Ordinary inner product of vectors for 1-D arrays (without complex
3513-
conjugation), in higher dimensions a sum product over the last axes.
3514-
3515-
Parameters
3516-
----------
3517-
a, b : ndarray
3518-
If `a` and `b` are nonscalar, their last dimensions must match.
3519-
3520-
Returns
3521-
-------
3522-
out : ndarray
3523-
`out.shape = a.shape[:-1] + b.shape[:-1]`
3524-
3525-
Raises
3526-
------
3527-
ValueError
3528-
If the last dimension of `a` and `b` has different size.
3529-
3530-
See Also
3531-
--------
3532-
tensordot : Sum products over arbitrary axes.
3533-
dot : Generalised matrix product, using second last dimension of `b`.
3534-
einsum : Einstein summation convention.
3535-
3536-
Notes
3537-
-----
3538-
For vectors (1-D arrays) it computes the ordinary inner-product::
3539-
np.inner(a, b) = sum(a[:]*b[:])
3540-
More generally, if `ndim(a) = r > 0` and `ndim(b) = s > 0`::
3541-
np.inner(a, b) = np.tensordot(a, b, axes=(-1,-1))
3542-
or explicitly::
3543-
np.inner(a, b)[i0,...,ir-1,j0,...,js-1]
3544-
= sum(a[i0,...,ir-1,:]*b[j0,...,js-1,:])
3545-
In addition `a` or `b` may be scalars, in which case::
3546-
np.inner(a,b) = a*b
3547-
3548-
Examples
3549-
--------
3550-
Ordinary inner product for vectors:
3551-
>>> a = np.array([1,2,3])
3552-
>>> b = np.array([0,1,0])
3553-
>>> np.inner(a, b)
3554-
2
3555-
A multidimensional example:
3556-
>>> a = np.arange(24).reshape((2,3,4))
3557-
>>> b = np.arange(4)
3558-
>>> np.inner(a, b)
3559-
array([[ 14, 38, 62],
3560-
[ 86, 110, 134]])
3561-
"""
3562-
return tensordot(a, b, [-1, -1])
3563-
3564-
3565-
@set_module('mxnet.ndarray.numpy')
3566-
def outer(a, b):
3567-
r"""
3568-
Compute the outer product of two vectors.
3569-
Given two vectors, ``a = [a0, a1, ..., aM]`` and
3570-
``b = [b0, b1, ..., bN]``,
3571-
the outer product [1]_ is::
3572-
[[a0*b0 a0*b1 ... a0*bN ]
3573-
[a1*b0 .
3574-
[ ... .
3575-
[aM*b0 aM*bN ]]
3576-
3577-
Parameters
3578-
----------
3579-
a : (M,) ndarray
3580-
First input vector. Input is flattened if
3581-
not already 1-dimensional.
3582-
b : (N,) ndarray
3583-
Second input vector. Input is flattened if
3584-
not already 1-dimensional.
3585-
3586-
Returns
3587-
-------
3588-
out : (M, N) ndarray
3589-
``out[i, j] = a[i] * b[j]``
3590-
See also
3591-
--------
3592-
inner
3593-
einsum : ``einsum('i,j->ij', a.ravel(), b.ravel())`` is the equivalent.
3594-
ufunc.outer : A generalization to N dimensions and other operations.
3595-
``np.multiply.outer(a.ravel(), b.ravel())`` is the equivalent.
3596-
References
3597-
----------
3598-
.. [1] : G. H. Golub and C. F. Van Loan, *Matrix Computations*, 3rd
3599-
ed., Baltimore, MD, Johns Hopkins University Press, 1996,
3600-
pg. 8.
3601-
Examples
3602-
--------
3603-
Make a (*very* coarse) grid for computing a Mandelbrot set:
3604-
>>> rl = np.outer(np.ones((5,)), np.linspace(-2, 2, 5))
3605-
>>> rl
3606-
array([[-2., -1., 0., 1., 2.],
3607-
[-2., -1., 0., 1., 2.],
3608-
[-2., -1., 0., 1., 2.],
3609-
[-2., -1., 0., 1., 2.],
3610-
[-2., -1., 0., 1., 2.]])
3611-
"""
3612-
return tensordot(a.flatten(), b.flatten(), 0)
3613-
3614-
3615-
@set_module('mxnet.ndarray.numpy')
3616-
def vdot(a, b):
3617-
r"""
3618-
Return the dot product of two vectors.
3619-
Note that `vdot` handles multidimensional arrays differently than `dot`:
3620-
it does *not* perform a matrix product, but flattens input arguments
3621-
to 1-D vectors first. Consequently, it should only be used for vectors.
3622-
3623-
Parameters
3624-
----------
3625-
a : ndarray
3626-
First argument to the dot product.
3627-
b : ndarray
3628-
Second argument to the dot product.
3629-
3630-
Returns
3631-
-------
3632-
output : ndarray
3633-
Dot product of `a` and `b`.
3634-
3635-
See Also
3636-
--------
3637-
dot : Return the dot product without using the complex conjugate of the
3638-
first argument.
3639-
3640-
Examples
3641-
--------
3642-
Note that higher-dimensional arrays are flattened!
3643-
>>> a = np.array([[1, 4], [5, 6]])
3644-
>>> b = np.array([[4, 1], [2, 2]])
3645-
>>> np.vdot(a, b)
3646-
30
3647-
>>> np.vdot(b, a)
3648-
30
3649-
>>> 1*4 + 4*1 + 5*2 + 6*2
3650-
30
3651-
"""
3652-
return tensordot(a.flatten(), b.flatten(), 1)
3653-
3654-
36553508
@set_module('mxnet.ndarray.numpy')
36563509
def equal(x1, x2, out=None):
36573510
"""

python/mxnet/numpy/multiarray.py

Lines changed: 1 addition & 148 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
'tensordot', 'linspace', 'expand_dims', 'tile', 'arange', 'split', 'concatenate',
5454
'stack', 'vstack', 'mean', 'maximum', 'minimum', 'swapaxes', 'clip', 'argmax', 'std', 'var', 'indices',
5555
'copysign', 'ravel', 'hanning', 'hamming', 'blackman', 'flip', 'around', 'arctan2', 'hypot',
56-
'rad2deg', 'deg2rad', 'unique', 'lcm', 'tril', 'identity', 'take', 'ldexp', 'vdot', 'inner', 'outer',
56+
'rad2deg', 'deg2rad', 'unique', 'lcm', 'tril', 'identity', 'take', 'ldexp',
5757
'equal', 'not_equal', 'greater', 'less', 'greater_equal', 'less_equal']
5858

5959
# Return code for dispatching indexing function call
@@ -5028,153 +5028,6 @@ def ldexp(x1, x2, out=None):
50285028
return _mx_nd_np.ldexp(x1, x2, out)
50295029

50305030

5031-
@set_module('mxnet.numpy')
5032-
def inner(a, b):
5033-
r"""Inner product of two arrays.
5034-
Ordinary inner product of vectors for 1-D arrays (without complex
5035-
conjugation), in higher dimensions a sum product over the last axes.
5036-
5037-
Parameters
5038-
----------
5039-
a, b : ndarray
5040-
If `a` and `b` are nonscalar, their last dimensions must match.
5041-
5042-
Returns
5043-
-------
5044-
out : ndarray
5045-
`out.shape = a.shape[:-1] + b.shape[:-1]`
5046-
5047-
Raises
5048-
------
5049-
ValueError
5050-
If the last dimension of `a` and `b` has different size.
5051-
5052-
See Also
5053-
--------
5054-
tensordot : Sum products over arbitrary axes.
5055-
dot : Generalised matrix product, using second last dimension of `b`.
5056-
einsum : Einstein summation convention.
5057-
5058-
Notes
5059-
-----
5060-
For vectors (1-D arrays) it computes the ordinary inner-product::
5061-
np.inner(a, b) = sum(a[:]*b[:])
5062-
More generally, if `ndim(a) = r > 0` and `ndim(b) = s > 0`::
5063-
np.inner(a, b) = np.tensordot(a, b, axes=(-1,-1))
5064-
or explicitly::
5065-
np.inner(a, b)[i0,...,ir-1,j0,...,js-1]
5066-
= sum(a[i0,...,ir-1,:]*b[j0,...,js-1,:])
5067-
In addition `a` or `b` may be scalars, in which case::
5068-
np.inner(a,b) = a*b
5069-
5070-
Examples
5071-
--------
5072-
Ordinary inner product for vectors:
5073-
>>> a = np.array([1,2,3])
5074-
>>> b = np.array([0,1,0])
5075-
>>> np.inner(a, b)
5076-
2
5077-
A multidimensional example:
5078-
>>> a = np.arange(24).reshape((2,3,4))
5079-
>>> b = np.arange(4)
5080-
>>> np.inner(a, b)
5081-
array([[ 14, 38, 62],
5082-
[ 86, 110, 134]])
5083-
"""
5084-
return tensordot(a, b, [-1, -1])
5085-
5086-
5087-
@set_module('mxnet.numpy')
5088-
def outer(a, b):
5089-
r"""Compute the outer product of two vectors.
5090-
Given two vectors, ``a = [a0, a1, ..., aM]`` and
5091-
``b = [b0, b1, ..., bN]``,
5092-
the outer product [1]_ is::
5093-
[[a0*b0 a0*b1 ... a0*bN ]
5094-
[a1*b0 .
5095-
[ ... .
5096-
[aM*b0 aM*bN ]]
5097-
5098-
Parameters
5099-
----------
5100-
a : (M,) ndarray
5101-
First input vector. Input is flattened if
5102-
not already 1-dimensional.
5103-
b : (N,) ndarray
5104-
Second input vector. Input is flattened if
5105-
not already 1-dimensional.
5106-
5107-
Returns
5108-
-------
5109-
out : (M, N) ndarray
5110-
``out[i, j] = a[i] * b[j]``
5111-
See also
5112-
--------
5113-
inner
5114-
einsum : ``einsum('i,j->ij', a.ravel(), b.ravel())`` is the equivalent.
5115-
ufunc.outer : A generalization to N dimensions and other operations.
5116-
``np.multiply.outer(a.ravel(), b.ravel())`` is the equivalent.
5117-
5118-
References
5119-
----------
5120-
.. [1] : G. H. Golub and C. F. Van Loan, *Matrix Computations*, 3rd
5121-
ed., Baltimore, MD, Johns Hopkins University Press, 1996,
5122-
pg. 8.
5123-
5124-
Examples
5125-
--------
5126-
Make a (*very* coarse) grid for computing a Mandelbrot set:
5127-
>>> rl = np.outer(np.ones((5,)), np.linspace(-2, 2, 5))
5128-
>>> rl
5129-
array([[-2., -1., 0., 1., 2.],
5130-
[-2., -1., 0., 1., 2.],
5131-
[-2., -1., 0., 1., 2.],
5132-
[-2., -1., 0., 1., 2.],
5133-
[-2., -1., 0., 1., 2.]])
5134-
"""
5135-
return tensordot(a.flatten(), b.flatten(), 0)
5136-
5137-
5138-
@set_module('mxnet.numpy')
5139-
def vdot(a, b):
5140-
r"""
5141-
Return the dot product of two vectors.
5142-
Note that `vdot` handles multidimensional arrays differently than `dot`:
5143-
it does *not* perform a matrix product, but flattens input arguments
5144-
to 1-D vectors first. Consequently, it should only be used for vectors.
5145-
5146-
Parameters
5147-
----------
5148-
a : ndarray
5149-
First argument to the dot product.
5150-
b : ndarray
5151-
Second argument to the dot product.
5152-
5153-
Returns
5154-
-------
5155-
output : ndarray
5156-
Dot product of `a` and `b`.
5157-
5158-
See Also
5159-
--------
5160-
dot : Return the dot product without using the complex conjugate of the
5161-
first argument.
5162-
5163-
Examples
5164-
--------
5165-
Note that higher-dimensional arrays are flattened!
5166-
>>> a = np.array([[1, 4], [5, 6]])
5167-
>>> b = np.array([[4, 1], [2, 2]])
5168-
>>> np.vdot(a, b)
5169-
30
5170-
>>> np.vdot(b, a)
5171-
30
5172-
>>> 1*4 + 4*1 + 5*2 + 6*2
5173-
30
5174-
"""
5175-
return tensordot(a.flatten(), b.flatten(), 1)
5176-
5177-
51785031
@set_module('mxnet.numpy')
51795032
def equal(x1, x2, out=None):
51805033
"""

0 commit comments

Comments
 (0)