Skip to content

Commit 34135eb

Browse files
committed
address comments
1 parent d1ed10f commit 34135eb

File tree

7 files changed

+646
-436
lines changed

7 files changed

+646
-436
lines changed

dpnp/dpnp_iface.py

Lines changed: 3 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@
6969
"get_usm_ndarray_or_scalar",
7070
"is_supported_array_or_scalar",
7171
"is_supported_array_type",
72-
"_replace_nan",
7372
]
7473

7574
from dpnp import float64, isscalar
@@ -91,6 +90,8 @@
9190
from dpnp.dpnp_iface_manipulation import __all__ as __all__manipulation
9291
from dpnp.dpnp_iface_mathematical import *
9392
from dpnp.dpnp_iface_mathematical import __all__ as __all__mathematical
93+
from dpnp.dpnp_iface_nanfunctions import *
94+
from dpnp.dpnp_iface_nanfunctions import __all__ as __all__nanfunctions
9495
from dpnp.dpnp_iface_searching import *
9596
from dpnp.dpnp_iface_searching import __all__ as __all__searching
9697
from dpnp.dpnp_iface_sorting import *
@@ -109,6 +110,7 @@
109110
__all__ += __all__logic
110111
__all__ += __all__manipulation
111112
__all__ += __all__mathematical
113+
__all__ += __all__nanfunctions
112114
__all__ += __all__searching
113115
__all__ += __all__sorting
114116
__all__ += __all__statistics
@@ -599,39 +601,3 @@ def is_supported_array_type(a):
599601
"""
600602

601603
return isinstance(a, (dpnp_array, dpt.usm_ndarray))
602-
603-
604-
def _replace_nan(a, val):
605-
"""
606-
If `a` is of inexact type, make a copy of `a`, replace NaNs with
607-
the `val` value, and return the copy together with a boolean mask
608-
marking the locations where NaNs were present. If `a` is not of
609-
inexact type, do nothing and return `a` together with a mask of None.
610-
Note that scalars will end up as array scalars, which is important
611-
for using the result as the value of the out argument in some
612-
operations.
613-
Parameters
614-
----------
615-
a : {dpnp_array, usm_ndarray}
616-
Input array.
617-
val : float
618-
NaN values are set to val before doing the operation.
619-
Returns
620-
-------
621-
out : {dpnp_array}
622-
If `a` is of inexact type, return a copy of `a` with the NaNs
623-
replaced by the fill value, otherwise return `a`.
624-
mask: {bool, None}
625-
If `a` is of inexact type, return a boolean mask marking locations of
626-
NaNs, otherwise return None.
627-
"""
628-
629-
dpnp.check_supported_arrays_type(a)
630-
if issubclass(a.dtype.type, dpnp.inexact):
631-
mask = dpnp.isnan(a)
632-
a = dpnp.array(a, copy=True)
633-
dpnp.copyto(a, val, where=mask)
634-
else:
635-
mask = None
636-
637-
return a, mask

dpnp/dpnp_iface_mathematical.py

Lines changed: 0 additions & 172 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,6 @@
104104
"mod",
105105
"modf",
106106
"multiply",
107-
"nancumprod",
108-
"nancumsum",
109-
"nanprod",
110-
"nansum",
111107
"negative",
112108
"positive",
113109
"power",
@@ -1660,174 +1656,6 @@ def multiply(
16601656
)
16611657

16621658

1663-
def nancumprod(x1, **kwargs):
1664-
"""
1665-
Return the cumulative product of array elements over a given axis treating Not a Numbers (NaNs) as one.
1666-
1667-
For full documentation refer to :obj:`numpy.nancumprod`.
1668-
1669-
Limitations
1670-
-----------
1671-
Parameter `x` is supported as :class:`dpnp.ndarray`.
1672-
Keyword argument `kwargs` is currently unsupported.
1673-
Otherwise the function will be executed sequentially on CPU.
1674-
Input array data types are limited by supported DPNP :ref:`Data types`.
1675-
1676-
.. seealso:: :obj:`dpnp.cumprod` : Return the cumulative product of elements along a given axis.
1677-
1678-
Examples
1679-
--------
1680-
>>> import dpnp as np
1681-
>>> a = np.array([1., np.nan])
1682-
>>> result = np.nancumprod(a)
1683-
>>> [x for x in result]
1684-
[1.0, 1.0]
1685-
>>> b = np.array([[1., 2., np.nan], [4., np.nan, 6.]])
1686-
>>> result = np.nancumprod(b)
1687-
>>> [x for x in result]
1688-
[1.0, 2.0, 2.0, 8.0, 8.0, 48.0]
1689-
1690-
1691-
"""
1692-
1693-
x1_desc = dpnp.get_dpnp_descriptor(x1, copy_when_nondefault_queue=False)
1694-
if x1_desc and not kwargs:
1695-
return dpnp_nancumprod(x1_desc).get_pyobj()
1696-
1697-
return call_origin(numpy.nancumprod, x1, **kwargs)
1698-
1699-
1700-
def nancumsum(x1, **kwargs):
1701-
"""
1702-
Return the cumulative sum of the elements along a given axis.
1703-
1704-
For full documentation refer to :obj:`numpy.nancumsum`.
1705-
1706-
Limitations
1707-
-----------
1708-
Parameter `x` is supported as :class:`dpnp.ndarray`.
1709-
Keyword argument `kwargs` is currently unsupported.
1710-
Otherwise the function will be executed sequentially on CPU.
1711-
Input array data types are limited by supported DPNP :ref:`Data types`.
1712-
1713-
See Also
1714-
--------
1715-
:obj:`dpnp.cumsum` : Return the cumulative sum of the elements along a given axis.
1716-
1717-
Examples
1718-
--------
1719-
>>> import dpnp as np
1720-
>>> a = np.array([1., np.nan])
1721-
>>> result = np.nancumsum(a)
1722-
>>> [x for x in result]
1723-
[1.0, 1.0]
1724-
>>> b = np.array([[1., 2., np.nan], [4., np.nan, 6.]])
1725-
>>> result = np.nancumprod(b)
1726-
>>> [x for x in result]
1727-
[1.0, 3.0, 3.0, 7.0, 7.0, 13.0]
1728-
1729-
"""
1730-
1731-
x1_desc = dpnp.get_dpnp_descriptor(x1, copy_when_nondefault_queue=False)
1732-
if x1_desc and not kwargs:
1733-
return dpnp_nancumsum(x1_desc).get_pyobj()
1734-
1735-
return call_origin(numpy.nancumsum, x1, **kwargs)
1736-
1737-
1738-
def nanprod(
1739-
a,
1740-
axis=None,
1741-
dtype=None,
1742-
out=None,
1743-
keepdims=False,
1744-
initial=None,
1745-
where=True,
1746-
):
1747-
"""
1748-
Return the product of array elements over a given axis treating Not a Numbers (NaNs) as ones.
1749-
1750-
For full documentation refer to :obj:`numpy.nanprod`.
1751-
1752-
Returns
1753-
-------
1754-
out : dpnp.ndarray
1755-
A new array holding the result is returned unless `out` is specified, in which case it is returned.
1756-
1757-
See Also
1758-
--------
1759-
:obj:`dpnp.prod` : Returns product across array propagating NaNs.
1760-
:obj:`dpnp.isnan` : Test element-wise for NaN and return result as a boolean array.
1761-
1762-
Limitations
1763-
-----------
1764-
Input array is only supported as either :class:`dpnp.ndarray` or :class:`dpctl.tensor.usm_ndarray`.
1765-
Parameters `initial`, and `where` are only supported with their default values.
1766-
Otherwise the function will be executed sequentially on CPU.
1767-
Input array data types are limited by supported DPNP :ref:`Data types`.
1768-
1769-
Examples
1770-
--------
1771-
>>> import dpnp as np
1772-
>>> np.nanprod(np.array(1))
1773-
array(1)
1774-
>>> np.nanprod(np.array([1]))
1775-
array(1)
1776-
>>> np.nanprod(np.array([1, np.nan]))
1777-
array(1.0)
1778-
>>> a = np.array([[1, 2], [3, np.nan]])
1779-
>>> np.nanprod(a)
1780-
array(6.0)
1781-
>>> np.nanprod(a, axis=0)
1782-
array([3., 2.])
1783-
1784-
"""
1785-
1786-
a, mask = dpnp._replace_nan(a, 1)
1787-
1788-
return dpnp.prod(
1789-
a,
1790-
axis=axis,
1791-
dtype=dtype,
1792-
out=out,
1793-
keepdims=keepdims,
1794-
initial=initial,
1795-
where=where,
1796-
)
1797-
1798-
1799-
def nansum(x1, **kwargs):
1800-
"""
1801-
Calculate sum() function treating 'Not a Numbers' (NaN) as zero.
1802-
1803-
For full documentation refer to :obj:`numpy.nansum`.
1804-
1805-
Limitations
1806-
-----------
1807-
Parameter `x1` is supported as :class:`dpnp.ndarray`.
1808-
Keyword argument `kwargs` is currently unsupported.
1809-
Otherwise the function will be executed sequentially on CPU.
1810-
Input array data types are limited by supported DPNP :ref:`Data types`.
1811-
1812-
Examples
1813-
--------
1814-
>>> import dpnp as np
1815-
>>> np.nansum(np.array([1, 2]))
1816-
3
1817-
>>> np.nansum(np.array([[1, 2], [3, 4]]))
1818-
10
1819-
1820-
"""
1821-
1822-
x1_desc = dpnp.get_dpnp_descriptor(x1, copy_when_nondefault_queue=False)
1823-
if x1_desc and not kwargs:
1824-
result_obj = dpnp_nansum(x1_desc).get_pyobj()
1825-
result = dpnp.convert_single_elem_array_to_scalar(result_obj)
1826-
return result
1827-
1828-
return call_origin(numpy.nansum, x1, **kwargs)
1829-
1830-
18311659
def negative(
18321660
x,
18331661
/,

0 commit comments

Comments
 (0)