Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
bfecc533
提交
bfecc533
authored
11月 24, 2011
作者:
nouiz
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #220 from yaoli/EnsureSortedIndicesReview
Ensure sorted indices reviewed
上级
b410eac0
d6a8421a
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
37 行增加
和
6 行删除
+37
-6
sp.py
theano/sparse/sandbox/sp.py
+15
-5
test_sp.py
theano/sparse/sandbox/test_sp.py
+22
-1
没有找到文件。
theano/sparse/sandbox/sp.py
浏览文件 @
bfecc533
...
...
@@ -254,25 +254,35 @@ class EnsureSortedIndices(Op):
"""
Remove explicit zeros from a sparse matrix, and resort indices
"""
inplace
=
False
def
__init__
(
self
,
inplace
):
self
.
inplace
=
inplace
self
.
inplace
=
inplace
if
self
.
inplace
:
self
.
view_map
=
{
0
:[
0
]}
def
make_node
(
self
,
x
):
return
gof
.
Apply
(
self
,
[
x
],
[
x
.
type
()])
def
perform
(
self
,
node
,
(
x
,),
(
z
,)):
def
perform
(
self
,
node
,
inputs
,
output_storage
):
x
=
inputs
[
0
]
z
=
output_storage
[
0
]
if
self
.
inplace
:
x
.
sort_indices
()
z
[
0
]
=
x
else
:
z
[
0
]
=
x
.
sorted_indices
()
def
grad
(
self
,
(
x
,),
(
gz
,)):
return
[
gz
]
def
grad
(
self
,
inputs
,
output_grad
):
return
[
output_grad
[
0
]]
def
infer_shape
(
self
,
node
,
i0_shapes
):
return
i0_shapes
def
__str__
(
self
):
if
self
.
inplace
:
return
self
.
__class__
.
__name__
+
"{inplace}"
else
:
return
self
.
__class__
.
__name__
+
"{no_inplace}"
ensure_sorted_indices
=
EnsureSortedIndices
(
inplace
=
False
)
...
...
theano/sparse/sandbox/test_sp.py
浏览文件 @
bfecc533
...
...
@@ -16,7 +16,7 @@ from theano import function, tensor
import
theano
from
theano.sparse.sandbox
import
sp
from
theano.tests
import
unittest_tools
as
utt
from
theano.sparse.tests.test_basic
import
random_lil
class
TestSP
(
unittest
.
TestCase
):
def
test_convolution
(
self
):
...
...
@@ -413,6 +413,27 @@ def test_diagonal():
assert
numpy
.
all
(
n
==
f
(
range
(
K
))
.
toarray
())
def
test_ensure_sorted_indices
():
x
=
2000
y
=
2000
sparsity
=
1000
for
i
in
range
(
2
):
# testing both csc and csr
if
i
is
0
:
# csc
input_tensor
=
theano
.
sparse
.
csc_dmatrix
()
sample
=
scipy
.
sparse
.
csc_matrix
(
random_lil
((
x
,
y
),
'float64'
,
sparsity
))
else
:
# csr
input_tensor
=
theano
.
sparse
.
csr_dmatrix
()
sample
=
scipy
.
sparse
.
csr_matrix
(
random_lil
((
x
,
y
),
'float64'
,
sparsity
))
sort_op
=
sp
.
ensure_sorted_indices
(
input_tensor
)
f
=
theano
.
function
([
input_tensor
],
sort_op
)
sorted_scipy
=
sample
.
sorted_indices
()
sorted_theano
=
f
(
sample
)
assert
numpy
.
all
(
sorted_theano
.
todense
()
==
sorted_scipy
.
todense
())
def
test_diagonal_grad
():
def
d
(
x
):
return
sp
.
sp_sum
(
sp
.
square_diagonal
(
x
),
sparse_grad
=
True
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论