Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
7a021c47
提交
7a021c47
authored
8月 31, 2012
作者:
lamblin
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #900 from nouiz/small
Small
上级
ce0a8359
31fe4c29
隐藏空白字符变更
内嵌
并排
正在显示
8 个修改的文件
包含
51 行增加
和
52 行删除
+51
-52
unittest.txt
doc/extending/unittest.txt
+2
-0
extending_theano.txt
doc/tutorial/extending_theano.txt
+6
-14
check_whitespace.py
theano/misc/hooks/check_whitespace.py
+4
-0
test_scan.py
theano/scan_module/tests/test_scan.py
+1
-3
test_basic.py
theano/tensor/tests/test_basic.py
+1
-1
test_inc_subtensor.py
theano/tensor/tests/test_inc_subtensor.py
+36
-33
test_opt.py
theano/tensor/tests/test_opt.py
+0
-1
test_rop.py
theano/tests/test_rop.py
+1
-0
没有找到文件。
doc/extending/unittest.txt
浏览文件 @
7a021c47
...
...
@@ -308,6 +308,8 @@ type this:
THEANO_FLAGS='mode=FAST_RUN' nosetests
THEANO_FLAGS='mode=DEBUG_MODE' nosetests
.. _random_value_in_tests:
Using Random Values in Test Cases
---------------------------------
...
...
doc/tutorial/extending_theano.txt
浏览文件 @
7a021c47
...
...
@@ -350,24 +350,16 @@ Here is some code that allow to make the op Optional:
Random number in tests
----------------------
Making test errors more reproducable is a good practice. To make your
Making test
s
errors more reproducable is a good practice. To make your
tests more reproducable, you need a way to get the same random
number. You can do this by seeding NumPy's randon number
generator. There is the Theano flag unittest.rseed that specify the
seed that should be used to init random number generators. There is 2
ways to do this it numpy, here is one:
generator.
.. code-block:: python
# You can set NumPy's internal random number generator state with
numpy.random.seed(utt.fetch_seed())
# All following call to numpy.random.*() function will get affected.
# Or you can create a new RandomState separate from the others
rng = numpy.random.RandomState(utt.fetch_seed())
# You can call all numpy's random number generator function's on rng
rng.rand(5, 5)
For conveniance, the classes InferShapeTester and RopLop_checker
already do this for you. If you implement your own ``setUp`` function,
don't forget to call the parent ``setUp`` function.
For more details see :ref:`random_value_in_tests`.
GPU Op
------
...
...
theano/misc/hooks/check_whitespace.py
浏览文件 @
7a021c47
...
...
@@ -86,6 +86,10 @@ def run_mercurial_command(hg_command):
hg_executable
=
os
.
environ
.
get
(
"HG"
,
"hg"
)
hg_command_tuple
=
hg_command
.
split
()
hg_command_tuple
.
insert
(
0
,
hg_executable
)
#If you install your own mercurial version in your home
#hg_executable don't always have execution permission.
if
not
os
.
access
(
hg_executable
,
os
.
X_OK
):
hg_command_tuple
.
insert
(
0
,
sys
.
executable
)
try
:
hg_subprocess
=
Popen
(
hg_command_tuple
,
stdout
=
PIPE
,
stderr
=
PIPE
)
except
OSError
,
e
:
...
...
theano/scan_module/tests/test_scan.py
浏览文件 @
7a021c47
...
...
@@ -15,6 +15,7 @@ from theano import tensor
from
theano.compile.pfunc
import
rebuild_collect_shared
from
theano.gof.python25
import
any
from
theano.tests
import
unittest_tools
as
utt
import
theano.scalar.sharedvar
from
numpy.testing.noseclasses
import
KnownFailureTest
...
...
@@ -1121,7 +1122,6 @@ class T_Scan(unittest.TestCase):
v_vsample
=
numpy
.
array
(
rng
.
binomial
(
1
,
.
5
,
size
=
(
3
,
20
),),
dtype
=
'float32'
)
vsample
=
theano
.
shared
(
v_vsample
)
import
theano.sandbox.rng_mrg
trng
=
theano
.
sandbox
.
rng_mrg
.
MRG_RandomStreams
(
utt
.
fetch_seed
())
...
...
@@ -3217,7 +3217,6 @@ def test_speed_rnn():
# The computation being tested here is a repeated tanh of a matrix-vector
# multiplication - the heart of an ESN or RNN.
#
import
theano.scalar.sharedvar
#We need the CVM for this speed test
if
not
theano
.
config
.
cxx
:
...
...
@@ -3297,7 +3296,6 @@ def test_speed_batchrnn():
# The computation being tested here is a repeated tanh of a matrix-vector
# multiplication - the heart of an ESN or RNN.
#
import
theano.scalar.sharedvar
#We need the CVM for this speed test
if
not
theano
.
config
.
cxx
:
...
...
theano/tensor/tests/test_basic.py
浏览文件 @
7a021c47
...
...
@@ -1397,7 +1397,7 @@ _good_broadcast_unary_gammaln = dict(
normal
=
(
rand_ranged
(
-
1
+
1e-2
,
10
,
(
2
,
3
)),),
empty
=
(
numpy
.
asarray
([]),),)
_grad_broadcast_unary_gammaln
=
dict
(
# smaler range as our grad method don't estimate it good enough.
# smal
l
er range as our grad method don't estimate it good enough.
normal
=
(
rand_ranged
(
1e-8
,
8
,
(
2
,
3
)),),)
GammaTester
=
makeBroadcastTester
(
...
...
theano/tensor/tests/test_inc_subtensor.py
浏览文件 @
7a021c47
...
...
@@ -2,7 +2,8 @@ import numpy
import
unittest
from
theano.tests
import
unittest_tools
as
utt
import
theano
import
theano.tensor
as
T
import
theano.tensor
as
tt
class
Test_inc_subtensor
(
unittest
.
TestCase
):
"""Partial testing.
...
...
@@ -14,8 +15,10 @@ class Test_inc_subtensor(unittest.TestCase):
- indices: scalar vs slice, constant vs variable, out of bound, ...
- inplace
NOTE: these are the same tests as test_incsubtensor.py, but using the new (read: not
deprecated) inc_subtensor, set_subtensor functions.
NOTE: these are the same tests as test_incsubtensor.py, but using
the new (read: not deprecated) inc_subtensor, set_subtensor
functions.
"""
def
setUp
(
self
):
utt
.
seed_rng
()
...
...
@@ -24,22 +27,22 @@ class Test_inc_subtensor(unittest.TestCase):
"""Increments or sets part of a tensor by a scalar using full slice and
a partial slice depending on a scalar.
"""
a
=
T
.
dmatrix
()
increment
=
T
.
dscalar
()
a
=
tt
.
dmatrix
()
increment
=
tt
.
dscalar
()
sl1
=
slice
(
None
)
sl2_end
=
T
.
lscalar
()
sl2_end
=
tt
.
lscalar
()
sl2
=
slice
(
sl2_end
)
for
do_set
in
[
False
,
True
]:
for
do_set
in
[
False
,
True
]:
if
do_set
:
resut
=
T
.
set_subtensor
(
a
[
sl1
,
sl2
],
increment
)
resut
=
tt
.
set_subtensor
(
a
[
sl1
,
sl2
],
increment
)
else
:
resut
=
T
.
inc_subtensor
(
a
[
sl1
,
sl2
],
increment
)
resut
=
tt
.
inc_subtensor
(
a
[
sl1
,
sl2
],
increment
)
f
=
theano
.
function
([
a
,
increment
,
sl2_end
],
resut
)
val_a
=
numpy
.
ones
((
5
,
5
))
val_a
=
numpy
.
ones
((
5
,
5
))
val_inc
=
2.3
val_sl2_end
=
2
...
...
@@ -47,9 +50,9 @@ class Test_inc_subtensor(unittest.TestCase):
expected_result
=
numpy
.
copy
(
val_a
)
if
do_set
:
expected_result
[:,:
val_sl2_end
]
=
val_inc
expected_result
[:,
:
val_sl2_end
]
=
val_inc
else
:
expected_result
[:,:
val_sl2_end
]
+=
val_inc
expected_result
[:,
:
val_sl2_end
]
+=
val_inc
self
.
assertTrue
(
numpy
.
array_equal
(
result
,
expected_result
))
...
...
@@ -57,24 +60,24 @@ class Test_inc_subtensor(unittest.TestCase):
"""Increments or sets part of a tensor by a scalar using full slice and
a partial slice depending on a scalar.
"""
a
=
T
.
dtensor3
()
increment
=
T
.
dscalar
()
a
=
tt
.
dtensor3
()
increment
=
tt
.
dscalar
()
sl1
=
slice
(
None
)
sl2_end
=
T
.
lscalar
()
sl2_end
=
tt
.
lscalar
()
sl2
=
slice
(
sl2_end
)
sl3
=
2
for
do_set
in
[
True
,
False
]:
for
do_set
in
[
True
,
False
]:
print
"Set"
,
do_set
if
do_set
:
resut
=
T
.
set_subtensor
(
a
[
sl1
,
sl3
,
sl2
],
increment
)
resut
=
tt
.
set_subtensor
(
a
[
sl1
,
sl3
,
sl2
],
increment
)
else
:
resut
=
T
.
inc_subtensor
(
a
[
sl1
,
sl3
,
sl2
],
increment
)
resut
=
tt
.
inc_subtensor
(
a
[
sl1
,
sl3
,
sl2
],
increment
)
f
=
theano
.
function
([
a
,
increment
,
sl2_end
],
resut
)
val_a
=
numpy
.
ones
((
5
,
3
,
4
))
val_a
=
numpy
.
ones
((
5
,
3
,
4
))
val_inc
=
2.3
val_sl2_end
=
2
...
...
@@ -82,39 +85,39 @@ class Test_inc_subtensor(unittest.TestCase):
result
=
f
(
val_a
,
val_inc
,
val_sl2_end
)
if
do_set
:
expected_result
[:,
sl3
,
:
val_sl2_end
]
=
val_inc
expected_result
[:,
sl3
,
:
val_sl2_end
]
=
val_inc
else
:
expected_result
[:,
sl3
,
:
val_sl2_end
]
+=
val_inc
expected_result
[:,
sl3
,
:
val_sl2_end
]
+=
val_inc
self
.
assertTrue
(
numpy
.
array_equal
(
result
,
expected_result
))
def
test_grad_inc_set
(
self
):
def
inc_slice
(
*
s
):
def
just_numeric_args
(
a
,
b
):
return
T
.
inc_subtensor
(
a
[
s
],
b
)
def
just_numeric_args
(
a
,
b
):
return
tt
.
inc_subtensor
(
a
[
s
],
b
)
return
just_numeric_args
def
set_slice
(
*
s
):
def
just_numeric_args
(
a
,
b
):
return
T
.
set_subtensor
(
a
[
s
],
b
)
def
just_numeric_args
(
a
,
b
):
return
tt
.
set_subtensor
(
a
[
s
],
b
)
return
just_numeric_args
for
f_slice
in
[
inc_slice
,
set_slice
]:
# vector
utt
.
verify_grad
(
f_slice
(
slice
(
2
,
4
,
None
)),
(
numpy
.
asarray
([
0
,
1
,
2
,
3
,
4
,
5.
]),
numpy
.
asarray
([
9
,
9.
]),
))
f_slice
(
slice
(
2
,
4
,
None
)),
(
numpy
.
asarray
([
0
,
1
,
2
,
3
,
4
,
5.
]),
numpy
.
asarray
([
9
,
9.
]),
))
# matrix
utt
.
verify_grad
(
f_slice
(
slice
(
1
,
2
,
None
),
slice
(
None
,
None
,
None
)),
(
numpy
.
asarray
([[
0
,
1
],[
2
,
3
],[
4
,
5.
]]),
numpy
.
asarray
([[
9
,
9.
]]),
))
f_slice
(
slice
(
1
,
2
,
None
),
slice
(
None
,
None
,
None
)),
(
numpy
.
asarray
([[
0
,
1
],
[
2
,
3
],
[
4
,
5.
]]),
numpy
.
asarray
([[
9
,
9.
]]),
))
#single element
utt
.
verify_grad
(
f_slice
(
2
,
1
),
(
numpy
.
asarray
([[
0
,
1
],[
2
,
3
],[
4
,
5.
]]),
(
numpy
.
asarray
([[
0
,
1
],
[
2
,
3
],
[
4
,
5.
]]),
numpy
.
asarray
(
9.
),))
theano/tensor/tests/test_opt.py
浏览文件 @
7a021c47
...
...
@@ -3781,4 +3781,3 @@ if __name__ == '__main__':
# unittest.main()
test_fusion().tes_memory_leak()
"""
theano/tests/test_rop.py
浏览文件 @
7a021c47
...
...
@@ -58,6 +58,7 @@ class RopLop_checker(unittest.TestCase):
Rop to class that inherit from it."""
def
setUp
(
self
):
utt
.
seed_rng
()
# Using vectors make things a lot simpler for generating the same
# computations using scan
self
.
x
=
tensor
.
vector
(
'x'
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论