Skip to content

Commit

Permalink
Simplify _get_ancestors().
Browse files Browse the repository at this point in the history
Per @lucianopaz. remove the initial special case/
  • Loading branch information
rpgoldman committed May 4, 2019
1 parent 9741271 commit 5d2312a
Showing 1 changed file with 19 additions and 25 deletions.
44 changes: 19 additions & 25 deletions pymc3/model_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,31 +54,25 @@ def _get_ancestors(self, var, func):
vars: List[var] = set(self.var_list)
vars.remove(var)

upstream = self._ancestors(var, func)

# Usual case
if upstream == self._ancestors(var, func, blockers=upstream):
return upstream
else: # deterministic accounting
blockers = set()
retval = set()
def _expand(node) -> Optional[Iterator[Tensor]]:
if node in blockers:
return None
elif node in vars:
blockers.add(node)
retval.add(node)
return None
elif node.owner:
blockers.add(node)
return reversed(node.owner.inputs)
else:
return None

stack_search(start = deque([func]),
expand=_expand,
mode='bfs')
return retval
blockers = set()
retval = set()
def _expand(node) -> Optional[Iterator[Tensor]]:
if node in blockers:
return None
elif node in vars:
blockers.add(node)
retval.add(node)
return None
elif node.owner:
blockers.add(node)
return reversed(node.owner.inputs)
else:
return None

stack_search(start = deque([func]),
expand=_expand,
mode='bfs')
return retval

def _filter_parents(self, var, parents):
"""Get direct parents of a var, as strings"""
Expand Down

0 comments on commit 5d2312a

Please sign in to comment.