Skip to content

array_info_sequence handles empty sequences as host data #694

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
Nov 30, 2021
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
5 changes: 5 additions & 0 deletions dpctl/tensor/_ctors.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ def _array_info_dispatch(obj):
return obj.shape, obj.dtype, _host_set
elif isinstance(obj, range):
return (len(obj),), int, _host_set
elif isinstance(obj, bool):
return _empty_tuple, bool, _host_set
elif isinstance(obj, float):
return _empty_tuple, float, _host_set
elif isinstance(obj, int):
Expand Down Expand Up @@ -63,6 +65,9 @@ def _array_info_sequence(li):
raise ValueError(
"Inconsistent dimensions, {} and {}".format(dim, el_dim)
)
if dim is None:
dim = tuple()
device = _host_set
return (n,) + dim, dt, device


Expand Down
11 changes: 11 additions & 0 deletions dpctl/tests/test_tensor_asarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,17 @@ def test_asarray_from_sequence():
Y = dpt.asarray(X, usm_type="device")
assert type(Y) is dpt.usm_ndarray
assert Y.ndim == 2
assert Y.shape == (len(X), 2)

X = []
Y = dpt.asarray(X, usm_type="device")
assert type(Y) is dpt.usm_ndarray
assert Y.shape == (0,)

X = [True, False]
Y = dpt.asarray(X, usm_type="device")
assert type(Y) is dpt.usm_ndarray
assert Y.dtype.kind == "b"


def test_asarray_from_object_with_suai():
Expand Down