Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
19b0cf16
提交
19b0cf16
authored
11月 17, 2010
作者:
James Bergstra
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
added tests for the borrow argument on SharedRandomStream objects
上级
3a260ce2
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
80 行增加
和
1 行删除
+80
-1
test_shared_randomstreams.py
theano/tensor/tests/test_shared_randomstreams.py
+80
-1
没有找到文件。
theano/tensor/tests/test_shared_randomstreams.py
浏览文件 @
19b0cf16
...
@@ -6,7 +6,7 @@ import numpy
...
@@ -6,7 +6,7 @@ import numpy
from
theano.tensor
import
raw_random
from
theano.tensor
import
raw_random
from
theano.tensor.shared_randomstreams
import
RandomStreams
from
theano.tensor.shared_randomstreams
import
RandomStreams
from
theano
import
function
from
theano
import
function
,
shared
from
theano
import
tensor
from
theano
import
tensor
from
theano
import
compile
,
config
,
gof
from
theano
import
compile
,
config
,
gof
...
@@ -611,6 +611,85 @@ class T_SharedRandomStreams(unittest.TestCase):
...
@@ -611,6 +611,85 @@ class T_SharedRandomStreams(unittest.TestCase):
assert
numpy
.
all
(
abs
(
val1
)
<=
1
)
assert
numpy
.
all
(
abs
(
val1
)
<=
1
)
def
test_shared_constructor_borrow
(
self
):
rng
=
numpy
.
random
.
RandomState
(
123
)
s_rng_default
=
shared
(
rng
)
s_rng_True
=
shared
(
rng
,
borrow
=
True
)
s_rng_False
=
shared
(
rng
,
borrow
=
False
)
# test borrow contract: that False means a copy must have been made
assert
s_rng_default
.
container
.
storage
[
0
]
is
not
rng
assert
s_rng_False
.
container
.
storage
[
0
]
is
not
rng
# test current implementation: that True means a copy was not made
assert
s_rng_True
.
container
.
storage
[
0
]
is
rng
# ensure that all the random number generators are in the same state
v
=
rng
.
randn
()
v0
=
s_rng_default
.
container
.
storage
[
0
]
.
randn
()
v1
=
s_rng_False
.
container
.
storage
[
0
]
.
randn
()
assert
v
==
v0
==
v1
def
test_get_value_borrow
(
self
):
rng
=
numpy
.
random
.
RandomState
(
123
)
s_rng
=
shared
(
rng
)
r_
=
s_rng
.
container
.
storage
[
0
]
r_T
=
s_rng
.
get_value
(
borrow
=
True
)
r_F
=
s_rng
.
get_value
(
borrow
=
False
)
#the contract requires that borrow=False returns a copy
assert
r_
is
not
r_F
# the current implementation allows for True to return the real thing
assert
r_
is
r_T
#either way, the rngs should all be in the same state
assert
r_
.
rand
()
==
r_F
.
rand
()
def
test_get_value_internal_type
(
self
):
rng
=
numpy
.
random
.
RandomState
(
123
)
s_rng
=
shared
(
rng
)
# there is no special behaviour required of return_internal_type
# this test just ensures that the flag doesn't screw anything up
# by repeating the get_value_borrow test.
r_
=
s_rng
.
container
.
storage
[
0
]
r_T
=
s_rng
.
get_value
(
borrow
=
True
,
return_internal_type
=
True
)
r_F
=
s_rng
.
get_value
(
borrow
=
False
,
return_internal_type
=
True
)
#the contract requires that borrow=False returns a copy
assert
r_
is
not
r_F
# the current implementation allows for True to return the real thing
assert
r_
is
r_T
#either way, the rngs should all be in the same state
assert
r_
.
rand
()
==
r_F
.
rand
()
def
test_set_value_borrow
(
self
):
rng
=
numpy
.
random
.
RandomState
(
123
)
s_rng
=
shared
(
rng
)
new_rng
=
numpy
.
random
.
RandomState
(
234234
)
# Test the borrow contract is respected:
# assigning with borrow=False makes a copy
s_rng
.
set_value
(
new_rng
,
borrow
=
False
)
assert
new_rng
is
not
s_rng
.
container
.
storage
[
0
]
assert
new_rng
.
randn
()
==
s_rng
.
container
.
storage
[
0
]
.
randn
()
# Test that the current implementation is actually borrowing when it can.
rr
=
numpy
.
random
.
RandomState
(
33
)
s_rng
.
set_value
(
rr
,
borrow
=
True
)
assert
rr
is
s_rng
.
container
.
storage
[
0
]
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
from
theano.tests
import
main
from
theano.tests
import
main
main
(
"test_shared_randomstreams"
)
main
(
"test_shared_randomstreams"
)
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论