Beispiel #1
0
def array_equal(a1, a2, equal_nan=False):
    """Returns ``True`` if two arrays are element-wise exactly equal.

    Args:
        a1 (cupy.ndarray): Input array to compare.
        a2 (cupy.ndarray): Input array to compare.
        equal_nan (bool): If ``True``, NaN's in ``a1`` will be considered equal
            to NaN's in ``a2``.

    Returns:
        cupy.ndarray: A boolean 0-dim array.
            If its value is ``True``, two arrays are element-wise equal.

    .. seealso:: :func:`numpy.array_equal`

    """
    if a1.shape != a2.shape:
        return cupy.array(False)
    if not equal_nan:
        return (a1 == a2).all()
    # Handling NaN values if equal_nan is True
    a1nan, a2nan = content.isnan(a1), content.isnan(a2)
    # NaN's occur at different locations
    if not (a1nan == a2nan).all():
        return cupy.array(False)
    # Shapes of a1, a2 and masks are guaranteed to be consistent by this point
    return (a1[~a1nan] == a2[~a1nan]).all()
Beispiel #2
0
def nanmin(a, axis=None, out=None, keepdims=False):
    """Returns the minimum of an array along an axis ignoring NaN.

    When there is a slice whose elements are all NaN, a :class:`RuntimeWarning`
    is raised and NaN is returned.

    Args:
        a (cupy.ndarray): Array to take the minimum.
        axis (int): Along which axis to take the minimum. The flattened array
            is used by default.
        out (cupy.ndarray): Output array.
        keepdims (bool): If ``True``, the axis is remained as an axis of
            size one.

    Returns:
        cupy.ndarray: The minimum of ``a``, along the axis if specified.

    .. warning::

        This function may synchronize the device.

    .. seealso:: :func:`numpy.nanmin`

    """
    # TODO(niboshi): Avoid synchronization.
    res = _core.nanmin(a, axis=axis, out=out, keepdims=keepdims)
    if content.isnan(res).any():  # synchronize!
        warnings.warn('All-NaN slice encountered', RuntimeWarning)
    return res