Skip to content

Commit efa348a

Browse files
Fixed examples from PR review by @antonwolfy
``` import dpnp, numpy, dpctl, dpctl.tensor as dpt w = dpt.full(4, -1, device="opencl:gpu") res = dpt.asarray([w, range(4)], dtype="f4") # now correctly infers where to allocate output array ``` ``` import dpctl, dpctl.tensor as dpt m = dpt.zeros((2, 4), dtype="i2", device="cpu") w = dpt.full(4, -1, device="opencl:gpu") res = dpt.asarray([m, [w, range(4)], dtype="f4", device="cpu") ```
1 parent bc50b3b commit efa348a

File tree

1 file changed

+25
-28
lines changed

1 file changed

+25
-28
lines changed

dpctl/tensor/_ctors.py

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,13 @@ def _array_info_dispatch(obj):
6565
return _empty_tuple, int, _host_set
6666
if isinstance(obj, complex):
6767
return _empty_tuple, complex, _host_set
68-
if isinstance(obj, (list, tuple, range)):
68+
if isinstance(
69+
obj,
70+
(
71+
list,
72+
tuple,
73+
),
74+
):
6975
return _array_info_sequence(obj)
7076
if _is_object_with_buffer_protocol(obj):
7177
np_obj = np.array(obj)
@@ -333,7 +339,7 @@ def _usm_types_walker(o, usm_types_list):
333339
return
334340
if isinstance(o, (int, bool, float, complex)):
335341
return
336-
if isinstance(o, (list, tuple)):
342+
if isinstance(o, (list, tuple, range)):
337343
for el in o:
338344
_usm_types_walker(el, usm_types_list)
339345
return
@@ -641,37 +647,28 @@ def asarray(
641647
)
642648
elif len(devs) > 1:
643649
devs = [dev for dev in devs if dev is not None]
644-
if len(devs) == 1:
645-
seq_dev = devs[0]
646-
return _asarray_from_seq_single_device(
647-
obj,
648-
seq_shape,
649-
seq_dt,
650-
seq_dev,
651-
dtype=dtype,
652-
usm_type=usm_type,
653-
sycl_queue=sycl_queue,
654-
order=order,
655-
)
656-
else:
657-
if sycl_queue is None:
650+
if sycl_queue is None:
651+
if len(devs) == 1:
652+
alloc_q = devs[0]
653+
else:
658654
raise dpctl.utils.ExecutionPlacementError(
659655
"Please specify `device` or `sycl_queue` keyword "
660-
"argument to determine where to allocated the "
656+
"argument to determine where to allocate the "
661657
"resulting array."
662658
)
659+
else:
663660
alloc_q = sycl_queue
664-
exec_q = None # force copying via host
665-
return _asarray_from_seq(
666-
obj,
667-
seq_shape,
668-
seq_dt,
669-
alloc_q,
670-
exec_q,
671-
dtype=dtype,
672-
usm_type=usm_type,
673-
order=order,
674-
)
661+
return _asarray_from_seq(
662+
obj,
663+
seq_shape,
664+
seq_dt,
665+
alloc_q,
666+
# force copying via host
667+
None,
668+
dtype=dtype,
669+
usm_type=usm_type,
670+
order=order,
671+
)
675672

676673
raise NotImplementedError(
677674
"Converting Python sequences is not implemented"

0 commit comments

Comments
 (0)