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 2018/10/24 22:22:08 UTC

[GitHub] anirudhacharya commented on a change in pull request #12967: [MXNET-1173] Debug operators - isfinite and isinf

anirudhacharya commented on a change in pull request #12967: [MXNET-1173] Debug operators - isfinite and isinf
URL: https://github.com/apache/incubator-mxnet/pull/12967#discussion_r227978989
 
 

 ##########
 File path: python/mxnet/ndarray/contrib.py
 ##########
 @@ -460,3 +461,65 @@ def _to_python_scalar(inputs, type_, name):
         return then_func()
     else:
         return else_func()
+
+def isinf(data, ctx=None):
+    """Checks whether a given NDArray has infinity or not
+
+
+    Parameters
+    ----------
+    input : NDArray
+        An N-D NDArray.
+    ctx : Context
+        Device context of output. Default is current context.
+
+    Returns
+    -------
+    output: NDArray
+        The output NDarray with 1 and 0 indicating whether infinite or not.
+
+    Examples
+    --------
+    >>> data = mx.nd.array([np.inf, -np.inf, np.NINF, -1])
+    >>> output = mx.nd.contrib.isinf(data)
+    >>> output
+    [1. 1. 1. 0.]
+    <NDArray 4 @cpu(0)>
+    """
+    if ctx is None:
+        ctx = current_context()
+    # any(x in data for x in [np.inf, -np.inf])
+    # abs(data) == np.inf > TypeError: bad operand type for abs(): 'NDArray'
+    # [abs(x) == np.inf for x in data] > TypeError: bad operand type for abs(): 'NDArray'
+    return ndarray.NDArray.abs(data) == np.inf
+
+def isfinite(data, ctx=None):
+    """Checks whether a given NDArray has finit value or not
 
 Review comment:
   same comments as above.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on 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