Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
2c9aec23
提交
2c9aec23
authored
9月 06, 2012
作者:
Ian Goodfellow
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
various sparse grads
上级
a5fa15fe
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
19 行增加
和
2 行删除
+19
-2
basic.py
theano/sparse/basic.py
+19
-2
没有找到文件。
theano/sparse/basic.py
浏览文件 @
2c9aec23
...
@@ -18,6 +18,7 @@ from theano.gof.python25 import all
...
@@ -18,6 +18,7 @@ from theano.gof.python25 import all
from
theano.gradient
import
DisconnectedType
from
theano.gradient
import
DisconnectedType
from
theano.sparse.utils
import
hash_from_sparse
from
theano.sparse.utils
import
hash_from_sparse
import
theano.tests.unittest_tools
as
utt
import
theano.tests.unittest_tools
as
utt
from
theano.gradient
import
grad_not_implemented
sparse_formats
=
[
'csc'
,
'csr'
]
sparse_formats
=
[
'csc'
,
'csr'
]
...
@@ -2149,7 +2150,9 @@ class MulSV(gof.op.Op):
...
@@ -2149,7 +2150,9 @@ class MulSV(gof.op.Op):
assert
y
.
type
.
ndim
==
1
assert
y
.
type
.
ndim
==
1
if
x
.
type
.
dtype
!=
y
.
type
.
dtype
:
if
x
.
type
.
dtype
!=
y
.
type
.
dtype
:
raise
NotImplementedError
()
raise
NotImplementedError
(
"MulSV not implemented for differing dtypes."
"Got
%
s and
%
s."
%
(
str
(
x
.
type
.
dtype
),
str
(
y
.
type
.
dtype
)))
return
gof
.
Apply
(
self
,
return
gof
.
Apply
(
self
,
[
x
,
y
],
[
x
,
y
],
[
SparseType
(
dtype
=
x
.
type
.
dtype
,
[
SparseType
(
dtype
=
x
.
type
.
dtype
,
...
@@ -2163,6 +2166,15 @@ class MulSV(gof.op.Op):
...
@@ -2163,6 +2166,15 @@ class MulSV(gof.op.Op):
def
grad
(
self
,
(
x
,
y
),
(
gz
,)):
def
grad
(
self
,
(
x
,
y
),
(
gz
,)):
assert
_is_sparse_variable
(
x
)
and
_is_dense_variable
(
y
)
assert
_is_sparse_variable
(
x
)
and
_is_dense_variable
(
y
)
assert
_is_sparse_variable
(
gz
)
assert
_is_sparse_variable
(
gz
)
# mul_s_v is not implemented if the types vary
if
gz
.
dtype
==
'float64'
and
y
.
dtype
==
'float32'
:
y
=
y
.
astype
(
'float64'
)
if
gz
.
dtype
==
'float32'
and
y
.
dtype
==
'float64'
:
gz
=
gz
.
astype
(
'float64'
)
return
mul_s_v
(
gz
,
y
),
sp_sum
(
x
*
gz
,
axis
=
0
,
sparse_grad
=
True
)
return
mul_s_v
(
gz
,
y
),
sp_sum
(
x
*
gz
,
axis
=
0
,
sparse_grad
=
True
)
def
infer_shape
(
self
,
node
,
ins_shapes
):
def
infer_shape
(
self
,
node
,
ins_shapes
):
...
@@ -2197,6 +2209,11 @@ def mul(x, y):
...
@@ -2197,6 +2209,11 @@ def mul(x, y):
assert
x_is_sparse_variable
or
y_is_sparse_variable
assert
x_is_sparse_variable
or
y_is_sparse_variable
if
x_is_sparse_variable
and
y_is_sparse_variable
:
if
x_is_sparse_variable
and
y_is_sparse_variable
:
# mul_s_s is not implemented if the types differ
if
y
.
dtype
==
'float64'
and
x
.
dtype
==
'float32'
:
x
=
x
.
astype
(
'float64'
)
return
mul_s_s
(
x
,
y
)
return
mul_s_s
(
x
,
y
)
elif
x_is_sparse_variable
and
not
y_is_sparse_variable
:
elif
x_is_sparse_variable
and
not
y_is_sparse_variable
:
...
@@ -3286,7 +3303,7 @@ class SamplingDot(gof.op.Op):
...
@@ -3286,7 +3303,7 @@ class SamplingDot(gof.op.Op):
rval
=
[
rval
=
[
dot
(
p
*
gz
,
y
),
dot
(
p
*
gz
,
y
),
dot
((
p
*
gz
)
.
T
,
x
),
dot
((
p
*
gz
)
.
T
,
x
),
None
grad_not_implemented
(
self
,
2
,
p
)
]
]
return
rval
return
rval
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论