Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
09e09da0
提交
09e09da0
authored
11月 24, 2014
作者:
Frederic
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
sparse.Dot() test grad with mixed sparse/dense.
Do not enforce that if the input is sparse, we need the grad to return sparse.
上级
2b076111
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
30 行增加
和
9 行删除
+30
-9
gradient.py
theano/gradient.py
+11
-8
basic.py
theano/sparse/basic.py
+5
-1
test_basic.py
theano/sparse/tests/test_basic.py
+14
-0
没有找到文件。
theano/gradient.py
浏览文件 @
09e09da0
...
@@ -1088,14 +1088,17 @@ def _populate_grad_dict(var_to_app_to_idx,
...
@@ -1088,14 +1088,17 @@ def _populate_grad_dict(var_to_app_to_idx,
if
len
(
input_grads
)
!=
len
(
inputs
):
if
len
(
input_grads
)
!=
len
(
inputs
):
raise
ValueError
((
"
%
s returned the wrong number of"
+
raise
ValueError
((
"
%
s returned the wrong number of"
+
" gradient terms."
)
%
str
(
node
.
op
))
" gradient terms."
)
%
str
(
node
.
op
))
# We can not enforce this, as AdvancedSubtensor1 have an option to
for
ig
,
i
in
zip
(
input_grads
,
inputs
):
# return the sparse grad for optimization reason.
if
(
not
isinstance
(
ig
.
type
,
DisconnectedType
)
and
type
(
ig
.
type
)
!=
type
(
i
.
type
)):
# for ig, i in zip(input_grads, inputs):
raise
ValueError
(
# if (not isinstance(ig.type, (DisconnectedType, NullType)) and
"
%
s returned the wrong type for gradient terms."
# type(ig.type) != type(i.type)):
" Sparse inputs must have sparse grads and dense"
# raise ValueError(
" inputs must have dense grad"
%
str
(
node
.
op
))
# "%s returned the wrong type for gradient terms."
# " Sparse inputs must have sparse grads and dense"
# " inputs must have dense grad. Got %s, expected %s" % (
# str(node.op), ig.type, i.type))
# must convert to list in case the op returns a tuple
# must convert to list in case the op returns a tuple
# we won't be able to post-process out the Nones if it does that
# we won't be able to post-process out the Nones if it does that
...
...
theano/sparse/basic.py
浏览文件 @
09e09da0
...
@@ -3709,11 +3709,15 @@ class Dot(gof.op.Op):
...
@@ -3709,11 +3709,15 @@ class Dot(gof.op.Op):
raise
NotImplementedError
()
raise
NotImplementedError
()
def
make_node
(
self
,
x
,
y
):
def
make_node
(
self
,
x
,
y
):
dtype_out
=
scalar
.
upcast
(
x
.
type
.
dtype
,
y
.
type
.
dtype
)
dtype_out
=
scalar
.
upcast
(
x
.
dtype
,
y
.
dtype
)
# Sparse dot product should have at least one sparse variable
# Sparse dot product should have at least one sparse variable
# as input. If the other one is not sparse, it has to be converted
# as input. If the other one is not sparse, it has to be converted
# into a tensor.
# into a tensor.
if
isinstance
(
x
,
scipy
.
sparse
.
spmatrix
):
x
=
as_sparse_variable
(
x
)
if
isinstance
(
y
,
scipy
.
sparse
.
spmatrix
):
y
=
as_sparse_variable
(
y
)
x_is_sparse_var
=
_is_sparse_variable
(
x
)
x_is_sparse_var
=
_is_sparse_variable
(
x
)
y_is_sparse_var
=
_is_sparse_variable
(
y
)
y_is_sparse_var
=
_is_sparse_variable
(
y
)
...
...
theano/sparse/tests/test_basic.py
浏览文件 @
09e09da0
...
@@ -1337,6 +1337,20 @@ class DotTests(utt.InferShapeTester):
...
@@ -1337,6 +1337,20 @@ class DotTests(utt.InferShapeTester):
dtype
=
intX
)
dtype
=
intX
)
f
(
i
,
a
)
f
(
i
,
a
)
def
test_csr_dense_grad
(
self
):
#shortcut: testing csc in float32, testing csr in float64
# allocate a random sparse matrix
spmat
=
sp
.
csr_matrix
(
random_lil
((
4
,
3
),
'float64'
,
3
))
mat
=
numpy
.
asarray
(
numpy
.
random
.
randn
(
2
,
4
),
'float64'
)
def
buildgraph_T
(
mat
):
return
Dot
()(
mat
,
spmat
)
theano
.
tests
.
unittest_tools
.
verify_grad
(
buildgraph_T
,
[
mat
])
class
UsmmTests
(
unittest
.
TestCase
):
class
UsmmTests
(
unittest
.
TestCase
):
""" Test the Usmm and UsmmCscDense class and related optimization """
""" Test the Usmm and UsmmCscDense class and related optimization """
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论