Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
57e65e2b
提交
57e65e2b
authored
4月 17, 2012
作者:
Yann N. Dauphin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
added tests for structured_add_s_v and bugfix gradient
上级
e62834b9
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
89 行增加
和
1 行删除
+89
-1
sp2.py
theano/sparse/sandbox/sp2.py
+1
-1
test_sp2.py
theano/sparse/tests/test_sp2.py
+88
-0
没有找到文件。
theano/sparse/sandbox/sp2.py
浏览文件 @
57e65e2b
...
@@ -494,7 +494,7 @@ class StructuredAddSV(gof.op.Op):
...
@@ -494,7 +494,7 @@ class StructuredAddSV(gof.op.Op):
def
grad
(
self
,
(
x
,
y
),
(
gz
,)):
def
grad
(
self
,
(
x
,
y
),
(
gz
,)):
assert
_is_sparse_variable
(
x
)
and
not
_is_sparse_variable
(
y
)
assert
_is_sparse_variable
(
x
)
and
not
_is_sparse_variable
(
y
)
assert
_is_sparse_variable
(
gz
)
assert
_is_sparse_variable
(
gz
)
return
gz
,
gz
.
sum
(
0
)
return
gz
,
sum
(
gz
,
0
)
structured_add_s_v
=
StructuredAddSV
()
structured_add_s_v
=
StructuredAddSV
()
...
...
theano/sparse/tests/test_sp2.py
0 → 100644
浏览文件 @
57e65e2b
import
time
import
unittest
from
nose.plugins.skip
import
SkipTest
import
numpy
try
:
import
scipy.sparse
as
sp
import
scipy.sparse
except
ImportError
:
pass
# The variable enable_sparse will be used to disable the test file.
import
theano
from
theano
import
tensor
as
T
from
theano
import
sparse
as
S
from
theano.sparse.sandbox
import
sp2
as
S2
from
theano.tests
import
unittest_tools
as
utt
if
S
.
enable_sparse
==
False
:
raise
SkipTest
(
'Optional package sparse disabled'
)
def
as_sparse_format
(
data
,
format
):
if
format
==
'csc'
:
return
scipy
.
sparse
.
csc_matrix
(
data
)
elif
format
==
'csr'
:
return
scipy
.
sparse
.
csr_matrix
(
data
)
else
:
raise
NotImplementedError
()
def
eval_outputs
(
outputs
):
return
compile
.
function
([],
outputs
)()[
0
]
def
random_lil
(
shape
,
dtype
,
nnz
):
rval
=
sp
.
lil_matrix
(
shape
,
dtype
=
dtype
)
huge
=
2
**
30
for
k
in
range
(
nnz
):
# set non-zeros in random locations (row x, col y)
idx
=
numpy
.
random
.
random_integers
(
huge
,
size
=
len
(
shape
))
%
shape
value
=
numpy
.
random
.
rand
()
#if dtype *int*, value will always be zeros!
if
"int"
in
dtype
:
value
=
int
(
value
*
100
)
rval
.
__setitem__
(
idx
,
value
)
return
rval
class
test_structured_add_s_v
(
unittest
.
TestCase
):
def
setUp
(
self
):
utt
.
seed_rng
()
def
test_structured_add_s_v_grad
(
self
):
sp_types
=
{
'csc'
:
sp
.
csc_matrix
,
'csr'
:
sp
.
csr_matrix
}
for
format
in
[
'csr'
]:
for
dtype
in
[
'float32'
,
'float64'
]:
spmat
=
sp_types
[
format
](
random_lil
((
4
,
3
),
dtype
,
3
))
mat
=
numpy
.
ones
(
3
,
dtype
=
dtype
)
S
.
verify_grad_sparse
(
S2
.
structured_add_s_v
,
[
spmat
,
mat
],
structured
=
True
)
def
test_structured_add_s_v
(
self
):
sp_types
=
{
'csc'
:
sp
.
csc_matrix
,
'csr'
:
sp
.
csr_matrix
}
for
format
in
[
'csr'
]:
for
dtype
in
[
'float32'
,
'float64'
]:
x
=
S
.
SparseType
(
format
,
dtype
=
dtype
)()
y
=
T
.
vector
(
dtype
=
dtype
)
f
=
theano
.
function
([
x
,
y
],
S2
.
structured_add_s_v
(
x
,
y
))
spmat
=
sp_types
[
format
](
random_lil
((
4
,
3
),
dtype
,
3
))
spones
=
spmat
.
copy
()
spones
.
data
=
numpy
.
ones_like
(
spones
.
data
)
mat
=
numpy
.
ones
(
3
,
dtype
=
dtype
)
out
=
f
(
spmat
,
mat
)
assert
numpy
.
all
(
out
.
toarray
()
==
spones
.
multiply
(
spmat
+
mat
))
if
__name__
==
'__main__'
:
unittest
.
main
()
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论