Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
2a28db96
提交
2a28db96
authored
6月 21, 2012
作者:
Nicolas Bouchard
提交者:
Frederic
7月 06, 2012
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add missing methods to AddSSData
上级
4171ff4c
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
76 行增加
和
3 行删除
+76
-3
sp2.py
theano/sparse/sandbox/sp2.py
+30
-3
test_sp2.py
theano/sparse/tests/test_sp2.py
+46
-0
没有找到文件。
theano/sparse/sandbox/sp2.py
浏览文件 @
2a28db96
...
@@ -248,8 +248,19 @@ def hstack(blocks, format=None, dtype=None):
...
@@ -248,8 +248,19 @@ def hstack(blocks, format=None, dtype=None):
class
AddSSData
(
gof
.
op
.
Op
):
class
AddSSData
(
gof
.
op
.
Op
):
'''Add two sparse matrices assuming they have the same sparsity
"""Add two sparse matrices assuming they have the same sparsity
pattern. '''
pattern.
:Parameters:
- `x`: Sparse matrix.
- `y`: Sparse matrix.
:return: The sum of the two sparse matrix element wise.
:note: `x` and `y` are assumed to have the same sparsity pattern.
The grad implemented is structured.
"""
def
__eq__
(
self
,
other
):
def
__eq__
(
self
,
other
):
return
(
type
(
self
)
==
type
(
other
))
return
(
type
(
self
)
==
type
(
other
))
...
@@ -270,8 +281,24 @@ class AddSSData(gof.op.Op):
...
@@ -270,8 +281,24 @@ class AddSSData(gof.op.Op):
def
perform
(
self
,
node
,
(
x
,
y
),
(
out
,
)):
def
perform
(
self
,
node
,
(
x
,
y
),
(
out
,
)):
assert
_is_sparse
(
x
)
and
_is_sparse
(
y
)
assert
_is_sparse
(
x
)
and
_is_sparse
(
y
)
assert
x
.
shape
==
y
.
shape
assert
x
.
shape
==
y
.
shape
assert
x
.
data
.
shape
==
y
.
data
.
shape
out
[
0
]
=
x
.
copy
()
out
[
0
]
=
x
.
copy
()
out
[
0
]
.
data
+=
y
.
data
out
[
0
]
.
data
+=
y
.
data
def
grad
(
self
,
inputs
,
(
gz
,
)):
is_continuous
=
[(
i
.
dtype
in
sparse
.
continuous_dtypes
)
for
i
in
inputs
]
if
all
(
is_continuous
):
return
[
gz
,
gz
]
else
:
return
[
None
]
*
len
(
inputs
)
def
infer_shape
(
self
,
node
,
ins_shapes
):
return
[
ins_shapes
[
0
]]
def
__str__
(
self
):
return
self
.
__class__
.
__name__
add_s_s_data
=
AddSSData
()
add_s_s_data
=
AddSSData
()
...
@@ -624,7 +651,7 @@ def structured_monoid(tensor_op):
...
@@ -624,7 +651,7 @@ def structured_monoid(tensor_op):
"""
"""
Generic operation to perform many kinds of monoid element-wise
Generic operation to perform many kinds of monoid element-wise
operations on the non-zeros of a sparse matrix.
operations on the non-zeros of a sparse matrix.
The first parameter must always be a sparse matrix. The other parameters
The first parameter must always be a sparse matrix. The other parameters
must be scalars which will be passed as argument to the tensor_op.
must be scalars which will be passed as argument to the tensor_op.
"""
"""
...
...
theano/sparse/tests/test_sp2.py
浏览文件 @
2a28db96
...
@@ -202,6 +202,52 @@ def _hv_switch(op, expected_function):
...
@@ -202,6 +202,52 @@ def _hv_switch(op, expected_function):
HStackTester
=
_hv_switch
(
S2
.
HStack
,
sp
.
hstack
)
HStackTester
=
_hv_switch
(
S2
.
HStack
,
sp
.
hstack
)
VStackTester
=
_hv_switch
(
S2
.
VStack
,
sp
.
vstack
)
VStackTester
=
_hv_switch
(
S2
.
VStack
,
sp
.
vstack
)
class
AddSSDataTester
(
utt
.
InferShapeTester
):
x
=
{}
a
=
{}
def
setUp
(
self
):
super
(
AddSSDataTester
,
self
)
.
setUp
()
self
.
op_class
=
S2
.
AddSSData
for
format
in
sparse
.
sparse_formats
:
variable
=
getattr
(
theano
.
sparse
,
format
+
'_matrix'
)
rand
=
np
.
array
(
np
.
random
.
random_integers
(
3
,
size
=
(
3
,
4
))
-
1
,
dtype
=
theano
.
config
.
floatX
)
constant
=
as_sparse_format
(
rand
,
format
)
self
.
x
[
format
]
=
[
variable
()
for
t
in
range
(
2
)]
self
.
a
[
format
]
=
[
constant
for
t
in
range
(
2
)]
def
test_op
(
self
):
for
format
in
sparse
.
sparse_formats
:
f
=
theano
.
function
(
self
.
x
[
format
],
S2
.
add_s_s_data
(
*
self
.
x
[
format
]))
tested
=
f
(
*
self
.
a
[
format
])
expected
=
2
*
self
.
a
[
format
][
0
]
assert
np
.
allclose
(
tested
.
toarray
(),
expected
.
toarray
())
assert
tested
.
format
==
expected
.
format
assert
tested
.
dtype
==
expected
.
dtype
def
test_infer_shape
(
self
):
for
format
in
sparse
.
sparse_formats
:
self
.
_compile_and_check
(
self
.
x
[
format
],
[
S2
.
add_s_s_data
(
*
self
.
x
[
format
])],
self
.
a
[
format
],
self
.
op_class
)
def
test_grad
(
self
):
for
format
in
sparse
.
sparse_formats
:
verify_grad_sparse
(
self
.
op_class
(),
self
.
a
[
format
],
structured
=
True
)
class
test_structured_add_s_v
(
unittest
.
TestCase
):
class
test_structured_add_s_v
(
unittest
.
TestCase
):
def
setUp
(
self
):
def
setUp
(
self
):
utt
.
seed_rng
()
utt
.
seed_rng
()
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论