Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
6f2a60ba
提交
6f2a60ba
authored
3月 25, 2021
作者:
Brandon T. Willard
提交者:
Brandon T. Willard
3月 25, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix attribute access error in local_rebroadcast_lift
上级
900d9f87
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
21 行增加
和
12 行删除
+21
-12
basic_opt.py
aesara/tensor/basic_opt.py
+5
-12
test_basic_opt.py
tests/tensor/test_basic_opt.py
+16
-0
没有找到文件。
aesara/tensor/basic_opt.py
浏览文件 @
6f2a60ba
...
...
@@ -26,7 +26,7 @@ from aesara.graph.basic import (
equal_computations
,
io_toposort
,
)
from
aesara.graph.fg
import
InconsistencyError
from
aesara.graph.fg
import
FunctionGraph
,
InconsistencyError
from
aesara.graph.op
import
get_test_value
from
aesara.graph.opt
import
(
GlobalOptimizer
,
...
...
@@ -3622,11 +3622,6 @@ def local_useless_inc_subtensor_alloc(fgraph, node):
return
[
r
]
####################
# Rebroadcast opts #
####################
@register_useless
@register_canonicalize
@register_specialize
...
...
@@ -3682,7 +3677,7 @@ def local_rebroadcast_lift(fgraph, node):
# is called from `apply_rebroadcast_opt`, which in particular is used
# by the `unbroadcast` function before we are in the actual function
# compilation phase.
if
len
(
fgraph
.
clients
[
input
]
)
==
1
:
if
len
(
fgraph
.
clients
.
get
(
input
,
())
)
==
1
:
rebroadcasted
=
Rebroadcast
(
*
list
(
op
.
axis
.
items
()))(
inode
.
inputs
[
0
])
# Copy over stacktrace from previous output (after rebroadcasting)
# to new output, because an error in the new graph right after
...
...
@@ -3730,16 +3725,17 @@ def apply_rebroadcast_opt(rval):
"""
fg
=
FunctionGraph
([],
[])
changed
=
True
while
changed
and
rval
.
owner
:
changed
=
False
rval2
=
local_useless_rebroadcast
.
transform
(
None
,
rval
.
owner
)
rval2
=
local_useless_rebroadcast
.
transform
(
fg
,
rval
.
owner
)
if
rval2
:
assert
len
(
rval2
)
==
1
rval
=
rval2
[
0
]
changed
=
True
if
rval
.
owner
:
rval2
=
local_rebroadcast_lift
.
transform
(
None
,
rval
.
owner
)
rval2
=
local_rebroadcast_lift
.
transform
(
fg
,
rval
.
owner
)
if
rval2
:
assert
len
(
rval2
)
==
1
rval
=
rval2
[
0
]
...
...
@@ -3747,9 +3743,6 @@ def apply_rebroadcast_opt(rval):
return
rval
#############
# Join opts #
#############
@register_specialize
@register_canonicalize
@register_useless
...
...
tests/tensor/test_basic_opt.py
浏览文件 @
6f2a60ba
...
...
@@ -38,6 +38,7 @@ from aesara.tensor.basic import (
)
from
aesara.tensor.basic_opt
import
(
ShapeFeature
,
apply_rebroadcast_opt
,
assert_op
,
local_canonicalize_alloc
,
local_dimshuffle_lift
,
...
...
@@ -5184,3 +5185,18 @@ def test_local_useless_alloc():
assert
len
(
topo
)
==
3
assert
isinstance
(
topo
[
-
2
]
.
op
,
Assert
)
assert
isinstance
(
topo
[
-
1
]
.
op
,
Alloc
)
def
test_apply_rebroadcast_opt
():
# Test the `Elemwise` case in `local_rebroadcast_lift` with `fgraph=None`.
# This is called by in `apply_rebroadcast_opt`.
a
=
vector
(
dtype
=
"float32"
)
b
=
tensor
(
"float64"
,
[
True
])
x
=
b
.
astype
(
a
.
dtype
)
broadcastable
=
(
False
,)
axis
=
[(
i
,
broadcastable
[
i
])
for
i
in
range
(
len
(
broadcastable
))]
rval
=
Rebroadcast
(
*
axis
)(
x
)
res
=
apply_rebroadcast_opt
(
rval
)
assert
res
is
rval
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论