Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
3021c1e3
提交
3021c1e3
authored
2月 22, 2012
作者:
Frederic
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added missing tests for sparse op infer_shape op and replaced 2 tests that had…
Added missing tests for sparse op infer_shape op and replaced 2 tests that had error and implemetend them with DWF tests systems.
上级
0fdd1c3d
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
84 行增加
和
28 行删除
+84
-28
test_basic.py
theano/sparse/tests/test_basic.py
+84
-28
没有找到文件。
theano/sparse/tests/test_basic.py
浏览文件 @
3021c1e3
...
@@ -21,12 +21,14 @@ from theano.sparse.basic import _is_dense, _is_sparse, _mtypes
...
@@ -21,12 +21,14 @@ from theano.sparse.basic import _is_dense, _is_sparse, _mtypes
from
theano.sparse.basic
import
_is_dense_variable
,
_is_sparse_variable
from
theano.sparse.basic
import
_is_dense_variable
,
_is_sparse_variable
from
theano.sparse.basic
import
verify_grad_sparse
from
theano.sparse.basic
import
verify_grad_sparse
from
theano.sparse
import
as_sparse_variable
,
CSC
,
CSR
,
CSM
,
CSMProperties
from
theano.sparse
import
as_sparse_variable
,
CSC
,
CSR
,
CSM
,
CSMProperties
from
theano.sparse
import
SparseType
,
StructuredDotCSC
,
CSMGrad
from
theano.sparse
import
SparseType
,
CSMGrad
from
theano.sparse
import
StructuredDot
,
StructuredDotCSC
from
theano.sparse
import
StructuredDotGradCSC
,
StructuredDotGradCSR
from
theano.sparse
import
AddSS
,
AddSD
,
MulSS
,
MulSD
,
Transpose
,
Neg
from
theano.sparse
import
AddSS
,
AddSD
,
MulSS
,
MulSD
,
Transpose
,
Neg
from
theano.sparse
import
add
,
mul
,
structured_dot
,
transpose
from
theano.sparse
import
add
,
mul
,
structured_dot
,
transpose
from
theano.sparse
import
(
csc_from_dense
,
csr_from_dense
,
dense_from_sparse
,
from
theano.sparse
import
(
csc_from_dense
,
csr_from_dense
,
dense_from_sparse
,
SparseFromDense
)
SparseFromDense
)
from
theano.sparse
import
Dot
,
Usmm
,
UsmmCscDense
,
sp_ones_like
from
theano.sparse
import
Dot
,
Usmm
,
UsmmCscDense
,
sp_ones_like
,
GetItemScalar
#from theano.sparse import get_item_2d, get_item_scalar
#from theano.sparse import get_item_2d, get_item_scalar
from
theano.tests
import
unittest_tools
as
utt
from
theano.tests
import
unittest_tools
as
utt
...
@@ -163,6 +165,14 @@ class SparseInferShapeTester(unittest.TestCase):
...
@@ -163,6 +165,14 @@ class SparseInferShapeTester(unittest.TestCase):
def
test_getitem_2d
(
self
):
def
test_getitem_2d
(
self
):
raise
SkipTest
(
'infer_shape not implemented for GetItem2d yet'
)
raise
SkipTest
(
'infer_shape not implemented for GetItem2d yet'
)
def
test_getitem_scalar
(
self
):
x
=
SparseType
(
'csr'
,
dtype
=
config
.
floatX
)()
self
.
_compile_and_check
([
x
],
[
x
[
2
,
2
]],
[
sp
.
csr_matrix
(
random_lil
((
10
,
40
),
config
.
floatX
,
3
))],
GetItemScalar
)
def
test_csm_grad
(
self
):
def
test_csm_grad
(
self
):
for
sparsetype
in
(
'csr'
,
'csc'
):
for
sparsetype
in
(
'csr'
,
'csc'
):
x
=
tensor
.
vector
()
x
=
tensor
.
vector
()
...
@@ -240,6 +250,78 @@ class SparseInferShapeTester(unittest.TestCase):
...
@@ -240,6 +250,78 @@ class SparseInferShapeTester(unittest.TestCase):
numpy
.
random
.
randn
(
10
,
40
)
.
astype
(
config
.
floatX
)],
numpy
.
random
.
randn
(
10
,
40
)
.
astype
(
config
.
floatX
)],
MulSD
)
MulSD
)
def
test_dot
(
self
):
x
=
SparseType
(
'csc'
,
dtype
=
config
.
floatX
)()
y
=
SparseType
(
'csc'
,
dtype
=
config
.
floatX
)()
self
.
_compile_and_check
(
[
x
,
y
],
[
Dot
()(
x
,
y
)],
[
sp
.
csc_matrix
(
random_lil
((
4
,
5
),
config
.
floatX
,
3
)),
sp
.
csc_matrix
(
random_lil
((
5
,
3
),
config
.
floatX
,
3
))],
Dot
)
def
test_structured_dot
(
self
):
x
=
SparseType
(
'csc'
,
dtype
=
config
.
floatX
)()
y
=
SparseType
(
'csc'
,
dtype
=
config
.
floatX
)()
self
.
_compile_and_check
(
[
x
,
y
],
[
structured_dot
(
x
,
y
)],
[
sp
.
csc_matrix
(
random_lil
((
4
,
5
),
config
.
floatX
,
3
)),
sp
.
csc_matrix
(
random_lil
((
5
,
3
),
config
.
floatX
,
3
))],
StructuredDot
)
def
test_csm
(
self
):
# We also need the grad of CSM to be implemetned.
raise
SkipTest
(
'infer_shape not implemented for CSM'
)
def
test_structured_dot_grad
(
self
):
# We also need the grad of CSM to be implemetned.
raise
SkipTest
(
'infer_shape not implemented for the grad'
' of structured_dot'
)
for
format
,
op
in
[(
'csc'
,
StructuredDotGradCSC
),
(
'csr'
,
StructuredDotGradCSR
)]:
x
=
SparseType
(
format
,
dtype
=
config
.
floatX
)()
y
=
SparseType
(
format
,
dtype
=
config
.
floatX
)()
grads
=
tensor
.
grad
(
dense_from_sparse
(
structured_dot
(
x
,
y
))
.
sum
(),
[
x
,
y
])
self
.
_compile_and_check
(
[
x
,
y
],
[
grads
[
0
]],
[
as_sparse_format
(
random_lil
((
4
,
5
),
config
.
floatX
,
3
),
format
),
as_sparse_format
(
random_lil
((
5
,
3
),
config
.
floatX
,
3
),
format
)],
op
)
self
.
_compile_and_check
(
[
x
,
y
],
[
grads
[
1
]],
[
as_sparse_format
(
random_lil
((
4
,
5
),
config
.
floatX
,
3
),
format
),
as_sparse_format
(
random_lil
((
5
,
3
),
config
.
floatX
,
3
),
format
)],
op
)
def
test_dense_from_sparse
(
self
):
x
=
SparseType
(
'csr'
,
dtype
=
config
.
floatX
)()
self
.
_compile_and_check
([
x
],
[
dense_from_sparse
(
x
)],
[
sp
.
csr_matrix
(
random_lil
((
10
,
40
),
config
.
floatX
,
3
))],
dense_from_sparse
.
__class__
)
def
test_sparse_from_dense
(
self
):
x
=
tensor
.
matrix
()
self
.
_compile_and_check
([
x
],
[
csc_from_dense
(
x
)],
[
numpy
.
random
.
randn
(
10
,
40
)
.
astype
(
config
.
floatX
)],
csc_from_dense
.
__class__
)
class
T_AddMul
(
unittest
.
TestCase
):
class
T_AddMul
(
unittest
.
TestCase
):
def
testAddSS
(
self
):
def
testAddSS
(
self
):
...
@@ -530,22 +612,6 @@ class test_structureddot(unittest.TestCase):
...
@@ -530,22 +612,6 @@ class test_structureddot(unittest.TestCase):
verify_grad_sparse
(
buildgraph_T
,
[
spmat
,
mat
],
structured
=
True
)
verify_grad_sparse
(
buildgraph_T
,
[
spmat
,
mat
],
structured
=
True
)
def
test_infer_shape_csr_csc_grad
(
self
):
for
sparsetype
in
(
'csr'
,
'csc'
):
a
=
SparseType
(
sparsetype
,
dtype
=
config
.
floatX
)()
b
=
SparseType
(
sparsetype
,
dtype
=
config
.
floatX
)()
grads
=
tensor
.
grad
(
dense_from_sparse
(
structured_dot
(
a
,
b
))
.
sum
(),
[
a
,
b
])
f
=
theano
.
function
([
a
,
b
],
[
g
.
shape
for
g
in
grads
])
topo
=
f
.
maker
.
env
.
toposort
()
assert
not
any
(
isinstance
(
t
,
self
.
__class__
)
for
t
in
topo
)
call
=
getattr
(
sp
,
sparsetype
+
'_matrix'
)
x
=
call
(
random_lil
((
500
,
300
),
config
.
floatX
,
10
))
y
=
call
(
random_lil
((
300
,
400
),
config
.
floatX
,
5
))
out1
,
out2
=
f
(
x
,
y
)
assert
numpy
.
all
(
out1
==
x
.
shape
)
assert
numpy
.
all
(
out2
==
y
.
shape
)
def
test_upcast
(
self
):
def
test_upcast
(
self
):
typenames
=
(
'float32'
,
'int64'
,
'int8'
,
'int32'
,
typenames
=
(
'float32'
,
'int64'
,
'int8'
,
'int32'
,
...
@@ -736,16 +802,6 @@ class test_structureddot(unittest.TestCase):
...
@@ -736,16 +802,6 @@ class test_structureddot(unittest.TestCase):
self
.
assertFalse
(
theano_time
>
overhead_rtol
*
scipy_time
+
self
.
assertFalse
(
theano_time
>
overhead_rtol
*
scipy_time
+
overhead_tol
)
overhead_tol
)
def
test_infer_shape
(
self
):
a
=
SparseType
(
'csc'
,
dtype
=
config
.
floatX
)()
b
=
SparseType
(
'csc'
,
dtype
=
config
.
floatX
)()
f
=
theano
.
function
([
a
,
b
],
structured_dot
(
a
,
b
)
.
shape
)
topo
=
f
.
maker
.
env
.
toposort
()
assert
not
any
(
isinstance
(
t
,
self
.
__class__
)
for
t
in
topo
)
x
=
sp
.
csc_matrix
((
4
,
5
),
dtype
=
config
.
floatX
)
y
=
sp
.
csc_matrix
((
5
,
3
),
dtype
=
config
.
floatX
)
assert
numpy
.
all
(
f
(
x
,
y
)
==
numpy
.
array
((
4
,
3
)))
class
DotTests
(
unittest
.
TestCase
):
class
DotTests
(
unittest
.
TestCase
):
def
setUp
(
self
):
def
setUp
(
self
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论