Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
dc6de565
提交
dc6de565
authored
11月 22, 2010
作者:
Frederic Bastien
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
moved test about shared variable to its own file.
上级
75c11ac0
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
206 行增加
和
200 行删除
+206
-200
test_basic_ops.py
theano/sandbox/cuda/tests/test_basic_ops.py
+2
-2
test_basic.py
theano/sparse/tests/test_basic.py
+2
-2
test_basic.py
theano/tensor/tests/test_basic.py
+0
-196
test_sharedvar.py
theano/tensor/tests/test_sharedvar.py
+202
-0
没有找到文件。
theano/sandbox/cuda/tests/test_basic_ops.py
浏览文件 @
dc6de565
...
@@ -812,8 +812,8 @@ def test_shared_float32():
...
@@ -812,8 +812,8 @@ def test_shared_float32():
del
theano
.
shared
.
constructors
[
-
1
]
del
theano
.
shared
.
constructors
[
-
1
]
import
theano.tensor.tests.test_
basic
import
theano.tensor.tests.test_
sharedvar
test_shared_options
=
theano
.
tensor
.
tests
.
test_
basic
.
makeSharedTester
(
test_shared_options
=
theano
.
tensor
.
tests
.
test_
sharedvar
.
makeSharedTester
(
tcn
.
shared_constructor
,
'float32'
,
False
,
False
,
False
,
tcn
.
shared_constructor
,
'float32'
,
False
,
False
,
False
,
cuda_ndarray
.
CudaNdarray
,
cuda_ndarray
.
CudaNdarray
,
lambda
a
:
isinstance
(
a
,
cuda_ndarray
.
CudaNdarray
),
lambda
a
:
isinstance
(
a
,
cuda_ndarray
.
CudaNdarray
),
...
...
theano/sparse/tests/test_basic.py
浏览文件 @
dc6de565
...
@@ -441,8 +441,8 @@ class test_structureddot(unittest.TestCase):
...
@@ -441,8 +441,8 @@ class test_structureddot(unittest.TestCase):
self
.
failUnless
(
numpy
.
allclose
(
theano_result
,
scipy_result
))
self
.
failUnless
(
numpy
.
allclose
(
theano_result
,
scipy_result
))
self
.
failIf
(
theano_time
>
overhead_rtol
*
scipy_time
+
overhead_tol
)
self
.
failIf
(
theano_time
>
overhead_rtol
*
scipy_time
+
overhead_tol
)
import
theano.tensor.tests.test_
basic
import
theano.tensor.tests.test_
sharedvar
test_shared_options
=
theano
.
tensor
.
tests
.
test_
basic
.
makeSharedTester
(
test_shared_options
=
theano
.
tensor
.
tests
.
test_
sharedvar
.
makeSharedTester
(
theano
.
sparse
.
shared
,
'float64'
,
theano
.
sparse
.
shared
,
'float64'
,
True
,
True
,
True
,
scipy
.
sparse
.
csc_matrix
,
scipy
.
sparse
.
issparse
,
True
,
True
,
True
,
scipy
.
sparse
.
csc_matrix
,
scipy
.
sparse
.
issparse
,
lambda
a
:
dense_from_sparse
(
a
*
2.
),
lambda
a
:
dense_from_sparse
(
a
*
2.
),
...
...
theano/tensor/tests/test_basic.py
浏览文件 @
dc6de565
...
@@ -3440,202 +3440,6 @@ def test_dimshuffle_duplicate():
...
@@ -3440,202 +3440,6 @@ def test_dimshuffle_duplicate():
assert
success
assert
success
def
makeSharedTester
(
shared_constructor_
,
dtype_
,
get_value_borrow_true_alias_
,
shared_borrow_true_alias_
,
set_value_borrow_true_alias_
,
internal_type_
,
test_internal_type_
,
theano_fct_
,
ref_fct_
,
cast_value_
=
numpy
.
asarray
,
add_matrix_
=
False
):
"""
This is a generic fct to allow reusing the same test function
for many shared variable of many types.
We must use /= as sparse type don't support other inplace operation.
"""
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_
internal_type
=
internal_type_
test_internal_type
=
staticmethod
(
test_internal_type_
)
theano_fct
=
staticmethod
(
theano_fct_
)
ref_fct
=
staticmethod
(
ref_fct_
)
set_value_borrow_true_alias
=
set_value_borrow_true_alias_
cast_value
=
staticmethod
(
cast_value_
)
add_matrix
=
add_matrix_
def
test_shared_dont_alias
(
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
=
self
.
cast_value
(
x
)
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
)
total_val
=
total_func
()
assert
numpy
.
allclose
(
self
.
ref_fct
(
x
),
total_val
)
x
/=
.
5
total_val_2
=
total_func
()
#value used to construct should not alias with internal
assert
numpy
.
allclose
(
total_val
,
total_val_2
)
x
=
x_shared
.
get_value
(
borrow
=
False
)
x
/=
.
5
total_val_3
=
total_func
()
#value returned by access should not alias with internal
assert
numpy
.
allclose
(
total_val
,
total_val_3
)
#in this case we can alias
x
=
x_shared
.
get_value
(
borrow
=
True
)
x
/=
.
5
#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
(
self
.
ref_fct
(
x
),
total_func
())
else
:
assert
numpy
.
allclose
(
x_ref
,
total_func
())
def
test_return_internal_type
(
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
=
self
.
cast_value
(
x
)
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
)
#in this case we can alias with the internal value
x
=
x_shared
.
get_value
(
borrow
=
True
,
return_internal_type
=
True
)
assert
self
.
test_internal_type
(
x
)
values_to_add
=
.
5
if
self
.
add_matrix
:
values_to_add
=
self
.
internal_type
(
numpy
.
ones
(
x
.
shape
,
dtype
=
dtype
)
/
2
)
#supported for cudandarray, but not ndarray.
x
/=
values_to_add
#supported by ndarray and CudaNdarray
#this is not required by the contract but it is a feature we can
#implement for some type of SharedVariable.
assert
numpy
.
allclose
(
self
.
ref_fct
(
x
),
total_func
())
x
=
x_shared
.
get_value
(
borrow
=
False
,
return_internal_type
=
True
)
assert
self
.
test_internal_type
(
x
)
assert
x
is
not
x_shared
.
container
.
value
x
/=
values_to_add
#supported by ndarray and CudaNdarray
#this is required by the contract
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
=
self
.
cast_value
(
x
)
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
/=
.
5
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
/.
5
),
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
self
.
test_internal_type
(
get_x
)
values_to_add
=
.
5
if
self
.
add_matrix
:
values_to_add
=
self
.
internal_type
(
numpy
.
ones
(
x
.
shape
,
dtype
=
dtype
)
/
2
)
#supported for cudandarray, but not ndarray.
assert
self
.
test_internal_type
(
values_to_add
)
get_x
/=
values_to_add
#supported by ndarray and CudaNdarray
assert
self
.
test_internal_type
(
get_x
)
x_shared
.
set_value
(
get_x
,
borrow
=
True
)
x
=
x_shared
.
get_value
(
borrow
=
True
,
return_internal_type
=
True
)
assert
self
.
test_internal_type
(
x
)
assert
x
is
get_x
################ TODO test Out.
def
test_shared_do_alias
(
self
):
dtype
=
self
.
dtype
if
dtype
is
None
:
dtype
=
theano
.
config
.
floatX
rng
=
numpy
.
random
.
RandomState
([
2
,
4
,
16
])
x
=
numpy
.
asarray
(
rng
.
uniform
(
1
,
2
,[
4
,
2
]),
dtype
=
dtype
)
x
=
self
.
cast_value
(
x
)
x_ref
=
self
.
ref_fct
(
x
)
x_shared
=
self
.
shared_constructor
(
x
,
borrow
=
True
)
total
=
self
.
theano_fct
(
x_shared
)
total_func
=
theano
.
function
([],
total
)
total_val
=
total_func
()
assert
numpy
.
allclose
(
self
.
ref_fct
(
x
),
total_val
)
x
/=
.
5
#not required by the contract but it is a feature we've implemented
if
self
.
shared_borrow_true_alias
:
assert
numpy
.
allclose
(
self
.
ref_fct
(
x
),
total_func
())
else
:
assert
numpy
.
allclose
(
x_ref
,
total_func
())
return
SharedTester
test_shared_options
=
makeSharedTester
(
tensor
.
shared
,
'float64'
,
True
,
True
,
True
,
numpy
.
ndarray
,
lambda
a
:
isinstance
(
a
,
numpy
.
ndarray
),
theano
.
tensor
.
sum
,
numpy
.
sum
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
if
1
:
if
1
:
unittest
.
main
()
unittest
.
main
()
...
...
theano/tensor/tests/test_sharedvar.py
0 → 100644
浏览文件 @
dc6de565
import
numpy
import
unittest
import
theano
from
theano
import
tensor
def
makeSharedTester
(
shared_constructor_
,
dtype_
,
get_value_borrow_true_alias_
,
shared_borrow_true_alias_
,
set_value_borrow_true_alias_
,
internal_type_
,
test_internal_type_
,
theano_fct_
,
ref_fct_
,
cast_value_
=
numpy
.
asarray
,
add_matrix_
=
False
):
"""
This is a generic fct to allow reusing the same test function
for many shared variable of many types.
We must use /= as sparse type don't support other inplace operation.
"""
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_
internal_type
=
internal_type_
test_internal_type
=
staticmethod
(
test_internal_type_
)
theano_fct
=
staticmethod
(
theano_fct_
)
ref_fct
=
staticmethod
(
ref_fct_
)
set_value_borrow_true_alias
=
set_value_borrow_true_alias_
cast_value
=
staticmethod
(
cast_value_
)
add_matrix
=
add_matrix_
def
test_shared_dont_alias
(
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
=
self
.
cast_value
(
x
)
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
)
total_val
=
total_func
()
assert
numpy
.
allclose
(
self
.
ref_fct
(
x
),
total_val
)
x
/=
.
5
total_val_2
=
total_func
()
#value used to construct should not alias with internal
assert
numpy
.
allclose
(
total_val
,
total_val_2
)
x
=
x_shared
.
get_value
(
borrow
=
False
)
x
/=
.
5
total_val_3
=
total_func
()
#value returned by access should not alias with internal
assert
numpy
.
allclose
(
total_val
,
total_val_3
)
#in this case we can alias
x
=
x_shared
.
get_value
(
borrow
=
True
)
x
/=
.
5
#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
(
self
.
ref_fct
(
x
),
total_func
())
else
:
assert
numpy
.
allclose
(
x_ref
,
total_func
())
def
test_return_internal_type
(
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
=
self
.
cast_value
(
x
)
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
)
#in this case we can alias with the internal value
x
=
x_shared
.
get_value
(
borrow
=
True
,
return_internal_type
=
True
)
assert
self
.
test_internal_type
(
x
)
values_to_add
=
.
5
if
self
.
add_matrix
:
values_to_add
=
self
.
internal_type
(
numpy
.
ones
(
x
.
shape
,
dtype
=
dtype
)
/
2
)
#supported for cudandarray, but not ndarray.
x
/=
values_to_add
#supported by ndarray and CudaNdarray
#this is not required by the contract but it is a feature we can
#implement for some type of SharedVariable.
assert
numpy
.
allclose
(
self
.
ref_fct
(
x
),
total_func
())
x
=
x_shared
.
get_value
(
borrow
=
False
,
return_internal_type
=
True
)
assert
self
.
test_internal_type
(
x
)
assert
x
is
not
x_shared
.
container
.
value
x
/=
values_to_add
#supported by ndarray and CudaNdarray
#this is required by the contract
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
=
self
.
cast_value
(
x
)
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
/=
.
5
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
/.
5
),
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
self
.
test_internal_type
(
get_x
)
values_to_add
=
.
5
if
self
.
add_matrix
:
values_to_add
=
self
.
internal_type
(
numpy
.
ones
(
x
.
shape
,
dtype
=
dtype
)
/
2
)
#supported for cudandarray, but not ndarray.
assert
self
.
test_internal_type
(
values_to_add
)
get_x
/=
values_to_add
#supported by ndarray and CudaNdarray
assert
self
.
test_internal_type
(
get_x
)
x_shared
.
set_value
(
get_x
,
borrow
=
True
)
x
=
x_shared
.
get_value
(
borrow
=
True
,
return_internal_type
=
True
)
assert
self
.
test_internal_type
(
x
)
assert
x
is
get_x
################ TODO test Out.
def
test_shared_do_alias
(
self
):
dtype
=
self
.
dtype
if
dtype
is
None
:
dtype
=
theano
.
config
.
floatX
rng
=
numpy
.
random
.
RandomState
([
2
,
4
,
16
])
x
=
numpy
.
asarray
(
rng
.
uniform
(
1
,
2
,[
4
,
2
]),
dtype
=
dtype
)
x
=
self
.
cast_value
(
x
)
x_ref
=
self
.
ref_fct
(
x
)
x_shared
=
self
.
shared_constructor
(
x
,
borrow
=
True
)
total
=
self
.
theano_fct
(
x_shared
)
total_func
=
theano
.
function
([],
total
)
total_val
=
total_func
()
assert
numpy
.
allclose
(
self
.
ref_fct
(
x
),
total_val
)
x
/=
.
5
#not required by the contract but it is a feature we've implemented
if
self
.
shared_borrow_true_alias
:
assert
numpy
.
allclose
(
self
.
ref_fct
(
x
),
total_func
())
else
:
assert
numpy
.
allclose
(
x_ref
,
total_func
())
return
SharedTester
test_shared_options
=
makeSharedTester
(
tensor
.
shared
,
'float64'
,
True
,
True
,
True
,
numpy
.
ndarray
,
lambda
a
:
isinstance
(
a
,
numpy
.
ndarray
),
theano
.
tensor
.
sum
,
numpy
.
sum
)
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论