Skip to content

dpnp.min() simplify plus moved to desc #848

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 16, 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
2 changes: 1 addition & 1 deletion dpnp/dpnp_algo/dpnp_algo.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ Statistics functions
"""
cpdef dpnp_descriptor dpnp_cov(dpnp_descriptor array1)
cpdef dparray dpnp_mean(dparray a, axis)
cpdef dparray dpnp_min(dparray a, axis)
cpdef dpnp_descriptor dpnp_min(dpnp_descriptor a, axis)


"""
Expand Down
32 changes: 17 additions & 15 deletions dpnp/dpnp_algo/dpnp_algo_statistics.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -337,14 +337,13 @@ cpdef dparray dpnp_median(utils.dpnp_descriptor array1):
return result


cpdef dparray _dpnp_min(dparray input, _axis_, output_shape):
cpdef utils.dpnp_descriptor _dpnp_min(utils.dpnp_descriptor input, _axis_, shape_type_c shape_output):
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_MIN, 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)
cdef utils.dpnp_descriptor result = utils.create_output_descriptor(shape_output, 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 @@ -356,22 +355,27 @@ cpdef dparray _dpnp_min(dparray input, _axis_, output_shape):
axis_.reserve(len(axis))
for shape_it in axis:
if shape_it < 0:
raise ValueError("DPNP dparray::__init__(): Negative values in 'shape' are not allowed")
raise ValueError("DPNP algo::_dpnp_min(): Negative values in 'shape' are not allowed")
axis_.push_back(shape_it)
axis_size = len(axis)

func(input.get_data(), result.get_data(), < size_t * > input_shape.data(), input.ndim, < size_t * > axis_.data(), axis_size)
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_min(dparray input, axis):
cpdef utils.dpnp_descriptor dpnp_min(utils.dpnp_descriptor input, axis):
cdef shape_type_c shape_input = input.shape
cdef shape_type_c shape_output

if axis is None:
axis_ = axis
output_shape = 1
shape_output = (1,)
else:
if isinstance(axis, int):
if axis < 0:
Expand All @@ -387,13 +391,11 @@ cpdef dparray dpnp_min(dparray input, axis):
_axis_.append(axis[i])
axis_ = tuple(_axis_)

output_shape = dparray(len(shape_input) - len(axis_), dtype=numpy.int64)
ind = 0
for id, shape_axis in enumerate(shape_input):
if id not in axis_:
output_shape[ind] = shape_axis
ind += 1
return _dpnp_min(input, axis_, output_shape)
shape_output.push_back(shape_axis)

return _dpnp_min(input, axis_, shape_output)


cpdef dparray dpnp_nanvar(utils.dpnp_descriptor arr, ddof):
Expand Down
2 changes: 1 addition & 1 deletion dpnp/dpnp_iface_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ def min(x1, axis=None, out=None, keepdims=False, initial=None, where=True):
elif where is not True:
pass
else:
result_obj = dpnp_min(x1, axis=axis)
result_obj = dpnp_min(x1_desc, axis).get_pyobj()
result = dpnp.convert_single_elem_array_to_scalar(result_obj)

return result
Expand Down