Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
e72884a4
提交
e72884a4
authored
3月 04, 2013
作者:
Frederic
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Make the apply node of ConstructSparseFromList take the shape as input.
This allow to remove the value itself from the graph earlier.
上级
41d61600
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
24 行增加
和
16 行删除
+24
-16
basic.py
theano/sparse/basic.py
+24
-16
没有找到文件。
theano/sparse/basic.py
浏览文件 @
e72884a4
...
...
@@ -3317,6 +3317,18 @@ class ConstructSparseFromList(gof.Op):
return
self
.
__class__
.
__name__
def
make_node
(
self
,
x
,
values
,
ilist
):
"""
:param x: a matrix that specify the output shape.
:param values: a matrix with the values that we want in the output.
:param ilist: a vector with the same lenght as the number of rows
then values. It specify where in the output to put
the corresponding rows.
This create a sparse matrix with the same shape as `x`. Its
values are the are the rows of `values` moved to the `ilist`
corresponding rows.
"""
x_
=
theano
.
tensor
.
as_tensor_variable
(
x
)
values_
=
theano
.
tensor
.
as_tensor_variable
(
values
)
ilist_
=
theano
.
tensor
.
as_tensor_variable
(
ilist
)
...
...
@@ -3325,23 +3337,19 @@ class ConstructSparseFromList(gof.Op):
raise
TypeError
(
'index must be integers'
)
if
ilist_
.
type
.
ndim
!=
1
:
raise
TypeError
(
'index must be vector'
)
if
x_
.
type
.
ndim
==
0
:
raise
TypeError
(
'cannot index into a scalar'
)
if
values_
.
type
.
ndim
>
x_
.
type
.
ndim
:
raise
TypeError
(
'cannot construct sparse matrix as dimensions differ'
)
return
gof
.
Apply
(
self
,
[
x_
,
values_
,
ilist_
],
if
x_
.
type
.
ndim
!=
2
:
raise
TypeError
(
'cannot create a sparse matrix with
%
d dimensions'
%
x_
.
type
.
ndim
)
if
values_
.
type
.
ndim
!=
2
:
raise
TypeError
(
'cannot create a sparse matrix from values with
%
d ndim'
%
values_
.
type
.
ndim
)
return
gof
.
Apply
(
self
,
[
x_
.
shape
,
values_
,
ilist_
],
[
csc_matrix
(
dtype
=
x
.
dtype
)])
def
perform
(
self
,
node
,
inp
,
out_
):
"""
:param inp: tuple(x, values, ilist)
x: specify the output shape and dtype only.
values: a matrix with the values that we want in the output
ilist: a vector with the same lenght as the number of row
then values. It specify where in the output to put
the corresponding rows.
"""
x
,
values
,
ilist
=
inp
out_shape
,
values
,
ilist
=
inp
out
,
=
out_
rows
,
cols
=
values
.
shape
assert
rows
==
len
(
ilist
)
...
...
@@ -3351,8 +3359,8 @@ class ConstructSparseFromList(gof.Op):
shape
=
(
cols
,
ilist
.
shape
[
0
]))
.
flatten
()
data
=
values
.
T
.
flatten
()
out
[
0
]
=
scipy
.
sparse
.
csc_matrix
((
data
,
indices
,
indptr
),
shape
=
x
.
shape
,
dtype
=
x
.
dtype
)
shape
=
out_
shape
,
dtype
=
values
.
dtype
)
def
infer_shape
(
self
,
node
,
ishapes
):
x
,
y
,
ilist
=
ishapes
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论