提交 8b0980b8 authored 作者: Iban Harlouchet's avatar Iban Harlouchet 提交者: Arnaud Bergeron

testcode for doc/extending/graphstructures.txt

上级 4b8b6eee
...@@ -18,10 +18,12 @@ should help you understand how these pieces fit together: ...@@ -18,10 +18,12 @@ should help you understand how these pieces fit together:
**Code** **Code**
.. code-block:: python .. testcode::
x = dmatrix('x') import theano.tensor as T
y = dmatrix('y')
x = T.dmatrix('x')
y = T.dmatrix('y')
z = x + y z = x + y
**Diagram** **Diagram**
...@@ -72,7 +74,7 @@ This is what you would normally type: ...@@ -72,7 +74,7 @@ This is what you would normally type:
.. If you modify this code, also change : .. If you modify this code, also change :
.. theano/tests/test_tutorial.py:T_graphstructures.test_graphstructures_1 .. theano/tests/test_tutorial.py:T_graphstructures.test_graphstructures_1
.. code-block:: python .. testcode::
# create 3 Variables with owner = None # create 3 Variables with owner = None
x = T.matrix('x') x = T.matrix('x')
...@@ -91,7 +93,7 @@ This is what you would type to build the graph explicitly: ...@@ -91,7 +93,7 @@ This is what you would type to build the graph explicitly:
.. If you modify this code, also change : .. If you modify this code, also change :
.. theano/tests/test_tutorial.py:T_graphstructures.test_graphstructures_1 .. theano/tests/test_tutorial.py:T_graphstructures.test_graphstructures_1
.. code-block:: python .. testcode::
from theano.tensor import add, mul, Apply, Variable, TensorType from theano.tensor import add, mul, Apply, Variable, TensorType
...@@ -153,13 +155,13 @@ All nodes in the graph must be instances of ``Apply`` or ``Result``, but ...@@ -153,13 +155,13 @@ All nodes in the graph must be instances of ``Apply`` or ``Result``, but
constraints. For example, the :func:`tensor.add` constraints. For example, the :func:`tensor.add`
Op instance is written so that: Op instance is written so that:
.. code-block:: python .. testcode::
e = dscalar('x') + 1 e = T.dscalar('x') + 1
builds the following graph: builds the following graph:
.. code-block:: python .. testcode::
node = Apply(op = add, node = Apply(op = add,
inputs = [Variable(type = dscalar, name = 'x'), inputs = [Variable(type = dscalar, name = 'x'),
...@@ -311,6 +313,7 @@ Theano. The symbolic inputs that you operate on are Variables and what ...@@ -311,6 +313,7 @@ Theano. The symbolic inputs that you operate on are Variables and what
you get from applying various Ops to these inputs are also you get from applying various Ops to these inputs are also
Variables. For example, when I type Variables. For example, when I type
>>> import theano
>>> x = theano.tensor.ivector() >>> x = theano.tensor.ivector()
>>> y = -x >>> y = -x
...@@ -399,7 +402,7 @@ In both types of pairs, the second element of the tuple is an index, ...@@ -399,7 +402,7 @@ In both types of pairs, the second element of the tuple is an index,
such that: ``var.clients[*][0].inputs[index]`` or such that: ``var.clients[*][0].inputs[index]`` or
``fgraph.outputs[index]`` is that variable. ``fgraph.outputs[index]`` is that variable.
.. code-block:: python .. testcode::
import theano import theano
v = theano.tensor.vector() v = theano.tensor.vector()
...@@ -427,3 +430,11 @@ such that: ``var.clients[*][0].inputs[index]`` or ...@@ -427,3 +430,11 @@ such that: ``var.clients[*][0].inputs[index]`` or
client client
# ('output', 0) # ('output', 0)
assert f.maker.fgraph.outputs[client[1]] is var assert f.maker.fgraph.outputs[client[1]] is var
.. testoutput::
Sum{acc_dtype=float64} [@A] '' 1
|Elemwise{add,no_inplace} [@B] '' 0
|TensorConstant{(1,) of 1.0} [@C]
|<TensorType(float64, vector)> [@D]
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论