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.empty_like`, `dpt.zeros_like` and `dpt.ones_like` do not create an array with the same stride as the input array #1714

Closed vtavana closed 1 week ago

vtavana commented 2 weeks ago

Array created using dpt.empty_like, dpt.zeros_like and dpt.ones_like does not have the same stride as the input array.

import dpctl.tensor as dpt, numpy
a = numpy.ones((2, 3, 4))
b = a.transpose(0, 2, 1)
b.strides
# (96, 8, 32)
c = numpy.empty_like(b)
c.strides
# (96, 8, 32)

a_dpt = dpt.ones((2, 3, 4))
b_dpt = dpt.permute_dims(a_dpt, (0, 2, 1))
b_dpt.strides
# (12, 1, 4)
c = dpt.empty_like(b_dpt)
c.strides
# (12, 3, 1)
vtavana commented 1 week ago

These functions have order="C" aas the default value. Even NumPy with order="K" in does not guarantee the output to have the same strides as input.

import numpy
a = numpy.ones((10,8))
b = a[::2,::2]
b.strides
# (128, 16)
c = numpy.empty_like(b)
c.strides
# (32, 8)