提交 6e438fe1 authored 作者: Frederic's avatar Frederic

Remove the optional reason argument to on_change_input.

This was slowing down python.
上级 f3c99f51
...@@ -442,7 +442,7 @@ if 0: ...@@ -442,7 +442,7 @@ if 0:
self.stale_droot = True self.stale_droot = True
def on_change_input(self, fgraph, app, i, old_r, new_r): def on_change_input(self, fgraph, app, i, old_r, new_r, reason):
"""app.inputs[i] changed from old_r to new_r """ """app.inputs[i] changed from old_r to new_r """
if app == 'output': if app == 'output':
# app == 'output' is special key that means FunctionGraph is redefining which nodes are being # app == 'output' is special key that means FunctionGraph is redefining which nodes are being
...@@ -827,7 +827,7 @@ class DestroyHandler(toolbox.Bookkeeper): ...@@ -827,7 +827,7 @@ class DestroyHandler(toolbox.Bookkeeper):
self.stale_droot = True self.stale_droot = True
def on_change_input(self, fgraph, app, i, old_r, new_r): def on_change_input(self, fgraph, app, i, old_r, new_r, reason):
"""app.inputs[i] changed from old_r to new_r """ """app.inputs[i] changed from old_r to new_r """
if app == 'output': if app == 'output':
# app == 'output' is special key that means FunctionGraph is redefining which nodes are being # app == 'output' is special key that means FunctionGraph is redefining which nodes are being
......
...@@ -376,7 +376,7 @@ class FunctionGraph(utils.object2): ...@@ -376,7 +376,7 @@ class FunctionGraph(utils.object2):
current value of node.inputs[i] which we want to replace. current value of node.inputs[i] which we want to replace.
For each feature that has a 'on_change_input' method, calls: For each feature that has a 'on_change_input' method, calls:
feature.on_change_input(function_graph, node, i, old_r, new_r, [reason]) feature.on_change_input(function_graph, node, i, old_r, new_r, reason)
""" """
# TODO: ERROR HANDLING FOR LISTENERS (should it complete the change or revert it?) # TODO: ERROR HANDLING FOR LISTENERS (should it complete the change or revert it?)
if node == 'output': if node == 'output':
...@@ -512,14 +512,7 @@ class FunctionGraph(utils.object2): ...@@ -512,14 +512,7 @@ class FunctionGraph(utils.object2):
# not existing # not existing
continue continue
#####HORRIBLE OPTIONAL ARGUMENT HACK
try:
fn(self, *args, **kwargs) fn(self, *args, **kwargs)
except TypeError, e:
if str(e) == "on_change_input() got an unexpected keyword argument 'reason'" and len(kwargs) == 1:
fn(self, *args)
else:
raise
def collect_callbacks(self, name, *args): def collect_callbacks(self, name, *args):
"""WRITEME """WRITEME
......
...@@ -423,7 +423,7 @@ class MergeFeature(object): ...@@ -423,7 +423,7 @@ class MergeFeature(object):
for node in fgraph.toposort(): for node in fgraph.toposort():
self.on_import(fgraph, node, "on_attach") self.on_import(fgraph, node, "on_attach")
def on_change_input(self, fgraph, node, i, r, new_r): def on_change_input(self, fgraph, node, i, r, new_r, reason):
# If inputs to node change, it is not guaranteed that it is distinct # If inputs to node change, it is not guaranteed that it is distinct
# from the other nodes in nodes_seen # from the other nodes in nodes_seen
if node in self.nodes_seen: if node in self.nodes_seen:
...@@ -1171,7 +1171,7 @@ class NavigatorOptimizer(Optimizer): ...@@ -1171,7 +1171,7 @@ class NavigatorOptimizer(Optimizer):
def on_prune(self, fgraph, node, reason): def on_prune(self, fgraph, node, reason):
pruner(node) pruner(node)
if chin is not None: if chin is not None:
def on_change_input(self, fgraph, node, i, r, new_r): def on_change_input(self, fgraph, node, i, r, new_r, reason):
chin(node, i, r, new_r) chin(node, i, r, new_r)
u = Updater() u = Updater()
...@@ -1360,7 +1360,7 @@ class ChangeTracker: ...@@ -1360,7 +1360,7 @@ class ChangeTracker:
def on_import(self, fgraph, node, reason): def on_import(self, fgraph, node, reason):
self.changed = True self.changed = True
def on_change_input(self, fgraph, node, i, r, new_r): def on_change_input(self, fgraph, node, i, r, new_r, reason):
self.changed = True self.changed = True
def reset(self): def reset(self):
......
...@@ -159,7 +159,7 @@ class HintsFeature(object): ...@@ -159,7 +159,7 @@ class HintsFeature(object):
if k not in new_hints: if k not in new_hints:
new_hints[k] = v new_hints[k] = v
def on_change_input(self, fgraph, node, i, r, new_r): def on_change_input(self, fgraph, node, i, r, new_r, reason):
# TODO: # TODO:
# This tells us that r and new_r must have the same shape # This tells us that r and new_r must have the same shape
# if we didn't know that the shapes are related, now we do. # if we didn't know that the shapes are related, now we do.
......
...@@ -1075,7 +1075,7 @@ class ShapeFeature(object): ...@@ -1075,7 +1075,7 @@ class ShapeFeature(object):
for r, s in izip(node.outputs, o_shapes): for r, s in izip(node.outputs, o_shapes):
self.set_shape(r, s) self.set_shape(r, s)
def on_change_input(self, fgraph, node, i, r, new_r): def on_change_input(self, fgraph, node, i, r, new_r, reason):
if new_r not in self.shape_of: if new_r not in self.shape_of:
# It happen that the fgraph didn't called on_import for some # It happen that the fgraph didn't called on_import for some
# new_r. This happen when new_r don't have an # new_r. This happen when new_r don't have an
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论