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

compiler: Fix issue 2194 #2212

Merged
merged 1 commit into from
Sep 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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