Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
e8ee0256
提交
e8ee0256
authored
7月 03, 2012
作者:
Nicolas Bouchard
提交者:
Frederic
7月 06, 2012
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
More corrections.
上级
63b5ea7f
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
28 行增加
和
17 行删除
+28
-17
sp2.py
theano/sparse/sandbox/sp2.py
+27
-15
test_sp2.py
theano/sparse/tests/test_sp2.py
+1
-2
没有找到文件。
theano/sparse/sandbox/sp2.py
浏览文件 @
e8ee0256
...
...
@@ -76,7 +76,7 @@ class HStack(gof.op.Op):
"""Stack sparse matrices horizontally (column wise).
:param blocks: Sequence of sparse array of compatible shape.
:param format: String representing the output format. Defaul
:param format: String representing the output format. Defaul
t
is csc.
:param dtype: Output dtype. Must be specified.
...
...
@@ -87,7 +87,7 @@ class HStack(gof.op.Op):
- The grad implemented is regular, i.e. not structured.
"""
def
__init__
(
self
,
dtype
,
format
=
None
):
def
__init__
(
self
,
format
=
None
,
dtype
=
None
):
if
format
is
None
:
self
.
format
=
'csc'
else
:
...
...
@@ -123,7 +123,6 @@ class HStack(gof.op.Op):
is_continuous
=
[(
inputs
[
i
]
.
dtype
in
tensor
.
continuous_dtypes
)
for
i
in
range
(
len
(
inputs
))]
if
all
(
is_continuous
):
if
_is_sparse_variable
(
gz
):
gz
=
sparse
.
DenseFromSparse
()(
gz
)
...
...
@@ -133,9 +132,15 @@ class HStack(gof.op.Op):
for
x
in
inputs
]))
if
not
isinstance
(
split
,
list
):
split
=
[
split
]
return
[
sparse
.
SparseFromDense
(
self
.
format
)(
s
)
for
s
in
split
]
derivative
=
[
sparse
.
SparseFromDense
(
self
.
format
)(
s
)
for
s
in
split
]
def
choose
(
continuous
,
derivative
):
if
continuous
:
return
derivative
else
:
return
[
None
]
*
len
(
inputs
)
return
None
return
[
choose
(
c
,
d
)
for
c
,
d
in
zip
(
is_continuous
,
derivative
)]
def
infer_shape
(
self
,
node
,
ins_shapes
):
def
_get
(
l
):
...
...
@@ -153,9 +158,9 @@ def hstack(blocks, format=None, dtype=None):
This wrap the method hstack from scipy.
:param blocks: List of sparse array of compatible shape.
:param format: String representing the output format. Defaul
:param format: String representing the output format. Defaul
t
is csc.
:param dtype: Output dtype.
Must be specified.
:param dtype: Output dtype.
:return: The concatenation of the sparse array column wise.
...
...
@@ -164,16 +169,17 @@ def hstack(blocks, format=None, dtype=None):
- The grad implemented is regular, i.e. not structured.
"""
blocks
=
[
as_sparse_variable
(
i
)
for
i
in
blocks
]
if
dtype
is
None
:
raise
ValueError
(
'The output dtype must be specified.'
)
return
HStack
(
dtype
,
format
=
format
)(
*
blocks
)
dtype
=
theano
.
scalar
.
upcast
([
i
.
dtype
for
i
in
blocks
]
)
return
HStack
(
format
=
format
,
dtype
=
dtype
)(
*
blocks
)
class
VStack
(
HStack
):
"""Stack sparse matrices vertically (row wise).
:param blocks: Sequence of sparse array of compatible shape.
:param format: String representing the output format. Defaul
:param format: String representing the output format. Defaul
t
is csc.
:param dtype: Output dtype. Must be specified.
...
...
@@ -194,7 +200,6 @@ class VStack(HStack):
is_continuous
=
[(
inputs
[
i
]
.
dtype
in
tensor
.
continuous_dtypes
)
for
i
in
range
(
len
(
inputs
))]
if
all
(
is_continuous
):
if
_is_sparse_variable
(
gz
):
gz
=
sparse
.
DenseFromSparse
()(
gz
)
...
...
@@ -204,9 +209,15 @@ class VStack(HStack):
for
x
in
inputs
]))
if
not
isinstance
(
split
,
list
):
split
=
[
split
]
return
[
sparse
.
SparseFromDense
(
self
.
format
)(
s
)
for
s
in
split
]
derivative
=
[
sparse
.
SparseFromDense
(
self
.
format
)(
s
)
for
s
in
split
]
def
choose
(
continuous
,
derivative
):
if
continuous
:
return
derivative
else
:
return
[
None
]
*
len
(
inputs
)
return
None
return
[
choose
(
c
,
d
)
for
c
,
d
in
zip
(
is_continuous
,
derivative
)]
def
infer_shape
(
self
,
node
,
ins_shapes
):
def
_get
(
l
):
...
...
@@ -221,7 +232,7 @@ def vstack(blocks, format=None, dtype=None):
This wrap the method vstack from scipy.
:param blocks: List of sparse array of compatible shape.
:param format: String representing the output format. Defaul
:param format: String representing the output format. Defaul
t
is csc.
:param dtype: Output dtype.
...
...
@@ -232,8 +243,9 @@ def vstack(blocks, format=None, dtype=None):
- The grad implemented is regular, i.e. not structured.
"""
blocks
=
[
as_sparse_variable
(
i
)
for
i
in
blocks
]
if
dtype
is
None
:
raise
ValueError
(
'The output dtype must be specified.'
)
dtype
=
theano
.
scalar
.
upcast
([
i
.
dtype
for
i
in
blocks
]
)
return
VStack
(
format
=
format
,
dtype
=
dtype
)(
*
blocks
)
...
...
theano/sparse/tests/test_sp2.py
浏览文件 @
e8ee0256
...
...
@@ -163,8 +163,7 @@ class _HVStackTester(utt.InferShapeTester):
def
test_infer_shape
(
self
):
for
format
in
sparse
.
sparse_formats
:
self
.
_compile_and_check
(
self
.
x
[
format
],
[
self
.
op_class
(
theano
.
config
.
floatX
)
(
*
self
.
x
[
format
])],
[
self
.
op_class
(
dtype
=
'float64'
)(
*
self
.
x
[
format
])],
self
.
mat
[
format
],
self
.
op_class
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论