Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
af0fbb52
提交
af0fbb52
authored
11月 15, 2010
作者:
Frederic Bastien
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactored TensorSharedVariable test of shared options to be able to reused them…
refactored TensorSharedVariable test of shared options to be able to reused them for CudaNdarrayShared.
上级
3949f88b
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
70 行增加
和
35 行删除
+70
-35
test_basic_ops.py
theano/sandbox/cuda/tests/test_basic_ops.py
+2
-0
test_basic.py
theano/tensor/tests/test_basic.py
+68
-35
没有找到文件。
theano/sandbox/cuda/tests/test_basic_ops.py
浏览文件 @
af0fbb52
...
...
@@ -802,6 +802,8 @@ def test_duplicate_arg_elemwise():
assert
numpy
.
allclose
(
Bval
,
f
(
Aval
))
import
theano.tensor.tests.test_basic
test_shared_options
=
theano
.
tensor
.
tests
.
test_basic
.
build_test_shared_options
(
tcn
.
shared_constructor
,
'float32'
,
False
,
False
)
if
__name__
==
'__main__'
:
test_many_arg_elemwise
()
...
...
theano/tensor/tests/test_basic.py
浏览文件 @
af0fbb52
...
...
@@ -3378,61 +3378,94 @@ def test_dimshuffle_duplicate():
assert
success
def
test_shared_dont_alias
():
rng
=
numpy
.
random
.
RandomState
([
3
,
5
,
17
])
x
=
rng
.
uniform
(
0
,
1
,[
2
,
4
])
x_shared
=
theano
.
shared
(
x
,
borrow
=
False
)
def
build_test_shared_options
(
shared_constructor_
,
dtype_
,
get_value_borrow_true_alias_
,
shared_borrow_true_alias_
):
"""
This is a generic fct to allow reusing the same test function
for many shared variable of many types.
"""
class
SharedTester
(
unittest
.
TestCase
):
shared_constructor
=
staticmethod
(
shared_constructor_
)
dtype
=
dtype_
get_value_borrow_true_alias
=
get_value_borrow_true_alias_
shared_borrow_true_alias
=
shared_borrow_true_alias_
def
test_shared_dont_alias
(
self
):
dtype
=
self
.
dtype
if
dtype
is
None
:
dtype
=
theano
.
config
.
floatX
total
=
theano
.
tensor
.
sum
(
x_shared
)
total_func
=
theano
.
function
([],
total
)
rng
=
numpy
.
random
.
RandomState
([
3
,
5
,
17
])
x
=
numpy
.
asarray
(
rng
.
uniform
(
0
,
1
,[
2
,
4
]),
dtype
=
dtype
)
x_sum
=
x
.
sum
()
x_shared
=
self
.
shared_constructor
(
x
,
borrow
=
False
)
total
=
theano
.
tensor
.
sum
(
x_shared
)
total_val
=
total_func
(
)
total_func
=
theano
.
function
([],
total
)
assert
numpy
.
allclose
(
x
.
sum
(),
total_val
)
total_val
=
total_func
(
)
x
+=
1
assert
numpy
.
allclose
(
x
.
sum
(),
total_val
)
total_val_2
=
total_func
()
x
+=
1
#value used to construct should not alias with internal
assert
total_val
==
total_val_2
total_val_2
=
total_func
()
x
=
x_shared
.
get_value
(
borrow
=
False
)
#value used to construct should not alias with internal
assert
total_val
==
total_val_2
x
+=
1
x
=
x_shared
.
get_value
(
borrow
=
False
)
total_val_3
=
total_func
()
x
+=
1
#value returned by access should not alias with internal
assert
total_val
==
total_val_3
total_val_3
=
total_func
()
#in this case we can alias
x
=
x_shared
.
get_value
(
borrow
=
True
)
x
+=
1
#value returned by access should not alias with internal
assert
total_val
==
total_val_3
#this is not required by the contract but it is a feature we've implemented
assert
numpy
.
allclose
(
x
.
sum
(),
total_func
())
#in this case we can alias
x
=
x_shared
.
get_value
(
borrow
=
True
)
x
+=
1
#this is not required by the contract but it is a feature we've
#implemented for some type of SharedVariable.
if
self
.
get_value_borrow_true_alias
:
assert
numpy
.
allclose
(
x
.
sum
(),
total_func
())
else
:
assert
numpy
.
allclose
(
x_sum
,
total_func
())
def
test_shared_do_alias
():
rng
=
numpy
.
random
.
RandomState
([
2
,
4
,
16
])
x
=
rng
.
uniform
(
1
,
2
,[
4
,
2
])
def
test_shared_do_alias
(
self
):
dtype
=
self
.
dtype
if
dtype
is
None
:
dtype
=
theano
.
config
.
floatX
x_shared
=
theano
.
shared
(
x
,
borrow
=
True
)
rng
=
numpy
.
random
.
RandomState
([
2
,
4
,
16
])
x
=
numpy
.
asarray
(
rng
.
uniform
(
1
,
2
,[
4
,
2
]),
dtype
=
dtype
)
x_sum
=
x
.
sum
()
total
=
theano
.
tensor
.
sum
(
x_shared
)
x_shared
=
self
.
shared_constructor
(
x
,
borrow
=
True
)
total_func
=
theano
.
function
([],
total
)
total
=
theano
.
tensor
.
sum
(
x_shared
)
total_val
=
total_func
(
)
total_func
=
theano
.
function
([],
total
)
assert
numpy
.
allclose
(
x
.
sum
(),
total_val
)
total_val
=
total_func
()
assert
numpy
.
allclose
(
x
.
sum
(),
total_val
)
x
+=
1
#not required by the contract but it is a feature we've implemented
if
self
.
shared_borrow_true_alias
:
assert
numpy
.
allclose
(
x
.
sum
(),
total_func
())
else
:
assert
numpy
.
allclose
(
x_sum
,
total_func
())
x
+=
1
return
SharedTester
#not required by the contract but it is a feature we've implemented
assert
numpy
.
allclose
(
x
.
sum
(),
total_func
())
test_shared_options
=
build_test_shared_options
(
tensor
.
shared
,
'float64'
,
True
,
True
)
if
__name__
==
'__main__'
:
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论