Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions dpnp/dpnp_iface.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
"synchronize_array_data",
]

from dpnp import float64, isscalar
from dpnp import float64
from dpnp.dpnp_iface_arraycreation import *
from dpnp.dpnp_iface_arraycreation import __all__ as __all__arraycreation
from dpnp.dpnp_iface_bitwise import *
Expand Down Expand Up @@ -490,7 +490,7 @@ def get_dpnp_descriptor(

# If input object is a scalar, it means it was allocated on host memory.
# We need to copy it to USM memory according to compute follows data.
if isscalar(ext_obj):
if dpnp.isscalar(ext_obj):
ext_obj = array(
ext_obj,
dtype=alloc_dtype,
Expand Down Expand Up @@ -701,7 +701,7 @@ def get_usm_ndarray_or_scalar(a):

"""

return a if isscalar(a) else get_usm_ndarray(a)
return a if dpnp.isscalar(a) else get_usm_ndarray(a)


def is_supported_array_or_scalar(a):
Expand All @@ -723,7 +723,7 @@ def is_supported_array_or_scalar(a):

"""

return isscalar(a) or is_supported_array_type(a)
return dpnp.isscalar(a) or is_supported_array_type(a)


def is_supported_array_type(a):
Expand Down
213 changes: 208 additions & 5 deletions dpnp/dpnp_iface_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,16 @@
"greater",
"greater_equal",
"isclose",
"iscomplex",
"iscomplexobj",
"isfinite",
"isinf",
"isnan",
"isneginf",
"isposinf",
"isreal",
"isrealobj",
"isscalar",
"less",
"less_equal",
"logical_and",
Expand Down Expand Up @@ -233,7 +238,7 @@ def allclose(a, b, rtol=1.0e-5, atol=1.0e-8, **kwargs):

"""

if dpnp.isscalar(a) and dpnp.isscalar(b):
if isscalar(a) and isscalar(b):
# at least one of inputs has to be an array
pass
elif not (
Expand All @@ -244,18 +249,18 @@ def allclose(a, b, rtol=1.0e-5, atol=1.0e-8, **kwargs):
elif kwargs:
pass
else:
if not dpnp.isscalar(rtol):
if not isscalar(rtol):
raise TypeError(
f"An argument `rtol` must be a scalar, but got {rtol}"
)
if not dpnp.isscalar(atol):
if not isscalar(atol):
raise TypeError(
f"An argument `atol` must be a scalar, but got {atol}"
)

if dpnp.isscalar(a):
if isscalar(a):
a = dpnp.full_like(b, fill_value=a)
elif dpnp.isscalar(b):
elif isscalar(b):
b = dpnp.full_like(a, fill_value=b)
elif a.shape != b.shape:
a, b = dpt.broadcast_arrays(a.get_array(), b.get_array())
Expand Down Expand Up @@ -610,6 +615,90 @@ def isclose(x1, x2, rtol=1e-05, atol=1e-08, equal_nan=False):
)


def iscomplex(x):
"""
Returns a bool array, where ``True`` if input element is complex.

What is tested is whether the input has a non-zero imaginary part, not if
the input type is complex.

For full documentation refer to :obj:`numpy.iscomplex`.

Parameters
----------
x : {dpnp.ndarray, usm_ndarray}
Input array.

Returns
-------
out : dpnp.ndarray
Output array.

See Also
--------
:obj:`dpnp.isreal` : Returns a bool array, where ``True`` if input element
is real.
:obj:`dpnp.iscomplexobj` : Return ``True`` if `x` is a complex type or an
array of complex numbers.

Examples
--------
>>> import dpnp as np
>>> a = np.array([1+1j, 1+0j, 4.5, 3, 2, 2j])
>>> np.iscomplex(a)
array([ True, False, False, False, False, True])

"""
dpnp.check_supported_arrays_type(x)
if dpnp.issubdtype(x.dtype, dpnp.complexfloating):
return x.imag != 0
res = dpnp.zeros_like(x, dtype=dpnp.bool)
return res


def iscomplexobj(x):
"""
Check for a complex type or an array of complex numbers.

The type of the input is checked, not the value. Even if the input
has an imaginary part equal to zero, `iscomplexobj` evaluates to ``True``.

For full documentation refer to :obj:`numpy.iscomplexobj`.

Parameters
----------
x : array_like
Input data, in any form that can be converted to an array. This
includes scalars, lists, lists of tuples, tuples, tuples of tuples,
tuples of lists, and ndarrays.

Returns
-------
out : dpnp.ndarray
The return value, ``True`` if `x` is of a complex type or has at least
one complex element.

See Also
--------
:obj:`dpnp.isrealobj` : Return ``True`` if `x` is a not complex type or an
array of complex numbers.
:obj:`dpnp.iscomplex` : Returns a bool array, where ``True`` if input
element is complex.

Examples
--------
>>> import dpnp as np
>>> np.iscomplexobj(1)
False
>>> np.iscomplexobj(1+0j)
True
>>> np.iscomplexobj([3, 1+0j, True])
True

"""
return numpy.iscomplexobj(x)


_ISFINITE_DOCSTRING = """
Test if each element of input array is a finite number.

Expand Down Expand Up @@ -923,6 +1012,120 @@ def isposinf(x, out=None):
return dpnp.logical_and(is_inf, signbit, out=out)


def isreal(x):
"""
Returns a bool array, where ``True`` if input element is real.

If element has complex type with zero imaginary part, the return value
for that element is ``True``.

For full documentation refer to :obj:`numpy.isreal`.

Parameters
----------
x : {dpnp.ndarray, usm_ndarray}
Input array.

Returns
-------
out : : dpnp.ndarray
Boolean array of same shape as `x`.

See Also
--------
:obj:`dpnp.iscomplex` : Returns a bool array, where ``True`` if input
element is complex.
:obj:`dpnp.isrealobj` : Return ``True`` if `x` is not a complex type.

Examples
--------
>>> import dpnp as np
>>> a = np.array([1+1j, 1+0j, 4.5, 3, 2, 2j])
>>> np.isreal(a)
array([False, True, True, True, True, False])

"""
return dpnp.imag(x) == 0


def isrealobj(x):
"""
Return ``True`` if `x` is a not complex type or an array of complex numbers.

The type of the input is checked, not the value. So even if the input
has an imaginary part equal to zero, `isrealobj` evaluates to ``False``
if the data type is complex.

For full documentation refer to :obj:`numpy.isrealobj`.

Parameters
----------
x : array_like
Input data, in any form that can be converted to an array. This
includes scalars, lists, lists of tuples, tuples, tuples of tuples,
tuples of lists, and ndarrays.

Returns
-------
out : dpnp.ndarray
The return value, ``False`` if `x` is of a complex type.

See Also
--------
:obj:`dpnp.iscomplexobj` : Check for a complex type or an array of complex
numbers.
:obj:`dpnp.isreal` : Returns a bool array, where ``True`` if input element
is real.

Examples
--------
>>> import dpnp as np
>>> np.isrealobj(False)
True
>>> np.isrealobj(1)
True
>>> np.isrealobj(1+0j)
False
>>> np.isrealobj([3, 1+0j, True])
False

"""
return not iscomplexobj(x)


def isscalar(element):
"""
Returns ``True`` if the type of `element` is a scalar type.

For full documentation refer to :obj:`numpy.isscalar`.

Parameters
----------
element : any
Input argument, can be of any type and shape.

Returns
-------
out : bool
``True`` if `element` is a scalar type, ``False`` if it is not.

Examples
--------
>>> import dpnp as np
>>> np.isscalar(3.1)
True
>>> np.isscalar(np.array(3.1))
False
>>> np.isscalar([3.1])
False
>>> np.isscalar(False)
True
>>> np.isscalar("dpnp")
True
"""
return numpy.isscalar(element)


_LESS_DOCSTRING = """
Computes the less-than test results for each element `x1_i` of
the input array `x1` with the respective element `x2_i` of the input array `x2`.
Expand Down
11 changes: 0 additions & 11 deletions dpnp/dpnp_iface_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@
"integer",
"intc",
"intp",
"isscalar",
"issubdtype",
"issubsctype",
"is_type_supported",
Expand Down Expand Up @@ -229,16 +228,6 @@ def iinfo(dtype):
return dpt.iinfo(dtype)


def isscalar(obj):
"""
Returns ``True`` if the type of `obj` is a scalar type.

For full documentation refer to :obj:`numpy.isscalar`.

"""
return numpy.isscalar(obj)


def issubdtype(arg1, arg2):
"""
Returns ``True`` if the first argument is a type code lower/equal
Expand Down
Loading