提交 92cb4b40 authored 作者: James Bergstra's avatar James Bergstra

fixing technical stuff in docs

上级 efa9630b
...@@ -26,26 +26,28 @@ What needs to be defined ...@@ -26,26 +26,28 @@ What needs to be defined
There are less methods to define for an Op than for a Type: There are less methods to define for an Op than for a Type:
.. function:: c_code(node, name, input_names, output_names, sub) .. class:: Op
This must return C code that carries the computation we want to do. .. method:: c_code(node, name, input_names, output_names, sub)
.. function:: c_code_cleanup(node, name, input_names, output_names, sub) This must return C code that carries the computation we want to do.
This must return C code that cleans up whatever c_code allocated and .. method:: c_code_cleanup(node, name, input_names, output_names, sub)
that we must free.
*Default:* The default behavior is to do nothing. This must return C code that cleans up whatever c_code allocated and
that we must free.
.. function:: c_compile_args() *Default:* The default behavior is to do nothing.
c_no_compile_args()
c_headers()
c_libraries()
c_support_code()
Allows you to specify headers, libraries, .. method:: c_compile_args()
special g++ arguments to add/exclude or .. method:: c_no_compile_args()
helper functions/structs that the type needs. See :ref:`op`. .. method:: c_headers()
.. method:: c_libraries()
.. method:: c_support_code()
Allows you to specify headers, libraries,
special g++ arguments to add/exclude or
helper functions/structs that the type needs. See :ref:`op`.
The ``name`` argument is currently given an invalid value, so steer The ``name`` argument is currently given an invalid value, so steer
......
...@@ -46,43 +46,45 @@ be found in the documentation for :api:`gof.type.Type`. Here, we'll focus on ...@@ -46,43 +46,45 @@ be found in the documentation for :api:`gof.type.Type`. Here, we'll focus on
the most important ones: the most important ones:
.. function:: c_declare(name, sub) .. class:: CLinkerType
This must return C code which declares variables. These variables .. method:: c_declare(name, sub)
will be available to operations defined in C. You may also write
typedefs.
.. function:: c_init(name, sub) This must return C code which declares variables. These variables
will be available to operations defined in C. You may also write
typedefs.
This must return C code which initializes the variables declared in .. method:: c_init(name, sub)
``c_declare``. Either this or ``c_extract`` will be called.
.. function:: c_extract(name, sub) This must return C code which initializes the variables declared in
``c_declare``. Either this or ``c_extract`` will be called.
This must return C code which takes a reference to a Python object .. method:: c_extract(name, sub)
and initializes the variables declared in ``c_declare`` to match the
Python object's data. Either this or ``c_init`` will be called.
.. function:: c_sync(name, sub) This must return C code which takes a reference to a Python object
and initializes the variables declared in ``c_declare`` to match the
Python object's data. Either this or ``c_init`` will be called.
When the computations are done, transfer the variables from the C .. method:: c_sync(name, sub)
structure we put them in to the destination Python object. This will
only be called for the outputs.
.. function:: c_cleanup(name, sub) When the computations are done, transfer the variables from the C
structure we put them in to the destination Python object. This will
only be called for the outputs.
When we are done using the data, clean up whatever we allocated and .. method:: c_cleanup(name, sub)
decrease the appropriate reference counts.
.. function:: c_compile_args() When we are done using the data, clean up whatever we allocated and
c_no_compile_args() decrease the appropriate reference counts.
c_headers()
c_libraries()
c_support_code()
Allows you to specify headers, libraries, .. method:: c_compile_args()
special g++ arguments to add/exclude or c_no_compile_args()
helper functions/structs that the type needs. See :ref:`type`. c_headers()
c_libraries()
c_support_code()
Allows you to specify headers, libraries,
special g++ arguments to add/exclude or
helper functions/structs that the type needs. See :ref:`type`.
Each of these functions take two arguments, ``name`` and ``sub`` which Each of these functions take two arguments, ``name`` and ``sub`` which
...@@ -391,7 +393,7 @@ done. Note which variables get extracted (the three inputs ``x``, ``y`` and ...@@ -391,7 +393,7 @@ done. Note which variables get extracted (the three inputs ``x``, ``y`` and
output ``b``) and which one is synced (the final output ``b``). output ``b``) and which one is synced (the final output ``b``).
The C code above is a single C block for the whole graph. Depending on The C code above is a single C block for the whole graph. Depending on
which :ref:`linker` is used to process the computation graph, it is which :term:`linker` is used to process the computation graph, it is
possible that one such block is generated for each operation and that possible that one such block is generated for each operation and that
we transit through Python after each operation. In that situation, we transit through Python after each operation. In that situation,
``a`` would be synced by the addition block and extracted by the ``a`` would be synced by the addition block and extracted by the
......
...@@ -146,7 +146,7 @@ Automatic wrapping ...@@ -146,7 +146,7 @@ Automatic wrapping
All nodes in the graph must be instances of ``Apply`` or ``Result``, but All nodes in the graph must be instances of ``Apply`` or ``Result``, but
``<Op subclass>.make_node()`` typically wraps constants to satisfy those ``<Op subclass>.make_node()`` typically wraps constants to satisfy those
constraints. For example, the :api:`tensor.add <theano.tensor.basic.add>` constraints. For example, the :func:`tensor.add`
Op instance is written so that: Op instance is written so that:
.. code-block:: python .. code-block:: python
...@@ -189,8 +189,8 @@ An *Apply node* is a type of internal node used to represent a ...@@ -189,8 +189,8 @@ An *Apply node* is a type of internal node used to represent a
manipulated directly by the end user. They may be accessed via manipulated directly by the end user. They may be accessed via
a Variable's ``owner`` field. a Variable's ``owner`` field.
An Apply node is typically an instance of the :api:`Apply An Apply node is typically an instance of the :class:`Apply`
<theano.gof.graph.Apply>` class. It represents the application class. It represents the application
of an :ref:`op` on one or more inputs, where each input is a of an :ref:`op` on one or more inputs, where each input is a
:ref:`variable`. By convention, each Op is responsible for :ref:`variable`. By convention, each Op is responsible for
knowing how to build an Apply node from a list of knowing how to build an Apply node from a list of
...@@ -215,8 +215,7 @@ An Apply instance has three important fields: ...@@ -215,8 +215,7 @@ An Apply instance has three important fields:
A list of :ref:`Variables <variable>` that represent the return values A list of :ref:`Variables <variable>` that represent the return values
of the function. of the function.
An Apply instance can be created by calling ``gof.Apply(op, inputs, An Apply instance can be created by calling ``gof.Apply(op, inputs, outputs)``.
outputs)``.
...@@ -260,7 +259,7 @@ Type ...@@ -260,7 +259,7 @@ Type
A :ref:`type` in Theano represents a set of constraints on potential A :ref:`type` in Theano represents a set of constraints on potential
data objects. These constraints allow Theano to tailor C code to handle data objects. These constraints allow Theano to tailor C code to handle
them and to statically optimize the computation graph. For instance, them and to statically optimize the computation graph. For instance,
the :ref:`irow <predefinedtypes>` type in the ``theano.tensor`` package the :ref:`irow <libdoc_tensor_creation>` type in the ``theano.tensor`` package
gives the following constraints on the data the Variables of type ``irow`` gives the following constraints on the data the Variables of type ``irow``
may contain: may contain:
...@@ -273,8 +272,8 @@ that declares the right data types and that contains the right number ...@@ -273,8 +272,8 @@ that declares the right data types and that contains the right number
of loops over the dimensions. of loops over the dimensions.
Note that a Theano :ref:`type` is not equivalent to a Python type or Note that a Theano :ref:`type` is not equivalent to a Python type or
class. Indeed, in Theano, :ref:`irow <predefinedtypes>` and :ref:`dmatrix class. Indeed, in Theano, :ref:`irow <libdoc_tensor_creation>` and :ref:`dmatrix
<predefinedtypes>` both use ``numpy.ndarray`` as the underlying type <libdoc_tensor_creation>` both use ``numpy.ndarray`` as the underlying type
for doing computations and storing data, yet they are different Theano for doing computations and storing data, yet they are different Theano
Types. Indeed, the constraints set by ``dmatrix`` are: Types. Indeed, the constraints set by ``dmatrix`` are:
...@@ -311,8 +310,7 @@ Variables. For example, when I type ...@@ -311,8 +310,7 @@ Variables. For example, when I type
>>> x = theano.tensor.ivector() >>> x = theano.tensor.ivector()
>>> y = -x >>> y = -x
``x`` and ``y`` are both Variables, i.e. instances of the :api:`Variable ``x`` and ``y`` are both Variables, i.e. instances of the :class:`Variable` class. The :ref:`type` of both ``x`` and
<theano.gof.graph.Variable>` class. The :ref:`type` of both ``x`` and
``y`` is ``theano.tensor.ivector``. ``y`` is ``theano.tensor.ivector``.
Unlike ``x``, ``y`` is a Variable produced by a computation (in this Unlike ``x``, ``y`` is a Variable produced by a computation (in this
...@@ -324,7 +322,7 @@ through ``y.owner``. ...@@ -324,7 +322,7 @@ through ``y.owner``.
More specifically, a Variable is a basic structure in Theano that More specifically, a Variable is a basic structure in Theano that
represents a datum at a certain point in computation. It is typically represents a datum at a certain point in computation. It is typically
an instance of the class :api:`Variable <theano.gof.graph.Variable>` or an instance of the class :class:`Variable` or
one of its subclasses. one of its subclasses.
A Variable ``r`` contains four important fields: A Variable ``r`` contains four important fields:
...@@ -365,6 +363,7 @@ any circumstances modify the input. This means that a constant is ...@@ -365,6 +363,7 @@ any circumstances modify the input. This means that a constant is
eligible to participate in numerous optimizations: constant inlining eligible to participate in numerous optimizations: constant inlining
in C code, constant folding, etc. in C code, constant folding, etc.
A constant does not need to be specified in a :ref:`function`'s list A constant does not need to be specified in a :func:`function
<function.function>`'s list
of inputs. In fact, doing so will raise an exception. of inputs. In fact, doing so will raise an exception.
...@@ -12,7 +12,7 @@ computations. We'll start by defining multiplication. ...@@ -12,7 +12,7 @@ computations. We'll start by defining multiplication.
Op's contract Op's contract
============= =============
An Op (:api:`gof.op.Op`) is any object which defines the An Op (:class:`gof.Op`) is any object which defines the
following methods: following methods:
...@@ -134,9 +134,7 @@ following methods: ...@@ -134,9 +134,7 @@ following methods:
includes this Op. includes this Op.
For each method, the *default* is what :api:`theano.gof.op.Op` defines At a bare minimum, a new Op must define ``make_node`` and ``perform``, which have no defaults.
for you. At a bare minimum, a new Op must define ``make_node`` and
``perform``, which have no defaults.
For more details, including the interface for providing a C For more details, including the interface for providing a C
implementation of ``perform()``, refer to the documentation for :ref:`op`. implementation of ``perform()``, refer to the documentation for :ref:`op`.
......
...@@ -139,7 +139,7 @@ simplification described above: ...@@ -139,7 +139,7 @@ simplification described above:
Here's how it works: first, in ``add_requirements``, we add the Here's how it works: first, in ``add_requirements``, we add the
``ReplaceValidate`` :ref:`envfeature` located in ``ReplaceValidate`` :ref:`envfeature` located in
:api:`theano.gof.toolbox`. This feature adds the ``replace_validate`` :ref:`libdoc_gof_toolbox`. This feature adds the ``replace_validate``
method to ``env``, which is an enhanced version of ``replace`` that method to ``env``, which is an enhanced version of ``replace`` that
does additional checks to ensure that we are not messing up the does additional checks to ensure that we are not messing up the
computation graph (note: if ``ReplaceValidate`` was already added by computation graph (note: if ``ReplaceValidate`` was already added by
...@@ -305,7 +305,7 @@ Theano defines some shortcuts to make LocalOptimizers: ...@@ -305,7 +305,7 @@ Theano defines some shortcuts to make LocalOptimizers:
.. function:: PatternSub(pattern1, pattern2) .. function:: PatternSub(pattern1, pattern2)
Replaces all occurrences of the first pattern by the second pattern. Replaces all occurrences of the first pattern by the second pattern.
See :api:`theano.gof.opt.PatternSub`. See :class:`PatternSub`.
.. code-block:: python .. code-block:: python
...@@ -342,7 +342,7 @@ or ``PatternSub``, it is highly recommended to use them. ...@@ -342,7 +342,7 @@ or ``PatternSub``, it is highly recommended to use them.
WRITEME: more about using PatternSub (syntax for the patterns, how to WRITEME: more about using PatternSub (syntax for the patterns, how to
use constraints, etc. - there's some decent doc at use constraints, etc. - there's some decent doc at
:api:`theano.gof.opt.PatternSub` for those interested) :class:`PatternSub` for those interested)
...@@ -376,8 +376,8 @@ Definition of optdb ...@@ -376,8 +376,8 @@ Definition of optdb
------------------- -------------------
optdb is an object which is an instance of optdb is an object which is an instance of
:api:`theano.gof.SequenceDB <theano.gof.optdb.SequenceDB>`, :class:`SequenceDB <optdb.SequenceDB>`,
itself a subclass of :api:`theano.gof.DB <theano.gof.optdb.DB>`. itself a subclass of :class:`DB <optdb.DB>`.
There exist (for now) two types of DB, SequenceDB and EquilibriumDB. There exist (for now) two types of DB, SequenceDB and EquilibriumDB.
When given an appropriate Query, DB objects build an Optimizer matching When given an appropriate Query, DB objects build an Optimizer matching
the query. the query.
...@@ -399,7 +399,7 @@ well and the LocalOptimizers they return will be put in their places ...@@ -399,7 +399,7 @@ well and the LocalOptimizers they return will be put in their places
(note that as of yet no DB can produce LocalOptimizer objects, so this (note that as of yet no DB can produce LocalOptimizer objects, so this
is a moot point). is a moot point).
Theano contains one principal DB object, :api:`theano.gof.optdb`, which Theano contains one principal DB object, :ref:`libdoc.gof.optdb`, which
contains all of Theano's optimizers with proper tags. It is contains all of Theano's optimizers with proper tags. It is
recommended to insert new Optimizers in it. As mentioned previously, recommended to insert new Optimizers in it. As mentioned previously,
optdb is a SequenceDB, so, at the top level, Theano applies a sequence optdb is a SequenceDB, so, at the top level, Theano applies a sequence
...@@ -411,33 +411,35 @@ Query ...@@ -411,33 +411,35 @@ Query
A Query is built by the following call: A Query is built by the following call:
:: .. code-block:: python
theano.gof.Query(include, require = None, exclude = None, subquery = None) theano.gof.Query(include, require = None, exclude = None, subquery = None)
.. attribute:: include .. class:: Query
.. attribute:: include
A set of tags (a tag being a string) such that every A set of tags (a tag being a string) such that every
optimization obtained through this Query must have **one** of the tags optimization obtained through this Query must have **one** of the tags
listed. This field is required and basically acts as a starting point listed. This field is required and basically acts as a starting point
for the search. for the search.
.. attribute:: require .. attribute:: require
A set of tags such that every optimization obtained A set of tags such that every optimization obtained
through this Query must have **all** of these tags. through this Query must have **all** of these tags.
.. attribute:: exclude .. attribute:: exclude
A set of tags such that every optimization obtained A set of tags such that every optimization obtained
through this Query must have **none** of these tags. through this Query must have **none** of these tags.
.. attribute:: subquery .. attribute:: subquery
optdb can contain sub-databases; subquery is a optdb can contain sub-databases; subquery is a
dictionary mapping the name of a sub-database to a special Query. dictionary mapping the name of a sub-database to a special Query.
If no subquery is given for a sub-database, the original Query will be If no subquery is given for a sub-database, the original Query will be
used again. used again.
Furthermore, a Query object includes three methods, ``including``, Furthermore, a Query object includes three methods, ``including``,
``requiring`` and ``excluding`` which each produce a new Query object ``requiring`` and ``excluding`` which each produce a new Query object
......
...@@ -22,69 +22,71 @@ i.e. the same default argument names and values. If you wish to add ...@@ -22,69 +22,71 @@ i.e. the same default argument names and values. If you wish to add
extra arguments to any of these methods, these extra arguments must have extra arguments to any of these methods, these extra arguments must have
default values. default values.
.. function:: filter(value, strict=False) .. class:: PureType
This casts a value to match the Type and returns the .. method:: filter(value, strict=False)
casted value. If ``value`` is incompatible with the Type,
the method must raise an exception. If ``strict`` is True, ``filter`` must return a
reference to ``value`` (i.e. casting prohibited)
We need to define ``filter`` with two arguments. The second argument This casts a value to match the Type and returns the
must be called ``strict`` (Theano often calls it by keyword) and must casted value. If ``value`` is incompatible with the Type,
have a default value of ``False``. the method must raise an exception. If ``strict`` is True, ``filter`` must return a
reference to ``value`` (i.e. casting prohibited)
.. function:: is_valid_value(value) We need to define ``filter`` with two arguments. The second argument
must be called ``strict`` (Theano often calls it by keyword) and must
have a default value of ``False``.
Returns True iff the value is compatible with the Type. If .. method:: is_valid_value(value)
``filter(value, strict = True)`` does not raise an exception, the
value is compatible with the Type.
*Default:* True iff ``filter(value, strict = True)`` does not raise Returns True iff the value is compatible with the Type. If
an exception. ``filter(value, strict = True)`` does not raise an exception, the
value is compatible with the Type.
.. function:: values_eq(a, b) *Default:* True iff ``filter(value, strict = True)`` does not raise
an exception.
Returns True iff ``a`` and ``b`` are equal. .. method:: values_eq(a, b)
*Default:* ``a == b`` Returns True iff ``a`` and ``b`` are equal.
.. function:: values_eq_approx(a, b) *Default:* ``a == b``
Returns True iff ``a`` and ``b`` are approximately equal, for a .. method:: values_eq_approx(a, b)
definition of "approximately" which varies from Type to Type.
*Default:* ``values_eq(a, b)`` Returns True iff ``a`` and ``b`` are approximately equal, for a
definition of "approximately" which varies from Type to Type.
.. function:: make_variable(name=None) *Default:* ``values_eq(a, b)``
Makes a :term:`Variable` of this Type with the specified name, if .. method:: make_variable(name=None)
``name`` is not ``None``. If ``name`` is ``None``, then the Variable does
not have a name. The Variable will have its ``type`` field set to
the Type object.
*Default:* there is a generic definition of this in Type. The Makes a :term:`Variable` of this Type with the specified name, if
Variable's ``type`` will be the object that defines this method (in ``name`` is not ``None``. If ``name`` is ``None``, then the Variable does
other words, ``self``). not have a name. The Variable will have its ``type`` field set to
the Type object.
.. function:: __call__(name=None) *Default:* there is a generic definition of this in Type. The
Variable's ``type`` will be the object that defines this method (in
other words, ``self``).
Syntactic shortcut to ``make_variable``. .. method:: __call__(name=None)
*Default:* ``make_variable`` Syntactic shortcut to ``make_variable``.
.. function:: __eq__(other) *Default:* ``make_variable``
Used to compare Type instances themselves .. method:: __eq__(other)
*Default:* ``object.__eq__`` Used to compare Type instances themselves
.. function:: __hash__() *Default:* ``object.__eq__``
Types should not be mutable, so it should be OK to define a hash .. method:: __hash__()
function. Typically this function should hash all of the terms
involved in ``__eq__``.
*Default:* ``id(self)`` Types should not be mutable, so it should be OK to define a hash
function. Typically this function should hash all of the terms
involved in ``__eq__``.
*Default:* ``id(self)``
For each method, the *default* is what ``Type`` defines For each method, the *default* is what ``Type`` defines
for you. So, if you create an instance of ``Type`` or an for you. So, if you create an instance of ``Type`` or an
......
...@@ -13,37 +13,12 @@ Glossary of terminology ...@@ -13,37 +13,12 @@ Glossary of terminology
Broadcasting Broadcasting
Broadcasting is a mechanism which allows tensors with Broadcasting is a mechanism which allows tensors with
different numbers of dimensions to be added or multiplied different numbers of dimensions to be used in element-by-element
together by (virtually) replicating the smaller tensor along (elementwise) computations. It works by
the dimensions that it is lacking. (virtually) replicating the smaller tensor along
the dimensions that it is lacking.
In a nutshell, broadcasting is the mechanism by which a scalar
may be added to a matrix, a vector to a matrix or a scalar to For more detail, see :ref:`libdoc_tensor_broadcastable`, and also
a vector.
.. figure:: bcast.png
Broadcasting a row matrix. T and F respectively stand for
True and False and indicate along which dimensions we allow
broadcasting.
If the second argument were a vector, its shape would be
``(2,)`` and its broadcastable pattern ``(F,)``. They would
be automatically expanded to the **left** to match the
dimensions of the matrix (adding ``1`` to the shape and ``T``
to the pattern), resulting in ``(1, 2)`` and ``(T, F)``.
It would then behave just like the example above.
Unlike numpy which does broadcasting dynamically, Theano needs
to know, for any operation which supports broadcasting, which
dimensions will need to be broadcasted. When applicable, this
information is given in the :term:`Type` of a :term:`Variable`.
See also:
* :ref:`How broadcasting is used in Theano's tensor types <tensortypes>`
* `SciPy documentation about numpy's broadcasting <http://www.scipy.org/EricsBroadcastingDoc>`_ * `SciPy documentation about numpy's broadcasting <http://www.scipy.org/EricsBroadcastingDoc>`_
* `OnLamp article about numpy's broadcasting <http://www.onlamp.com/pub/a/python/2000/09/27/numerically.html>`_ * `OnLamp article about numpy's broadcasting <http://www.onlamp.com/pub/a/python/2000/09/27/numerically.html>`_
...@@ -79,6 +54,9 @@ Glossary of terminology ...@@ -79,6 +54,9 @@ Glossary of terminology
others. These operations are all instances of :api:`Elemwise others. These operations are all instances of :api:`Elemwise
<theano.tensor.elemwise.Elemwise>`. <theano.tensor.elemwise.Elemwise>`.
Expression
See :term:`Apply`
Expression Graph Expression Graph
A directed, acyclic set of connected :term:`Variable` and A directed, acyclic set of connected :term:`Variable` and
:term:`Apply` nodes that express symbolic functional relationship :term:`Apply` nodes that express symbolic functional relationship
...@@ -89,7 +67,6 @@ Glossary of terminology ...@@ -89,7 +67,6 @@ Glossary of terminology
:term:`Type`, or read more about :ref:`tutorial_graphstructures`. :term:`Type`, or read more about :ref:`tutorial_graphstructures`.
Destructive Destructive
An :term:`Op` is destructive (of particular input[s]) if its An :term:`Op` is destructive (of particular input[s]) if its
computation requires that one or more inputs be overwritten or computation requires that one or more inputs be overwritten or
otherwise invalidated. For example, :term:`inplace` Ops are otherwise invalidated. For example, :term:`inplace` Ops are
...@@ -110,13 +87,24 @@ Glossary of terminology ...@@ -110,13 +87,24 @@ Glossary of terminology
Inplace computations are computations that destroy their inputs as a Inplace computations are computations that destroy their inputs as a
side-effect. For example, if you iterate over a matrix and double side-effect. For example, if you iterate over a matrix and double
every element, this is an inplace operation because when you are done, every element, this is an inplace operation because when you are done,
the original input has been overwritten. the original input has been overwritten. Ops representing inplace
computations are :term:`destructive`, and by default these can only be
inserted by optimizations, not user code.
Linker
Part of a function :term:`Mode` -- an object responsible for 'running'
the compiled function. Among other things, the linker determines whether computations are carried out with C or Python code.
Merge Merge
A simple optimization in which redundant :term:`Apply` nodes are A simple optimization in which redundant :term:`Apply` nodes are
combined. For example, in ``function([x,y], [(x+y)*2, (x+y)*3])`` the merge combined. For example, in ``function([x,y], [(x+y)*2, (x+y)*3])`` the merge
optimization will ensure that ``x`` and ``y`` are only added once. optimization will ensure that ``x`` and ``y`` are only added once.
Mode
An object providing an :term:`optimizer` and a :term:`linker` that is
passed to :term:`theano.funcion`. It parametrizes how an expression
graph is converted to a callable object.
Op Op
The ``.op`` of an :term:`Apply`, together with its symbolic inputs The ``.op`` of an :term:`Apply`, together with its symbolic inputs
fully determines what kind of computation will be carried out for that fully determines what kind of computation will be carried out for that
...@@ -128,13 +116,18 @@ Glossary of terminology ...@@ -128,13 +116,18 @@ Glossary of terminology
See also :term:`Variable`, :term:`Type`, and :term:`Apply`, See also :term:`Variable`, :term:`Type`, and :term:`Apply`,
or read more about :ref:`tutorial_graphstructures`. or read more about :ref:`tutorial_graphstructures`.
Expression Optimizer
See :term:`Apply` An instance of :class:`Optimizer`, which has the capacity to provide
:term:`optimization`s.
Optimization
A :term:`graph` transformation applied by an :term:`optimizer` during
the compilation of a :term:`graph` by :term:`theano.function`.
Storage Storage
The memory that is used to store the value of a Variable. In most The memory that is used to store the value of a Variable. In most
cases storage is internal to a compiled function, but in some cases cases storage is internal to a compiled function, but in some cases
(such as :term:`constant` and :term:`<shared variable>` the storage is not internal. (such as :term:`constant` and :term:`shared variable <shared variable>` the storage is not internal.
Shared Variable Shared Variable
A :term:`Variable` whose value may be shared between multiple functions. See :func:`shared` and :func:`theano.function <function.function>`. A :term:`Variable` whose value may be shared between multiple functions. See :func:`shared` and :func:`theano.function <function.function>`.
......
...@@ -168,32 +168,27 @@ bytes, we would do: ...@@ -168,32 +168,27 @@ bytes, we would do:
Shared Variable Shared Variable
--------------- ---------------
Yet another way of creating a special type of Theano variable is by using Another way of creating a TensorVariable (a TensorSharedVariable to be
:func:`shared` as in the example below: precise) is by calling :func:`shared()`
.. code-block:: python .. code-block:: python
x = shared(value, name) x = shared(numpy.random.randn(3,4))
Shared takes two parameters, `value` and `name` and creates a Theano This will return a :term:`shared variable <shared variable>` whose ``.value`` is
variable with the name `name` and initial value `value`. The type of this a numpy ndarray. The number of dimensions and dtype of the Variable are
variable is obtained from the type of the value `value`, so if value is a inferred from the ndarray argument.
numpy float matrix the shared variable will be of type `fmatrix`.
Note that a shared variable is not like other Theano variables. For more For additional information, see the :func:`shared` documentation.
details of how to use shared variables look :ref:`here <functionstateexample>` (or for more details
:ref:`here <sharedvars>`). TODO : make the last link to a detailed
description of shared variables.
Autocasting Autocasting
----------- -----------
Theano does autocasting of numpy ndarray or python floats/ints into Theano does autocasting of python floats/ints into Theano constants.
Theano constants.
TODO: What does (or compatible) mean? Talk about casting rules, refer . .. TODO: What does (or compatible) mean? Talk about casting rules, refer .
TODO: link to floatX (?) .. TODO: link to floatX (?)
.. function:: as_tensor_variable(x, ...) .. function:: as_tensor_variable(x, ...)
...@@ -438,8 +433,6 @@ information is given in the :ref:`type` of a *Variable*. ...@@ -438,8 +433,6 @@ information is given in the :ref:`type` of a *Variable*.
See also: See also:
* :ref:`How broadcasting is used in Theano's tensor types <tensortypes>`
* `SciPy documentation about numpy's broadcasting <http://www.scipy.org/EricsBroadcastingDoc>`_ * `SciPy documentation about numpy's broadcasting <http://www.scipy.org/EricsBroadcastingDoc>`_
* `OnLamp article about numpy's broadcasting <http://www.onlamp.com/pub/a/python/2000/09/27/numerically.html>`_ * `OnLamp article about numpy's broadcasting <http://www.onlamp.com/pub/a/python/2000/09/27/numerically.html>`_
......
...@@ -130,19 +130,14 @@ This is actually so simple the debugging could be done easily, but it's for ...@@ -130,19 +130,14 @@ This is actually so simple the debugging could be done easily, but it's for
illustrative purposes. As the matrices can't be element-wise multiplied illustrative purposes. As the matrices can't be element-wise multiplied
(unsuitable shapes), we get the following exception: (unsuitable shapes), we get the following exception:
:: .. code-block:: text
File "ex.py", line 14, in <module> File "ex.py", line 14, in <module>
f(mat1, mat2) f(mat1, mat2)
File "/u/username/Theano/theano/compile/function_module.py", line 451, in File "/u/username/Theano/theano/compile/function_module.py", line 451, in __call__
__call__ File "/u/username/Theano/theano/gof/link.py", line 271, in streamline_default_f
File "/u/username/Theano/theano/gof/link.py", line 271, in File "/u/username/Theano/theano/gof/link.py", line 267, in streamline_default_f
streamline_default_f File "/u/username/Theano/theano/gof/cc.py", line 1049, in execute ValueError: ('Input dimension mis-match. (input[0].shape[0] = 3, input[1].shape[0] = 5)', Elemwise{mul,no_inplace}(a, b), Elemwise{mul,no_inplace}(a, b))
File "/u/username/Theano/theano/gof/link.py", line 267, in
streamline_default_f
File "/u/username/Theano/theano/gof/cc.py", line 1049, in execute
ValueError: ('Input dimension mis-match. (input[0].shape[0] = 3,
input[1].shape[0] = 5)',
Elemwise{mul,no_inplace}(a, b), Elemwise{mul,no_inplace}(a, b))
The call stack contains a few useful informations to trace back the source The call stack contains a few useful informations to trace back the source
of the error. There's the script where the compiled function was called -- of the error. There's the script where the compiled function was called --
...@@ -160,21 +155,20 @@ dimensions of the matrices involved, but for the sake of example say we'd ...@@ -160,21 +155,20 @@ dimensions of the matrices involved, but for the sake of example say we'd
need the other dimensions to pinpoint the error. First, we re-launch with need the other dimensions to pinpoint the error. First, we re-launch with
the debugger module and run the program with "c": the debugger module and run the program with "c":
:: .. code-block:: text
python -m pdb ex.py
> /u/username/experiments/doctmp1/ex.py(1)<module>() python -m pdb ex.py
-> import theano > /u/username/experiments/doctmp1/ex.py(1)<module>()
(Pdb) c -> import theano
(Pdb) c
Then we get back the above error printout, but the interpreter breaks in Then we get back the above error printout, but the interpreter breaks in
that state. Useful commands here are that state. Useful commands here are
* "up" and "down" (to move up and down the call stack),</li> * "up" and "down" (to move up and down the call stack),
* "l" (to print code around the line in the current stack position),</li> * "l" (to print code around the line in the current stack position),
* "p variable_name" (to print the string representation of * "p variable_name" (to print the string representation of 'variable_name'),
'variable_name'),</li> * "p dir(object_name)", using the Python dir() function to print the list of an object's members
* "p dir(object_name)", using the Python dir() function to print the list of
an object's members
Here, for example, I do "up", and a simple "l" shows me there's a local Here, for example, I do "up", and a simple "l" shows me there's a local
variable "node". This is the "node" from the computation graph, so by variable "node". This is the "node" from the computation graph, so by
......
.. _symbolic_graph: .. _tutorial_graphstructures:
================ ================
Graph Structures Graph Structures
...@@ -77,7 +77,7 @@ Optimizations ...@@ -77,7 +77,7 @@ Optimizations
============= =============
When compiling a Theano function, what you give to the When compiling a Theano function, what you give to the
:ref:`theano.function <libdoc_compile_function>` is actually a graph :func:`theano.function <function.function>` is actually a graph
(starting from the outputs variables you can traverse the graph up to (starting from the outputs variables you can traverse the graph up to
the input variables). While this graph structure shows how to compute the input variables). While this graph structure shows how to compute
the output from the input, it also offers the posibility to improve the the output from the input, it also offers the posibility to improve the
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论