Skip to content

Dpnp ptp #715

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 34 commits into from
Dec 29, 2021
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
50db5c7
add python version ptp
Rubtsowa May 6, 2021
a9bcb0e
add doc & start add native version
Rubtsowa May 6, 2021
68d261c
merge
Rubtsowa May 14, 2021
5560830
Merge branch 'master' into dpnp_ptp
shssf Jun 7, 2021
0209a15
Merge branch 'master' into dpnp_ptp
shssf Jun 8, 2021
54912d5
Merge branch 'master' into dpnp_ptp
shssf Jun 13, 2021
e87e004
Merge branch 'master' into dpnp_ptp
shssf Jun 14, 2021
335e8be
Merge branch 'master' into dpnp_ptp
shssf Jun 14, 2021
2c3c49d
Merge branch 'master' into dpnp_ptp
shssf Jun 15, 2021
39431d2
Merge branch 'master' into dpnp_ptp
shssf Jun 21, 2021
6a30f75
Merge branch 'master' into dpnp_ptp
shssf Jun 22, 2021
fc7950a
Merge branch 'master' into dpnp_ptp
shssf Jul 17, 2021
8f94d65
Resolve conflicts and update dpnp_ptp
LukichevaPolina Sep 30, 2021
d5c5b8c
Merge branch 'master' into dpnp_ptp
Alexander-Makaryev Oct 1, 2021
c1ac080
Merge branch 'master' into dpnp_ptp
Alexander-Makaryev Oct 1, 2021
fe4b81c
Moving checks and freeing of memory
LukichevaPolina Oct 1, 2021
16ffaca
Merge branch 'dpnp_ptp' of https://github.com/Rubtsowa/dpnp into dpnp…
LukichevaPolina Oct 1, 2021
8834a4a
Change condition and call convert_single_elem_array_to_scalar, change…
LukichevaPolina Oct 4, 2021
a23aaf3
fix parametrs of dpnp_ptp_c
LukichevaPolina Oct 5, 2021
4f87393
Merge branch 'master' into dpnp_ptp
Alexander-Makaryev Oct 5, 2021
d99f505
Change interface of function dpnp_ptp
LukichevaPolina Oct 6, 2021
55c644b
Merge branch 'master' of https://github.com/IntelPython/dpnp into dpn…
LukichevaPolina Oct 6, 2021
87e429c
Merge branch 'dpnp_ptp' of https://github.com/Rubtsowa/dpnp into dpnp…
LukichevaPolina Oct 6, 2021
e826d04
fix style
LukichevaPolina Oct 7, 2021
63fdd05
Merge branch 'master' into dpnp_ptp
Alexander-Makaryev Dec 27, 2021
211fbd9
Update dpnp_iface.hpp
Alexander-Makaryev Dec 27, 2021
0a62779
Update dpnp_krnl_arraycreation.cpp
Alexander-Makaryev Dec 27, 2021
62a794a
Update dpnp_algo_arraycreation.pyx
Alexander-Makaryev Dec 27, 2021
ee6ad45
Merge branch 'master' into dpnp_ptp
Alexander-Makaryev Dec 29, 2021
a615cbd
Merge branch 'master' into dpnp_ptp
Alexander-Makaryev Dec 29, 2021
c28cfc3
Update dpnp_krnl_arraycreation.cpp
Alexander-Makaryev Dec 29, 2021
763c4e2
Merge branch 'master' into dpnp_ptp
Alexander-Makaryev Dec 29, 2021
0c11ff7
Update dpnp_krnl_arraycreation.cpp
Alexander-Makaryev Dec 29, 2021
3723567
Update dpnp_algo_arraycreation.pyx
Alexander-Makaryev Dec 29, 2021
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
16 changes: 16 additions & 0 deletions dpnp/backend/include/dpnp_iface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,22 @@ INP_DLLEXPORT void dpnp_prod_c(void* result_out,
const void* initial,
const long* where);

