Skip to content

Commit 3e813d1

Browse files
authored
stat submodule to desc completed (#870)
1 parent a72a346 commit 3e813d1

File tree

2 files changed

+35
-34
lines changed

2 files changed

+35
-34
lines changed

dpnp/dpnp_algo/dpnp_algo_statistics.pyx

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,18 @@ ctypedef void(*fptr_custom_std_var_1in_1out_t)(void *, void * , size_t * , size_
5757
ctypedef void(*custom_statistic_1in_1out_func_ptr_t)(void *, void * , size_t * , size_t, size_t * , size_t)
5858

5959

60-
cdef dparray call_fptr_custom_std_var_1in_1out(DPNPFuncName fptr_name, utils.dpnp_descriptor x1, ddof):
60+
cdef utils.dpnp_descriptor call_fptr_custom_std_var_1in_1out(DPNPFuncName fptr_name, utils.dpnp_descriptor x1, ddof):
6161
cdef shape_type_c x1_shape = x1.shape
6262

63-
""" Convert string type names (dparray.dtype) to C enum DPNPFuncType """
63+
""" Convert string type names (array.dtype) to C enum DPNPFuncType """
6464
cdef DPNPFuncType param_type = dpnp_dtype_to_DPNPFuncType(x1.dtype)
6565

6666
""" get the FPTR data structure """
6767
cdef DPNPFuncData kernel_data = get_dpnp_function_ptr(fptr_name, param_type, DPNP_FT_NONE)
6868

69-
result_type = dpnp_DPNPFuncType_to_dtype(< size_t > kernel_data.return_type)
70-
""" Create result array with type given by FPTR data """
71-
cdef dparray result = dparray((1,), dtype=result_type)
69+
# ceate result array with type given by FPTR data
70+
cdef shape_type_c result_shape = (1,)
71+
cdef utils.dpnp_descriptor result = utils.create_output_descriptor(result_shape, kernel_data.return_type, None)
7272

7373
cdef fptr_custom_std_var_1in_1out_t func = <fptr_custom_std_var_1in_1out_t > kernel_data.ptr
7474

@@ -92,7 +92,7 @@ cpdef dpnp_average(utils.dpnp_descriptor x1):
9292
return (return_type(array_sum / x1.size))
9393

9494

95-
cpdef dparray dpnp_correlate(utils.dpnp_descriptor x1, utils.dpnp_descriptor x2):
95+
cpdef utils.dpnp_descriptor dpnp_correlate(utils.dpnp_descriptor x1, utils.dpnp_descriptor x2):
9696
cdef DPNPFuncType param1_type = dpnp_dtype_to_DPNPFuncType(x1.dtype)
9797
cdef DPNPFuncType param2_type = dpnp_dtype_to_DPNPFuncType(x2.dtype)
9898

@@ -101,9 +101,9 @@ cpdef dparray dpnp_correlate(utils.dpnp_descriptor x1, utils.dpnp_descriptor x2)
101101

102102
cdef DPNPFuncData kernel_data = get_dpnp_function_ptr(DPNP_FN_CORRELATE, param1_type, param2_type)
103103

104-
result_type = dpnp_DPNPFuncType_to_dtype(< size_t > kernel_data.return_type)
105-
106-
cdef dparray result = dparray(1, dtype=result_type)
104+
# ceate result array with type given by FPTR data
105+
cdef shape_type_c result_shape = (1,)
106+
cdef utils.dpnp_descriptor result = utils.create_output_descriptor(result_shape, kernel_data.return_type, None)
107107

108108
cdef fptr_2in_1out_t func = <fptr_2in_1out_t > kernel_data.ptr
109109

@@ -120,7 +120,7 @@ cpdef utils.dpnp_descriptor dpnp_cov(utils.dpnp_descriptor array1):
120120
if array1.ndim == 1:
121121
input_shape.insert(input_shape.begin(), 1)
122122

123-
# convert string type names (dparray.dtype) to C enum DPNPFuncType
123+
# convert string type names (array.dtype) to C enum DPNPFuncType
124124
cdef DPNPFuncType param1_type = dpnp_dtype_to_DPNPFuncType(array1.dtype)
125125

126126
# get the FPTR data structure
@@ -137,14 +137,14 @@ cpdef utils.dpnp_descriptor dpnp_cov(utils.dpnp_descriptor array1):
137137
return result
138138

139139

140-
cpdef dparray _dpnp_max(dparray input, _axis_, output_shape):
140+
cdef utils.dpnp_descriptor _dpnp_max(utils.dpnp_descriptor input, _axis_, shape_type_c result_shape):
141141
cdef shape_type_c input_shape = input.shape
142142
cdef DPNPFuncType param1_type = dpnp_dtype_to_DPNPFuncType(input.dtype)
143143

144144
cdef DPNPFuncData kernel_data = get_dpnp_function_ptr(DPNP_FN_MAX, param1_type, param1_type)
145145

146-
result_type = dpnp_DPNPFuncType_to_dtype( < size_t > kernel_data.return_type)
147-
cdef dparray result = dparray(output_shape, dtype=result_type)
146+
# ceate result array with type given by FPTR data
147+
cdef utils.dpnp_descriptor result = utils.create_output_descriptor(result_shape, kernel_data.return_type, None)
148148

149149
cdef custom_statistic_1in_1out_func_ptr_t func = <custom_statistic_1in_1out_func_ptr_t > kernel_data.ptr
150150
cdef shape_type_c axis
@@ -160,16 +160,16 @@ cpdef dparray _dpnp_max(dparray input, _axis_, output_shape):
160160

161161
func(input.get_data(), result.get_data(), < size_t * > input_shape.data(), input.ndim, < size_t * > axis_.data(), axis_size)
162162

163-
dpnp_array = dpnp.array(result, dtype=input.dtype)
164-
dpnp_result_array = dpnp_array.reshape(output_shape)
165-
return dpnp_result_array
163+
return result
166164

167165

168-
cpdef dparray dpnp_max(dparray input, axis):
166+
cpdef utils.dpnp_descriptor dpnp_max(utils.dpnp_descriptor input, axis):
169167
cdef shape_type_c shape_input = input.shape
168+
cdef shape_type_c output_shape
169+
170170
if axis is None:
171171
axis_ = axis
172-
output_shape = 1
172+
output_shape.push_back(1)
173173
else:
174174
if isinstance(axis, int):
175175
if axis < 0:
@@ -185,12 +185,13 @@ cpdef dparray dpnp_max(dparray input, axis):
185185
_axis_.append(axis[i])
186186
axis_ = tuple(_axis_)
187187

188-
output_shape = dparray(len(shape_input) - len(axis_), dtype=numpy.int64)
188+
output_shape.resize(len(shape_input) - len(axis_), 0)
189189
ind = 0
190190
for id, shape_axis in enumerate(shape_input):
191191
if id not in axis_:
192192
output_shape[ind] = shape_axis
193193
ind += 1
194+
194195
return _dpnp_max(input, axis_, output_shape)
195196

196197

@@ -407,29 +408,29 @@ cpdef utils.dpnp_descriptor dpnp_min(utils.dpnp_descriptor input, axis):
407408
return _dpnp_min(input, axis_, shape_output)
408409

409410

410-
cpdef dparray dpnp_nanvar(utils.dpnp_descriptor arr, ddof):
411-
cdef dparray mask_arr = dpnp.isnan(arr)
412-
n = sum(mask_arr)
411+
cpdef utils.dpnp_descriptor dpnp_nanvar(utils.dpnp_descriptor arr, ddof):
412+
cdef utils.dpnp_descriptor mask_arr = dpnp_isnan(arr)
413+
n = sum(mask_arr.get_pyobj())
413414
res_size = arr.size - n
414415

415416
cdef DPNPFuncType param1_type = dpnp_dtype_to_DPNPFuncType(arr.dtype)
416417

417418
cdef DPNPFuncData kernel_data = get_dpnp_function_ptr(DPNP_FN_NANVAR, param1_type, param1_type)
418419

419-
result_type = dpnp_DPNPFuncType_to_dtype(< size_t > kernel_data.return_type)
420-
cdef dparray without_nan_arr = dparray((res_size, ), dtype=result_type)
420+
# ceate result array with type given by FPTR data
421+
cdef shape_type_c result_shape = utils._object_to_tuple(res_size)
422+
cdef utils.dpnp_descriptor result = utils.create_output_descriptor(result_shape, kernel_data.return_type, None)
421423

422424
cdef fptr_custom_nanvar_t func = <fptr_custom_nanvar_t > kernel_data.ptr
423425

424-
func(arr.get_data(), mask_arr.get_data(), without_nan_arr.get_data(), arr.size)
426+
func(arr.get_data(), mask_arr.get_data(), result.get_data(), arr.size)
425427

426-
without_nan_arr_desc = dpnp.get_dpnp_descriptor(without_nan_arr)
427-
return call_fptr_custom_std_var_1in_1out(DPNP_FN_VAR, without_nan_arr_desc, ddof)
428+
return call_fptr_custom_std_var_1in_1out(DPNP_FN_VAR, result, ddof)
428429

429430

430-
cpdef dparray dpnp_std(utils.dpnp_descriptor a, size_t ddof):
431+
cpdef utils.dpnp_descriptor dpnp_std(utils.dpnp_descriptor a, size_t ddof):
431432
return call_fptr_custom_std_var_1in_1out(DPNP_FN_STD, a, ddof)
432433

433434

434-
cpdef dparray dpnp_var(utils.dpnp_descriptor a, size_t ddof):
435+
cpdef utils.dpnp_descriptor dpnp_var(utils.dpnp_descriptor a, size_t ddof):
435436
return call_fptr_custom_std_var_1in_1out(DPNP_FN_VAR, a, ddof)

dpnp/dpnp_iface_statistics.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ def correlate(x1, x2, mode='valid'):
231231
elif mode != 'valid':
232232
pass
233233
else:
234-
return dpnp_correlate(x1_desc, x2_desc)
234+
return dpnp_correlate(x1_desc, x2_desc).get_pyobj()
235235

236236
return call_origin(numpy.correlate, x1, x2, mode=mode)
237237

@@ -384,7 +384,7 @@ def max(x1, axis=None, out=None, keepdims=False, initial=None, where=True):
384384
elif where is not True:
385385
pass
386386
else:
387-
result_obj = dpnp_max(x1, axis=axis)
387+
result_obj = dpnp_max(x1_desc, axis).get_pyobj()
388388
result = dpnp.convert_single_elem_array_to_scalar(result_obj)
389389

390390
return result
@@ -562,7 +562,7 @@ def nanvar(x1, axis=None, dtype=None, out=None, ddof=0, keepdims=False):
562562
elif keepdims:
563563
pass
564564
else:
565-
result_obj = dpnp_nanvar(x1_desc, ddof)
565+
result_obj = dpnp_nanvar(x1_desc, ddof).get_pyobj()
566566
result = dpnp.convert_single_elem_array_to_scalar(result_obj)
567567

568568
return result
@@ -620,7 +620,7 @@ def std(x1, axis=None, dtype=None, out=None, ddof=0, keepdims=False):
620620
elif keepdims:
621621
pass
622622
else:
623-
result_obj = dpnp_std(x1_desc, ddof)
623+
result_obj = dpnp_std(x1_desc, ddof).get_pyobj()
624624
result = dpnp.convert_single_elem_array_to_scalar(result_obj)
625625

626626
return result
@@ -678,7 +678,7 @@ def var(x1, axis=None, dtype=None, out=None, ddof=0, keepdims=False):
678678
elif keepdims:
679679
pass
680680
else:
681-
result_obj = dpnp_var(x1_desc, ddof)
681+
result_obj = dpnp_var(x1_desc, ddof).get_pyobj()
682682
result = dpnp.convert_single_elem_array_to_scalar(result_obj)
683683

684684
return result

0 commit comments

Comments
 (0)