Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slicing Data returns incorrect results following a transpose() #2187

Open
rhodrin opened this issue Aug 15, 2023 · 1 comment
Open

Slicing Data returns incorrect results following a transpose() #2187

rhodrin opened this issue Aug 15, 2023 · 1 comment
Assignees

Comments

@rhodrin
Copy link
Contributor

rhodrin commented Aug 15, 2023

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 rhodrin self-assigned this Aug 15, 2023
@rhodrin
Copy link
Contributor Author

rhodrin commented Aug 15, 2023

I should add that a temporary workaround for anyone encountering this bug is to slice first, and then transpose the Data object.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant