提交 74554f33 authored 作者: Olivier Delalleau's avatar Olivier Delalleau

Merge pull request #187 from nouiz/doc_str

Doc str
...@@ -127,17 +127,43 @@ Op example ...@@ -127,17 +127,43 @@ Op example
z = output_storage[0] z = output_storage[0]
z[0] = x * 2 z[0] = x * 2
def infer_shape(self, node, i0_shapes):
return i0_shapes
def grad(self, inputs, output_grads):
return [output_grads[0] * 2]
Test it! Test it!
>>> x = theano.tensor.matrix() .. code-block:: python
>>> f = theano.function([x],DoubleOp()(x))
>>> import numpy x = theano.tensor.matrix()
>>> inp = numpy.random.rand(5,5) f = theano.function([x], DoubleOp()(x))
>>> out = f(inp) import numpy
>>> assert numpy.allclose(inp*2, out) inp = numpy.random.rand(5, 5)
>>> print inp out = f(inp)
>>> print out assert numpy.allclose(inp * 2, out)
print inp
print out
Testing the gradient
--------------------
The function :ref:`verify_grad <validating_grad>`
verifies the gradient of an Op or Theano graph. It compares the
analytic (symbolically computed) gradient and the numeric
gradient (computed through the Finite Difference Method).
To verify the grad method of the DoubleOp, you can use this:
.. code-block:: python
import numpy
import theano.tests
theano.tests.unittest_tools.verify_grad(DoubleOp(), [numpy.random.rand(5,7,2)])
If nothing happens, then it works! If you want to see it fail, you can
implement a wrong gradient (for instance removing the multiplication by 2).
Exercises 8 Exercises 8
----------- -----------
......
...@@ -374,6 +374,8 @@ A few tools have been developed to help automate the development of ...@@ -374,6 +374,8 @@ A few tools have been developed to help automate the development of
unitests for Theano Ops. unitests for Theano Ops.
.. _validating_grad:
Validating the Gradient Validating the Gradient
----------------------- -----------------------
......
...@@ -43,6 +43,14 @@ Mailing list ...@@ -43,6 +43,14 @@ Mailing list
See the Theano main page for the theano-dev, theano-buildbot and See the Theano main page for the theano-dev, theano-buildbot and
theano-github mailing list. They are useful to Theano contributors. theano-github mailing list. They are useful to Theano contributors.
Git config
----------
.. code-block:: bash
git config --global user.email you@yourdomain.example.com
git config --global user.name "Your Name Comes Here"
Typical development workflow Typical development workflow
---------------------------- ----------------------------
......
.. _faq:
==========================
Frequently Asked Questions
==========================
TypeError: object of type 'TensorVariable' has no len()
-------------------------------------------------------
If you receive this error:
.. code-block:: python
TypeError: object of type 'TensorVariable' has no len()
We can't implement the __len__ function on Theano Variables. This is
because Python requires that this function returns an integer, but we
can't do this as we are working with symbolic variables. You can use
`var.shape[0]` as a workaround.
Also we can't change the above error message into a more explicit one
because of some other Python internal behavior that can't be modified.
...@@ -39,4 +39,4 @@ you out. ...@@ -39,4 +39,4 @@ you out.
shape_info shape_info
remarks remarks
debug_faq debug_faq
faq
...@@ -3857,6 +3857,9 @@ class Split(Op): ...@@ -3857,6 +3857,9 @@ class Split(Op):
return (type(self) == type(other) and return (type(self) == type(other) and
self.len_splits == other.len_splits) self.len_splits == other.len_splits)
def __str__(self):
return self.__class__.__name__ + "{%s}" % self.len_splits
def __hash__(self): def __hash__(self):
return hash(Split) ^ self.len_splits return hash(Split) ^ self.len_splits
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论