From 176caedf0a8d1c00d42f409c2386928cd6b45ec7 Mon Sep 17 00:00:00 2001 From: Juan Orduz Date: Mon, 24 Aug 2026 14:43:32 +0200 Subject: [PATCH] Fix test incompatibilities with numpy 2.5 numpy 2.5 broke three tests on main (all CI jobs failing since it was picked up): - test_convolve2d seeded default_rng with a tuple containing the shape tuples; SeedSequence now raises "does not accept nested sequences". Flatten the seed entropy instead. - test_searchsortedOp_on_right_side and the numba test_Searchsorted compared np.searchsorted against the pytensor/numba implementations on UNSORTED arrays. That is documented undefined behavior, and numpy 2.5's reworked binary search now returns different (equally valid) results than the C/numba implementations. Use sorted inputs. --- tests/link/numba/test_extra_ops.py | 4 +++- tests/tensor/signal/test_conv.py | 2 +- tests/tensor/test_extra_ops.py | 7 ++++--- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/tests/link/numba/test_extra_ops.py b/tests/link/numba/test_extra_ops.py index 7375ce9396..f52ecc5b5e 100644 --- a/tests/link/numba/test_extra_ops.py +++ b/tests/link/numba/test_extra_ops.py @@ -391,7 +391,9 @@ def test_UnravelIndex(arr, shape, requires_obj_mode): pytest.param( ( pt.vector(), - np.array([0.29769574, 0.71649186, 0.20475563]).astype(config.floatX), + # Must be sorted: searchsorted on unsorted input is undefined + # behavior and numba/numpy implementations disagree there + np.array([0.20475563, 0.29769574, 0.71649186]).astype(config.floatX), ), ( pt.matrix(), diff --git a/tests/tensor/signal/test_conv.py b/tests/tensor/signal/test_conv.py index 6834df6a28..d623d43e1b 100644 --- a/tests/tensor/signal/test_conv.py +++ b/tests/tensor/signal/test_conv.py @@ -146,7 +146,7 @@ def test_convolve2d(kernel_shape, data_shape, mode, boundary, boundary_kwargs): fn = function([data, kernel], conv_result) - rng = np.random.default_rng((172, kernel_shape, data_shape, sum(map(ord, mode)))) + rng = np.random.default_rng((172, *kernel_shape, *data_shape, sum(map(ord, mode)))) data_val = rng.normal(size=data_shape).astype(data.dtype) kernel_val = rng.normal(size=kernel_shape).astype(kernel.dtype) diff --git a/tests/tensor/test_extra_ops.py b/tests/tensor/test_extra_ops.py index 3dd8d4c3de..4d18e14761 100644 --- a/tests/tensor/test_extra_ops.py +++ b/tests/tensor/test_extra_ops.py @@ -151,12 +151,13 @@ def test_searchsortedOp_on_int_sorter(self, dtype): ) def test_searchsortedOp_on_right_side(self): + # searchsorted on unsorted input is undefined behavior, and numpy's + # results there depend on its binary search implementation details + sa = self.a[self.idx_sorted] f = pytensor.function( [self.x, self.v], searchsorted(self.x, self.v, side="right") ) - assert np.allclose( - np.searchsorted(self.a, self.b, side="right"), f(self.a, self.b) - ) + assert np.allclose(np.searchsorted(sa, self.b, side="right"), f(sa, self.b)) def test_infer_shape(self): # Test using default parameters' value