Skip to content

Fix nonzero result dtype win #1336

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 3 commits into from
Aug 11, 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
2 changes: 1 addition & 1 deletion dpctl/tensor/_copy_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ 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_dt = ti.default_device_index_type(exec_q.sycl_device)
indexes = dpt.empty(
(ary.ndim, mask_count),
dtype=indexes_dt,
Expand Down
11 changes: 11 additions & 0 deletions dpctl/tensor/libtensor/source/device_support_queries.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ std::string _default_device_bool_type(sycl::device)
return "b1";
}

std::string _default_device_index_type(sycl::device)
{
return "i8";
}

sycl::device _extract_device(py::object arg)
{
auto const &api = dpctl::detail::dpctl_capi::get();
Expand Down Expand Up @@ -115,6 +120,12 @@ std::string default_device_complex_type(py::object arg)
return _default_device_complex_type(d);
}

std::string default_device_index_type(py::object arg)
{
sycl::device d = _extract_device(arg);
return _default_device_index_type(d);
}

} // namespace py_internal
} // namespace tensor
} // namespace dpctl
1 change: 1 addition & 0 deletions dpctl/tensor/libtensor/source/device_support_queries.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ extern std::string default_device_fp_type(py::object);
extern std::string default_device_int_type(py::object);
extern std::string default_device_bool_type(py::object);
extern std::string default_device_complex_type(py::object);
extern std::string default_device_index_type(py::object);

} // namespace py_internal
} // namespace tensor
Expand Down
6 changes: 5 additions & 1 deletion dpctl/tensor/libtensor/source/tensor_py.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,13 @@ PYBIND11_MODULE(_tensor_impl, m)

m.def("default_device_complex_type",
dpctl::tensor::py_internal::default_device_complex_type,
"Gives default complex floating point type support by device.",
"Gives default complex floating point type supported by device.",
py::arg("dev"));

m.def("default_device_index_type",
dpctl::tensor::py_internal::default_device_index_type,
"Gives default index type supported by device.", py::arg("dev"));

auto tril_fn = [](dpctl::tensor::usm_ndarray src,
dpctl::tensor::usm_ndarray dst, py::ssize_t k,
sycl::queue exec_q,
Expand Down
9 changes: 5 additions & 4 deletions dpctl/tests/test_usm_ndarray_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import dpctl
import dpctl.tensor as dpt
import dpctl.tensor._tensor_impl as ti
from dpctl.utils import ExecutionPlacementError

_all_dtypes = [
Expand Down Expand Up @@ -1353,7 +1354,7 @@ def test_nonzero_dtype():
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
# default index data type
index_dt = dpt.dtype(ti.default_device_index_type(x.sycl_queue))
assert idx.dtype == index_dt
assert idy.dtype == index_dt