提交 f331d521 authored 作者: Frédéric Bastien's avatar Frédéric Bastien

Merge pull request #3631 from hantek/doctest

add doc test in yaml
...@@ -29,8 +29,14 @@ install: ...@@ -29,8 +29,14 @@ install:
- source activate pyenv - source activate pyenv
- if [[ $TRAVIS_PYTHON_VERSION == '2.6' ]]; then pip install pydot; fi - if [[ $TRAVIS_PYTHON_VERSION == '2.6' ]]; then pip install pydot; fi
- pip install . --no-deps - pip install . --no-deps
- pip install -U Sphinx
# command to run tests # command to run tests
env:
- PART="theano/sandbox theano/sparse theano/scalar theano/tensor/nnet theano/scan_module"
- PART="theano/tensor/tests/test_basic.py theano/tensor/signal theano/compile theano/gof theano/misc theano/tests theano/compat"
- PART="-e test_basic.py theano/tensor/tests"
matrix: matrix:
fast_finish: true fast_finish: true
include: include:
...@@ -38,11 +44,8 @@ matrix: ...@@ -38,11 +44,8 @@ matrix:
env: PART="." THEANO_FLAGS="mode=FAST_COMPILE" env: PART="." THEANO_FLAGS="mode=FAST_COMPILE"
- python: "2.6" - python: "2.6"
env: PART="." THEANO_FLAGS="mode=FAST_COMPILE,floatX=float32" env: PART="." THEANO_FLAGS="mode=FAST_COMPILE,floatX=float32"
- python: 2.6
env: env: PART="." DOC=1
- PART="sandbox sparse scalar tensor/nnet scan_module"
- PART="tensor/tests/test_basic.py tensor/signal compile gof misc tests compat"
- PART="-e test_basic.py tensor/tests"
script: script:
- export THEANO_FLAGS=$THEANO_FLAGS,warn.ignore_bug_before=all,on_opt_error=raise,on_shape_error=raise,gcc.cxxflags=-pipe - export THEANO_FLAGS=$THEANO_FLAGS,warn.ignore_bug_before=all,on_opt_error=raise,on_shape_error=raise,gcc.cxxflags=-pipe
...@@ -56,7 +59,9 @@ script: ...@@ -56,7 +59,9 @@ script:
# Move to the path of the installed version # Move to the path of the installed version
- cd $(python -c 'import theano; import os; print(os.path.split(theano.__file__)[0])') - cd $(python -c 'import theano; import os; print(os.path.split(theano.__file__)[0])')
- echo "$PART" - echo "$PART"
- theano-nose -v $PART - cd -; cd Theano
- if [[ $DOC == "1" ]]; then python doc/scripts/docgen.py --nopdf; else theano-nose -v $PART; fi
- if [[ $DOC == "1" ]]; then python doc/scripts/docgen.py --test; fi
# - theano-cache list # - theano-cache list
#after_script: #after_script:
......
...@@ -2,7 +2,6 @@ To install the package, see this page: ...@@ -2,7 +2,6 @@ To install the package, see this page:
http://deeplearning.net/software/theano/install.html http://deeplearning.net/software/theano/install.html
For the documentation, see the project website: For the documentation, see the project website:
http://deeplearning.net/software/theano/ http://deeplearning.net/software/theano/
...@@ -14,7 +13,7 @@ Related Projects: ...@@ -14,7 +13,7 @@ Related Projects:
We recommend you look at the documentation on the website, since it We recommend you look at the documentation on the website, since it
will be more current than the documentation included with the package. will be more current than the documentation included with the package.
If you really wish to build the documentation yourself, you will need If you really wish to build the documentation yourself, you will need
epydoc and sphinx. Issue the following command: sphinx. Issue the following command:
python ./doc/scripts/docgen.py python ./doc/scripts/docgen.py
......
# TODO:
# Get all graphs to work!
[epydoc] # Epydoc section marker (required by ConfigParser)
# The list of objects to document. Objects can be named using
# dotted names, module filenames, or package directory names.
# Alases for this option include "objects" and "values".
modules: theano scipy.sparse
# The type of output that should be generated. Should be one
# of: html, text, latex, dvi, ps, pdf.
output: html
# An integer indicating how verbose epydoc should be. The default
# value is 0; negative values will supress warnings and errors;
# positive values will give more verbose output.
verbosity: 1
# A boolean value indicating that Epydoc should show a tracaback
# in case of unexpected error. By default don't show tracebacks
debug: 1
# If True, don't try to use colors or cursor control when doing
# textual output. The default False assumes a rich text prompt
simple-term: 0
### Generation options
# The default markup language for docstrings, for modules that do
# not define __docformat__. Defaults to epytext.
docformat: epytext
# Whether or not parsing should be used to examine objects.
parse: yes
# Whether or not introspection should be used to examine objects.
introspect: yes
# Don't examine in any way the modules whose dotted name match this
# regular expression pattern.
#exclude
# Don't perform introspection on the modules whose dotted name match this
# regular expression pattern.
#exclude-introspect
# Don't perform parsing on the modules whose dotted name match this
# regular expression pattern.
#exclude-parse
# The format for showing inheritance objects.
# It should be one of: 'grouped', 'listed', 'included'.
inheritance: grouped
# Whether or not to inclue private variables. (Even if included,
# private variables will be hidden by default.)
private: yes
# Whether or not to list each module's imports.
imports: yes
# Whether or not to include syntax highlighted source code in
# the output (HTML only).
sourcecode: yes
# Whether or not to includea a page with Epydoc log, containing
# effective option at the time of generation and the reported logs.
include-log: yes
### Output options
# The documented project's name.
name: Theano
# The CSS stylesheet for HTML output. Can be the name of a builtin
# stylesheet, or the name of a file.
css: white
# The documented project's URL.
url: http://lgcm.iro.umontreal.ca/theano/
# HTML code for the project link in the navigation bar. If left
# unspecified, the project link will be generated based on the
# project's name and URL.
#link: <a href="somewhere">My Cool Project</a>
# The "top" page for the documentation. Can be a URL, the name
# of a module or class, or one of the special names "trees.html",
# "indices.html", or "help.html"
#top: os.path
# An alternative help file. The named file should contain the
# body of an HTML file; navigation bars will be added to it.
#help: my_helpfile.html
# Whether or not to include a frames-based table of contents.
#frames: yes
frames: no
# Whether each class should be listed in its own section when
# generating LaTeX or PDF output.
separate-classes: no
### API linking options
# Define a new API document. A new interpreted text role
# will be created
#external-api: epydoc
# Use the records in this file to resolve objects in the API named NAME.
#external-api-file: epydoc:api-objects.txt
# Use this URL prefix to configure the string returned for external API.
#external-api-root: epydoc:http://epydoc.sourceforge.net/api
# external-api: wiki doc
# external-api-root: wiki:http://lgcm.iro.umontreal.ca/theano/wiki/ doc:http://lgcm.iro.umontreal.ca/auto_theano/doc/
# external-api-file: wiki:wiki.idx doc:doc/doc.idx
### Graph options
# The list of graph types that should be automatically included
# in the output. Graphs are generated using the Graphviz "dot"
# executable. Graph types include: "classtree", "callgraph",
# "umlclass". Use "all" to include all graph types
graph: all
# The path to the Graphviz "dot" executable, used to generate
# graphs.
dotpath: /usr/bin/dot
# The name of one or more pstat files (generated by the profile
# or hotshot module). These are used to generate call graphs.
#pstat: autotest.pstat
# Specify the font used to generate Graphviz graphs.
# (e.g., helvetica or times).
graph-font: Helvetica
# Specify the font size used to generate Graphviz graphs.
graph-font-size: 10
### Return value options
# The condition upon which Epydoc should exit with a non-zero
# exit status. Possible values are error, warning, docstring_warning
#fail-on: error
...@@ -21,12 +21,11 @@ To get up to speed, you'll need to ...@@ -21,12 +21,11 @@ To get up to speed, you'll need to
- Learn some non-basic Python to understand what's going on in some of the - Learn some non-basic Python to understand what's going on in some of the
trickier files (like tensor.py). trickier files (like tensor.py).
- Go through the `NumPy documentation`_. - Go through the `NumPy documentation`_.
- Learn to write reStructuredText_ for epydoc_ and Sphinx_. - Learn to write reStructuredText_ for Sphinx_.
- Learn about how unittest_ and nose_ work - Learn about how unittest_ and nose_ work
.. _Sphinx: http://sphinx.pocoo.org/ .. _Sphinx: http://sphinx.pocoo.org/
.. _reStructuredText: http://docutils.sourceforge.net/rst.html .. _reStructuredText: http://docutils.sourceforge.net/rst.html
.. _epydoc: http://epydoc.sourceforge.net/
.. _NumPy documentation: http://docs.scipy.org/numpy/ .. _NumPy documentation: http://docs.scipy.org/numpy/
.. _unittest: http://docs.python.org/library/unittest.html .. _unittest: http://docs.python.org/library/unittest.html
.. _nose: http://somethingaboutorange.com/mrl/projects/nose/ .. _nose: http://somethingaboutorange.com/mrl/projects/nose/
......
...@@ -672,13 +672,14 @@ is a :ref:`variable` we statically know the value of. ...@@ -672,13 +672,14 @@ is a :ref:`variable` we statically know the value of.
.. doctest:: mul .. doctest:: mul
>>> import numpy
>>> x = double('x') >>> x = double('x')
>>> z = mul(x, 2) >>> z = mul(x, 2)
>>> f = theano.function([x], z) >>> f = theano.function([x], z)
>>> f(10) >>> f(10)
20.0 20.0
>>> f(3.4) >>> numpy.allclose(f(3.4), 6.8)
6.8 True
Now the code works the way we want it to. Now the code works the way we want it to.
......
...@@ -146,7 +146,7 @@ the params type. ...@@ -146,7 +146,7 @@ the params type.
def make_node(self, inp): def make_node(self, inp):
inp = as_scalar(inp) inp = as_scalar(inp)
return Apply(self, [inp], [inp.type()] return Apply(self, [inp], [inp.type()])
def perform(self, node, inputs, output_storage, params): def perform(self, node, inputs, output_storage, params):
# Here params is a python float so this is ok # Here params is a python float so this is ok
...@@ -193,7 +193,7 @@ weights. ...@@ -193,7 +193,7 @@ weights.
def make_node(self, x, y): def make_node(self, x, y):
x = as_scalar(x) x = as_scalar(x)
y = as_scalar(y) y = as_scalar(y)
return Apply(self, [x, y], [x.type()] return Apply(self, [x, y], [x.type()])
def c_support_code_struct(self, node, name): def c_support_code_struct(self, node, name):
return """ return """
......
...@@ -886,7 +886,7 @@ We recommend you look at the documentation on the website, since it ...@@ -886,7 +886,7 @@ We recommend you look at the documentation on the website, since it
will be more current than the documentation included with the package. will be more current than the documentation included with the package.
If you really wish to build the documentation yourself, you will need If you really wish to build the documentation yourself, you will need
epydoc and sphinx, as described above. Issue the following command:: sphinx, as described above. Issue the following command::
python ./doc/scripts/docgen.py python ./doc/scripts/docgen.py
......
...@@ -40,8 +40,8 @@ Use ReST for documentation ...@@ -40,8 +40,8 @@ Use ReST for documentation
-------------------------- --------------------------
* `ReST <http://docutils.sourceforge.net/rst.html>`__ is standardized. * `ReST <http://docutils.sourceforge.net/rst.html>`__ is standardized.
epydoc is not. trac wiki-markup is not. trac wiki-markup is not.
This means that ReST can be cut-and-pasted between epydoc, code, other This means that ReST can be cut-and-pasted between code, other
docs, and TRAC. This is a huge win! 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 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. * ReST has figure and table directives, and can be converted (using a standard tool) to latex documents.
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
:mod:`shared` - defines theano.shared :mod:`shared` - defines theano.shared
=========================================== ===========================================
.. module:: shared .. module:: theano.compile.sharedvalue
:platform: Unix, Windows :platform: Unix, Windows
:synopsis: defines theano.shared and related classes :synopsis: defines theano.shared and related classes
.. moduleauthor:: LISA .. moduleauthor:: LISA
...@@ -47,7 +47,7 @@ ...@@ -47,7 +47,7 @@
:type: class:`Container` :type: class:`Container`
.. autofunction:: theano.compile.sharedvalue.shared .. autofunction:: shared
.. function:: shared_constructor(ctor) .. function:: shared_constructor(ctor)
......
...@@ -19,7 +19,7 @@ Blas Op ...@@ -19,7 +19,7 @@ Blas Op
.. automodule:: theano.sandbox.cuda.blas .. automodule:: theano.sandbox.cuda.blas
:members: :members:
.. autofunction:: theano.sandbox.cuda.blas.batched_dot .. autoclass:: theano.sandbox.cuda.blas.BatchedDotOp
Nnet Op Nnet Op
======= =======
......
...@@ -104,7 +104,7 @@ TODO: Give examples on how to use these things! They are pretty complicated. ...@@ -104,7 +104,7 @@ TODO: Give examples on how to use these things! They are pretty complicated.
as a manual replacement for nnet.conv2d. as a manual replacement for nnet.conv2d.
- :func:`GpuCorrMM <theano.sandbox.cuda.blas.GpuCorrMM>` - :func:`GpuCorrMM <theano.sandbox.cuda.blas.GpuCorrMM>`
This is a GPU-only 2d correlation implementation taken from This is a GPU-only 2d correlation implementation taken from
`caffe <https://github.com/BVLC/caffe/blob/master/src/caffe/layers/conv_layer.cu>`_ `caffe's CUDA implementation <https://github.com/BVLC/caffe/blob/master/src/caffe/layers/conv_layer.cu>`_
and also used by Torch. It does not flip the kernel. and also used by Torch. It does not flip the kernel.
For each element in a batch, it first creates a For each element in a batch, it first creates a
...@@ -122,7 +122,7 @@ TODO: Give examples on how to use these things! They are pretty complicated. ...@@ -122,7 +122,7 @@ TODO: Give examples on how to use these things! They are pretty complicated.
If using it, please see the warning about a bug in CUDA 5.0 to 6.0 below. If using it, please see the warning about a bug in CUDA 5.0 to 6.0 below.
- :func:`CorrMM <theano.tensor.nnet.corr.CorrMM>` - :func:`CorrMM <theano.tensor.nnet.corr.CorrMM>`
This is a CPU-only 2d correlation implementation taken from This is a CPU-only 2d correlation implementation taken from
`caffe <https://github.com/BVLC/caffe/blob/master/src/caffe/layers/conv_layer.cpp>`_ `caffe's cpp implementation <https://github.com/BVLC/caffe/blob/master/src/caffe/layers/conv_layer.cpp>`_
and also used by Torch. It does not flip the kernel. As it provides a gradient, and also used by Torch. It does not flip the kernel. As it provides a gradient,
you can use it as a replacement for nnet.conv2d. For convolutions done on you can use it as a replacement for nnet.conv2d. For convolutions done on
CPU, nnet.conv2d will be replaced by CorrMM. To explicitly disable it, set CPU, nnet.conv2d will be replaced by CorrMM. To explicitly disable it, set
......
...@@ -21,7 +21,7 @@ object for each such variable, and draw from it as necessary. We will call this ...@@ -21,7 +21,7 @@ object for each such variable, and draw from it as necessary. We will call this
random numbers a *random stream*. random numbers a *random stream*.
For an example of how to use random numbers, see For an example of how to use random numbers, see
:ref:`using_random_numbers`. :ref:`Using Random Numbers <using_random_numbers>`.
Reference Reference
......
...@@ -89,7 +89,7 @@ The proposal is for two new ways of creating a *shared* variable: ...@@ -89,7 +89,7 @@ The proposal is for two new ways of creating a *shared* variable:
def shared(value, name=None, strict=False, **kwargs): def shared(value, name=None, strict=False, **kwargs):
"""Return a SharedVariable Variable, initialized with a copy or reference of `value`. """Return a SharedVariable Variable, initialized with a copy or reference of `value`.
This function iterates over constructor functions (see `shared_constructor`) to find a This function iterates over constructor functions (see :func:`shared_constructor`) to find a
suitable SharedVariable subclass. suitable SharedVariable subclass.
:note: :note:
......
...@@ -4,56 +4,6 @@ import sys ...@@ -4,56 +4,6 @@ import sys
import os import os
import shutil import shutil
import inspect import inspect
from epydoc import docintrospecter
from epydoc.apidoc import RoutineDoc
def Op_to_RoutineDoc(op, routine_doc, module_name=None):
routine_doc.specialize_to(RoutineDoc)
#NB: this code is lifted from epydoc/docintrospecter.py
# op should be an op instance
assert hasattr(op, 'perform')
# Record the function's docstring.
routine_doc.docstring = getattr(op, '__doc__', '')
# Record the function's signature.
func = op.__epydoc_asRoutine
if isinstance(func, type(Op_to_RoutineDoc)):
(args, vararg, kwarg, defaults) = inspect.getargspec(func)
# Add the arguments.
routine_doc.posargs = args
routine_doc.vararg = vararg
routine_doc.kwarg = kwarg
# Set default values for positional arguments.
routine_doc.posarg_defaults = [None] * len(args)
# Set the routine's line number.
if hasattr(func, '__code__'):
routine_doc.lineno = func.__code__.co_firstlineno
else:
# [XX] I should probably use UNKNOWN here??
# dvarrazzo: if '...' is to be changed, also check that
# `docstringparser.process_arg_field()` works correctly.
# See SF bug #1556024.
routine_doc.posargs = ['...']
routine_doc.posarg_defaults = [None]
routine_doc.kwarg = None
routine_doc.vararg = None
return routine_doc
docintrospecter.register_introspecter(
lambda value: getattr(value, '__epydoc_asRoutine', False),
Op_to_RoutineDoc,
priority=-1)
import getopt import getopt
from collections import defaultdict from collections import defaultdict
...@@ -66,7 +16,7 @@ if __name__ == '__main__': ...@@ -66,7 +16,7 @@ if __name__ == '__main__':
opts, args = getopt.getopt( opts, args = getopt.getopt(
sys.argv[1:], sys.argv[1:],
'o:f:', 'o:f:',
['epydoc', 'rst', 'help', 'nopdf', 'cache', 'test']) ['rst', 'help', 'nopdf', 'cache', 'test'])
options.update(dict([x, y or True] for x, y in opts)) options.update(dict([x, y or True] for x, y in opts))
if options['--help']: if options['--help']:
print('Usage: %s [OPTIONS] [files...]' % sys.argv[0]) print('Usage: %s [OPTIONS] [files...]' % sys.argv[0])
...@@ -74,8 +24,6 @@ if __name__ == '__main__': ...@@ -74,8 +24,6 @@ if __name__ == '__main__':
print(' --cache: use the doctree cache') print(' --cache: use the doctree cache')
print(' --rst: only compile the doc (requires sphinx)') print(' --rst: only compile the doc (requires sphinx)')
print(' --nopdf: do not produce a PDF file from the doc, only HTML') print(' --nopdf: do not produce a PDF file from the doc, only HTML')
print(' --epydoc: only compile the api documentation', end=' ')
print('(requires epydoc)')
print(' --test: run all the code samples in the documentaton') print(' --test: run all the code samples in the documentaton')
print(' --help: this help') print(' --help: this help')
print('If one or more files are specified after the options then only ' print('If one or more files are specified after the options then only '
...@@ -83,7 +31,7 @@ if __name__ == '__main__': ...@@ -83,7 +31,7 @@ if __name__ == '__main__':
'processed. Specifying files will implies --cache.') 'processed. Specifying files will implies --cache.')
sys.exit(0) sys.exit(0)
if not (options['--epydoc'] or options['--rst'] or options['--test']): if options['--rst'] or options['--test']:
# Default is now rst # Default is now rst
options['--rst'] = True options['--rst'] = True
...@@ -105,26 +53,10 @@ if __name__ == '__main__': ...@@ -105,26 +53,10 @@ if __name__ == '__main__':
pythonpath = os.pathsep.join([throot, pythonpath]) pythonpath = os.pathsep.join([throot, pythonpath])
sys.path[0:0] = [throot] # We must not use os.environ. sys.path[0:0] = [throot] # We must not use os.environ.
if options['--all'] or options['--epydoc']:
mkdir("api")
#Generate HTML doc
## This causes problems with the subsequent generation of sphinx doc
#from epydoc.cli import cli
#sys.argv[:] = ['', '--config', '%s/doc/api/epydoc.conf' % throot,
# '-o', 'api']
#cli()
## So we use this instead
os.system("epydoc --config %s/doc/api/epydoc.conf -o api" % throot)
# Generate PDF doc
# TODO
def call_sphinx(builder, workdir, extraopts=None): def call_sphinx(builder, workdir, extraopts=None):
import sphinx import sphinx
if extraopts is None: if extraopts is None:
extraopts = [] extraopts = ['-W']
if not options['--cache'] and files is None: if not options['--cache'] and files is None:
extraopts.append('-E') extraopts.append('-E')
docpath = os.path.join(throot, 'doc') docpath = os.path.join(throot, 'doc')
......
...@@ -11,6 +11,7 @@ To get us started with Theano and get a feel of what we're working with, ...@@ -11,6 +11,7 @@ To get us started with Theano and get a feel of what we're working with,
let's make a simple function: add two numbers together. Here is how you do let's make a simple function: add two numbers together. Here is how you do
it: it:
>>> import numpy
>>> import theano.tensor as T >>> import theano.tensor as T
>>> from theano import function >>> from theano import function
>>> x = T.dscalar('x') >>> x = T.dscalar('x')
...@@ -22,9 +23,8 @@ And now that we've created our function we can use it: ...@@ -22,9 +23,8 @@ And now that we've created our function we can use it:
>>> f(2, 3) >>> f(2, 3)
array(5.0) array(5.0)
>>> f(16.3, 12.1) >>> numpy.allclose(f(16.3, 12.1), 28.4)
array(28.4) True
Let's break this down into several steps. The first step is to define Let's break this down into several steps. The first step is to define
two symbols (*Variables*) representing the quantities that you want two symbols (*Variables*) representing the quantities that you want
...@@ -123,12 +123,13 @@ then be used like a normal Python function. ...@@ -123,12 +123,13 @@ then be used like a normal Python function.
the tutorial so far. It has the added benefit of not requiring the tutorial so far. It has the added benefit of not requiring
you to import :func:`function` . Here is how :func:`eval` works: you to import :func:`function` . Here is how :func:`eval` works:
>>> import numpy
>>> import theano.tensor as T >>> import theano.tensor as T
>>> x = T.dscalar('x') >>> x = T.dscalar('x')
>>> y = T.dscalar('y') >>> y = T.dscalar('y')
>>> z = x + y >>> z = x + y
>>> z.eval({x : 16.3, y : 12.1}) >>> numpy.allclose(z.eval({x : 16.3, y : 12.1}), 28.4)
array(28.4) True
We passed :func:`eval` a dictionary mapping symbolic theano We passed :func:`eval` a dictionary mapping symbolic theano
variables to the values to substitute for them, and it returned variables to the values to substitute for them, and it returned
......
...@@ -207,15 +207,15 @@ Let's try it out! ...@@ -207,15 +207,15 @@ Let's try it out!
.. theano/tests/test_tutorial.py:T_examples.test_examples_8 .. theano/tests/test_tutorial.py:T_examples.test_examples_8
>>> state.get_value() >>> state.get_value()
array(0) 0
>>> accumulator(1) >>> accumulator(1)
array(0) array(0)
>>> state.get_value() >>> state.get_value()
array(1) 1
>>> accumulator(300) >>> accumulator(300)
array(1) array(1)
>>> state.get_value() >>> state.get_value()
array(301) 301
It is possible to reset the state. Just use the ``.set_value()`` method: It is possible to reset the state. Just use the ``.set_value()`` method:
...@@ -223,7 +223,7 @@ It is possible to reset the state. Just use the ``.set_value()`` method: ...@@ -223,7 +223,7 @@ It is possible to reset the state. Just use the ``.set_value()`` method:
>>> accumulator(3) >>> accumulator(3)
array(-1) array(-1)
>>> state.get_value() >>> state.get_value()
array(2) 2
As we mentioned above, you can define more than one function to use the same As we mentioned above, you can define more than one function to use the same
shared variable. These functions can all update the value. shared variable. These functions can all update the value.
...@@ -235,7 +235,7 @@ shared variable. These functions can all update the value. ...@@ -235,7 +235,7 @@ shared variable. These functions can all update the value.
>>> decrementor(2) >>> decrementor(2)
array(2) array(2)
>>> state.get_value() >>> state.get_value()
array(0) 0
You might be wondering why the updates mechanism exists. You can always You might be wondering why the updates mechanism exists. You can always
achieve a similar result by returning the new expressions, and working with achieve a similar result by returning the new expressions, and working with
...@@ -262,7 +262,7 @@ for the purpose of one particular function. ...@@ -262,7 +262,7 @@ for the purpose of one particular function.
>>> skip_shared(1, 3) # we're using 3 for the state, not state.value >>> skip_shared(1, 3) # we're using 3 for the state, not state.value
array(7) array(7)
>>> state.get_value() # old state still there, but we didn't use it >>> state.get_value() # old state still there, but we didn't use it
array(0) 0
The ``givens`` parameter can be used to replace any symbolic variable, not just a The ``givens`` parameter can be used to replace any symbolic variable, not just a
shared variable. You can replace constants, and expressions, in general. Be shared variable. You can replace constants, and expressions, in general. Be
......
...@@ -23,6 +23,7 @@ Here is the code to compute this gradient: ...@@ -23,6 +23,7 @@ Here is the code to compute this gradient:
.. If you modify this code, also change : .. If you modify this code, also change :
.. theano/tests/test_tutorial.py:T_examples.test_examples_4 .. theano/tests/test_tutorial.py:T_examples.test_examples_4
>>> import numpy
>>> import theano >>> import theano
>>> import theano.tensor as T >>> import theano.tensor as T
>>> from theano import pp >>> from theano import pp
...@@ -34,8 +35,8 @@ Here is the code to compute this gradient: ...@@ -34,8 +35,8 @@ Here is the code to compute this gradient:
>>> f = theano.function([x], gy) >>> f = theano.function([x], gy)
>>> f(4) >>> f(4)
array(8.0) array(8.0)
>>> f(94.2) >>> numpy.allclose(f(94.2), 188.4)
array(188.4) True
In this example, we can see from ``pp(gy)`` that we are computing In this example, we can see from ``pp(gy)`` that we are computing
the correct symbolic gradient. the correct symbolic gradient.
......
...@@ -27,9 +27,7 @@ functions using either of the following two options: ...@@ -27,9 +27,7 @@ functions using either of the following two options:
:attr:`profiling.n_ops` and :attr:`profiling.min_memory_size` :attr:`profiling.n_ops` and :attr:`profiling.min_memory_size`
to modify the quantify of information printed. to modify the quantify of information printed.
2. Pass the argument :attr:`profile=True` to the function 2. Pass the argument :attr:`profile=True` to the function :func:`theano.function <function.function>`. And then call :attr:`f.profile.print_summary()` for a single function.
:func:`theano.function <function.function>`. And then call
:attr:`f.profile.print_summary()` for a single function.
- Use this option when you want to profile not all the - Use this option when you want to profile not all the
functions but one or more specific function(s). functions but one or more specific function(s).
- You can also combine the profile of many functions: - You can also combine the profile of many functions:
......
...@@ -50,9 +50,9 @@ def function_dump(filename, inputs, outputs=None, mode=None, updates=None, ...@@ -50,9 +50,9 @@ def function_dump(filename, inputs, outputs=None, mode=None, updates=None,
>>> f = theano.function(**d) # doctest: +SKIP >>> f = theano.function(**d) # doctest: +SKIP
Note: Note:
The parameter extra_tag_to_remove, is passed to the StripPickler used. The parameter extra_tag_to_remove, is passed to the StripPickler used.
To pickle graph made by Blocks, it must be: To pickle graph made by Blocks, it must be:
['annotations', 'replacement_of', 'aggregation_scheme', 'rolesc'] ['annotations', 'replacement_of', 'aggregation_scheme', 'rolesc']
""" """
assert isinstance(filename, string_types) assert isinstance(filename, string_types)
......
...@@ -200,20 +200,25 @@ def shared_constructor(ctor, remove=False): ...@@ -200,20 +200,25 @@ def shared_constructor(ctor, remove=False):
def shared(value, name=None, strict=False, allow_downcast=None, **kwargs): def shared(value, name=None, strict=False, allow_downcast=None, **kwargs):
""" """Return a SharedVariable Variable, initialized with a copy or
Return a SharedVariable Variable, initialized with a copy or
reference of `value`. reference of `value`.
This function iterates over This function iterates over constructor functions to find a
:ref:`constructor functions <shared_constructor>` suitable SharedVariable subclass. The suitable one is the first
to find a suitable SharedVariable subclass. constructor that accept the given value. See the documentation of
The suitable one is the first constructor that accept the given value. :func:`shared_constructor` for the definition of a contructor
function.
This function is meant as a convenient default. If you want to use a This function is meant as a convenient default. If you want to use a
specific shared variable constructor, consider calling it directly. specific shared variable constructor, consider calling it directly.
``theano.shared`` is a shortcut to this function. ``theano.shared`` is a shortcut to this function.
.. attribute:: constructors
A list of shared variable constructors that will be tried in reverse
order.
Notes Notes
----- -----
By passing kwargs, you effectively limit the set of potential constructors By passing kwargs, you effectively limit the set of potential constructors
...@@ -229,11 +234,6 @@ def shared(value, name=None, strict=False, allow_downcast=None, **kwargs): ...@@ -229,11 +234,6 @@ def shared(value, name=None, strict=False, allow_downcast=None, **kwargs):
This parameter allows you to create for example a `row` or `column` 2d This parameter allows you to create for example a `row` or `column` 2d
tensor. tensor.
.. attribute:: constructors
A list of shared variable constructors that will be tried in reverse
order.
""" """
try: try:
......
...@@ -485,12 +485,13 @@ class Variable(Node): ...@@ -485,12 +485,13 @@ class Variable(Node):
Examples Examples
-------- --------
>>> import numpy
>>> import theano.tensor as T >>> import theano.tensor as T
>>> x = T.dscalar('x') >>> x = T.dscalar('x')
>>> y = T.dscalar('y') >>> y = T.dscalar('y')
>>> z = x + y >>> z = x + y
>>> z.eval({x : 16.3, y : 12.1}) >>> numpy.allclose(z.eval({x : 16.3, y : 12.1}), 28.4)
array(28.4) True
We passed :func:`eval` a dictionary mapping symbolic theano We passed :func:`eval` a dictionary mapping symbolic theano
variables to the values to substitute for them, and it returned variables to the values to substitute for them, and it returned
......
...@@ -144,6 +144,7 @@ else: ...@@ -144,6 +144,7 @@ else:
u = CompatUnpickler(fp, encoding="latin1") u = CompatUnpickler(fp, encoding="latin1")
else: else:
u = CompatUnpickler(fp) u = CompatUnpickler(fp)
mat = u.load() mat = u.load()
""" """
pass pass
......
...@@ -273,7 +273,7 @@ def sp_ones_like(x): ...@@ -273,7 +273,7 @@ def sp_ones_like(x):
Returns Returns
------- -------
matrix A sparse matrix
The same as `x` with data changed for ones. The same as `x` with data changed for ones.
""" """
...@@ -293,7 +293,7 @@ def sp_zeros_like(x): ...@@ -293,7 +293,7 @@ def sp_zeros_like(x):
Returns Returns
------- -------
matrix A sparse matrix
The same as `x` with zero entries for all element. The same as `x` with zero entries for all element.
""" """
...@@ -1765,7 +1765,7 @@ def row_scale(x, s): ...@@ -1765,7 +1765,7 @@ def row_scale(x, s):
Returns Returns
------- -------
matrix A sparse matrix
A sparse matrix in the same format as `x` whose each row has been A sparse matrix in the same format as `x` whose each row has been
multiplied by the corresponding element of `s`. multiplied by the corresponding element of `s`.
...@@ -2070,7 +2070,7 @@ def clean(x): ...@@ -2070,7 +2070,7 @@ def clean(x):
Returns Returns
------- -------
matrix A sparse matrix
The same as `x` with indices sorted and zeros The same as `x` with indices sorted and zeros
removed. removed.
...@@ -2166,7 +2166,7 @@ y ...@@ -2166,7 +2166,7 @@ y
Returns Returns
------- -------
matrix A sparse matrix
The sum of the two sparse matrices element wise. The sum of the two sparse matrices element wise.
Notes Notes
...@@ -2270,7 +2270,7 @@ y ...@@ -2270,7 +2270,7 @@ y
Returns Returns
------- -------
matrix A sparse matrix
A sparse matrix containing the addition of the vector to A sparse matrix containing the addition of the vector to
the data of the sparse matrix. the data of the sparse matrix.
...@@ -2297,7 +2297,7 @@ def add(x, y): ...@@ -2297,7 +2297,7 @@ def add(x, y):
Returns Returns
------- -------
matrix A sparse matrix
`x` + `y` `x` + `y`
Notes Notes
...@@ -2348,7 +2348,7 @@ def sub(x, y): ...@@ -2348,7 +2348,7 @@ def sub(x, y):
Returns Returns
------- -------
matrix A sparse matrix
`x` - `y` `x` - `y`
Notes Notes
...@@ -2547,7 +2547,7 @@ y ...@@ -2547,7 +2547,7 @@ y
Returns Returns
------- -------
matrix A sparse matrix
The product x * y element wise. The product x * y element wise.
Notes Notes
...@@ -2572,7 +2572,7 @@ def mul(x, y): ...@@ -2572,7 +2572,7 @@ def mul(x, y):
Returns Returns
------- -------
matrix A sparse matrix
`x` + `y` `x` + `y`
Notes Notes
...@@ -3720,7 +3720,7 @@ def structured_dot(x, y): ...@@ -3720,7 +3720,7 @@ def structured_dot(x, y):
Returns Returns
------- -------
matrix A sparse matrix
The dot product of `a` and `b`. The dot product of `a` and `b`.
Notes Notes
......
...@@ -461,7 +461,7 @@ class Elemwise(OpenMPOp): ...@@ -461,7 +461,7 @@ class Elemwise(OpenMPOp):
scalar.ScalarOp to get help about controlling the output type) scalar.ScalarOp to get help about controlling the output type)
Parameters Parameters
----------- ----------
scalar_op scalar_op
An instance of a subclass of scalar.ScalarOp which works uniquely An instance of a subclass of scalar.ScalarOp which works uniquely
on scalars. on scalars.
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论