@@ -80,19 +80,18 @@ ctypedef void(*ftpr_custom_trapz_2in_1out_with_2size_t)(void *, void * , void *
80
80
ctypedef void (* ftpr_custom_around_1in_1out_t)(const void * , void * , const size_t, const int )
81
81
82
82
83
- cpdef dparray dpnp_absolute(utils.dpnp_descriptor input ):
83
+ cpdef utils.dpnp_descriptor dpnp_absolute(utils.dpnp_descriptor input ):
84
84
cdef shape_type_c input_shape = input .shape
85
85
cdef size_t input_shape_size = input .ndim
86
86
87
- # convert string type names (dparray .dtype) to C enum DPNPFuncType
87
+ # convert string type names (array .dtype) to C enum DPNPFuncType
88
88
cdef DPNPFuncType param1_type = dpnp_dtype_to_DPNPFuncType(input .dtype)
89
89
90
90
# get the FPTR data structure
91
91
cdef DPNPFuncData kernel_data = get_dpnp_function_ptr(DPNP_FN_ABSOLUTE, param1_type, param1_type)
92
92
93
- result_type = dpnp_DPNPFuncType_to_dtype( < size_t > kernel_data.return_type)
94
93
# ceate result array with type given by FPTR data
95
- cdef dparray result = dparray (input_shape, dtype = result_type )
94
+ cdef utils.dpnp_descriptor result = utils.create_output_descriptor (input_shape, kernel_data.return_type, None )
96
95
97
96
cdef fptr_custom_elemwise_absolute_1in_1out_t func = < fptr_custom_elemwise_absolute_1in_1out_t > kernel_data.ptr
98
97
# call FPTR function
@@ -117,15 +116,15 @@ cpdef utils.dpnp_descriptor dpnp_arctan2(utils.dpnp_descriptor x1_obj,
117
116
return call_fptr_2in_1out(DPNP_FN_ARCTAN2, x1_obj, x2_obj, dtype, out, where, func_name = " arctan2" )
118
117
119
118
120
- cpdef dpnp_around(utils.dpnp_descriptor x1, int decimals):
119
+ cpdef utils.dpnp_descriptor dpnp_around(utils.dpnp_descriptor x1, int decimals):
121
120
122
121
cdef DPNPFuncType param1_type = dpnp_dtype_to_DPNPFuncType(x1.dtype)
123
122
124
123
cdef DPNPFuncData kernel_data = get_dpnp_function_ptr(DPNP_FN_AROUND, param1_type, param1_type)
125
124
126
- result_type = dpnp_DPNPFuncType_to_dtype( < size_t > kernel_data.return_type)
127
-
128
- cdef dparray result = dparray(x1.shape, dtype = result_type )
125
+ # ceate result array with type given by FPTR data
126
+ cdef shape_type_c result_shape = x1.shape
127
+ cdef utils.dpnp_descriptor result = utils.create_output_descriptor(result_shape, kernel_data.return_type, None )
129
128
130
129
cdef ftpr_custom_around_1in_1out_t func = < ftpr_custom_around_1in_1out_t > kernel_data.ptr
131
130
@@ -182,11 +181,11 @@ cpdef utils.dpnp_descriptor dpnp_cumsum(utils.dpnp_descriptor x1):
182
181
return call_fptr_1in_1out(DPNP_FN_CUMSUM, x1, (x1.size,))
183
182
184
183
185
- cpdef dparray dpnp_diff(object input , int n):
184
+ cpdef object dpnp_diff(utils.dpnp_descriptor input , int n):
186
185
if n == 0 :
187
- return input
186
+ return input .get_pyobj()
188
187
if n < input .shape[- 1 ]:
189
- arr = input
188
+ arr = input .get_pyobj()
190
189
for _ in range (n):
191
190
list_shape_i = list (arr.shape)
192
191
list_shape_i[- 1 ] = list_shape_i[- 1 ] - 1
@@ -249,23 +248,25 @@ cpdef utils.dpnp_descriptor dpnp_fmod(utils.dpnp_descriptor x1_obj,
249
248
return call_fptr_2in_1out(DPNP_FN_FMOD, x1_obj, x2_obj, dtype, out, where)
250
249
251
250
252
- cpdef dparray dpnp_gradient(object y1, int dx = 1 ):
251
+ cpdef utils.dpnp_descriptor dpnp_gradient(utils.dpnp_descriptor y1, int dx = 1 ):
253
252
254
- size = y1.size
253
+ cdef size_t size = y1.size
255
254
256
- cdef dparray result = dparray(size, dtype = dpnp.float64)
255
+ # ceate result array with type given by FPTR data
256
+ cdef shape_type_c result_shape = utils._object_to_tuple(size)
257
+ cdef utils.dpnp_descriptor result = utils_py.create_output_descriptor_py(result_shape, dpnp.float64, None )
257
258
258
- cur = (y1[1 ] - y1[0 ]) / dx
259
+ cdef double cur = (y1.get_pyobj() [1 ] - y1.get_pyobj() [0 ]) / dx
259
260
260
- result._setitem_scalar( 0 , cur)
261
+ result.get_pyobj().flat[ 0 ] = cur
261
262
262
- cur = (y1[- 1 ] - y1[- 2 ]) / dx
263
+ cur = (y1.get_pyobj() [- 1 ] - y1.get_pyobj() [- 2 ]) / dx
263
264
264
- result._setitem_scalar( size - 1 , cur)
265
+ result.get_pyobj().flat[ size - 1 ] = cur
265
266
266
267
for i in range (1 , size - 1 ):
267
- cur = (y1[i + 1 ] - y1[i - 1 ]) / (2 * dx)
268
- result._setitem_scalar(i, cur)
268
+ cur = (y1.get_pyobj() [i + 1 ] - y1.get_pyobj() [i - 1 ]) / (2 * dx)
269
+ result.get_pyobj().flat[i] = cur
269
270
270
271
return result
271
272
@@ -295,22 +296,22 @@ cpdef utils.dpnp_descriptor dpnp_minimum(utils.dpnp_descriptor x1_obj,
295
296
296
297
297
298
cpdef tuple dpnp_modf(utils.dpnp_descriptor x1):
298
- """ Convert string type names (dparray .dtype) to C enum DPNPFuncType """
299
+ """ Convert string type names (array .dtype) to C enum DPNPFuncType """
299
300
cdef DPNPFuncType param1_type = dpnp_dtype_to_DPNPFuncType(x1.dtype)
300
301
301
302
""" get the FPTR data structure """
302
303
cdef DPNPFuncData kernel_data = get_dpnp_function_ptr(DPNP_FN_MODF, param1_type, DPNP_FT_NONE)
303
304
304
- result_type = dpnp_DPNPFuncType_to_dtype( < size_t > kernel_data.return_type)
305
- """ Create result arrays with type given by FPTR data """
306
- cdef dparray result1 = dparray(x1.shape, dtype = result_type )
307
- cdef dparray result2 = dparray(x1.shape, dtype = result_type )
305
+ # ceate result array with type given by FPTR data
306
+ cdef shape_type_c result_shape = x1.shape
307
+ cdef utils.dpnp_descriptor result1 = utils.create_output_descriptor(result_shape, kernel_data.return_type, None )
308
+ cdef utils.dpnp_descriptor result2 = utils.create_output_descriptor(result_shape, kernel_data.return_type, None )
308
309
309
310
cdef fptr_1in_2out_t func = < fptr_1in_2out_t > kernel_data.ptr
310
311
""" Call FPTR function """
311
312
func(x1.get_data(), result1.get_data(), result2.get_data(), x1.size)
312
313
313
- return result1, result2
314
+ return ( result1.get_pyobj() , result2.get_pyobj())
314
315
315
316
316
317
cpdef utils.dpnp_descriptor dpnp_multiply(utils.dpnp_descriptor x1_obj,
@@ -343,38 +344,32 @@ cpdef utils.dpnp_descriptor dpnp_nancumsum(utils.dpnp_descriptor x1):
343
344
return dpnp_cumsum(x1_desc)
344
345
345
346
346
- cpdef dpnp_nanprod(object x1):
347
- cdef dparray result = dparray (x1.shape, dtype = x1.dtype)
347
+ cpdef utils.dpnp_descriptor dpnp_nanprod(utils.dpnp_descriptor x1):
348
+ cdef utils.dpnp_descriptor result = utils_py.create_output_descriptor_py (x1.shape, x1.dtype, None )
348
349
349
350
for i in range (result.size):
350
- input_elem = x1.item(i)
351
+ input_elem = x1.get_pyobj().flat[i]
351
352
352
353
if dpnp.isnan(input_elem):
353
- result._setitem_scalar(i, 1 )
354
+ result.get_pyobj().flat[i] = 1
354
355
else :
355
- result._setitem_scalar(i, input_elem)
356
+ result.get_pyobj().flat[i] = input_elem
356
357
357
- result_desc = dpnp.get_dpnp_descriptor(result) # TODO remove it later
358
- return dpnp_prod(result_desc)
358
+ return dpnp_prod(result)
359
359
360
360
361
- cpdef dpnp_nansum(object x1):
362
- cdef dparray result = dparray (x1.shape, dtype = x1.dtype)
361
+ cpdef utils.dpnp_descriptor dpnp_nansum(utils.dpnp_descriptor x1):
362
+ cdef utils.dpnp_descriptor result = utils_py.create_output_descriptor_py (x1.shape, x1.dtype, None )
363
363
364
364
for i in range (result.size):
365
- input_elem = x1.item(i)
365
+ input_elem = x1.get_pyobj().flat[i]
366
366
367
367
if dpnp.isnan(input_elem):
368
- result._setitem_scalar(i, 0 )
368
+ result.get_pyobj().flat[i] = 0
369
369
else :
370
- result._setitem_scalar(i, input_elem)
370
+ result.get_pyobj().flat[i] = input_elem
371
371
372
- # due to bug in dpnp_sum need this workaround
373
- # return dpnp_sum(result)
374
-
375
- result_desc = dpnp.get_dpnp_descriptor(result) # TODO remove it later
376
- sum_result = dpnp_sum(result_desc).get_pyobj()
377
- return x1.dtype.type(sum_result[0 ])
372
+ return dpnp_sum(result)
378
373
379
374
380
375
cpdef utils.dpnp_descriptor dpnp_negative(dpnp_descriptor x1):
@@ -476,20 +471,20 @@ cpdef utils.dpnp_descriptor dpnp_sum(utils.dpnp_descriptor input,
476
471
return result
477
472
478
473
479
- cpdef dpnp_trapz(utils.dpnp_descriptor y1, dparray x1, double dx):
474
+ cpdef utils.dpnp_descriptor dpnp_trapz(utils.dpnp_descriptor y1, utils.dpnp_descriptor x1, double dx):
480
475
481
476
cdef DPNPFuncType param1_type = dpnp_dtype_to_DPNPFuncType(y1.dtype)
482
477
cdef DPNPFuncType param2_type = dpnp_dtype_to_DPNPFuncType(x1.dtype)
483
478
cdef DPNPFuncData kernel_data = get_dpnp_function_ptr(DPNP_FN_TRAPZ, param1_type, param2_type)
484
479
485
- result_type = dpnp_DPNPFuncType_to_dtype( < size_t > kernel_data.return_type)
486
-
487
- cdef dparray result = dparray(( 1 ,), dtype = result_type )
480
+ # ceate result array with type given by FPTR data
481
+ cdef shape_type_c result_shape = ( 1 ,)
482
+ cdef utils.dpnp_descriptor result = utils.create_output_descriptor(result_shape, kernel_data.return_type, None )
488
483
489
484
cdef ftpr_custom_trapz_2in_1out_with_2size_t func = < ftpr_custom_trapz_2in_1out_with_2size_t > kernel_data.ptr
490
485
func(y1.get_data(), x1.get_data(), result.get_data(), dx, y1.size, x1.size)
491
486
492
- return result[ 0 ]
487
+ return result
493
488
494
489
495
490
cpdef utils.dpnp_descriptor dpnp_trunc(utils.dpnp_descriptor x1, utils.dpnp_descriptor out):
0 commit comments