|
13 | 13 | from devito.finite_differences.differentiable import IndexDerivative |
14 | 14 | from devito.ir import Cluster, Scope, cluster_pass |
15 | 15 | from devito.symbolics import estimate_cost, q_leaf, q_terminal |
| 16 | +from devito.symbolics.search import retrieve_ctemps |
16 | 17 | from devito.symbolics.manipulation import _uxreplace |
17 | 18 | from devito.tools import DAG, as_list, as_tuple, frozendict, extract_dtype |
18 | 19 | from devito.types import Eq, Symbol, Temp |
@@ -222,36 +223,17 @@ def _compact(exprs, exclude): |
222 | 223 | `for (i = ...) { a = b; for (j = a ...) ... }`. Hence, this routine |
223 | 224 | only targets CTemps. |
224 | 225 | """ |
225 | | - # FIXME: Can use is_CTemp rather than isinstance |
226 | 226 | candidates = [e for e in exprs |
227 | 227 | if isinstance(e.lhs, CTemp) and e.lhs not in exclude] |
228 | 228 |
|
229 | 229 | mapper = {e.lhs: e.rhs for e in candidates if q_leaf(e.rhs)} |
230 | 230 |
|
231 | | - # FIXME: Move this to searches as retrieve_ctemps |
232 | | - from devito.symbolics.search import search |
233 | | - |
234 | | - def q_ctemp(expr): |
235 | | - try: |
236 | | - return expr.is_CTemp |
237 | | - except AttributeError: |
238 | | - return False |
239 | | - |
240 | | - # Find all the CTemps in expressions without removing duplicates |
241 | | - # ctemps = search(exprs, q_ctemp, 'all', 'dfs') |
242 | | - # I think it was more like |
243 | | - ctemps = search([e.rhs for e in exprs], q_ctemp, 'all', 'dfs') |
244 | | - |
245 | | - # print(ctemps, len(ctemps), len(set(ctemps)), len(candidates)) |
246 | | - |
247 | | - # FIXME: This line is kinda slow. I should find some way to replace it. |
248 | | - # FIXME: Specifically sum([i.rhs.count(e.lhs) for i in exprs]) == 1 is slow as hell |
249 | | - # mapper.update({e.lhs: e.rhs for e in candidates |
250 | | - # if sum([i.rhs.count(e.lhs) for i in exprs]) == 1}) |
| 231 | + # Find all the CTemps in expression right-hand-sides without removing duplicates |
| 232 | + ctemps = retrieve_ctemps([e.rhs for e in exprs]) |
251 | 233 |
|
252 | 234 | # If there are ctemps in the expressions, then add any to the mapper which only |
253 | 235 | # appear once |
254 | | - # TODO: Double check this is exactly the prior behaviour? |
| 236 | + # TODO: Double check this is exactly the prior behaviour |
255 | 237 | if ctemps: |
256 | 238 | mapper.update({e.lhs: e.rhs for e in candidates |
257 | 239 | if ctemps.count(e.lhs) == 1}) |
|
0 commit comments