Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
b30ebcdb
提交
b30ebcdb
authored
2月 20, 2012
作者:
Arnaud Bergeron
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Implement verify_grad_sparse as a wrapper around verify_grad.
上级
7ccfbb01
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
46 行增加
和
0 行删除
+46
-0
basic.py
theano/sparse/basic.py
+46
-0
没有找到文件。
theano/sparse/basic.py
浏览文件 @
b30ebcdb
...
@@ -17,6 +17,7 @@ from theano import gof, tensor, compile, scalar, config
...
@@ -17,6 +17,7 @@ from theano import gof, tensor, compile, scalar, config
from
theano.gof.python25
import
all
from
theano.gof.python25
import
all
from
theano.tensor
import
blas
from
theano.tensor
import
blas
from
theano.sparse.utils
import
hash_from_sparse
from
theano.sparse.utils
import
hash_from_sparse
import
theano.tests.unittest_tools
as
utt
sparse_formats
=
[
'csc'
,
'csr'
]
sparse_formats
=
[
'csc'
,
'csr'
]
...
@@ -140,6 +141,51 @@ def as_sparse_or_tensor_variable(x, name=None):
...
@@ -140,6 +141,51 @@ def as_sparse_or_tensor_variable(x, name=None):
return
theano
.
tensor
.
as_tensor_variable
(
x
,
name
)
return
theano
.
tensor
.
as_tensor_variable
(
x
,
name
)
def
verify_grad_sparse
(
op
,
pt
,
*
args
,
**
kwargs
):
"""
Wrapper for theano.test.unittest_tools.py:verify_grad
Converts sparse variables back and forth.
"""
conv_none
=
lambda
x
:
x
def
conv_csr
(
ind
,
indptr
,
shp
):
def
f
(
spdata
):
return
CSR
(
spdata
,
ind
,
indptr
,
shp
)
return
f
def
conv_csc
(
ind
,
indptr
,
shp
):
def
f
(
spdata
):
return
CSC
(
spdata
,
ind
,
indptr
,
shp
)
return
f
iconv
=
[]
dpt
=
[]
for
p
in
pt
:
if
_is_sparse
(
p
):
dpt
.
append
(
p
.
data
)
if
p
.
format
==
'csr'
:
iconv
.
append
(
conv_csr
(
p
.
indices
[:
p
.
size
],
p
.
indptr
,
p
.
shape
))
elif
p
.
format
==
'csc'
:
iconv
.
append
(
conv_csc
(
p
.
indices
[:
p
.
size
],
p
.
indptr
,
p
.
shape
))
else
:
raise
NotImplementedError
(
"No conv for
%
s"
%
(
p
.
format
,))
else
:
dpt
.
append
(
p
)
iconv
.
append
(
conv_none
)
output
=
op
(
*
[
as_sparse_or_tensor_variable
(
p
)
for
p
in
pt
])
if
isinstance
(
output
,
(
list
,
tuple
)):
raise
NotImplementedError
(
"verify_grad can't deal with "
"multiple outputs"
)
if
_is_sparse_variable
(
output
):
oconv
=
dense_from_sparse
else
:
oconv
=
conv_none
def
conv_op
(
*
inputs
):
ipt
=
[
conv
(
i
)
for
i
,
conv
in
zip
(
inputs
,
iconv
)]
out
=
op
(
*
ipt
)
return
oconv
(
out
)
return
utt
.
verify_grad
(
conv_op
,
dpt
,
*
args
,
**
kwargs
)
verify_grad_sparse
.
E_grad
=
utt
.
verify_grad
.
E_grad
def
constant
(
x
,
name
=
None
):
def
constant
(
x
,
name
=
None
):
if
not
isinstance
(
x
,
scipy
.
sparse
.
spmatrix
):
if
not
isinstance
(
x
,
scipy
.
sparse
.
spmatrix
):
raise
TypeError
(
"sparse.constant must be called on a "
raise
TypeError
(
"sparse.constant must be called on a "
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论