Skip to content

Commit 36152fa

Browse files
Implement dpnp.isneginf()
1 parent af601c6 commit 36152fa

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

dpnp/dpnp_iface_logic.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
"isfinite",
6767
"isinf",
6868
"isnan",
69+
"isneginf",
6970
"less",
7071
"less_equal",
7172
"logical_and",
@@ -710,6 +711,70 @@ def isclose(x1, x2, rtol=1e-05, atol=1e-08, equal_nan=False):
710711
)
711712

712713

714+
def isneginf(x, out=None):
715+
"""
716+
Test element-wise for negative infinity, return result as bool array.
717+
718+
For full documentation refer to :obj:`numpy.isneginf`.
719+
720+
Parameters
721+
----------
722+
x : {dpnp.ndarray, usm_ndarray}
723+
Input array.
724+
out : {None, dpnp.ndarray, usm_ndarray}, optional
725+
A location into which the result is stored. If provided, it must have a
726+
shape that the input broadcasts to and a boolean data type.
727+
If not provided or None, a freshly-allocated boolean array is returned
728+
729+
Returns
730+
-------
731+
out : dpnp.ndarray
732+
Boolean array of same shape as ``x``.
733+
734+
See Also
735+
--------
736+
:obj:`dpnp.isinf` : Test element-wise for positive or negative infinity.
737+
:obj:`dpnp.isposinf` : Test element-wise for positive infinity,
738+
return result as bool array.
739+
:obj:`dpnp.isnan` : Test element-wise for NaN and
740+
return result as a boolean array.
741+
:obj:`dpnp.isfinite` : Test element-wise for finiteness.
742+
743+
Examples
744+
--------
745+
>>> import dpnp as np
746+
>>> x = np.array(np.inf)
747+
>>> np.isneginf(-x)
748+
array(True)
749+
>>> np.isneginf(x)
750+
array(False)
751+
752+
>>> x = np.array([-np.inf, 0., np.inf])
753+
>>> np.isneginf(x)
754+
array([ True, False, False])
755+
756+
>>> x = np.array([-np.inf, 0., np.inf])
757+
>>> y = np.zeros(x.shape, dtype='bool')
758+
>>> np.isneginf(x, y)
759+
array([ True, False, False])
760+
>>> y
761+
array([ True, False, False])
762+
763+
"""
764+
765+
is_inf = dpnp.isinf(x)
766+
try:
767+
signbit = dpnp.signbit(x)
768+
except ValueError as e:
769+
dtype = x.dtype
770+
raise TypeError(
771+
f"This operation is not supported for {dtype} values "
772+
"because it would be ambiguous."
773+
) from e
774+
775+
return dpnp.logical_and(is_inf, signbit, out)
776+
777+
713778
_LESS_DOCSTRING = """
714779
Computes the less-than test results for each element `x1_i` of
715780
the input array `x1` with the respective element `x2_i` of the input array `x2`.

0 commit comments

Comments
 (0)