Skip to content

Nonzero regression #1323

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

Merged
merged 2 commits into from
Aug 2, 2023
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
3 changes: 2 additions & 1 deletion dpctl/tensor/_copy_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,9 +517,10 @@ def _nonzero_impl(ary):
mask_nelems, dtype=cumsum_dt, sycl_queue=exec_q, order="C"
)
mask_count = ti.mask_positions(ary, cumsum, sycl_queue=exec_q)
indexes_dt = ti.default_device_int_type(exec_q.sycl_device)
indexes = dpt.empty(
(ary.ndim, mask_count),
dtype=cumsum.dtype,
dtype=indexes_dt,
usm_type=usm_type,
sycl_queue=exec_q,
order="C",
Expand Down
12 changes: 12 additions & 0 deletions dpctl/tests/test_usm_ndarray_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1345,3 +1345,15 @@ def test_nonzero_arg_validation():
dpt.nonzero(list())
with pytest.raises(ValueError):
dpt.nonzero(dpt.asarray(1))


def test_nonzero_dtype():
"See gh-1322"
get_queue_or_skip()
x = dpt.ones((3, 4))
idx, idy = dpt.nonzero(x)
# create array using device's
# default integral data type
ref = dpt.arange(8)
assert idx.dtype == ref.dtype
assert idy.dtype == ref.dtype