Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
b9f75a3d
提交
b9f75a3d
authored
1月 12, 2012
作者:
Valentin Bisson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fixed Remove0 testing.
上级
e9697dc4
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
28 行增加
和
28 行删除
+28
-28
test_sp.py
theano/sparse/sandbox/test_sp.py
+28
-28
没有找到文件。
theano/sparse/sandbox/test_sp.py
浏览文件 @
b9f75a3d
...
...
@@ -26,43 +26,44 @@ class TestSP(unittest.TestCase):
# fixed parameters
bsize
=
10
# batch size
imshp
=
(
28
,
28
)
kshp
=
(
5
,
5
)
imshp
=
(
28
,
28
)
kshp
=
(
5
,
5
)
nkern
=
5
ssizes
=
((
1
,
1
),(
2
,
2
),(
3
,
3
),(
4
,
4
))
convmodes
=
(
'full'
,
'valid'
)
ssizes
=
((
1
,
1
),
(
2
,
2
),
(
3
,
3
),
(
4
,
4
))
convmodes
=
(
'full'
,
'valid'
)
# symbolic stuff
bias
=
tensor
.
dvector
()
kerns
=
tensor
.
dmatrix
()
input
=
tensor
.
dmatrix
()
rng
=
numpy
.
random
.
RandomState
(
3423489
)
filters
=
rng
.
randn
(
nkern
,
numpy
.
prod
(
kshp
))
filters
=
rng
.
randn
(
nkern
,
numpy
.
prod
(
kshp
))
biasvals
=
rng
.
randn
(
nkern
)
for
mode
in
(
'FAST_COMPILE'
,
'FAST_RUN'
):
#
, profmode):
for
mode
in
(
'FAST_COMPILE'
,
'FAST_RUN'
):
#
, profmode):
ttot
,
ntot
=
0
,
0
for
conv_mode
in
convmodes
:
for
ss
in
ssizes
:
output
,
outshp
=
sp
.
convolve
(
kerns
,
kshp
,
nkern
,
input
,
\
output
,
outshp
=
sp
.
convolve
(
kerns
,
kshp
,
nkern
,
input
,
\
imshp
,
ss
,
bias
=
bias
,
mode
=
conv_mode
)
f
=
function
([
kerns
,
bias
,
input
],
output
,
mode
=
mode
)
# now test with real values
img2d
=
numpy
.
arange
(
bsize
*
numpy
.
prod
(
imshp
))
.
reshape
((
bsize
,)
+
imshp
)
img1d
=
img2d
.
reshape
(
bsize
,
-
1
)
img2d
=
numpy
.
arange
(
bsize
*
numpy
.
prod
(
imshp
))
.
reshape
((
\
bsize
,)
+
imshp
)
img1d
=
img2d
.
reshape
(
bsize
,
-
1
)
# create filters (need to be flipped to use convolve2d)
filtersflipped
=
numpy
.
zeros
((
nkern
,)
+
kshp
)
filtersflipped
=
numpy
.
zeros
((
nkern
,)
+
kshp
)
for
k
in
range
(
nkern
):
it
=
reversed
(
filters
[
k
,:])
it
=
reversed
(
filters
[
k
,
:])
for
i
in
range
(
kshp
[
0
]):
for
j
in
range
(
kshp
[
1
]):
filtersflipped
[
k
,
i
,
j
]
=
it
.
next
()
# compute output with convolve2d
if
conv_mode
==
'valid'
:
if
conv_mode
==
'valid'
:
fulloutshp
=
numpy
.
array
(
imshp
)
-
numpy
.
array
(
kshp
)
+
1
else
:
fulloutshp
=
numpy
.
array
(
imshp
)
+
numpy
.
array
(
kshp
)
-
1
...
...
@@ -70,11 +71,11 @@ class TestSP(unittest.TestCase):
refout
=
numpy
.
zeros
((
bsize
,)
+
tuple
(
fulloutshp
)
+
(
nkern
,))
for
b
in
range
(
bsize
):
for
n
in
range
(
nkern
):
refout
[
b
,
...
,
n
]
=
convolve2d
(
\
img2d
[
b
,:,:],
filtersflipped
[
n
,
...
],
conv_mode
)
refout
[
b
,
...
,
n
]
=
convolve2d
(
img2d
[
b
,:,:],
filtersflipped
[
n
,
...
],
conv_mode
)
ntot
+=
time
.
time
()
-
ntime1
# need to flatten images
bench1
=
refout
[:,
0
::
ss
[
0
],
0
::
ss
[
1
],:]
.
reshape
(
bsize
,
-
1
,
nkern
)
bench1
+=
biasvals
.
reshape
(
1
,
1
,
nkern
)
...
...
@@ -428,32 +429,31 @@ class TestSP(unittest.TestCase):
def
test_remove0
():
print
print
'test_remove0()'
import
scipy
import
numpy
as
N
configs
=
[
# structure type, numpy matching class
, optimized
# structure type, numpy matching class
(
'csc'
,
scipy
.
sparse
.
csc_matrix
),
(
'csr'
,
scipy
.
sparse
.
csr_matrix
),
]
for
format
,
matrix_class
in
configs
:
print
'config: format=
\'
%(format)
s
\'
, matrix_class=
%(matrix_class)
s'
%
locals
()
# real
origin
=
N
.
arange
(
9
)
.
reshape
((
3
,
3
))
.
astype
(
theano
.
config
.
floatX
)
with0
=
matrix_class
(
origin
)
.
astype
(
theano
.
config
.
floatX
)
with0
[
0
,
1
]
=
with0
[
1
,
0
]
=
with0
[
2
,
2
]
=
0
origin
=
(
numpy
.
arange
(
9
)
+
1
)
.
reshape
((
3
,
3
))
.
astype
(
theano
.
config
.
floatX
)
with0
=
matrix_class
(
origin
)
.
astype
(
theano
.
config
.
floatX
)
with0
[
0
,
1
]
=
with0
[
1
,
0
]
=
with0
[
2
,
2
]
=
0
assert
with0
.
size
==
9
# symbolic
x
=
theano
.
sparse
.
SparseType
(
format
=
format
,
dtype
=
theano
.
config
.
floatX
)()
f
=
theano
.
function
([
x
],
sp
.
Remove0
()(
x
))
x
=
theano
.
sparse
.
SparseType
(
format
=
format
,
dtype
=
theano
.
config
.
floatX
)()
f
=
theano
.
function
([
x
],
sp
.
Remove0
()(
x
))
# checking
with0
.
eliminate_zeros
()
# makes sense to change its name
target
=
with0
assert
(
f
(
with0
)
.
todense
()
==
target
.
todense
())
.
all
()
target
=
with0
result
=
f
(
with0
)
with0
.
eliminate_zeros
()
assert
result
.
size
==
target
.
size
,
'Matrices sizes differ. Have zeros been removed ?'
def
test_diagonal
():
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论