Skip to content

Commit 2d09f58

Browse files
authored
dpnp.mean() to desc (#851)
1 parent 36d3504 commit 2d09f58

File tree

3 files changed

+26
-17
lines changed

3 files changed

+26
-17
lines changed

dpnp/dpnp_algo/dpnp_algo.pxd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ cpdef dparray dpnp_transpose(dpnp_descriptor array1, axes=*)
347347
Statistics functions
348348
"""
349349
cpdef dpnp_descriptor dpnp_cov(dpnp_descriptor array1)
350-
cpdef dparray dpnp_mean(dparray a, axis)
350+
cpdef object dpnp_mean(dpnp_descriptor a, axis)
351351
cpdef dpnp_descriptor dpnp_min(dpnp_descriptor a, axis)
352352

353353

dpnp/dpnp_algo/dpnp_algo_statistics.pyx

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -194,29 +194,35 @@ cpdef dparray dpnp_max(dparray input, axis):
194194
return _dpnp_max(input, axis_, output_shape)
195195

196196

197-
cpdef dparray _dpnp_mean(dparray input):
197+
cpdef utils.dpnp_descriptor _dpnp_mean(utils.dpnp_descriptor input):
198198
cdef shape_type_c input_shape = input.shape
199199
cdef DPNPFuncType param1_type = dpnp_dtype_to_DPNPFuncType(input.dtype)
200200

201201
cdef DPNPFuncData kernel_data = get_dpnp_function_ptr(DPNP_FN_MEAN, param1_type, param1_type)
202202

203-
result_type = dpnp_DPNPFuncType_to_dtype(< size_t > kernel_data.return_type)
204-
cdef dparray result = dparray((1,), dtype=result_type)
203+
cdef utils.dpnp_descriptor result = utils.create_output_descriptor((1,), kernel_data.return_type, None)
205204

206205
cdef custom_statistic_1in_1out_func_ptr_t func = <custom_statistic_1in_1out_func_ptr_t > kernel_data.ptr
207206

208207
# stub for interface support
209208
cdef shape_type_c axis
210209
cdef Py_ssize_t axis_size = 0
211210

212-
func(input.get_data(), result.get_data(), < size_t * > input_shape.data(), input.ndim, < size_t * > axis.data(), axis_size)
211+
func(input.get_data(),
212+
result.get_data(),
213+
< size_t * > input_shape.data(),
214+
input.ndim,
215+
< size_t * > axis.data(),
216+
axis_size)
213217

214218
return result
215219

216220

217-
cpdef dparray dpnp_mean(dparray input, axis):
221+
cpdef object dpnp_mean(utils.dpnp_descriptor input, axis):
222+
cdef shape_type_c output_shape
223+
218224
if axis is None:
219-
return _dpnp_mean(input)
225+
return _dpnp_mean(input).get_pyobj()
220226

221227
cdef long size_input = input.size
222228
cdef shape_type_c shape_input = input.shape
@@ -235,10 +241,9 @@ cpdef dparray dpnp_mean(dparray input, axis):
235241
axis_ = axis
236242

237243
if axis_ is None:
238-
output_shape = dparray(1, dtype=dpnp.int64)
239-
output_shape[0] = 1
244+
output_shape.push_back(1)
240245
else:
241-
output_shape = dparray(len(shape_input) - len(axis_), dtype=dpnp.int64)
246+
output_shape = (0, ) * (len(shape_input) - len(axis_))
242247
ind = 0
243248
for id, shape_axis in enumerate(shape_input):
244249
if id not in axis_:
@@ -295,7 +300,7 @@ cpdef dparray dpnp_mean(dparray input, axis):
295300
for i, result_axis_val in enumerate(result_axis):
296301
result_offset += (output_shape_offsets[i] * result_axis_val)
297302

298-
input_elem = input.item(source_idx)
303+
input_elem = input.get_pyobj().item(source_idx)
299304
if axis_ is None:
300305
if result_array[0] is None:
301306
result_array[0] = input_elem
@@ -317,22 +322,26 @@ cpdef dparray dpnp_mean(dparray input, axis):
317322
return dpnp_result_array / del_
318323

319324

320-
cpdef dparray dpnp_median(utils.dpnp_descriptor array1):
325+
cpdef utils.dpnp_descriptor dpnp_median(utils.dpnp_descriptor array1):
321326
cdef shape_type_c x1_shape = array1.shape
322327
cdef DPNPFuncType param1_type = dpnp_dtype_to_DPNPFuncType(array1.dtype)
323328

324329
cdef DPNPFuncData kernel_data = get_dpnp_function_ptr(DPNP_FN_MEDIAN, param1_type, param1_type)
325330

326-
result_type = dpnp_DPNPFuncType_to_dtype(< size_t > kernel_data.return_type)
327-
cdef dparray result = dparray((1,), dtype=result_type)
331+
cdef utils.dpnp_descriptor result = utils.create_output_descriptor((1,), kernel_data.return_type, None)
328332

329333
cdef custom_statistic_1in_1out_func_ptr_t func = <custom_statistic_1in_1out_func_ptr_t > kernel_data.ptr
330334

331335
# stub for interface support
332336
cdef shape_type_c axis
333337
cdef Py_ssize_t axis_size = 0
334338

335-
func(array1.get_data(), result.get_data(), < size_t * > x1_shape.data(), array1.ndim, < size_t * > axis.data(), axis_size)
339+
func(array1.get_data(),
340+
result.get_data(),
341+
< size_t * > x1_shape.data(),
342+
array1.ndim,
343+
< size_t * > axis.data(),
344+
axis_size)
336345

337346
return result
338347

dpnp/dpnp_iface_statistics.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ def mean(x1, axis=None, **kwargs):
432432
if x1_desc.size == 0:
433433
pass
434434
else:
435-
result_obj = dpnp_mean(x1, axis=axis)
435+
result_obj = dpnp_mean(x1_desc, axis)
436436
result = dpnp.convert_single_elem_array_to_scalar(result_obj)
437437

438438
return result
@@ -482,7 +482,7 @@ def median(x1, axis=None, out=None, overwrite_input=False, keepdims=False):
482482
elif keepdims:
483483
pass
484484
else:
485-
result_obj = dpnp_median(x1_desc)
485+
result_obj = dpnp_median(x1_desc).get_pyobj()
486486
result = dpnp.convert_single_elem_array_to_scalar(result_obj)
487487

488488
return result

0 commit comments

Comments
 (0)