提交 74253a36 authored 作者: Frederic's avatar Frederic

fix and better explaination in the doc by code review.

上级 ecdbcd92
......@@ -158,17 +158,17 @@ Try it!
How to test it
--------------
Theano has some functions to simplify testing. Those help test the
infer_shape, grad and R_op method. Put the following code in a file
and execute with the `nosetests` program to run it.
Theano has some functions to simplify testing. These help test the
``infer_shape``, ``grad`` and ``R_op`` methods. Put the following code
in a file and execute it with the ``nosetests`` program.
Basic tests
===========
Basic tests are done by you just by using the Op and checking it
Basic tests are done by you just by using the Op and checking that it
return the right answer. If you detect an error, you must raise an
exception. You can use the `assert` keyword to raise automatically an
AssertionError.
exception. You can use the `assert` keyword to automatically raise an
``AssertionError``.
.. code-block:: python
......@@ -185,25 +185,29 @@ AssertionError.
f = theano.function([x], self.op(x))
inp = numpy.asarray(numpy.random.rand(5, 4), dtype=config.floatX)
out = f(inp)
# Compare to result computed to the expected value.
# Compare the result computed to the expected value.
assert numpy.allclose(inp * 2, out)
Testing the infer_shape
=======================
When a class inherits from the InferShapeTester class, it gets the
`self._compile_and_check` method that tests the Op infer_shape
method. It checks if the optimized graph obtained gives the correct
values. It also tests that the Op gets removed from the
graph. `self._compile_and_check` compiles a Theano function. So it
takes as parameter the list of inputs and outputs Theano variable
that is passed to `theano.function`. Then
with a list of real values to pass the the compiled function (don't
use symmetric shape!). It also takes the class op to verify that
it get removed from the graph.
When a class inherits from the ``InferShapeTester`` class, it gets the
`self._compile_and_check` method that tests the Op ``infer_shape``
method. It tests that the Op gets optimized out of the graph if only
the shape of the output is needed and not the output
itself. Additionally, it checks that such an optimized graph computes
the correct shape, by comparing it to the actual shape of the computed
output.
`self._compile_and_check` compiles a Theano function. It takes as
parameters the lists of input and output Theano variables, as would be
provided to theano.function, and a list of real values to pass to the
compiled function (don't use shapes that are symmetric, e.g. (3, 3),
as they can easily to hide errors). It also takes the Op class to
verify that no Ops of that type appear in the shape-optimized graph.
If there is an error, the function raises an exception. If you want to
see it fail, you can implement a wrong infer_shape.
see it fail, you can implement an incorrect ``infer_shape``.
.. code-block:: python
......@@ -227,7 +231,7 @@ analytic (symbolically computed) gradient and the numeric
gradient (computed through the Finite Difference Method).
If there is an error, the function raises an exception. If you want to
see it fail, you can implement a wrong gradient (for instance removing
see it fail, you can implement an incorrect gradient (for instance, by removing
the multiplication by 2).
.. code-block:: python
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论