diff --git a/dpnp/dpnp_algo/dpnp_algo_statistics.pyx b/dpnp/dpnp_algo/dpnp_algo_statistics.pyx index b8107d929eb..d9907e43bf6 100644 --- a/dpnp/dpnp_algo/dpnp_algo_statistics.pyx +++ b/dpnp/dpnp_algo/dpnp_algo_statistics.pyx @@ -57,18 +57,18 @@ ctypedef void(*fptr_custom_std_var_1in_1out_t)(void *, void * , size_t * , size_ ctypedef void(*custom_statistic_1in_1out_func_ptr_t)(void *, void * , size_t * , size_t, size_t * , size_t) -cdef dparray call_fptr_custom_std_var_1in_1out(DPNPFuncName fptr_name, utils.dpnp_descriptor x1, ddof): +cdef utils.dpnp_descriptor call_fptr_custom_std_var_1in_1out(DPNPFuncName fptr_name, utils.dpnp_descriptor x1, ddof): cdef shape_type_c x1_shape = x1.shape - """ Convert string type names (dparray.dtype) to C enum DPNPFuncType """ + """ Convert string type names (array.dtype) to C enum DPNPFuncType """ cdef DPNPFuncType param_type = dpnp_dtype_to_DPNPFuncType(x1.dtype) """ get the FPTR data structure """ cdef DPNPFuncData kernel_data = get_dpnp_function_ptr(fptr_name, param_type, DPNP_FT_NONE) - result_type = dpnp_DPNPFuncType_to_dtype(< size_t > kernel_data.return_type) - """ Create result array with type given by FPTR data """ - cdef dparray result = dparray((1,), dtype=result_type) + # ceate result array with type given by FPTR data + cdef shape_type_c result_shape = (1,) + cdef utils.dpnp_descriptor result = utils.create_output_descriptor(result_shape, kernel_data.return_type, None) cdef fptr_custom_std_var_1in_1out_t func = kernel_data.ptr @@ -92,7 +92,7 @@ cpdef dpnp_average(utils.dpnp_descriptor x1): return (return_type(array_sum / x1.size)) -cpdef dparray dpnp_correlate(utils.dpnp_descriptor x1, utils.dpnp_descriptor x2): +cpdef utils.dpnp_descriptor dpnp_correlate(utils.dpnp_descriptor x1, utils.dpnp_descriptor x2): cdef DPNPFuncType param1_type = dpnp_dtype_to_DPNPFuncType(x1.dtype) cdef DPNPFuncType param2_type = dpnp_dtype_to_DPNPFuncType(x2.dtype) @@ -101,9 +101,9 @@ cpdef dparray dpnp_correlate(utils.dpnp_descriptor x1, utils.dpnp_descriptor x2) cdef DPNPFuncData kernel_data = get_dpnp_function_ptr(DPNP_FN_CORRELATE, param1_type, param2_type) - result_type = dpnp_DPNPFuncType_to_dtype(< size_t > kernel_data.return_type) - - cdef dparray result = dparray(1, dtype=result_type) + # ceate result array with type given by FPTR data + cdef shape_type_c result_shape = (1,) + cdef utils.dpnp_descriptor result = utils.create_output_descriptor(result_shape, kernel_data.return_type, None) cdef fptr_2in_1out_t func = kernel_data.ptr @@ -120,7 +120,7 @@ cpdef utils.dpnp_descriptor dpnp_cov(utils.dpnp_descriptor array1): if array1.ndim == 1: input_shape.insert(input_shape.begin(), 1) - # convert string type names (dparray.dtype) to C enum DPNPFuncType + # convert string type names (array.dtype) to C enum DPNPFuncType cdef DPNPFuncType param1_type = dpnp_dtype_to_DPNPFuncType(array1.dtype) # get the FPTR data structure @@ -137,14 +137,14 @@ cpdef utils.dpnp_descriptor dpnp_cov(utils.dpnp_descriptor array1): return result -cpdef dparray _dpnp_max(dparray input, _axis_, output_shape): +cdef utils.dpnp_descriptor _dpnp_max(utils.dpnp_descriptor input, _axis_, shape_type_c result_shape): cdef shape_type_c input_shape = input.shape cdef DPNPFuncType param1_type = dpnp_dtype_to_DPNPFuncType(input.dtype) cdef DPNPFuncData kernel_data = get_dpnp_function_ptr(DPNP_FN_MAX, param1_type, param1_type) - result_type = dpnp_DPNPFuncType_to_dtype( < size_t > kernel_data.return_type) - cdef dparray result = dparray(output_shape, dtype=result_type) + # ceate result array with type given by FPTR data + cdef utils.dpnp_descriptor result = utils.create_output_descriptor(result_shape, kernel_data.return_type, None) cdef custom_statistic_1in_1out_func_ptr_t func = kernel_data.ptr cdef shape_type_c axis @@ -160,16 +160,16 @@ cpdef dparray _dpnp_max(dparray input, _axis_, output_shape): func(input.get_data(), result.get_data(), < size_t * > input_shape.data(), input.ndim, < size_t * > axis_.data(), axis_size) - dpnp_array = dpnp.array(result, dtype=input.dtype) - dpnp_result_array = dpnp_array.reshape(output_shape) - return dpnp_result_array + return result -cpdef dparray dpnp_max(dparray input, axis): +cpdef utils.dpnp_descriptor dpnp_max(utils.dpnp_descriptor input, axis): cdef shape_type_c shape_input = input.shape + cdef shape_type_c output_shape + if axis is None: axis_ = axis - output_shape = 1 + output_shape.push_back(1) else: if isinstance(axis, int): if axis < 0: @@ -185,12 +185,13 @@ cpdef dparray dpnp_max(dparray input, axis): _axis_.append(axis[i]) axis_ = tuple(_axis_) - output_shape = dparray(len(shape_input) - len(axis_), dtype=numpy.int64) + output_shape.resize(len(shape_input) - len(axis_), 0) ind = 0 for id, shape_axis in enumerate(shape_input): if id not in axis_: output_shape[ind] = shape_axis ind += 1 + return _dpnp_max(input, axis_, output_shape) @@ -407,29 +408,29 @@ cpdef utils.dpnp_descriptor dpnp_min(utils.dpnp_descriptor input, axis): return _dpnp_min(input, axis_, shape_output) -cpdef dparray dpnp_nanvar(utils.dpnp_descriptor arr, ddof): - cdef dparray mask_arr = dpnp.isnan(arr) - n = sum(mask_arr) +cpdef utils.dpnp_descriptor dpnp_nanvar(utils.dpnp_descriptor arr, ddof): + cdef utils.dpnp_descriptor mask_arr = dpnp_isnan(arr) + n = sum(mask_arr.get_pyobj()) res_size = arr.size - n cdef DPNPFuncType param1_type = dpnp_dtype_to_DPNPFuncType(arr.dtype) cdef DPNPFuncData kernel_data = get_dpnp_function_ptr(DPNP_FN_NANVAR, param1_type, param1_type) - result_type = dpnp_DPNPFuncType_to_dtype(< size_t > kernel_data.return_type) - cdef dparray without_nan_arr = dparray((res_size, ), dtype=result_type) + # ceate result array with type given by FPTR data + cdef shape_type_c result_shape = utils._object_to_tuple(res_size) + cdef utils.dpnp_descriptor result = utils.create_output_descriptor(result_shape, kernel_data.return_type, None) cdef fptr_custom_nanvar_t func = kernel_data.ptr - func(arr.get_data(), mask_arr.get_data(), without_nan_arr.get_data(), arr.size) + func(arr.get_data(), mask_arr.get_data(), result.get_data(), arr.size) - without_nan_arr_desc = dpnp.get_dpnp_descriptor(without_nan_arr) - return call_fptr_custom_std_var_1in_1out(DPNP_FN_VAR, without_nan_arr_desc, ddof) + return call_fptr_custom_std_var_1in_1out(DPNP_FN_VAR, result, ddof) -cpdef dparray dpnp_std(utils.dpnp_descriptor a, size_t ddof): +cpdef utils.dpnp_descriptor dpnp_std(utils.dpnp_descriptor a, size_t ddof): return call_fptr_custom_std_var_1in_1out(DPNP_FN_STD, a, ddof) -cpdef dparray dpnp_var(utils.dpnp_descriptor a, size_t ddof): +cpdef utils.dpnp_descriptor dpnp_var(utils.dpnp_descriptor a, size_t ddof): return call_fptr_custom_std_var_1in_1out(DPNP_FN_VAR, a, ddof) diff --git a/dpnp/dpnp_iface_statistics.py b/dpnp/dpnp_iface_statistics.py index 3fab0193336..9b6e44e483c 100644 --- a/dpnp/dpnp_iface_statistics.py +++ b/dpnp/dpnp_iface_statistics.py @@ -231,7 +231,7 @@ def correlate(x1, x2, mode='valid'): elif mode != 'valid': pass else: - return dpnp_correlate(x1_desc, x2_desc) + return dpnp_correlate(x1_desc, x2_desc).get_pyobj() return call_origin(numpy.correlate, x1, x2, mode=mode) @@ -384,7 +384,7 @@ def max(x1, axis=None, out=None, keepdims=False, initial=None, where=True): elif where is not True: pass else: - result_obj = dpnp_max(x1, axis=axis) + result_obj = dpnp_max(x1_desc, axis).get_pyobj() result = dpnp.convert_single_elem_array_to_scalar(result_obj) return result @@ -562,7 +562,7 @@ def nanvar(x1, axis=None, dtype=None, out=None, ddof=0, keepdims=False): elif keepdims: pass else: - result_obj = dpnp_nanvar(x1_desc, ddof) + result_obj = dpnp_nanvar(x1_desc, ddof).get_pyobj() result = dpnp.convert_single_elem_array_to_scalar(result_obj) return result @@ -620,7 +620,7 @@ def std(x1, axis=None, dtype=None, out=None, ddof=0, keepdims=False): elif keepdims: pass else: - result_obj = dpnp_std(x1_desc, ddof) + result_obj = dpnp_std(x1_desc, ddof).get_pyobj() result = dpnp.convert_single_elem_array_to_scalar(result_obj) return result @@ -678,7 +678,7 @@ def var(x1, axis=None, dtype=None, out=None, ddof=0, keepdims=False): elif keepdims: pass else: - result_obj = dpnp_var(x1_desc, ddof) + result_obj = dpnp_var(x1_desc, ddof).get_pyobj() result = dpnp.convert_single_elem_array_to_scalar(result_obj) return result