Skip to content

Commit 143e3c9

Browse files
vlad-perevezentsevantonwolfy
authored andcommitted
Reuse dpctl.tensor.place for dpnp.place (#1337)
* Reuse dpctl.tensor.place for dpnp.place * Remove unused declaration and usefixtures
1 parent 8e13e36 commit 143e3c9

File tree

9 files changed

+19
-95
lines changed

9 files changed

+19
-95
lines changed

dpnp/backend/include/dpnp_iface_fptr.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,6 @@ enum class DPNPFuncName : size_t
240240
DPNP_FN_PARTITION, /**< Used in numpy.partition() impl */
241241
DPNP_FN_PARTITION_EXT, /**< Used in numpy.partition() impl, requires extra parameters */
242242
DPNP_FN_PLACE, /**< Used in numpy.place() impl */
243-
DPNP_FN_PLACE_EXT, /**< Used in numpy.place() impl, requires extra parameters */
244243
DPNP_FN_POWER, /**< Used in numpy.power() impl */
245244
DPNP_FN_POWER_EXT, /**< Used in numpy.power() impl, requires extra parameters */
246245
DPNP_FN_PROD, /**< Used in numpy.prod() impl */

dpnp/backend/kernels/dpnp_krnl_indexing.cpp

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -546,20 +546,12 @@ void dpnp_place_c(void* arr_in, long* mask_in, void* vals_in, const size_t arr_s
546546
vals_size,
547547
dep_event_vec_ref);
548548
DPCTLEvent_WaitAndThrow(event_ref);
549+
DPCTLEvent_Delete(event_ref);
549550
}
550551

551552
template <typename _DataType>
552553
void (*dpnp_place_default_c)(void*, long*, void*, const size_t, const size_t) = dpnp_place_c<_DataType>;
553554

