You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2020/03/27 15:51:49 UTC

[GitHub] [incubator-mxnet] Yiyan66 opened a new pull request #17926: [numpy] add op copyto

Yiyan66 opened a new pull request #17926: [numpy] add op copyto
URL: https://github.com/apache/incubator-mxnet/pull/17926
 
 
   ## Description ##
   add op copyto, nanargmin, nanargmax, nanmax, nanmin, nansum, nancumsum
   
   ## Checklist ##
   ### Essentials ###
   Please feel free to remove inapplicable items for your PR.
   - [ ] The PR title starts with [MXNET-$JIRA_ID], where $JIRA_ID refers to the relevant [JIRA issue](https://issues.apache.org/jira/projects/MXNET/issues) created (except PRs with tiny changes)
   - [ ] Changes are complete (i.e. I finished coding on this PR)
   - [ ] All changes have test coverage:
   - Unit tests are added for small changes to verify correctness (e.g. adding a new operator)
   - Nightly tests are added for complicated/long-running ones (e.g. changing distributed kvstore)
   - Build tests will be added for build configuration changes (e.g. adding a new build option with NCCL)
   - [ ] Code is well-documented: 
   - For user-facing API changes, API doc string has been updated. 
   - For new C++ functions in header files, their functionalities and arguments are documented. 
   - For new examples, README.md is added to explain the what the example does, the source of the dataset, expected performance on test set and reference to the original paper if applicable
   - Check the API doc at https://mxnet-ci-doc.s3-accelerate.dualstack.amazonaws.com/PR-$PR_ID/$BUILD_ID/index.html
   - [ ] To the best of my knowledge, examples are either not affected by this change, or have been fixed to be compatible with this change
   
   ### Changes ###
   - [ ] Feature1, tests, (and when applicable, API doc)
   - [ ] Feature2, tests, (and when applicable, API doc)
   
   ## Comments ##
   - If this change is a backward incompatible change, why must this change be made.
   - Interesting edge cases to note here
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] mxnet-bot commented on issue #17926: [numpy] add op copyto

Posted by GitBox <gi...@apache.org>.
mxnet-bot commented on issue #17926: [numpy] add op copyto
URL: https://github.com/apache/incubator-mxnet/pull/17926#issuecomment-605075155
 
 
   Hey @Yiyan66 , Thanks for submitting the PR 
   Once your PR is ready for CI checks, invoke the following commands: 
   - To trigger all jobs: @mxnet-bot run ci [all] 
   - To trigger specific jobs: @mxnet-bot run ci [job1, job2] 
   *** 
   **CI supported jobs**: [miscellaneous, edge, centos-gpu, sanity, unix-gpu, unix-cpu, windows-gpu, website, centos-cpu, clang, windows-cpu]
   *** 
   _Note_: 
    Only following 3 categories can trigger CI :PR Author, MXNet Committer, Jenkins Admin. 
   All CI tests must pass before the PR can be merged. 
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] leezu commented on a change in pull request #17926: [numpy] add op copyto

Posted by GitBox <gi...@apache.org>.
leezu commented on a change in pull request #17926: [numpy] add op copyto
URL: https://github.com/apache/incubator-mxnet/pull/17926#discussion_r399512371
 
 

 ##########
 File path: python/mxnet/symbol/numpy/_symbol.py
 ##########
 @@ -1209,6 +1210,237 @@ def bitwise_not(x, out=None, **kwargs):
     return _unary_func_helper(x, _npi.bitwise_not, _np.bitwise_not, out=out, **kwargs)
 
 
