Skip to content

Commit

Permalink
Avoid assigning utility functions to self
Browse files Browse the repository at this point in the history
Was that way to avoid circular imports
  • Loading branch information
FabioLuporini committed Nov 28, 2016
1 parent b92f96c commit c1cdaae
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions coffee/visitors/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,7 @@ def default_retval(cls):
"""

def __init__(self, symbols):
from coffee.utils import flatten
self.symbols = symbols
self.flatten = flatten
super(ProjectExpansion, self).__init__()

def visit_object(self, o, *args, **kwargs):
Expand All @@ -303,17 +301,18 @@ def visit_Expr(self, o, parent=None, *args, **kwargs):
return ret

def visit_Prod(self, o, parent=None, *args, **kwargs):
from coffee.utils import flatten
if isinstance(parent, Prod):
projection = self.default_retval()
for n in o.children:
projection.extend(self.visit(n, parent=o, *args, **kwargs))
return [list(self.flatten(projection))]
return [list(flatten(projection))]
else:
# Only the top level Prod, in a chain of Prods, should do the
# tensor product
projection = [self.visit(n, parent=o, *args, **kwargs) for n in o.children]
product = itertools.product(*projection)
ret = [list(self.flatten(i)) for i in product] or projection
ret = [list(flatten(i)) for i in product] or projection
return ret

def visit_Symbol(self, o, *args, **kwargs):
Expand Down

0 comments on commit c1cdaae

Please sign in to comment.