Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
1a3a477e
提交
1a3a477e
authored
11月 01, 2013
作者:
Frederic
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactored gpu test for conv3d2d to be skipped when cuda isn't therei.
上级
26cc1f73
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
43 行增加
和
75 行删除
+43
-75
test_tensor_op.py
theano/sandbox/cuda/tests/test_tensor_op.py
+10
-0
test_conv3d2d.py
theano/tensor/nnet/tests/test_conv3d2d.py
+33
-75
没有找到文件。
theano/sandbox/cuda/tests/test_tensor_op.py
浏览文件 @
1a3a477e
...
...
@@ -12,6 +12,7 @@ import theano.tensor as T
# Skip test if cuda_ndarray is not available.
import
theano.sandbox.cuda
as
cuda
from
theano.tensor.nnet.tests
import
test_conv3d2d
if
cuda
.
cuda_available
==
False
:
raise
SkipTest
(
'Optional package cuda disabled'
)
...
...
@@ -133,3 +134,12 @@ def test_deepcopy():
out
=
f
(
a_v
)
assert
out
is
not
a_v
assert
numpy
.
allclose
(
numpy
.
asarray
(
a_v
),
numpy
.
asarray
(
out
))
def
test_get_diagonal_subtensor_view
():
test_conv3d2d
.
test_get_diagonal_subtensor_view
(
wrap
=
cuda
.
CudaNdarray
)
def
test_conv3d
():
test_conv3d2d
.
test_conv3d
(
mode
=
mode_with_gpu
,
shared
=
cuda
.
shared_constructor
)
theano/tensor/nnet/tests/test_conv3d2d.py
浏览文件 @
1a3a477e
...
...
@@ -5,57 +5,21 @@ from scipy import ndimage
import
theano
from
theano.tensor.nnet.conv3d2d
import
*
import
theano.tests.unittest_tools
as
utt
from
theano.sandbox
import
cuda
if
theano
.
config
.
mode
==
'FAST_COMPILE'
:
mode_with_gpu
=
theano
.
compile
.
mode
.
get_mode
(
'FAST_RUN'
)
.
including
(
'gpu'
)
mode_without_gpu
=
theano
.
compile
.
mode
.
get_mode
(
'FAST_RUN'
)
.
excluding
(
'gpu'
)
else
:
mode_with_gpu
=
theano
.
compile
.
mode
.
get_default_mode
()
.
including
(
'gpu'
)
mode_without_gpu
=
theano
.
compile
.
mode
.
get_default_mode
()
.
excluding
(
'gpu'
)
def
test_get_diagonal_subtensor_view
():
x
=
numpy
.
arange
(
20
)
.
reshape
(
5
,
4
)
xv01
=
get_diagonal_subtensor_view
(
x
,
0
,
1
)
# test that it works in 2d
assert
numpy
.
all
(
xv01
==
[[
12
,
9
,
6
,
3
],
[
16
,
13
,
10
,
7
]])
x
=
numpy
.
arange
(
24
)
.
reshape
(
4
,
3
,
2
)
xv01
=
get_diagonal_subtensor_view
(
x
,
0
,
1
)
xv02
=
get_diagonal_subtensor_view
(
x
,
0
,
2
)
xv12
=
get_diagonal_subtensor_view
(
x
,
1
,
2
)
#print 'x', x
#print 'xv01', xv01
#print 'xv02', xv02
assert
numpy
.
all
(
xv01
==
[
[[
12
,
13
],
[
8
,
9
],
[
4
,
5
]],
[[
18
,
19
],
[
14
,
15
],
[
10
,
11
]]])
assert
numpy
.
all
(
xv02
==
[
[[
6
,
1
],
[
8
,
3
],
[
10
,
5
]],
[[
12
,
7
],
[
14
,
9
],
[
16
,
11
]],
[[
18
,
13
],
[
20
,
15
],
[
22
,
17
]],
])
# diagonal views of each leading matrix is the same
# as the slices out of the diagonal view of the entire 3d tensor
for
xi
,
xvi
in
zip
(
x
,
xv12
):
assert
numpy
.
all
(
xvi
==
get_diagonal_subtensor_view
(
xi
,
0
,
1
))
def
test_get_diagonal_subtensor_view_gpu
():
x
=
numpy
.
arange
(
20
,
dtype
=
'float32'
)
.
reshape
(
5
,
4
)
x
=
cuda
.
CudaNdarray
(
x
)
def
test_get_diagonal_subtensor_view
(
wrap
=
lambda
a
:
a
):
x
=
numpy
.
arange
(
20
)
.
reshape
(
5
,
4
)
.
astype
(
'float32'
)
x
=
wrap
(
x
)
xv01
=
get_diagonal_subtensor_view
(
x
,
0
,
1
)
# test that it works in 2d
assert
numpy
.
all
(
numpy
.
asarray
(
xv01
)
==
[[
12
,
9
,
6
,
3
],
[
16
,
13
,
10
,
7
]])
assert
numpy
.
all
(
numpy
.
asarray
(
xv01
)
==
[[
12
,
9
,
6
,
3
],
[
16
,
13
,
10
,
7
]])
x
=
numpy
.
arange
(
24
)
.
reshape
(
4
,
3
,
2
)
xv01
=
get_diagonal_subtensor_view
(
x
,
0
,
1
)
...
...
@@ -77,9 +41,8 @@ def test_get_diagonal_subtensor_view_gpu():
# diagonal views of each leading matrix is the same
# as the slices out of the diagonal view of the entire 3d tensor
for
xi
,
xvi
in
zip
(
x
,
numpy
.
asarray
(
xv12
)):
assert
numpy
.
all
(
numpy
.
asarray
(
xvi
)
==
numpy
.
asarray
(
get_diagonal_subtensor_view
(
xi
,
0
,
1
)))
for
xi
,
xvi
in
zip
(
x
,
xv12
):
assert
numpy
.
all
(
xvi
==
get_diagonal_subtensor_view
(
xi
,
0
,
1
))
def
pyconv3d
(
signals
,
filters
):
...
...
@@ -103,7 +66,7 @@ def pyconv3d(signals, filters):
return
rval
def
test_conv3d
():
def
test_conv3d
(
mode
=
mode_without_gpu
,
shared
=
theano
.
tensor
.
_shared
):
Ns
,
Ts
,
C
,
Hs
,
Ws
=
3
,
10
,
3
,
32
,
32
Nf
,
Tf
,
C
,
Hf
,
Wf
=
32
,
5
,
3
,
5
,
5
...
...
@@ -115,37 +78,32 @@ def test_conv3d():
pyres
=
pyconv3d
(
signals
,
filters
)
print
time
.
time
()
-
t0
modes
=
[(
mode_without_gpu
,
theano
.
tensor
.
_shared
)]
if
cuda
.
cuda_available
:
modes
.
append
((
mode_with_gpu
,
cuda
.
shared_constructor
))
for
mode
,
shared
in
modes
:
s_signals
=
shared
(
signals
)
s_filters
=
shared
(
filters
)
s_output
=
shared
(
signals
*
0
)
out
=
conv3d
(
s_signals
,
s_filters
,
signals_shape
=
signals
.
shape
,
filters_shape
=
filters
.
shape
)
newconv3d
=
theano
.
function
([],
[],
updates
=
{
s_output
:
out
},
mode
=
mode
)
t0
=
time
.
time
()
newconv3d
()
print
time
.
time
()
-
t0
utt
.
assert_allclose
(
pyres
,
s_output
.
get_value
(
borrow
=
True
))
gsignals
,
gfilters
=
theano
.
grad
(
out
.
sum
(),
[
s_signals
,
s_filters
])
gnewconv3d
=
theano
.
function
([],
[],
updates
=
[(
s_filters
,
gfilters
),
(
s_signals
,
gsignals
)],
mode
=
mode
,
name
=
'grad'
)
t0
=
time
.
time
()
gnewconv3d
()
print
'grad'
,
time
.
time
()
-
t0
s_signals
=
shared
(
signals
)
s_filters
=
shared
(
filters
)
s_output
=
shared
(
signals
*
0
)
out
=
conv3d
(
s_signals
,
s_filters
,
signals_shape
=
signals
.
shape
,
filters_shape
=
filters
.
shape
)
newconv3d
=
theano
.
function
([],
[],
updates
=
{
s_output
:
out
},
mode
=
mode
)
t0
=
time
.
time
()
newconv3d
()
print
time
.
time
()
-
t0
utt
.
assert_allclose
(
pyres
,
s_output
.
get_value
(
borrow
=
True
))
gsignals
,
gfilters
=
theano
.
grad
(
out
.
sum
(),
[
s_signals
,
s_filters
])
gnewconv3d
=
theano
.
function
([],
[],
updates
=
[(
s_filters
,
gfilters
),
(
s_signals
,
gsignals
)],
mode
=
mode
,
name
=
'grad'
)
t0
=
time
.
time
()
gnewconv3d
()
print
'grad'
,
time
.
time
()
-
t0
Ns
,
Ts
,
C
,
Hs
,
Ws
=
3
,
3
,
3
,
5
,
5
Nf
,
Tf
,
C
,
Hf
,
Wf
=
4
,
2
,
3
,
2
,
2
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论