Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
8054c46b
提交
8054c46b
authored
9月 27, 2012
作者:
Ian Goodfellow
提交者:
Frederic
10月 02, 2012
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
handle case where all outputs are int
上级
c6de7352
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
34 行增加
和
0 行删除
+34
-0
elemwise.py
theano/tensor/elemwise.py
+34
-0
没有找到文件。
theano/tensor/elemwise.py
浏览文件 @
8054c46b
...
@@ -15,6 +15,7 @@ from theano.printing import min_informative_str, pprint
...
@@ -15,6 +15,7 @@ from theano.printing import min_informative_str, pprint
from
theano.gof.python25
import
all
,
any
from
theano.gof.python25
import
all
,
any
from
theano.tensor.utils
import
hash_from_dict
from
theano.tensor.utils
import
hash_from_dict
from
theano.gradient
import
DisconnectedType
from
theano.gradient
import
DisconnectedType
from
theano.gof.null_type
import
NullType
config
=
theano
.
config
config
=
theano
.
config
...
@@ -638,9 +639,42 @@ class Elemwise(Op):
...
@@ -638,9 +639,42 @@ class Elemwise(Op):
def
grad
(
self
,
inputs
,
ograds
):
def
grad
(
self
,
inputs
,
ograds
):
outs
=
self
(
*
inputs
)
if
not
isinstance
(
outs
,
(
list
,
tuple
)):
outs
=
[
outs
]
#compute grad with respect to broadcasted input
#compute grad with respect to broadcasted input
rval
=
self
.
_bgrad
(
inputs
,
ograds
)
rval
=
self
.
_bgrad
(
inputs
,
ograds
)
# TODO: make sure that zeros are clearly identifiable
# to the gradient.grad method when the outputs have
# some integer and some floating point outputs
if
False
in
[
str
(
out
.
type
.
dtype
)
.
find
(
'int'
)
==
-
1
for
out
in
outs
]:
# For integer output, return value may
# only be zero or undefined
# We don't bother with trying to check
# that the scalar ops correctly
# returned something that evaluates to 0,
# we just make the return
# value obviously zero so that gradient.grad
# can tell this op did
# the right thing.
new_rval
=
[]
for
elem
,
ipt
in
zip
(
rval
,
inputs
):
if
isinstance
(
elem
.
type
,
(
NullType
,
DisconnectedType
)):
new_rval
.
append
(
elem
)
else
:
elem
=
ipt
.
zeros_like
()
if
str
(
elem
.
type
.
dtype
)
.
find
(
'int'
)
!=
-
1
:
elem
=
elem
.
astype
(
theano
.
config
.
floatX
)
assert
str
(
elem
.
type
.
dtype
)
.
find
(
'int'
)
==
-
1
new_rval
.
append
(
elem
)
return
new_rval
#sum out the broadcasted dimensions
#sum out the broadcasted dimensions
for
i
,
ipt
in
enumerate
(
inputs
):
for
i
,
ipt
in
enumerate
(
inputs
):
if
rval
[
i
]
is
None
:
if
rval
[
i
]
is
None
:
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论