Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
f0cd8ba1
提交
f0cd8ba1
authored
3月 06, 2017
作者:
Vikram
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Optimization to remove upcast in local_cast_cast
上级
4b246506
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
43 行增加
和
2 行删除
+43
-2
opt.py
theano/tensor/opt.py
+43
-2
没有找到文件。
theano/tensor/opt.py
浏览文件 @
f0cd8ba1
...
@@ -2204,7 +2204,7 @@ def local_cast_cast(node):
...
@@ -2204,7 +2204,7 @@ def local_cast_cast(node):
when those contrain:
when those contrain:
dtype1 == dtype2
dtype1 == dtype2
TODO:
the base dtype is the same (int, uint, float, complex)
OR
the base dtype is the same (int, uint, float, complex)
and the first cast cause an upcast.
and the first cast cause an upcast.
"""
"""
...
@@ -2216,10 +2216,51 @@ def local_cast_cast(node):
...
@@ -2216,10 +2216,51 @@ def local_cast_cast(node):
not
isinstance
(
x
.
owner
.
op
,
T
.
Elemwise
)
or
not
isinstance
(
x
.
owner
.
op
,
T
.
Elemwise
)
or
not
isinstance
(
x
.
owner
.
op
.
scalar_op
,
scalar
.
Cast
)):
not
isinstance
(
x
.
owner
.
op
.
scalar_op
,
scalar
.
Cast
)):
return
return
if
node
.
op
.
scalar_op
.
o_type
==
x
.
owner
.
op
.
scalar_op
.
o_type
:
type1
=
x
.
owner
.
op
.
scalar_op
.
o_type
type2
=
node
.
op
.
scalar_op
.
o_type
base
=
x
.
owner
.
inputs
[
0
]
if
type1
==
type2
:
# We don't need to copy over any stack traces here
# We don't need to copy over any stack traces here
return
[
x
]
return
[
x
]
if
(
upcast
(
base
.
dtype
,
type1
.
dtype
)):
# Checking for further redundancy. Eg: int8 -> int32 -> int8
if
(
type2
.
dtype
==
base
.
dtype
):
return
x
.
owner
.
inputs
else
:
# Apply the second cast only
v
=
node
.
op
(
base
)
return
[
v
]
def
upcast
(
type1
,
type2
):
'''
Given two data types (as strings), check if converting to
type2 from type1 constitutes an upcast.
'''
upcast_pairs
=
(
(
'int8'
,
'int16'
),(
'int8'
,
'int32'
),(
'int8'
,
'int64'
),(
'int16'
,
'int32'
),(
'int16'
,
'int64'
),(
'int32'
,
'int64'
),
(
'uint8'
,
'uint16'
),(
'uint8'
,
'uint32'
),(
'uint8'
,
'uint64'
),(
'uint16'
,
'uint32'
),(
'uint16'
,
'uint64'
),(
'uint32'
,
'uint64'
),
(
'float16'
,
'float32'
),(
'float16'
,
'float32'
),(
'float16'
,
'float64'
),(
'float32'
,
'float64'
),
(
'complex64'
,
'complex128'
),
(
'uint8'
,
'int16'
),(
'uint8'
,
'int32'
),(
'uint8'
,
'int64'
),(
'uint16'
,
'int32'
),(
'uint16'
,
'int64'
),(
'uint32'
,
'int64'
),
(
'int8'
,
'float16'
),(
'int8'
,
'float32'
),(
'int8'
,
'float64'
),(
'int16'
,
'float32'
),(
'int16'
,
'float64'
),(
'int32'
,
'float64'
),
(
'uint8'
,
'float16'
),(
'uint8'
,
'float32'
),(
'uint8'
,
'float64'
),(
'uint16'
,
'float32'
),(
'uint16'
,
'float64'
),(
'uint32'
,
'float64'
),
(
'int8'
,
'complex64'
),(
'int16'
,
'complex64'
),
(
'uint8'
,
'complex64'
),(
'uint16'
,
'complex64'
),
(
'float32'
,
'complex64'
),
(
'int8'
,
'complex128'
),(
'int16'
,
'complex128'
),(
'int32'
,
'complex128'
),
(
'uint8'
,
'complex128'
),(
'uint16'
,
'complex128'
),(
'uint32'
,
'complex128'
),
(
'float32'
,
'complex128'
),(
'float64'
,
'complex128'
)
)
for
pair
in
upcast_pairs
:
if
(
type1
==
pair
[
0
]
and
type2
==
pair
[
1
]):
return
True
return
False
@register_canonicalize
@register_canonicalize
@register_specialize
@register_specialize
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论