Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
cbb4af7b
提交
cbb4af7b
authored
8月 18, 2021
作者:
Ricardo
提交者:
Thomas Wiecki
8月 19, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove `warn__inc_set_subtensor1` flag
上级
e9a0e775
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
39 行增加
和
96 行删除
+39
-96
configdefaults.py
aesara/configdefaults.py
+0
-12
subtensor.py
aesara/tensor/subtensor.py
+0
-31
test_subtensor.py
tests/tensor/test_subtensor.py
+39
-53
没有找到文件。
aesara/configdefaults.py
浏览文件 @
cbb4af7b
...
...
@@ -1454,18 +1454,6 @@ def add_deprecated_configvars():
in_c_key
=
False
,
)
config
.
add
(
"warn__inc_set_subtensor1"
,
(
"Warn if previous versions of Aesara (before 0.7) could have "
"given incorrect results for inc_subtensor and set_subtensor "
"when using some patterns of advanced indexing (indexing with "
"one vector or matrix of ints)."
),
BoolParam
(
_warn_default
(
"0.7"
)),
in_c_key
=
False
,
)
config
.
add
(
"warn__round"
,
"Warn when using `tensor.round` with the default mode. "
...
...
aesara/tensor/subtensor.py
浏览文件 @
cbb4af7b
import
logging
import
sys
import
warnings
from
itertools
import
chain
,
groupby
from
textwrap
import
dedent
from
typing
import
Iterable
,
List
,
Tuple
,
Union
...
...
@@ -1337,22 +1336,6 @@ def inc_subtensor(
if
v
!=
"x"
and
(
v
-
dim_offset
)
>=
0
:
y_order
[
v
-
dim_offset
]
=
i
# Warn if this code path would have produced wrong results in the past
if
config
.
warn__inc_set_subtensor1
:
# Dimshuffle pattern for y that would be equivalent to past code
prev_y_order
=
[
"x"
]
*
(
dim_offset
)
+
list
(
range
(
y
.
ndim
))
if
y_order
!=
prev_y_order
:
warnings
.
warn
(
"Although your current code is fine, please note that "
"earlier versions prior to 0.7 (or this development "
"version) may have yielded an incorrect result in "
"this `inc_subtensor` or `set_subtensor` operation. "
"To remove this warning, you can either set the "
"`warn__inc_set_subtensor1` config option to `False`, "
'or `warn__ignore_bug_before` to at least "0.7".'
,
stacklevel
=
2
,
)
inner_incsubtensor
=
inc_subtensor
(
inner_x
,
y
.
dimshuffle
(
y_order
),
...
...
@@ -1385,20 +1368,6 @@ def inc_subtensor(
else
:
flattened_y
=
y
# Warn if this code path would have produced wrong results in the past
if
config
.
warn__inc_set_subtensor1
:
if
inner_x
.
ndim
>
1
and
sum
(
y
.
broadcastable
)
>
0
:
warnings
.
warn
(
"Although your current code is fine, please note that "
"earlier versions prior to 0.7 (or this development "
"version) may have yielded an incorrect result in "
"this `inc_subtensor` or `set_subtensor` operation. "
"To remove this warning, you can either set the "
"`warn__inc_set_subtensor1` config option to `False`, "
'or `warn__ignore_bug_before` to at least "0.7".'
,
stacklevel
=
2
,
)
inner_incsubtensor
=
inc_subtensor
(
inner_x
,
flattened_y
,
...
...
tests/tensor/test_subtensor.py
浏览文件 @
cbb4af7b
...
...
@@ -1362,31 +1362,24 @@ class TestSubtensor(utt.OptimizationTestMixin):
shape_i
=
((
4
,),
(
4
,
2
))
shape_val
=
((
3
,
1
),
(
3
,
1
,
1
))
# Disable the warning emitted for that case
orig_warn
=
config
.
warn__inc_set_subtensor1
try
:
config
.
warn__inc_set_subtensor1
=
False
for
i
,
shp_i
,
shp_v
in
zip
(
sym_i
,
shape_i
,
shape_val
):
sub_m
=
m
[:,
i
]
m1
=
set_subtensor
(
sub_m
,
np
.
zeros
(
shp_v
))
m2
=
inc_subtensor
(
sub_m
,
np
.
ones
(
shp_v
))
f
=
aesara
.
function
([
m
,
i
],
[
m1
,
m2
],
mode
=
self
.
mode
)
m_val
=
random
(
3
,
5
)
i_val
=
integers_ranged
(
min
=
0
,
max
=
4
,
shape
=
shp_i
)
m1_ref
=
m_val
.
copy
()
m2_ref
=
m_val
.
copy
()
m1_val
,
m2_val
=
f
(
m_val
,
i_val
)
for
idx
in
i_val
.
ravel
():
m1_ref
[:,
idx
]
=
0
m2_ref
[:,
idx
]
+=
1
assert
np
.
allclose
(
m1_val
,
m1_ref
),
(
m1_val
,
m1_ref
)
assert
np
.
allclose
(
m2_val
,
m2_ref
),
(
m2_val
,
m2_ref
)
finally
:
config
.
warn__inc_set_subtensor1
=
orig_warn
for
i
,
shp_i
,
shp_v
in
zip
(
sym_i
,
shape_i
,
shape_val
):
sub_m
=
m
[:,
i
]
m1
=
set_subtensor
(
sub_m
,
np
.
zeros
(
shp_v
))
m2
=
inc_subtensor
(
sub_m
,
np
.
ones
(
shp_v
))
f
=
aesara
.
function
([
m
,
i
],
[
m1
,
m2
],
mode
=
self
.
mode
)
m_val
=
random
(
3
,
5
)
i_val
=
integers_ranged
(
min
=
0
,
max
=
4
,
shape
=
shp_i
)
m1_ref
=
m_val
.
copy
()
m2_ref
=
m_val
.
copy
()
m1_val
,
m2_val
=
f
(
m_val
,
i_val
)
for
idx
in
i_val
.
ravel
():
m1_ref
[:,
idx
]
=
0
m2_ref
[:,
idx
]
+=
1
assert
np
.
allclose
(
m1_val
,
m1_ref
),
(
m1_val
,
m1_ref
)
assert
np
.
allclose
(
m2_val
,
m2_ref
),
(
m2_val
,
m2_ref
)
def
test_adv1_inc_sub_notlastdim_1_2dval_no_broadcast
(
self
):
# Test that taking 1-dimensional advanced indexing
...
...
@@ -1399,34 +1392,27 @@ class TestSubtensor(utt.OptimizationTestMixin):
shape_i
=
((
4
,),
(
4
,
2
))
shape_val
=
((
3
,
4
),
(
3
,
4
,
2
))
# Disable the warning emitted for that case
orig_warn
=
config
.
warn__inc_set_subtensor1
try
:
config
.
warn__inc_set_subtensor1
=
False
for
i
,
shp_i
,
shp_v
in
zip
(
sym_i
,
shape_i
,
shape_val
):
sub_m
=
m
[:,
i
]
m1
=
set_subtensor
(
sub_m
,
np
.
zeros
(
shp_v
))
m2
=
inc_subtensor
(
sub_m
,
np
.
ones
(
shp_v
))
f
=
aesara
.
function
([
m
,
i
],
[
m1
,
m2
],
mode
=
self
.
mode
)
m_val
=
random
(
3
,
5
)
i_val
=
integers_ranged
(
min
=
0
,
max
=
4
,
shape
=
shp_i
)
m1_ref
=
m_val
.
copy
()
m2_ref
=
m_val
.
copy
()
m1_val
,
m2_val
=
f
(
m_val
,
i_val
)
# We have to explicitly loop over all individual indices,
# not as a list or array, numpy only increments the indexed
# elements once even if the indices are repeated.
for
idx
in
i_val
.
ravel
():
m1_ref
[:,
idx
]
=
0
m2_ref
[:,
idx
]
+=
1
assert
np
.
allclose
(
m1_val
,
m1_ref
),
(
m1_val
,
m1_ref
)
assert
np
.
allclose
(
m2_val
,
m2_ref
),
(
m2_val
,
m2_ref
)
finally
:
config
.
warn__inc_set_subtensor1
=
orig_warn
for
i
,
shp_i
,
shp_v
in
zip
(
sym_i
,
shape_i
,
shape_val
):
sub_m
=
m
[:,
i
]
m1
=
set_subtensor
(
sub_m
,
np
.
zeros
(
shp_v
))
m2
=
inc_subtensor
(
sub_m
,
np
.
ones
(
shp_v
))
f
=
aesara
.
function
([
m
,
i
],
[
m1
,
m2
],
mode
=
self
.
mode
)
m_val
=
random
(
3
,
5
)
i_val
=
integers_ranged
(
min
=
0
,
max
=
4
,
shape
=
shp_i
)
m1_ref
=
m_val
.
copy
()
m2_ref
=
m_val
.
copy
()
m1_val
,
m2_val
=
f
(
m_val
,
i_val
)
# We have to explicitly loop over all individual indices,
# not as a list or array, numpy only increments the indexed
# elements once even if the indices are repeated.
for
idx
in
i_val
.
ravel
():
m1_ref
[:,
idx
]
=
0
m2_ref
[:,
idx
]
+=
1
assert
np
.
allclose
(
m1_val
,
m1_ref
),
(
m1_val
,
m1_ref
)
assert
np
.
allclose
(
m2_val
,
m2_ref
),
(
m2_val
,
m2_ref
)
def
test_take_basic
():
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论