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: Patch indirect ConditionalDimension #2432

Merged
merged 1 commit into from
Aug 1, 2024
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
7 changes: 5 additions & 2 deletions devito/ir/equations/equation.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ def apply(self, func):
"""
args = [func(self.lhs), func(self.rhs)]
kwargs = dict(self.state)
kwargs['conditionals'] = {k: func(v) for k, v in self.conditionals.items()}

conditionals = {k: func(v) for k, v in self.conditionals.items()}
kwargs['conditionals'] = frozendict(conditionals)

return self.func(*args, **kwargs)

def __repr__(self):
Expand Down Expand Up @@ -197,7 +200,7 @@ def __new__(cls, *args, **kwargs):
conditionals[d] = cond
# Replace dimension with index
index = d.index
if d.condition is not None:
if d.condition is not None and d in expr.free_symbols:
index = index - relational_min(d.condition, d.parent)
expr = uxreplace(expr, {d: IntDiv(index, d.factor)})

Expand Down
18 changes: 18 additions & 0 deletions tests/test_dimension.py
Original file line number Diff line number Diff line change
Expand Up @@ -1255,6 +1255,24 @@ def test_no_index_sparse(self):
assert np.all(f.data[0, :, 0] == 0.)
assert np.all(f.data[0, :, -1] == 0.)

def test_no_index_symbolic(self):
grid = Grid(shape=(10, 10, 10))
x, y, z = grid.dimensions

u = TimeFunction(name='u', grid=grid)

v0 = Constant(name='v0', dtype=np.float32)
v1 = Constant(name='v1', dtype=np.float32)
condition = And(Ge(x, v0), Le(x, v1))
cd = ConditionalDimension(name='cd', parent=x, condition=condition,
indirect=True)

eq = Eq(u.forward, u + 1, implicit_dims=cd)

# Ensure both code generation and jitting work
op = Operator(eq)
op.cfunction

def test_symbolic_factor(self):
"""
Test ConditionalDimension with symbolic factor (provided as a Constant).
Expand Down
Loading