提交 99647a3b authored 作者: Olivier Breuleux's avatar Olivier Breuleux

merge

...@@ -5,43 +5,6 @@ Making the double type ...@@ -5,43 +5,6 @@ Making the double type
====================== ======================
What is a Type?
===============
A :ref:`type` in Theano represents a set of constraints on potential
data objects. These constraints allow Theano to tailor C code to handle
them and to statically optimize the computation graph. For instance,
the :ref:`irow <predefinedtypes>` type in the ``theano.tensor`` package
gives the following constraints on the data the Results of type ``irow``
may contain:
#. Must be an instance of ``numpy.ndarray``: ``isinstance(x, numpy.ndarray)``
#. Must be an array of 32-bit integers: ``str(x.dtype) == 'int32'``
#. Must have a shape of 1xN: ``len(x.shape) == 2 and x.shape[0] == 1``
Knowing these restrictions, Theano may generate C code for addition, etc.
that declares the right data types and that contains the right number
of loops over the dimensions.
Note that a Theano :ref:`type` is not equivalent to a Python type or
class. Indeed, in Theano, :ref:`irow <predefinedtypes>` and :ref:`dmatrix
<predefinedtypes>` both use ``numpy.ndarray`` as the underlying type
for doing computations and storing data, yet they are different Theano
Types. Indeed, the constraints set by ``dmatrix`` are:
#. Must be an instance of ``numpy.ndarray``: ``isinstance(x, numpy.ndarray)``
#. Must be an array of 64-bit floating point numbers: ``str(x.dtype) == 'float64'``
#. Must have a shape of MxN, no restriction on M or N: ``len(x.shape) == 2``
These restrictions are different from those of ``irow`` which are listed above.
There are cases in which a Type can fully correspond to a Python type,
such as the ``double`` Type we will define here which corresponds to
Python's ``float``. But, it's good to know that this is not necessarily
the case. Unless specified otherwise, when we say "Type" we mean a
Theano Type.
Type's contract Type's contract
=============== ===============
......
...@@ -169,6 +169,10 @@ theano's version of a function definition. ...@@ -169,6 +169,10 @@ theano's version of a function definition.
An Apply instance has three important fields: An Apply instance has three important fields:
**op**
An :ref:`op` that determines the function/transformation being
applied here.
**inputs** **inputs**
A list of :ref:`Results <result>` that represent the arguments of A list of :ref:`Results <result>` that represent the arguments of
the function. the function.
...@@ -177,33 +181,8 @@ An Apply instance has three important fields: ...@@ -177,33 +181,8 @@ An Apply instance has three important fields:
A list of :ref:`Results <result>` that represent the return values A list of :ref:`Results <result>` that represent the return values
of the function. of the function.
**op** An Apply instance can be created by calling ``gof.Apply(op, inputs,
An :ref:`op` that determines the function/transformation being outputs)``.
applied here.
.. index::
single: Constant
single: graph construct; Constant
.. _constant:
--------
Constant
--------
A constant is a :ref:`Result` with one extra field, *data* (only
settable once). When used in a computation graph as the input of an
:ref:`Op` :ref:`application <Apply>`, it is assumed that said input
will *always* take the value contained in the constant's data
field. Furthermore, it is assumed that the :ref:`Op` will not under
any circumstances modify the input. This means that a constant is
eligible to participate in numerous optimizations: constant inlining
in C code, constant folding, etc.
A constant does not need to be specified in a :ref:`function`'s list
of inputs.
.. index:: .. index::
...@@ -212,6 +191,8 @@ of inputs. ...@@ -212,6 +191,8 @@ of inputs.
.. _result: .. _result:
------ ------
Result Result
------ ------
...@@ -263,6 +244,28 @@ A Result ``r`` contains four important fields: ...@@ -263,6 +244,28 @@ A Result ``r`` contains four important fields:
Result has one special subclass: :ref:`constant <constant>`. Result has one special subclass: :ref:`constant <constant>`.
.. index::
single: Constant
single: graph construct; Constant
.. _constant:
Constant
^^^^^^^^
A constant is a :ref:`Result` with one extra field, *data* (only
settable once). When used in a computation graph as the input of an
:ref:`Op` :ref:`application <Apply>`, it is assumed that said input
will *always* take the value contained in the constant's data
field. Furthermore, it is assumed that the :ref:`Op` will not under
any circumstances modify the input. This means that a constant is
eligible to participate in numerous optimizations: constant inlining
in C code, constant folding, etc.
A constant does not need to be specified in a :ref:`function`'s list
of inputs.
.. index:: .. index::
...@@ -275,7 +278,20 @@ Result has one special subclass: :ref:`constant <constant>`. ...@@ -275,7 +278,20 @@ Result has one special subclass: :ref:`constant <constant>`.
Op Op
-- --
WRITEME An :ref:`op` in Theano defines a certain computation on some types of
inputs, producing some types of outputs. It is equivalent to a
function definition in most programming languages. From a list of
input :ref:`Results <result>` and an Op, you can build an :ref:`apply`
node representing the application of the Op to the inputs.
It is important to understand the distinction between an Op (the
definition of a function) and an Apply node (the application of a
function). If you were to interpret the Python language using Theano's
structures, code going like ``def f(x): ...`` would produce an Op for
``f`` whereas code like ``a = f(x)`` or ``g(f(4), 5)`` would produce an
Apply node involving the ``f`` Op.
...@@ -289,5 +305,37 @@ WRITEME ...@@ -289,5 +305,37 @@ WRITEME
Type Type
---- ----
WRITEME A :ref:`type` in Theano represents a set of constraints on potential
data objects. These constraints allow Theano to tailor C code to handle
them and to statically optimize the computation graph. For instance,
the :ref:`irow <predefinedtypes>` type in the ``theano.tensor`` package
gives the following constraints on the data the Results of type ``irow``
may contain:
#. Must be an instance of ``numpy.ndarray``: ``isinstance(x, numpy.ndarray)``
#. Must be an array of 32-bit integers: ``str(x.dtype) == 'int32'``
#. Must have a shape of 1xN: ``len(x.shape) == 2 and x.shape[0] == 1``
Knowing these restrictions, Theano may generate C code for addition, etc.
that declares the right data types and that contains the right number
of loops over the dimensions.
Note that a Theano :ref:`type` is not equivalent to a Python type or
class. Indeed, in Theano, :ref:`irow <predefinedtypes>` and :ref:`dmatrix
<predefinedtypes>` both use ``numpy.ndarray`` as the underlying type
for doing computations and storing data, yet they are different Theano
Types. Indeed, the constraints set by ``dmatrix`` are:
#. Must be an instance of ``numpy.ndarray``: ``isinstance(x, numpy.ndarray)``
#. Must be an array of 64-bit floating point numbers: ``str(x.dtype) == 'float64'``
#. Must have a shape of MxN, no restriction on M or N: ``len(x.shape) == 2``
These restrictions are different from those of ``irow`` which are listed above.
There are cases in which a Type can fully correspond to a Python type,
such as the ``double`` Type we will define here which corresponds to
Python's ``float``. But, it's good to know that this is not necessarily
the case. Unless specified otherwise, when we say "Type" we mean a
Theano Type.
...@@ -12,7 +12,7 @@ analogue in Python: ...@@ -12,7 +12,7 @@ analogue in Python:
Theano Python Theano Python
=============== =========================================================== =============== ===========================================================
Apply function application / function call Apply function application / function call
Result function data Result function data / variable
Op operations carried out in computation / function definition Op operations carried out in computation / function definition
Type data types Type data types
Module ??? class? Module ??? class?
......
差异被折叠。
...@@ -30,6 +30,7 @@ Now we're ready for the tour: ...@@ -30,6 +30,7 @@ Now we're ready for the tour:
adding adding
examples examples
function
module module
module_vs_op module_vs_op
randomstreams randomstreams
......
.. _numpy::
===============
NumPy refresher
===============
Give summary of type(x) vs x.type vs x.dtype
...@@ -110,8 +110,20 @@ class Function(object): ...@@ -110,8 +110,20 @@ class Function(object):
outputs, performs the packing and unpacking of inputs and return values. It implements the outputs, performs the packing and unpacking of inputs and return values. It implements the
square-bracket indexing so that you can look up the value of a symbolic node. square-bracket indexing so that you can look up the value of a symbolic node.
Functions are copyable via {{{fn.copy()}}} and {{{copy.copy(fn)}}}.
When a function is copied, this instance is duplicated. Contrast with self.maker When a function is copied, this instance is duplicated. Contrast with self.maker
(instance of `FunctionMaker`) that is shared between copies. (instance of `FunctionMaker`) that is shared between copies.
The meaning of copying a function is that the containers and their current values will all be duplicated.
This requires that mutable inputs be copied, whereas immutable inputs may be shared between copies.
A Function instance is hashable, on the basis of its memory address (its id).
A Function instance is only equal to itself.
A Function instance may be serialized using the `pickle` or `cPickle` modules.
This will save all default inputs, the graph, and *** to the pickle file (WRITEME).
""" """
......
"""Define `SymbolicInput`, `SymbolicOutput`, `In`, `Out` """
__docformat__ = 'restructuredtext en'
class SymbolicInput(object): class SymbolicInput(object):
""" """
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论