提交 bca401d7 authored 作者: Ian Goodfellow's avatar Ian Goodfellow

made _contains_cycles take an fgraph instead of inputs and outputs

上级 0d0cc128
...@@ -45,16 +45,11 @@ class DestroyHandler(object): ...@@ -45,16 +45,11 @@ class DestroyHandler(object):
def orderings(self, fgraph): def orderings(self, fgraph):
return self.map[fgraph].orderings(fgraph) return self.map[fgraph].orderings(fgraph)
def _contains_cycle(inputs, outputs, orderings):
"""
inputs - list of graph inputs def _contains_cycle(fgraph, orderings):
must be Variable instances """
collection must be tuple, list, or deque
outputs - list of graph outputs fgraph - the FunctionGraph to check for cycles
must be Variable instances
collection must be tuple, list or deque
orderings - dictionary specifying extra dependencies besides orderings - dictionary specifying extra dependencies besides
those encoded in Variable.owner / Apply.inputs those encoded in Variable.owner / Apply.inputs
...@@ -73,6 +68,10 @@ def _contains_cycle(inputs, outputs, orderings): ...@@ -73,6 +68,10 @@ def _contains_cycle(inputs, outputs, orderings):
Returns True if the graph contains a cycle, False otherwise. Returns True if the graph contains a cycle, False otherwise.
""" """
# These are lists of Variable instances
inputs = fgraph.inputs
outputs = fgraph.outputs
# this is hard-coded reimplementation of functions from graph.py # this is hard-coded reimplementation of functions from graph.py
# reason: go faster, prepare for port to C. # reason: go faster, prepare for port to C.
...@@ -449,7 +448,7 @@ class DestroyHandlerHelper2(toolbox.Bookkeeper): ...@@ -449,7 +448,7 @@ class DestroyHandlerHelper2(toolbox.Bookkeeper):
if self.destroyers: if self.destroyers:
ords = self.orderings(fgraph) ords = self.orderings(fgraph)
if _contains_cycle(fgraph.inputs, fgraph.outputs, ords): if _contains_cycle(fgraph, ords):
raise InconsistencyError("Dependency graph contains cycles") raise InconsistencyError("Dependency graph contains cycles")
else: else:
#James's Conjecture: #James's Conjecture:
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论