提交 7668d632 authored 作者: Brandon T. Willard's avatar Brandon T. Willard

Fix docstrings and argument names in the Feature class

上级 ff3a67f1
...@@ -235,62 +235,62 @@ class Feature: ...@@ -235,62 +235,62 @@ class Feature:
""" """
def on_attach(self, function_graph): def on_attach(self, fgraph):
""" """
Called by FunctionGraph.attach_feature, the method that attaches Called by `FunctionGraph.attach_feature`, the method that attaches the
the feature to the FunctionGraph. Since this is called after the feature to the `FunctionGraph`. Since this is called after the
FunctionGraph is initially populated, this is where you should `FunctionGraph` is initially populated, this is where you should run
run checks on the initial contents of the FunctionGraph. checks on the initial contents of the `FunctionGraph`.
The on_attach method may raise the AlreadyThere exception to cancel The on_attach method may raise the `AlreadyThere` exception to cancel
the attach operation if it detects that another Feature instance the attach operation if it detects that another Feature instance
implementing the same functionality is already atttached to the implementing the same functionality is already attached to the
FunctionGraph. `FunctionGraph`.
The feature has great freedom in what it can do with the
function_graph: it may, for example, add methods to it dynamically.
""" The feature has great freedom in what it can do with the `fgraph`: it
may, for example, add methods to it dynamically.
def on_detach(self, function_graph):
""" """
Called by remove_feature(feature). Should remove any dynamically-added
functionality that it installed into the function_graph.
def on_detach(self, fgraph):
""" """
Called by `FunctionGraph.remove_feature`. Should remove any
dynamically-added functionality that it installed into the fgraph.
def on_import(self, function_graph, node, reason):
""" """
Called whenever a node is imported into function_graph, which is
just before the node is actually connected to the graph.
Note: on_import is not called when the graph is created. If you
want to detect the first nodes to be implemented to the graph,
you should do this by implementing on_attach.
def on_import(self, fgraph, node, reason):
""" """
Called whenever a node is imported into `fgraph`, which is just before
the node is actually connected to the graph.
def on_prune(self, function_graph, node, reason): Note: this is not called when the graph is created. If you want to
""" detect the first nodes to be implemented to the graph, you should do
Called whenever a node is pruned (removed) from the function_graph, this by implementing `on_attach`.
after it is disconnected from the graph.
""" """
def on_change_input(self, function_graph, node, i, r, new_r, reason=None): def on_change_input(self, fgraph, node, i, var, new_var, reason=None):
""" """
Called whenever node.inputs[i] is changed from r to new_r. Called whenever ``node.inputs[i]`` is changed from `var` to `new_var`.
At the moment the callback is done, the change has already At the moment the callback is done, the change has already taken place.
taken place.
If you raise an exception in this function, the state of the graph If you raise an exception in this function, the state of the graph
might be broken for all intents and purposes. might be broken for all intents and purposes.
""" """
def orderings(self, function_graph): def on_prune(self, fgraph, node, reason):
"""
Called whenever a node is pruned (removed) from the `fgraph`, after it
is disconnected from the graph.
"""
def orderings(self, fgraph):
""" """
Called by toposort. It should return a dictionary of Called by `FunctionGraph.toposort`. It should return a dictionary of
{node: predecessors} where predecessors is a list of ``{node: predecessors}`` where ``predecessors`` is a list of
nodes that should be computed before the key node. nodes that should be computed before the key node.
If you raise an exception in this function, the state of the graph If you raise an exception in this function, the state of the graph
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论