+@set_module('mxnet.symbol.numpy')
+def copyto(dst, src, casting='same_kind', where=True):  # pylint: disable=W0621
+    r"""
+    Copies values from one array to another, broadcasting as necessary.
+
+    Raises a TypeError if the `casting` rule is violated, and if
+    `where` is provided, it selects which elements to copy.
+
+    Parameters
+    ----------
+    dst : ndarray
+        The array into which values are copied.
+    src : ndarray
+        The array from which values are copied.
+    casting : {'no', 'equiv', 'safe', 'same_kind', 'unsafe'}, optional
+        Controls what kind of data casting may occur when copying.
+
+        * 'no' means the data types should not be cast at all.
+        * 'equiv' means only byte-order changes are allowed.
+        * 'safe' means only casts which can preserve values are allowed.
+        * 'same_kind' means only safe casts or casts within a kind,
+            like float64 to float32, are allowed.
+        * 'unsafe' means any data conversions may be done.
+    where : array_like of bool, optional
+        A boolean array which is broadcasted to match the dimensions
+        of `dst`, and selects elements to copy from `src` to `dst`
+        wherever it contains the value True.
+    """
+
+    if not isinstance(src, numeric_types):
+        src.astype(dst.dtype, casting=casting)
+        if not isinstance(where, numeric_types):
+            _npi.copy2(dst, src, where, src=None,
+                       casting=casting, where=None)
+        else:
+            _npi.copy2(dst, src, src=None, casting=casting, where=where)
+    else:
+        if not isinstance(where, numeric_types):
+            _npi.copy2(dst, where, src=src, casting=casting, where=None)
+        else:
+            _npi.copy2(dst, src=src, casting=casting, where=where)
+
+
+@set_module('mxnet.symbol.numpy')
+def nanargmin(a, axis=None):
+    """
+    Return the indices of the minimum values in the specified axis ignoring
+    NaNs. For all-NaN slices ``ValueError`` is raised. Warning: the results
+    cannot be trusted if a slice contains only NaNs and Infs.
+    Parameters
+    ----------
+    a : ndarray
+        Input data.
+    axis : int, optional
+        Axis along which to operate.  By default flattened input is used.
+    Returns
+    -------
+    index_array : ndarray
+        An array of indices or a single index value.
+    See Also
+    --------
+    argmin, nanargmax
+    Examples
+    --------
+    >>> a = np.array([[np.nan, 4], [2, 3]])
+    >>> np.argmin(a)
+    0
+    >>> np.nanargmin(a)
+    2
+    >>> np.nanargmin(a, axis=0)
+    array([1, 1])
+    >>> np.nanargmin(a, axis=1)
+    array([1, 0])
+    """
+    mask = isnan(a)
+    if mask is not None:
+        copyto(a, 2147483647, where=mask)
 
 Review comment:
   2147483647 seems to be correct for int32 dtype. But you're testing for 'float16', 'float32', 'float64'. How is this supposed to work?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] leezu commented on a change in pull request #17926: [numpy] add op copyto

Posted by GitBox <gi...@apache.org>.
leezu commented on a change in pull request #17926: [numpy] add op copyto
URL: https://github.com/apache/incubator-mxnet/pull/17926#discussion_r399515311
 
 

 ##########
 File path: python/mxnet/symbol/numpy/_symbol.py
 ##########
 @@ -1209,6 +1210,237 @@ def bitwise_not(x, out=None, **kwargs):
     return _unary_func_helper(x, _npi.bitwise_not, _np.bitwise_not, out=out, **kwargs)
 
 
+@set_module('mxnet.symbol.numpy')
+def copyto(dst, src, casting='same_kind', where=True):  # pylint: disable=W0621
+    r"""
+    Copies values from one array to another, broadcasting as necessary.
+
+    Raises a TypeError if the `casting` rule is violated, and if
+    `where` is provided, it selects which elements to copy.
+
+    Parameters
+    ----------
+    dst : ndarray
+        The array into which values are copied.
 
 Review comment:
   You're modifying `dst` inplace. How is this expressed in the nnvm graph? 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] haojin2 commented on a change in pull request #17926: [numpy] add op copyto

Posted by GitBox <gi...@apache.org>.
haojin2 commented on a change in pull request #17926: [numpy] add op copyto
URL: https://github.com/apache/incubator-mxnet/pull/17926#discussion_r407881204
 
 

 ##########
 File path: python/mxnet/symbol/numpy/_symbol.py
 ##########
 @@ -1209,6 +1210,237 @@ def bitwise_not(x, out=None, **kwargs):
     return _unary_func_helper(x, _npi.bitwise_not, _np.bitwise_not, out=out, **kwargs)
 
 
+@set_module('mxnet.symbol.numpy')
+def copyto(dst, src, casting='same_kind', where=True):  # pylint: disable=W0621
+    r"""
+    Copies values from one array to another, broadcasting as necessary.
+
+    Raises a TypeError if the `casting` rule is violated, and if
+    `where` is provided, it selects which elements to copy.
+
+    Parameters
+    ----------
+    dst : ndarray
+        The array into which values are copied.
 
 Review comment:
   My guess is that it'll be similar to how the `out` argument is handled in all previous nd operators?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services