You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by re...@apache.org on 2019/10/19 06:58:26 UTC

[incubator-mxnet] branch numpy_1_6_prs updated (720c161 -> 6166778)

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

reminisce pushed a change to branch numpy_1_6_prs
in repository https://gitbox.apache.org/repos/asf/incubator-mxnet.git.


 discard 720c161  Numpy dispatch test (#16437)
 discard 4dcff08  numpy op doc: max, min, prod (#16506)
     add a75ec06  [Numpy] einsum (#15911)
     new be041d2  numpy op doc: max, min, prod (#16506)
     new 6166778  Numpy dispatch test (#16437)

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (720c161)
            \
             N -- N -- N   refs/heads/numpy_1_6_prs (6166778)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 benchmark/python/einsum/benchmark_einsum.py        |   78 ++
 python/mxnet/ndarray/numpy/_op.py                  |  241 ++++-
 python/mxnet/numpy/multiarray.py                   |  235 ++++-
 python/mxnet/numpy_dispatch_protocol.py            |    3 +-
 python/mxnet/symbol/numpy/_symbol.py               |  129 ++-
 src/operator/mxnet_op.h                            |   36 +
 src/operator/numpy/np_dot-inl.h                    |   16 +-
 src/operator/numpy/np_dot.cc                       |    4 +-
 src/operator/numpy/np_einsum_op-inl.h              | 1092 ++++++++++++++++++++
 src/operator/numpy/np_einsum_op.cc                 |  370 +++++++
 .../numpy/{np_cumsum.cu => np_einsum_op.cu}        |   15 +-
 src/operator/numpy/np_einsum_path_op-inl.h         |  964 +++++++++++++++++
 src/operator/numpy/np_tensordot_op-inl.h           |  120 ++-
 src/operator/numpy/np_tensordot_op.cc              |    8 +-
 .../python/unittest/test_numpy_interoperability.py |   73 ++
 tests/python/unittest/test_numpy_op.py             |  131 +++
 16 files changed, 3478 insertions(+), 37 deletions(-)
 create mode 100644 benchmark/python/einsum/benchmark_einsum.py
 create mode 100644 src/operator/numpy/np_einsum_op-inl.h
 create mode 100644 src/operator/numpy/np_einsum_op.cc
 copy src/operator/numpy/{np_cumsum.cu => np_einsum_op.cu} (72%)
 create mode 100644 src/operator/numpy/np_einsum_path_op-inl.h


[incubator-mxnet] 01/02: numpy op doc: max, min, prod (#16506)

Posted by re...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit be041d276eeb0eea9d496976542d1d22faada73c
Author: alicia <32...@users.noreply.github.com>
AuthorDate: Sat Oct 19 13:16:12 2019 +0800

    numpy op doc: max, min, prod (#16506)
---
 python/mxnet/_numpy_op_doc.py | 213 +++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 211 insertions(+), 2 deletions(-)

diff --git a/python/mxnet/_numpy_op_doc.py b/python/mxnet/_numpy_op_doc.py
index f08d19a..ce8be59 100644
--- a/python/mxnet/_numpy_op_doc.py
+++ b/python/mxnet/_numpy_op_doc.py
@@ -130,8 +130,8 @@ def _npx_nonzero(a):
 
     Notes
     -----
-    This function differs from the original numpy.prod in the following aspects:
-        - Do not support python numeric.
+    This function differs from the original numpy.nonzero in the following aspects:
+        - Does not support python numeric.
         - The return value is same as numpy.transpose(numpy.nonzero(a)).
 
     Examples
@@ -706,6 +706,214 @@ def _np_squeeze(a, axis=None, out=None):
     pass
 
 
+def _np_max(a, axis=None, out=None, keepdims=False):
+    """
+    Return the maximum of an array or maximum along an axis.
+    
+    Parameters
+    ----------
+    a : ndarray
+        Input data.
+    axis : int, optional
+        Axis along which to operate.  By default, flattened input is used.
+    out : ndarray, optional
+        Alternative output array in which to place the result.  Must
+        be of the same shape and buffer length as the expected output.
+        See `doc.ufuncs` (Section "Output arguments") for more details.
+    keepdims : bool, optional
+        If this is set to True, the axes which are reduced are left
+        in the result as dimensions with size one. With this option,
+        the result will broadcast correctly against the original `arr`.
+    
+    Returns
+    -------
+    max : ndarray 
+        Maximum of `a`. If `axis` is None, the result is an array of dimension 1.
+        If `axis` is given, the result is an array of dimension
+        ``a.ndim - 1``.
+    
+    See Also
+    --------
+    min :
+        The minimum value of an array along a given axis, ignoring any nan.
+    maximum :
+        Element-wise maximum of two arrays, ignoring any nan.
+    argmax :
+        Return the indices of the maximum values.
+    
+    Notes
+    -----
+    NaN in the orginal `numpy` is denoted as nan and will be ignored.
+    
+    Don't use `max` for element-wise comparison of 2 arrays; when
+    ``a.shape[0]`` is 2, ``maximum(a[0], a[1])`` is faster than
+    ``max(a, axis=0)``.
+    
+    Examples
+    --------
+    >>> a = np.arange(4).reshape((2,2))
+    >>> a
+    array([[0., 1.],
+        [2., 3.]]) 
+    >>> np.max(a)            # Maximum of the flattened array
+    array(3.)
+    >>> np.max(a, axis=0)    # Maxima along the first axis
+    array([2., 3.])
+    >>> np.max(a, axis=1)    # Maxima along the second axis
+    array([1., 3.])
+    
+    >>> b = np.arange(5, dtype=np.float32)
+    >>> b[2] = np.nan
+    >>> np.max(b)
+    array(4.)
+    """
+    pass
+
+
+def _np_min(a, axis=None, out=None, keepdims=False):
+    """
+    Return the minimum of an array or minimum along an axis.
+    
+    Parameters
+    ----------
+    a : ndarray
+        Input data.
+    axis : int, optional
+        Axis along which to operate.  By default, flattened input is used.
+    out : ndarray, optional
+        Alternative output array in which to place the result.  Must
+        be of the same shape and buffer length as the expected output.
+        See `doc.ufuncs` (Section "Output arguments") for more details.
+    keepdims : bool, optional
+        If this is set to True, the axes which are reduced are left
+        in the result as dimensions with size one. With this option,
+        the result will broadcast correctly against the original `arr`.
+    
+    Returns
+    -------
+    min : ndarray
+        Minimum of `a`. If `axis` is None, the result is an array of dimension 1.
+        If `axis` is given, the result is an array of dimension
+        ``a.ndim - 1``.
+    
+    See Also
+    --------
+    max :
+        The maximum value of an array along a given axis, ignoring any nan.
+    minimum :
+        Element-wise minimum of two arrays, ignoring any nan.
+    
+    Notes
+    -----
+    NaN in the orginal `numpy` is denoted as nan and will be ignored.
+    
+    Don't use `min` for element-wise comparison of 2 arrays; when
+    ``a.shape[0]`` is 2, ``minimum(a[0], a[1])`` is faster than
+    ``min(a, axis=0)``.
+
+    Examples
+    --------
+    >>> a = np.arange(4).reshape((2,2))
+    >>> a
+    array([[0., 1.],
+        [2., 3.]])
+    >>> np.min(a)           # Minimum of the flattened array
+    array(0.)
+    >>> np.min(a, axis=0)   # Minima along the first axis
+    array([0., 1.])
+    >>> np.min(a, axis=1)   # Minima along the second axis
+    array([0., 2.])
+    >>> b = np.arange(5, dtype=np.float32)
+    >>> b[2] = np.nan
+    >>> np.min(b)
+    array(0.) # nan will be ignored
+    """    
+    pass
+
+
+def _np_prod(a, axis=None, dtype=None, out=None, keepdims=False):
+    """
+    Return the product of array elements over a given axis.
+    
+    Parameters
+    ----------
+    a : ndarray
+        Input data.
+    axis : None or int or tuple of ints, optional
+        Axis or axes along which a product is performed.
+        The default (`axis` = `None`) is perform a product over all
+        the dimensions of the input array. `axis` may be negative, in
+        which case it counts from the last to the first axis.
+        If this is a tuple of ints, a product is performed on multiple
+        axes, instead of a single axis or all the axes as before.
+    dtype : data-type, optional
+        The data-type of the returned array, as well as of the accumulator
+        in which the elements are multiplied.  By default, if `a` is of
+        integer type, `dtype` is the default platform integer. (Note: if
+        the type of `a` is unsigned, then so is `dtype`.)  Otherwise,
+        the dtype is the same as that of `a`.
+    out : ndarray, optional
+        Alternative output array in which to place the result. It must have
+        the same shape as the expected output, but the type of the
+        output values will be cast if necessary.
+    keepdims : bool, optional
+        If this is set to True, the axes which are reduced are left
+        in the result as dimensions with size one. With this option,
+        the result will broadcast correctly against the original `arr`.
+    
+    Returns
+    -------
+    product_along_axis : ndarray, see `dtype` parameter above.
+        An array shaped as `a` but with the specified axis removed.
+        Returns a reference to `out` if specified.
+    
+    See Also
+    --------
+    ndarray.prod : equivalent method
+    
+    Notes
+    -----
+    Arithmetic is modular when using integer types, and no error is
+    raised on overflow.  That means that, on a 32-bit platform:
+    
+    >>> x = np.array([536870910, 536870910, 536870910, 536870910])
+    >>> np.prod(x) #random
+    array(8.307675e+34)
+    
+    Examples
+    --------
+    By default, calculate the product of all elements:
+    
+    >>> np.prod(np.array([1.,2.]))
+    array(2.)
+    
+    Even when the input array is two-dimensional:
+    
+    >>> np.prod(np.array([1.,2.,3.,4.]).reshape((2,2)))
+    array(24.)
+    
+    But we can also specify the axis over which to multiply:
+    
+    >>> np.prod(np.array([1.,2.,3.,4.]).reshape((2,2)), axis=1)
+    array([  2.,  12.])
+
+    If the type of `x` is unsigned, then the output type is
+    the unsigned platform integer:
+    
+    >>> x = np.array([1, 2, 3], dtype=np.uint8)
+    >>> np.prod(x).dtype == np.uint8
+    True
+
+    If `x` is of a signed integer type, then the output type
+    is the default platform integer:
+    
+    >>> x = np.array([1, 2, 3], dtype=np.int8)
+    >>> np.prod(x).dtype == np.int8
+    True
+    """
+    pass
+
+
 def _np_moveaxis(a, source, destination):
     """Move axes of an array to new positions.
     Other axes remain in their original order.
@@ -784,6 +992,7 @@ def _np__random_shuffle(x):
     """
     pass
 
+
 def _np_broadcast_to(array, shape, out=None):
     """
     Broadcast an array to a new shape.


[incubator-mxnet] 02/02: Numpy dispatch test (#16437)

Posted by re...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 6166778a587097e9a3ecc2d0e0880bba55f282c3
Author: JiangZhaoh <54...@users.noreply.github.com>
AuthorDate: Sat Oct 19 13:18:10 2019 +0800

    Numpy dispatch test (#16437)
    
    * vstack
    
    * zeros_like
    
    * zeros_like
    
    * vdot
    
    * stack
    
    * less
    
    * less
    
    * less_equal
    
    * greater and greater_equal
    
    * var
    
    * equal and not_equal
    
    * print test
    
    * try to test again
    
    * test without l le g ge e ne
    
    * test again
    
    * remove l le e ne g ge
    
    * remove float16
    
    * final submit
---
 python/mxnet/numpy_dispatch_protocol.py            |  8 ++++
 .../python/unittest/test_numpy_interoperability.py | 46 ++++++++++++++++++++++
 2 files changed, 54 insertions(+)

diff --git a/python/mxnet/numpy_dispatch_protocol.py b/python/mxnet/numpy_dispatch_protocol.py
index a241d26..8fc9e2e 100644
--- a/python/mxnet/numpy_dispatch_protocol.py
+++ b/python/mxnet/numpy_dispatch_protocol.py
@@ -112,6 +112,8 @@ _NUMPY_ARRAY_FUNCTION_LIST = [
     'tile',
     'transpose',
     'var',
+    'vdot',
+    'vstack',
     'zeros_like',
     'meshgrid',
     'outer',
@@ -162,6 +164,10 @@ def _register_array_function():
 # https://docs.scipy.org/doc/numpy/reference/ufuncs.html#available-ufuncs
 _NUMPY_ARRAY_UFUNC_LIST = [
     'add',
+    #'equal',
+    #'not_equal',
+    #'greater',
+    #'greater_equal',
     'subtract',
     'multiply',
     # Uncomment divide when mxnet.numpy.true_divide is added
@@ -173,6 +179,8 @@ _NUMPY_ARRAY_UFUNC_LIST = [
     'rint',
     'sign',
     'exp',
+    #'less',
+    #'less_equal',
     'log',
     'log2',
     'log10',
diff --git a/tests/python/unittest/test_numpy_interoperability.py b/tests/python/unittest/test_numpy_interoperability.py
index f22d42b..50a1507 100644
--- a/tests/python/unittest/test_numpy_interoperability.py
+++ b/tests/python/unittest/test_numpy_interoperability.py
@@ -223,6 +223,13 @@ def _prepare_workloads():
     OpArgMngr.add_workload('split', array_pool['4x1'], 2)
     OpArgMngr.add_workload('squeeze', array_pool['4x1'])
     OpArgMngr.add_workload('stack', [array_pool['4x1']] * 2)
+    OpArgMngr.add_workload('stack', [array_pool['4x1']] * 2, 1)
+    OpArgMngr.add_workload('stack', [array_pool['4x1']] * 2, -1)
+    OpArgMngr.add_workload('stack', [array_pool['4x1']] * 2, -2)
+    OpArgMngr.add_workload('stack', np.random.normal(size=(2, 4, 3)), 2)
+    OpArgMngr.add_workload('stack', np.random.normal(size=(2, 4, 3)), -3)
+    OpArgMngr.add_workload('stack', np.array([[], [], []]), 1)
+    OpArgMngr.add_workload('stack', np.array([[], [], []]))
     OpArgMngr.add_workload('std', array_pool['4x1'])
     OpArgMngr.add_workload('sum', array_pool['4x1'])
     OpArgMngr.add_workload('swapaxes', array_pool['4x1'], 0, 1)
@@ -231,7 +238,24 @@ def _prepare_workloads():
     OpArgMngr.add_workload('tile', np.array([[[]]]), (3, 2, 5))
     OpArgMngr.add_workload('transpose', array_pool['4x1'])
     OpArgMngr.add_workload('var', array_pool['4x1'])
+    OpArgMngr.add_workload('var', np.array([np.float16(1.)]))
+    OpArgMngr.add_workload('var', np.array([1]))
+    OpArgMngr.add_workload('var', np.array([1.]))
+    OpArgMngr.add_workload('var', np.array([[1, 2, 3], [4, 5, 6]]))
+    OpArgMngr.add_workload('var', np.array([[1, 2, 3], [4, 5, 6]]), 0)
+    OpArgMngr.add_workload('var', np.array([[1, 2, 3], [4, 5, 6]]), 1)
+    OpArgMngr.add_workload('var', np.array([np.nan]))
+    OpArgMngr.add_workload('var', np.array([1, -1, 1, -1]))
+    OpArgMngr.add_workload('var', np.array([1,2,3,4], dtype='f8'))
+    OpArgMngr.add_workload('vdot', np.random.normal(size=(2, 4)), np.random.normal(size=(4, 2)))
+    OpArgMngr.add_workload('vdot', np.random.normal(size=(2, 4)).astype(np.float64), np.random.normal(size=(2, 4)).astype(np.float64))
+    OpArgMngr.add_workload('vstack', (array_pool['4x1'], np.random.uniform(size=(5, 1))))
+    OpArgMngr.add_workload('vstack', array_pool['4x1'])
+    OpArgMngr.add_workload('vstack', array_pool['1x1x0'])
     OpArgMngr.add_workload('zeros_like', array_pool['4x1'])
+    OpArgMngr.add_workload('zeros_like', np.random.uniform(size=(3, 3)).astype(np.float64))
+    OpArgMngr.add_workload('zeros_like', np.random.uniform(size=(3, 3)).astype(np.float32))
+    OpArgMngr.add_workload('zeros_like', np.random.randint(2, size = (3, 3)))
     OpArgMngr.add_workload('outer', np.ones((5)), np.ones((2)))
     OpArgMngr.add_workload('meshgrid', np.array([1, 2, 3]))
     OpArgMngr.add_workload('meshgrid', np.array([1, 2, 3]), np.array([4, 5, 6, 7]))
@@ -243,6 +267,20 @@ def _prepare_workloads():
     OpArgMngr.add_workload('add', array_pool['4x1'], 2)
     OpArgMngr.add_workload('add', 2, array_pool['4x1'])
     OpArgMngr.add_workload('add', array_pool['4x1'], array_pool['1x1x0'])
+    """
+    OpArgMngr.add_workload('equal', np.array([0, 1, 2, 4, 2], dtype=np.float16), np.array([-2, 5, 1, 4, 3], dtype=np.float16))
+    OpArgMngr.add_workload('equal', np.array([np.nan]), np.array([np.nan]))
+    OpArgMngr.add_workload('equal', array_pool['4x1'], array_pool['1x2'])
+    OpArgMngr.add_workload('not_equal', np.array([0, 1, 2, 4, 2], dtype=np.float16), np.array([-2, 5, 1, 4, 3], dtype=np.float16))
+    OpArgMngr.add_workload('not_equal', np.array([np.nan]), np.array([np.nan]))
+    OpArgMngr.add_workload('not_equal', array_pool['4x1'], array_pool['1x2'])
+    OpArgMngr.add_workload('greater', np.array([0, 1, 2, 4, 2], dtype=np.float16), np.array([-2, 5, 1, 4, 3], dtype=np.float16))
+    OpArgMngr.add_workload('greater', array_pool['4x1'], array_pool['1x2'])
+    OpArgMngr.add_workload('greater', np.array([np.nan]), np.array([np.nan]))
+    OpArgMngr.add_workload('greater_equal', np.array([0, 1, 2, 4, 2], dtype=np.float16), np.array([-2, 5, 1, 4, 3], dtype=np.float16))
+    OpArgMngr.add_workload('greater_equal', array_pool['4x1'], array_pool['1x2'])
+    OpArgMngr.add_workload('greater_equal', np.array([np.nan]), np.array([np.nan]))
+    """
     OpArgMngr.add_workload('subtract', array_pool['4x1'], array_pool['1x2'])
     OpArgMngr.add_workload('subtract', array_pool['4x1'], 2)
     OpArgMngr.add_workload('subtract', 2, array_pool['4x1'])
@@ -337,6 +375,14 @@ def _prepare_workloads():
     # OpArgMngr.add_workload('sign', np.array(_np.array([_np.nan]))) # failed
 
     OpArgMngr.add_workload('exp', array_pool['4x1'])
+    """
+    OpArgMngr.add_workload('less', np.array([0, 1, 2, 4, 2], dtype=np.float16), np.array([-2, 5, 1, 4, 3], dtype=np.float16))
+    OpArgMngr.add_workload('less', array_pool['4x1'], array_pool['1x2'])
+    OpArgMngr.add_workload('less', np.array([np.nan]), np.array([np.nan]))
+    OpArgMngr.add_workload('less_equal', np.array([0, 1, 2, 4, 2], dtype=np.float16), np.array([-2, 5, 1, 4, 3], dtype=np.float16))
+    OpArgMngr.add_workload('less_equal', array_pool['4x1'], array_pool['1x2'])
+    OpArgMngr.add_workload('less_equal', np.array([np.nan]), np.array([np.nan]))
+    """
     OpArgMngr.add_workload('log', array_pool['4x1'])
     OpArgMngr.add_workload('log2', array_pool['4x1'])
     OpArgMngr.add_workload('log2', np.array(2.**65))