Skip to content

Commit 8455c10

Browse files
Implement dpnp.isposinf()
1 parent 070286f commit 8455c10

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
@@ -67,6 +67,7 @@
6767
"isinf",
6868
"isnan",
6969
"isneginf",
70+
"isposinf",
7071
"less",
7172
"less_equal",
7273
"logical_and",
@@ -775,6 +776,70 @@ def isneginf(x, out=None):
775776
return dpnp.logical_and(is_inf, signbit, out)
776777

777778

779+
def isposinf(x, out=None):
780+
"""
781+
Test element-wise for positive infinity, return result as bool array.
782+
783+
For full documentation refer to :obj:`numpy.isposinf`.
784+
785+
Parameters
786+
----------
787+
x : {dpnp.ndarray, usm_ndarray}
788+
Input array.
789+
out : {None, dpnp.ndarray, usm_ndarray}, optional
790+
A location into which the result is stored. If provided, it must have a
791+
shape that the input broadcasts to and a boolean data type.
792+
If not provided or None, a freshly-allocated boolean array is returned
793+
794+
Returns
795+
-------
796+
out : dpnp.ndarray
797+
Boolean array of same shape as ``x``.
798+
799+
See Also
800+
--------
801+
:obj:`dpnp.isinf` : Test element-wise for positive or negative infinity.
802+
:obj:`dpnp.isneginf` : Test element-wise for negative infinity,
803+
return result as bool array.
804+
:obj:`dpnp.isnan` : Test element-wise for NaN and
805+
return result as a boolean array.
806+
:obj:`dpnp.isfinite` : Test element-wise for finiteness.
807+
808+
Examples
809+
--------
810+
>>> import dpnp as np
811+
>>> x = np.array(np.inf)
812+
>>> np.isposinf(x)
813+
array(True)
814+
>>> np.isposinf(-x)
815+
array(False)
816+
817+
>>> x = np.array([-np.inf, 0., np.inf])
818+
>>> np.isposinf(x)
819+
array([False, False, True])
820+
821+
>>> x = np.array([-np.inf, 0., np.inf])
822+
>>> y = np.zeros(x.shape, dtype='bool')
823+
>>> np.isposinf(x, y)
824+
array([False, False, True])
825+
>>> y
826+
array([False, False, True])
827+
828+
"""
829+
830+
is_inf = dpnp.isinf(x)
831+
try:
832+
signbit = ~dpnp.signbit(x)
833+
except ValueError as e:
834+
dtype = x.dtype
835+
raise TypeError(
836+
f"This operation is not supported for {dtype} values "
837+
"because it would be ambiguous."
838+
) from e
839+
840+
return dpnp.logical_and(is_inf, signbit, out)
841+
842+
778843
_LESS_DOCSTRING = """
779844
Computes the less-than test results for each element `x1_i` of
780845
the input array `x1` with the respective element `x2_i` of the input array `x2`.

0 commit comments

Comments
 (0)