Skip to content

Commit debd572

Browse files
Deprecated unwanted for compute_test_value
1 parent 1080228 commit debd572

File tree

10 files changed

+96
-116
lines changed

10 files changed

+96
-116
lines changed

tests/graph/test_destroyhandler.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import pytest
44

5-
from pytensor.configdefaults import config
65
from pytensor.graph.basic import Apply, Constant, Variable, clone
76
from pytensor.graph.destroyhandler import DestroyHandler
87
from pytensor.graph.features import ReplaceValidate
@@ -408,7 +407,6 @@ def test_value_repl():
408407
assert g.consistent()
409408

410409

411-
@config.change_flags(compute_test_value="off")
412410
def test_value_repl_2():
413411
x, y, z = inputs()
414412
sy = sigmoid(y)

tests/graph/test_op.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,6 @@ def test_test_value_op():
168168
assert np.allclose(v, np.zeros((5, 5)))
169169

170170

171-
@config.change_flags(compute_test_value="off")
172171
def test_get_test_values_no_debugger():
173172
"""Tests that `get_test_values` returns `[]` when debugger is off."""
174173

tests/scan/test_basic.py

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2245,7 +2245,7 @@ def test_compute_test_value_grad():
22452245
"""
22462246
# WEIGHT = np.array([1, 2, 1, 3, 4, 1, 5, 6, 1, 7, 8, 1], dtype="float32")
22472247

2248-
with config.change_flags(compute_test_value="raise", exception_verbosity="high"):
2248+
with config.change_flags(exception_verbosity="high"):
22492249
W_flat = fvector(name="W")
22502250
W = W_flat.reshape((2, 2, 3))
22512251

@@ -2283,28 +2283,23 @@ def test_compute_test_value_grad_cast():
22832283
22842284
See https://groups.google.com/d/topic/theano-users/o4jK9xDe5WI/discussion
22852285
"""
2286-
with config.change_flags(compute_test_value="raise"):
2287-
h = matrix("h")
2288-
with pytest.warns(FutureWarning):
2289-
h.tag.test_value = np.array(
2290-
[[1, 2, 3, 4], [5, 6, 7, 8]], dtype=config.floatX
2291-
)
2286+
h = matrix("h")
2287+
with pytest.warns(FutureWarning):
2288+
h.tag.test_value = np.array([[1, 2, 3, 4], [5, 6, 7, 8]], dtype=config.floatX)
22922289

2293-
w = shared(
2294-
np.random.default_rng(utt.fetch_seed())
2295-
.random((4, 3))
2296-
.astype(config.floatX),
2297-
name="w",
2298-
)
2290+
w = shared(
2291+
np.random.default_rng(utt.fetch_seed()).random((4, 3)).astype(config.floatX),
2292+
name="w",
2293+
)
22992294

2300-
outputs, _ = scan(
2301-
lambda i, h, w: (dot(h[i], w), i),
2302-
outputs_info=[None, 0],
2303-
non_sequences=[h, w],
2304-
n_steps=3,
2305-
)
2295+
outputs, _ = scan(
2296+
lambda i, h, w: (dot(h[i], w), i),
2297+
outputs_info=[None, 0],
2298+
non_sequences=[h, w],
2299+
n_steps=3,
2300+
)
23062301

2307-
grad(outputs[0].sum(), w)
2302+
grad(outputs[0].sum(), w)
23082303

23092304

23102305
def test_constant_folding_n_steps():

tests/tensor/random/rewriting/test_basic.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,6 @@ def test_inplace_rewrites(rv_op):
146146
assert check_stack_trace(f)
147147

148148

149-
@config.change_flags(compute_test_value="raise")
150149
@pytest.mark.parametrize(
151150
"dist_op, dist_params, size",
152151
[
@@ -417,7 +416,6 @@ def test_local_rv_size_lift(dist_op, dist_params, size):
417416
),
418417
],
419418
)
420-
@config.change_flags(compute_test_value_opt="raise", compute_test_value="raise")
421419
def test_DimShuffle_lift(ds_order, lifted, dist_op, dist_params, size, rtol):
422420
rng = shared(np.random.default_rng(1233532), borrow=False)
423421

