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

Code speedup/clean up in cycle detection

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