Allow asarray to work on sequences of usm_array#1139
Allow asarray to work on sequences of usm_array#1139oleksandr-pavlyk merged 9 commits intomasterfrom
Conversation
|
View rendered docs @ https://intelpython.github.io/dpctl/pulls/1139/index.html |
|
Array API standard conformance tests for dpctl=0.14.3dev0=py310h76be34b_24 ran successfully. |
import dpctl.tensor as dpt
import dpnp
dpt.asarray([dpnp.ones(3)])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/localdisk/work/npolina/ws/dpctl/dpctl/tensor/_ctors.py", line 543, in asarray
seq_shape, seq_dt, devs = _array_info_sequence(obj)
File "/localdisk/work/npolina/ws/dpctl/dpctl/tensor/_ctors.py", line 85, in _array_info_sequence
el_dim, el_dt, el_dev = _array_info_dispatch(el)
File "/localdisk/work/npolina/ws/dpctl/dpctl/tensor/_ctors.py", line 75, in _array_info_dispatch
raise ValueError(type(obj))
ValueError: <class 'dpnp.dpnp_array.dpnp_array'> |
This should be fixed now: In [1]: import dpctl.tensor as dpt, dpnp
In [2]: dpt.asarray([dpnp.ones(3)])
Out[2]: usm_ndarray([[1., 1., 1.]], dtype=float32)
In [3]: dpnp.asarray([dpnp.ones(3)])
Out[3]: array([[1., 1., 1.]], dtype=float32) |
|
Array API standard conformance tests for dpctl=0.14.3dev0=py310h76be34b_33 ran successfully. |
>>> dpnp.array(dpnp.ones(0))
array([])
>>> dpnp.array([dpnp.ones(0)])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/nfs/site/home/npolina/work/ws/dpnp_bench/dpnp/dpnp/dpnp_iface_arraycreation.py", line 208, in array
return dpnp_container.asarray(x1,
File "/nfs/site/home/npolina/work/ws/dpnp_bench/dpnp/dpnp/dpnp_container.py", line 100, in asarray
array_obj = dpt.asarray(x1_obj,
File "/nfs/site/home/npolina/work/ws/dpctl/dpctl/tensor/_ctors.py", line 561, in asarray
seq_shape, seq_dt, devs = _array_info_sequence(obj)
File "/nfs/site/home/npolina/work/ws/dpctl/dpctl/tensor/_ctors.py", line 86, in _array_info_sequence
el_dim, el_dt, el_dev = _array_info_dispatch(el)
File "/nfs/site/home/npolina/work/ws/dpctl/dpctl/tensor/_ctors.py", line 74, in _array_info_dispatch
usm_ar = _usm_ndarray_from_suai(obj)
File "/nfs/site/home/npolina/work/ws/dpctl/dpctl/tensor/_ctors.py", line 226, in _usm_ndarray_from_suai
membuf = dpm.as_usm_memory(obj)
File "dpctl/memory/_memory.pyx", line 823, in dpctl.memory._memory.as_usm_memory
File "dpctl/memory/_memory.pyx", line 208, in dpctl.memory._memory._Memory._cinit_other
File "dpctl/memory/_sycl_usm_array_interface_utils.pxi", line 199, in dpctl.memory._memory._USMBufferData.from_sycl_usm_ary_iface
File "dpctl/memory/_sycl_usm_array_interface_utils.pxi", line 97, in dpctl.memory._memory._pointers_from_shape_and_stride
ValueError: Array shape elements need to be positive |
|
Thank for tracing this down, @npolina4 ! A simpler reproducer: |
|
Array API standard conformance tests for dpctl=0.14.3dev0=py310h76be34b_37 ran successfully. |
In [1]: import dpnp
In [2]: x = dpnp.array([1, 2, 3], device='cpu')
In [3]: dpnp.asarray(x)
Out[3]: array([1, 2, 3])
In [4]: dpnp.asarray([x])
RuntimeError: Unrecogized typenum 17 encountered. |
|
@npolina4 This must be a bug in
The type number 17 corresponds to type |
b9e3ea7 to
a0a341c
Compare
Examples: ``` import dpctl.tensor as dpt m = dpt.ones((2,4), dtype='i4') w = dpt.zeros(4) v = dpt.full(4, -1) ar = dpt.asarray([m, [w, v]]) ar2 = dpt.asarray([m, [w, v]], device='cpu') ```
``` In [1]: import dpctl.tensor._tensor_impl as ti, dpctl.tensor as dpt, dpnp In [2]: dpt.asarray([dpnp.ones(3)]) Out[2]: usm_ndarray([[1., 1., 1.]], dtype=float32) In [3]: dpnp.asarray([dpnp.ones(3)]) Out[3]: array([[1., 1., 1.]], dtype=float32) ```
a0a341c to
3036a67
Compare
| f"does not support {dtype} natively." | ||
| ) | ||
| dtype = _mapped_dt | ||
| if order in "KA": |
There was a problem hiding this comment.
| if order in "KA": | |
| if order in ("K", "A"): |
There was a problem hiding this comment.
Using str appears faster overall:
In [1]: t = "C"
In [2]: %timeit t in ("K", "A")
40.3 ns ± 0.768 ns per loop (mean ± std. dev. of 7 runs, 10,000,000 loops each)
In [3]: %timeit t in "KA"
26.9 ns ± 0.518 ns per loop (mean ± std. dev. of 7 runs, 10,000,000 loops each)
In [4]: %timeit t in ("K", "A")
40.3 ns ± 0.486 ns per loop (mean ± std. dev. of 7 runs, 10,000,000 loops each)
In [5]: %timeit t in "KA"
27.6 ns ± 1.17 ns per loop (mean ± std. dev. of 7 runs, 10,000,000 loops each)
In [6]: t = "K"
In [7]: %timeit t in ("K", "A")
25.7 ns ± 0.39 ns per loop (mean ± std. dev. of 7 runs, 10,000,000 loops each)
In [8]: %timeit t in "KA"
26.2 ns ± 0.488 ns per loop (mean ± std. dev. of 7 runs, 10,000,000 loops each)
|
Array API standard conformance tests for dpctl=0.14.3dev0=py310h76be34b_39 ran successfully. |
|
Array API standard conformance tests for dpctl=0.14.3dev0=py310h76be34b_39 ran successfully. |
import dpnp
import dpctl.tensor as dpt
x = dpnp.ones((3,3), device='cpu')
dpt.asarray([x], device='gpu')
RuntimeError: Unrecogized typenum 17 encountered. |
|
Thank you @npolina4 for thorough review. I have fixed the underlying issue. The reported error can be reproduced without involvement of import dpctl.tensor as dpt, numpy as np
u = dpt.empty(5)
n = np.empty(5, dtype="O")
u[...] = n # raises RuntimeError: Unrecogized typenum 17 encountered. which trips cascade of other exceptions |
|
Array API standard conformance tests for dpctl=0.14.3dev0=py310h76be34b_41 ran successfully. |
|
Deleted rendered PR docs from intelpython.github.com/dpctl, latest should be updated shortly. 🤞 |
|
Array API standard conformance tests for dpctl=0.14.3dev0=py310h76be34b_46 ran successfully. |
Closes gh-1134