IntelPython / dpctl

Python SYCL bindings and SYCL-based Python Array API library
https://intelpython.github.io/dpctl/
Apache License 2.0
99 stars 30 forks source link

`dpt.usm_ndarray` does not support order `"K"` #1764

Closed antonwolfy closed 2 months ago

antonwolfy commented 2 months ago

The example below points on different range supported values for order keyword passed into asarray function and usm_ndarray constructor:

import numpy, dpctl, dpctl.tensor as dpt

dpctl.__version__
# Out: '0.18.0dev0+158.g7450558d25'

a = dpt.ones((2, 5), order='F')

# order="K" works for asarray:
b = dpt.asarray(a, order="K")

# but fails with usm_ndarray constructor
c = dpt.usm_ndarray(a.shape, buffer=a, order="K")
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[13], line 1
----> 1 c = dpt.usm_ndarray(a.shape, buffer=a, order="K")

File dpctl/tensor/_usmarray.pyx:264, in dpctl.tensor._usmarray.usm_ndarray.__cinit__()

ValueError: Unsupported order='K' given. Supported values are 'C' or 'F'.

# for numpy both use cases are supporting
a = numpy.ones((2, 5), order="F")
b = numpy.asarray(a, order="K")
c = numpy.ndarray(a.shape, buffer=a, order="K")
oleksandr-pavlyk commented 2 months ago

usm_ndarray constructor is not intended for use by end-user. Python Array API constructors should be used instead.

Support for order "K" does not make sense for dpctl, because buffer keyword is always interpreted as an untyped 1D memory blob.

@antonwolfy Feel free to close this ticket.

antonwolfy commented 2 months ago

@oleksandr-pavlyk, it's clear now, thank you!