提交 bc6770cc authored 作者: Ramana.S's avatar Ramana.S

initial commit

上级 9627228c
...@@ -153,6 +153,7 @@ class FunctionGraph(utils.object2): ...@@ -153,6 +153,7 @@ class FunctionGraph(utils.object2):
self.inputs = list(inputs) self.inputs = list(inputs)
self.outputs = outputs self.outputs = outputs
self._removed_nodes = set()
for f in features: for f in features:
self.attach_feature(f) self.attach_feature(f)
...@@ -320,10 +321,12 @@ class FunctionGraph(utils.object2): ...@@ -320,10 +321,12 @@ class FunctionGraph(utils.object2):
if output.clients or output in self.outputs] if output.clients or output in self.outputs]
# If the apply node is not used and is not an output # If the apply node is not used and is not an output
if not used_or_output: if not used_or_output:
if apply_node in self.apply_nodes:
#keeping track of removed apply node
self.apply_nodes.remove(apply_node) self.apply_nodes.remove(apply_node)
self.variables.difference_update(apply_node.outputs) self.variables.difference_update(apply_node.outputs)
self.execute_callbacks('on_prune', apply_node, reason) self.execute_callbacks('on_prune', apply_node, reason)
self._removed_nodes.add(apply_node)
for i, input in enumerate(apply_node.inputs): for i, input in enumerate(apply_node.inputs):
self.__remove_clients__(input, [(apply_node, i)], self.__remove_clients__(input, [(apply_node, i)],
reason=reason) reason=reason)
...@@ -478,6 +481,12 @@ class FunctionGraph(utils.object2): ...@@ -478,6 +481,12 @@ class FunctionGraph(utils.object2):
for node in new_nodes: for node in new_nodes:
assert node not in self.apply_nodes assert node not in self.apply_nodes
prevent_addition = False
for n in self._removed_nodes :
if node is n :
prevent_addition = True
if not prevent_addition :
self.__setup_node__(node) self.__setup_node__(node)
self.apply_nodes.add(node) self.apply_nodes.add(node)
for output in node.outputs: for output in node.outputs:
...@@ -488,6 +497,7 @@ class FunctionGraph(utils.object2): ...@@ -488,6 +497,7 @@ class FunctionGraph(utils.object2):
self.__setup_r__(input) self.__setup_r__(input)
self.variables.add(input) self.variables.add(input)
self.__add_clients__(input, [(node, i)]) self.__add_clients__(input, [(node, i)])
if not prevent_addition :
assert node.fgraph is self assert node.fgraph is self
self.execute_callbacks('on_import', node, reason) self.execute_callbacks('on_import', node, reason)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论