1515)
1616from devito .symbolics import IntDiv , limits_mapper , uxreplace
1717from devito .tools import Pickable , Tag , frozendict
18- from devito .types import Eq , Inc , ReduceMax , ReduceMin , ReduceMinMax , relational_min , relational_shift
18+ from devito .types import (
19+ Eq , Inc , ReduceMax , ReduceMin , ReduceMinMax , relational_min , relational_shift
20+ )
1921
2022__all__ = [
2123 'ClusterizedEq' ,
@@ -294,7 +296,7 @@ def __new__(cls, *args, **kwargs):
294296 relations = ordering .relations , mode = 'partial' )
295297 ispace = IterationSpace (intervals , iterators )
296298
297- # Construct the conditionals and replace the ConditionalDimensions in `expr`
299+ # Construct the conditionals
298300 conditionals = {}
299301 for d in ordering :
300302 if not d .is_Conditional :
@@ -306,14 +308,6 @@ def __new__(cls, *args, **kwargs):
306308 if d ._factor is not None :
307309 cond = d .relation (cond , GuardFactor (d ))
308310 conditionals [d ] = cond
309- # Replace dimension with index
310- index = d .index
311- if d .condition is not None and d in expr .free_symbols :
312- index = index - relational_min (d .condition , d .parent )
313- shift = relational_shift (d .condition , d .parent )
314- else :
315- shift = 0
316- expr = uxreplace (expr , {d : IntDiv (index , d .symbolic_factor ) + shift })
317311
318312 # Merge conditionals when possible. E.g if we have an implicit_dim
319313 # and there is a dimension with the same parent, we ca merged
@@ -330,6 +324,14 @@ def __new__(cls, *args, **kwargs):
330324
331325 conditionals = frozendict (conditionals )
332326
327+ # Replace the ConditionalDimensions in `expr`
328+ for d , cond in conditionals .items ():
329+ # Replace dimension with index
330+ index = d .index
331+ index = index - relational_min (cond , d .parent )
332+ shift = relational_shift (cond , d .parent )
333+ expr = uxreplace (expr , {d : IntDiv (index , d .symbolic_factor ) + shift })
334+
333335 # Lower all Differentiable operations into SymPy operations
334336 rhs = diff2sympy (expr .rhs )
335337
0 commit comments