Repository: scipy/scipy
File: scipy/special/tests/test_boost_ufuncs.py (Python)

Code before:
def test_landau():
    # Test that Landau distribution ufuncs are wrapped as expected;
    # accuracy is tested by Boost.
    x = np.linspace(-3, 10, 10)
    args = (0, 1)
    res = tanhsinh(lambda x: scu._landau_pdf(x, *args), -np.inf, x)
    cdf = scu._landau_cdf(x, *args)
    assert_allclose(res.integral, cdf)
    sf = scu._landau_sf(x, *args)
    assert_allclose(sf, 1-cdf)
    ppf = scu._landau_ppf(cdf, *args)
    assert_allclose(ppf, x)
    isf = scu._landau_isf(sf, *args)
    assert_allclose(isf, x, rtol=1e-6)

def test_gh22956():
    _ = scu._ncx2_pdf(30, 1e307, 16)

@pytest.mark.parametrize("k, n, p", [
    (3*10**18, 10*10**18, 0.3),
    (10**200, 10**210, 0.5),
])
def test_extreme_inputs(k, n, p):
    # extreme inputs caused C++ exceptions 
    # resulting in Python interpreter crashes
    scu._binom_cdf(k, n, p)


Review comment (bug):
I can reproduce the CI complaints on x86_64 Linux when I build this branch from source with latest NumPy and then downgrade to NumPy `1.26.4` before running this test.

I can make it pass with some type coercions on `1.26.4`,

```diff
--- a/scipy/special/tests/test_boost_ufuncs.py
+++ b/scipy/special/tests/test_boost_ufuncs.py
@@ -70,4 +70,4 @@ def test_gh22956():
 def test_extreme_inputs(k, n, p):
     # extreme inputs caused C++ exceptions 
     # resulting in Python interpreter crashes
-    scu._binom_cdf(k, n, p)
+    scu._binom_cdf(np.float64(k), np.float64(n), p)
```

Or, without any source changes at all when using `NPY_PROMOTION_STATE=weak` with the older NumPy. I think Matt has basically been skipping cases that require shims for older NumPy due to NEP50, so maybe we should do the same here using i.e., `numpy.lib.NumpyVersion`?

Circling back to the source patch itself--I confirmed that locally I see a Python interpreter crash on x86_64 Linux when I revert it and run your new test.

Code after:
def test_landau():
    # Test that Landau distribution ufuncs are wrapped as expected;
    # accuracy is tested by Boost.
    x = np.linspace(-3, 10, 10)
    args = (0, 1)
    res = tanhsinh(lambda x: scu._landau_pdf(x, *args), -np.inf, x)
    cdf = scu._landau_cdf(x, *args)
    assert_allclose(res.integral, cdf)
    sf = scu._landau_sf(x, *args)
    assert_allclose(sf, 1-cdf)
    ppf = scu._landau_ppf(cdf, *args)
    assert_allclose(ppf, x)
    isf = scu._landau_isf(sf, *args)
    assert_allclose(isf, x, rtol=1e-6)

def test_gh22956():
    _ = scu._ncx2_pdf(30, 1e307, 16)

@pytest.mark.parametrize("func", [scu._binom_cdf, scu._binom_sf])
@pytest.mark.parametrize("dtype", [np.float32, np.float64])
def test_extreme_inputs_for_binomial_probabilities(func, dtype):
    # certain inputs caused C++ exceptions in boost
    # resulting in Python interpreter crashes
    k = 3e18
    n = 10e18
    p = 0.3
    func(dtype(k), dtype(n), dtype(p))

@pytest.mark.parametrize("func", [scu._binom_ppf, scu._binom_isf])
@pytest.mark.parametrize("dtype", [np.float32, np.float64])
def test_extreme_inputs_for_binomial_quantiles(func, dtype):
    # certain inputs caused C++ exceptions in boost
    # resulting in Python interpreter crashes
    n = 10e18
    p = 0.5
    func(dtype(p), dtype(n), dtype(p))