From acadbd1b294155c6fa4474e7dddb267e0006caf7 Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Tue, 30 Nov 2021 08:53:38 -0600 Subject: [PATCH] Fixed type inferencing for nest sequences with no elements Fixed #696 ```python In [3]: import dpctl.tensor as dpt In [4]: dpt.asarray( [[],]*2) Out[4]: In [5]: Out[4].dtype Out[5]: dtype('float64') ``` --- dpctl/tensor/_ctors.py | 1 + dpctl/tests/test_tensor_asarray.py | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/dpctl/tensor/_ctors.py b/dpctl/tensor/_ctors.py index 5126f40837..d0cce717b0 100644 --- a/dpctl/tensor/_ctors.py +++ b/dpctl/tensor/_ctors.py @@ -67,6 +67,7 @@ def _array_info_sequence(li): ) if dim is None: dim = tuple() + dt = float device = _host_set return (n,) + dim, dt, device diff --git a/dpctl/tests/test_tensor_asarray.py b/dpctl/tests/test_tensor_asarray.py index 8c61fc9f13..d8c6f9d7ce 100644 --- a/dpctl/tests/test_tensor_asarray.py +++ b/dpctl/tests/test_tensor_asarray.py @@ -87,6 +87,11 @@ def test_asarray_from_sequence(): assert type(Y) is dpt.usm_ndarray assert Y.shape == (0,) + X = [[], []] + Y = dpt.asarray(X, usm_type="device") + assert type(Y) is dpt.usm_ndarray + assert Y.shape == (2, 0) + X = [True, False] Y = dpt.asarray(X, usm_type="device") assert type(Y) is dpt.usm_ndarray