from cupy import _core

import cupy


def _create_float_test_ufunc(name, doc):
    return _core.create_ufunc(
        'cupy_' + name,
        ('e->?', 'f->?', 'd->?', 'F->?', 'D->?',
         ), 'out0 = %s(in0)' % name,
        doc=doc)


isfinite = _create_float_test_ufunc(
    'isfinite',
    '''Tests finiteness elementwise.

    Each element of returned array is ``True`` only if the corresponding
    element of the input is finite (i.e. not an infinity nor NaN).

    .. seealso:: :data:`numpy.isfinite`

    ''')


isinf = _create_float_test_ufunc(
    'isinf',
    '''Tests if each element is the positive or negative infinity.

    .. seealso:: :data:`numpy.isinf`

    ''')


isnan = _create_float_test_ufunc(
    'isnan',
    '''Tests if each element is a NaN.

    .. seealso:: :data:`numpy.isnan`

    ''')


def isneginf(x, out=None):
    """Test element-wise for negative infinity, return result as bool array.

    Parameters
    ----------
    x : cupy.ndarray)
        Input array.

    Returns
    -------
    y : cupy.ndarray
        Boolean array of same shape as ``x``.

    Examples
    --------
    >>> cupy.isneginf(0)
    False
    >>> cupy.isneginf([4, -4, cupy.inf, -cupy.inf, cupy.nan])
    [False, False, False, True, False]

    See Also
    --------
    numpy.isneginf

    """

    is_inf = isinf(x)
    try:
        signbit = cupy.signbit(x)
    except TypeError as e:
        dtype = x.dtype
        raise TypeError(f'This operation is not supported for {dtype} values '
                        'because it would be ambiguous.') from e

    # TODO(khushi-411): Use `out` instead of `out=out` (see #6393)
    return cupy.logical_and(is_inf, signbit, out=out)


def isposinf(x, out=None):
    """Test element-wise for positive infinity, return result as bool array.

    Parameters
    ----------
    x : cupy.ndarray
        Input array.

    Returns
    -------
    y : cupy.ndarray
        Boolean array of same shape as ``x``.

    Examples
    --------
    >>> cupy.isposinf(0)
    False
    >>> cupy.isposinf([4, -4, cupy.inf, -cupy.inf, cupy.nan])
    [False, False, True, False, False]

    See Also
    --------
    numpy.isposinf

    """

    is_inf = isinf(x)
    try:
        signbit = ~cupy.signbit(x)
    except TypeError as e:
        dtype = x.dtype
        raise TypeError(f'This operation is not supported for {dtype} values '
                        'because it would be ambiguous.') from e

    # TODO(khushi-411): Use `out` instead of `out=out` (see #6393)
    return cupy.logical_and(is_inf, signbit, out=out)

@@ -971,17 +971,16 @@
 .ndarray
-)
 %0A       
@@ -985,32 +985,274 @@
    Input array.%0A
+    out : cupy.ndarray, optional%0A        A location into which the result is stored. If provided,%0A        it should have a shape that input broadcasts to.%0A        By default, None, a freshly- allocated boolean array,%0A        is returned.%0A    
 %0A    Returns%0A   
@@ -1375,37 +1375,44 @@
 isneginf(0)%0A    
+array(
 False
+)
 %0A    %3E%3E%3E cupy.is
@@ -1418,34 +1418,77 @@
 sneginf(
-%5B4, -4, cupy.inf, 
+-cupy.inf)%0A    array(True)%0A    %3E%3E%3E cupy.isneginf(cupy.array(%5B
 -cupy.in
@@ -1481,32 +1481,36 @@
 rray(%5B-cupy.inf,
+ -4,
  cupy.nan%5D)%0A    
@@ -1498,32 +1498,69 @@
 -4, cupy.nan
-%5D)%0A    %5B
+, 0, 4, cupy.inf%5D))%0A    array(%5B True, False, 
 False, False
@@ -1571,21 +1571,16 @@
 lse,
- True,
  False%5D
+)
 %0A%0A  
@@ -2188,24 +2188,252 @@
 Input array.
+%0A    out : cupy.ndarray%0A        A location into which the result is stored. If provided,%0A        it should have a shape that input broadcasts to.%0A        By default, None, a freshly- allocated boolean array,%0A        is returned.
 %0A%0A    Return
@@ -2569,21 +2569,28 @@
 (0)%0A    
+array(
 False
+)
 %0A    %3E%3E%3E
@@ -2608,26 +2608,68 @@
 inf(
-%5B4, -4, cupy.inf, 
+cupy.inf)%0A    array(True)%0A    %3E%3E%3E cupy.isposinf(cupy.array(%5B
 -cup
@@ -2674,16 +2674,20 @@
 upy.inf,
+ -4,
  cupy.na
@@ -2691,15 +2691,38 @@
 .nan
-%5D)%0A    
+, 0, 4, cupy.inf%5D))%0A    array(
 %5BFal
@@ -2732,19 +2732,20 @@
  False, 
-Tru
+Fals
 e, False
@@ -2751,17 +2751,25 @@
 e, False
-%5D
+,  True%5D)
 %0A%0A    Se

address reviews