Skip to content

Commit 8af4120

Browse files
committed
added many stubs to the advanced section of the docs
1 parent 077c982 commit 8af4120

13 files changed

+281
-101
lines changed

LICENSE.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
doc/doc/LICENSE.txt
1+
doc/LICENSE.txt
File renamed without changes.

doc/advanced/compilation.txt

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
.. _compilation:
3+
4+
=======================
5+
Compilation and Linking
6+
=======================

doc/advanced/env.txt

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
.. _env:
3+
4+
===
5+
Env
6+
===

doc/advanced/function.txt

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
2+
.. _functioninterface:
3+
4+
==================
5+
Function Interface
6+
==================
7+
8+
This section details the various structures used to make ``function``
9+
work. You might want to read the sections about :ref:`compilation` and
10+
:ref:`optimization`.
11+
12+
13+
14+
15+
16+
.. index::
17+
single: Mode
18+
19+
.. _mode:
20+
21+
----
22+
Mode
23+
----
24+
25+
WRITEME
26+
27+
28+
.. index::
29+
single: function
30+
31+
.. _function:
32+
33+
--------
34+
function
35+
--------
36+
37+
WRITEME
38+
39+
40+
.. index::
41+
single: FunctionMaker
42+
43+
.. _functionmaker:
44+
45+
-------------
46+
FunctionMaker
47+
-------------
48+
49+
WRITEME
50+

doc/advanced/graphstructures.txt

+133
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,139 @@
55
Graph Structures
66
================
77