@@ -803,7 +801,6 @@ def rand_bool_mask(shape, rng=None):
803801
),
804802
],
805803
)
806-
@config.change_flags(compute_test_value_opt="raise", compute_test_value="raise")
807804
def test_Subtensor_lift(indices, lifted, dist_op, dist_params, size):
808805
from pytensor.tensor.subtensor import as_index_constant
809806

tests/tensor/random/test_basic.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,6 @@ def test_dirichlet_infer_shape(M, size):
752752
assert tuple(rv_shape_val) == tuple(rv_val.shape)
753753

754754

755-
@config.change_flags(compute_test_value="raise")
756755
def test_dirichlet_ShapeFeature():
757756
"""Make sure `RandomVariable.infer_shape` works with `ShapeFeature`."""
758757
with pytest.warns(FutureWarning):
@@ -1600,7 +1599,6 @@ def test_unnatural_batched_dims(batch_dims_tester):
16001599
batch_dims_tester()
16011600

16021601

1603-
@config.change_flags(compute_test_value="off")
16041602
def test_pickle():
16051603
# This is an interesting `Op` case, because it has a conditional dtype
16061604
sample_a = choice(5, replace=False, size=(2, 3))

tests/tensor/random/test_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
def set_pytensor_flags():
1818
rewrites_query = RewriteDatabaseQuery(include=[None], exclude=[])
1919
py_mode = Mode("py", rewrites_query)
20-
with config.change_flags(mode=py_mode, compute_test_value="warn"):
20+
with config.change_flags(mode=py_mode):
2121
yield
2222

2323

tests/tensor/test_basic.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3549,11 +3549,11 @@ def test_assert(self):
35493549
a = Assert()(c, c > 1)
35503550
assert get_underlying_scalar_constant_value(a) == 2
35513551

3552-
with config.change_flags(compute_test_value="off"):
3553-
# condition is always False
3554-
a = Assert()(c, c > 2)
3555-
with pytest.raises(NotScalarConstantError):
3556-
get_underlying_scalar_constant_value(a)
3552+
# with config.change_flags(compute_test_value="off"):
3553+
# condition is always False
3554+
a = Assert()(c, c > 2)
3555+
with pytest.raises(NotScalarConstantError):
3556+
get_underlying_scalar_constant_value(a)
35573557

35583558
# condition is not constant
35593559
a = Assert()(c, c > x)

tests/tensor/test_subtensor.py

Lines changed: 70 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,6 @@ def test_err_invalid(self):
398398
with pytest.raises(IndexError):
399399
n.__getitem__(0)
400400

401-
@config.change_flags(compute_test_value="off")
402401
def test_err_bounds(self):
403402
n = self.shared(np.ones(3, dtype=self.dtype))
404403
t = n[7]
@@ -479,7 +478,6 @@ def test_ok_strided(self):
479478
assert tval.shape == (2,)
480479
assert (tval == [0.0, 2.0]).all()
481480

482-
@config.change_flags(compute_test_value="off")
483481
def test_err_bounds0(self):
484482
n = self.shared(np.ones((2, 3), dtype=self.dtype) * 5)
485483
for idx in [(0, 4), (0, -4)]:
@@ -495,7 +493,6 @@ def test_err_bounds0(self):
495493
finally:
496494
_logger.setLevel(oldlevel)
497495

498-
@config.change_flags(compute_test_value="off")
499496
def test_err_bounds1(self):
500497
n = self.shared(np.ones((2, 3), dtype=self.dtype) * 5)
501498
t = n[4:5, 3]
@@ -717,71 +714,70 @@ def numpy_inc_subtensor(x, idx, a):
717714
inc_subtensor(n4[test_array > 2, ..., 0, 1], 1).eval(),
718715
)
719716

