提交 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:
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 """
if app == 'output':
# app == 'output' is special key that means FunctionGraph is redefining which nodes are being
......@@ -827,7 +827,7 @@ class DestroyHandler(toolbox.Bookkeeper):
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 """
if app == 'output':
# app == 'output' is special key that means FunctionGraph is redefining which nodes are being
......
......@@ -376,7 +376,7 @@ class FunctionGraph(utils.object2):
current value of node.inputs[i] which we want to replace.
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?)
if node == 'output':
......@@ -512,14 +512,7 @@ class FunctionGraph(utils.object2):
# not existing
continue
#####HORRIBLE OPTIONAL ARGUMENT HACK
try:
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
fn(self, *args, **kwargs)
def collect_callbacks(self, name, *args):
"""WRITEME
......
......@@ -423,7 +423,7 @@ class MergeFeature(object):
for node in fgraph.toposort():
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
# from the other nodes in nodes_seen
if node in self.nodes_seen:
......@@ -1171,7 +1171,7 @@ class NavigatorOptimizer(Optimizer):
def on_prune(self, fgraph, node, reason):
pruner(node)
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)
u = Updater()
......@@ -1360,7 +1360,7 @@ class ChangeTracker:
def on_import(self, fgraph, node, reason):
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
def reset(self):
......
......@@ -159,7 +159,7 @@ class HintsFeature(object):
if k not in new_hints:
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:
# 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.
......
......@@ -1075,7 +1075,7 @@ class ShapeFeature(object):
for r, s in izip(node.outputs, o_shapes):
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:
# It happen that the fgraph didn't called on_import for some
# new_r. This happen when new_r don't have an
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论