提交 45c258e0 authored 作者: Ian Goodfellow's avatar Ian Goodfellow

made destroyhandler's cycle checking logic more obvious

上级 198cac60
...@@ -45,7 +45,7 @@ class DestroyHandler(object): ...@@ -45,7 +45,7 @@ class DestroyHandler(object):
def orderings(self, fgraph): def orderings(self, fgraph):
return self.map[fgraph].orderings(fgraph) return self.map[fgraph].orderings(fgraph)
def _dfs_toposort(inputs, outputs, orderings): def _contains_cycle(inputs, outputs, orderings):
""" """
inputs - list of graph inputs inputs - list of graph inputs
must be Variable instances must be Variable instances
...@@ -148,9 +148,7 @@ def _dfs_toposort(inputs, outputs, orderings): ...@@ -148,9 +148,7 @@ def _dfs_toposort(inputs, outputs, orderings):
if not expand_cache[client]: if not expand_cache[client]:
fifo_queue.append(client) fifo_queue.append(client)
if len(rlist) != len(rval_list): return len(rlist) != len(rval_list)
raise ValueError('graph contains cycles')
#return [o for o in rlist if isinstance(o, graph.Apply)] #return [o for o in rlist if isinstance(o, graph.Apply)]
...@@ -424,20 +422,10 @@ class DestroyHandlerHelper2(toolbox.Bookkeeper): ...@@ -424,20 +422,10 @@ class DestroyHandlerHelper2(toolbox.Bookkeeper):
""" """
if self.destroyers: if self.destroyers:
try: ords = self.orderings(fgraph)
ords = self.orderings(fgraph)
except Exception, e:
raise
try: if _contains_cycle(fgraph.inputs, fgraph.outputs, ords):
### graph.io_toposort(fgraph.inputs, fgraph.outputs, ords) raise InconsistencyError("Dependency graph contains cycles")
_dfs_toposort(fgraph.inputs, fgraph.outputs, ords)
except ValueError, e:
if 'cycles' in str(e):
raise InconsistencyError("Dependency graph contains cycles")
else:
raise
#print 'passing...', ords
else: else:
#James's Conjecture: #James's Conjecture:
#If there are no destructive ops, then there can be no cycles. #If there are no destructive ops, then there can be no cycles.
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论