Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
42080b8d
提交
42080b8d
authored
1月 16, 2009
作者:
James Bergstra
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
sparse operators neg and sub, and changed definition of grad(sparse.add)
上级
58f2b986
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
23 行增加
和
3 行删除
+23
-3
__init__.py
theano/__init__.py
+1
-0
basic.py
theano/sparse/basic.py
+22
-3
没有找到文件。
theano/__init__.py
浏览文件 @
42080b8d
...
...
@@ -128,6 +128,7 @@ def __src_version__():
def
dot
(
l
,
r
):
"""Return a symbolic matrix/dot product between l and r """
rval
=
NotImplemented
e0
,
e1
=
None
,
None
if
rval
==
NotImplemented
and
hasattr
(
l
,
'__dot__'
):
try
:
...
...
theano/sparse/basic.py
浏览文件 @
42080b8d
...
...
@@ -6,7 +6,7 @@ To read about different sparse formats, see U{http://www-users.cs.umn.edu/~saad/
@todo: Automatic methods for determining best sparse format?
"""
import
sys
import
sys
,
operator
import
numpy
from
scipy
import
sparse
...
...
@@ -177,8 +177,11 @@ csr_matrix = Sparse(format='csr')
class
_sparse_py_operators
:
T
=
property
(
lambda
self
:
transpose
(
self
),
doc
=
"Return aliased transpose of self (read-only)"
)
def
__neg__
(
self
):
return
neg
(
self
)
def
__add__
(
left
,
right
):
return
add
(
left
,
right
)
def
__radd__
(
right
,
left
):
return
add
(
left
,
right
)
def
__sub__
(
left
,
right
):
return
sub
(
left
,
right
)
def
__rsub__
(
right
,
left
):
return
sub
(
left
,
right
)
def
__mul__
(
left
,
right
):
return
mul
(
left
,
right
)
def
__rmul__
(
left
,
right
):
return
mul
(
left
,
right
)
...
...
@@ -410,8 +413,20 @@ class Transpose(gof.op.Op):
return
transpose
(
gz
),
transpose
=
Transpose
()
class
Neg
(
gof
.
op
.
Op
):
def
make_node
(
self
,
x
):
x
=
as_sparse
(
x
)
return
gof
.
Apply
(
self
,
[
x
],
[
x
.
type
()])
def
perform
(
self
,
node
,
(
x
,
),
(
out
,
)):
assert
_is_sparse
(
x
)
out
[
0
]
=
-
x
def
grad
(
self
,
(
x
,),
(
gz
,)):
assert
_is_sparse_result
(
x
)
and
_is_sparse_result
(
gz
)
return
-
gz
,
neg
=
Neg
()
class
AddSS
(
gof
.
op
.
Op
):
'''
Add two sparse matrices '''
'''Add two sparse matrices '''
def
make_node
(
self
,
x
,
y
):
x
,
y
=
map
(
as_sparse
,
[
x
,
y
])
if
x
.
type
.
dtype
!=
y
.
type
.
dtype
:
...
...
@@ -450,7 +465,7 @@ class AddSD(gof.op.Op):
def
grad
(
self
,
(
x
,
y
),
(
gz
,)):
assert
_is_sparse_result
(
x
)
and
_is_dense_result
(
y
)
assert
_is_dense_result
(
gz
)
return
SparseFromDense
(
x
.
type
.
format
)(
gz
)
,
gz
return
sp_one_like
(
x
)
*
gz
,
gz
add_s_d
=
AddSD
()
def
add
(
x
,
y
):
"""
...
...
@@ -467,6 +482,10 @@ def add(x,y):
elif
x_is_sparse_result
and
not
y_is_sparse_result
:
return
add_s_d
(
x
,
y
)
elif
y_is_sparse_result
and
not
x_is_sparse_result
:
return
add_s_d
(
y
,
x
)
else
:
raise
NotImplementedError
()
def
sub
(
x
,
y
):
return
x
+
(
-
y
)
class
MulSS
(
gof
.
op
.
Op
):
''' Elementwise multiply a sparse and a ndarray '''
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论