提交 cbb4af7b authored 作者: Ricardo's avatar Ricardo 提交者: Thomas Wiecki

Remove `warn__inc_set_subtensor1` flag

上级 e9a0e775
......@@ -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. "
......
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,
......
......@@ -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 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论