|
11 | 11 | q_constant, q_comp_acc, q_affine, q_routine, search, |
12 | 12 | uxreplace) |
13 | 13 | from devito.tools import (Tag, as_mapper, as_tuple, is_integer, filter_sorted, |
14 | | - flatten, memoized_meth, memoized_generator) |
| 14 | + flatten, memoized_meth, memoized_generator, smart_gt, |
| 15 | + smart_lt) |
15 | 16 | from devito.types import (ComponentAccess, Dimension, DimensionTuple, Fence, |
16 | 17 | CriticalRegion, Function, Symbol, Temp, TempArray, |
17 | 18 | TBArray) |
@@ -317,9 +318,6 @@ def lex_le(self, other): |
317 | 318 | def lex_lt(self, other): |
318 | 319 | return self.timestamp < other.timestamp |
319 | 320 |
|
320 | | - # Note: memoization yields mild compiler speedup. Will need to be made |
321 | | - # thread-safe for multithreading the compiler. |
322 | | - @memoized_meth |
323 | 321 | def distance(self, other): |
324 | 322 | """ |
325 | 323 | Compute the distance from ``self`` to ``other``. |
@@ -366,21 +364,14 @@ def distance(self, other): |
366 | 364 | # Case 1: `sit` is an IterationInterval with statically known |
367 | 365 | # trip count. E.g. it ranges from 0 to 3; `other` performs a |
368 | 366 | # constant access at 4 |
369 | | - |
370 | | - # To avoid evaluating expensive symbolic Lt or Gt operations, |
371 | | - # we pre-empt such operations by checking if the values to be compared |
372 | | - # to are symbolic, and skip this case if not. |
373 | | - if not any(isinstance(i, sympy.Basic) |
374 | | - for i in (sit.symbolic_min, sit.symbolic_max)): |
375 | | - |
376 | | - for v in (self[n], other[n]): |
377 | | - try: |
378 | | - # Note: Boolean is split to make the conditional short |
379 | | - # circuit more frequently for mild speedup |
380 | | - if bool(v < sit.symbolic_min) or bool(v > sit.symbolic_max): |
381 | | - return Vector(S.ImaginaryUnit) |
382 | | - except TypeError: |
383 | | - pass |
| 367 | + for v in (self[n], other[n]): |
| 368 | + # Note: To avoid evaluating expensive symbolic Lt or Gt operations, |
| 369 | + # we pre-empt such operations by checking if the values to be compared |
| 370 | + # to are symbolic, and skip this case if not. |
| 371 | + # Note: Boolean is split to make the conditional short |
| 372 | + # circuit more frequently for mild speedup. |
| 373 | + if smart_lt(v, sit.symbolic_min) or smart_gt(v, sit.symbolic_max): |
| 374 | + return Vector(S.ImaginaryUnit) |
384 | 375 |
|
385 | 376 | # Case 2: `sit` is an IterationInterval over a local SubDimension |
386 | 377 | # and `other` performs a constant access |
|
0 commit comments