提交 88bd76f4 authored 作者: James Bergstra's avatar James Bergstra

refactored graph.inputs to also provide new function: graph.ancestors

上级 a156506d
......@@ -390,8 +390,6 @@ class Constant(Value):
return cp
def stack_search(start, expand, mode='bfs', build_inv = False):
"""Search through a graph, either breadth- or depth-first
......@@ -439,15 +437,15 @@ def stack_search(start, expand, mode='bfs', build_inv = False):
return rval_list
def inputs(variable_list, blockers = None):
"""Return the inputs required to compute the given Variables.
def ancestors(variable_list, blockers = None):
"""Return the variables that contribute to those in variable_list (inclusive).
:type variable_list: list of `Variable` instances
:param variable_list:
output `Variable` instances from which to search backward through owners
:rtype: list of `Variable` instances
:returns:
input nodes with no owner, in the order found by a left-recursive depth-first search
all input nodes, in the order found by a left-recursive depth-first search
started at the nodes in `variable_list`.
"""
......@@ -457,8 +455,23 @@ def inputs(variable_list, blockers = None):
l.reverse()
return l
dfs_variables = stack_search(deque(variable_list), expand, 'dfs')
rval = [r for r in dfs_variables if r.owner is None]
#print rval, _orig_inputs(o)
return dfs_variables
def inputs(variable_list, blockers = None):
"""Return the inputs required to compute the given Variables.
:type variable_list: list of `Variable` instances
:param variable_list:
output `Variable` instances from which to search backward through owners
:rtype: list of `Variable` instances
:returns:
input nodes with no owner, in the order found by a left-recursive depth-first search
started at the nodes in `variable_list`.
"""
anc = ancestors(variable_list, blockers)
rval = [r for r in ancestors if r.owner is None]
return rval
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论