提交 3e53378c authored 作者: lamblin's avatar lamblin

Merge pull request #676 from nouiz/doc

Doc
......@@ -482,3 +482,14 @@ a specific branch (REMOTE_BRANCH_NAME) from the remote repository
.. code-block:: bash
git checkout -b LOCAL_BRANCH_NAME REPO_NAME/REMOTE_BRANCH_NAME
Other tools that can help you
=============================
* `cProfile <http://docs.python.org/library/profile.html>`_: time profiler that work at function level.
* `Yep <http://pypi.python.org/pypi/yep>`_: A module for profiling compiled extensions.
* `autopep8 <http://pypi.python.org/pypi/autopep8/>`_: A tool that automatically formats Python code to conform to the PEP 8 style guide.
* `line_profiler <http://pypi.python.org/pypi/line_profiler/>`_: Line-by-line profiler.
* `memory_profiler <http://fseoane.net/blog/2012/line-by-line-report-of-memory-usage/>`_: memory profiler
* `runsnake <http://www.vrplumber.com/programming/runsnakerun/>`_: Gui for cProfile(time profiler) and Meliae(memory profiler)
......@@ -129,7 +129,7 @@ to your machine, you can install to an alternate prefix using
.. code-block:: bash
pip install Theano --install-option='--prefix=YOURPREFIX'
pip install Theano --install-option='--prefix=~/.local
e.g. using ``--install-option='--prefix=~/.local'`` on Python 2.4 would
install Theano into ``.local/lib/python2.4/site-packages`` inside your home
......@@ -138,6 +138,7 @@ listed in your ``PYTHONPATH`` environment variable; for Python 2.6 and later,
``~/.local`` is
automatically searched and does *not* need to be explicitly included in
``PYTHONPATH``, see :ref:`config_pythonpath` for instructions).
You can change ``~/.local``, but you need to change your ``PYTHONPATH`` as said above.
Alternatively you can use virtualenv_ to create an isolated ``site-packages``
directory; see the `virtualenv documentation`_ for details.
......@@ -202,19 +203,19 @@ Bleeding-edge install instructions
If you are a developer of Theano, then check out the :ref:`dev_start_guide`.
If you want the bleeding-edge without developing the code you can use pip for
this with the command line below. Note that it will also try to download and
upgrade Theano's dependencies (like numpy and scipy). If you do not wish to do
so, add the ``--no-deps`` switch to it.
this with the command line below. Note that it will also try to install Theano's dependencies
(like numpy and scipy), but not upgrade them. If you wish to upgrade them,
remove the ``--no-deps`` switch to it, but go see a previous warning before doing this.
.. code-block:: bash
pip install --upgrade git+git://github.com/Theano/Theano.git
pip install --upgrade --no-deps git+git://github.com/Theano/Theano.git
or (if you want to install to a custom directory):
or (if you want to install it for the current user only):
.. code-block:: bash
pip install --upgrade git+git://github.com/Theano/Theano.git --install-option='--prefix=YOURPREFIX'
pip install --upgrade --no-deps git+git://github.com/Theano/Theano.git --install-option='--prefix=~/.local'
The following are general instructions that will set you up with the
bleeding-edge version of Theano and allow you to hack it. First,
......@@ -243,7 +244,7 @@ can specify an alternative installation prefix using
.. code-block:: bash
python setup.py develop --prefix=YOURPREFIX
python setup.py develop --prefix=~/.local
A common choice is ``~/.local`` which is automatically searched for Python >=
2.6; for earlier Python versions and other installation prefixes, the prefix
......@@ -736,7 +737,7 @@ MinGW, but this has not been tested yet.
in a Windows command prompt vs. a MSYS shell. One way to do this without
setting a global Windows ``HOME`` environment variable (which may affect
other programs) is to edit your ``msys.bat`` file (found e.g. under
``C:\MinGW\msys\1.0`` or ``C:\mingw64\msys) and add the following line at
``C:\MinGW\msys\1.0`` or ``C:\mingw64\msys``) and add the following line at
the beginning (note that you may need to use e.g. Wordpad to edit this file,
since Notepad gets confused by Unix-style line breaks):
......
......@@ -5,95 +5,86 @@ Documentation Documentation AKA Meta-Documentation
==================================================
How to link from Sphinx to API documentation
--------------------------------------------
How to build documentation
--------------------------
Link from Sphinx to epydoc this way::
Let's say you are writing documentation, and want to see the `sphinx
<http://sphinx.pocoo.org/>`__ output before you push it.
The documentation will be generated in the ``html`` directory.
:api:`linkname <path-to-symbol>`
.. code-block:: bash
For example::
cd Theano/
python ./doc/scripts/docgen.py
:api:`function <theano.compile.function>`
If you don't want to generate the pdf, do the following:
You can also use ``:api:\`path-to-symbol\``` directly.
.. code-block:: bash
If you are lazy, you can try::
cd Theano/
python ./doc/scripts/docgen.py --nopdf
:api:`<function>`
However, if the link target is ambiguous, Sphinx will generate errors.
For more details:
NB the ``:api:`` reference is special magic by Olivier, in
./doc/scripts/docgen.py.
.. code-block:: bash
How to add TODO comments in Sphinx documentation
-------------------------------------------------
$ python doc/scripts/docgen.py --help
Usage: doc/scripts/docgen.py [OPTIONS]
-o <dir>: output the html files in the specified dir
--rst: only compile the doc (requires sphinx)
--nopdf: do not produce a PDF file from the doc, only HTML
--help: this help
To include a TODO comment in Sphinx documentation, use an indented block as
follows::
Use ReST for documentation
--------------------------
.. TODO: This is a comment.
.. You have to put .. at the beginning of every line :(
.. These lines should all be indented.
* :ref:`ReST <http://docutils.sourceforge.net/rst.html>` is standardized.
epydoc is not. trac wiki-markup is not.
This means that ReST can be cut-and-pasted between epydoc, code, other
docs, and TRAC. This is a huge win!
* ReST is extensible: we can write our own roles and directives to automatically link to WIKI, for example.
* ReST has figure and table directives, and can be converted (using a standard tool) to latex documents.
* No text documentation has good support for math rendering, but ReST is closest: it has three renderer-specific solutions (render latex, use latex to build images for html, use itex2mml to generate MathML)
It will not appear in the output generated.
.. TODO: Check it out, this won't appear.
.. Nor will this.
How to link to class/function documentations
--------------------------------------------
How to write API documentation
---------------------------------------
Link to the generated doc of a function this way::
API documentation is processed by `epydoc
<http://epydoc.sourceforge.net/>`__ and should be written in
`reStructuredText <http://docutils.sourceforge.net/rst.html>`__. See `here
<http://epydoc.sourceforge.net/manual-othermarkup.html#restructuredtext>`__
for details about how to use reST with epydoc documentation.
:func:`perform`
Use ReST for API and Sphinx documentation
-----------------------------------------
For example::
* ReST is standardized. epydoc is not. trac wiki-markup is not.
This means that ReST can be cut-and-pasted between epydoc, code, other
docs, and TRAC. This is a huge win!
* ReST is extensible: we can write our own roles and directives to automatically link to WIKI, for example.
* ReST has figure and table directives, and can be converted (using a standard tool) to latex documents.
* No text documentation has good support for math rendering, but ReST is closest: it has three renderer-specific solutions (render latex, use latex to build images for html, use itex2mml to generate MathML)
of the :func:`perform` function.
How to build documentation
---------------------------------------
Link to the generated doc of a class this way::
Let's say you are writing documentation, and want to see
the `epydoc <http://epydoc.sourceforge.net/>`__ and `sphinx
<http://sphinx.pocoo.org/>`__ output before you push it.
:class:`RopLop_checker`
The following technique uses Olivier's code to insert :api: links:
For example::
.. code-block:: bash
The class :class:`RopLop_checker`, give the functions
cd Theano/
python ./doc/scripts/docgen.py
If you don't want to rerun epydoc, do the following:
However, if the link target is ambiguous, Sphinx will generate warning or errors.
.. code-block:: bash
cd Theano/
python ./doc/scripts/docgen.py --rst
How to add TODO comments in Sphinx documentation
-------------------------------------------------
To include a TODO comment in Sphinx documentation, use an indented block as
follows::
For more details:
.. TODO: This is a comment.
.. You have to put .. at the beginning of every line :(
.. These lines should all be indented.
.. code-block:: bash
It will not appear in the output generated.
$ python doc/scripts/docgen.py --help
Usage: doc/scripts/docgen.py [OPTIONS]
-o <dir>: output the html files in the specified dir
--rst: only compile the doc (requires sphinx)
--nopdf: do not produce a PDF file from the doc, only HTML
--epydoc: only compile the api documentation (requires epydoc)
--help: this help
.. TODO: Check it out, this won't appear.
.. Nor will this.
How documentation is built on deeplearning.net
......@@ -107,7 +98,7 @@ newly generated ones.
Note that the server will most definitely use a different version of sphinx
than yours so formatting could be slightly off, or even wrong. If you're
getting unxpected results and/or the auto-build of the documentation seems
broken, please contact theano-dev@ (or Dumitru, or Fred directly).
broken, please contact theano-dev@.
In the future, we might go back to the system of auto-refresh on push (though
that might increase the load of the server quite significantly).
......@@ -147,8 +138,5 @@ TO WRITE
*There is other stuff to document here, e.g.:*
* where the documentation is getting built, and epy.
* How epydoc and sphinx are integrated
* Explain the special magic in ./doc/scripts/docgen.py
* We also want examples of good documentation, to show people how to write sphinx,
* We also want examples of good documentation, to show people how to write ReST.
......@@ -121,29 +121,35 @@ Reference
:param name: an optional name for this function.
The profile mode will print the time spent in this function.
:param rebuild_strict: True (Default) is the safer and better tested setting, in which case
`givens` must substitute new variables with the same Type as the variables they replace.
False is a you-better-know-what-you-are-doing setting, that permits `givens` to replace
variables with new variables of any Type. The consequence of changing a Type is that all
results depending on that variable may have a different Type too (the graph is rebuilt from
inputs to outputs). If one of the new types does not make sense for one of the Ops in the
graph, an Exception will be raised.
:param rebuild_strict: True (Default) is the safer and better
tested setting, in which case `givens` must substitute new
variables with the same Type as the variables they replace.
False is a you-better-know-what-you-are-doing setting, that
permits `givens` to replace variables with new variables of
any Type. The consequence of changing a Type is that all
results depending on that variable may have a different Type
too (the graph is rebuilt from inputs to outputs). If one of
the new types does not make sense for one of the Ops in the
graph, an Exception will be raised.
:type allow_input_downcast: Boolean or None
:param allow_input_downcast: True means that the values passed as
inputs when calling the function can be silently downcasted to fit
the dtype of the corresponding Variable, which may lose precision.
False means that it will only be cast to a more general, or
precise, type. None (default) is almost like False, but allows
downcasting of Python float scalars to floatX.
inputs when calling the function can be silently downcasted to
fit the dtype of the corresponding Variable, which may lose
precision. False means that it will only be cast to a more
general, or precise, type. None (default) is almost like
False, but allows downcasting of Python float scalars to
floatX.
:type profile: None, True, or ProfileStats instance
:param profile: accumulate profiling information into a given ProfileStats
instance. If argument is `True` then a new ProfileStats instance will be
used. This profiling object will be available via self.profile.
:param on_unused_input: What to do if a variable in the 'inputs' list is
not used in the graph. Possible values are 'raise', 'warn', and 'ignore'.
:param profile: accumulate profiling information into a given
ProfileStats instance. If argument is `True` then a new
ProfileStats instance will be used. This profiling object
will be available via self.profile.
:param on_unused_input: What to do if a variable in the 'inputs'
list is not used in the graph. Possible values are 'raise',
'warn', and 'ignore'.
:rtype: Function instance
......
......@@ -746,7 +746,7 @@ Reductions
:Returns: bitwise and of *x* along *axis*
axis can be:
* *None* - variance computed along all axes (like numpy)
* *None* - computed along all axes (like numpy)
* an *int* - computed along this axis
* a *list of ints* - computed along these axes
......@@ -757,7 +757,7 @@ Reductions
:Returns: bitwise or of *x* along *axis*
axis can be:
* *None* - variance computed along all axes (like numpy)
* *None* - computed along all axes (like numpy)
* an *int* - computed along this axis
* a *list of ints* - computed along these axes
......
===================================================================
:mod:`tensor.extra_ops` -- Tensor Extra Ops
===================================================================
.. module:: tensor.extra_ops
:platform: Unix, Windows
:synopsis: Tensor Extra Ops
.. moduleauthor:: LISA
.. automodule:: theano.tensor.extra_ops
:members:
......@@ -22,3 +22,5 @@ They are grouped into the following sections:
raw_random
shared_randomstreams
signal/index
utils
extra_ops
===================================================================
:mod:`tensor.utils` -- Tensor Utils
===================================================================
.. module:: tensor.utils
:platform: Unix, Windows
:synopsis: Tensor Utils
.. moduleauthor:: LISA
.. automodule:: theano.tensor.utils
:members:
......@@ -93,7 +93,7 @@ if __name__ == '__main__':
# Make sure the appropriate 'theano' directory is in the PYTHONPATH
pythonpath = os.environ.get('PYTHONPATH', '')
pythonpath = os.pathsep.join([throot, pythonpath])
os.environ['PYTHONPATH'] = pythonpath
sys.path[0:0] = [throot] # We must not use os.environ.
if options['--all'] or options['--epydoc']:
mkdir("api")
......
......@@ -169,6 +169,13 @@ control over the order in which multiple Print() Ops are evaluted. For a more
precise inspection of what's being computed where, when, and how, see the
:ref:`faq_wraplinker`.
.. warning::
Using this ``Print`` Theano Op can prevent some Theano
optimization from being applied. This can also happen with
stability optimization. So if you use this Print and have nan, try
to remove them to know if this is the cause or not.
How do I print a graph (before or after compilation)?
----------------------------------------------------------
......
......@@ -18,6 +18,28 @@ Inputs and Outputs are lists of Theano variables
.. image:: ../hpcs2011_tutorial/pics/apply_node.png
:width: 500 px
.. note::
This tutorial does not cover how to make an op that returns a view or
modify the values in its inputs. So all
Ops created with the instructions here MUST return newly allocated
memory or reuse the memory provided in the parameter
output_storage of the :func:`perform` function. See :ref:`views_and_inplace`
for explanation of how to do this.
If your Op returns a view or change the value on its inputs
without doing as said in that page, Theano will run, but will
return good results for some graphs, but bad results for others.
It is recommented that you run your tests in DebugMode (Theano flag
mode=DebugMode) that checks if your Op behaves correctly in this
regard.
.. note::
See :ref:`dev_start_guide` for information about git, github, the
development workflow and how to make a quality contribution.
Op contract
-----------
......@@ -266,13 +288,27 @@ To verify the Rop method of the DoubleOp, you can use this:
def test_double_rop(self):
self.check_rop_lop(DoubleRop()(self.x), self.in_shape)
You can use `nosetests` to run it as all other test in Theano or you can run it like that in a python shell:
Running your tests
==================
You can run ``nosetests`` in the Theano folder to run all of Theano's
tests, including yours if they are somewhere in the directory
structure. You can run ``nosetests test_file.py`` to run only the
tests in that file. You can run ``nosetests
test_file.py:test_DoubleRop`` to run only the tests inside that test
class. You can run ``nosetests
test_file.py:test_DoubleRop.test_double_op`` to run only one
particular test. More `nosetests
<http://readthedocs.org/docs/nose/en/latest/>`_ documentation.
You can also add this at the end of the test file:
.. code-block:: python
t = test_DoubleRop("test_double_rop")
t.setUp()
t.test_double_rop()
if __name__ == '__main__':
t = test_DoubleRop("test_double_rop")
t.setUp()
t.test_double_rop()
Exercises 8
-----------
......@@ -291,3 +327,10 @@ Op that execute on the GPU should inherit from the
to make the distinction between both. Currently, we use this to test
if the NVIDIA driver works correctly with our sum reduction code on the
gpu.
Documentation
-------------
See :ref:`metadocumentation`, for some information on how to generate
and do documentation.
......@@ -34,6 +34,7 @@ you out.
aliasing
conditions
loop
sparse
using_gpu
gpu_data_convert
shape_info
......
.. _tutsparse:
======
Sparse
======
This is a very short tutorial on sparse matrices with Theano. There is still
some not well documented behavior like how we take care of the
gradient. There are 2 types of gradient for sparse operations. ``full
gradient`` that compute a gradient for values even if they were 0 and
the ``structured gradient`` that returns a gradient only for values
that were not 0. You need to check the code to know which gradient an
Op implements.
More documentation in the :ref:`Sparse Library Reference <libdoc_sparse>`.
A small example:
.. code-block:: python
import theano
import theano.tensor as T
import scipy.sparse as sp
import theano.sparse as S
import numpy as np
x = S.csr_matrix ('x')
#x = T.matrix ('x')
y = T.matrix ('y')
z = S.dot (x, y)
f = theano.function ([x, y], z)
#a = np.array ([[0, 1], [1, 0], [1, 0], [0, 1]], dtype=np.float32)
a = sp.coo_matrix (([1] * 4, (range (4), [0, 1, 1, 0])), dtype=np.float32)
b = np.array ([[10, 11], [12, 13]], dtype=np.float32)
print f (a, b)
......@@ -5,6 +5,11 @@ from theano.gof.cc import hash_from_code
def hash_from_ndarray(data):
"""Return a hash from an ndarray
It takes care of the data, shapes, strides and dtype.
"""
# We need to hash the shapes and strides as hash_from_code only hashes
# the data buffer. Otherwise, this will cause problem with shapes like:
# (1, 0) and (2, 0) and problem with inplace transpose.
......@@ -27,7 +32,7 @@ def hash_from_dict(d):
This request that all object have a sorted order that depend only
on the value of the object. This is true for integer/float/string
We do not verify that the objects in the dict what this properties
We do not verify that the objects in the dict have this property.
Also, we transform values that are list into tuple as list are not
hashable.
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论