dpctl icon indicating copy to clipboard operation
dpctl copied to clipboard

Shape setter does not work with negative shape

Open antonwolfy opened this issue 1 year ago • 0 comments

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]

antonwolfy avatar May 28 '24 17:05 antonwolfy