Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an empty value check for dpt.place #1105

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions dpctl/tensor/_indexing_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 10 additions & 0 deletions dpctl/tests/test_usm_ndarray_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down