Skip to content

Commit

Permalink
Merge pull request #903 from opesci/index_dist_to_repl_fix
Browse files Browse the repository at this point in the history
 index_dist_to_repl fix
  • Loading branch information
mloubout authored Aug 7, 2019
2 parents 844488e + 5f68e60 commit ef35c14
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions devito/data/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ def index_dist_to_repl(idx, decomposition):
elif not is_integer(value):
raise ValueError("Cannot derive shift value from type `%s`" % type(value))

if value < 0:
value += decomposition.glb_max + 1

# Convert into absolute local index
idx = decomposition.index_glb_to_loc(idx, rel=False)

Expand Down
10 changes: 10 additions & 0 deletions tests/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,16 @@ def test_negative_step(self):
assert (np.array(u.data[0, 3::-1, 0, 0]) == dat[3::-1]).all()
assert (np.array(u.data[0, 5:1:-1, 0, 0]) == dat[5:1:-1]).all()

@skipif('yask')
def test_negative_start(self):
"""Test slicing with a negative start."""
grid = Grid(shape=(13,))
f = Function(name='f', grid=grid)
idx = slice(-4, None, 1)
dat = np.array([1, 2, 3, 4])
f.data[idx] = dat
assert np.all(np.array(f.data[9:]) == dat)

def test_halo_indexing(self):
"""Test data packing/unpacking in presence of a halo region."""
domain_shape = (16, 16, 16)
Expand Down

0 comments on commit ef35c14

Please sign in to comment.