Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
2b66049f
提交
2b66049f
authored
12月 21, 2010
作者:
Frederic Bastien
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Test for cuda shared variable that set_value work inplace.
For tensor and sparse shared varible, test that we don't work inplace.(not implemented for now)
上级
23aa7ddc
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
47 行增加
和
0 行删除
+47
-0
test_basic_ops.py
theano/sandbox/cuda/tests/test_basic_ops.py
+1
-0
test_basic.py
theano/sparse/tests/test_basic.py
+1
-0
test_sharedvar.py
theano/tensor/tests/test_sharedvar.py
+45
-0
没有找到文件。
theano/sandbox/cuda/tests/test_basic_ops.py
浏览文件 @
2b66049f
...
...
@@ -827,6 +827,7 @@ test_shared_options = theano.tensor.tests.test_sharedvar.makeSharedTester(
get_value_borrow_true_alias_
=
False
,
shared_borrow_true_alias_
=
False
,
set_value_borrow_true_alias_
=
False
,
set_value_inplace_
=
True
,
internal_type_
=
cuda_ndarray
.
CudaNdarray
,
test_internal_type_
=
lambda
a
:
isinstance
(
a
,
cuda_ndarray
.
CudaNdarray
),
theano_fct_
=
theano
.
tensor
.
exp
,
...
...
theano/sparse/tests/test_basic.py
浏览文件 @
2b66049f
...
...
@@ -506,6 +506,7 @@ test_shared_options=theano.tensor.tests.test_sharedvar.makeSharedTester(
get_value_borrow_true_alias_
=
True
,
shared_borrow_true_alias_
=
True
,
set_value_borrow_true_alias_
=
True
,
set_value_inplace_
=
False
,
internal_type_
=
scipy
.
sparse
.
csc_matrix
,
test_internal_type_
=
scipy
.
sparse
.
issparse
,
theano_fct_
=
lambda
a
:
dense_from_sparse
(
a
*
2.
),
...
...
theano/tensor/tests/test_sharedvar.py
浏览文件 @
2b66049f
...
...
@@ -4,6 +4,7 @@ import unittest
import
theano
from
theano
import
tensor
from
theano.tests
import
unittest_tools
as
utt
from
theano.misc.may_share_memory
import
may_share_memory
utt
.
seed_rng
()
...
...
@@ -12,6 +13,7 @@ def makeSharedTester(shared_constructor_,
get_value_borrow_true_alias_
,
shared_borrow_true_alias_
,
set_value_borrow_true_alias_
,
set_value_inplace_
,
internal_type_
,
test_internal_type_
,
theano_fct_
,
...
...
@@ -34,6 +36,7 @@ def makeSharedTester(shared_constructor_,
theano_fct
=
staticmethod
(
theano_fct_
)
ref_fct
=
staticmethod
(
ref_fct_
)
set_value_borrow_true_alias
=
set_value_borrow_true_alias_
set_value_inplace
=
set_value_inplace_
cast_value
=
staticmethod
(
cast_value_
)
op_by_matrix
=
op_by_matrix_
...
...
@@ -239,6 +242,47 @@ def makeSharedTester(shared_constructor_,
else
:
assert
numpy
.
allclose
(
x_ref
,
total_func
())
def
test_inplace_shared
(
self
):
dtype
=
self
.
dtype
if
dtype
is
None
:
dtype
=
theano
.
config
.
floatX
shp
=
(
100
/
4
,
1024
)
#100KB
x
=
numpy
.
zeros
(
shp
,
dtype
=
'float32'
)
x
=
self
.
cast_value
(
x
)
x_shared
=
self
.
shared_constructor
(
x
,
borrow
=
True
)
old_data
=
x_shared
.
container
.
storage
[
0
]
nd
=
numpy
.
ones
(
shp
,
dtype
=
'float32'
)
if
x
.
__class__
.
__name__
!=
'csr_matrix'
:
#sparse matrix don't support inplace affectation
x_shared
.
container
.
value
[:]
=
nd
assert
(
numpy
.
asarray
(
x_shared
.
value
)
==
nd
)
.
all
()
#This should always share value!
assert
may_share_memory
(
old_data
,
x_shared
.
container
.
storage
[
0
])
assert
may_share_memory
(
old_data
,
x_shared
.
get_value
(
borrow
=
True
,
return_internal_type
=
True
))
if
x
.
__class__
.
__name__
!=
'csr_matrix'
:
#sparse matrix don't support inplace affectation
nd
+=
1
#THIS DON't DO WHAT WE EXPECT the contain of a is not updated!
x_shared
.
value
[:]
=
nd
#assert (numpy.asarray(a.value)!=nd).all()
assert
may_share_memory
(
old_data
,
x_shared
.
container
.
storage
[
0
])
x_shared
.
value
nd
+=
1
x_shared
.
value
=
nd
assert
numpy
.
allclose
(
self
.
ref_fct
(
x_shared
.
value
),
self
.
ref_fct
(
self
.
cast_value
(
nd
)))
assert
may_share_memory
(
old_data
,
x_shared
.
container
.
storage
[
0
])
==
self
.
set_value_inplace
nd
+=
1
x_shared
.
set_value
(
nd
,
borrow
=
False
)
assert
numpy
.
allclose
(
self
.
ref_fct
(
x_shared
.
value
),
self
.
ref_fct
(
self
.
cast_value
(
nd
)))
assert
may_share_memory
(
old_data
,
x_shared
.
container
.
storage
[
0
])
==
self
.
set_value_inplace
def
test_specify_shape
(
self
):
dtype
=
self
.
dtype
if
dtype
is
None
:
...
...
@@ -415,6 +459,7 @@ test_shared_options=makeSharedTester(
get_value_borrow_true_alias_
=
True
,
shared_borrow_true_alias_
=
True
,
set_value_borrow_true_alias_
=
True
,
set_value_inplace_
=
False
,
internal_type_
=
numpy
.
ndarray
,
test_internal_type_
=
lambda
a
:
isinstance
(
a
,
numpy
.
ndarray
),
theano_fct_
=
theano
.
tensor
.
sum
,
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论