Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
2566bedd
提交
2566bedd
authored
11月 08, 2016
作者:
Pascal Lamblin
提交者:
GitHub
11月 08, 2016
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #5175 from abergeron/fix_elem_grad_bool
Fix grad of elemwise with boolean inputs.
上级
1db72747
229d874b
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
10 行增加
和
13 行删除
+10
-13
elemwise.py
theano/tensor/elemwise.py
+5
-13
test_elemwise.py
theano/tensor/tests/test_elemwise.py
+5
-0
没有找到文件。
theano/tensor/elemwise.py
浏览文件 @
2566bedd
...
@@ -9,6 +9,7 @@ from six.moves import xrange
...
@@ -9,6 +9,7 @@ from six.moves import xrange
import
theano
import
theano
from
theano
import
gof
from
theano
import
gof
from
theano.compat
import
izip
from
theano.compat
import
izip
from
theano.configparser
import
change_flags
from
theano.gof
import
Apply
,
Op
,
OpenMPOp
from
theano.gof
import
Apply
,
Op
,
OpenMPOp
from
theano
import
scalar
from
theano
import
scalar
from
theano.scalar
import
get_scalar_type
from
theano.scalar
import
get_scalar_type
...
@@ -667,8 +668,8 @@ second dimension
...
@@ -667,8 +668,8 @@ second dimension
# TODO: make sure that zeros are clearly identifiable
# TODO: make sure that zeros are clearly identifiable
# to the gradient.grad method when the outputs have
# to the gradient.grad method when the outputs have
# some integer and some floating point outputs
# some integer and some floating point outputs
if
False
in
[
str
(
out
.
type
.
dtype
)
.
find
(
'int'
)
==
-
1
if
any
(
out
.
type
.
dtype
not
in
theano
.
tensor
.
continuous_dtypes
for
out
in
outs
]
:
for
out
in
outs
)
:
# For integer output, return value may
# For integer output, return value may
# only be zero or undefined
# only be zero or undefined
# We don't bother with trying to check
# We don't bother with trying to check
...
@@ -684,7 +685,7 @@ second dimension
...
@@ -684,7 +685,7 @@ second dimension
new_rval
.
append
(
elem
)
new_rval
.
append
(
elem
)
else
:
else
:
elem
=
ipt
.
zeros_like
()
elem
=
ipt
.
zeros_like
()
if
str
(
elem
.
type
.
dtype
)
.
find
(
'int'
)
!=
-
1
:
if
str
(
elem
.
type
.
dtype
)
not
in
theano
.
tensor
.
continuous_dtypes
:
elem
=
elem
.
astype
(
theano
.
config
.
floatX
)
elem
=
elem
.
astype
(
theano
.
config
.
floatX
)
assert
str
(
elem
.
type
.
dtype
)
.
find
(
'int'
)
==
-
1
assert
str
(
elem
.
type
.
dtype
)
.
find
(
'int'
)
==
-
1
new_rval
.
append
(
elem
)
new_rval
.
append
(
elem
)
...
@@ -724,12 +725,7 @@ second dimension
...
@@ -724,12 +725,7 @@ second dimension
def
_bgrad
(
self
,
inputs
,
ograds
):
def
_bgrad
(
self
,
inputs
,
ograds
):
# returns grad, with respect to broadcasted versions of inputs
# returns grad, with respect to broadcasted versions of inputs
prev_setting
=
theano
.
config
.
compute_test_value
with
change_flags
(
compute_test_value
=
'off'
):
try
:
theano
.
config
.
compute_test_value
=
'off'
def
as_scalar
(
t
):
def
as_scalar
(
t
):
if
isinstance
(
t
.
type
,
(
NullType
,
DisconnectedType
)):
if
isinstance
(
t
.
type
,
(
NullType
,
DisconnectedType
)):
return
t
return
t
...
@@ -741,10 +737,6 @@ second dimension
...
@@ -741,10 +737,6 @@ second dimension
for
igrad
in
scalar_igrads
:
for
igrad
in
scalar_igrads
:
assert
igrad
is
not
None
,
self
.
scalar_op
assert
igrad
is
not
None
,
self
.
scalar_op
finally
:
theano
.
config
.
compute_test_value
=
prev_setting
if
not
isinstance
(
scalar_igrads
,
(
list
,
tuple
)):
if
not
isinstance
(
scalar_igrads
,
(
list
,
tuple
)):
raise
TypeError
(
'
%
s.grad returned
%
s instead of list or tuple'
%
raise
TypeError
(
'
%
s.grad returned
%
s instead of list or tuple'
%
(
str
(
self
.
scalar_op
),
str
(
type
(
scalar_igrads
))))
(
str
(
self
.
scalar_op
),
str
(
type
(
scalar_igrads
))))
...
...
theano/tensor/tests/test_elemwise.py
浏览文件 @
2566bedd
...
@@ -1154,6 +1154,11 @@ class TestBitOpReduceGrad(unittest.TestCase):
...
@@ -1154,6 +1154,11 @@ class TestBitOpReduceGrad(unittest.TestCase):
class
TestElemwise
(
unittest_tools
.
InferShapeTester
):
class
TestElemwise
(
unittest_tools
.
InferShapeTester
):
def
test_elemwise_grad_bool
(
self
):
x
=
theano
.
tensor
.
scalar
(
dtype
=
'bool'
)
y
=
theano
.
tensor
.
bscalar
()
z
=
x
*
y
dx
,
dy
=
theano
.
grad
(
z
,
[
x
,
y
])
def
test_infer_shape
(
self
):
def
test_infer_shape
(
self
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论