3939
4040import warnings
4141
42- import numpy
43-
4442import dpnp
4543
46- # pylint: disable=no-name-in-module
47- from .dpnp_algo import (
48- dpnp_nancumprod ,
49- )
50- from .dpnp_utils import (
51- call_origin ,
52- )
53-
5444__all__ = [
5545 "nanargmax" ,
5646 "nanargmin" ,
@@ -249,19 +239,40 @@ def nanargmin(a, axis=None, out=None, *, keepdims=False):
249239 return dpnp .argmin (a , axis = axis , out = out , keepdims = keepdims )
250240
251241
252- def nancumprod (x1 , ** kwargs ):
242+ def nancumprod (a , axis = None , dtype = None , out = None ):
253243 """
254244 Return the cumulative product of array elements over a given axis treating
255- Not a Numbers (NaNs) as one.
245+ Not a Numbers (NaNs) as zero. The cumulative product does not change when
246+ NaNs are encountered and leading NaNs are replaced by ones.
256247
257248 For full documentation refer to :obj:`numpy.nancumprod`.
258249
259- Limitations
260- -----------
261- Parameter `x` is supported as :class:`dpnp.ndarray`.
262- Keyword argument `kwargs` is currently unsupported.
263- Otherwise the function will be executed sequentially on CPU.
264- Input array data types are limited by supported DPNP :ref:`Data types`.
250+ Parameters
251+ ----------
252+ a : {dpnp.ndarray, usm_ndarray}
253+ Input array.
254+ axis : {None, int}, optional
255+ Axis along which the cumulative product is computed. The default
256+ (``None``) is to compute the cumulative product over the flattened
257+ array.
258+ dtype : {None, dtype}, optional
259+ Type of the returned array and of the accumulator in which the elements
260+ are summed. If `dtype` is not specified, it defaults to the dtype of
261+ `a`, unless `a` has an integer dtype with a precision less than that of
262+ the default platform integer. In that case, the default platform
263+ integer is used.
264+ out : {None, dpnp.ndarray, usm_ndarray}, optional
265+ Alternative output array in which to place the result. It must have the
266+ same shape and buffer length as the expected output but the type will
267+ be cast if necessary.
268+
269+ Returns
270+ -------
271+ out : dpnp.ndarray
272+ A new array holding the result is returned unless `out` is specified as
273+ :class:`dpnp.ndarray`, in which case a reference to `out` is returned.
274+ The result has the same size as `a`, and the same shape as `a` if `axis`
275+ is not ``None`` or `a` is a 1-d array.
265276
266277 See Also
267278 --------
@@ -271,22 +282,26 @@ def nancumprod(x1, **kwargs):
271282 Examples
272283 --------
273284 >>> import dpnp as np
274- >>> a = np.array([1., np.nan])
275- >>> result = np.nancumprod(a)
276- >>> [x for x in result]
277- [1.0, 1.0]
278- >>> b = np.array([[1., 2., np.nan], [4., np.nan, 6.]])
279- >>> result = np.nancumprod(b)
280- >>> [x for x in result]
281- [1.0, 2.0, 2.0, 8.0, 8.0, 48.0]
285+ >>> np.nancumprod(np.array(1))
286+ array(1)
287+ >>> np.nancumprod(np.array([1]))
288+ array([1])
289+ >>> np.nancumprod(np.array([1, np.nan]))
290+ array([1., 1.])
291+ >>> a = np.array([[1, 2], [3, np.nan]])
292+ >>> np.nancumprod(a)
293+ array([1., 2., 6., 6.])
294+ >>> np.nancumprod(a, axis=0)
295+ array([[1., 2.],
296+ [3., 2.]])
297+ >>> np.nancumprod(a, axis=1)
298+ array([[1., 2.],
299+ [3., 3.]])
282300
283301 """
284302
285- x1_desc = dpnp .get_dpnp_descriptor (x1 , copy_when_nondefault_queue = False )
286- if x1_desc and not kwargs :
287- return dpnp_nancumprod (x1_desc ).get_pyobj ()
288-
289- return call_origin (numpy .nancumprod , x1 , ** kwargs )
303+ a , _ = _replace_nan (a , 1 )
304+ return dpnp .cumprod (a , axis = axis , dtype = dtype , out = out )
290305
291306
292307def nancumsum (a , axis = None , dtype = None , out = None ):
@@ -332,7 +347,7 @@ def nancumsum(a, axis=None, dtype=None, out=None):
332347 --------
333348 >>> import dpnp as np
334349 >>> np.nancumsum(np.array(1))
335- array([1] )
350+ array(1 )
336351 >>> np.nancumsum(np.array([1]))
337352 array([1])
338353 >>> np.nancumsum(np.array([1, np.nan]))
0 commit comments