8+
Theano represents mathematical computations as graphs. These graphs
9+
are formed of interconnected :ref:`apply` and :ref:`result` nodes,
10+
which are standard types of objects. They are respectively associated
11+
to *function application* and *data*. Two additional structures are
12+
used by Theano in order to represent the operations carried in the
13+
computations and the data types that are processed. Operations are
14+
represented :ref:`op` instances and data types are represented by
15+
:ref:`type` instances. Here is a piece of code and a diagram showing
16+
the structure built by that piece of code. This should help you
17+
understand how all these things play together:
18+
19+
20+
-----------------------
21+
22+
**Code**
23+
24+
.. code-block:: python
25+
26+
x = dmatrix('x')
27+
y = dmatrix('y')
28+
z = x + y
29+
30+
**Diagram**
31+
32+
.. image:: apply.png
33+
34+
-----------------------
35+
36+
Arrows represent references to the Python objects pointed at. The blue
37+
box is an :ref:`apply` node. Red boxes are :ref:`result` nodes. Green
38+
circles are :ref:`Ops <op>`. Purple boxes are :ref:`Types <type>`.
39+
40+
When we create :ref:`Results <result>` and then :ref:`apply`
41+
:ref:`operations <op>` to them to make more Results, we build a
42+
bi-partite, directed, acyclic graph. Results point to the Apply nodes
43+
representing the function application producing them via their
44+
``owner`` field. These Apply nodes point in turn to their input and
45+
output Results via their ``inputs`` and ``outputs`` fields.
46+
47+
The ``owner`` field of both ``x`` and ``y`` point to ``None`` because
48+
they are not the result of another computation. If they were the
49+
result of another computation, they would point to another blue box
50+
like ``z`` does, and so on.
51+
52+
53+
An explicit example
54+
===================
55+
56+
In this example we will see in turn a short example where the graph
57+
construction is hidden behind the standard interface's syntactic
58+
shortcuts and then the same example but rolled out so that the graph
59+
construction is made explicit.
60+
61+
62+
**Short example**
63+
64+
This is what you would normally type:
65+
66+
.. code-block:: python
67+
68+
from theano.tensor import *
69+
70+
# create 3 Results with owner = None
71+
x = matrix('x')
72+
y = matrix('y')
73+
z = matrix('z')
74+
75+
# create 2 Results (one for 'e', one intermediate for y*z)
76+
# create 2 Apply instances (one for '+', one for '*')
77+
e = x + y * z
78+
79+
80+
**Long example**
81+
82+
This is what you would type to build the graph explicitly:
83+
84+
.. code-block:: python
85+
86+
from theano.tensor import *
87+
88+
# We instantiate a type that represents a matrix of doubles
89+
float64_matrix = Tensor(dtype = 'float64', # double
90+
broadcastable = (False, False)) # matrix
91+
92+
# We make the Result instances we need.
93+
x = Result(type = float64_matrix, name = 'x')
94+
y = Result(type = float64_matrix, name = 'y')
95+
z = Result(type = float64_matrix, name = 'z')
96+
97+
# This is the Result that we want to symbolically represents y*z
98+
mul_result = Result(type = float64_matrix)
99+
assert mul_result.owner is None
100+
101+
# We instantiate a symbolic multiplication
102+
node_mul = Apply(op = mul,
103+
inputs = [y, z],
104+
outputs = [mul_result])
105+
assert mul_result.owner is node_mul and mul_result.index == 0 # these fields are set by Apply
106+
107+
# This is the Result that we want to symbolically represents x+(y*z)
108+
add_result = Result(type = float64_matrix)
109+
assert add_result.owner is None
110+
111+
# We instantiate a symbolic addition
112+
node_add = Apply(op = add,
113+
inputs = [x, mul_result],
114+
outputs = [add_result])
115+
assert add_result.owner is node_add and add_result.index == 0 # these fields are set by Apply
116+
117+
e = add_result
118+
119+
# We have access to x, y and z through pointers
120+
assert e.owner.inputs[0] is x
121+
assert e.owner.inputs[1] is mul_result
122+
assert e.owner.inputs[1].owner.inputs[0] is y
123+
assert e.owner.inputs[1].owner.inputs[1] is z
124+
125+
126+
Note how the call to ``Apply`` modifies the ``owner`` and ``index``
127+
fields of the :ref:`Results <result>` passed as outputs to point to
128+
itself and the rank they occupy in the output list. This whole
129+
machinery builds a DAG (Directed Acyclic Graph) representing the
130+
computation, a graph that theano can compile and optimize.
131+
132+
133+
Graph Structures
134+
================
135+
136+
The following section outlines each type of structure that may be used
137+
in a Theano-built computation graph. The following structures are
138+
explained: :ref:`apply`, :ref:`constant`, :ref:`op`, :ref:`result` and
139+
:ref:`type`.
140+
8141

9142
.. index::
10143
single: Apply

doc/advanced/index.txt

+6
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,10 @@ Advanced Topics
99
:maxdepth: 2
1010

1111
graphstructures
12+
env
13+
optimization
14+
compilation
15+
function
16+
module
17+
1218

doc/advanced/module.txt

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
2+
.. _moduleinterface:
3+
4+
================
5+
Module Interface
6+
================
7+
8+
WRITEME
9+
10+
11+
12+
.. index::
13+
single: Member
14+
single: component; Member
15+
16+
.. _member:
17+
18+
------
19+
Member
20+
------
21+
22+
WRITEME
23+
24+
25+
.. index::
26+
single: Method
27+
single: component; Method
28+
29+
.. _method:
30+
31+
------
32+
Method
33+
------
34+
35+
WRITEME
36+
37+
38+
.. index::
39+
single: Module
40+
single: component; Module
41+
42+
.. _module:
43+
44+
------
45+
Module
46+
------
47+
48+
WRITEME
49+
50+
51+
52+

doc/advanced/optimization.txt

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
.. _optimization:
3+
4+
============
5+
Optimization
6+
============

doc/glossary.txt

+1-93
Original file line numberDiff line numberDiff line change
@@ -183,100 +183,8 @@ Glossary of terminology
183183
WRITEME
184184

