Skip to content

Commit

Permalink
Merge pull request #8066 from asi1024/btdtr-deprecation
Browse files Browse the repository at this point in the history
`scipy.special.{btdtr,btdtri}` are deprecated since SciPy 1.12
  • Loading branch information
takagi committed Jan 9, 2024
2 parents 61ef1a8 + 311a631 commit f9563bc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
17 changes: 15 additions & 2 deletions cupyx/scipy/special/_stats_distributions.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
Cephes Math Library, Release 2.3: March, 1995
Copyright 1984, 1995 by Stephen L. Moshier
"""
import warnings

from cupy import _core
from cupyx.scipy.special._beta import incbet_preamble, incbi_preamble
Expand Down Expand Up @@ -353,7 +354,7 @@

# Beta distribution functions

btdtr = _core.create_ufunc(
_btdtr = _core.create_ufunc(
"cupyx_scipy_btdtr",
("fff->f", "ddd->d"),
"out0 = out0_type(incbet(in0, in1, in2));",
Expand Down Expand Up @@ -383,7 +384,13 @@
)


btdtri = _core.create_ufunc(
def btdtr(a, b, x, out=None):
warnings.warn(
"Use cupyx.scipy.special.betainc instead.", DeprecationWarning)
return _btdtr(a, b, x, out)


_btdtri = _core.create_ufunc(
"cupyx_scipy_btdtri",
("fff->f", "ddd->d"),
"out0 = out0_type(incbi(in0, in1, in2));",
Expand Down Expand Up @@ -415,6 +422,12 @@
)


def btdtri(a, b, p, out=None):
warnings.warn(
"Use cupyx.scipy.special.betaincinv instead.", DeprecationWarning)
return _btdtri(a, b, p, out)


# Chi square distribution functions

chdtrc_definition = """
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def test_scalar(self, function, args, expected):
@testing.with_requires('scipy')
class TestThreeArgumentDistributions(_TestDistributionsBase):

@pytest.mark.parametrize('function', ['btdtr', 'btdtri', 'fdtr', 'fdtrc',
@pytest.mark.parametrize('function', ['fdtr', 'fdtrc',
'fdtri', 'gdtr', 'gdtrc'])
@testing.for_float_dtypes()
@testing.numpy_cupy_allclose(atol=1e-5, rtol=1e-5, scipy_name='scp')
Expand All @@ -221,7 +221,7 @@ def test_linspace_broadcasted(self, xp, scp, dtype, function):
# a and b should be positive
a = xp.linspace(-1, 21, 30, dtype=dtype)[:, xp.newaxis, xp.newaxis]
b = xp.linspace(-1, 21, 30, dtype=dtype)[xp.newaxis, :, xp.newaxis]
if function in ['fdtri', 'btdtr', 'btdtri']:
if function == 'fdtri':
# x should be in [0, 1] so concentrate values around that
x = xp.linspace(-0.1, 1.3, 20, dtype=dtype)
else:
Expand Down Expand Up @@ -275,9 +275,7 @@ def test_negbinomdist_linspace(self, xp, scp, function, dtype, int_dtype):

@pytest.mark.parametrize(
'function, args, expected',
[('btdtr', (1, 1, 1), 1.0),
('btdtri', (1, 1, 1), 1.0),
('betainc', (1, 1, 0), 0.0),
[('betainc', (1, 1, 0), 0.0),
# Computed using Wolfram Alpha: CDF[FRatioDistribution[1e-6, 5], 10]
('fdtr', (1e-6, 5, 10), 0.9999940790193488),
('fdtrc', (1, 1, 0), 1.0),
Expand Down

0 comments on commit f9563bc

Please sign in to comment.