IntelPython / dpctl

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

Shape setter does not work with negative shape #1699

Open antonwolfy opened 1 month ago

antonwolfy commented 1 month ago

The below example reproduces an issue with passing negative shape to the setter:

import numpy, dpctl, dpctl.tensor as dpt

dpctl.__version__
Out: '0.18.0dev0+21.g60fc3eb9d0'

a = dpt.ones(4)
a.shape = [-1]
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[7], line 1
----> 1 a.shape = [-1]

File dpctl/tensor/_usmarray.pyx:582, in dpctl.tensor._usmarray.usm_ndarray.shape.__set__()

TypeError: Can not reshape array of size 4 into (-1,)

but works with positive shape and with reshape and in numpy:

a = dpt.ones(4)

a.shape = [4]
dpt.reshape(a, [-1])

a = numpy.ones(4)
a.shape = [-1]