720-
with config.change_flags(compute_test_value="off"):
721-
# the boolean mask should have the correct shape
722-
# - too large, padded with True
723-
mask = np.array([True, False, True])
724-
with pytest.raises(IndexError):
725-
test_array[mask].eval()
726-
with pytest.raises(IndexError):
727-
test_array[mask, ...].eval()
728-
with pytest.raises(IndexError):
729-
inc_subtensor(test_array[mask], 1).eval()
730-
with pytest.raises(IndexError):
731-
inc_subtensor(test_array[mask, ...], 1).eval()
732-
mask = np.array([[True, False, False, True], [False, True, False, True]])
733-
with pytest.raises(IndexError):
734-
test_array[mask].eval()
735-
with pytest.raises(IndexError):
736-
inc_subtensor(test_array[mask], 1).eval()
737-
# - too large, padded with False (this works in NumPy < 0.13.0)
738-
mask = np.array([True, False, False])
739-
with pytest.raises(IndexError):
740-
test_array[mask].eval()
741-
with pytest.raises(IndexError):
742-
test_array[mask, ...].eval()
743-
with pytest.raises(IndexError):
744-
inc_subtensor(test_array[mask], 1).eval()
745-
with pytest.raises(IndexError):
746-
inc_subtensor(test_array[mask, ...], 1).eval()
747-
mask = np.array([[True, False, False, False], [False, True, False, False]])
748-
with pytest.raises(IndexError):
749-
test_array[mask].eval()
750-
with pytest.raises(IndexError):
751-
inc_subtensor(test_array[mask], 1).eval()
752-
# - mask too small (this works in NumPy < 0.13.0)
753-
mask = np.array([True])
754-
with pytest.raises(IndexError):
755-
test_array[mask].eval()
756-
with pytest.raises(IndexError):
757-
test_array[mask, ...].eval()
758-
with pytest.raises(IndexError):
759-
inc_subtensor(test_array[mask], 1).eval()
760-
with pytest.raises(IndexError):
761-
inc_subtensor(test_array[mask, ...], 1).eval()
762-
mask = np.array([[True], [True]])
763-
with pytest.raises(IndexError):
764-
test_array[mask].eval()
765-
with pytest.raises(IndexError):
766-
inc_subtensor(test_array[mask], 1).eval()
767-
# - too many dimensions
768-
mask = np.array([[[True, False, False], [False, True, False]]])
769-
with pytest.raises(IndexError):
770-
test_array.__getitem__(mask)
771-
with pytest.raises(IndexError):
772-
test_array.__getitem__(mask)
773-
774-
# special cases: Python bools and bools nested in Python arrays are not supported
775-
with pytest.raises(TypeError):
776-
test_array.__getitem__((True,))
777-
with pytest.raises(TypeError):
778-
test_array.__getitem__((False,))
779-
with pytest.raises(TypeError):
780-
test_array.__getitem__((True, False))
781-
with pytest.raises(TypeError):
782-
test_array.__getitem__(([0, 1], [0, False]))
783-
with pytest.raises(TypeError):
784-
test_array.__getitem__(([0, 1], [0, pytensor.shared(True)]))
717+
# the boolean mask should have the correct shape
718+
# - too large, padded with True
719+
mask = np.array([True, False, True])
720+
with pytest.raises(IndexError):
721+
test_array[mask].eval()
722+
with pytest.raises(IndexError):
723+
test_array[mask, ...].eval()
724+
with pytest.raises(IndexError):
725+
inc_subtensor(test_array[mask], 1).eval()
726+
with pytest.raises(IndexError):
727+
inc_subtensor(test_array[mask, ...], 1).eval()
728+
mask = np.array([[True, False, False, True], [False, True, False, True]])
729+
with pytest.raises(IndexError):
730+
test_array[mask].eval()
731+
with pytest.raises(IndexError):
732+
inc_subtensor(test_array[mask], 1).eval()
733+
# - too large, padded with False (this works in NumPy < 0.13.0)
734+
mask = np.array([True, False, False])
735+
with pytest.raises(IndexError):
736+
test_array[mask].eval()
737+
with pytest.raises(IndexError):
738+
test_array[mask, ...].eval()
739+
with pytest.raises(IndexError):
740+
inc_subtensor(test_array[mask], 1).eval()
741+
with pytest.raises(IndexError):
742+
inc_subtensor(test_array[mask, ...], 1).eval()
743+
mask = np.array([[True, False, False, False], [False, True, False, False]])
744+
with pytest.raises(IndexError):
745+
test_array[mask].eval()
746+
with pytest.raises(IndexError):
747+
inc_subtensor(test_array[mask], 1).eval()
748+
# - mask too small (this works in NumPy < 0.13.0)
749+
mask = np.array([True])
750+
with pytest.raises(IndexError):
751+
test_array[mask].eval()
752+
with pytest.raises(IndexError):
753+
test_array[mask, ...].eval()
754+
with pytest.raises(IndexError):
755+
inc_subtensor(test_array[mask], 1).eval()
756+
with pytest.raises(IndexError):
757+
inc_subtensor(test_array[mask, ...], 1).eval()
758+
mask = np.array([[True], [True]])
759+
with pytest.raises(IndexError):
760+
test_array[mask].eval()
761+
with pytest.raises(IndexError):
762+
inc_subtensor(test_array[mask], 1).eval()
763+
# - too many dimensions
764+
mask = np.array([[[True, False, False], [False, True, False]]])
765+
with pytest.raises(IndexError):
766+
test_array.__getitem__(mask)
767+
with pytest.raises(IndexError):
768+
test_array.__getitem__(mask)
769+
770+
# special cases: Python bools and bools nested in Python arrays are not supported
771+
with pytest.raises(TypeError):
772+
test_array.__getitem__((True,))
773+
with pytest.raises(TypeError):
774+
test_array.__getitem__((False,))
775+
with pytest.raises(TypeError):
776+
test_array.__getitem__((True, False))
777+
with pytest.raises(TypeError):
778+
test_array.__getitem__(([0, 1], [0, False]))
779+
with pytest.raises(TypeError):
780+
test_array.__getitem__(([0, 1], [0, pytensor.shared(True)]))
785781

