Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
898d146d
提交
898d146d
authored
3月 20, 2017
作者:
Frédéric Bastien
提交者:
GitHub
3月 20, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #5698 from lamblin/fix_pep8
Fix pep8
上级
44f7578c
d11e2251
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
18 行增加
和
18 行删除
+18
-18
unittest.txt
doc/extending/unittest.txt
+18
-13
test_basic.py
theano/tensor/tests/test_basic.py
+0
-0
test_flake8.py
theano/tests/test_flake8.py
+0
-1
unittest_tools.py
theano/tests/unittest_tools.py
+0
-4
没有找到文件。
doc/extending/unittest.txt
浏览文件 @
898d146d
...
@@ -333,12 +333,12 @@ type this:
...
@@ -333,12 +333,12 @@ type this:
Using Random Values in Test Cases
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
structures, for use as inputs to the function or module being
tested. When doing this, it is imperative that the random number
tested. When doing this, it is imperative that the random number
generator be seeded at the be beginning of each unit test. This will
generator be seeded at the be beginning of each unit test. This will
ensure that unittest behaviour is consistent from one execution to
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
Instead of using ``numpy.random.seed`` to do this, we encourage users to
do the following:
do the following:
...
@@ -350,39 +350,39 @@ do the following:
...
@@ -350,39 +350,39 @@ do the following:
class TestTensorDot(unittest.TestCase):
class TestTensorDot(unittest.TestCase):
def setUp(self):
def setUp(self):
unittest_tools.seed_rng()
unittest_tools.seed_rng()
# OR ... call with an explicit seed
# OR ... call with an explicit seed
unittest_tools.seed_rng(234234)
#
use only if really necessary!
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 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.
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
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
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
a higher confidence that the variables are correct), while still
making sure unittests are deterministic.
making sure unittests are deterministic.
Users who prefer their unittests to be random (when run on their local
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`).
: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::
.. testcode::
import numpy
import numpy
rng = numpy.random.RandomState(unittest_tools.fetch_seed())
rng = numpy.random.RandomState(unittest_tools.fetch_seed())
# OR providing an explicit 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,
Note that the ability to change the seed from one nosetest to another,
is incompatible with the method of hard-coding the baseline variables
is incompatible with the method of hard-coding the baseline variables
...
@@ -390,6 +390,11 @@ is incompatible with the method of hard-coding the baseline variables
...
@@ -390,6 +390,11 @@ is incompatible with the method of hard-coding the baseline variables
determined "algorithmically". Although this represents more work, the
determined "algorithmically". Although this represents more work, the
test suite will be better because of it.
test suite will be better because of it.
To help you check that the boundaries provided to ``numpy.random`` are
correct and your tests will pass those corner cases, you can check
``utt.MockRandomState``. Code using ``utt.MockRandomState`` should not
be committed, it is just a tool to help adjust the sampling range.
Creating an Op UnitTest
Creating an Op UnitTest
=======================
=======================
...
...
theano/tensor/tests/test_basic.py
浏览文件 @
898d146d
This source diff could not be displayed because it is too large. You can
view the blob
instead.
theano/tests/test_flake8.py
浏览文件 @
898d146d
...
@@ -51,7 +51,6 @@ whitelist_flake8 = [
...
@@ -51,7 +51,6 @@ whitelist_flake8 = [
"tensor/tests/test_misc.py"
,
"tensor/tests/test_misc.py"
,
"tensor/tests/mlp_test.py"
,
"tensor/tests/mlp_test.py"
,
"tensor/tests/test_opt_uncanonicalize.py"
,
"tensor/tests/test_opt_uncanonicalize.py"
,
"tensor/tests/test_basic.py"
,
"tensor/tests/test_blas.py"
,
"tensor/tests/test_blas.py"
,
"tensor/tests/test_merge.py"
,
"tensor/tests/test_merge.py"
,
"tensor/tests/test_gc.py"
,
"tensor/tests/test_gc.py"
,
...
...
theano/tests/unittest_tools.py
浏览文件 @
898d146d
...
@@ -120,10 +120,6 @@ class MockRandomState:
...
@@ -120,10 +120,6 @@ class MockRandomState:
return
out
+
minval
return
out
+
minval
else
:
else
:
return
out
+
maxval
-
1
return
out
+
maxval
-
1
# Examples of use:
# test_rng = MockRandomState(0)
# test_rng = MockRandomState(0.99999982)
# test_rng = MockRandomState(1)
class
TestOptimizationMixin
(
object
):
class
TestOptimizationMixin
(
object
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论