Skip to content

Commit

Permalink
Merge pull request #466 from gamdow/pull-request-cleanup
Browse files Browse the repository at this point in the history
Optimisation of count
  • Loading branch information
FabioLuporini authored Feb 20, 2018
2 parents ce3ed62 + 123bf3a commit 6de44c0
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions devito/symbolics/inspection.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from collections import OrderedDict
from collections import Counter
from operator import attrgetter

from sympy import Indexed, cos, sin
Expand All @@ -17,13 +17,10 @@ def count(exprs, query):
Return a mapper ``{(k, v)}`` where ``k`` is a sub-expression in ``exprs``
matching ``query`` and ``v`` is the number of its occurrences.
"""
mapper = OrderedDict()
mapper = Counter()
for expr in exprs:
found = search(expr, query, 'all', 'bfs')
for i in found:
mapper.setdefault(i, 0)
mapper[i] += 1
return mapper
mapper.update(Counter(search(expr, query, 'all', 'bfs')))
return dict(mapper)


def estimate_cost(handle, estimate_functions=False):
Expand Down

0 comments on commit 6de44c0

Please sign in to comment.