Skip to content

Copy usm_ndarray fails with order='K' #1350

Closed
@antonwolfy

Description

@antonwolfy

Below example is not working when both copy=True and order='K' are passed to dpt.asarray:

a = dpt.ones((2, 4, 3))
b = dpt.permute_dims(a, (2, 0, 1))
c = dpt.asarray(b, copy=True, order='K')
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[31], line 1
----> 1 c = dpt.asarray(b, copy=True, order='K')

File ~/miniconda3/envs/dpnp_dev/lib/python3.9/site-packages/dpctl/tensor/_ctors.py:580, in asarray(obj, dtype, device, copy, usm_type, sycl_queue, order)
    578 # handle instance(obj, usm_ndarray)
    579 if isinstance(obj, dpt.usm_ndarray):
--> 580     return _asarray_from_usm_ndarray(
    581         obj,
    582         dtype=dtype,
    583         copy=copy,
    584         usm_type=usm_type,
    585         sycl_queue=sycl_queue,
    586         order=order,
    587     )
    588 if hasattr(obj, "__sycl_usm_array_interface__"):
    589     ary = _usm_ndarray_from_suai(obj)

File ~/miniconda3/envs/dpnp_dev/lib/python3.9/site-packages/dpctl/tensor/_ctors.py:198, in _asarray_from_usm_ndarray(usm_ndary, dtype, copy, usm_type, sycl_queue, order)
    196 eq = dpctl.utils.get_execution_queue([usm_ndary.sycl_queue, copy_q])
    197 if eq is not None:
--> 198     hev, _ = ti._copy_usm_ndarray_into_usm_ndarray(
    199         src=usm_ndary, dst=res, sycl_queue=eq
    200     )
    201     hev.wait()
    202 else:

ValueError: Destination array can not accomodate all the elements of source array.

# while with copy=False or order='C' all works fine:
c = dpt.asarray(b, copy=False, order='K')
c is b
# Out: True

c = dpt.asarray(b, copy=True, order='C')
c.flags.c_contiguous
# Out: True

dpctl.__version__
# Out: '0.14.6dev3+4.g9afdb5802'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions