提交 01470a1b authored 作者: Frederic Bastien's avatar Frederic Bastien

Make FunctionGraph.__remove_client__ don't recur anymore.

上级 1950f592
...@@ -298,40 +298,44 @@ class FunctionGraph(utils.object2): ...@@ -298,40 +298,44 @@ class FunctionGraph(utils.object2):
(op, i) pair such that node.inputs[i] is not r anymore. (op, i) pair such that node.inputs[i] is not r anymore.
""" """
r.clients.remove(client_to_remove) l = [(r, client_to_remove)]
# entry should be uniq in r. No need to assert it as it is while l:
# already asserted in __add_client__. r, client_to_remove = l.pop()
# assert entry not in r.clients r.clients.remove(client_to_remove)
if r.clients: # entry should be uniq in r. No need to assert it as it is
return # already asserted in __add_client__.
variable = r # assert entry not in r.clients
if not variable.owner: if r.clients:
# A Constant or input without client. Remove it. continue
self.variables.remove(variable)
# This allow to quickly know if a var is still in the fgraph # r have no more clients, so check if we need to remove it
# or not. # and its parent.
del variable.fgraph variable = r
else: if not variable.owner:
apply_node = variable.owner # A Constant or input without client. Remove it.
used_or_output = [output for output in apply_node.outputs self.variables.remove(variable)
if output.clients or output in self.outputs] # This allow to quickly know if a var is still in the fgraph
# If the apply node is not used and is not an output # or not.
if not used_or_output: del variable.fgraph
if not hasattr(apply_node.tag, 'removed_by'): else:
apply_node.tag.removed_by = [] apply_node = variable.owner
apply_node.tag.removed_by.append(str(reason)) used_or_output = [output for output in apply_node.outputs
self.apply_nodes.remove(apply_node) if output.clients or output in self.outputs]
del apply_node.fgraph # If the apply node is not used and is not an output
self.variables.difference_update(apply_node.outputs) if not used_or_output:
for var in apply_node.outputs: if not hasattr(apply_node.tag, 'removed_by'):
del var.fgraph apply_node.tag.removed_by = []
self.execute_callbacks('on_prune', apply_node, reason) apply_node.tag.removed_by.append(str(reason))
self.apply_nodes.remove(apply_node)
for i, input in enumerate(apply_node.inputs): del apply_node.fgraph
self.__remove_client__(input, (apply_node, i), self.variables.difference_update(apply_node.outputs)
reason=reason) for var in apply_node.outputs:
del var.fgraph
# import # self.execute_callbacks('on_prune', apply_node, reason)
for i, input in enumerate(apply_node.inputs):
l.append((input, (apply_node, i)))
def __import_r__(self, variable, reason): def __import_r__(self, variable, reason):
""" """
Import variables to this FunctionGraph and also their apply_node, Import variables to this FunctionGraph and also their apply_node,
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论