Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
46fe0e84
提交
46fe0e84
authored
11月 26, 2010
作者:
Frederic Bastien
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
make Sparse structured_dot work when both matrix are sparse.
上级
382cb4d3
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
32 行增加
和
1 行删除
+32
-1
basic.py
theano/sparse/basic.py
+10
-1
test_basic.py
theano/sparse/tests/test_basic.py
+22
-0
没有找到文件。
theano/sparse/basic.py
浏览文件 @
46fe0e84
...
@@ -790,7 +790,11 @@ class StructuredDot(gof.Op):
...
@@ -790,7 +790,11 @@ class StructuredDot(gof.Op):
dtype_out
=
scalar
.
upcast
(
a
.
type
.
dtype
,
b
.
type
.
dtype
)
dtype_out
=
scalar
.
upcast
(
a
.
type
.
dtype
,
b
.
type
.
dtype
)
if
b
.
type
.
ndim
!=
2
:
if
b
.
type
.
ndim
!=
2
:
raise
NotImplementedError
(
'non-matrix b'
)
raise
NotImplementedError
(
'non-matrix b'
)
return
gof
.
Apply
(
self
,
[
a
,
b
],
[
tensor
.
tensor
(
dtype_out
,
(
False
,
b
.
type
.
broadcastable
[
1
]))])
if
_is_sparse_variable
(
b
):
return
gof
.
Apply
(
self
,
[
a
,
b
],
[
SparseType
(
a
.
type
.
format
,
dtype_out
)()])
else
:
return
gof
.
Apply
(
self
,
[
a
,
b
],
[
tensor
.
tensor
(
dtype_out
,
(
False
,
b
.
type
.
broadcastable
[
1
]))])
def
perform
(
self
,
node
,
(
a
,
b
),
(
out
,)):
def
perform
(
self
,
node
,
(
a
,
b
),
(
out
,)):
if
a
.
shape
[
1
]
!=
b
.
shape
[
0
]:
if
a
.
shape
[
1
]
!=
b
.
shape
[
0
]:
...
@@ -798,6 +802,11 @@ class StructuredDot(gof.Op):
...
@@ -798,6 +802,11 @@ class StructuredDot(gof.Op):
#variable = a.dot(b) # deprecated
#variable = a.dot(b) # deprecated
variable
=
a
*
b
variable
=
a
*
b
if
isinstance
(
node
.
outputs
[
0
]
.
type
,
SparseType
):
assert
_is_sparse
(
variable
)
out
[
0
]
=
variable
return
assert
_is_dense
(
variable
)
# scipy 0.7 automatically converts to dense
assert
_is_dense
(
variable
)
# scipy 0.7 automatically converts to dense
# dot of an NxM sparse matrix, with a Mx1 dense matrix, returns vector not matrix
# dot of an NxM sparse matrix, with a Mx1 dense matrix, returns vector not matrix
...
...
theano/sparse/tests/test_basic.py
浏览文件 @
46fe0e84
...
@@ -344,6 +344,28 @@ class test_structureddot(unittest.TestCase):
...
@@ -344,6 +344,28 @@ class test_structureddot(unittest.TestCase):
outvals
=
f
(
kernvals
,
imvals
)
outvals
=
f
(
kernvals
,
imvals
)
print
outvals
print
outvals
def
test_dot_sparse_sparse
(
self
):
#test dot for 2 input sparse matrix
sparse_dtype
=
'float64'
for
sparse_format
in
[
'csc'
,
'csr'
]:
a
=
SparseType
(
sparse_format
,
dtype
=
sparse_dtype
)()
b
=
SparseType
(
sparse_format
,
dtype
=
sparse_dtype
)()
d
=
theano
.
dot
(
a
,
b
)
f
=
theano
.
function
([
a
,
b
],
theano
.
Out
(
d
,
borrow
=
True
))
topo
=
f
.
maker
.
env
.
toposort
()
for
M
,
N
,
K
,
nnz
in
[(
4
,
3
,
2
,
3
),
(
40
,
30
,
20
,
3
),
(
40
,
30
,
20
,
30
),
(
400
,
3000
,
200
,
6000
),
]:
if
sparse_format
==
'csc'
:
spmat
=
sp
.
csc_matrix
(
random_lil
((
M
,
N
),
sparse_dtype
,
nnz
))
spmat2
=
sp
.
csc_matrix
(
random_lil
((
N
,
K
),
sparse_dtype
,
nnz
))
elif
sparse_format
==
'csr'
:
spmat
=
sp
.
csr_matrix
(
random_lil
((
M
,
N
),
sparse_dtype
,
nnz
))
spmat2
=
sp
.
csr_matrix
(
random_lil
((
N
,
K
),
sparse_dtype
,
nnz
))
f
(
spmat
,
spmat2
)
def
test_csc_correct_output_faster_than_scipy
(
self
):
def
test_csc_correct_output_faster_than_scipy
(
self
):
sparse_dtype
=
'float64'
sparse_dtype
=
'float64'
dense_dtype
=
'float64'
dense_dtype
=
'float64'
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论