@@ -63,6 +63,8 @@ __all__ += [
6363 " dpnp_minimum" ,
6464 " dpnp_modf" ,
6565 " dpnp_multiply" ,
66+ " dpnp_nancumprod" ,
67+ " dpnp_nancumsum" ,
6668 " dpnp_nanprod" ,
6769 " dpnp_nansum" ,
6870 " dpnp_negative" ,
@@ -139,54 +141,28 @@ cpdef dparray dpnp_cross(dparray x1, dparray x2):
139141 return call_fptr_2in_1out(DPNP_FN_CROSS, x1, x2, x1.shape)
140142
141143
142- cpdef dparray dpnp_cumprod(dparray x1, bint usenan = False ):
144+ cpdef dparray dpnp_cumprod(dparray x1):
145+ # instead of x1.shape, (x1.size, ) is passed to the function
146+ # due to the following:
147+ # >>> import numpy
148+ # >>> a = numpy.array([[1, 2], [2, 3]])
149+ # >>> res = numpy.cumprod(a)
150+ # >>> res.shape
151+ # (4,)
143152
144- types_map = {
145- dpnp.int32: dpnp.int64,
146- dpnp.int64: dpnp.int64,
147- dpnp.float32: dpnp.float32,
148- dpnp.float64: dpnp.float64
149- }
150-
151- res_type = types_map[x1.dtype.type]
152-
153- cdef dparray result = dparray(x1.size, dtype = res_type)
154-
155- cur_res = 1
156-
157- for i in range (result.size):
158-
159- if not usenan or not dpnp.isnan(x1[i]):
160- cur_res *= x1[i]
161-
162- result._setitem_scalar(i, cur_res)
163-
164- return result
165-
166-
167- cpdef dparray dpnp_cumsum(dparray x1, bint usenan = False ):
168-
169- types_map = {
170- dpnp.int32: dpnp.int64,
171- dpnp.int64: dpnp.int64,
172- dpnp.float32: dpnp.float32,
173- dpnp.float64: dpnp.float64
174- }
175-
176- res_type = types_map[x1.dtype.type]
153+ return call_fptr_1in_1out(DPNP_FN_CUMPROD, x1, (x1.size,))
177154
178- cdef dparray result = dparray(x1.size, dtype = res_type)
179155
180- cur_res = 0
156+ cpdef dparray dpnp_cumsum(dparray x1):
157+ # instead of x1.shape, (x1.size, ) is passed to the function
158+ # due to the following:
159+ # >>> import numpy
160+ # >>> a = numpy.array([[1, 2], [2, 3]])
161+ # >>> res = numpy.cumsum(a)
162+ # >>> res.shape
163+ # (4,)
181164
182- for i in range (result.size):
183-
184- if not usenan or not dpnp.isnan(x1[i]):
185- cur_res += x1[i]
186-
187- result._setitem_scalar(i, cur_res)
188-
189- return result
165+ return call_fptr_1in_1out(DPNP_FN_CUMSUM, x1, (x1.size,))
190166
191167
192168cpdef dparray dpnp_diff(dparray input , int n):
@@ -344,6 +320,28 @@ cpdef dparray dpnp_multiply(dparray x1, x2):
344320 return call_fptr_2in_1out(DPNP_FN_MULTIPLY, x1, x2, x1.shape)
345321
346322
323+ cpdef dparray dpnp_nancumprod(dparray x1):
324+
325+ cur_x1 = dpnp.copy(x1)
326+
327+ for i in range (cur_x1.size):
328+ if dpnp.isnan(cur_x1[i]):
329+ cur_x1._setitem_scalar(i, 1 )
330+
331+ return dpnp_cumprod(cur_x1)
332+
333+
334+ cpdef dparray dpnp_nancumsum(dparray x1):
335+
336+ cur_x1 = dpnp.copy(x1)
337+
338+ for i in range (cur_x1.size):
339+ if dpnp.isnan(cur_x1[i]):
340+ cur_x1._setitem_scalar(i, 0 )
341+
342+ return dpnp_cumsum(cur_x1)
343+
344+
347345cpdef dpnp_nanprod(dparray x1):
348346 cdef dparray result = dparray(x1.shape, dtype = x1.dtype)
349347
0 commit comments