提交 03b82c26 authored 作者: Brandon T. Willard's avatar Brandon T. Willard 提交者: Brandon T. Willard

Update and add missing docstrings in theano.gof.graph

上级 63fd27b5
...@@ -22,13 +22,12 @@ NoParams = object() ...@@ -22,13 +22,12 @@ NoParams = object()
class Node(utils.object2): class Node(utils.object2):
""" """A `Node` in a Theano graph.
A Node in a theano graph.
Graphs contain two kinds of Nodes -- Variable and Apply. Currently, graphs contain two kinds of `Nodes`: `Variable`s and `Apply`s.
Edges in the graph are not explicitly represented. Edges in the graph are not explicitly represented.
Instead each Node keeps track of its parents via Instead each `Node` keeps track of its parents via
Variable.owner / Apply.inputs and its children `Variable.owner` / `Apply.inputs` and its children
via Variable.clients / Apply.outputs. via Variable.clients / Apply.outputs.
""" """
...@@ -44,48 +43,46 @@ class Node(utils.object2): ...@@ -44,48 +43,46 @@ class Node(utils.object2):
class Apply(Node): class Apply(Node):
""" """A `Node` representing the application of an operation to inputs.
An :term:`Apply` instance is a node in an expression graph which represents
the application of an `Op` to some input `Variable` nodes, producing some
output `Variable` nodes.
This class is typically instantiated by an Op's make_node() function, which An `Apply` instance serves as a simple structure with three important
is typically called by that Op's __call__() function.
An Apply instance serves as a simple structure with three important
attributes: attributes:
- :literal:`inputs` : a list of `Variable` nodes that represent the - :literal:`inputs` : a list of `Variable` nodes that represent the
arguments of the expression, arguments of the expression,
- :literal:`outputs` : a list of `Variable` nodes that represent the - :literal:`outputs` : a list of `Variable` nodes that represent the
variable of the expression, and computed outputs of the expression, and
- :literal:`op` : an `Op` instance that determines the nature of the - :literal:`op` : an `Op` instance that determines the nature of the
expression being applied. expression being applied.
The driver `compile.function` uses Apply's inputs attribute together with Basically, an `Apply` instance is an object that represents the
Variable's owner attribute to search the expression graph and determine Python statement `outputs = op(*inputs)`.
which inputs are necessary to compute the function's outputs.
This class is typically instantiated by a `PureOp.make_node` method, which
is called by `PureOp.__call__`.
A `Linker` uses the Apply instance's `op` field to compute the variables. The driver `theano.compile.function` uses `Apply.inputs` together with
`Variable.owner` to search the expression graph and determine which inputs
are necessary to compute the function's outputs.
Comparing with the Python language, an `Apply` instance is theano's version A `Linker` uses the `Apply` instance's `op` field to compute numeric values
of a function call (or expression instance) whereas `Op` is theano's version for the output variables.
of a function definition.
Parameters Parameters
---------- ----------
op : `Op` instance op : A PureOp instance
inputs : list of Variable instances inputs : list of Variable instances
outputs : list of Variable instances outputs : list of Variable instances
Notes Notes
----- -----
The owner field of each output in the outputs list will be set to self. The `Variable.owner` field of each `Apply.outputs` element is set to `self`
in `Apply.make_node`.
If an output element has an owner that is neither None nor self, then a If an output element has an owner that is neither `None` nor `self`, then a
ValueError exception will be raised. `ValueError` exception will be raised.
""" """
...@@ -381,7 +378,7 @@ class Variable(Node): ...@@ -381,7 +378,7 @@ class Variable(Node):
__count__ = count(0) __count__ = count(0)
def __init__(self, type, owner=None, index=None, name=None): def __init__(self, type, owner=None, index=None, name=None):
super(Variable, self).__init__() super().__init__()
self.tag = utils.ValidatingScratchpad("test_value", type.filter) self.tag = utils.ValidatingScratchpad("test_value", type.filter)
...@@ -567,25 +564,22 @@ class Variable(Node): ...@@ -567,25 +564,22 @@ class Variable(Node):
class Constant(Variable): class Constant(Variable):
""" """A `Variable` with a fixed `value` field.
A :term:`Constant` is a `Variable` with a `value` field that cannot be
changed at runtime.
Constant nodes make eligible numerous optimizations: constant inlining in Constant nodes make numerous optimizations possible (e.g. constant inlining
C code, constant folding, etc. in C code, constant folding, etc.)
Notes Notes
----- -----
The data field is filtered by what is provided in the constructor for the The data field is filtered by what is provided in the constructor for the
Constant's type field. `Constant`'s type field.
WRITEME
""" """
# __slots__ = ['data'] # __slots__ = ['data']
def __init__(self, type, data, name=None): def __init__(self, type, data, name=None):
Variable.__init__(self, type, None, None, name) super().__init__(type, None, None, name)
self.data = type.filter(data) self.data = type.filter(data)
utils.add_tag_trace(self) utils.add_tag_trace(self)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论