Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
56e5b9c0
提交
56e5b9c0
authored
5月 01, 2017
作者:
Frederic Bastien
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix an opt being skipped due to wrong dtype exchange. This remove opt warning in a keras test.
上级
46000c76
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
28 行增加
和
6 行删除
+28
-6
opt.py
theano/tensor/opt.py
+15
-6
test_opt.py
theano/tensor/tests/test_opt.py
+13
-0
没有找到文件。
theano/tensor/opt.py
浏览文件 @
56e5b9c0
...
...
@@ -5717,11 +5717,19 @@ def local_opt_alloc(node):
only_process_constants
=
True
)
assert
val
.
size
==
1
# check which type of op
casted
=
T
.
mul
(
*
shapes
)
.
astype
(
str
(
input
.
dtype
)
)
size
=
T
.
mul
(
*
shapes
)
if
isinstance
(
node
.
op
,
T
.
Sum
):
val
=
val
.
reshape
(
1
)[
0
]
*
casted
val
=
val
.
reshape
(
1
)[
0
]
*
size
else
:
val
=
val
.
reshape
(
1
)[
0
]
**
casted
val
=
val
.
reshape
(
1
)[
0
]
**
size
# Sum can change the input dtype (upcast or bool
# -> float32) by default or by user request.
# We can ignore the acc_dtype, as there is only 1
# elemwise we will do and not a sequence, so there is no
# accumulation of errors.
# So mostly, we just need to cast the output to the old
# dtype.
val
=
val
.
astype
(
node
.
outputs
[
0
]
.
dtype
)
return
[
val
]
except
NotScalarConstantError
:
...
...
@@ -5735,11 +5743,12 @@ def local_opt_alloc(node):
to_prod
=
[
shapes
[
i
]
for
i
in
xrange
(
len
(
shapes
))
if
i
in
node
.
op
.
axis
]
if
to_prod
:
casted
=
T
.
mul
(
*
to_prod
)
.
astype
(
str
(
input
.
dtype
)
)
size
=
T
.
mul
(
*
to_prod
)
if
isinstance
(
node
.
op
,
T
.
Sum
):
val
*=
casted
val
*=
size
else
:
val
=
val
**
casted
val
=
val
**
size
val
=
val
.
astype
(
node
.
outputs
[
0
]
.
dtype
)
return
[
T
.
alloc
(
val
,
*
[
shapes
[
i
]
for
i
in
xrange
(
len
(
shapes
))
if
i
not
in
node
.
op
.
axis
])]
...
...
theano/tensor/tests/test_opt.py
浏览文件 @
56e5b9c0
...
...
@@ -5580,6 +5580,19 @@ class T_local_opt_alloc(unittest.TestCase):
finally
:
theano
.
config
.
warn_float64
=
orig
@theano.configparser.change_flags
(
on_opt_error
=
'raise'
)
def
test_sum_bool_upcast
(
self
):
s
=
theano
.
tensor
.
lscalar
()
a
=
theano
.
tensor
.
alloc
(
np
.
asarray
(
True
,
dtype
=
'bool'
),
s
,
s
)
f
=
theano
.
function
([
s
],
a
.
sum
())
f
(
5
)
# test with user specified dtype
f
=
theano
.
function
([
s
],
a
.
sum
(
dtype
=
'float32'
))
f
(
5
)
# test only 1 axis summed
f
=
theano
.
function
([
s
],
a
.
sum
(
axis
=
0
,
dtype
=
'float32'
))
f
(
5
)
class
T_local_reduce
(
unittest
.
TestCase
):
def
setUp
(
self
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论