Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
9359dba1
提交
9359dba1
authored
6月 24, 2011
作者:
Pascal Lamblin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix various tests for sparse/sandbox.
上级
ba9de0e0
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
13 行增加
和
12 行删除
+13
-12
test_sp.py
theano/sparse/sandbox/test_sp.py
+13
-12
没有找到文件。
theano/sparse/sandbox/test_sp.py
浏览文件 @
9359dba1
...
@@ -11,6 +11,7 @@ import scipy.sparse as sparse
...
@@ -11,6 +11,7 @@ import scipy.sparse as sparse
import
numpy
import
numpy
import
numpy
as
N
import
numpy
as
N
from
theano.sparse.sandbox
import
sp
from
theano.sparse.sandbox
import
sp
from
theano.tests
import
unittest_tools
as
utt
import
unittest
import
unittest
import
time
import
time
...
@@ -191,7 +192,7 @@ class TestSP(unittest.TestCase):
...
@@ -191,7 +192,7 @@ class TestSP(unittest.TestCase):
assert
(
temp
<
1e-10
)
.
all
()
assert
(
temp
<
1e-10
)
.
all
()
# test downward propagation
# test downward propagation
vis
=
T
.
grad
(
output
,
input
,
out
put
)
vis
=
T
.
grad
(
0.5
*
T
.
sqr
(
output
)
.
sum
(),
in
put
)
downprop
=
function
([
kerns
,
output
],
vis
)
downprop
=
function
([
kerns
,
output
],
vis
)
temp1
=
time
.
time
()
temp1
=
time
.
time
()
for
zz
in
range
(
100
):
for
zz
in
range
(
100
):
...
@@ -200,7 +201,7 @@ class TestSP(unittest.TestCase):
...
@@ -200,7 +201,7 @@ class TestSP(unittest.TestCase):
sp
.
convolution_indices
.
sparse_eval
(
imshp
,
kshp
,
nkern
,
ss
,
conv_mode
)
sp
.
convolution_indices
.
sparse_eval
(
imshp
,
kshp
,
nkern
,
ss
,
conv_mode
)
spmat
=
sparse
.
csc_matrix
((
spfilt
[
kmap
],
indices
,
indptr
),
spmat_shape
)
spmat
=
sparse
.
csc_matrix
((
spfilt
[
kmap
],
indices
,
indptr
),
spmat_shape
)
visref
=
N
.
dot
(
out1
,
spmat
.
todense
())
visref
=
N
.
dot
(
out1
,
spmat
.
todense
())
assert
N
.
all
(
visref
==
visval
)
assert
N
.
all
(
visref
==
visval
)
,
(
visref
,
visval
)
print
'**** Sparse Profiling Results ('
,
mode
,
') ****'
print
'**** Sparse Profiling Results ('
,
mode
,
') ****'
print
'Numpy processing time: '
,
ntot
print
'Numpy processing time: '
,
ntot
...
@@ -322,7 +323,7 @@ class TestSP(unittest.TestCase):
...
@@ -322,7 +323,7 @@ class TestSP(unittest.TestCase):
def
mp
(
input
):
def
mp
(
input
):
output
,
outshp
=
sp
.
max_pool
(
input
,
imval
.
shape
[
1
:],
maxpoolshp
)
output
,
outshp
=
sp
.
max_pool
(
input
,
imval
.
shape
[
1
:],
maxpoolshp
)
return
output
return
output
T
.
verify_grad
(
None
,
mp
,
[
imval
.
reshape
(
imval
.
shape
[
0
],
-
1
)])
utt
.
verify_grad
(
mp
,
[
imval
.
reshape
(
imval
.
shape
[
0
],
-
1
)])
def
test_CSMGrad
(
self
):
def
test_CSMGrad
(
self
):
...
@@ -339,20 +340,20 @@ class TestSP(unittest.TestCase):
...
@@ -339,20 +340,20 @@ class TestSP(unittest.TestCase):
indptr
=
T
.
ivector
()
indptr
=
T
.
ivector
()
spmat_shape
=
T
.
ivector
()
spmat_shape
=
T
.
ivector
()
def
d
(
kerns
,
indices
,
indptr
,
spmat_shape
):
return
theano
.
sparse
.
dense_from_sparse
(
\
theano
.
sparse
.
CSM
(
sptype
,
kmap
)(
kerns
,
indices
,
indptr
,
spmat_shape
))
for
mode
in
[
'FAST_COMPILE'
,
'FAST_RUN'
]:
for
mode
in
[
'FAST_COMPILE'
,
'FAST_RUN'
]:
for
conv_mode
in
convmodes
:
for
conv_mode
in
convmodes
:
for
ss
in
ssizes
:
for
ss
in
ssizes
:
indvals
,
indptrvals
,
spshapevals
,
sptype
,
outshp
,
kmap
=
\
indvals
,
indptrvals
,
spshapevals
,
sptype
,
outshp
,
kmap
=
\
sp
.
convolution_indices
.
sparse_eval
(
imshp
,
kshp
,
nkern
,
ss
,
conv_mode
)
sp
.
convolution_indices
.
sparse_eval
(
imshp
,
kshp
,
nkern
,
ss
,
conv_mode
)
kvals
=
N
.
random
.
random
(
nkern
*
N
.
prod
(
kshp
)
*
N
.
prod
(
outshp
))
.
flatten
()
kvals
=
N
.
random
.
random
(
nkern
*
N
.
prod
(
kshp
)
*
N
.
prod
(
outshp
))
.
flatten
()
def
d
(
kerns
):
return
theano
.
sparse
.
dense_from_sparse
(
theano
.
sparse
.
CSM
(
sptype
,
kmap
)(
kerns
,
indvals
,
indptrvals
,
spshapevals
))
# symbolic stuff
# symbolic stuff
T
.
verify_grad
(
None
,
d
,
\
utt
.
verify_grad
(
d
,
[
kvals
])
[
kvals
,
indvals
,
indptrvals
,
spshapevals
])
def
test_diagonal
():
def
test_diagonal
():
...
@@ -373,11 +374,11 @@ def test_diagonal():
...
@@ -373,11 +374,11 @@ def test_diagonal():
def
test_diagonal_grad
():
def
test_diagonal_grad
():
def
d
(
x
):
def
d
(
x
):
return
sp
.
sp_sum
(
sp
.
square_diagonal
(
x
),
sparse_grad
=
True
)
return
sp
.
sp_sum
(
sp
.
square_diagonal
(
x
),
sparse_grad
=
True
)
T
.
verify_grad
(
None
,
d
,
[[
0.0
,
0.1
,
0.2
,
0.3
]],
utt
.
verify_grad
(
d
,
[[
0.0
,
0.1
,
0.2
,
0.3
]],
mode
=
theano
.
Mode
(
linker
=
'py'
,
optimizer
=
'fast_compile'
))
mode
=
theano
.
Mode
(
linker
=
'py'
,
optimizer
=
'fast_compile'
))
def
test_row_scale
():
def
test_row_scale
():
x
=
theano
.
sparse
.
csc_matrix
()
x
=
theano
.
sparse
.
csc_
d
matrix
()
s
=
theano
.
tensor
.
dvector
()
s
=
theano
.
tensor
.
dvector
()
def
d
(
x
,
s
):
def
d
(
x
,
s
):
...
@@ -408,7 +409,7 @@ def test_row_scale():
...
@@ -408,7 +409,7 @@ def test_row_scale():
print
>>
sys
.
stderr
,
"WARNING: skipping gradient test because verify_grad doesn't support sparse arguments"
print
>>
sys
.
stderr
,
"WARNING: skipping gradient test because verify_grad doesn't support sparse arguments"
def
test_col_scale
():
def
test_col_scale
():
x
=
theano
.
sparse
.
csc_matrix
()
x
=
theano
.
sparse
.
csc_
d
matrix
()
s
=
theano
.
tensor
.
dvector
()
s
=
theano
.
tensor
.
dvector
()
def
d
(
x
,
s
):
def
d
(
x
,
s
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论