Skip to content

Commit ce12203

Browse files
authored
Merge branch 'master' into logspace_geomspace
2 parents 6e792b0 + 79cb518 commit ce12203

15 files changed

+318
-347
lines changed

.github/workflows/conda-package.yml

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ env:
1313
# TODO: to add test_arraymanipulation.py back to the scope once crash on Windows is gone
1414
TEST_SCOPE: >-
1515
test_arraycreation.py
16+
test_amin_amax.py
1617
test_dot.py
1718
test_dparray.py
1819
test_copy.py

dpnp/backend/include/dpnp_iface_fptr.hpp

+12-14
Original file line numberDiff line numberDiff line change
@@ -212,20 +212,18 @@ enum class DPNPFuncName : size_t
212212
DPNP_FN_MATRIX_RANK_EXT, /**< Used in numpy.linalg.matrix_rank() impl,
213213
requires extra parameters */
214214
DPNP_FN_MAX, /**< Used in numpy.max() impl */
215-
DPNP_FN_MAX_EXT, /**< Used in numpy.max() impl, requires extra parameters */
216-
DPNP_FN_MAXIMUM, /**< Used in numpy.fmax() impl */
217-
DPNP_FN_MAXIMUM_EXT, /**< Used in numpy.fmax() impl , requires extra
218-
parameters */
219-
DPNP_FN_MEAN, /**< Used in numpy.mean() impl */
220-
DPNP_FN_MEDIAN, /**< Used in numpy.median() impl */
221-
DPNP_FN_MEDIAN_EXT, /**< Used in numpy.median() impl, requires extra
222-
parameters */
223-
DPNP_FN_MIN, /**< Used in numpy.min() impl */
224-
DPNP_FN_MIN_EXT, /**< Used in numpy.min() impl, requires extra parameters */
225-
DPNP_FN_MINIMUM, /**< Used in numpy.fmin() impl */
226-
DPNP_FN_MINIMUM_EXT, /**< Used in numpy.fmax() impl, requires extra
227-
parameters */
228-
DPNP_FN_MODF, /**< Used in numpy.modf() impl */
215+
DPNP_FN_MAXIMUM, /**< Used in numpy.fmax() impl */
216+
DPNP_FN_MAXIMUM_EXT, /**< Used in numpy.fmax() impl , requires extra
217+
parameters */
218+
DPNP_FN_MEAN, /**< Used in numpy.mean() impl */
219+
DPNP_FN_MEDIAN, /**< Used in numpy.median() impl */
220+
DPNP_FN_MEDIAN_EXT, /**< Used in numpy.median() impl, requires extra
221+
parameters */
222+
DPNP_FN_MIN, /**< Used in numpy.min() impl */
223+
DPNP_FN_MINIMUM, /**< Used in numpy.fmin() impl */
224+
DPNP_FN_MINIMUM_EXT, /**< Used in numpy.fmax() impl, requires extra
225+
parameters */
226+
DPNP_FN_MODF, /**< Used in numpy.modf() impl */
229227
DPNP_FN_MODF_EXT, /**< Used in numpy.modf() impl, requires extra parameters
230228
*/
231229
DPNP_FN_MULTIPLY, /**< Used in numpy.multiply() impl */

dpnp/backend/kernels/dpnp_krnl_statistics.cpp

-42
Original file line numberDiff line numberDiff line change
@@ -503,18 +503,6 @@ void (*dpnp_max_default_c)(void *,
503503
const shape_elem_type *,
504504
size_t) = dpnp_max_c<_DataType>;
505505

