Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
5a04235b
提交
5a04235b
authored
8月 29, 2012
作者:
Ian Goodfellow
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
made some sparse.basic ops work with DisconnectedType
上级
43e64647
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
18 行增加
和
8 行删除
+18
-8
basic.py
theano/sparse/basic.py
+18
-8
没有找到文件。
theano/sparse/basic.py
浏览文件 @
5a04235b
...
@@ -7,7 +7,6 @@ http://www-users.cs.umn.edu/~saad/software/SPARSKIT/paper.ps
...
@@ -7,7 +7,6 @@ http://www-users.cs.umn.edu/~saad/software/SPARSKIT/paper.ps
# TODO
# TODO
# Automatic methods for determining best sparse format?
# Automatic methods for determining best sparse format?
from
itertools
import
izip
import
sys
import
sys
import
numpy
import
numpy
...
@@ -16,7 +15,7 @@ import scipy.sparse
...
@@ -16,7 +15,7 @@ import scipy.sparse
from
theano
import
gof
,
tensor
,
compile
,
scalar
,
config
from
theano
import
gof
,
tensor
,
compile
,
scalar
,
config
from
theano.gof.python25
import
all
from
theano.gof.python25
import
all
from
theano.
tensor
import
blas
from
theano.
gradient
import
DisconnectedType
from
theano.sparse.utils
import
hash_from_sparse
from
theano.sparse.utils
import
hash_from_sparse
import
theano.tests.unittest_tools
as
utt
import
theano.tests.unittest_tools
as
utt
...
@@ -626,7 +625,18 @@ class CSMProperties(gof.Op):
...
@@ -626,7 +625,18 @@ class CSMProperties(gof.Op):
out
[
3
][
0
]
=
theano
.
_asarray
(
csm
.
shape
,
dtype
=
'int32'
)
out
[
3
][
0
]
=
theano
.
_asarray
(
csm
.
shape
,
dtype
=
'int32'
)
def
grad
(
self
,
(
csm
,),
g
):
def
grad
(
self
,
(
csm
,),
g
):
assert
[
gg
is
None
for
gg
in
g
[
1
:]]
#g[1:] is all integers, so their Jacobian in this op
#is 0. We thus don't need to worry about what their values
#are.
#if g[0] is disconnected, then this op doesn't contribute
#any gradient anywhere. but we know that at least one of
#g[1:] is connected, or this grad method wouldn't have been
#called, so we should report zeros
if
isinstance
(
g
[
0
]
.
type
,
DisconnectedType
):
return
[
csm
.
zeros_like
()]
data
,
indices
,
indptr
,
shape
=
csm_properties
(
csm
)
data
,
indices
,
indptr
,
shape
=
csm_properties
(
csm
)
return
[
CSM
(
csm
.
format
)(
g
[
0
],
indices
,
indptr
,
shape
)]
return
[
CSM
(
csm
.
format
)(
g
[
0
],
indices
,
indptr
,
shape
)]
# don't make this a function or it breaks some optimizations below
# don't make this a function or it breaks some optimizations below
...
@@ -662,10 +672,10 @@ class CSM(gof.Op):
...
@@ -662,10 +672,10 @@ class CSM(gof.Op):
:param data: One dimensionnal tensor representing
:param data: One dimensionnal tensor representing
the data of the sparse to construct.
the data of the sparse to construct.
:param indices: One dimension
n
al tensor of integers
:param indices: One dimensional tensor of integers
representing the indices of the sparse
representing the indices of the sparse
matrix to construct.
matrix to construct.
:param indptr: One dimension
n
al tensor of integers
:param indptr: One dimensional tensor of integers
representing the indice pointer for
representing the indice pointer for
the sparse matrix to construct.
the sparse matrix to construct.
:param shape: One dimensionnal tensor of integers
:param shape: One dimensionnal tensor of integers
...
@@ -673,9 +683,9 @@ class CSM(gof.Op):
...
@@ -673,9 +683,9 @@ class CSM(gof.Op):
matrix to construct.
matrix to construct.
:return: A sparse matrix having the properties
:return: A sparse matrix having the properties
spe
fic
ied by the inputs.
spe
cif
ied by the inputs.
:note: The grad method returns a dense vector, so it provide
:note: The grad method returns a dense vector, so it provide
s
a regular grad.
a regular grad.
"""
"""
...
@@ -777,7 +787,7 @@ class CSM(gof.Op):
...
@@ -777,7 +787,7 @@ class CSM(gof.Op):
#unpack the data vector and wrap it as a 1d TensorType
#unpack the data vector and wrap it as a 1d TensorType
g_data
=
csm_grad
(
self
.
kmap
)(
x_data
,
x_indices
,
x_indptr
,
x_shape
,
g_data
=
csm_grad
(
self
.
kmap
)(
x_data
,
x_indices
,
x_indptr
,
x_shape
,
g_data
,
g_indices
,
g_indptr
,
g_shape
)
g_data
,
g_indices
,
g_indptr
,
g_shape
)
return
[
g_data
,
None
,
None
,
None
]
return
[
g_data
,
DisconnectedType
()(),
DisconnectedType
()(),
DisconnectedType
()
]
def
infer_shape
(
self
,
node
,
shapes
):
def
infer_shape
(
self
,
node
,
shapes
):
if
self
.
kmap
is
None
:
if
self
.
kmap
is
None
:
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论