Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
9cbb58f4
提交
9cbb58f4
authored
3月 13, 2012
作者:
Frederic Bastien
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
make tests less verbose
上级
68ec79f5
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
37 行增加
和
43 行删除
+37
-43
sp.py
theano/sparse/sandbox/sp.py
+4
-4
test_sp.py
theano/sparse/sandbox/test_sp.py
+19
-19
test_basic.py
theano/sparse/tests/test_basic.py
+13
-19
unittest_tools.py
theano/tests/unittest_tools.py
+1
-1
没有找到文件。
theano/sparse/sandbox/sp.py
浏览文件 @
9cbb58f4
...
@@ -750,10 +750,10 @@ def max_pool(images, imgshp, maxpoolshp):
...
@@ -750,10 +750,10 @@ def max_pool(images, imgshp, maxpoolshp):
convolution_indices
.
conv_eval
(
imgshp
,
maxpoolshp
,
convolution_indices
.
conv_eval
(
imgshp
,
maxpoolshp
,
maxpoolshp
,
mode
=
'valid'
)
maxpoolshp
,
mode
=
'valid'
)
print
'XXXXXXXXXXXXXXXX MAX POOLING LAYER XXXXXXXXXXXXXXXXXXXX'
#
print 'XXXXXXXXXXXXXXXX MAX POOLING LAYER XXXXXXXXXXXXXXXXXXXX'
print
'imgshp = '
,
imgshp
#
print 'imgshp = ', imgshp
print
'maxpoolshp = '
,
maxpoolshp
#
print 'maxpoolshp = ', maxpoolshp
print
'outshp = '
,
outshp
#
print 'outshp = ', outshp
# build sparse matrix, then generate stack of image patches
# build sparse matrix, then generate stack of image patches
csc
=
theano
.
sparse
.
CSM
(
sptype
)(
N
.
ones
(
indices
.
size
),
indices
,
csc
=
theano
.
sparse
.
CSM
(
sptype
)(
N
.
ones
(
indices
.
size
),
indices
,
...
...
theano/sparse/sandbox/test_sp.py
浏览文件 @
9cbb58f4
...
@@ -21,9 +21,9 @@ from theano.tests import unittest_tools as utt
...
@@ -21,9 +21,9 @@ from theano.tests import unittest_tools as utt
class
TestSP
(
unittest
.
TestCase
):
class
TestSP
(
unittest
.
TestCase
):
def
test_convolution
(
self
):
def
test_convolution
(
self
):
print
'
\n\n
*************************************************'
#
print '\n\n*************************************************'
print
' TEST CONVOLUTION'
#
print ' TEST CONVOLUTION'
print
'*************************************************'
#
print '*************************************************'
# fixed parameters
# fixed parameters
bsize
=
10
# batch size
bsize
=
10
# batch size
...
@@ -118,18 +118,18 @@ class TestSP(unittest.TestCase):
...
@@ -118,18 +118,18 @@ class TestSP(unittest.TestCase):
#assert numpy.all(visref==visval)
#assert numpy.all(visref==visval)
print
'**** Convolution Profiling Results ('
,
mode
,
') ****'
#
print '**** Convolution Profiling Results (',mode,') ****'
print
'Numpy processing time: '
,
ntot
#
print 'Numpy processing time: ', ntot
print
'Theano processing time: '
,
ttot
#
print 'Theano processing time: ', ttot
#profmode.print_summary()
#profmode.print_summary()
def
test_sparse
(
self
):
def
test_sparse
(
self
):
print
'
\n\n
*************************************************'
#
print '\n\n*************************************************'
print
' TEST SPARSE'
#
print ' TEST SPARSE'
print
'*************************************************'
#
print '*************************************************'
# fixed parameters
# fixed parameters
bsize
=
10
# batch size
bsize
=
10
# batch size
...
@@ -209,9 +209,9 @@ class TestSP(unittest.TestCase):
...
@@ -209,9 +209,9 @@ class TestSP(unittest.TestCase):
visref
=
numpy
.
dot
(
out1
,
spmat
.
todense
())
visref
=
numpy
.
dot
(
out1
,
spmat
.
todense
())
assert
numpy
.
all
(
visref
==
visval
),
(
visref
,
visval
)
assert
numpy
.
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
print
'Theano processing time: '
,
ttot
#
print 'Theano processing time: ', ttot
#profmode.print_summary()
#profmode.print_summary()
...
@@ -409,7 +409,7 @@ class TestSP(unittest.TestCase):
...
@@ -409,7 +409,7 @@ class TestSP(unittest.TestCase):
# Sparse gradient on Sum on all axis
# Sparse gradient on Sum on all axis
# unfinished, and suspended until verify_grad get fixed
# unfinished, and suspended until verify_grad get fixed
if
False
:
if
False
:
print
'grad on sum on all axis...'
#
print 'grad on sum on all axis...'
def
fun
(
x
):
def
fun
(
x
):
## verify_grad does not handle sparse data, so here's some casting as a workaround.
## verify_grad does not handle sparse data, so here's some casting as a workaround.
# x is a dense matrix: make it sparse
# x is a dense matrix: make it sparse
...
@@ -421,11 +421,11 @@ class TestSP(unittest.TestCase):
...
@@ -421,11 +421,11 @@ class TestSP(unittest.TestCase):
dense_sum
=
theano
.
sparse
.
DenseFromSparse
()(
sparse_sum
)
dense_sum
=
theano
.
sparse
.
DenseFromSparse
()(
sparse_sum
)
return
dense_sum
return
dense_sum
x_val
=
x_data
.
copy
()
x_val
=
x_data
.
copy
()
print
type
(
x_val
)
#
print type(x_val)
import
pdb
;
pdb
.
set_trace
()
import
pdb
;
pdb
.
set_trace
()
tensor
.
verify_grad
(
fun
,
[
x_val
],
rng
=
rng
)
tensor
.
verify_grad
(
fun
,
[
x_val
],
rng
=
rng
)
#utt.verify_grad(SpSum(axis=None), [x_val])
#utt.verify_grad(SpSum(axis=None), [x_val])
print
'ok'
#
print 'ok'
def
test_diag
():
def
test_diag
():
...
@@ -513,8 +513,8 @@ def test_row_scale():
...
@@ -513,8 +513,8 @@ def test_row_scale():
f
=
theano
.
function
([
x
,
s
],
sp
.
row_scale
(
x
,
s
))
f
=
theano
.
function
([
x
,
s
],
sp
.
row_scale
(
x
,
s
))
print
'A'
,
f
(
x_val
,
s_val
)
.
toarray
()
#
print 'A', f(x_val, s_val).toarray()
print
'B'
,
(
x_val_dense
.
T
*
s_val
)
.
T
#
print 'B', (x_val_dense.T * s_val).T
assert
numpy
.
all
(
f
(
x_val
,
s_val
)
.
toarray
()
==
(
x_val_dense
.
T
*
s_val
)
.
T
)
assert
numpy
.
all
(
f
(
x_val
,
s_val
)
.
toarray
()
==
(
x_val_dense
.
T
*
s_val
)
.
T
)
...
@@ -544,8 +544,8 @@ def test_col_scale():
...
@@ -544,8 +544,8 @@ def test_col_scale():
f
=
theano
.
function
([
x
,
s
],
sp
.
col_scale
(
x
,
s
))
f
=
theano
.
function
([
x
,
s
],
sp
.
col_scale
(
x
,
s
))
print
'A'
,
f
(
x_val
,
s_val
)
.
toarray
()
#
print 'A', f(x_val, s_val).toarray()
print
'B'
,
(
x_val_dense
*
s_val
)
#
print 'B', (x_val_dense * s_val)
assert
numpy
.
all
(
f
(
x_val
,
s_val
)
.
toarray
()
==
(
x_val_dense
*
s_val
))
assert
numpy
.
all
(
f
(
x_val
,
s_val
)
.
toarray
()
==
(
x_val_dense
*
s_val
))
...
...
theano/sparse/tests/test_basic.py
浏览文件 @
9cbb58f4
...
@@ -624,11 +624,11 @@ class test_structureddot(unittest.TestCase):
...
@@ -624,11 +624,11 @@ class test_structureddot(unittest.TestCase):
spmat
.
dtype
=
numpy
.
dtype
(
sparse_dtype
)
spmat
.
dtype
=
numpy
.
dtype
(
sparse_dtype
)
mat
=
numpy
.
asarray
(
numpy
.
random
.
randn
(
N
,
K
)
*
9
,
mat
=
numpy
.
asarray
(
numpy
.
random
.
randn
(
N
,
K
)
*
9
,
dtype
=
dense_dtype
)
dtype
=
dense_dtype
)
print
'DTYPES'
,
sparse_dtype
,
dense_dtype
#
print 'DTYPES', sparse_dtype, dense_dtype
print
'sym types'
,
a
.
type
,
b
.
type
#
print 'sym types', a.type, b.type
print
'dtype strings'
,
spmat
.
dtype
,
mat
.
dtype
#
print 'dtype strings', spmat.dtype, mat.dtype
print
'numpy dtype num'
,
mat
.
dtype
.
num
#
print 'numpy dtype num', mat.dtype.num
print
'scipy dtype num'
,
spmat
.
data
.
dtype
.
num
#
print 'scipy dtype num', spmat.data.dtype.num
theano_result
=
f
(
spmat
,
mat
)
theano_result
=
f
(
spmat
,
mat
)
scipy_result
=
spmat
*
mat
scipy_result
=
spmat
*
mat
assert
theano_result
.
shape
==
scipy_result
.
shape
assert
theano_result
.
shape
==
scipy_result
.
shape
...
@@ -665,7 +665,7 @@ class test_structureddot(unittest.TestCase):
...
@@ -665,7 +665,7 @@ class test_structureddot(unittest.TestCase):
sdcscpresent
=
False
sdcscpresent
=
False
for
node
in
f
.
maker
.
env
.
toposort
():
for
node
in
f
.
maker
.
env
.
toposort
():
print
node
.
op
#
print node.op
assert
not
isinstance
(
node
.
op
,
CSM
)
assert
not
isinstance
(
node
.
op
,
CSM
)
assert
not
isinstance
(
node
.
op
,
CSMProperties
)
assert
not
isinstance
(
node
.
op
,
CSMProperties
)
if
isinstance
(
f
.
maker
.
env
.
toposort
()[
1
]
.
op
,
StructuredDotCSC
):
if
isinstance
(
f
.
maker
.
env
.
toposort
()[
1
]
.
op
,
StructuredDotCSC
):
...
@@ -680,7 +680,7 @@ class test_structureddot(unittest.TestCase):
...
@@ -680,7 +680,7 @@ class test_structureddot(unittest.TestCase):
imvals
=
1.0
*
numpy
.
array
(
numpy
.
arange
(
bsize
*
spmat
.
shape
[
1
])
.
\
imvals
=
1.0
*
numpy
.
array
(
numpy
.
arange
(
bsize
*
spmat
.
shape
[
1
])
.
\
reshape
(
bsize
,
spmat
.
shape
[
1
]),
dtype
=
'float32'
)
reshape
(
bsize
,
spmat
.
shape
[
1
]),
dtype
=
'float32'
)
outvals
=
f
(
kernvals
,
imvals
)
outvals
=
f
(
kernvals
,
imvals
)
print
outvals
#
print outvals
def
test_dot_sparse_sparse
(
self
):
def
test_dot_sparse_sparse
(
self
):
#test dot for 2 input sparse matrix
#test dot for 2 input sparse matrix
...
@@ -738,10 +738,10 @@ class test_structureddot(unittest.TestCase):
...
@@ -738,10 +738,10 @@ class test_structureddot(unittest.TestCase):
scipy_time
=
numpy
.
min
(
scipy_times
)
scipy_time
=
numpy
.
min
(
scipy_times
)
speedup
=
scipy_time
/
theano_time
speedup
=
scipy_time
/
theano_time
print
scipy_times
#
print scipy_times
print
theano_times
#
print theano_times
print
(
'M=
%(M)
s N=
%(N)
s K=
%(K)
s nnz=
%(nnz)
s theano_time'
#
print ('M=%(M)s N=%(N)s K=%(K)s nnz=%(nnz)s theano_time'
'=
%(theano_time)
s speedup=
%(speedup)
s'
)
%
locals
()
#
'=%(theano_time)s speedup=%(speedup)s') % locals()
# fail if Theano is slower than scipy by more than a certain amount
# fail if Theano is slower than scipy by more than a certain amount
overhead_tol
=
0.003
# seconds overall
overhead_tol
=
0.003
# seconds overall
...
@@ -778,10 +778,8 @@ class test_structureddot(unittest.TestCase):
...
@@ -778,10 +778,8 @@ class test_structureddot(unittest.TestCase):
theano_time
=
t1
-
t0
theano_time
=
t1
-
t0
scipy_time
=
t2
-
t1
scipy_time
=
t2
-
t1
#print theano_result
#print 'theano took', theano_time,
#print scipy_result
#print 'scipy took', scipy_time
print
'theano took'
,
theano_time
,
print
'scipy took'
,
scipy_time
overhead_tol
=
0.002
# seconds
overhead_tol
=
0.002
# seconds
overhead_rtol
=
1.1
# times as long
overhead_rtol
=
1.1
# times as long
self
.
assertTrue
(
numpy
.
allclose
(
theano_result
,
scipy_result
))
self
.
assertTrue
(
numpy
.
allclose
(
theano_result
,
scipy_result
))
...
@@ -1169,16 +1167,12 @@ def test_size():
...
@@ -1169,16 +1167,12 @@ def test_size():
def
test_remove0
():
def
test_remove0
():
print
print
'test_remove0()'
configs
=
[
configs
=
[
# structure type, numpy matching class
# structure type, numpy matching class
(
'csc'
,
scipy
.
sparse
.
csc_matrix
),
(
'csc'
,
scipy
.
sparse
.
csc_matrix
),
(
'csr'
,
scipy
.
sparse
.
csr_matrix
),
(
'csr'
,
scipy
.
sparse
.
csr_matrix
),
]
]
for
format
,
matrix_class
in
configs
:
for
format
,
matrix_class
in
configs
:
print
(
'config: format=
\'
%(format)
s
\'
,'
' matrix_class=
%(matrix_class)
s'
%
locals
())
# real
# real
origin
=
(
numpy
.
arange
(
9
)
+
1
)
.
reshape
((
3
,
3
))
.
astype
(
config
.
floatX
)
origin
=
(
numpy
.
arange
(
9
)
+
1
)
.
reshape
((
3
,
3
))
.
astype
(
config
.
floatX
)
mat
=
matrix_class
(
origin
)
.
astype
(
theano
.
config
.
floatX
)
mat
=
matrix_class
(
origin
)
.
astype
(
theano
.
config
.
floatX
)
...
...
theano/tests/unittest_tools.py
浏览文件 @
9cbb58f4
...
@@ -164,7 +164,7 @@ class InferShapeTester(unittest.TestCase):
...
@@ -164,7 +164,7 @@ class InferShapeTester(unittest.TestCase):
outputs_function
=
theano
.
function
(
inputs
,
outputs
,
mode
=
self
.
mode
)
outputs_function
=
theano
.
function
(
inputs
,
outputs
,
mode
=
self
.
mode
)
shapes_function
=
theano
.
function
(
inputs
,
[
o
.
shape
for
o
in
outputs
],
shapes_function
=
theano
.
function
(
inputs
,
[
o
.
shape
for
o
in
outputs
],
mode
=
self
.
mode
)
mode
=
self
.
mode
)
theano
.
printing
.
debugprint
(
shapes_function
)
#
theano.printing.debugprint(shapes_function)
# Check that the Op is removed from the compiled function.
# Check that the Op is removed from the compiled function.
topo_shape
=
shapes_function
.
maker
.
env
.
toposort
()
topo_shape
=
shapes_function
.
maker
.
env
.
toposort
()
assert
not
any
(
isinstance
(
t
.
op
,
cls
)
for
t
in
topo_shape
)
assert
not
any
(
isinstance
(
t
.
op
,
cls
)
for
t
in
topo_shape
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论