Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
4a12110c
提交
4a12110c
authored
1月 08, 2014
作者:
Frédéric Bastien
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1691 from SuperElectric/sparse_stack_fix
Bugfix in sparse.hstack(), sparse.vstack()
上级
1d9767b5
4b1ece1b
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
33 行增加
和
4 行删除
+33
-4
basic.py
theano/sparse/basic.py
+3
-3
test_basic.py
theano/sparse/tests/test_basic.py
+30
-1
没有找到文件。
theano/sparse/basic.py
浏览文件 @
4a12110c
...
@@ -1820,7 +1820,7 @@ class AddSD(gof.op.Op):
...
@@ -1820,7 +1820,7 @@ class AddSD(gof.op.Op):
pos = row * Yi + col * Yj;
pos = row * Yi + col * Yj;
zdata[pos] = ydata[pos] + data[ind];
zdata[pos] = ydata[pos] + data[ind];
}
}
}
}
}
}
"""
%
dict
(
locals
(),
**
sub
)
"""
%
dict
(
locals
(),
**
sub
)
return
code
return
code
...
@@ -2302,7 +2302,7 @@ def hstack(blocks, format=None, dtype=None):
...
@@ -2302,7 +2302,7 @@ def hstack(blocks, format=None, dtype=None):
blocks
=
[
as_sparse_variable
(
i
)
for
i
in
blocks
]
blocks
=
[
as_sparse_variable
(
i
)
for
i
in
blocks
]
if
dtype
is
None
:
if
dtype
is
None
:
dtype
=
theano
.
scalar
.
upcast
([
i
.
dtype
for
i
in
blocks
])
dtype
=
theano
.
scalar
.
upcast
(
*
[
i
.
dtype
for
i
in
blocks
])
return
HStack
(
format
=
format
,
dtype
=
dtype
)(
*
blocks
)
return
HStack
(
format
=
format
,
dtype
=
dtype
)(
*
blocks
)
...
@@ -2378,7 +2378,7 @@ def vstack(blocks, format=None, dtype=None):
...
@@ -2378,7 +2378,7 @@ def vstack(blocks, format=None, dtype=None):
blocks
=
[
as_sparse_variable
(
i
)
for
i
in
blocks
]
blocks
=
[
as_sparse_variable
(
i
)
for
i
in
blocks
]
if
dtype
is
None
:
if
dtype
is
None
:
dtype
=
theano
.
scalar
.
upcast
([
i
.
dtype
for
i
in
blocks
])
dtype
=
theano
.
scalar
.
upcast
(
*
[
i
.
dtype
for
i
in
blocks
])
return
VStack
(
format
=
format
,
dtype
=
dtype
)(
*
blocks
)
return
VStack
(
format
=
format
,
dtype
=
dtype
)(
*
blocks
)
...
...
theano/sparse/tests/test_basic.py
浏览文件 @
4a12110c
...
@@ -1950,7 +1950,7 @@ class Test_getitem(unittest.TestCase):
...
@@ -1950,7 +1950,7 @@ class Test_getitem(unittest.TestCase):
assert
r1
.
shape
==
t1
.
shape
assert
r1
.
shape
==
t1
.
shape
assert
numpy
.
all
(
t1
.
toarray
()
==
r1
.
toarray
())
assert
numpy
.
all
(
t1
.
toarray
()
==
r1
.
toarray
())
"""
"
"""
Important: based on a discussion with both Fred and James
Important: based on a discussion with both Fred and James
The following indexing methods is not supported because the rval
The following indexing methods is not supported because the rval
would be a sparse matrix rather than a sparse vector, which is a
would be a sparse matrix rather than a sparse vector, which is a
...
@@ -2463,6 +2463,35 @@ def elemwise_checker(op, expected_f, gap=None, test_dtypes=None,
...
@@ -2463,6 +2463,35 @@ def elemwise_checker(op, expected_f, gap=None, test_dtypes=None,
return
Tester
return
Tester
def
test_hstack_vstack
():
"""
Tests sparse.hstack and sparse.vstack (as opposed to the HStack and VStack
classes that they wrap).
"""
def
make_block
(
dtype
):
return
theano
.
sparse
.
csr_matrix
(
name
=
"
%
s block"
%
dtype
,
dtype
=
dtype
)
def
get_expected_dtype
(
blocks
,
to_dtype
):
if
to_dtype
is
None
:
block_dtypes
=
tuple
(
b
.
dtype
for
b
in
blocks
)
return
theano
.
scalar
.
upcast
(
*
block_dtypes
)
else
:
return
to_dtype
# a deliberately weird mix of dtypes to stack
dtypes
=
(
'complex128'
,
theano
.
config
.
floatX
)
blocks
=
[
make_block
(
dtype
)
for
dtype
in
dtypes
]
for
stack_dimension
,
stack_function
in
enumerate
((
theano
.
sparse
.
vstack
,
theano
.
sparse
.
hstack
)):
for
to_dtype
in
(
None
,
)
+
dtypes
:
stacked_blocks
=
stack_function
(
blocks
,
dtype
=
to_dtype
)
expected_dtype
=
get_expected_dtype
(
blocks
,
to_dtype
)
assert
stacked_blocks
.
dtype
==
expected_dtype
def
structure_function
(
f
,
index
=
0
):
def
structure_function
(
f
,
index
=
0
):
"""Decorator to structure a function wich
"""Decorator to structure a function wich
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论