Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
f43227ba
提交
f43227ba
authored
11月 25, 2010
作者:
James Bergstra
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
modified definition of sparse matrix "shape" property
上级
6026b300
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
19 行增加
和
1 行删除
+19
-1
basic.py
theano/sparse/basic.py
+14
-1
test_basic.py
theano/sparse/tests/test_basic.py
+2
-0
opt.py
theano/tensor/opt.py
+3
-0
没有找到文件。
theano/sparse/basic.py
浏览文件 @
f43227ba
...
...
@@ -248,9 +248,18 @@ class _sparse_py_operators:
def
__dot__
(
left
,
right
):
return
structured_dot
(
left
,
right
)
def
__rdot__
(
right
,
left
):
return
structured_dot
(
left
,
right
)
#N.B. THIS IS COMMENTED OUT ON PURPOSE!!!
# Discussion with Fred & James (at least, and maybe others before)
# we decided that casting from a sparse to dense should be explicit
# because it's usually something you want to be pretty careful about,
# and not to do by accident.
#def _as_TensorVariable(self):
# return dense_from_sparse(self)
shape
=
property
(
lambda
self
:
tensor
.
shape
(
self
))
shape
=
property
(
lambda
self
:
tensor
.
shape
(
dense_from_sparse
(
self
)))
# don't worry!
# ... the plan is that the ShapeFeature in tensor.opt will do shape propagation
# ... and remove the dense_from_sparse from the graph. This will *NOT* actually expand
# ... your sparse matrix just to get the shape.
ndim
=
property
(
lambda
self
:
self
.
type
.
ndim
)
dtype
=
property
(
lambda
self
:
self
.
type
.
dtype
)
...
...
@@ -513,6 +522,8 @@ class DenseFromSparse(gof.op.Op):
return
[
sp_ones_like
(
x
)
*
gz
]
else
:
return
[
SparseFromDense
(
x
.
type
.
format
)(
gz
)]
def
infer_shape
(
self
,
node
,
(
ishape
,)):
return
[
ishape
]
dense_from_sparse
=
DenseFromSparse
()
class
SparseFromDense
(
gof
.
op
.
Op
):
...
...
@@ -535,6 +546,8 @@ class SparseFromDense(gof.op.Op):
out
[
0
]
=
SparseType
.
format_cls
[
self
.
format
](
x
)
def
grad
(
self
,
(
x
,
),
(
gz
,
)):
return
dense_from_sparse
(
gz
),
def
infer_shape
(
self
,
node
,
(
ishape
,)):
return
[
ishape
]
csr_from_dense
=
SparseFromDense
(
'csr'
)
csc_from_dense
=
SparseFromDense
(
'csc'
)
...
...
theano/sparse/tests/test_basic.py
浏览文件 @
f43227ba
...
...
@@ -449,6 +449,8 @@ def test_shape_i():
assert
f
(
sp
.
csr_matrix
(
random_lil
((
100
,
10
),
sparse_dtype
,
3
)))
==
(
10
)
def
test_shape
():
# Test that getting the shape of a sparse variable
# does not actually create a dense tensor in the process.
sparse_dtype
=
'float32'
a
=
SparseType
(
'csr'
,
dtype
=
sparse_dtype
)()
...
...
theano/tensor/opt.py
浏览文件 @
f43227ba
...
...
@@ -407,6 +407,9 @@ class Shape_i(T.Op):
((npy_int64*)PyArray_DATA(
%(out)
s))[0]=CudaNdarray_HOST_DIMS(
%(x)
s)[
%(i)
s];
"""
%
locals
()
else
:
#TODO: if your type is not listed here, make a damn registry of shape_i ops for
# various types of variables.
# Do not continue this madness.
return
super
(
Shape_i
,
self
)
.
c_code
(
node
,
name
,
(
x
,),
(
out
,),
sub
)
def
grad
(
self
,
(
x
,),
(
gz
,)):
return
[
None
]
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论