Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
23e67f75
提交
23e67f75
authored
4月 17, 2008
作者:
turian@grenat.iro.umontreal.ca
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Better sparse addition testing
上级
2ea6bd45
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
88 行增加
和
26 行删除
+88
-26
_test_sparse.py
_test_sparse.py
+87
-25
sparse.py
sparse.py
+1
-1
没有找到文件。
_test_sparse.py
浏览文件 @
23e67f75
...
...
@@ -4,6 +4,13 @@ import unittest
import
compile
import
gradient
from
sparse
import
_is_dense
,
_is_sparse
,
_is_dense_result
,
_is_sparse_result
""" Types of sparse matrices to use for testing """
_mtypes
=
[
sparse
.
csc_matrix
,
sparse
.
csr_matrix
]
#_mtypes = [sparse.csc_matrix, sparse.csr_matrix, sparse.dok_matrix, sparse.lil_matrix, sparse.coo_matrix]
_mtypes_str
=
[
"csc"
,
"csr"
]
class
T_transpose
(
unittest
.
TestCase
):
def
setUp
(
self
):
numpy
.
random
.
seed
(
44
)
...
...
@@ -33,23 +40,82 @@ class T_transpose(unittest.TestCase):
self
.
failUnless
(
vta
.
shape
==
(
3
,
5
))
class
T_Add
(
unittest
.
TestCase
):
def
test0
(
self
):
sp_a
=
sparse
.
csc_matrix
(
sparse
.
speye
(
5
,
3
))
a
=
assparse
(
sp_a
)
self
.
failUnless
(
a
.
data
is
sp_a
)
sp_b
=
sparse
.
csc_matrix
(
sparse
.
speye
(
5
,
3
))
b
=
assparse
(
sp_b
)
self
.
failUnless
(
b
.
data
is
sp_b
)
def
testSS
(
self
):
for
mtype
in
_mtypes
:
a
=
mtype
(
numpy
.
array
([[
1.
,
0
],
[
3
,
0
],
[
0
,
6
]]))
aR
=
assparse
(
a
)
self
.
failUnless
(
aR
.
data
is
a
)
self
.
failUnless
(
_is_sparse
(
a
))
self
.
failUnless
(
_is_sparse_result
(
aR
))
b
=
mtype
(
numpy
.
asarray
([[
0
,
2.
],
[
0
,
4
],
[
5
,
0
]]))
bR
=
assparse
(
b
)
self
.
failUnless
(
bR
.
data
is
b
)
self
.
failUnless
(
_is_sparse
(
b
))
self
.
failUnless
(
_is_sparse_result
(
bR
))
apb
=
add
(
aR
,
bR
)
self
.
failUnless
(
_is_sparse_result
(
apb
))
self
.
failUnless
(
apb
.
dtype
==
aR
.
dtype
,
apb
.
dtype
)
self
.
failUnless
(
apb
.
dtype
==
bR
.
dtype
,
apb
.
dtype
)
self
.
failUnless
(
apb
.
format
==
aR
.
format
,
apb
.
format
)
self
.
failUnless
(
apb
.
format
==
bR
.
format
,
apb
.
format
)
apb
=
add
(
a
,
b
)
val
=
compile
.
eval_outputs
([
apb
])
self
.
failUnless
(
val
.
shape
==
(
3
,
2
))
self
.
failUnless
(
numpy
.
all
(
val
.
todense
()
==
(
a
+
b
)
.
todense
()))
self
.
failUnless
(
numpy
.
all
(
val
.
todense
()
==
numpy
.
array
([[
1.
,
2
],
[
3
,
4
],
[
5
,
6
]])))
def
testSD
(
self
):
for
mtype
in
_mtypes
:
a
=
numpy
.
array
([[
1.
,
0
],
[
3
,
0
],
[
0
,
6
]])
aR
=
tensor
.
astensor
(
a
)
self
.
failUnless
(
aR
.
data
is
a
)
self
.
failUnless
(
_is_dense
(
a
))
self
.
failUnless
(
_is_dense_result
(
aR
))
b
=
mtype
(
numpy
.
asarray
([[
0
,
2.
],
[
0
,
4
],
[
5
,
0
]]))
bR
=
assparse
(
b
)
self
.
failUnless
(
bR
.
data
is
b
)
self
.
failUnless
(
_is_sparse
(
b
))
self
.
failUnless
(
_is_sparse_result
(
bR
))
apb
=
add
(
aR
,
bR
)
self
.
failUnless
(
_is_dense_result
(
apb
))
self
.
failUnless
(
apb
.
dtype
==
aR
.
dtype
,
apb
.
dtype
)
self
.
failUnless
(
apb
.
dtype
==
bR
.
dtype
,
apb
.
dtype
)
self
.
failUnless
(
apb
.
dtype
==
a
.
dtype
,
apb
.
dtype
)
self
.
failUnless
(
apb
.
format
==
a
.
format
,
apb
.
format
)
val
=
compile
.
eval_outputs
([
apb
])
self
.
failUnless
(
val
.
shape
==
(
3
,
2
))
self
.
failUnless
(
numpy
.
all
(
val
==
(
a
+
b
)))
self
.
failUnless
(
numpy
.
all
(
val
==
numpy
.
array
([[
1.
,
2
],
[
3
,
4
],
[
5
,
6
]])))
def
testDS
(
self
):
for
mtype
in
_mtypes
:
a
=
mtype
(
numpy
.
array
([[
1.
,
0
],
[
3
,
0
],
[
0
,
6
]]))
aR
=
assparse
(
a
)
self
.
failUnless
(
aR
.
data
is
a
)
self
.
failUnless
(
_is_sparse
(
a
))
self
.
failUnless
(
_is_sparse_result
(
aR
))
b
=
numpy
.
asarray
([[
0
,
2.
],
[
0
,
4
],
[
5
,
0
]])
bR
=
tensor
.
astensor
(
b
)
self
.
failUnless
(
bR
.
data
is
b
)
self
.
failUnless
(
_is_dense
(
b
))
self
.
failUnless
(
_is_dense_result
(
bR
))
apb
=
add
(
aR
,
bR
)
self
.
failUnless
(
_is_dense_result
(
apb
))
self
.
failUnless
(
apb
.
dtype
==
aR
.
dtype
,
apb
.
dtype
)
self
.
failUnless
(
apb
.
dtype
==
bR
.
dtype
,
apb
.
dtype
)
val
=
compile
.
eval_outputs
([
apb
])
self
.
failUnless
(
val
.
shape
==
(
5
,
3
))
self
.
failUnless
(
numpy
.
all
(
val
.
todense
()
==
(
sp_a
+
sp_b
)
.
todense
()))
self
.
failUnless
(
val
.
shape
==
(
3
,
2
))
self
.
failUnless
(
numpy
.
all
(
val
==
(
a
+
b
)))
self
.
failUnless
(
numpy
.
all
(
val
==
numpy
.
array
([[
1.
,
2
],
[
3
,
4
],
[
5
,
6
]])))
class
T_conversion
(
unittest
.
TestCase
):
def
setUp
(
self
):
...
...
@@ -70,25 +136,21 @@ class T_conversion(unittest.TestCase):
self
.
failUnless
(
val
.
format
==
'csr'
)
def
test2
(
self
):
csr
=
sparse
.
csr_matrix
((
2
,
5
))
d
=
dense_from_sparse
(
csr
)
csr
[
0
,
0
]
=
1.0
for
t
in
_mtypes
:
s
=
t
((
2
,
5
))
d
=
dense_from_sparse
(
s
)
s
[
0
,
0
]
=
1.0
val
=
compile
.
eval_outputs
([
d
])
self
.
failUnless
(
str
(
val
.
dtype
)
==
'float64'
)
self
.
failUnless
(
numpy
.
all
(
val
[
0
]
==
[
1
,
0
,
0
,
0
,
0
]))
class
_testCase_dot
(
unittest
.
TestCase
):
""" Types of sparse matrices to use for testing """
mtypes
=
[
sparse
.
csc_matrix
,
sparse
.
csr_matrix
]
mtypes_str
=
[
"csc"
,
"csr"
]
#mtypes = [sparse.csc_matrix, sparse.csr_matrix, sparse.dok_matrix, sparse.lil_matrix, sparse.coo_matrix]
def
setUp
(
self
):
numpy
.
random
.
seed
(
44
)
def
test_basic0
(
self
):
for
mtype
in
self
.
mtypes
:
for
mtype
in
_
mtypes
:
x
=
assparse
(
mtype
((
500
,
3
)))
x
.
data
[(
10
,
1
)]
=
1
x
.
data
[(
20
,
2
)]
=
2
...
...
@@ -116,7 +178,7 @@ class _testCase_dot(unittest.TestCase):
self
.
failUnless
((
z
==
w
)
.
all
()
==
True
)
def
test_basic1
(
self
):
for
mtype
in
self
.
mtypes
:
for
mtype
in
_
mtypes
:
x
=
assparse
(
mtype
((
500
,
3
)))
x
.
data
[(
10
,
1
)]
=
1
x
.
data
[(
20
,
2
)]
=
2
...
...
@@ -150,14 +212,14 @@ class _testCase_dot(unittest.TestCase):
self
.
failUnless
((
z
==
w
)
.
all
()
==
True
)
def
test_missing
(
self
):
raise
NotImplementedError
(
'tests commented out'
)
raise
NotImplementedError
(
'tests commented out
. want to test dotSS and dotSD and dotDS
'
)
def
test_graph_bprop0
(
self
):
# x = tensor.astensor(numpy.random.rand(10,2))
# w = assparse(sparse.csr_matrix(
# numpy.asarray([[1, 0, 3, 0, 5], [0, 0, -2, 0,0]],dtype='float64')
# ))
for
mtype
in
self
.
mtypes_str
:
for
mtype
in
_
mtypes_str
:
# x = tensor.astensor([[1., 2], [3, 4], [2, 1]])
# w = assparse(mtype((500,3)))
# w.data[(10, 1)] = 1
...
...
sparse.py
浏览文件 @
23e67f75
...
...
@@ -32,7 +32,7 @@ def _is_dense_result(x):
"""
if
not
isinstance
(
x
,
SparseResult
)
and
not
isinstance
(
x
,
base_tensor
.
BaseTensor
):
raise
NotImplementedError
(
"_is_sparse should only be called on sparse.SparseResult or base_tensor.BaseTensor, not,"
,
x
)
return
isinstance
(
x
,
SparseResult
)
return
isinstance
(
x
,
base_tensor
.
BaseTensor
)
def
_is_sparse
(
x
):
"""
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论