Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
2ed28f39
提交
2ed28f39
authored
8月 12, 2022
作者:
Brandon T. Willard
提交者:
Brandon T. Willard
8月 13, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Split local_useless_AdvancedSubtensor1 from local_useless_subtensor
上级
8e3c356f
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
25 行增加
和
18 行删除
+25
-18
subtensor_opt.py
aesara/tensor/subtensor_opt.py
+25
-18
没有找到文件。
aesara/tensor/subtensor_opt.py
浏览文件 @
2ed28f39
...
@@ -879,22 +879,15 @@ def local_set_to_inc_subtensor(fgraph, node):
...
@@ -879,22 +879,15 @@ def local_set_to_inc_subtensor(fgraph, node):
@register_canonicalize
@register_canonicalize
@register_specialize
@register_specialize
@local_optimizer
([
Subtensor
,
AdvancedSubtensor1
])
@local_optimizer
([
Subtensor
])
def
local_useless_subtensor
(
fgraph
,
node
):
def
local_useless_subtensor
(
fgraph
,
node
):
"""
"""Remove `Subtensor` if it takes the full input."""
Remove Subtensor/AdvancedSubtensor1 if it takes the full input. In the
AdvancedSubtensor1 case, the full input is taken when the indices are
equivalent to `arange(0, input.shape[0], 1)` using either an explicit
list/vector or the ARange op.
"""
# This optimization needs ShapeOpt and fgraph.shape_feature
# This optimization needs ShapeOpt and fgraph.shape_feature
if
not
hasattr
(
fgraph
,
"shape_feature"
):
if
not
hasattr
(
fgraph
,
"shape_feature"
):
return
return
shape_of
=
fgraph
.
shape_feature
.
shape_of
shape_of
=
fgraph
.
shape_feature
.
shape_of
if
isinstance
(
node
.
op
,
Subtensor
):
cdata
=
get_constant_idx
(
cdata
=
get_constant_idx
(
node
.
op
.
idx_list
,
node
.
op
.
idx_list
,
node
.
inputs
,
node
.
inputs
,
...
@@ -939,9 +932,7 @@ def local_useless_subtensor(fgraph, node):
...
@@ -939,9 +932,7 @@ def local_useless_subtensor(fgraph, node):
length_pos_shape_i
.
owner
.
op
,
ScalarFromTensor
length_pos_shape_i
.
owner
.
op
,
ScalarFromTensor
):
):
length_pos_shape_i
=
length_pos_shape_i
.
owner
.
inputs
[
0
]
length_pos_shape_i
=
length_pos_shape_i
.
owner
.
inputs
[
0
]
elif
length_pos
.
owner
and
isinstance
(
elif
length_pos
.
owner
and
isinstance
(
length_pos
.
owner
.
op
,
TensorFromScalar
):
length_pos
.
owner
.
op
,
TensorFromScalar
):
length_pos
=
length_pos
.
owner
.
inputs
[
0
]
length_pos
=
length_pos
.
owner
.
inputs
[
0
]
else
:
else
:
# We did not find underlying variables of the same type
# We did not find underlying variables of the same type
...
@@ -963,10 +954,30 @@ def local_useless_subtensor(fgraph, node):
...
@@ -963,10 +954,30 @@ def local_useless_subtensor(fgraph, node):
if
length_pos_shape_i
!=
length_pos
:
if
length_pos_shape_i
!=
length_pos
:
return
False
return
False
elif
idx
.
stop
is
None
:
elif
idx
.
stop
is
None
:
pass
continue
else
:
else
:
return
False
return
False
elif
isinstance
(
node
.
op
,
AdvancedSubtensor1
):
return
[
node
.
inputs
[
0
]]
@register_canonicalize
@register_specialize
@local_optimizer
([
AdvancedSubtensor1
])
def
local_useless_AdvancedSubtensor1
(
fgraph
,
node
):
"""Remove `AdvancedSubtensor1` if it takes the full input.
In the `AdvancedSubtensor1` case, the full input is taken when the indices
are equivalent to ``arange(0, input.shape[0], 1)`` using either an explicit
list/vector or the `ARange` `Op`.
"""
# This optimization needs ShapeOpt and fgraph.shape_feature
if
not
hasattr
(
fgraph
,
"shape_feature"
):
return
shape_of
=
fgraph
.
shape_feature
.
shape_of
# get length of the indexed tensor along the first axis
# get length of the indexed tensor along the first axis
try
:
try
:
length
=
get_scalar_constant_value
(
length
=
get_scalar_constant_value
(
...
@@ -1003,11 +1014,7 @@ def local_useless_subtensor(fgraph, node):
...
@@ -1003,11 +1014,7 @@ def local_useless_subtensor(fgraph, node):
return
False
return
False
else
:
else
:
return
False
return
False
else
:
return
False
# We don't need to copy over any stacktrace here,
# because previous stacktrace should suffice.
return
[
node
.
inputs
[
0
]]
return
[
node
.
inputs
[
0
]]
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论