Skip to content

stat submodule to desc completed #870

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 30 additions & 29 deletions dpnp/dpnp_algo/dpnp_algo_statistics.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <fptr_custom_std_var_1in_1out_t > kernel_data.ptr

Expand All @@ -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)

Expand All @@ -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 = <fptr_2in_1out_t > kernel_data.ptr

Expand All @@ -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
Expand All @@ -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 = <custom_statistic_1in_1out_func_ptr_t > kernel_data.ptr
cdef shape_type_c axis
Expand All @@ -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:
Expand All @@ -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)


Expand Down Expand Up @@ -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 = <fptr_custom_nanvar_t > 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)
10 changes: 5 additions & 5 deletions dpnp/dpnp_iface_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down