185185
Graph
186-
interconnected :term:`Apply` and :term:`Result` instances
187-
188-
In theano, a graph is an implicit concept, not a class or
189-
an instance. When we create :term:`Results <Result>` and
190-
then :term:`apply` :term:`operations <Op>` to them to make
191-
more Results, we build a bi-partite, directed, acyclic graph.
192-
Results point to Apply instances (via the ``owner`` field)
193-
and Apply instances point to Results (via their ``inputs``
194-
and ``outputs`` fields).
195-
196-
To see how :term:`Result`, :term:`Type`, :term:`Apply`, and
197-
:term:`Op` all work together, compare the following code fragment
198-
and illustration.
199-
200-
.. code-block:: python
201-
202-
#!python
203-
x = matrix('x')
204-
y = matrix('y')
205-
z = x + y
206-
207-
.. image:: apply.png
208-
209-
Arrows represent references (python's pointers), the blue box is an Apply instance, red boxes are :term:`Result` nodes, green circles are :term:`Op` instances, purple boxes are :term:`Type` instances.
210-
211-
Short example:
212-
213-
.. code-block:: python
214-
215-
#!python
216-
from theano.tensor import *
217-
218-
# create 3 Results with owner = None
219-
x = matrix('x')
220-
y = matrix('y')
221-
z = matrix('z')
222-
223-
# create 2 Results (one for 'e', one intermediate for y*z)
224-
# create 2 Apply instances (one for '+', one for '*')
225-
e = x + y * z
226-
227-
Long example:
228-
229-
The example above uses several syntactic shortcuts.
230-
If we had wanted a more brute-force approach to graph construction, we could have typed this.
231-
232-
.. code-block:: python
186+
TRANSFERRED
233187

234-
#!python
235-
from theano.tensor import *
236-
237-
# We instantiate a type that represents a matrix of doubles
238-
float64_matrix = Tensor(dtype = 'float64', # double
239-
broadcastable = (False, False)) # matrix
240-
241-
# We make the Result instances we need.
242-
x = Result(type = float64_matrix, name = 'x')
243-
y = Result(type = float64_matrix, name = 'y')
244-
z = Result(type = float64_matrix, name = 'z')
245-
246-
# This is the Result that we want to symbolically represents y*z
247-
mul_result = Result(type = float64_matrix)
248-
assert mul_result.owner is None
249-
250-
# We instantiate a symbolic multiplication
251-
node_mul = Apply(op = mul,
252-
inputs = [y, z],
253-
outputs = [mul_result])
254-
assert mul_result.owner is node_mul and mul_result.index == 0 # these fields are set by Apply
255-
256-
# This is the Result that we want to symbolically represents x+(y*z)
257-
add_result = Result(type = float64_matrix)
258-
assert add_result.owner is None
259-
260-
# We instantiate a symbolic addition
261-
node_add = Apply(op = add,
262-
inputs = [x, mul_result],
263-
outputs = [add_result])
264-
assert add_result.owner is node_add and add_result.index == 0 # these fields are set by Apply
265-
266-
e = add_result
267-
268-
# We have access to x, y and z through pointers
269-
assert e.owner.inputs[0] is x
270-
assert e.owner.inputs[1] is mul_result
271-
assert e.owner.inputs[1].owner.inputs[0] is y
272-
assert e.owner.inputs[1].owner.inputs[1] is z
273-
274-
Note how the call to ``Apply`` modifies the ``owner``
275-
and ``index`` fields of the :term:`Results <Result>` passed as
276-
outputs to point to itself and the rank they occupy in the
277-
output list. This whole machinery builds a DAG (Directed
278-
Acyclic Graph) representing the computation, a graph that
279-
theano can compile and optimize.
280188

281189
Graph Transformation
282190
compilation stage

doc/index.txt

+1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ Contents
6969
advtutorial/index
7070
advanced/index
7171
indexes/index
72+
glossary
7273
LICENSE
7374

7475

0 commit comments

Comments
 (0)