1111)
1212from devito .symbolics import IntDiv , limits_mapper , uxreplace
1313from devito .tools import Pickable , Tag , frozendict
14- from devito .types import Eq , Inc , ReduceMax , ReduceMin , ReduceMinMax , relational_min , relational_shift
14+ from devito .types import (
15+ Eq , Inc , ReduceMax , ReduceMin , ReduceMinMax , relational_min , relational_shift
16+ )
1517
1618__all__ = [
1719 'ClusterizedEq' ,
@@ -222,7 +224,7 @@ def __new__(cls, *args, **kwargs):
222224 relations = ordering .relations , mode = 'partial' )
223225 ispace = IterationSpace (intervals , iterators )
224226
225- # Construct the conditionals and replace the ConditionalDimensions in `expr`
227+ # Construct the conditionals
226228 conditionals = {}
227229 for d in ordering :
228230 if not d .is_Conditional :
@@ -234,14 +236,6 @@ def __new__(cls, *args, **kwargs):
234236 if d ._factor is not None :
235237 cond = d .relation (cond , GuardFactor (d ))
236238 conditionals [d ] = cond
237- # Replace dimension with index
238- index = d .index
239- if d .condition is not None and d in expr .free_symbols :
240- index = index - relational_min (d .condition , d .parent )
241- shift = relational_shift (d .condition , d .parent )
242- else :
243- shift = 0
244- expr = uxreplace (expr , {d : IntDiv (index , d .symbolic_factor ) + shift })
245239
246240 # Merge conditionals when possible. E.g if we have an implicit_dim
247241 # and there is a dimension with the same parent, we ca merged
@@ -258,6 +252,14 @@ def __new__(cls, *args, **kwargs):
258252
259253 conditionals = frozendict (conditionals )
260254
255+ # Replace the ConditionalDimensions in `expr`
256+ for d , cond in conditionals .items ():
257+ # Replace dimension with index
258+ index = d .index
259+ index = index - relational_min (cond , d .parent )
260+ shift = relational_shift (cond , d .parent )
261+ expr = uxreplace (expr , {d : IntDiv (index , d .symbolic_factor ) + shift })
262+
261263 # Lower all Differentiable operations into SymPy operations
262264 rhs = diff2sympy (expr .rhs )
263265
0 commit comments