786782
def test_grad_1d(self):
787783
subi = 0
@@ -2490,13 +2486,12 @@ def test_AdvancedSubtensor(self):
24902486
bivec.tag.test_value = bivec_val
24912487

24922488
# Make sure it doesn't complain about test values
2493-
with config.change_flags(compute_test_value="raise"):
2494-
self._compile_and_check(
2495-
[admat, aivec],
2496-
[admat[1:3, aivec]],
2497-
[admat_val, aivec_val],
2498-
AdvancedSubtensor,
2499-
)
2489+
self._compile_and_check(
2490+
[admat, aivec],
2491+
[admat[1:3, aivec]],
2492+
[admat_val, aivec_val],
2493+
AdvancedSubtensor,
2494+
)
25002495

25012496
def test_AdvancedSubtensor_bool(self):
25022497
n = dmatrix()

tests/test_gradient.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -910,7 +910,6 @@ def test_grad_scale():
910910
assert np.allclose(out, (8, 4))
911911

912912

913-
@config.change_flags(compute_test_value="off")
914913
def test_undefined_grad_opt():
915914
# Make sure that undefined grad get removed in optimized graph.
916915
random = RandomStream(np.random.default_rng().integers(1, 2147462579))

tests/test_ifelse.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -500,12 +500,11 @@ def test_merge_ifs_true_false(self):
500500

501501
def test_grad_test_values(self):
502502
# Regression test for test values of `ifelse` gradient.
503-
with pytensor.config.change_flags(compute_test_value="raise"):
504-
x = scalar("x")
505-
with pytest.warns(FutureWarning):
506-
x.tag.test_value = 1
507-
# Used to crash due to undefined test value.
508-
pytensor.grad(ifelse(0, x, x), x)
503+
x = scalar("x")
504+
with pytest.warns(FutureWarning):
505+
x.tag.test_value = 1
506+
# Used to crash due to undefined test value.
507+
pytensor.grad(ifelse(0, x, x), x)
509508

510509
def test_grad_int_value(self):
511510
w = pytensor.shared(np.random.random(10))

0 commit comments

Comments
 (0)