anon-iclr-submission/benchname-bug-localization huggingface dataset:
Repository: intelpython/dpctl
Issue: `dpt.place` wrong behavior with an empty values argument

When we pass an empty `usm_ndarray` for `vals` argument, `dpt.place` replaces the array elements to 0.

The original behavior of `numpy.place` throws `ValueError` exception.

```
#NUMPY
np_arr = np.arange(6)
np_mask = np_arr > 2
np_vals = np.array([], dtype='int32')

#DPT
dpt_arr = dpt.asarray(np_arr)
dpt_mask = dpt.asarray(np_mask)
dpt_vals = dpt.asarray(np_vals)

np.place(np_arr,np_mask,np_vals)
>>ValueError: Cannot insert from an empty array!

dpt.place(dpt_arr,dpt_mask,dpt_vals)
dpt_arr>>>usm_ndarray([0, 1, 2, 0, 0, 0])
```




Changed files:
dpctl/tests/test_usm_ndarray_indexing.py, dpctl/tensor/_indexing_functions.py

diff --git a/dpctl/tensor/_indexing_functions.py b/dpctl/tensor/_indexing_functions.py
index e585d6bf6..18efa4951 100644
--- a/dpctl/tensor/_indexing_functions.py
+++ b/dpctl/tensor/_indexing_functions.py
@@ -293,6 +293,8 @@ def place(arr, mask, vals):
         raise dpctl.utils.ExecutionPlacementError
     if arr.shape != mask.shape or vals.ndim != 1:
         raise ValueError("Array sizes are not as required")
+    if vals.size == 0:
+        raise ValueError("Cannot insert from an empty array!")
     cumsum = dpt.empty(mask.size, dtype="i8", sycl_queue=exec_q)
     nz_count = ti.mask_positions(mask, cumsum, sycl_queue=exec_q)
     if nz_count == 0:
diff --git a/dpctl/tests/test_usm_ndarray_indexing.py b/dpctl/tests/test_usm_ndarray_indexing.py
index b41160d3d..a3a1c54f0 100644
--- a/dpctl/tests/test_usm_ndarray_indexing.py
+++ b/dpctl/tests/test_usm_ndarray_indexing.py
@@ -1201,6 +1201,16 @@ def test_place_subset():
     assert (dpt.asnumpy(x) == expected).all()
 
 
+def test_place_empty_vals_error():
+    get_queue_or_skip()
+    x = dpt.zeros(10, dtype="f4")
+    y = dpt.empty((0,), dtype=x.dtype)
+    sel = dpt.ones(x.size, dtype="?")
+    sel[::2] = False
+    with pytest.raises(ValueError):
+        dpt.place(x, sel, y)
+
+
 def test_nonzero():
     get_queue_or_skip()
     x = dpt.concat((dpt.zeros(3), dpt.ones(4), dpt.zeros(3)))