devito icon indicating copy to clipboard operation
devito copied to clipboard

Slicing `Data` returns incorrect results following a `transpose()`

Open rhodrin opened this issue 10 months ago • 1 comments

As described in the title. MFE below.

Consider the following numpy array operation:

import numpy as np
a = np.zeros((4, 6))
b = a.T[::2, ::2]

We then have that b is given by

array([[0., 0.],
       [0., 0.],
       [0., 0.]])

and b.shape is (3, 2).

We would expected similar behavior from the Devito Data type:

grid = Grid(shape=(4, 6))
f = Function(name='f', grid=grid)
g = f.data.T[::2, ::2]

but in this case, g is

Data([[0., 0.],
      [0., 0.]], dtype=float32)

and hence g.shape is (2, 2).

Note that f.data[::2, ::2].T returns

Data([[0., 0.],
      [0., 0.],
      [0., 0.]], dtype=float32)

and f.data.T returns

Data([[0., 0., 0., 0.],
      [0., 0., 0., 0.],
      [0., 0., 0., 0.],
      [0., 0., 0., 0.],
      [0., 0., 0., 0.],
      [0., 0., 0., 0.]], dtype=float32)

which is of the correct form, but slicing this transposed Data will in many cases result in an incorrect output.

It would seem that some property of the Data object is not being properly updated by the transpose operation.

rhodrin avatar Aug 15 '23 16:08 rhodrin