Skip to content

Commit 444d7e9

Browse files
committed
Deprecate Chi2SF ScalarOp
1 parent 4fa9bb8 commit 444d7e9

File tree

4 files changed

+2
-61
lines changed

4 files changed

+2
-61
lines changed

pytensor/scalar/math.py

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
true_div,
4141
upcast,
4242
upgrade_to_float,
43-
upgrade_to_float64,
4443
upgrade_to_float_no_complex,
4544
)
4645
from pytensor.scalar.basic import abs as scalar_abs
@@ -592,50 +591,6 @@ def c_code(self, *args, **kwargs):
592591
polygamma = PolyGamma(name="polygamma")
593592

594593

595-
class Chi2SF(BinaryScalarOp):
596-
"""
597-
Compute (1 - chi2_cdf(x))
598-
ie. chi2 pvalue (chi2 'survival function')
599-
"""
600-
601-
nfunc_spec = ("scipy.stats.chi2.sf", 2, 1)
602-
603-
@staticmethod
604-
def st_impl(x, k):
605-
return scipy.stats.chi2.sf(x, k)
606-
607-
def impl(self, x, k):
608-
return Chi2SF.st_impl(x, k)
609-
610-
def c_support_code(self, **kwargs):
611-
return (C_CODE_PATH / "gamma.c").read_text(encoding="utf-8")
612-
613-
def c_code(self, node, name, inp, out, sub):
614-
x, k = inp
615-
(z,) = out
616-
if node.inputs[0].type in float_types:
617-
dtype = "npy_" + node.outputs[0].dtype
618-
return f"""{z} =
619-
({dtype}) 1 - GammaP({k}/2., {x}/2.);"""
620-
raise NotImplementedError("only floatingpoint is implemented")
621-
622-
def __eq__(self, other):
623-
return type(self) is type(other)
624-
625-
def __hash__(self):
626-
return hash(type(self))
627-
628-
def c_code_cache_version(self):
629-
v = super().c_code_cache_version()
630-
if v:
631-
return (2, *v)
632-
else:
633-
return v
634-
635-
636-
chi2sf = Chi2SF(upgrade_to_float64, name="chi2sf")
637-
638-
639594
class GammaInc(BinaryScalarOp):
640595
"""
641596
Compute the regularized lower gamma function (P).

pytensor/tensor/inplace.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -258,11 +258,6 @@ def tri_gamma_inplace(a):
258258
"""second derivative of the log gamma function"""
259259

260260

261-
@scalar_elemwise
262-
def chi2sf_inplace(x, k):
263-
"""chi squared survival function"""
264-
265-
266261
@scalar_elemwise
267262
def gammainc_inplace(k, x):
268263
"""regularized lower gamma function (P)"""

pytensor/tensor/math.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1154,9 +1154,10 @@ def polygamma(n, x):
11541154
"""Polygamma function of order n evaluated at x"""
11551155

11561156

1157-
@scalar_elemwise
11581157
def chi2sf(x, k):
11591158
"""chi squared survival function"""
1159+
warnings.warn("chi2sf is deprecated. Use `gammaincc(k / 2, x / 2)` instead")
1160+
return gammaincc(k / 2, x / 2)
11601161

11611162

11621163
@scalar_elemwise

tests/tensor/test_math_scipy.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -306,16 +306,6 @@ def scipy_special_gammal(k, x):
306306
name="Chi2SF",
307307
)
308308

309-
TestChi2SFInplaceBroadcast = makeBroadcastTester(
310-
op=inplace.chi2sf_inplace,
311-
expected=expected_chi2sf,
312-
good=_good_broadcast_unary_chi2sf,
313-
eps=2e-10,
314-
mode=mode_no_scipy,
315-
inplace=True,
316-
name="Chi2SF",
317-
)
318-
319309
rng = np.random.default_rng(seed=utt.fetch_seed())
320310
_good_broadcast_binary_gamma = dict(
321311
normal=(

0 commit comments

Comments
 (0)