Skip to content

Commit

Permalink
compiler: Fix issue 2194
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewCheng827 authored and mloubout committed Sep 29, 2023
1 parent 0f0ae38 commit c3abf22
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
13 changes: 12 additions & 1 deletion devito/ir/support/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,18 @@ def distance(self, other):
else:
v = i - j
if v.is_Number and v.is_finite:
return Vector(S.ImaginaryUnit)
if i.is_Number and j.is_Number:
return Vector(S.ImaginaryUnit)
else:
# For example:
# self=W<u,[0,y]> and other=R<u,[0,y+1]>
ret.append(v)

# Writing (reading) over an entire dimension, reading (writing)
# from one point. For example:
# self=R<u,[1,2]> and other=W<u,[1, y+1]>
elif (not i.is_Number or not j.is_Number):
ret.append(S.Infinity)

return Vector(*ret)

Expand Down
52 changes: 52 additions & 0 deletions tests/test_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -1936,6 +1936,58 @@ def test_topofuse_w_numeric_dim(self):

assert_structure(op, ['r,i', 'r'], 'r,i')

@pytest.mark.parametrize('eqns, expected, exp_trees, exp_iters', [
(['Eq(u[0, x], 1)',
'Eq(u[1, x], u[0, x + h_x] + u[0, x - h_x] - 2*u[0, x])'],
np.array([[1., 1., 1.], [-1., 0., -1.]]),
['x', 'x'], 'x,x')
])
def test_2194(self, eqns, expected, exp_trees, exp_iters):
grid = Grid(shape=(3, ))
u = TimeFunction(name='u', grid=grid)
x = grid.dimensions[0]
h_x = x.spacing # noqa: F841

for i, e in enumerate(list(eqns)):
eqns[i] = eval(e)

op = Operator(eqns)
assert_structure(op, exp_trees, exp_iters)

op.apply()
assert(np.all(u.data[:] == expected[:]))

@pytest.mark.parametrize('eqns, expected, exp_trees, exp_iters', [
(['Eq(u[0, y], 1)', 'Eq(u[1, y], u[0, y + 1])'],
np.array([[1., 1.], [1., 0.]]),
['y', 'y'], 'y,y'),
(['Eq(u[0, y], 1)', 'Eq(u[1, y], u[0, 2])'],
np.array([[1., 1.], [0., 0.]]),
['y', 'y'], 'y,y'),
(['Eq(u[0, y], 1)', 'Eq(u[1, y], u[0, 1])'],
np.array([[1., 1.], [1., 1.]]),
['y', 'y'], 'y,y'),
(['Eq(u[0, y], 1)', 'Eq(u[1, y], u[0, y + 1])'],
np.array([[1., 1.], [1., 0.]]),
['y', 'y'], 'y,y'),
(['Eq(u[0, 1], 1)', 'Eq(u[x, y], u[0, y])'],
np.array([[0., 1.], [0., 1.]]),
['xy'], 'x,y')
])
def test_2194_v2(self, eqns, expected, exp_trees, exp_iters):
grid = Grid(shape=(2, 2))
u = Function(name='u', grid=grid)
x, y = grid.dimensions

for i, e in enumerate(list(eqns)):
eqns[i] = eval(e)

op = Operator(eqns)
assert_structure(op, exp_trees, exp_iters)

op.apply()
assert(np.all(u.data[:] == expected[:]))


class TestInternals(object):

Expand Down

0 comments on commit c3abf22

Please sign in to comment.