Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
d11e2251
提交
d11e2251
authored
3月 18, 2017
作者:
Pascal Lamblin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
pep8 and syntax in unittest doc
上级
a3b4133f
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
13 行增加
和
13 行删除
+13
-13
unittest.txt
doc/extending/unittest.txt
+13
-13
没有找到文件。
doc/extending/unittest.txt
浏览文件 @
d11e2251
...
...
@@ -333,12 +333,12 @@ type this:
Using Random Values in Test Cases
---------------------------------
numpy.random
is often used in unit tests to initialize large data
``numpy.random``
is often used in unit tests to initialize large data
structures, for use as inputs to the function or module being
tested. When doing this, it is imperative that the random number
generator be seeded at the be beginning of each unit test. This will
ensure that unittest behaviour is consistent from one execution to
another (i.e always pass or always fail).
another (i.e
.,
always pass or always fail).
Instead of using ``numpy.random.seed`` to do this, we encourage users to
do the following:
...
...
@@ -350,39 +350,39 @@ do the following:
class TestTensorDot(unittest.TestCase):
def setUp(self):
unittest_tools.seed_rng()
# OR ... call with an explicit seed
unittest_tools.seed_rng(234234)
#
use only if really necessary!
# OR ... call with an explicit seed
unittest_tools.seed_rng(234234)
#
use only if really necessary!
The behaviour of
seed_rng
is as follows:
The behaviour of
``seed_rng``
is as follows:
* If an explicit seed is given, it will be used for seeding numpy's rng.
* If not, it will use ``config.unittests.rseed`` (its default value is
666
).
* If not, it will use ``config.unittests.rseed`` (its default value is
``666``
).
* If
config.unittests.rseed is set to "random"
, it will seed the rng with
* If
``config.unittests.rseed`` is set to ``"random"``
, it will seed the rng with
None, which is equivalent to seeding with a random seed.
The main advantage of using
unittest_tools.seed_rng
is that it allows
The main advantage of using
``unittest_tools.seed_rng``
is that it allows
us to change the seed used in the unitests, without having to manually
edit all the files. For example, this allows the nightly build to run
theano-nose
repeatedly, changing the seed on every run (hence achieving
``theano-nose``
repeatedly, changing the seed on every run (hence achieving
a higher confidence that the variables are correct), while still
making sure unittests are deterministic.
Users who prefer their unittests to be random (when run on their local
machine) can simply set ``config.unittests.rseed`` to
'random'
(see
machine) can simply set ``config.unittests.rseed`` to
``'random'``
(see
:mod:`config`).
Similarly, to provide a seed to
numpy.random.RandomState
, simply use:
Similarly, to provide a seed to
``numpy.random.RandomState``
, simply use:
.. testcode::
import numpy
rng = numpy.random.RandomState(unittest_tools.fetch_seed())
# OR providing an explicit seed
rng = numpy.random.RandomState(unittest_tools.fetch_seed(1231))
#
again not recommended
rng = numpy.random.RandomState(unittest_tools.fetch_seed(1231))
#
again not recommended
Note that the ability to change the seed from one nosetest to another,
is incompatible with the method of hard-coding the baseline variables
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论