提交 60c2d925 authored 作者: Ricardo Vieira's avatar Ricardo Vieira 提交者: Ricardo Vieira

Deprecate Chi2SF ScalarOp

上级 ffdde1cd
......@@ -40,7 +40,6 @@ from pytensor.scalar.basic import (
true_div,
upcast,
upgrade_to_float,
upgrade_to_float64,
upgrade_to_float_no_complex,
)
from pytensor.scalar.basic import abs as scalar_abs
......@@ -592,50 +591,6 @@ class PolyGamma(BinaryScalarOp):
polygamma = PolyGamma(name="polygamma")
class Chi2SF(BinaryScalarOp):
"""
Compute (1 - chi2_cdf(x))
ie. chi2 pvalue (chi2 'survival function')
"""
nfunc_spec = ("scipy.stats.chi2.sf", 2, 1)
@staticmethod
def st_impl(x, k):
return scipy.stats.chi2.sf(x, k)
def impl(self, x, k):
return Chi2SF.st_impl(x, k)
def c_support_code(self, **kwargs):
return (C_CODE_PATH / "gamma.c").read_text(encoding="utf-8")
def c_code(self, node, name, inp, out, sub):
x, k = inp
(z,) = out
if node.inputs[0].type in float_types:
dtype = "npy_" + node.outputs[0].dtype
return f"""{z} =
({dtype}) 1 - GammaP({k}/2., {x}/2.);"""
raise NotImplementedError("only floatingpoint is implemented")
def __eq__(self, other):
return type(self) is type(other)
def __hash__(self):
return hash(type(self))
def c_code_cache_version(self):
v = super().c_code_cache_version()
if v:
return (2, *v)
else:
return v
chi2sf = Chi2SF(upgrade_to_float64, name="chi2sf")
class GammaInc(BinaryScalarOp):
"""
Compute the regularized lower gamma function (P).
......
......@@ -258,11 +258,6 @@ def tri_gamma_inplace(a):
"""second derivative of the log gamma function"""
@scalar_elemwise
def chi2sf_inplace(x, k):
"""chi squared survival function"""
@scalar_elemwise
def gammainc_inplace(k, x):
"""regularized lower gamma function (P)"""
......
......@@ -1154,9 +1154,10 @@ def polygamma(n, x):
"""Polygamma function of order n evaluated at x"""
@scalar_elemwise
def chi2sf(x, k):
"""chi squared survival function"""
warnings.warn("chi2sf is deprecated. Use `gammaincc(k / 2, x / 2)` instead")
return gammaincc(k / 2, x / 2)
@scalar_elemwise
......
......@@ -306,16 +306,6 @@ TestChi2SFBroadcast = makeBroadcastTester(
name="Chi2SF",
)
TestChi2SFInplaceBroadcast = makeBroadcastTester(
op=inplace.chi2sf_inplace,
expected=expected_chi2sf,
good=_good_broadcast_unary_chi2sf,
eps=2e-10,
mode=mode_no_scipy,
inplace=True,
name="Chi2SF",
)
rng = np.random.default_rng(seed=utt.fetch_seed())
_good_broadcast_binary_gamma = dict(
normal=(
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论