/**
* @ingroup BACKEND_API
* @brief Range of values (maximum - minimum) along an axis.
*
* @param [out] result Output array.
* @param [in] array Input array with data.
* @param [in] res_shape Shape of input array.
* @param [in] res_ndim Number of elements in shape.
* @param [in] shape Shape of input array.
* @param [in] ndim Number of elements in shape.
* @param [in] axis Axis.
* @param [in] naxis Number of elements in axis.
*/
template <typename _DataType>
void dpnp_ptp_c(void* result1, void* array1_in, const size_t* res_shape, size_t res_ndim, const size_t* shape, size_t ndim, const size_t* axis, size_t naxis);

/**
* @ingroup BACKEND_API
* @brief Product of array elements
Expand Down
1 change: 1 addition & 0 deletions dpnp/backend/include/dpnp_iface_fptr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ enum class DPNPFuncName : size_t
DPNP_FN_PLACE, /**< Used in numpy.place() implementation */
DPNP_FN_POWER, /**< Used in numpy.power() implementation */
DPNP_FN_PROD, /**< Used in numpy.prod() implementation */
DPNP_FN_PTP, /**< Used in numpy.ptp() implementation */
DPNP_FN_PUT, /**< Used in numpy.put() implementation */
DPNP_FN_PUT_ALONG_AXIS, /**< Used in numpy.put_along_axis() implementation */
DPNP_FN_QR, /**< Used in numpy.linalg.qr() implementation */
Expand Down
47 changes: 47 additions & 0 deletions dpnp/backend/kernels/dpnp_krnl_arraycreation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,48 @@ void dpnp_ones_like_c(void* result, size_t size)
dpnp_ones_c<_DataType>(result, size);
}

template <typename _DataType>
void dpnp_ptp_c(void* result1, void* array1_in, const size_t* res_shape, size_t res_ndim, const size_t* shape, size_t ndim, const size_t* axis, size_t naxis)
{
if ((array1_in == nullptr) || (result1 == nullptr))
{
return;
}

if (ndim < 1)
{
return;
}

size_t size = 1;
for (size_t i = 0; i < ndim; ++i)
{
size *= shape[i];
}

size_t res_size = 1;
for (size_t i = 0; i < res_ndim; ++i)
{
res_size *= res_shape[i];
}

DPNPC_ptr_adapter<_DataType> input1_ptr(array1_in, size, true);
DPNPC_ptr_adapter<_DataType> result_ptr(result1, res_size, false, true);
_DataType* arr = input1_ptr.get_ptr();
_DataType* result = result_ptr.get_ptr();

_DataType* min_arr = reinterpret_cast<_DataType*>(dpnp_memory_alloc_c(res_size * sizeof(_DataType)));
_DataType* max_arr = reinterpret_cast<_DataType*>(dpnp_memory_alloc_c(res_size * sizeof(_DataType)));

dpnp_min_c<_DataType>(arr, min_arr, res_size, shape, ndim, axis, naxis);
dpnp_max_c<_DataType>(arr, max_arr, res_size, shape, ndim, axis, naxis);
dpnp_subtract_c<_DataType, _DataType, _DataType>(result, max_arr, res_size, res_shape, res_ndim, min_arr, res_size, res_shape, res_ndim, NULL);

dpnp_memory_free_c(min_arr);
dpnp_memory_free_c(max_arr);

}

