Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
3c9177df
提交
3c9177df
authored
3月 26, 2012
作者:
nouiz
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #568 from ynd/sp_sandbox
Remove AddSSData Optimization
上级
ebf5ff54
60027c57
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
0 行增加
和
60 行删除
+0
-60
sp2.py
theano/sparse/sandbox/sp2.py
+0
-60
没有找到文件。
theano/sparse/sandbox/sp2.py
浏览文件 @
3c9177df
...
@@ -36,66 +36,6 @@ fcast = Cast('float32')
...
@@ -36,66 +36,6 @@ fcast = Cast('float32')
dcast
=
Cast
(
'float64'
)
dcast
=
Cast
(
'float64'
)
# register a specialization to replace AddSS -> AddSSData
@gof.local_optimizer
([
add_s_s
])
def
local_add_s_s
(
node
):
"""
If two matrices are known to have the same sparsity pattern,
optimize the addition by only adding their data vector.
Very special case optimization. Activate when for add(x, y),
y is an expression like sp_ones_like(x) * another_matrix.
This is useful for sparse weight updates.
Work also for add(x, neg(y)) in the same case.
As of this writting sub is only implemented as x + neg(y) for
sparse matrix.
"""
if
node
.
op
==
add_s_s
:
x
,
y
=
node
.
inputs
# In case addition was transformed to subtraction
if
hasattr
(
y
.
owner
,
'op'
)
and
y
.
owner
.
op
==
neg
:
y_
=
y
.
owner
.
inputs
[
0
]
else
:
y_
=
y
if
y_
.
owner
is
None
:
return
False
if
hasattr
(
y_
.
owner
,
'op'
)
and
y_
.
owner
.
op
not
in
[
mul_s_s
,
mul_s_d
]:
return
False
def
same_pattern
(
node
):
"""Check node has same sparsity as x."""
# In case the sparse matrix is multiplied by a scalar (ex:
# learning rate)
if
hasattr
(
node
.
owner
,
'op'
)
and
node
.
owner
.
op
==
mul_scalar
:
node
=
node
.
owner
.
inputs
[
1
]
# Check node creates a matrix
if
not
hasattr
(
node
.
owner
,
'op'
)
or
not
isinstance
(
node
.
owner
.
op
,
CSM
):
return
False
# Check matrix is creates from CSMProperties
if
filter
(
lambda
i
:
not
hasattr
(
i
.
owner
,
'op'
)
or
not
isinstance
(
i
.
owner
.
op
,
CSMProperties
),
node
.
owner
.
inputs
[
1
:]):
return
False
# Verify indices, indptr and shape are the same as x
if
filter
(
lambda
i
:
i
.
owner
.
inputs
[
0
]
!=
x
,
node
.
owner
.
inputs
[
1
:]):
return
False
return
True
if
filter
(
same_pattern
,
y_
.
owner
.
inputs
):
return
[
add_s_s_data
(
x
,
y
)]
return
False
register_specialize
(
local_add_s_s
)
class
AddSSData
(
gof
.
op
.
Op
):
class
AddSSData
(
gof
.
op
.
Op
):
'''Add two sparse matrices assuming they have the same sparsity
'''Add two sparse matrices assuming they have the same sparsity
pattern. '''
pattern. '''
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论