提交 0faeaab5 authored 作者: Arnaud Bergeron's avatar Arnaud Bergeron

Remove the developer section of the doc since it's full of outdated

things and move the explanation of the scan internals to extending.
上级 9fc02584
===================================
Compatibility with Python versions.
===================================
Theano is compatible with Python versions >= 2.6 including 3.x series.
This guide provides coding guidelines on how to maintain
comnpatibility.
Installation (2to3 and setup.py)
--------------------------------
Python code compatibility
-------------------------
Ideally, Python 3-incompatible changes should be caught by the Travis build,
but here are some guidelines for the major things to be aware of.
* When catching an exception and giving a name to it, use the new-style
syntax:
.. code-block:: python
except Exception as e:
...
* No tuple-unpacking in the argument list:
.. code-block:: python
def f(a, (b, c)): # wrong
...
def f(a, others):
b, c = others # right
* Always use ``print(...)`` as a function, and add
.. code-block:: python
from __future__ import print_function
At the top of files that use ``print``, above all other imports.
* If you mean to iterate over a range, use ``six.moves.xrange``. If you need
a range as a list, use ``list(range(...))``.
* If you mean to iterate over a zipped sequence, use ``theano.compat.izip``.
If you actually need it to be a list, use ``list(zip(...))``.
* If you mean to iterate over the output of a ``map``, use
``theano.compat.imap``. If you actually need it to be a list, use
``list(map(...))``.
* If using ``reduce``, ``StringIO``, ``pickle``/``cPickle``, or ``copy_reg``,
use the one in ``six.moves`` (note that ``copy_reg`` is named ``copyreg``).
* For iterating over the items, keys, values of a list, use
``six.iteritems(...)``, ``six.iterkeys(...)``, ``six.itervalues(...)``. If
you wish to grab these as lists, wrap them in a ``list(...)`` call.
* Avoid ``itertools.{izip,ifilter,imap}``. Use the equivalently named functions
from ``theano.compat``.
* Don't use `__builtin__`. Rather, ``six.moves.builtins``.
* Rather than the three-argument version of ``raise``, use
``six.reraise(...)``.
* Don't call the ``.next()`` method of iterators. Use the builtin
``next(...)``.
* When type testing for ``str`` or ``int``/``long``, use ``six.string_types``
and ``six.integer_types``, respectively.
* Use the ``six.add_metaclass`` class decorator for adding metaclasses.
Compatibility package (theano.compat)
.....................................
Compatibility between 2.x and 3.x is implemented using six_, a Python
2 and 3 compatibility library by Benjamin Peterson. Additionally,
certain additional or modified functions are available in the ``theano.compat``
module.
Strings, bytes and unicode
..........................
``str`` and ``bytes`` are different types in Python 3. Mostly this doesn't
come up for Theano's purposes. ``str`` represents encoded text, i.e. character
encoding-aware; all Python 3 strings are internally stored as Unicode. When
converting from one or the other, you must `.encode(...)` bytes and
`.decode(...)` strings with a given character encoding (e.g. ``'ascii'``,
``'utf8'``, ``'latin1'``).
C code compatibility
--------------------
Module initialization
.....................
PyCapsule and PyCObject
.......................
References
----------
.. _six: http://pythonhosted.org/six
:orphan:
.. _developer:
==============================================
Theano Design and Implementation Documentation
==============================================
.. toctree::
:maxdepth: 2
tensor
scan
compat
.. _tensor:
=======
Tensor
=======
This file describes the design of theano.tensor.
Elemwise grad and R_op
======================
Here's another straightforward example, though a bit more elaborate
than adding two numbers together. Let's say that you want to compute
the logistic curve, which is given by:
.. math::
s(x) = \frac{1}{1 + e^{-x}}
......@@ -49,4 +49,5 @@ with Theano itself.
optimization
tips
unittest
scan
extending_faq
......@@ -94,24 +94,27 @@ Scan variables
The following are the different types of variables that Scan has the capacity to
handle, along with their various caracteristics.
**Sequence** : A sequence is a Theano variable which Scan will iterate over and
give sub-elements to its inner function as input. A sequence has no associated
output. For a sequence variable ``X``, at timestep ``t``, the inner function will
receive as input the sequence element ``X[t]``. These variables are used through
the argument ``sequences`` of the ``theano.scan()`` function.
**Non-sequences** : A non-sequence is a Theano variable which Scan will provide
*as-is* to its inner function. Like a sequence, a non-sequence has no
associated output. For a non-sequence variable ``X``, at timestep ``t``, the inner
function will receive as input the variable ``X``. These variables are used through
the argument ``non_sequences`` of the ``theano.scan()`` function.
**Nitsot (no input tap, single output tap)** : A nitsot is an output variable of
the inner function that is not fed back as an input to the next iteration of the
inner function. Nitsots are typically encountered in situations where Scan is
used to perform a 'map' operation (every element in a tensor is independently
altered using a given operation to produce a new tensor) such as squaring every
number in a vector.
**Sequence** : A sequence is a Theano variable which Scan will iterate
over and give sub-elements to its inner function as input. A sequence
has no associated output. For a sequence variable ``X``, at timestep
``t``, the inner function will receive as input the sequence element
``X[t]``. These variables are used through the argument ``sequences``
of the ``theano.scan()`` function.
**Non-sequences** : A non-sequence is a Theano variable which Scan
*will provide as-is* to its inner function. Like a sequence, a
*non-sequence has no associated output. For a non-sequence variable
*``X``, at timestep ``t``, the inner function will receive as input
*the variable ``X``. These variables are used through the argument
*``non_sequences`` of the ``theano.scan()`` function.
**Nitsot (no input tap, single output tap)** : A nitsot is an output
variable of the inner function that is not fed back as an input to the
next iteration of the inner function. Nitsots are typically
encountered in situations where Scan is used to perform a 'map'
operation (every element in a tensor is independently altered using a
given operation to produce a new tensor) such as squaring every number
in a vector.
**Sitsot (single input tap, single output tap)** : A sitsot is an output
variable of the inner function that is fed back as an input to the next
......@@ -120,13 +123,14 @@ encountered is the case where Scan is used to compute the cumulative sum over
the elements of a vector and a sitsot output is employed to act as an
accumulator.
**Mitsot (multiple input taps, single output tap)** : A mitsot is an output
variable of the inner function that is fed back as an input to future iterations
of the inner function (either multiple future iterations or a single one that
isn't the immediate next one). For example, a mitsot might be used in the case
where Scan is used to compute the Fibonacci sequence, one term of the sequence
at every timestep, since every computed term needs to be reused to compute
the two next terms of the sequence.
**Mitsot (multiple input taps, single output tap)** : A mitsot is an
output variable of the inner function that is fed back as an input to
future iterations of the inner function (either multiple future
iterations or a single one that isn't the immediate next one). For
example, a mitsot might be used in the case where Scan is used to
compute the Fibonacci sequence, one term of the sequence at every
timestep, since every computed term needs to be reused to compute the
two next terms of the sequence.
**Mitmot (multiple input taps, multiple output taps)** : These outputs exist
but they cannot be directly created by the user. They can appear in a theano
......@@ -272,12 +276,13 @@ by usage.
Accessing/manipulating Scan's inputs and outputs by type
--------------------------------------------------------
Declared in ``scan_utils.py``, the class ``scan_args`` handles the parsing
of the inputs and outputs (both inner and outer) to a format that is easier to
analyse and manipulate. Without this class, analysing Scan's inputs and
outputs often required convoluted logic which make for code that is hard to
read and to maintain. Because of this, you should favor using ``scan_args`` when
it is practical and appropriate to do so.
Declared in ``scan_utils.py``, the class ``scan_args`` handles the
parsing of the inputs and outputs (both inner and outer) to a format
that is easier to analyse and manipulate. Without this class,
analysing Scan's inputs and outputs often required convoluted logic
which make for code that is hard to read and to maintain. Because of
this, you should favor using ``scan_args`` when it is practical and
appropriate to do so.
The scan op also defines a few helper functions for this purpose, such as
``inner_nitsot_outs()`` or ``mitmot_out_taps()``, but they are often poorly
......@@ -320,10 +325,11 @@ individual indices or -1 if there is not corresponding outer variable.
For mappings to inner variables, the values are list of indices because
multiple inner variables may be associated with the same state.
If the goal is to navigate between variables that are *connected* (meaning
that one of them is used to compute the other), the methods
``connection_pattern()`` and ``inner_connection_pattern()`` can be used.
The method ``connection_pattern()`` returns a list of lists detailing, for every
pair of outer input and outer output whether they are connected or not. The
method ``inner_connection_pattern()`` accomplishes the same goal but for every
possible pair of inner output and inner input.
If the goal is to navigate between variables that are *connected*
(meaning that one of them is used to compute the other), the methods
``connection_pattern()`` and ``inner_connection_pattern()`` can be
used. The method ``connection_pattern()`` returns a list of lists
detailing, for every pair of outer input and outer output whether they
are connected or not. The method ``inner_connection_pattern()``
accomplishes the same goal but for every possible pair of inner output
and inner input.
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论