554-
template <typename _DataType>
555-
DPCTLSyclEventRef (*dpnp_place_ext_c)(DPCTLSyclQueueRef,
556-
void*,
557-
long*,
558-
void*,
559-
const size_t,
560-
const size_t,
561-
const DPCTLEventVectorRef) = dpnp_place_c<_DataType>;
562-
563555
template <typename _DataType, typename _IndecesType, typename _ValueType>
564556
DPCTLSyclEventRef dpnp_put_c(DPCTLSyclQueueRef q_ref,
565557
void* array1_in,
@@ -1017,11 +1009,6 @@ void func_map_init_indexing_func(func_map_t& fmap)
10171009
fmap[DPNPFuncName::DPNP_FN_PLACE][eft_FLT][eft_FLT] = {eft_FLT, (void*)dpnp_place_default_c<float>};
10181010
fmap[DPNPFuncName::DPNP_FN_PLACE][eft_DBL][eft_DBL] = {eft_DBL, (void*)dpnp_place_default_c<double>};
10191011

1020-
fmap[DPNPFuncName::DPNP_FN_PLACE_EXT][eft_INT][eft_INT] = {eft_INT, (void*)dpnp_place_ext_c<int32_t>};
1021-
fmap[DPNPFuncName::DPNP_FN_PLACE_EXT][eft_LNG][eft_LNG] = {eft_LNG, (void*)dpnp_place_ext_c<int64_t>};
1022-
fmap[DPNPFuncName::DPNP_FN_PLACE_EXT][eft_FLT][eft_FLT] = {eft_FLT, (void*)dpnp_place_ext_c<float>};
1023-
fmap[DPNPFuncName::DPNP_FN_PLACE_EXT][eft_DBL][eft_DBL] = {eft_DBL, (void*)dpnp_place_ext_c<double>};
1024-
10251012
fmap[DPNPFuncName::DPNP_FN_PUT][eft_INT][eft_INT] = {eft_INT,
10261013
(void*)dpnp_put_default_c<int32_t, int64_t, int32_t>};
10271014
fmap[DPNPFuncName::DPNP_FN_PUT][eft_LNG][eft_LNG] = {eft_LNG,

dpnp/dpnp_algo/dpnp_algo.pxd

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,6 @@ cdef extern from "dpnp_iface_fptr.hpp" namespace "DPNPFuncName": # need this na
217217
DPNP_FN_PARTITION
218218
DPNP_FN_PARTITION_EXT
219219
DPNP_FN_PLACE
220-
DPNP_FN_PLACE_EXT
221220
DPNP_FN_POWER
222221
DPNP_FN_POWER_EXT
223222
DPNP_FN_PROD

dpnp/dpnp_algo/dpnp_algo_indexing.pyx

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ __all__ += [
4040
"dpnp_diagonal",
4141
"dpnp_fill_diagonal",
4242
"dpnp_indices",
43-
"dpnp_place",
4443
"dpnp_put",
4544
"dpnp_put_along_axis",
4645
"dpnp_putmask",
@@ -78,13 +77,6 @@ ctypedef c_dpctl.DPCTLSyclEventRef(*custom_indexing_2in_1out_func_ptr_t_)(c_dpct
7877
ctypedef c_dpctl.DPCTLSyclEventRef(*custom_indexing_2in_func_ptr_t)(c_dpctl.DPCTLSyclQueueRef,
7978
void *, void * , shape_elem_type * , const size_t,
8079
const c_dpctl.DPCTLEventVectorRef)
81-
ctypedef c_dpctl.DPCTLSyclEventRef(*custom_indexing_3in_func_ptr_t)(c_dpctl.DPCTLSyclQueueRef,
82-
void * ,
83-
void * ,
84-
void * ,
85-
const size_t,
86-
const size_t,
87-
const c_dpctl.DPCTLEventVectorRef)
8880
ctypedef c_dpctl.DPCTLSyclEventRef(*custom_indexing_3in_with_axis_func_ptr_t)(c_dpctl.DPCTLSyclQueueRef,
8981
void * ,
9082
void * ,
@@ -307,41 +299,6 @@ cpdef object dpnp_indices(dimensions):
307299
return dpnp_result
308300

309301

310-
cpdef dpnp_place(dpnp_descriptor arr, object mask, dpnp_descriptor vals):
311-
result_sycl_device, result_usm_type, result_sycl_queue = utils.get_common_usm_allocation(arr, vals)
312-
313-
cdef utils.dpnp_descriptor mask_ = utils_py.create_output_descriptor_py((mask.size,),
314-
dpnp.int64,
315-
None,
316-
device=result_sycl_device,
317-
usm_type=result_usm_type,
318-
sycl_queue=result_sycl_queue)
319-
for i in range(mask.size):
320-
if mask.item(i):
321-
mask_.get_pyobj()[i] = 1
322-
else:
323-
mask_.get_pyobj()[i] = 0
324-
cdef DPNPFuncType param1_type = dpnp_dtype_to_DPNPFuncType(arr.dtype)
325-
326-
cdef DPNPFuncData kernel_data = get_dpnp_function_ptr(DPNP_FN_PLACE_EXT, param1_type, param1_type)
327-
328-
cdef c_dpctl.SyclQueue q = <c_dpctl.SyclQueue> result_sycl_queue
329-
cdef c_dpctl.DPCTLSyclQueueRef q_ref = q.get_queue_ref()
330-
331-
cdef custom_indexing_3in_func_ptr_t func = <custom_indexing_3in_func_ptr_t > kernel_data.ptr
332-
333-
cdef c_dpctl.DPCTLSyclEventRef event_ref = func(q_ref,
334-
arr.get_data(),
335-
mask_.get_data(),
336-
vals.get_data(),
337-
arr.size,
338-
vals.size,
339-
NULL) # dep_events_ref
340-
341-
with nogil: c_dpctl.DPCTLEvent_WaitAndThrow(event_ref)
342-
c_dpctl.DPCTLEvent_Delete(event_ref)
343-
344-
345302
cpdef dpnp_put(dpnp_descriptor x1, object ind, v):
346303
ind_is_list = isinstance(ind, list)
347304

dpnp/dpnp_iface_indexing.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -377,24 +377,26 @@ def nonzero(x, /):
377377
return call_origin(numpy.nonzero, x)
378378

379379

380-
def place(x1, mask, vals):
380+
def place(x, mask, vals, /):
381381
"""
382382
Change elements of an array based on conditional and input values.
383383
For full documentation refer to :obj:`numpy.place`.
384384
385385
Limitations
386386
-----------
387-
Input arrays ``arr`` and ``mask`` are supported as :obj:`dpnp.ndarray`.
388-
Parameter ``vals`` is supported as 1-D sequence.
387+
Parameters `x`, `mask` and `vals` are supported either as
388+
:class:`dpnp.ndarray` or :class:`dpctl.tensor.usm_ndarray`.
389+
Otherwise the function will be executed sequentially on CPU.
389390
"""
390391

391-
x1_desc = dpnp.get_dpnp_descriptor(x1, copy_when_nondefault_queue=False)
392-
mask_desc = dpnp.get_dpnp_descriptor(mask, copy_when_nondefault_queue=False)
393-
vals_desc = dpnp.get_dpnp_descriptor(vals, copy_when_nondefault_queue=False)
394-
if x1_desc and mask_desc and vals_desc:
395-
return dpnp_place(x1_desc, mask, vals_desc)
392+
check_input_type = lambda x: isinstance(x, (dpnp_array, dpt.usm_ndarray))
393+
if check_input_type(x) and check_input_type(mask) and check_input_type(vals):
394+
dpt_array = x.get_array() if isinstance(x, dpnp_array) else x
395+
dpt_mask = mask.get_array() if isinstance(mask, dpnp_array) else mask
396+
dpt_vals = vals.get_array() if isinstance(vals, dpnp_array) else vals
397+
return dpt.place(dpt_array, dpt_mask, dpt_vals)
396398

397-
return call_origin(numpy.place, x1, mask, vals, dpnp_inplace=True)
399+
return call_origin(numpy.place, x, mask, vals, dpnp_inplace=True)
398400

399401

400402
def put(x1, ind, v, mode='raise'):

tests/skipped_tests.tbl

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -508,12 +508,6 @@ tests/third_party/cupy/indexing_tests/test_insert.py::TestFillDiagonal_param_5_{
508508
tests/third_party/cupy/indexing_tests/test_insert.py::TestFillDiagonal_param_6_{shape=(3, 3), val=(2, 2), wrap=True}::test_columnar_slice
509509
tests/third_party/cupy/indexing_tests/test_insert.py::TestFillDiagonal_param_7_{shape=(3, 3), val=(2, 2), wrap=False}::test_columnar_slice
510510
tests/third_party/cupy/indexing_tests/test_insert.py::TestFillDiagonal_param_9_{shape=(2, 2, 2), val=1, wrap=False}::test_1darray
511-
tests/third_party/cupy/indexing_tests/test_insert.py::TestPlaceRaises_param_0_{shape=(7,)}::test_place_empty_value_error
512-
tests/third_party/cupy/indexing_tests/test_insert.py::TestPlaceRaises_param_0_{shape=(7,)}::test_place_shape_unmatch_error
513-
tests/third_party/cupy/indexing_tests/test_insert.py::TestPlaceRaises_param_1_{shape=(2, 3)}::test_place_empty_value_error
514-
tests/third_party/cupy/indexing_tests/test_insert.py::TestPlaceRaises_param_1_{shape=(2, 3)}::test_place_shape_unmatch_error
515-
tests/third_party/cupy/indexing_tests/test_insert.py::TestPlaceRaises_param_2_{shape=(4, 3, 2)}::test_place_empty_value_error
516-
tests/third_party/cupy/indexing_tests/test_insert.py::TestPlaceRaises_param_2_{shape=(4, 3, 2)}::test_place_shape_unmatch_error
517511
tests/third_party/cupy/indexing_tests/test_insert.py::TestPutmaskDifferentDtypes::test_putmask_differnt_dtypes_raises
518512
tests/third_party/cupy/indexing_tests/test_insert.py::TestPutmask::test_putmask_non_equal_shape_raises
519513
tests/third_party/cupy/indexing_tests/test_iterate.py::TestFlatiter::test_next

tests/skipped_tests_gpu.tbl

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,6 @@ tests/test_sycl_queue.py::test_1in_1out[opencl:gpu:0-trapz-data19]
5353
tests/test_sycl_queue.py::test_1in_1out[opencl:cpu:0-trapz-data19]
5454

5555
tests/third_party/cupy/indexing_tests/test_indexing.py::TestIndexing::test_take_no_axis
56-
tests/third_party/cupy/indexing_tests/test_insert.py::TestPlace_param_3_{n_vals=1, shape=(7,)}::test_place
57-
tests/third_party/cupy/indexing_tests/test_insert.py::TestPlace_param_4_{n_vals=1, shape=(2, 3)}::test_place
58-
tests/third_party/cupy/indexing_tests/test_insert.py::TestPlace_param_5_{n_vals=1, shape=(4, 3, 2)}::test_place
59-
tests/third_party/cupy/indexing_tests/test_insert.py::TestPlace_param_6_{n_vals=3, shape=(7,)}::test_place
60-
tests/third_party/cupy/indexing_tests/test_insert.py::TestPlace_param_7_{n_vals=3, shape=(2, 3)}::test_place
61-
tests/third_party/cupy/indexing_tests/test_insert.py::TestPlace_param_8_{n_vals=3, shape=(4, 3, 2)}::test_place
62-
tests/third_party/cupy/indexing_tests/test_insert.py::TestPlace_param_9_{n_vals=15, shape=(7,)}::test_place
63-
tests/third_party/cupy/indexing_tests/test_insert.py::TestPlace_param_10_{n_vals=15, shape=(2, 3)}::test_place
64-
tests/third_party/cupy/indexing_tests/test_insert.py::TestPlace_param_11_{n_vals=15, shape=(4, 3, 2)}::test_place
6556
tests/third_party/cupy/indexing_tests/test_insert.py::TestDiagIndices_param_0_{n=2, ndim=2}::test_diag_indices
6657
tests/third_party/cupy/indexing_tests/test_insert.py::TestDiagIndices_param_1_{n=2, ndim=3}::test_diag_indices
6758
tests/third_party/cupy/indexing_tests/test_insert.py::TestDiagIndices_param_2_{n=2, ndim=1}::test_diag_indices
@@ -702,12 +693,6 @@ tests/third_party/cupy/indexing_tests/test_insert.py::TestFillDiagonal_param_5_{
702693
tests/third_party/cupy/indexing_tests/test_insert.py::TestFillDiagonal_param_6_{shape=(3, 3), val=(2, 2), wrap=True}::test_columnar_slice
703694
tests/third_party/cupy/indexing_tests/test_insert.py::TestFillDiagonal_param_7_{shape=(3, 3), val=(2, 2), wrap=False}::test_columnar_slice
704695
tests/third_party/cupy/indexing_tests/test_insert.py::TestFillDiagonal_param_9_{shape=(2, 2, 2), val=1, wrap=False}::test_1darray
705-
tests/third_party/cupy/indexing_tests/test_insert.py::TestPlaceRaises_param_0_{shape=(7,)}::test_place_empty_value_error
706-
tests/third_party/cupy/indexing_tests/test_insert.py::TestPlaceRaises_param_0_{shape=(7,)}::test_place_shape_unmatch_error
707-
tests/third_party/cupy/indexing_tests/test_insert.py::TestPlaceRaises_param_1_{shape=(2, 3)}::test_place_empty_value_error
708-
tests/third_party/cupy/indexing_tests/test_insert.py::TestPlaceRaises_param_1_{shape=(2, 3)}::test_place_shape_unmatch_error
709-
tests/third_party/cupy/indexing_tests/test_insert.py::TestPlaceRaises_param_2_{shape=(4, 3, 2)}::test_place_empty_value_error
710-
tests/third_party/cupy/indexing_tests/test_insert.py::TestPlaceRaises_param_2_{shape=(4, 3, 2)}::test_place_shape_unmatch_error
711696
tests/third_party/cupy/indexing_tests/test_insert.py::TestPutmaskDifferentDtypes::test_putmask_differnt_dtypes_raises
712697
tests/third_party/cupy/indexing_tests/test_insert.py::TestPutmask::test_putmask_non_equal_shape_raises
713698
tests/third_party/cupy/indexing_tests/test_iterate.py::TestFlatiter::test_next

tests/test_indexing.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ def test_nonzero(array):
127127
assert_array_equal(expected, result)
128128

129129

130-
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
131130
@pytest.mark.parametrize("vals",
132131
[[100, 200],
133132
(100, 200)],
@@ -152,12 +151,12 @@ def test_place1(arr, mask, vals):
152151
ia = dpnp.array(a)
153152
m = numpy.array(mask)
154153
im = dpnp.array(m)
154+
iv = dpnp.array(vals)
155155
numpy.place(a, m, vals)
156-
dpnp.place(ia, im, vals)
156+
dpnp.place(ia, im, iv)
157157
assert_array_equal(a, ia)
158158

159159

160-
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
161160
@pytest.mark.parametrize("vals",
162161
[[100, 200],
163162
[100, 200, 300, 400, 500, 600],
@@ -176,12 +175,12 @@ def test_place2(arr, mask, vals):
176175
ia = dpnp.array(a)
177176
m = numpy.array(mask)
178177
im = dpnp.array(m)
178+
iv = dpnp.array(vals)
179179
numpy.place(a, m, vals)
180-
dpnp.place(ia, im, vals)
180+
dpnp.place(ia, im, iv)
181181
assert_array_equal(a, ia)
182182

183183

184-
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
185184
@pytest.mark.parametrize("vals",
186185
[[100, 200],
187186
[100, 200, 300, 400, 500, 600],
@@ -201,8 +200,9 @@ def test_place3(arr, mask, vals):
201200
ia = dpnp.array(a)
202201
m = numpy.array(mask)
203202
im = dpnp.array(m)
203+
iv = dpnp.array(vals)
204204
numpy.place(a, m, vals)
205-
dpnp.place(ia, im, vals)
205+
dpnp.place(ia, im, iv)
206206
assert_array_equal(a, ia)
207207

208208

tests/third_party/cupy/indexing_tests/test_insert.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class TestPlaceRaises(unittest.TestCase):
3939
# https://github.com/numpy/numpy/pull/5821
4040
@testing.with_requires('numpy>=1.10')
4141
@testing.for_all_dtypes()
42+
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
4243
def test_place_empty_value_error(self, dtype):
4344
for xp in (numpy, cupy):
4445
a = testing.shaped_arange(self.shape, xp, dtype)

0 commit comments

Comments
 (0)