Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
4cda2e52
提交
4cda2e52
authored
4月 11, 2021
作者:
Brandon T. Willard
提交者:
Brandon T. Willard
4月 11, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use the indestructible tag to prevent in-place updates to BroadcastTo output
上级
9655d978
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
25 行增加
和
0 行删除
+25
-0
extra_ops.py
aesara/tensor/extra_ops.py
+3
-0
test_extra_ops.py
tests/tensor/test_extra_ops.py
+22
-0
没有找到文件。
aesara/tensor/extra_ops.py
浏览文件 @
4cda2e52
...
...
@@ -1575,6 +1575,9 @@ class BroadcastTo(Op):
out
=
type
(
a
.
type
)(
dtype
=
a
.
type
.
dtype
,
broadcastable
=
bcast
)()
# Attempt to prevent in-place operations on this view-based output
out
.
tag
.
indestructible
=
True
return
Apply
(
self
,
[
a
]
+
shape
,
[
out
])
def
perform
(
self
,
node
,
inputs
,
output_storage
):
...
...
tests/tensor/test_extra_ops.py
浏览文件 @
4cda2e52
...
...
@@ -5,9 +5,11 @@ import aesara
from
aesara
import
function
from
aesara
import
tensor
as
aet
from
aesara.assert_op
import
Assert
from
aesara.compile.mode
import
Mode
from
aesara.configdefaults
import
config
from
aesara.gradient
import
grad
from
aesara.graph.basic
import
applys_between
from
aesara.graph.optdb
import
Query
from
aesara.tensor.elemwise
import
DimShuffle
from
aesara.tensor.extra_ops
import
(
Bartlett
,
...
...
@@ -41,6 +43,7 @@ from aesara.tensor.extra_ops import (
unravel_index
,
)
from
aesara.tensor.math
import
sum
as
aet_sum
from
aesara.tensor.subtensor
import
AdvancedIncSubtensor1
from
aesara.tensor.type
import
(
TensorType
,
dmatrix
,
...
...
@@ -1155,3 +1158,22 @@ class TestBroadcastTo(utt.InferShapeTester):
[
np
.
random
.
rand
(
2
,
1
,
3
)
.
astype
(
config
.
floatX
),
6
,
2
,
5
,
3
],
self
.
op_class
,
)
def
test_inplace
(
self
):
"""Make sure that in-place optimizations are *not* performed on the output of a ``BroadcastTo``."""
a
=
aet
.
zeros
((
5
,))
d
=
aet
.
vector
(
"d"
)
c
=
aet
.
set_subtensor
(
a
[
np
.
r_
[
0
,
1
,
3
]],
d
)
b
=
broadcast_to
(
c
,
(
5
,))
q
=
b
[
np
.
r_
[
0
,
1
,
3
]]
e
=
aet
.
set_subtensor
(
q
,
np
.
r_
[
0
,
0
,
0
])
opts
=
Query
(
include
=
[
"inplace"
])
py_mode
=
Mode
(
"py"
,
opts
)
e_fn
=
function
([
d
],
e
,
mode
=
py_mode
)
advincsub_node
=
e_fn
.
maker
.
fgraph
.
outputs
[
0
]
.
owner
assert
isinstance
(
advincsub_node
.
op
,
AdvancedIncSubtensor1
)
assert
isinstance
(
advincsub_node
.
inputs
[
0
]
.
owner
.
op
,
BroadcastTo
)
assert
advincsub_node
.
op
.
inplace
is
False
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论