提交 f21dd447 authored 作者: Frederic's avatar Frederic

2 small speed up

上级 78821dc6
...@@ -549,9 +549,7 @@ def ancestors(variable_list, blockers=None): ...@@ -549,9 +549,7 @@ def ancestors(variable_list, blockers=None):
""" """
def expand(r): def expand(r):
if r.owner and (not blockers or r not in blockers): if r.owner and (not blockers or r not in blockers):
l = list(r.owner.inputs) return reversed(r.owner.inputs)
l.reverse()
return l
dfs_variables = stack_search(deque(variable_list), expand, 'dfs') dfs_variables = stack_search(deque(variable_list), expand, 'dfs')
return dfs_variables return dfs_variables
...@@ -801,7 +799,7 @@ def io_toposort(inputs, outputs, orderings=None): ...@@ -801,7 +799,7 @@ def io_toposort(inputs, outputs, orderings=None):
if isinstance(obj, Variable): if isinstance(obj, Variable):
if obj.owner: if obj.owner:
rval = [obj.owner] rval = [obj.owner]
if isinstance(obj, Apply): elif isinstance(obj, Apply):
rval = list(obj.inputs) rval = list(obj.inputs)
rval.extend(orderings.get(obj, [])) rval.extend(orderings.get(obj, []))
else: else:
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论