Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
74253a36
提交
74253a36
authored
5月 16, 2012
作者:
Frederic
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix and better explaination in the doc by code review.
上级
ecdbcd92
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
23 行增加
和
19 行删除
+23
-19
extending_theano.txt
doc/tutorial/extending_theano.txt
+23
-19
没有找到文件。
doc/tutorial/extending_theano.txt
浏览文件 @
74253a36
...
@@ -158,17 +158,17 @@ Try it!
...
@@ -158,17 +158,17 @@ Try it!
How to test it
How to test it
--------------
--------------
Theano has some functions to simplify testing. Th
o
se help test the
Theano has some functions to simplify testing. Th
e
se help test the
infer_shape, grad and R_op method. Put the following code in a fil
e
``infer_shape``, ``grad`` and ``R_op`` methods. Put the following cod
e
and execute with the `nosetests` program to run it
.
in a file and execute it with the ``nosetests`` program
.
Basic tests
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
return the right answer. If you detect an error, you must raise an
exception. You can use the `assert` keyword to
raise automatically
an
exception. You can use the `assert` keyword to
automatically raise
an
AssertionError
.
``AssertionError``
.
.. code-block:: python
.. code-block:: python
...
@@ -185,25 +185,29 @@ AssertionError.
...
@@ -185,25 +185,29 @@ AssertionError.
f = theano.function([x], self.op(x))
f = theano.function([x], self.op(x))
inp = numpy.asarray(numpy.random.rand(5, 4), dtype=config.floatX)
inp = numpy.asarray(numpy.random.rand(5, 4), dtype=config.floatX)
out = f(inp)
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)
assert numpy.allclose(inp * 2, out)
Testing the infer_shape
Testing the infer_shape
=======================
=======================
When a class inherits from the InferShapeTester class, it gets the
When a class inherits from the ``InferShapeTester`` class, it gets the
`self._compile_and_check` method that tests the Op infer_shape
`self._compile_and_check` method that tests the Op ``infer_shape``
method. It checks if the optimized graph obtained gives the correct
method. It tests that the Op gets optimized out of the graph if only
values. It also tests that the Op gets removed from the
the shape of the output is needed and not the output
graph. `self._compile_and_check` compiles a Theano function. So it
itself. Additionally, it checks that such an optimized graph computes
takes as parameter the list of inputs and outputs Theano variable
the correct shape, by comparing it to the actual shape of the computed
that is passed to `theano.function`. Then
output.
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
`self._compile_and_check` compiles a Theano function. It takes as
it get removed from the graph.
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
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 a
n incorrect ``infer_shape``
.
.. code-block:: python
.. code-block:: python
...
@@ -227,7 +231,7 @@ analytic (symbolically computed) gradient and the numeric
...
@@ -227,7 +231,7 @@ analytic (symbolically computed) gradient and the numeric
gradient (computed through the Finite Difference Method).
gradient (computed through the Finite Difference Method).
If there is an error, the function raises an exception. If you want to
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 a
n incorrect gradient (for instance, by
removing
the multiplication by 2).
the multiplication by 2).
.. code-block:: python
.. code-block:: python
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论