Skip to content

Commit d9cfb43

Browse files
array_info_sequence handles empty sequences as host data (#694)
* array_info_sequence should handle empty sequences as host data Added a test for this input * Fixes #690 Since bool is a subclass of int, the lack of missing test for instance of bool was being handled by test for instance of int. Fixed implementation, added a test.
2 parents cd85369 + 5f279d6 commit d9cfb43

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

dpctl/tensor/_ctors.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ def _array_info_dispatch(obj):
3232
return obj.shape, obj.dtype, _host_set
3333
elif isinstance(obj, range):
3434
return (len(obj),), int, _host_set
35+
elif isinstance(obj, bool):
36+
return _empty_tuple, bool, _host_set
3537
elif isinstance(obj, float):
3638
return _empty_tuple, float, _host_set
3739
elif isinstance(obj, int):
@@ -63,6 +65,9 @@ def _array_info_sequence(li):
6365
raise ValueError(
6466
"Inconsistent dimensions, {} and {}".format(dim, el_dim)
6567
)
68+
if dim is None:
69+
dim = tuple()
70+
device = _host_set
6671
return (n,) + dim, dt, device
6772

6873

dpctl/tests/test_tensor_asarray.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,17 @@ def test_asarray_from_sequence():
8080
Y = dpt.asarray(X, usm_type="device")
8181
assert type(Y) is dpt.usm_ndarray
8282
assert Y.ndim == 2
83+
assert Y.shape == (len(X), 2)
84+
85+
X = []
86+
Y = dpt.asarray(X, usm_type="device")
87+
assert type(Y) is dpt.usm_ndarray
88+
assert Y.shape == (0,)
89+
90+
X = [True, False]
91+
Y = dpt.asarray(X, usm_type="device")
92+
assert type(Y) is dpt.usm_ndarray
93+
assert Y.dtype.kind == "b"
8394

8495

8596
def test_asarray_from_object_with_suai():

0 commit comments

Comments
 (0)