506-
template <typename _DataType>
507-
DPCTLSyclEventRef (*dpnp_max_ext_c)(DPCTLSyclQueueRef,
508-
void *,
509-
void *,
510-
const size_t,
511-
const shape_elem_type *,
512-
size_t,
513-
const shape_elem_type *,
514-
size_t,
515-
const DPCTLEventVectorRef) =
516-
dpnp_max_c<_DataType>;
517-
518506
template <typename _DataType, typename _ResultType>
519507
DPCTLSyclEventRef dpnp_mean_c(DPCTLSyclQueueRef q_ref,
520508
void *array1_in,
@@ -887,18 +875,6 @@ void (*dpnp_min_default_c)(void *,
887875
const shape_elem_type *,
888876
size_t) = dpnp_min_c<_DataType>;
889877

890-
template <typename _DataType>
891-
DPCTLSyclEventRef (*dpnp_min_ext_c)(DPCTLSyclQueueRef,
892-
void *,
893-
void *,
894-
const size_t,
895-
const shape_elem_type *,
896-
size_t,
897-
const shape_elem_type *,
898-
size_t,
899-
const DPCTLEventVectorRef) =
900-
dpnp_min_c<_DataType>;
901-
902878
template <typename _DataType>
903879
DPCTLSyclEventRef dpnp_nanvar_c(DPCTLSyclQueueRef q_ref,
904880
void *array1_in,
@@ -1283,15 +1259,6 @@ void func_map_init_statistics(func_map_t &fmap)
12831259
fmap[DPNPFuncName::DPNP_FN_MAX][eft_DBL][eft_DBL] = {
12841260
eft_DBL, (void *)dpnp_max_default_c<double>};
12851261

1286-
fmap[DPNPFuncName::DPNP_FN_MAX_EXT][eft_INT][eft_INT] = {
1287-
eft_INT, (void *)dpnp_max_ext_c<int32_t>};
1288-
fmap[DPNPFuncName::DPNP_FN_MAX_EXT][eft_LNG][eft_LNG] = {
1289-
eft_LNG, (void *)dpnp_max_ext_c<int64_t>};
1290-
fmap[DPNPFuncName::DPNP_FN_MAX_EXT][eft_FLT][eft_FLT] = {
1291-
eft_FLT, (void *)dpnp_max_ext_c<float>};
1292-
fmap[DPNPFuncName::DPNP_FN_MAX_EXT][eft_DBL][eft_DBL] = {
1293-
eft_DBL, (void *)dpnp_max_ext_c<double>};
1294-
12951262
fmap[DPNPFuncName::DPNP_FN_MEAN][eft_INT][eft_INT] = {
12961263
eft_DBL, (void *)dpnp_mean_default_c<int32_t, double>};
12971264
fmap[DPNPFuncName::DPNP_FN_MEAN][eft_LNG][eft_LNG] = {
@@ -1340,15 +1307,6 @@ void func_map_init_statistics(func_map_t &fmap)
13401307
fmap[DPNPFuncName::DPNP_FN_MIN][eft_DBL][eft_DBL] = {
13411308
eft_DBL, (void *)dpnp_min_default_c<double>};
13421309

1343-
fmap[DPNPFuncName::DPNP_FN_MIN_EXT][eft_INT][eft_INT] = {
1344-
eft_INT, (void *)dpnp_min_ext_c<int32_t>};
1345-
fmap[DPNPFuncName::DPNP_FN_MIN_EXT][eft_LNG][eft_LNG] = {
1346-
eft_LNG, (void *)dpnp_min_ext_c<int64_t>};
1347-
fmap[DPNPFuncName::DPNP_FN_MIN_EXT][eft_FLT][eft_FLT] = {
1348-
eft_FLT, (void *)dpnp_min_ext_c<float>};
1349-
fmap[DPNPFuncName::DPNP_FN_MIN_EXT][eft_DBL][eft_DBL] = {
1350-
eft_DBL, (void *)dpnp_min_ext_c<double>};
1351-
13521310
fmap[DPNPFuncName::DPNP_FN_NANVAR][eft_INT][eft_INT] = {
13531311
eft_INT, (void *)dpnp_nanvar_default_c<int32_t>};
13541312
fmap[DPNPFuncName::DPNP_FN_NANVAR][eft_LNG][eft_LNG] = {

dpnp/dpnp_algo/dpnp_algo.pxd

-10
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,10 @@ cdef extern from "dpnp_iface_fptr.hpp" namespace "DPNPFuncName": # need this na
106106
DPNP_FN_MATMUL_EXT
107107
DPNP_FN_MATRIX_RANK
108108
DPNP_FN_MATRIX_RANK_EXT
109-
DPNP_FN_MAX
110-
DPNP_FN_MAX_EXT
111109
DPNP_FN_MAXIMUM
112110
DPNP_FN_MAXIMUM_EXT
113111
DPNP_FN_MEDIAN
114112
DPNP_FN_MEDIAN_EXT
115-
DPNP_FN_MIN
116-
DPNP_FN_MIN_EXT
117113
DPNP_FN_MINIMUM
118114
DPNP_FN_MINIMUM_EXT
119115
DPNP_FN_MODF
@@ -369,12 +365,6 @@ Array manipulation routines
369365
cpdef dpnp_descriptor dpnp_repeat(dpnp_descriptor array1, repeats, axes=*)
370366

371367

372-
"""
373-
Statistics functions
374-
"""
375-
cpdef dpnp_descriptor dpnp_min(dpnp_descriptor a, axis)
376-
377-
378368
"""
379369
Sorting functions
380370
"""

dpnp/dpnp_algo/dpnp_algo_statistics.pxi

-171
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@ and the rest of the library
3838
__all__ += [
3939
"dpnp_average",
4040
"dpnp_correlate",
41-
"dpnp_max",
4241
"dpnp_median",
43-
"dpnp_min",
4442
"dpnp_nanvar",
4543
"dpnp_std",
4644
"dpnp_var",
@@ -64,16 +62,6 @@ ctypedef c_dpctl.DPCTLSyclEventRef(*custom_statistic_1in_1out_func_ptr_t)(c_dpct
6462
void *, void * , shape_elem_type * , size_t,
6563
shape_elem_type * , size_t,
6664
const c_dpctl.DPCTLEventVectorRef)
67-
ctypedef c_dpctl.DPCTLSyclEventRef(*custom_statistic_1in_1out_func_ptr_t_max)(c_dpctl.DPCTLSyclQueueRef,
68-
void *,
69-
void * ,
70-
const size_t,
71-
shape_elem_type * ,
72-
size_t,
73-
shape_elem_type * ,
74-
size_t,
75-
const c_dpctl.DPCTLEventVectorRef)
76-
7765

7866
cdef utils.dpnp_descriptor call_fptr_custom_std_var_1in_1out(DPNPFuncName fptr_name, utils.dpnp_descriptor x1, ddof):
7967
cdef shape_type_c x1_shape = x1.shape
@@ -177,86 +165,6 @@ cpdef utils.dpnp_descriptor dpnp_correlate(utils.dpnp_descriptor x1, utils.dpnp_
177165
return result
178166

179167

180-
cdef utils.dpnp_descriptor _dpnp_max(utils.dpnp_descriptor x1, _axis_, shape_type_c result_shape):
181-
cdef shape_type_c x1_shape = x1.shape
182-
cdef DPNPFuncType param1_type = dpnp_dtype_to_DPNPFuncType(x1.dtype)
183-
184-
cdef DPNPFuncData kernel_data = get_dpnp_function_ptr(DPNP_FN_MAX_EXT, param1_type, param1_type)
185-
186-
x1_obj = x1.get_array()
187-
188-
# create result array with type given by FPTR data
189-
cdef utils.dpnp_descriptor result = utils.create_output_descriptor(result_shape,
190-
kernel_data.return_type,
191-
None,
192-
device=x1_obj.sycl_device,
193-
usm_type=x1_obj.usm_type,
194-
sycl_queue=x1_obj.sycl_queue)
195-
196-
result_sycl_queue = result.get_array().sycl_queue
197-
198-
cdef c_dpctl.SyclQueue q = <c_dpctl.SyclQueue> result_sycl_queue
199-
cdef c_dpctl.DPCTLSyclQueueRef q_ref = q.get_queue_ref()
200-
201-
cdef custom_statistic_1in_1out_func_ptr_t_max func = <custom_statistic_1in_1out_func_ptr_t_max > kernel_data.ptr
202-
cdef shape_type_c axis
203-
cdef Py_ssize_t axis_size = 0
204-
cdef shape_type_c axis_ = axis
205-
206-
if _axis_ is not None:
207-
axis = _axis_
208-
axis_.reserve(len(axis))
209-
for shape_it in axis:
210-
axis_.push_back(shape_it)
211-
axis_size = len(axis)
212-
213-
cdef c_dpctl.DPCTLSyclEventRef event_ref = func(q_ref,
214-
x1.get_data(),
215-
result.get_data(),
216-
result.size,
217-
x1_shape.data(),
218-
x1.ndim,
219-
axis_.data(),
220-
axis_size,
221-
NULL) # dep_events_ref
222-
223-
with nogil: c_dpctl.DPCTLEvent_WaitAndThrow(event_ref)
224-
c_dpctl.DPCTLEvent_Delete(event_ref)
225-
226-
return result
227-
228-
229-
cpdef utils.dpnp_descriptor dpnp_max(utils.dpnp_descriptor x1, axis):
230-
cdef shape_type_c x1_shape = x1.shape
231-
cdef shape_type_c output_shape
232-
233-
if axis is None:
234-
axis_ = axis
235-
output_shape.push_back(1)
236-
else:
237-
if isinstance(axis, int):
238-
if axis < 0:
239-
axis_ = tuple([x1.ndim - axis])
240-
else:
241-
axis_ = tuple([axis])
242-
else:
243-
_axis_ = []
244-
for i in range(len(axis)):
245-
if axis[i] < 0:
246-
_axis_.append(x1.ndim - axis[i])
247-
else:
248-
_axis_.append(axis[i])
249-
axis_ = tuple(_axis_)
250-
251-
output_shape.resize(len(x1_shape) - len(axis_), 0)
252-
ind = 0
253-
for id, shape_axis in enumerate(x1_shape):
254-
if id not in axis_:
255-
output_shape[ind] = shape_axis
256-
ind += 1
257-
258-
return _dpnp_max(x1, axis_, output_shape)
259-
260168
cpdef utils.dpnp_descriptor dpnp_median(utils.dpnp_descriptor array1):
261169
cdef shape_type_c x1_shape = array1.shape
262170
cdef DPNPFuncType param1_type = dpnp_dtype_to_DPNPFuncType(array1.dtype)
@@ -301,85 +209,6 @@ cpdef utils.dpnp_descriptor dpnp_median(utils.dpnp_descriptor array1):
301209
return result
302210

303211

304-
cpdef utils.dpnp_descriptor _dpnp_min(utils.dpnp_descriptor x1, _axis_, shape_type_c shape_output):
305-
cdef shape_type_c x1_shape = x1.shape
306-
cdef DPNPFuncType param1_type = dpnp_dtype_to_DPNPFuncType(x1.dtype)
307-
308-
cdef DPNPFuncData kernel_data = get_dpnp_function_ptr(DPNP_FN_MIN_EXT, param1_type, param1_type)
309-
310-
x1_obj = x1.get_array()
311-
312-
cdef utils.dpnp_descriptor result = utils.create_output_descriptor(shape_output,
313-
kernel_data.return_type,
314-
None,
315-
device=x1_obj.sycl_device,
316-
usm_type=x1_obj.usm_type,
317-
sycl_queue=x1_obj.sycl_queue)
318-
319-
result_sycl_queue = result.get_array().sycl_queue
320-
321-
cdef c_dpctl.SyclQueue q = <c_dpctl.SyclQueue> result_sycl_queue
322-
cdef c_dpctl.DPCTLSyclQueueRef q_ref = q.get_queue_ref()
323-
324-
cdef custom_statistic_1in_1out_func_ptr_t_max func = <custom_statistic_1in_1out_func_ptr_t_max > kernel_data.ptr
325-
cdef shape_type_c axis
326-
cdef Py_ssize_t axis_size = 0
327-
cdef shape_type_c axis_ = axis
328-
329-
if _axis_ is not None:
330-
axis = _axis_
331-
axis_.reserve(len(axis))
332-
for shape_it in axis:
333-
if shape_it < 0:
334-
raise ValueError("DPNP algo::_dpnp_min(): Negative values in 'shape' are not allowed")
335-
axis_.push_back(shape_it)
336-
axis_size = len(axis)
337-
338-
cdef c_dpctl.DPCTLSyclEventRef event_ref = func(q_ref,
339-
x1.get_data(),
340-
result.get_data(),
341-
result.size,
342-
x1_shape.data(),
343-
x1.ndim,
344-
axis_.data(),
345-
axis_size,
346-
NULL) # dep_events_ref
347-
348-
with nogil: c_dpctl.DPCTLEvent_WaitAndThrow(event_ref)
349-
c_dpctl.DPCTLEvent_Delete(event_ref)
350-
351-
return result
352-
353-
354-
cpdef utils.dpnp_descriptor dpnp_min(utils.dpnp_descriptor x1, axis):
355-
cdef shape_type_c x1_shape = x1.shape
356-
cdef shape_type_c shape_output
357-
358-
if axis is None:
359-
axis_ = axis
360-
shape_output = (1,)
361-
else:
362-
if isinstance(axis, int):
363-
if axis < 0:
364-
axis_ = tuple([x1.ndim - axis])
365-
else:
366-
axis_ = tuple([axis])
367-
else:
368-
_axis_ = []
369-
for i in range(len(axis)):
370-
if axis[i] < 0:
371-
_axis_.append(x1.ndim - axis[i])
372-
else:
373-
_axis_.append(axis[i])
374-
axis_ = tuple(_axis_)
375-
376-
for id, shape_axis in enumerate(x1_shape):
377-
if id not in axis_:
378-
shape_output.push_back(shape_axis)
379-
380-
return _dpnp_min(x1, axis_, shape_output)
381-
382-
383212
cpdef utils.dpnp_descriptor dpnp_nanvar(utils.dpnp_descriptor arr, ddof):
384213
# dpnp_isnan does not support USM array as input in comparison to dpnp.isnan
385214
cdef utils.dpnp_descriptor mask_arr = dpnp.get_dpnp_descriptor(dpnp.isnan(arr.get_pyobj()),

dpnp/dpnp_algo/dpnp_elementwise_common.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# cython: language_level=3
2-
# distutils: language = c++
31
# -*- coding: utf-8 -*-
42
# *****************************************************************************
53
# Copyright (c) 2023, Intel Corporation

dpnp/dpnp_array.py

+16-9
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
# *****************************************************************************
2626

2727
import dpctl.tensor as dpt
28-
import numpy
2928

3029
import dpnp
3130

@@ -939,11 +938,15 @@ def max(
939938
self,
940939
axis=None,
941940
out=None,
942-
keepdims=numpy._NoValue,
943-
initial=numpy._NoValue,
944-
where=numpy._NoValue,
941+
keepdims=False,
942+
initial=None,
943+
where=True,
945944
):
946-
"""Return the maximum along an axis."""
945+
"""
946+
Return the maximum along an axis.
947+
948+
Refer to :obj:`dpnp.max` for full documentation.
949+
"""
947950

948951
return dpnp.max(self, axis, out, keepdims, initial, where)
949952

@@ -956,11 +959,15 @@ def min(
956959
self,
957960
axis=None,
958961
out=None,
959-
keepdims=numpy._NoValue,
960-
initial=numpy._NoValue,
961-
where=numpy._NoValue,
962+
keepdims=False,
963+
initial=None,
964+
where=True,
962965
):
963-
"""Return the minimum along a given axis."""
966+
"""
967+
Return the minimum along a given axis.
968+
969+
Refer to :obj:`dpnp.min` for full documentation.
970+
"""
964971

965972
return dpnp.min(self, axis, out, keepdims, initial, where)
966973

0 commit comments

Comments
 (0)