Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
e70f9594
提交
e70f9594
authored
6月 13, 2012
作者:
Nicolas Bouchard
提交者:
Frederic
7月 06, 2012
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
complete eliminate_zeros and added tests
上级
13de103e
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
62 行增加
和
0 行删除
+62
-0
sp2.py
theano/sparse/sandbox/sp2.py
+13
-0
test_sp2.py
theano/sparse/tests/test_sp2.py
+49
-0
没有找到文件。
theano/sparse/sandbox/sp2.py
浏览文件 @
e70f9594
...
...
@@ -387,6 +387,10 @@ multinomial = Multinomial()
class
EliminateZeros
(
gof
.
op
.
Op
):
"""Eliminate zeros from the data of the matrix.
This wrap the method eliminate_zeros from scipy.
"""
def
__eq__
(
self
,
other
):
return
(
type
(
self
)
==
type
(
other
))
...
...
@@ -401,6 +405,15 @@ class EliminateZeros(gof.op.Op):
assert
_is_sparse
(
x
)
out
[
0
]
=
x
.
copy
()
out
[
0
]
.
eliminate_zeros
()
def
grad
(
self
,
inputs
,
outputs_gradients
):
return
outputs_gradients
def
infer_shape
(
self
,
node
,
ins_shapes
):
return
ins_shapes
def
__str__
(
self
):
return
self
.
__class__
.
__name__
eliminate_zeros
=
EliminateZeros
()
...
...
theano/sparse/tests/test_sp2.py
浏览文件 @
e70f9594
...
...
@@ -21,6 +21,7 @@ from theano.sparse.sandbox import sp2 as S2
from
theano.tests
import
unittest_tools
as
utt
from
theano.sparse.basic
import
verify_grad_sparse
def
as_sparse_format
(
data
,
format
):
if
format
==
'csc'
:
return
scipy
.
sparse
.
csc_matrix
(
data
)
...
...
@@ -112,6 +113,54 @@ class TestCast(utt.InferShapeTester):
verify_grad_sparse
(
S2
.
Cast
(
'float64'
),
[
a
])
class
EliminateZerosTester
(
utt
.
InferShapeTester
):
indptr
=
np
.
array
([
0
,
2
,
3
,
6
])
indices
=
np
.
array
([
0
,
2
,
2
,
0
,
1
,
2
])
data
=
np
.
array
([
1
,
0
,
3
,
0
,
5
,
6
],
dtype
=
'float32'
)
properties
=
(
data
,
indices
,
indptr
)
x_csc
=
S
.
csc_matrix
(
'csc'
,
dtype
=
'float32'
)
x_csr
=
S
.
csr_matrix
(
'csr'
,
dtype
=
'float32'
)
def
setUp
(
self
):
super
(
EliminateZerosTester
,
self
)
.
setUp
()
self
.
op_class
=
S2
.
EliminateZeros
def
test_eliminate_zeros
(
self
):
f_csc
=
theano
.
function
([
self
.
x_csc
],
S2
.
eliminate_zeros
(
self
.
x_csc
))
f_csr
=
theano
.
function
([
self
.
x_csr
],
S2
.
eliminate_zeros
(
self
.
x_csr
))
a
=
sp
.
csc_matrix
(
self
.
properties
,
dtype
=
'float32'
)
b
=
a
.
copy
()
b
.
eliminate_zeros
()
assert
np
.
all
(
f_csc
(
a
)
.
todense
()
==
b
.
todense
())
a
=
sp
.
csr_matrix
(
self
.
properties
)
b
=
a
.
copy
()
b
.
eliminate_zeros
()
assert
np
.
all
(
f_csr
(
a
)
.
todense
()
==
b
.
todense
())
def
test_infer_shape
(
self
):
a
=
sp
.
csc_matrix
(
self
.
properties
,
dtype
=
'float32'
)
self
.
_compile_and_check
([
self
.
x_csc
],
[
S2
.
eliminate_zeros
(
self
.
x_csc
)],
[
a
],
self
.
op_class
)
a
=
sp
.
csr_matrix
(
self
.
properties
,
dtype
=
'float32'
)
self
.
_compile_and_check
([
self
.
x_csr
],
[
S2
.
eliminate_zeros
(
self
.
x_csr
)],
[
a
],
self
.
op_class
)
def
test_grad
(
self
):
a
=
sp
.
csc_matrix
(
self
.
properties
,
dtype
=
'float32'
)
verify_grad_sparse
(
S2
.
eliminate_zeros
,
[
a
])
a
=
sp
.
csr_matrix
(
self
.
properties
,
dtype
=
'float32'
)
verify_grad_sparse
(
S2
.
eliminate_zeros
,
[
a
])
class
test_structured_add_s_v
(
unittest
.
TestCase
):
def
setUp
(
self
):
utt
.
seed_rng
()
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论