Skip to content

Commit 5515580

Browse files
Deprecated unwanted for compute_test_value
1 parent 718f409 commit 5515580

12 files changed

+96
-48799
lines changed

coverage/coverage-.xml

-48,682
This file was deleted.

tests/graph/test_destroyhandler.py

-2
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

-1
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/link/jax/test_basic.py

-1
Original file line numberDiff line numberDiff line change
@@ -224,4 +224,3 @@ def test_OpFromGraph():
224224
zv = np.ones((2, 2), dtype=config.floatX) * 5
225225

226226
compare_jax_and_py(out_fg, [xv, yv, zv])
227-

tests/scan/test_basic.py

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

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

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

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

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

2306-
grad(outputs[0].sum(), w)
2301+
grad(outputs[0].sum(), w)
23072302

23082303

23092304
def test_constant_folding_n_steps():

tests/tensor/random/rewriting/test_basic.py

-3
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

-2
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

+1-1
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

+5-5
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

+70-75
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,6 @@ def test_err_invalid(self):
400400
with pytest.raises(IndexError):
401401
n.__getitem__(0)
402402

403-
@config.change_flags(compute_test_value="off")
404403
def test_err_bounds(self):
405404
n = self.shared(np.ones(3, dtype=self.dtype))
406405
t = n[7]
@@ -481,7 +480,6 @@ def test_ok_strided(self):
481480
assert tval.shape == (2,)
482481
assert (tval == [0.0, 2.0]).all()
483482

484-
@config.change_flags(compute_test_value="off")
485483
def test_err_bounds0(self):
486484
n = self.shared(np.ones((2, 3), dtype=self.dtype) * 5)
487485
for idx in [(0, 4), (0, -4)]:
@@ -497,7 +495,6 @@ def test_err_bounds0(self):
497495
finally:
498496
_logger.setLevel(oldlevel)
499497

500-
@config.change_flags(compute_test_value="off")
501498
def test_err_bounds1(self):
502499
n = self.shared(np.ones((2, 3), dtype=self.dtype) * 5)
503500
t = n[4:5, 3]
@@ -719,71 +716,70 @@ def numpy_inc_subtensor(x, idx, a):
719716
inc_subtensor(n4[test_array > 2, ..., 0, 1], 1).eval(),
720717
)
721718

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

788784
def test_grad_1d(self):
789785
subi = 0
@@ -2492,13 +2488,12 @@ def test_AdvancedSubtensor(self):
24922488
bivec.tag.test_value = bivec_val
24932489

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

25032498
def test_AdvancedSubtensor_bool(self):
25042499
n = dmatrix()

tests/test_gradient.py

-1
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

+5-6
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)