Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
282ab9ae
提交
282ab9ae
authored
8月 16, 2016
作者:
Frederic Bastien
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
More opt pre clean up.
上级
99f22fb4
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
22 行增加
和
11 行删除
+22
-11
opt.py
theano/tensor/opt.py
+22
-11
没有找到文件。
theano/tensor/opt.py
浏览文件 @
282ab9ae
...
...
@@ -2006,14 +2006,14 @@ def local_useless_elemwise(node):
# it is the same var in the graph. That will always be true
ret
=
T
.
fill
(
node
.
inputs
[
in_idx
],
T
.
constant
(
0.0
,
dtype
=
node
.
outputs
[
0
]
.
type
.
dtype
))
ret
=
pre_greedy_local_optimizer
(
local_useless_fill
,
ret
)
ret
=
pre_greedy_local_optimizer
(
[
local_useless_fill
]
,
ret
)
return
[
ret
]
def
ones_like
(
node
,
in_idx
):
# it is the same var in the graph. That will always be true
ret
=
T
.
fill
(
node
.
inputs
[
in_idx
],
T
.
constant
(
1.0
,
dtype
=
node
.
outputs
[
0
]
.
type
.
dtype
))
ret
=
pre_greedy_local_optimizer
(
local_useless_fill
,
ret
)
ret
=
pre_greedy_local_optimizer
(
[
local_useless_fill
]
,
ret
)
return
[
ret
]
if
node
.
op
.
scalar_op
==
theano
.
scalar
.
eq
and
len
(
node
.
inputs
)
==
2
:
...
...
@@ -4883,14 +4883,25 @@ def local_useless_elemwise_comparison(node):
return
if
node
.
op
.
scalar_op
.
nin
!=
2
:
return
def
zeros_like
(
model
,
dtype
):
ret
=
T
.
zeros_like
(
node
.
inputs
[
0
],
dtype
=
node
.
outputs
[
0
]
.
dtype
)
ret
=
pre_greedy_local_optimizer
([
local_useless_fill
],
ret
)
return
ret
def
ones_like
(
model
,
dtype
):
ret
=
T
.
ones_like
(
node
.
inputs
[
0
],
dtype
=
node
.
outputs
[
0
]
.
dtype
)
ret
=
pre_greedy_local_optimizer
([
local_useless_fill
],
ret
)
return
ret
# Elemwise[{LT,GT}](X, X) -> Elemwise[zeros](X)
if
isinstance
(
node
.
op
.
scalar_op
,
(
scalar
.
LT
,
scalar
.
GT
))
and
\
node
.
inputs
[
0
]
is
node
.
inputs
[
1
]:
return
[
T
.
zeros_like
(
node
.
inputs
[
0
],
dtype
=
node
.
outputs
[
0
]
.
dtype
)]
return
[
zeros_like
(
node
.
inputs
[
0
],
dtype
=
node
.
outputs
[
0
]
.
dtype
)]
# Elemwise[{LE,GE}](X, X) -> Elemwise[ones](X)
if
isinstance
(
node
.
op
.
scalar_op
,
(
scalar
.
LE
,
scalar
.
GE
))
and
\
node
.
inputs
[
0
]
is
node
.
inputs
[
1
]:
return
[
T
.
ones_like
(
node
.
inputs
[
0
],
dtype
=
node
.
outputs
[
0
]
.
dtype
)]
return
[
ones_like
(
node
.
inputs
[
0
],
dtype
=
node
.
outputs
[
0
]
.
dtype
)]
# Elemwise[{minimum,maximum}](X, X) -> X
if
isinstance
(
node
.
op
.
scalar_op
,
(
scalar
.
Minimum
,
scalar
.
Maximum
))
and
\
node
.
inputs
[
0
]
is
node
.
inputs
[
1
]:
...
...
@@ -4901,13 +4912,13 @@ def local_useless_elemwise_comparison(node):
node
.
inputs
[
0
]
.
owner
and
\
isinstance
(
node
.
inputs
[
0
]
.
owner
.
op
,
Shape_i
)
and
\
T
.
extract_constant
(
node
.
inputs
[
1
],
only_process_constants
=
True
)
==
0
:
return
[
T
.
zeros_like
(
node
.
inputs
[
0
],
dtype
=
node
.
outputs
[
0
]
.
dtype
)]
return
[
zeros_like
(
node
.
inputs
[
0
],
dtype
=
node
.
outputs
[
0
]
.
dtype
)]
# Elemwise[GE](X.shape[i], 0) -> Elemwise[ones](X)
if
isinstance
(
node
.
op
.
scalar_op
,
scalar
.
GE
)
and
\
node
.
inputs
[
0
]
.
owner
and
\
isinstance
(
node
.
inputs
[
0
]
.
owner
.
op
,
Shape_i
)
and
\
T
.
extract_constant
(
node
.
inputs
[
1
],
only_process_constants
=
True
)
==
0
:
return
[
T
.
ones_like
(
node
.
inputs
[
0
],
dtype
=
node
.
outputs
[
0
]
.
dtype
)]
return
[
ones_like
(
node
.
inputs
[
0
],
dtype
=
node
.
outputs
[
0
]
.
dtype
)]
# Elemwise[maximum](X.shape[i], 0) -> X.shape[i]
if
isinstance
(
node
.
op
.
scalar_op
,
scalar
.
Maximum
)
and
\
node
.
inputs
[
0
]
.
owner
and
\
...
...
@@ -4925,13 +4936,13 @@ def local_useless_elemwise_comparison(node):
node
.
inputs
[
0
]
.
owner
and
\
isinstance
(
node
.
inputs
[
0
]
.
owner
.
op
,
Shape_i
)
and
\
T
.
extract_constant
(
node
.
inputs
[
1
],
only_process_constants
=
True
)
==
0
:
return
[
T
.
zeros_like
(
node
.
inputs
[
0
],
dtype
=
node
.
outputs
[
0
]
.
dtype
)]
return
[
zeros_like
(
node
.
inputs
[
0
],
dtype
=
node
.
outputs
[
0
]
.
dtype
)]
# Elemwise[minimum](0, X.shape[i]) -> 0
if
isinstance
(
node
.
op
.
scalar_op
,
scalar
.
Minimum
)
and
\
T
.
extract_constant
(
node
.
inputs
[
0
],
only_process_constants
=
True
)
==
0
and
\
node
.
inputs
[
1
]
.
owner
and
\
isinstance
(
node
.
inputs
[
1
]
.
owner
.
op
,
Shape_i
):
return
[
T
.
zeros_like
(
node
.
inputs
[
1
],
dtype
=
node
.
outputs
[
0
]
.
dtype
)]
return
[
zeros_like
(
node
.
inputs
[
1
],
dtype
=
node
.
outputs
[
0
]
.
dtype
)]
# Elemwise[LT](add([anything that is shapes]), 0) -> Elemwise[zeros](X)
if
isinstance
(
node
.
op
.
scalar_op
,
scalar
.
LT
)
and
\
...
...
@@ -4942,7 +4953,7 @@ def local_useless_elemwise_comparison(node):
for
var
in
node
.
inputs
[
0
]
.
owner
.
inputs
])
and
\
T
.
extract_constant
(
node
.
inputs
[
1
],
only_process_constants
=
True
)
==
0
:
return
[
T
.
zeros_like
(
node
.
inputs
[
0
],
dtype
=
node
.
outputs
[
0
]
.
dtype
)]
return
[
zeros_like
(
node
.
inputs
[
0
],
dtype
=
node
.
outputs
[
0
]
.
dtype
)]
# Elemwise[GE](add([anything that is shapes]), 0) -> Elemwise[ones](X)
if
isinstance
(
node
.
op
.
scalar_op
,
scalar
.
GE
)
and
\
node
.
inputs
[
0
]
.
owner
and
\
...
...
@@ -4951,7 +4962,7 @@ def local_useless_elemwise_comparison(node):
all
([
isinstance
(
var
.
owner
and
var
.
owner
.
op
,
Shape_i
)
for
var
in
node
.
inputs
[
0
]
.
owner
.
inputs
])
and
\
T
.
extract_constant
(
node
.
inputs
[
1
],
only_process_constants
=
True
)
==
0
:
return
[
T
.
ones_like
(
node
.
inputs
[
0
],
dtype
=
node
.
outputs
[
0
]
.
dtype
)]
return
[
ones_like
(
node
.
inputs
[
0
],
dtype
=
node
.
outputs
[
0
]
.
dtype
)]
# Elemwise[EQ](Subtensor(Shape(x)), -N)
# Elemwise[EQ](somegraph that only depend of shape, -N)
...
...
@@ -4984,7 +4995,7 @@ def local_useless_elemwise_comparison(node):
cst
=
get_scalar_constant_value
(
node
.
inputs
[
1
],
only_process_constants
=
True
)
if
cst
<
0
:
return
[
T
.
zeros_like
(
node
.
inputs
[
0
],
return
[
zeros_like
(
node
.
inputs
[
0
],
dtype
=
node
.
outputs
[
0
]
.
dtype
)]
except
NotScalarConstantError
:
pass
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论