Skip to content

Fixed issue in asarray_from_numpy for uint64 dtype. #949

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 5 commits into from
Oct 21, 2022
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
37 changes: 29 additions & 8 deletions dpctl/tensor/_ctors.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,35 @@ def _asarray_from_usm_ndarray(
order=order,
buffer_ctor_kwargs={"queue": copy_q},
)
# FIXME: call copy_to when implemented
res[(slice(None, None, None),) * res.ndim] = usm_ndary
hev, _ = ti._copy_usm_ndarray_into_usm_ndarray(
src=usm_ndary, dst=res, sycl_queue=copy_q
)
hev.wait()
return res


def _map_to_device_dtype(dt, q):
if dt.char == "?" or np.issubdtype(dt, np.integer):
return dt
d = q.sycl_device
dtc = dt.char
if np.issubdtype(dt, np.floating):
if dtc == "f":
return dt
else:
if dtc == "d" and d.has_aspect_fp64:
return dt
if dtc == "h" and d.has_aspect_fp16:
return dt
return dpt.dtype("f4")
elif np.issubdtype(dt, np.complexfloating):
if dtc == "F":
return dt
if dtc == "D" and d.has_aspect_fp64:
return dt
return dpt.dtype("c8")


def _asarray_from_numpy_ndarray(
ary, dtype=None, usm_type=None, sycl_queue=None, order="K"
):
Expand All @@ -205,10 +229,8 @@ def _asarray_from_numpy_ndarray(
"Please convert the input to an array with numeric data type."
)
if dtype is None:
ary_dtype = ary.dtype
dtype = _get_dtype(dtype, copy_q, ref_type=ary_dtype)
if dtype.itemsize > ary_dtype.itemsize:
dtype = ary_dtype
# deduce device-representable output data type
dtype = _map_to_device_dtype(ary.dtype, copy_q)
f_contig = ary.flags["F"]
c_contig = ary.flags["C"]
fc_contig = f_contig or c_contig
Expand Down Expand Up @@ -244,8 +266,7 @@ def _asarray_from_numpy_ndarray(
order=order,
buffer_ctor_kwargs={"queue": copy_q},
)
# FIXME: call copy_to when implemented
res[(slice(None, None, None),) * res.ndim] = ary
res[...] = ary
return res


Expand Down
6 changes: 6 additions & 0 deletions dpctl/tests/test_usm_ndarray_ctor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1458,3 +1458,9 @@ def test_flags():
f.writable
# check comparison with generic types
f == Ellipsis


def test_asarray_uint64():
Xnp = np.ndarray(1, dtype=np.uint64)
X = dpt.asarray(Xnp)
assert X.dtype == Xnp.dtype