Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
f18d434a
提交
f18d434a
authored
11月 16, 2010
作者:
Frederic Bastien
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add test for Shared.set_value for tensor and cudandarray.
上级
f4e82d73
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
48 行增加
和
4 行删除
+48
-4
test_basic_ops.py
theano/sandbox/cuda/tests/test_basic_ops.py
+1
-1
test_basic.py
theano/tensor/tests/test_basic.py
+47
-3
没有找到文件。
theano/sandbox/cuda/tests/test_basic_ops.py
浏览文件 @
f18d434a
...
@@ -803,7 +803,7 @@ def test_duplicate_arg_elemwise():
...
@@ -803,7 +803,7 @@ def test_duplicate_arg_elemwise():
import
theano.tensor.tests.test_basic
import
theano.tensor.tests.test_basic
test_shared_options
=
theano
.
tensor
.
tests
.
test_basic
.
build_test_shared_options
(
tcn
.
shared_constructor
,
'float32'
,
False
,
False
,
cuda_ndarray
.
CudaNdarray
,
theano
.
tensor
.
exp
,
numpy
.
exp
)
test_shared_options
=
theano
.
tensor
.
tests
.
test_basic
.
build_test_shared_options
(
tcn
.
shared_constructor
,
'float32'
,
False
,
False
,
False
,
cuda_ndarray
.
CudaNdarray
,
theano
.
tensor
.
exp
,
numpy
.
exp
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
test_many_arg_elemwise
()
test_many_arg_elemwise
()
...
...
theano/tensor/tests/test_basic.py
浏览文件 @
f18d434a
...
@@ -3382,6 +3382,7 @@ def build_test_shared_options(shared_constructor_,
...
@@ -3382,6 +3382,7 @@ def build_test_shared_options(shared_constructor_,
dtype_
,
dtype_
,
get_value_borrow_true_alias_
,
get_value_borrow_true_alias_
,
shared_borrow_true_alias_
,
shared_borrow_true_alias_
,
set_value_borrow_true_alias_
,
internal_type_
,
internal_type_
,
theano_fct_
,
theano_fct_
,
ref_fct_
):
ref_fct_
):
...
@@ -3397,6 +3398,7 @@ def build_test_shared_options(shared_constructor_,
...
@@ -3397,6 +3398,7 @@ def build_test_shared_options(shared_constructor_,
internal_type
=
internal_type_
internal_type
=
internal_type_
theano_fct
=
staticmethod
(
theano_fct_
)
theano_fct
=
staticmethod
(
theano_fct_
)
ref_fct
=
staticmethod
(
ref_fct_
)
ref_fct
=
staticmethod
(
ref_fct_
)
set_value_borrow_true_alias
=
set_value_borrow_true_alias_
def
test_shared_dont_alias
(
self
):
def
test_shared_dont_alias
(
self
):
dtype
=
self
.
dtype
dtype
=
self
.
dtype
...
@@ -3444,8 +3446,6 @@ def build_test_shared_options(shared_constructor_,
...
@@ -3444,8 +3446,6 @@ def build_test_shared_options(shared_constructor_,
def
test_return_internal_type
(
self
):
def
test_return_internal_type
(
self
):
################ TODO test Out.
################ TODO test set_value!!!!
dtype
=
self
.
dtype
dtype
=
self
.
dtype
if
dtype
is
None
:
if
dtype
is
None
:
dtype
=
theano
.
config
.
floatX
dtype
=
theano
.
config
.
floatX
...
@@ -3479,6 +3479,50 @@ def build_test_shared_options(shared_constructor_,
...
@@ -3479,6 +3479,50 @@ def build_test_shared_options(shared_constructor_,
#this is required by the contract
#this is required by the contract
assert
not
numpy
.
allclose
(
self
.
ref_fct
(
x
),
total_func
())
assert
not
numpy
.
allclose
(
self
.
ref_fct
(
x
),
total_func
())
def
test_set_value
(
self
):
dtype
=
self
.
dtype
if
dtype
is
None
:
dtype
=
theano
.
config
.
floatX
rng
=
numpy
.
random
.
RandomState
([
3
,
5
,
17
])
x
=
numpy
.
asarray
(
rng
.
uniform
(
0
,
1
,[
2
,
4
]),
dtype
=
dtype
)
x_orig
=
x
x_orig_copy
=
x
.
copy
()
x_ref
=
self
.
ref_fct
(
x
)
x_shared
=
self
.
shared_constructor
(
x
,
borrow
=
False
)
total
=
self
.
theano_fct
(
x_shared
)
total_func
=
theano
.
function
([],
total
)
#test if that theano shared variable optimize set_value(borrow=True)
get_x
=
x_shared
.
get_value
(
borrow
=
True
)
assert
get_x
is
not
x_orig
#borrow=False to shared_constructor
get_x
+=
1
x_shared
.
set_value
(
get_x
,
borrow
=
True
)
x
=
x_shared
.
get_value
(
borrow
=
True
)
if
self
.
set_value_borrow_true_alias
:
assert
x
is
get_x
else
:
assert
x
is
not
get_x
assert
numpy
.
allclose
(
self
.
ref_fct
(
x_orig
+
1
),
self
.
ref_fct
(
x
))
#test optimized get set value on the gpu(don't pass data to the cpu)
get_x
=
x_shared
.
get_value
(
borrow
=
True
,
return_internal_type
=
True
)
assert
get_x
is
not
x_orig
#borrow=False to shared_constructor
assert
isinstance
(
get_x
,
self
.
internal_type
)
values_to_add
=
numpy
.
ones
(
x
.
shape
,
dtype
=
dtype
)
if
not
isinstance
(
values_to_add
,
self
.
internal_type
):
values_to_add
=
self
.
internal_type
(
values_to_add
)
#supported for cudandarray, but not ndarray.
assert
isinstance
(
values_to_add
,
self
.
internal_type
)
get_x
+=
values_to_add
#supported by ndarray and CudaNdarray
assert
isinstance
(
get_x
,
self
.
internal_type
)
x_shared
.
set_value
(
get_x
,
borrow
=
True
)
x
=
x_shared
.
get_value
(
borrow
=
True
,
return_internal_type
=
True
)
assert
isinstance
(
x
,
self
.
internal_type
)
assert
x
is
get_x
################ TODO test Out.
def
test_shared_do_alias
(
self
):
def
test_shared_do_alias
(
self
):
dtype
=
self
.
dtype
dtype
=
self
.
dtype
if
dtype
is
None
:
if
dtype
is
None
:
...
@@ -3509,7 +3553,7 @@ def build_test_shared_options(shared_constructor_,
...
@@ -3509,7 +3553,7 @@ def build_test_shared_options(shared_constructor_,
return
SharedTester
return
SharedTester
test_shared_options
=
build_test_shared_options
(
tensor
.
shared
,
'float64'
,
test_shared_options
=
build_test_shared_options
(
tensor
.
shared
,
'float64'
,
True
,
True
,
numpy
.
ndarray
,
True
,
True
,
True
,
numpy
.
ndarray
,
theano
.
tensor
.
sum
,
numpy
.
sum
)
theano
.
tensor
.
sum
,
numpy
.
sum
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论