Skip to content

Commit 851d25a

Browse files
author
Vahid Tavanashad
committed
avoid additionacopy to host when obj is NumPy, list, etc
1 parent 132728d commit 851d25a

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

dpnp/dpnp_iface_manipulation.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1417,23 +1417,29 @@ def delete(arr, obj, axis=None):
14171417

14181418
if isinstance(obj, (int, dpnp.integer)) and not isinstance(obj, bool):
14191419
single_value = True
1420+
indices = obj
14201421
else:
14211422
single_value = False
14221423
is_array = isinstance(obj, (dpnp_array, numpy.ndarray, dpt.usm_ndarray))
1423-
obj = dpnp.asarray(obj, sycl_queue=exec_q, usm_type=usm_type)
1424+
indices = dpnp.asarray(obj, sycl_queue=exec_q, usm_type=usm_type)
14241425
# if `obj` is originally an empty list, after converting it into
14251426
# an array, it will have float dtype, so we need to change its dtype
14261427
# to integer. However, if `obj` is originally an empty array with
14271428
# float dtype, it is a mistake by user and it will raise an error later
1428-
if obj.size == 0 and not is_array:
1429-
obj = obj.astype(dpnp.intp)
1430-
elif obj.size == 1 and obj.dtype.kind in "ui":
1429+
if indices.size == 0 and not is_array:
1430+
indices = indices.astype(dpnp.intp)
1431+
elif indices.size == 1 and indices.dtype.kind in "ui":
14311432
# For a size 1 integer array we can use the single-value path
14321433
# (most dtypes, except boolean, should just fail later).
1433-
obj = obj.item()
1434+
if isinstance(obj, (dpnp_array, dpt.usm_ndarray)):
1435+
indices = indices.item()
1436+
else:
1437+
indices = numpy.asarray(obj).item()
14341438
single_value = True
14351439

1436-
return _delete_without_slice(arr, obj, axis, single_value, exec_q, usm_type)
1440+
return _delete_without_slice(
1441+
arr, indices, axis, single_value, exec_q, usm_type
1442+
)
14371443

14381444

14391445
def dsplit(ary, indices_or_sections):

0 commit comments

Comments
 (0)