提交 5917ead5 authored 作者: Reyhane Askari's avatar Reyhane Askari

fast_destroyers_check added

上级 b997f389
...@@ -132,6 +132,11 @@ class Supervisor: ...@@ -132,6 +132,11 @@ class Supervisor:
self.protected = list(protected) self.protected = list(protected)
def validate(self, fgraph): def validate(self, fgraph):
if config.cycle_detection == 'fast' and hasattr(fgraph, 'fast_destroyers_check'):
if fgraph.fast_destroyers_check(self.protected):
raise gof.InconsistencyError("Trying to destroy a protected"
"Variable.")
if not hasattr(fgraph, 'destroyers'): if not hasattr(fgraph, 'destroyers'):
return True return True
for r in self.protected + list(fgraph.outputs): for r in self.protected + list(fgraph.outputs):
......
...@@ -297,7 +297,7 @@ class DestroyHandler(toolbox.Bookkeeper): # noqa ...@@ -297,7 +297,7 @@ class DestroyHandler(toolbox.Bookkeeper): # noqa
<unknown> <unknown>
""" """
pickle_rm_attr = ["destroyers"] pickle_rm_attr = ["destroyers", "fast_destroyers_check"]
def __init__(self, do_imports_on_attach=True, algo=None): def __init__(self, do_imports_on_attach=True, algo=None):
self.fgraph = None self.fgraph = None
...@@ -394,6 +394,26 @@ class DestroyHandler(toolbox.Bookkeeper): # noqa ...@@ -394,6 +394,26 @@ class DestroyHandler(toolbox.Bookkeeper): # noqa
return [] return []
fgraph.destroyers = get_destroyers_of fgraph.destroyers = get_destroyers_of
def recursive_destroys_finder(clients_list):
for client in clients_list:
# client is a tuple (I don't know if its size is always one)
for item in client:
if item.op.destroy_map:
return True
if len(item.outputs) == 0:
return False
for output in item.outputs:
if recursive_destroys_finder(output.clients):
return True
return False
def fast_destroyers_check(protected_list):
for protected_var in protected_list:
if recursive_destroys_finder(protected_var.clients):
return True
fgraph.fast_destroyers_check = fast_destroyers_check
def refresh_droot_impact(self): def refresh_droot_impact(self):
""" """
Makes sure self.droot, self.impact, and self.root_destroyer are up to Makes sure self.droot, self.impact, and self.root_destroyer are up to
...@@ -416,6 +436,7 @@ class DestroyHandler(toolbox.Bookkeeper): # noqa ...@@ -416,6 +436,7 @@ class DestroyHandler(toolbox.Bookkeeper): # noqa
del self.stale_droot del self.stale_droot
assert self.fgraph.destroyer_handler is self assert self.fgraph.destroyer_handler is self
delattr(self.fgraph, 'destroyers') delattr(self.fgraph, 'destroyers')
delattr(self.fgraph, 'fast_destroyers_check')
delattr(self.fgraph, 'destroy_handler') delattr(self.fgraph, 'destroy_handler')
self.fgraph = None self.fgraph = None
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论