template <typename _DataType_input, typename _DataType_output>
void dpnp_vander_c(const void* array1_in, void* result1, const size_t size_in, const size_t N, const int increasing)
{
Expand Down Expand Up @@ -588,6 +630,11 @@ void func_map_init_arraycreation(func_map_t& fmap)
fmap[DPNPFuncName::DPNP_FN_ONES_LIKE][eft_C128][eft_C128] = {eft_C128,
(void*)dpnp_ones_like_c<std::complex<double>>};

fmap[DPNPFuncName::DPNP_FN_PTP][eft_INT][eft_INT] = {eft_INT, (void*)dpnp_ptp_c<int>};
fmap[DPNPFuncName::DPNP_FN_PTP][eft_LNG][eft_LNG] = {eft_LNG, (void*)dpnp_ptp_c<long>};
fmap[DPNPFuncName::DPNP_FN_PTP][eft_FLT][eft_FLT] = {eft_FLT, (void*)dpnp_ptp_c<float>};
fmap[DPNPFuncName::DPNP_FN_PTP][eft_DBL][eft_DBL] = {eft_DBL, (void*)dpnp_ptp_c<double>};

fmap[DPNPFuncName::DPNP_FN_VANDER][eft_INT][eft_INT] = {eft_LNG, (void*)dpnp_vander_c<int, long>};
fmap[DPNPFuncName::DPNP_FN_VANDER][eft_LNG][eft_LNG] = {eft_LNG, (void*)dpnp_vander_c<long, long>};
fmap[DPNPFuncName::DPNP_FN_VANDER][eft_FLT][eft_FLT] = {eft_DBL, (void*)dpnp_vander_c<float, double>};
Expand Down
3 changes: 3 additions & 0 deletions dpnp/dparray.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1189,6 +1189,9 @@ cdef class dparray:
"""Return a copy of the array."""
return copy(self, order=order)

def ptp(self, axis=None, out=None, keepdims=numpy._NoValue):
return ptp(self, axis=axis, out=out, keepdims=keepdims)

def tobytes(self, order='C'):
""" Construct Python bytes containing the raw data bytes in the array.

Expand Down
1 change: 1 addition & 0 deletions dpnp/dpnp_algo/dpnp_algo.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ cdef extern from "dpnp_iface_fptr.hpp" namespace "DPNPFuncName": # need this na
DPNP_FN_PLACE
DPNP_FN_POWER
DPNP_FN_PROD
DPNP_FN_PTP
DPNP_FN_PUT
DPNP_FN_QR
DPNP_FN_RADIANS
Expand Down
65 changes: 59 additions & 6 deletions dpnp/dpnp_algo/dpnp_algo_arraycreation.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ __all__ += [
"dpnp_meshgrid",
"dpnp_ones",
"dpnp_ones_like",
"dpnp_ptp",
"dpnp_trace",
"dpnp_tri",
"dpnp_tril",
Expand All @@ -55,12 +56,11 @@ __all__ += [
"dpnp_zeros_like"
]


ctypedef void(*custom_1in_1out_func_ptr_t)(void * , void * , const int , size_t * , size_t * , const size_t, const size_t)
ctypedef void(*ftpr_custom_vander_1in_1out_t)(void *, void * , size_t, size_t, int)
ctypedef void(*custom_indexing_1out_func_ptr_t)(void *, const size_t , const size_t , const int)
ctypedef void(*fptr_dpnp_trace_t)(const void * , void * , const size_t * , const size_t)

ctypedef void(*custom_1in_1out_func_ptr_t)(void *, void * , const int , size_t * , size_t * , const size_t, const size_t)
ctypedef void(*ftpr_custom_vander_1in_1out_t)(void * , void * , size_t, size_t, int)
ctypedef void(*custom_arraycreation_1in_1out_func_ptr_t)(void * , void * , size_t * , size_t, size_t * , size_t, size_t * , size_t)
ctypedef void(*custom_indexing_1out_func_ptr_t)(void * , const size_t , const size_t , const int)
ctypedef void(*fptr_dpnp_trace_t)(const void *, void * , const size_t * , const size_t)

cpdef utils.dpnp_descriptor dpnp_copy(utils.dpnp_descriptor x1):
return call_fptr_1in_1out(DPNP_FN_COPY, x1, x1.shape)
Expand Down Expand Up @@ -272,6 +272,59 @@ cpdef utils.dpnp_descriptor dpnp_ones_like(result_shape, result_dtype):
return call_fptr_1out(DPNP_FN_ONES_LIKE, utils._object_to_tuple(result_shape), result_dtype)


cpdef dpnp_ptp(utils.dpnp_descriptor arr, axis=None):
cdef shape_type_c shape_arr = arr.shape
cdef shape_type_c output_shape
if axis is None:
axis_ = axis
output_shape = (1,)
else:
if isinstance(axis, int):
if axis < 0:
axis_ = tuple([arr.ndim - axis])
else:
axis_ = tuple([axis])
else:
_axis_ = []
for i in range(len(axis)):
if axis[i] < 0:
_axis_.append(arr.ndim - axis[i])
else:
_axis_.append(axis[i])
axis_ = tuple(_axis_)

out_shape = []
ind = 0
for id, shape_axis in enumerate(shape_arr):
if id not in axis_:
out_shape.append(shape_axis)
output_shape = tuple(out_shape)

cdef DPNPFuncType param1_type = dpnp_dtype_to_DPNPFuncType(arr.dtype)

cdef DPNPFuncData kernel_data = get_dpnp_function_ptr(DPNP_FN_PTP, param1_type, param1_type)

cdef utils.dpnp_descriptor result = utils.create_output_descriptor(output_shape, kernel_data.return_type, None)

cdef custom_arraycreation_1in_1out_func_ptr_t func = <custom_arraycreation_1in_1out_func_ptr_t > kernel_data.ptr

cdef shape_type_c axis1
cdef Py_ssize_t axis_size = 0
cdef shape_type_c axis2 = axis1
if axis_ is not None:
axis1 = axis_
axis2.reserve(len(axis1))
for shape_it in axis1:
if shape_it < 0:
raise ValueError("DPNP dparray::__init__(): Negative values in 'shape' are not allowed")
axis2.push_back(shape_it)
axis_size = len(axis1)

func(result.get_data(), arr.get_data(), < size_t * > output_shape.data(), result.ndim, < size_t * > shape_arr.data(), arr.ndim, < size_t * > axis2.data(), axis_size)

return result


cpdef utils.dpnp_descriptor dpnp_trace(utils.dpnp_descriptor arr, offset=0, axis1=0, axis2=1, dtype=None, out=None):
if dtype is None:
dtype_ = arr.dtype
Expand Down
30 changes: 30 additions & 0 deletions dpnp/dpnp_iface_arraycreation.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
"ogrid",
"ones",
"ones_like",
"ptp",
"trace",
"tri",
"tril",
Expand Down Expand Up @@ -1082,6 +1083,35 @@ def ones_like(x1, dtype=None, order='C', subok=False, shape=None):
return call_origin(numpy.ones_like, x1, dtype, order, subok, shape)


def ptp(arr, axis=None, out=None, keepdims=numpy._NoValue):
"""
Range of values (maximum - minimum) along an axis.

For full documentation refer to :obj:`numpy.ptp`.

Limitations
-----------
Input array is supported as :obj:`dpnp.ndarray`.
Parameters ``out`` and ``keepdims`` are supported only with default values.
"""
arr_desc = dpnp.get_dpnp_descriptor(arr)
if not arr_desc:
pass
elif axis is not None and not isinstance(axis, int):
pass
elif out is not None:
pass
elif keepdims is not numpy._NoValue:
pass
else:
result_obj = dpnp_ptp(arr_desc, axis=axis).get_pyobj()
result = dpnp.convert_single_elem_array_to_scalar(result_obj)

return result

return call_origin(numpy.ptp, arr, axis, out, keepdims)


def trace(x1, offset=0, axis1=0, axis2=1, dtype=None, out=None):
"""
Return the sum along diagonals of the array.
Expand Down
7 changes: 0 additions & 7 deletions tests/skipped_tests.tbl
Original file line number Diff line number Diff line change
Expand Up @@ -1584,10 +1584,3 @@ tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentil
tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_scalar_q
tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_tuple_axis
tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_uxpected_interpolation
tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_ptp_all
tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_ptp_all_nan
tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_ptp_axis0
tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_ptp_axis1
tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_ptp_axis2
tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_ptp_axis_large
tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_ptp_nan
7 changes: 0 additions & 7 deletions tests/skipped_tests_gpu.tbl
Original file line number Diff line number Diff line change
Expand Up @@ -1951,10 +1951,3 @@ tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentil
tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_scalar_q
tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_tuple_axis
tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_uxpected_interpolation
tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_ptp_all
tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_ptp_all_nan
tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_ptp_axis0
tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_ptp_axis1
tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_ptp_axis2
tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_ptp_axis_large
tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_ptp_nan