Skip to content

Commit c082884

Browse files
authored
add putmask (#491)
1 parent 27e94bd commit c082884

File tree

5 files changed

+197
-40
lines changed

5 files changed

+197
-40
lines changed

dpnp/dpnp_algo/dpnp_algo_indexing.pyx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ __all__ += [
4545
"dpnp_nonzero",
4646
"dpnp_place",
4747
"dpnp_put",
48+
"dpnp_putmask",
4849
"dpnp_take",
4950
"dpnp_tril_indices",
5051
"dpnp_tril_indices_from",
@@ -189,6 +190,13 @@ cpdef dpnp_put(input, ind, v):
189190
in_ind = 1
190191

191192

193+
cpdef dpnp_putmask(dparray arr, dparray mask, dparray values):
194+
cpdef int values_size = values.size
195+
for i in range(arr.size):
196+
if mask[i]:
197+
arr[i] = values[i % values_size]
198+
199+
192200
cpdef dparray dpnp_take(dparray input, dparray indices):
193201
indices_size = indices.size
194202
res_array = dparray(indices_size, dtype=input.dtype)

dpnp/dpnp_iface_indexing.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
"nonzero",
5959
"place",
6060
"put",
61+
"putmask",
6162
"take",
6263
"tril_indices",
6364
"tril_indices_from",
@@ -320,6 +321,29 @@ def put(input, ind, v, mode='raise'):
320321
return call_origin(numpy.put, input, ind, v, mode)
321322

322323

324+
def putmask(arr, mask, values):
325+
"""
326+
Changes elements of an array based on conditional and input values.
327+
For full documentation refer to :obj:`numpy.putmask`.
328+
329+
Limitations
330+
-----------
331+
Input arrays ``arr``, ``mask`` and ``values`` are supported as :obj:`dpnp.ndarray`.
332+
"""
333+
334+
if not use_origin_backend(arr):
335+
if not isinstance(arr, dparray):
336+
pass
337+
elif not isinstance(mask, dparray):
338+
pass
339+
elif not isinstance(values, dparray):
340+
pass
341+
else:
342+
return dpnp_putmask(arr, mask, values)
343+
344+
return call_origin(numpy.putmask, arr, mask, values)
345+
346+
323347
def take(input, indices, axis=None, out=None, mode='raise'):
324348
"""
325349
Take elements from an array.

tests/skipped_tests.tbl

Lines changed: 85 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -604,11 +604,19 @@ tests/third_party/cupy/indexing_tests/test_indexing.py::TestSelect::test_select_
604604
tests/third_party/cupy/indexing_tests/test_indexing.py::TestSelect::test_select_odd_shaped_non_broadcastable
605605
tests/third_party/cupy/indexing_tests/test_indexing.py::TestSelect::test_select_type_error_choicelist
606606
tests/third_party/cupy/indexing_tests/test_indexing.py::TestSelect::test_select_type_error_condlist
607-
tests/third_party/cupy/indexing_tests/test_insert.py::TestPutmask::test_putmask_int_mask_scalar_values
608607
tests/third_party/cupy/indexing_tests/test_insert.py::TestPutmask::test_putmask_non_equal_shape_raises
609-
tests/third_party/cupy/indexing_tests/test_insert.py::TestPutmask::test_putmask_scalar_values
610-
tests/third_party/cupy/indexing_tests/test_insert.py::TestPutmaskDifferentDtypes::test_putmask_differnt_dtypes_mask
611-
tests/third_party/cupy/indexing_tests/test_insert.py::TestPutmaskDifferentDtypes::test_putmask_differnt_dtypes_raises
608+
tests/third_party/cupy/indexing_tests/test_insert.py::TestPlace_param_0_{n_vals=0, shape=(7,)}::test_place
609+
tests/third_party/cupy/indexing_tests/test_insert.py::TestPlace_param_1_{n_vals=0, shape=(2, 3)}::test_place
610+
tests/third_party/cupy/indexing_tests/test_insert.py::TestPlace_param_2_{n_vals=0, shape=(4, 3, 2)}::test_place
611+
tests/third_party/cupy/indexing_tests/test_insert.py::TestPlace_param_3_{n_vals=1, shape=(7,)}::test_place
612+
tests/third_party/cupy/indexing_tests/test_insert.py::TestPlace_param_4_{n_vals=1, shape=(2, 3)}::test_place
613+
tests/third_party/cupy/indexing_tests/test_insert.py::TestPlace_param_5_{n_vals=1, shape=(4, 3, 2)}::test_place
614+
tests/third_party/cupy/indexing_tests/test_insert.py::TestPlace_param_6_{n_vals=3, shape=(7,)}::test_place
615+
tests/third_party/cupy/indexing_tests/test_insert.py::TestPlace_param_7_{n_vals=3, shape=(2, 3)}::test_place
616+
tests/third_party/cupy/indexing_tests/test_insert.py::TestPlace_param_8_{n_vals=3, shape=(4, 3, 2)}::test_place
617+
tests/third_party/cupy/indexing_tests/test_insert.py::TestPlace_param_9_{n_vals=15, shape=(7,)}::test_place
618+
tests/third_party/cupy/indexing_tests/test_insert.py::TestPlace_param_10_{n_vals=15, shape=(2, 3)}::test_place
619+
tests/third_party/cupy/indexing_tests/test_insert.py::TestPlace_param_11_{n_vals=15, shape=(4, 3, 2)}::test_place
612620
tests/third_party/cupy/indexing_tests/test_insert.py::TestPlaceRaises_param_0_{shape=(7,)}::test_place_empty_value_error
613621
tests/third_party/cupy/indexing_tests/test_insert.py::TestPlaceRaises_param_0_{shape=(7,)}::test_place_shape_unmatch_error
614622
tests/third_party/cupy/indexing_tests/test_insert.py::TestPlaceRaises_param_1_{shape=(2, 3)}::test_place_empty_value_error
@@ -672,22 +680,7 @@ tests/third_party/cupy/indexing_tests/test_insert.py::TestPutRaises_param_0_{sha
672680
tests/third_party/cupy/indexing_tests/test_insert.py::TestPutRaises_param_1_{shape=(2, 3)}::test_put_inds_overflow_error
673681
tests/third_party/cupy/indexing_tests/test_insert.py::TestPutRaises_param_1_{shape=(2, 3)}::test_put_inds_underflow_error
674682
tests/third_party/cupy/indexing_tests/test_insert.py::TestPutRaises_param_1_{shape=(2, 3)}::test_put_mode_error
675-
tests/third_party/cupy/indexing_tests/test_insert.py::TestPutmaskSameShape_param_0_{shape=(0,)}::test_putmask
676-
tests/third_party/cupy/indexing_tests/test_insert.py::TestPutmaskSameShape_param_1_{shape=(1,)}::test_putmask
677-
tests/third_party/cupy/indexing_tests/test_insert.py::TestPutmaskSameShape_param_2_{shape=(2, 3)}::test_putmask
678-
tests/third_party/cupy/indexing_tests/test_insert.py::TestPutmaskSameShape_param_3_{shape=(2, 3, 4)}::test_putmask
679-
tests/third_party/cupy/indexing_tests/test_insert.py::TestPutmaskDifferentShapes_param_0_{shape=(0,), values_shape=(2,)}::test_putmask
680-
tests/third_party/cupy/indexing_tests/test_insert.py::TestPutmaskDifferentShapes_param_1_{shape=(0,), values_shape=(3, 1)}::test_putmask
681-
tests/third_party/cupy/indexing_tests/test_insert.py::TestPutmaskDifferentShapes_param_2_{shape=(0,), values_shape=(5,)}::test_putmask
682-
tests/third_party/cupy/indexing_tests/test_insert.py::TestPutmaskDifferentShapes_param_3_{shape=(1,), values_shape=(2,)}::test_putmask
683-
tests/third_party/cupy/indexing_tests/test_insert.py::TestPutmaskDifferentShapes_param_4_{shape=(1,), values_shape=(3, 1)}::test_putmask
684-
tests/third_party/cupy/indexing_tests/test_insert.py::TestPutmaskDifferentShapes_param_5_{shape=(1,), values_shape=(5,)}::test_putmask
685-
tests/third_party/cupy/indexing_tests/test_insert.py::TestPutmaskDifferentShapes_param_6_{shape=(2, 3), values_shape=(2,)}::test_putmask
686-
tests/third_party/cupy/indexing_tests/test_insert.py::TestPutmaskDifferentShapes_param_7_{shape=(2, 3), values_shape=(3, 1)}::test_putmask
687-
tests/third_party/cupy/indexing_tests/test_insert.py::TestPutmaskDifferentShapes_param_8_{shape=(2, 3), values_shape=(5,)}::test_putmask
688-
tests/third_party/cupy/indexing_tests/test_insert.py::TestPutmaskDifferentShapes_param_9_{shape=(2, 3, 4), values_shape=(2,)}::test_putmask
689-
tests/third_party/cupy/indexing_tests/test_insert.py::TestPutmaskDifferentShapes_param_10_{shape=(2, 3, 4), values_shape=(3, 1)}::test_putmask
690-
tests/third_party/cupy/indexing_tests/test_insert.py::TestPutmaskDifferentShapes_param_11_{shape=(2, 3, 4), values_shape=(5,)}::test_putmask
683+
tests/third_party/cupy/indexing_tests/test_insert.py::TestPutmaskDifferentDtypes::test_putmask_differnt_dtypes_raises
691684
tests/third_party/cupy/indexing_tests/test_insert.py::TestFillDiagonal_param_0_{shape=(3, 3), val=1, wrap=True}::test_1darray
692685
tests/third_party/cupy/indexing_tests/test_insert.py::TestFillDiagonal_param_0_{shape=(3, 3), val=1, wrap=True}::test_columnar_slice
693686
tests/third_party/cupy/indexing_tests/test_insert.py::TestFillDiagonal_param_1_{shape=(3, 3), val=1, wrap=False}::test_1darray
@@ -876,6 +869,78 @@ tests/third_party/cupy/logic_tests/test_comparison.py::TestComparisonOperator::t
876869
tests/third_party/cupy/logic_tests/test_comparison.py::TestComparisonOperator::test_binary_array_pyscalar
877870
tests/third_party/cupy/logic_tests/test_comparison.py::TestComparisonOperator::test_binary_npscalar_array
878871
tests/third_party/cupy/logic_tests/test_comparison.py::TestComparisonOperator::test_binary_pyscalar_array
872+
tests/third_party/cupy/manipulation_tests/test_basic.py::TestBasic::test_copyto_broadcast
873+
tests/third_party/cupy/manipulation_tests/test_basic.py::TestBasic::test_copyto_where
874+
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_0_{dst_shape=(), src=3.2}::test_copyto
875+
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_0_{dst_shape=(), src=3.2}::test_copyto_where
876+
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_10_{dst_shape=(0,), src=-4}::test_copyto
877+
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_10_{dst_shape=(0,), src=-4}::test_copyto_where
878+
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_11_{dst_shape=(0,), src=True}::test_copyto
879+
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_11_{dst_shape=(0,), src=True}::test_copyto_where
880+
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_12_{dst_shape=(0,), src=False}::test_copyto
881+
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_12_{dst_shape=(0,), src=False}::test_copyto_where
882+
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_13_{dst_shape=(0,), src=(1+1j)}::test_copyto
883+
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_13_{dst_shape=(0,), src=(1+1j)}::test_copyto_where
884+
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_14_{dst_shape=(1,), src=3.2}::test_copyto
885+
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_14_{dst_shape=(1,), src=3.2}::test_copyto_where
886+
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_15_{dst_shape=(1,), src=0}::test_copyto
887+
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_15_{dst_shape=(1,), src=0}::test_copyto_where
888+
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_16_{dst_shape=(1,), src=4}::test_copyto
889+
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_16_{dst_shape=(1,), src=4}::test_copyto_where
890+
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_17_{dst_shape=(1,), src=-4}::test_copyto
891+
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_17_{dst_shape=(1,), src=-4}::test_copyto_where
892+
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_18_{dst_shape=(1,), src=True}::test_copyto
893+
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_18_{dst_shape=(1,), src=True}::test_copyto_where
894+
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_19_{dst_shape=(1,), src=False}::test_copyto
895+
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_19_{dst_shape=(1,), src=False}::test_copyto_where
896+
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_1_{dst_shape=(), src=0}::test_copyto
897+
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_1_{dst_shape=(), src=0}::test_copyto_where
898+
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_20_{dst_shape=(1,), src=(1+1j)}::test_copyto
899+
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_20_{dst_shape=(1,), src=(1+1j)}::test_copyto_where
900+
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_21_{dst_shape=(1, 1), src=3.2}::test_copyto
901+
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_21_{dst_shape=(1, 1), src=3.2}::test_copyto_where
902+
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_22_{dst_shape=(1, 1), src=0}::test_copyto
903+
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_22_{dst_shape=(1, 1), src=0}::test_copyto_where
904+
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_23_{dst_shape=(1, 1), src=4}::test_copyto
905+
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_23_{dst_shape=(1, 1), src=4}::test_copyto_where
906+
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_24_{dst_shape=(1, 1), src=-4}::test_copyto
907+
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_24_{dst_shape=(1, 1), src=-4}::test_copyto_where
908+
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_25_{dst_shape=(1, 1), src=True}::test_copyto
909+
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_25_{dst_shape=(1, 1), src=True}::test_copyto_where
910+
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_26_{dst_shape=(1, 1), src=False}::test_copyto
911+
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_26_{dst_shape=(1, 1), src=False}::test_copyto_where
912+
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_27_{dst_shape=(1, 1), src=(1+1j)}::test_copyto
913+
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_27_{dst_shape=(1, 1), src=(1+1j)}::test_copyto_where
914+
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_28_{dst_shape=(2, 2), src=3.2}::test_copyto
915+
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_28_{dst_shape=(2, 2), src=3.2}::test_copyto_where
916+
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_29_{dst_shape=(2, 2), src=0}::test_copyto
917+
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_29_{dst_shape=(2, 2), src=0}::test_copyto_where
918+
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_2_{dst_shape=(), src=4}::test_copyto
919+
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_2_{dst_shape=(), src=4}::test_copyto_where
920+
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_30_{dst_shape=(2, 2), src=4}::test_copyto
921+
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_30_{dst_shape=(2, 2), src=4}::test_copyto_where
922+
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_31_{dst_shape=(2, 2), src=-4}::test_copyto
923+
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_31_{dst_shape=(2, 2), src=-4}::test_copyto_where
924+
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_32_{dst_shape=(2, 2), src=True}::test_copyto
925+
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_32_{dst_shape=(2, 2), src=True}::test_copyto_where
926+
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_33_{dst_shape=(2, 2), src=False}::test_copyto
927+
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_33_{dst_shape=(2, 2), src=False}::test_copyto_where
928+
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_34_{dst_shape=(2, 2), src=(1+1j)}::test_copyto
929+
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_34_{dst_shape=(2, 2), src=(1+1j)}::test_copyto_where
930+
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_3_{dst_shape=(), src=-4}::test_copyto
931+
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_3_{dst_shape=(), src=-4}::test_copyto_where
932+
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_4_{dst_shape=(), src=True}::test_copyto
933+
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_4_{dst_shape=(), src=True}::test_copyto_where
934+
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_5_{dst_shape=(), src=False}::test_copyto
935+
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_5_{dst_shape=(), src=False}::test_copyto_where
936+
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_6_{dst_shape=(), src=(1+1j)}::test_copyto
937+
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_6_{dst_shape=(), src=(1+1j)}::test_copyto_where
938+
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_7_{dst_shape=(0,), src=3.2}::test_copyto
939+
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_7_{dst_shape=(0,), src=3.2}::test_copyto_where
940+
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_8_{dst_shape=(0,), src=0}::test_copyto
941+
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_8_{dst_shape=(0,), src=0}::test_copyto_where
942+
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_9_{dst_shape=(0,), src=4}::test_copyto
943+
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_9_{dst_shape=(0,), src=4}::test_copyto_where
879944
tests/third_party/cupy/manipulation_tests/test_dims.py::TestDims::test_broadcast_to
880945
tests/third_party/cupy/manipulation_tests/test_dims.py::TestDims::test_broadcast_to_fail
881946
tests/third_party/cupy/manipulation_tests/test_dims.py::TestDims::test_broadcast_to_fail_numpy19

0 commit comments

Comments
 (0)