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

`dpt.reshape` changes strides of input array when reshaping to the same shape #1664

Closed antonwolfy closed 1 month ago

antonwolfy commented 1 month ago

The below example demonstrates different behavior in reshape method of NumPy and dpctl:

import numpy, dpctl, dpctl.tensor as dpt

dpctl.__version__
# Out: '0.17.0dev0+325.g0cb2181547'

a = dpt.ones((2, 1))
a.shape, a.strides
# Out: ((2, 1), (1, 1))

b = dpt.reshape(a, (2, 1))
b.shape, b.strides
# Out: ((2, 1), (1, 0))    # the output strides are changed

a = numpy.ones((2, 1)
a.shape, a.strides
# Out: ((2, 1), (8, 8))

b = numpy.reshape(a, (2, 1))
b.shape, b.strides
# Out: ((2, 1), (8, 8))    # the output strides are the same as for input array "a"

So, the question here if it's expected that the strides of output array might be changed when reshaping to the same shape?