Skip to content

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

Open
@rhodrin

Description

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.

Activity

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

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions