提交 77ea266d authored 作者: Frederic's avatar Frederic

Code speedup/clean up in cycle detection

上级 a5c84b94
...@@ -116,21 +116,14 @@ def _contains_cycle(fgraph, orderings): ...@@ -116,21 +116,14 @@ def _contains_cycle(fgraph, orderings):
# this is faster than calling get_parents # this is faster than calling get_parents
owner = var.owner owner = var.owner
if owner:
parents = [owner]
else:
parents = []
# variables don't appear in orderings, so we don't need to worry # variables don't appear in orderings, so we don't need to worry
# about that here # about that here
if owner:
if parents: # insert node in node_to_children[r]
for parent in parents: # (if r is not already in node_to_children,
# insert node in node_to_children[r] # intialize it to [])
# (if r is not already in node_to_children, node_to_children.setdefault(owner, []).append(var)
# intialize it to []) parent_counts[var] = 1
node_to_children.setdefault(parent, []).append(var)
parent_counts[var] = len(parents)
else: else:
visitable.append(var) visitable.append(var)
parent_counts[var] = 0 parent_counts[var] = 0
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论