Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
0a3e8fce
提交
0a3e8fce
authored
7月 20, 2015
作者:
Amjad Almahairi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
rename optimization and change dependencies
上级
a63cd50f
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
7 行增加
和
14 行删除
+7
-14
scan_opt.py
theano/scan_module/scan_opt.py
+1
-1
opt.py
theano/tensor/opt.py
+6
-13
没有找到文件。
theano/scan_module/scan_opt.py
浏览文件 @
0a3e8fce
...
@@ -89,7 +89,7 @@ _logger = logging.getLogger('theano.scan_module.scan_opt')
...
@@ -89,7 +89,7 @@ _logger = logging.getLogger('theano.scan_module.scan_opt')
list_opt_slice
=
[
tensor
.
opt
.
local_abs_merge
,
list_opt_slice
=
[
tensor
.
opt
.
local_abs_merge
,
tensor
.
opt
.
local_mul_switch_sink
,
tensor
.
opt
.
local_mul_switch_sink
,
tensor
.
opt
.
local_upcast_elemwise_constant_inputs
,
tensor
.
opt
.
local_upcast_elemwise_constant_inputs
,
tensor
.
opt
.
local_
remove_switch_const_cond
,
tensor
.
opt
.
local_
useless_switch
,
tensor
.
opt
.
constant_folding
]
tensor
.
opt
.
constant_folding
]
...
...
theano/tensor/opt.py
浏览文件 @
0a3e8fce
...
@@ -1609,7 +1609,7 @@ def local_useless_elemwise(node):
...
@@ -1609,7 +1609,7 @@ def local_useless_elemwise(node):
return
[
node
.
inputs
[
1
]]
return
[
node
.
inputs
[
1
]]
elif
const_val
==
0
:
elif
const_val
==
0
:
return
zeros_like
(
node
,
1
)
return
zeros_like
(
node
,
1
)
if
isinstance
(
node
.
inputs
[
1
],
T
.
TensorConstant
):
if
isinstance
(
node
.
inputs
[
1
],
T
.
TensorConstant
):
const_val
=
T
.
extract_constant
(
node
.
inputs
[
1
])
const_val
=
T
.
extract_constant
(
node
.
inputs
[
1
])
if
const_val
==
1
:
if
const_val
==
1
:
...
@@ -2439,7 +2439,7 @@ def merge_two_slices(slice1, len1, slice2, len2):
...
@@ -2439,7 +2439,7 @@ def merge_two_slices(slice1, len1, slice2, len2):
"""
"""
list_opt
=
[
local_abs_merge
,
local_mul_switch_sink
,
list_opt
=
[
local_abs_merge
,
local_mul_switch_sink
,
local_upcast_elemwise_constant_inputs
,
local_upcast_elemwise_constant_inputs
,
local_
remove_switch_const_cond
,
constant_folding
]
local_
useless_switch
,
constant_folding
]
if
type
(
slice1
)
is
not
slice
:
if
type
(
slice1
)
is
not
slice
:
raise
ValueError
((
'First provided slice should actually be of type'
raise
ValueError
((
'First provided slice should actually be of type'
...
@@ -3256,7 +3256,7 @@ def local_join_make_vector(node):
...
@@ -3256,7 +3256,7 @@ def local_join_make_vector(node):
# Switch opts #
# Switch opts #
###############
###############
@register_canonicalize
(
'fast_compile'
)
@register_canonicalize
(
'fast_compile'
,
'local_remove_switch_const_cond'
)
@register_specialize
@register_specialize
@gof.local_optimizer
([
T
.
Elemwise
])
@gof.local_optimizer
([
T
.
Elemwise
])
def
local_useless_switch
(
node
):
def
local_useless_switch
(
node
):
...
@@ -3266,7 +3266,6 @@ def local_useless_switch(node):
...
@@ -3266,7 +3266,6 @@ def local_useless_switch(node):
if cond is constant and cond == 0: right
if cond is constant and cond == 0: right
if cond is constant and cond != 0: left
if cond is constant and cond != 0: left
if left is right -> left
if left is right -> left
if left equal right -> left
T.switch(le(shape_i{id}(X), 0), 0, shape_i{id}(X)) -> shape_i{id}(X)
T.switch(le(shape_i{id}(X), 0), 0, shape_i{id}(X)) -> shape_i{id}(X)
"""
"""
...
@@ -3292,17 +3291,12 @@ def local_useless_switch(node):
...
@@ -3292,17 +3291,12 @@ def local_useless_switch(node):
# if left is right -> left
# if left is right -> left
if
node
.
inputs
[
1
]
is
node
.
inputs
[
2
]:
if
node
.
inputs
[
1
]
is
node
.
inputs
[
2
]:
return
[
node
.
inputs
[
1
]]
return
[
node
.
inputs
[
1
]]
# if left equal right -> left
if
(
T
.
extract_constant
(
node
.
inputs
[
1
])
==
# This case happens with scan.
T
.
extract_constant
(
node
.
inputs
[
2
])):
if
node
.
inputs
[
1
]
.
type
==
node
.
outputs
[
0
]
.
type
:
return
[
node
.
inputs
[
1
]]
if
node
.
inputs
[
2
]
.
type
==
node
.
outputs
[
0
]
.
type
:
return
[
node
.
inputs
[
2
]]
# This case happen with scan.
# Elemwise{switch}(le(shape_i{id}(X), 0), 0, shape_i{id}(X)) -> shape_i{id}(X)
# Elemwise{switch}(le(shape_i{id}(X), 0), 0, shape_i{id}(X)) -> shape_i{id}(X)
left
=
node
.
inputs
[
1
]
left
=
node
.
inputs
[
1
]
right
=
node
.
inputs
[
2
]
right
=
node
.
inputs
[
2
]
if
(
cond
.
owner
and
if
(
cond
.
owner
and
isinstance
(
cond
.
owner
.
op
,
T
.
Elemwise
)
and
isinstance
(
cond
.
owner
.
op
,
T
.
Elemwise
)
and
isinstance
(
cond
.
owner
.
op
.
scalar_op
,
scalar
.
LE
)
and
isinstance
(
cond
.
owner
.
op
.
scalar_op
,
scalar
.
LE
)
and
...
@@ -3315,7 +3309,6 @@ def local_useless_switch(node):
...
@@ -3315,7 +3309,6 @@ def local_useless_switch(node):
return
[
right
]
return
[
right
]
return
False
return
False
return
False
return
False
local_remove_switch_const_cond
=
local_useless_switch
#@register_canonicalize
#@register_canonicalize
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论