From ca528e9b97686f9abf7989d17be9ae438f554664 Mon Sep 17 00:00:00 2001 From: jorenham Date: Fri, 6 Sep 2024 17:42:48 +0200 Subject: [PATCH 01/13] fix `scipy.special._orthogonal` stubtests --- scipy-stubs/special/_orthogonal.pyi | 87 ++++++++++++++++++++++------- 1 file changed, 68 insertions(+), 19 deletions(-) diff --git a/scipy-stubs/special/_orthogonal.pyi b/scipy-stubs/special/_orthogonal.pyi index adc946d6..46b20d04 100644 --- a/scipy-stubs/special/_orthogonal.pyi +++ b/scipy-stubs/special/_orthogonal.pyi @@ -1,25 +1,37 @@ -from collections.abc import Callable -from typing import Literal, TypeAlias, overload +from collections.abc import Callable, Sequence +from typing import Any, Literal, TypeAlias, overload +from typing_extensions import TypeVar import numpy as np import numpy.typing as npt +import optype.numpy as onpt import scipy._typing as spt _PointsWeights: TypeAlias = tuple[npt.NDArray[np.float64], npt.NDArray[np.float64]] _PointsWeightsMu: TypeAlias = tuple[npt.NDArray[np.float64], npt.NDArray[np.float64], np.float64] __all__ = [ + "c_roots", + "cg_roots", "chebyc", "chebys", "chebyt", "chebyu", "gegenbauer", "genlaguerre", + "h_roots", + "he_roots", "hermite", "hermitenorm", + "j_roots", "jacobi", + "js_roots", + "l_roots", + "la_roots", "laguerre", "legendre", + "p_roots", + "ps_roots", "roots_chebyc", "roots_chebys", "roots_chebyt", @@ -35,12 +47,50 @@ __all__ = [ "roots_sh_chebyu", "roots_sh_jacobi", "roots_sh_legendre", + "s_roots", "sh_chebyt", "sh_chebyu", "sh_jacobi", "sh_legendre", + "t_roots", + "ts_roots", + "u_roots", + "us_roots", ] +_ShapeT = TypeVar("_ShapeT", bound=tuple[int, ...]) + +# pyright: reportUnnecessaryTypeIgnoreComment=false +# mypy: disable-error-code="explicit-override" +class orthopoly1d(np.poly1d): + limits: tuple[float, float] + weights: npt.NDArray[np.float64] + weight_func: Callable[[float], float] + normcoef: float + def __init__( + self, + /, + roots: npt.ArrayLike, + weights: npt.ArrayLike | None = None, + hn: float = 1.0, + kn: float = 1.0, + wfunc: Callable[[float], float] | None = None, + limits: tuple[float, float] | None = None, + monic: bool = False, + eval_func: np.ufunc | None = None, + ) -> None: ... + @overload # type: ignore[override] + def __call__(self, v: np.poly1d) -> np.poly1d: ... + @overload + def __call__(self, v: spt.AnyReal) -> np.floating[Any]: ... + @overload + def __call__(self, v: spt.AnyComplex) -> np.inexact[Any]: ... + @overload + def __call__( # pyright: ignore[reportIncompatibleMethodOverride] + self, + v: onpt.CanArray[_ShapeT, np.dtype[np.floating[Any] | np.integer[Any] | np.bool_]] | Sequence[npt.ArrayLike], + ) -> onpt.Array[_ShapeT, np.floating[Any]]: ... + @overload def roots_jacobi(n: spt.AnyInt, alpha: spt.AnyReal, beta: spt.AnyReal, mu: Literal[False] = ...) -> _PointsWeights: ... @overload @@ -101,23 +151,6 @@ def roots_legendre(n: spt.AnyInt, mu: Literal[True]) -> _PointsWeightsMu: ... def roots_sh_legendre(n: spt.AnyInt, mu: Literal[False] = ...) -> _PointsWeights: ... @overload def roots_sh_legendre(n: spt.AnyInt, mu: Literal[True]) -> _PointsWeightsMu: ... - -class orthopoly1d(np.poly1d): - @property - def limits(self) -> tuple[float, float]: ... - def __init__( - self, - roots: npt.ArrayLike, - weights: npt.ArrayLike | None, - hn: float = ..., - kn: float = ..., - wfunc: Callable[[float], float] | None = ..., - limits: tuple[float, float] | None = ..., - monic: bool = ..., - eval_func: np.ufunc = ..., - ) -> None: ... - def weight_func(self, x: float) -> float: ... - def legendre(n: spt.AnyInt, monic: bool = ...) -> orthopoly1d: ... def chebyt(n: spt.AnyInt, monic: bool = ...) -> orthopoly1d: ... def chebyu(n: spt.AnyInt, monic: bool = ...) -> orthopoly1d: ... @@ -137,3 +170,19 @@ def sh_jacobi(n: spt.AnyInt, p: spt.AnyReal, q: spt.AnyReal, monic: bool = ...) # These functions are not public, but still need stubs because they # get checked in the tests. def _roots_hermite_asy(n: spt.AnyInt) -> _PointsWeights: ... + +p_roots = roots_legendre +t_roots = roots_chebyt +u_roots = roots_chebyu +c_roots = roots_chebyc +s_roots = roots_chebys +j_roots = roots_jacobi +l_roots = roots_laguerre +la_roots = roots_genlaguerre +h_roots = roots_hermite +he_roots = roots_hermitenorm +cg_roots = roots_gegenbauer +ps_roots = roots_sh_legendre +ts_roots = roots_sh_chebyt +us_roots = roots_sh_chebyu +js_roots = roots_sh_jacobi From 3252a1d1026342154b84ff0f88ee260aa508a780 Mon Sep 17 00:00:00 2001 From: jorenham Date: Fri, 6 Sep 2024 17:52:10 +0200 Subject: [PATCH 02/13] fix `scipy.special.__all__` stubtests --- scipy-stubs/special/__init__.pyi | 381 ++++++++++++++++-- scipy-stubs/special/_add_newdocs.pyi | 2 - scipy-stubs/special/_ellip_harm.pyi | 2 - scipy-stubs/special/_lambertw.pyi | 2 - scipy-stubs/special/_sf_error.pyi | 2 - scipy-stubs/special/_spherical_bessel.pyi | 2 - .../special/_support_alternative_backends.pyi | 12 +- tests/stubtest/allowlist.txt | 9 - 8 files changed, 352 insertions(+), 60 deletions(-) diff --git a/scipy-stubs/special/__init__.pyi b/scipy-stubs/special/__init__.pyi index f7580e7f..43f803a9 100644 --- a/scipy-stubs/special/__init__.pyi +++ b/scipy-stubs/special/__init__.pyi @@ -1,53 +1,368 @@ -from . import _basic, _ellip_harm, _lambertw, _logsumexp, _orthogonal, _sf_error, _spfun_stats, _spherical_bessel, _ufuncs from ._basic import * -from ._ellip_harm import * -from ._lambertw import * -from ._logsumexp import * +from ._ellip_harm import ellip_harm, ellip_harm_2, ellip_normal +from ._lambertw import lambertw +from ._logsumexp import log_softmax, logsumexp, softmax from ._orthogonal import * -from ._sf_error import * -from ._spfun_stats import * -from ._spherical_bessel import * +from ._sf_error import SpecialFunctionError, SpecialFunctionWarning +from ._spfun_stats import multigammaln +from ._spherical_bessel import spherical_in, spherical_jn, spherical_kn, spherical_yn +from ._support_alternative_backends import * from ._ufuncs import * -__all__: list[str] = [ +__all__ = [ + "SpecialFunctionError", + "SpecialFunctionWarning", + "agm", + "ai_zeros", + "airy", + "airye", + "assoc_laguerre", + "bdtr", + "bdtrc", + "bdtri", + "bdtrik", + "bdtrin", + "bei", + "bei_zeros", + "beip", + "beip_zeros", + "ber", + "ber_zeros", + "bernoulli", + "berp", + "berp_zeros", + "besselpoly", + "beta", + "betainc", + "betaincc", + "betainccinv", + "betaincinv", + "betaln", + "bi_zeros", + "binom", + "boxcox", + "boxcox1p", + "btdtr", + "btdtri", + "btdtria", + "btdtrib", "c_roots", + "cbrt", "cg_roots", + "chdtr", + "chdtrc", + "chdtri", + "chdtriv", + "chebyc", + "chebys", + "chebyt", + "chebyu", + "chndtr", + "chndtridf", + "chndtrinc", + "chndtrix", + "clpmn", + "comb", + "cosdg", + "cosm1", + "cotdg", + "dawsn", + "digamma", + "diric", + "ellip_harm", + "ellip_harm_2", + "ellip_normal", + "ellipe", + "ellipeinc", + "ellipj", + "ellipk", + "ellipkinc", + "ellipkm1", + "elliprc", + "elliprd", + "elliprf", + "elliprg", + "elliprj", + "entr", + "erf", + "erf_zeros", + "erfc", + "erfcinv", + "erfcx", + "erfi", + "erfinv", + "errstate", + "euler", + "eval_chebyc", + "eval_chebys", + "eval_chebyt", + "eval_chebyu", + "eval_gegenbauer", + "eval_genlaguerre", + "eval_hermite", + "eval_hermitenorm", + "eval_jacobi", + "eval_laguerre", + "eval_legendre", + "eval_sh_chebyt", + "eval_sh_chebyu", + "eval_sh_jacobi", + "eval_sh_legendre", + "exp1", + "exp2", + "exp10", + "expi", + "expit", + "expm1", + "expn", + "exprel", + "factorial", + "factorial2", + "factorialk", + "fdtr", + "fdtrc", + "fdtri", + "fdtridfd", + "fresnel", + "fresnel_zeros", + "fresnelc_zeros", + "fresnels_zeros", + "gamma", + "gammainc", + "gammaincc", + "gammainccinv", + "gammaincinv", + "gammaln", + "gammasgn", + "gdtr", + "gdtrc", + "gdtria", + "gdtrib", + "gdtrix", + "gegenbauer", + "genlaguerre", + "geterr", + "h1vp", + "h2vp", "h_roots", + "hankel1", + "hankel1e", + "hankel2", + "hankel2e", "he_roots", + "hermite", + "hermitenorm", + "huber", + "hyp0f1", + "hyp1f1", + "hyp2f1", + "hyperu", + "i0", + "i0e", + "i1", + "i1e", + "inv_boxcox", + "inv_boxcox1p", + "it2i0k0", + "it2j0y0", + "it2struve0", + "itairy", + "iti0k0", + "itj0y0", + "itmodstruve0", + "itstruve0", + "iv", + "ive", + "ivp", + "j0", + "j1", "j_roots", + "jacobi", + "jn", + "jn_zeros", + "jnjnp_zeros", + "jnp_zeros", + "jnyn_zeros", "js_roots", + "jv", + "jve", + "jvp", + "k0", + "k0e", + "k1", + "k1e", + "kei", + "kei_zeros", + "keip", + "keip_zeros", + "kelvin", + "kelvin_zeros", + "ker", + "ker_zeros", + "kerp", + "kerp_zeros", + "kl_div", + "kn", + "kolmogi", + "kolmogorov", + "kv", + "kve", + "kvp", "l_roots", "la_roots", + "laguerre", + "lambertw", + "legendre", + "lmbda", + "log1p", + "log_expit", + "log_ndtr", + "log_softmax", + "log_wright_bessel", + "loggamma", + "logit", + "logsumexp", + "lpmn", + "lpmv", + "lpn", + "lqmn", + "lqn", + "mathieu_a", + "mathieu_b", + "mathieu_cem", + "mathieu_even_coef", + "mathieu_modcem1", + "mathieu_modcem2", + "mathieu_modsem1", + "mathieu_modsem2", + "mathieu_odd_coef", + "mathieu_sem", + "modfresnelm", + "modfresnelp", + "modstruve", + "multigammaln", + "nbdtr", + "nbdtrc", + "nbdtri", + "nbdtrik", + "nbdtrin", + "ncfdtr", + "ncfdtri", + "ncfdtridfd", + "ncfdtridfn", + "ncfdtrinc", + "nctdtr", + "nctdtridf", + "nctdtrinc", + "nctdtrit", + "ndtr", + "ndtri", + "ndtri_exp", + "nrdtrimn", + "nrdtrisd", + "obl_ang1", + "obl_ang1_cv", + "obl_cv", + "obl_cv_seq", + "obl_rad1", + "obl_rad1_cv", + "obl_rad2", + "obl_rad2_cv", + "owens_t", "p_roots", + "pbdn_seq", + "pbdv", + "pbdv_seq", + "pbvv", + "pbvv_seq", + "pbwa", + "pdtr", + "pdtrc", + "pdtri", + "pdtrik", + "perm", + "poch", + "polygamma", + "powm1", + "pro_ang1", + "pro_ang1_cv", + "pro_cv", + "pro_cv_seq", + "pro_rad1", + "pro_rad1_cv", + "pro_rad2", + "pro_rad2_cv", "ps_roots", + "pseudo_huber", + "psi", + "radian", + "rel_entr", + "rgamma", + "riccati_jn", + "riccati_yn", + "roots_chebyc", + "roots_chebys", + "roots_chebyt", + "roots_chebyu", + "roots_gegenbauer", + "roots_genlaguerre", + "roots_hermite", + "roots_hermitenorm", + "roots_jacobi", + "roots_laguerre", + "roots_legendre", + "roots_sh_chebyt", + "roots_sh_chebyu", + "roots_sh_jacobi", + "roots_sh_legendre", + "round", "s_roots", + "seterr", + "sh_chebyt", + "sh_chebyu", + "sh_jacobi", + "sh_legendre", + "shichi", + "sici", + "sinc", + "sindg", + "smirnov", + "smirnovi", + "softmax", + "spence", + "sph_harm", + "spherical_in", + "spherical_jn", + "spherical_kn", + "spherical_yn", + "stdtr", + "stdtridf", + "stdtrit", + "stirling2", + "struve", "t_roots", + "tandg", + "tklmbda", "ts_roots", "u_roots", "us_roots", + "voigt_profile", + "wofz", + "wright_bessel", + "wrightomega", + "xlog1py", + "xlogy", + "y0", + "y0_zeros", + "y1", + "y1_zeros", + "y1p_zeros", + "yn", + "yn_zeros", + "ynp_zeros", + "yv", + "yve", + "yvp", + "zeta", + "zetac", ] -__all__ += _basic.__all__ -__all__ += _ellip_harm.__all__ -__all__ += _lambertw.__all__ -__all__ += _logsumexp.__all__ -__all__ += _orthogonal.__all__ -__all__ += _sf_error.__all__ -__all__ += _spfun_stats.__all__ -__all__ += _spherical_bessel.__all__ -__all__ += _ufuncs.__all__ - -p_roots = roots_legendre -t_roots = roots_chebyt -u_roots = roots_chebyu -c_roots = roots_chebyc -s_roots = roots_chebys -j_roots = roots_jacobi -l_roots = roots_laguerre -la_roots = roots_genlaguerre -h_roots = roots_hermite -he_roots = roots_hermitenorm -cg_roots = roots_gegenbauer -ps_roots = roots_sh_legendre -ts_roots = roots_sh_chebyt -us_roots = roots_sh_chebyu -js_roots = roots_sh_jacobi diff --git a/scipy-stubs/special/_add_newdocs.pyi b/scipy-stubs/special/_add_newdocs.pyi index da950482..cc88079b 100644 --- a/scipy-stubs/special/_add_newdocs.pyi +++ b/scipy-stubs/special/_add_newdocs.pyi @@ -1,8 +1,6 @@ from typing import Final from typing_extensions import LiteralString -__all__ = () - docdict: Final[dict[str, str]] def get(name: LiteralString) -> str: ... diff --git a/scipy-stubs/special/_ellip_harm.pyi b/scipy-stubs/special/_ellip_harm.pyi index 723da99c..c3998216 100644 --- a/scipy-stubs/special/_ellip_harm.pyi +++ b/scipy-stubs/special/_ellip_harm.pyi @@ -3,8 +3,6 @@ from typing import Literal import numpy as np import scipy._typing as spt -__all__ = ["ellip_harm", "ellip_harm_2", "ellip_normal"] - def ellip_harm( h2: spt.AnyReal, k2: spt.AnyReal, diff --git a/scipy-stubs/special/_lambertw.pyi b/scipy-stubs/special/_lambertw.pyi index 74db161b..bad95094 100644 --- a/scipy-stubs/special/_lambertw.pyi +++ b/scipy-stubs/special/_lambertw.pyi @@ -1,6 +1,4 @@ import numpy as np import numpy.typing as npt -__all__ = ["lambertw"] - def lambertw(z: npt.ArrayLike, k: int = ..., tol: float = ...) -> np.complex128 | npt.NDArray[np.complex128]: ... diff --git a/scipy-stubs/special/_sf_error.pyi b/scipy-stubs/special/_sf_error.pyi index 92b7ea87..af5b8709 100644 --- a/scipy-stubs/special/_sf_error.pyi +++ b/scipy-stubs/special/_sf_error.pyi @@ -1,4 +1,2 @@ -__all__ = ["SpecialFunctionError", "SpecialFunctionWarning"] - class SpecialFunctionWarning(Warning): ... class SpecialFunctionError(Exception): ... diff --git a/scipy-stubs/special/_spherical_bessel.pyi b/scipy-stubs/special/_spherical_bessel.pyi index a273fcfa..45fadfc5 100644 --- a/scipy-stubs/special/_spherical_bessel.pyi +++ b/scipy-stubs/special/_spherical_bessel.pyi @@ -3,8 +3,6 @@ from typing import TypeAlias import numpy as np import numpy.typing as npt -__all__ = ["spherical_in", "spherical_jn", "spherical_kn", "spherical_yn"] - _Scalar_fc: TypeAlias = np.float64 | np.complex128 def spherical_jn(n: npt.ArrayLike, z: npt.ArrayLike, derivative: bool = ...) -> _Scalar_fc | npt.NDArray[_Scalar_fc]: ... diff --git a/scipy-stubs/special/_support_alternative_backends.pyi b/scipy-stubs/special/_support_alternative_backends.pyi index 76e13203..3dcb37cc 100644 --- a/scipy-stubs/special/_support_alternative_backends.pyi +++ b/scipy-stubs/special/_support_alternative_backends.pyi @@ -1,7 +1,7 @@ from ._ufuncs import ( - betainc, - betaincc, - chdtr, + betainc, # pyright: ignore[reportUnusedImport] + betaincc, # pyright: ignore[reportUnusedImport] + chdtr, # pyright: ignore[reportUnusedImport] chdtrc, entr, erf, @@ -19,14 +19,11 @@ from ._ufuncs import ( ndtr, ndtri, rel_entr, - stdtr, + stdtr, # pyright: ignore[reportUnusedImport] xlogy, ) __all__ = [ - "betainc", - "betaincc", - "chdtr", "chdtrc", "entr", "erf", @@ -44,6 +41,5 @@ __all__ = [ "ndtr", "ndtri", "rel_entr", - "stdtr", "xlogy", ] diff --git a/tests/stubtest/allowlist.txt b/tests/stubtest/allowlist.txt index 4ddb5046..0bb95390 100644 --- a/tests/stubtest/allowlist.txt +++ b/tests/stubtest/allowlist.txt @@ -74,10 +74,6 @@ scipy._lib.array_api_compat.common._typing.* scipy._lib.cobyqa.* scipy._lib.messagestream scipy.fft._pocketfft.pypocketfft.* -scipy.special.add_newdocs -scipy.special.libsf_error_state -scipy.special._precompute.* -scipy.special._support_alternative_backends.* scipy.stats._rcont.rcont scipy.stats._unuran.unuran_wrapper @@ -105,11 +101,6 @@ scipy.optimize.optimize.* scipy.optimize.slsqp.* scipy.optimize.tnc.* scipy.optimize.zeros.* -scipy.special.basic -scipy.special.orthogonal -scipy.special.sf_error -scipy.special.specfun -scipy.special.spfun_stats scipy.linalg.basic scipy.stats.kde.* scipy.stats.morestats.* From 57fb97a838199b821b07b02df9bec4d5390cdb0d Mon Sep 17 00:00:00 2001 From: jorenham Date: Fri, 6 Sep 2024 20:36:27 +0200 Subject: [PATCH 03/13] fix `scipy.special._basic` stubtests --- scipy-stubs/special/_basic.pyi | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/scipy-stubs/special/_basic.pyi b/scipy-stubs/special/_basic.pyi index 12328e30..8b5a4ddb 100644 --- a/scipy-stubs/special/_basic.pyi +++ b/scipy-stubs/special/_basic.pyi @@ -118,10 +118,10 @@ def keip_zeros(nt: int) -> Untyped: ... def kelvin_zeros(nt: int) -> Untyped: ... def pro_cv_seq(m: int, n: int, c: complex) -> Untyped: ... def obl_cv_seq(m: int, n: int, c: complex) -> Untyped: ... -def comb(n: npt.ArrayLike, k: npt.ArrayLike, *, exact: bool = ..., repetition: bool = ...) -> Untyped: ... -def perm(n: npt.ArrayLike, k: npt.ArrayLike, *, exact: bool = ...) -> Untyped: ... -def factorial(n: npt.ArrayLike, *, exact: bool = ...) -> Untyped: ... -def factorial2(n: npt.ArrayLike, *, exact: bool = ...) -> Untyped: ... -def factorialk(n: npt.ArrayLike, k: int, *, exact: bool | None = ...) -> Untyped: ... +def comb(N: npt.ArrayLike, k: npt.ArrayLike, *, exact: bool = ..., repetition: bool = ...) -> Untyped: ... +def perm(N: npt.ArrayLike, k: npt.ArrayLike, exact: bool = ...) -> Untyped: ... +def factorial(n: npt.ArrayLike, exact: bool = ...) -> Untyped: ... +def factorial2(n: npt.ArrayLike, exact: bool = ...) -> Untyped: ... +def factorialk(n: npt.ArrayLike, k: int, exact: bool | None = ...) -> Untyped: ... def stirling2(N: npt.ArrayLike, K: npt.ArrayLike, *, exact: bool = ...) -> Untyped: ... def zeta(x: npt.ArrayLike, q: npt.ArrayLike | None = ..., out: npt.NDArray[np.generic] | None = ...) -> Untyped: ... From 45bb5ed7bd93148a5ad3c02d3abe419baa4aad73 Mon Sep 17 00:00:00 2001 From: jorenham Date: Fri, 6 Sep 2024 20:36:41 +0200 Subject: [PATCH 04/13] fix `scipy.special._precompute.*` stubtests --- tests/stubtest/allowlist.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/stubtest/allowlist.txt b/tests/stubtest/allowlist.txt index 0bb95390..3970a050 100644 --- a/tests/stubtest/allowlist.txt +++ b/tests/stubtest/allowlist.txt @@ -63,7 +63,7 @@ scipy.stats.tests.* scipy.stats._qmc_cy.__test__ scipy.stats._sobol.__test__ -# undocumented internal scipy machinery +# undocumented & irrelevant internal scipy machinery scipy._lib._docscrape.* scipy._lib._uarray.* scipy._lib.array_api_compat.cupy @@ -74,6 +74,7 @@ scipy._lib.array_api_compat.common._typing.* scipy._lib.cobyqa.* scipy._lib.messagestream scipy.fft._pocketfft.pypocketfft.* +scipy.special._precompute.* scipy.stats._rcont.rcont scipy.stats._unuran.unuran_wrapper From 9a6b59ed1e868e06dc09bd29a7d789d6f7a1a1b7 Mon Sep 17 00:00:00 2001 From: jorenham Date: Fri, 6 Sep 2024 20:49:36 +0200 Subject: [PATCH 05/13] workaround the `btdtr[i]` "deprecation by redefinition" stunt --- scipy-stubs/special/__init__.pyi | 249 ++++++++++++++++++++++++++++++- 1 file changed, 248 insertions(+), 1 deletion(-) diff --git a/scipy-stubs/special/__init__.pyi b/scipy-stubs/special/__init__.pyi index 43f803a9..023aec79 100644 --- a/scipy-stubs/special/__init__.pyi +++ b/scipy-stubs/special/__init__.pyi @@ -1,3 +1,5 @@ +from typing_extensions import deprecated + from ._basic import * from ._ellip_harm import ellip_harm, ellip_harm_2, ellip_normal from ._lambertw import lambertw @@ -7,7 +9,247 @@ from ._sf_error import SpecialFunctionError, SpecialFunctionWarning from ._spfun_stats import multigammaln from ._spherical_bessel import spherical_in, spherical_jn, spherical_kn, spherical_yn from ._support_alternative_backends import * -from ._ufuncs import * + +# `from ._ufuncs import *` doesn't work here because of the `btdtr[i]` deprecation by redefinition :( +from ._ufuncs import ( + agm, + airy, + airye, + bdtr, + bdtrc, + bdtri, + bdtrik, + bdtrin, + bei, + beip, + ber, + berp, + besselpoly, + beta, + betainc, + betaincc, + betainccinv, + betaincinv, + betaln, + binom, + boxcox, + boxcox1p, + # btdtr, + # btdtri, + btdtria, + btdtrib, + cbrt, + chdtr, + chdtrc, + chdtri, + chdtriv, + chndtr, + chndtridf, + chndtrinc, + chndtrix, + cosdg, + cosm1, + cotdg, + dawsn, + ellipe, + ellipeinc, + ellipj, + ellipk, + ellipkinc, + ellipkm1, + elliprc, + elliprd, + elliprf, + elliprg, + elliprj, + entr, + erf, + erfc, + erfcinv, + erfcx, + erfi, + erfinv, + errstate, + eval_chebyc, + eval_chebys, + eval_chebyt, + eval_chebyu, + eval_gegenbauer, + eval_genlaguerre, + eval_hermite, + eval_hermitenorm, + eval_jacobi, + eval_laguerre, + eval_legendre, + eval_sh_chebyt, + eval_sh_chebyu, + eval_sh_jacobi, + eval_sh_legendre, + exp1, + exp2, + exp10, + expi, + expit, + expm1, + expn, + exprel, + fdtr, + fdtrc, + fdtri, + fdtridfd, + fresnel, + gamma, + gammainc, + gammaincc, + gammainccinv, + gammaincinv, + gammaln, + gammasgn, + gdtr, + gdtrc, + gdtria, + gdtrib, + gdtrix, + geterr, + hankel1, + hankel1e, + hankel2, + hankel2e, + huber, + hyp0f1, + hyp1f1, + hyp2f1, + hyperu, + i0, + i0e, + i1, + i1e, + inv_boxcox, + inv_boxcox1p, + it2i0k0, + it2j0y0, + it2struve0, + itairy, + iti0k0, + itj0y0, + itmodstruve0, + itstruve0, + iv, + ive, + j0, + j1, + jn, + jv, + jve, + k0, + k0e, + k1, + k1e, + kei, + keip, + kelvin, + ker, + kerp, + kl_div, + kn, + kolmogi, + kolmogorov, + kv, + kve, + log1p, + log_expit, + log_ndtr, + log_wright_bessel, + loggamma, + logit, + lpmv, + mathieu_a, + mathieu_b, + mathieu_cem, + mathieu_modcem1, + mathieu_modcem2, + mathieu_modsem1, + mathieu_modsem2, + mathieu_sem, + modfresnelm, + modfresnelp, + modstruve, + nbdtr, + nbdtrc, + nbdtri, + nbdtrik, + nbdtrin, + ncfdtr, + ncfdtri, + ncfdtridfd, + ncfdtridfn, + ncfdtrinc, + nctdtr, + nctdtridf, + nctdtrinc, + nctdtrit, + ndtr, + ndtri, + ndtri_exp, + nrdtrimn, + nrdtrisd, + obl_ang1, + obl_ang1_cv, + obl_cv, + obl_rad1, + obl_rad1_cv, + obl_rad2, + obl_rad2_cv, + owens_t, + pbdv, + pbvv, + pbwa, + pdtr, + pdtrc, + pdtri, + pdtrik, + poch, + powm1, + pro_ang1, + pro_ang1_cv, + pro_cv, + pro_rad1, + pro_rad1_cv, + pro_rad2, + pro_rad2_cv, + pseudo_huber, + psi, + radian, + rel_entr, + rgamma, + round, + seterr, + shichi, + sici, + sindg, + smirnov, + smirnovi, + spence, + sph_harm, + stdtr, + stdtridf, + stdtrit, + struve, + tandg, + tklmbda, + voigt_profile, + wofz, + wright_bessel, + wrightomega, + xlog1py, + xlogy, + y0, + y1, + yn, + yv, + yve, + zetac, +) __all__ = [ "SpecialFunctionError", @@ -366,3 +608,8 @@ __all__ = [ "zeta", "zetac", ] + +@deprecated("will be removed in SciPy 1.14.0") +def btdtr(*args: object, **kwargs: object) -> object: ... +@deprecated("will be removed in SciPy 1.14.0") +def btdtri(*args: object, **kwargs: object) -> object: ... From 808e7451056c57bbef4dc71bb75a2a9b87e06ade Mon Sep 17 00:00:00 2001 From: jorenham Date: Fri, 6 Sep 2024 21:07:30 +0200 Subject: [PATCH 06/13] fix remaining `scipy.special` stubtest errors --- scipy-stubs/special/add_newdocs.pyi | 3 + scipy-stubs/special/basic.pyi | 134 ++++++++++++++++++++++++++++ scipy-stubs/special/orthogonal.pyi | 53 +++++++++++ scipy-stubs/special/sf_error.pyi | 5 ++ scipy-stubs/special/specfun.pyi | 13 +++ scipy-stubs/special/spfun_stats.pyi | 3 + tests/stubtest/allowlist.txt | 1 + 7 files changed, 212 insertions(+) create mode 100644 scipy-stubs/special/add_newdocs.pyi create mode 100644 scipy-stubs/special/basic.pyi create mode 100644 scipy-stubs/special/orthogonal.pyi create mode 100644 scipy-stubs/special/sf_error.pyi create mode 100644 scipy-stubs/special/specfun.pyi create mode 100644 scipy-stubs/special/spfun_stats.pyi diff --git a/scipy-stubs/special/add_newdocs.pyi b/scipy-stubs/special/add_newdocs.pyi new file mode 100644 index 00000000..ac6b45e0 --- /dev/null +++ b/scipy-stubs/special/add_newdocs.pyi @@ -0,0 +1,3 @@ +# Nothing to see here. + +__all__: list[str] = [] diff --git a/scipy-stubs/special/basic.pyi b/scipy-stubs/special/basic.pyi new file mode 100644 index 00000000..1c71a230 --- /dev/null +++ b/scipy-stubs/special/basic.pyi @@ -0,0 +1,134 @@ +# This file is not meant for public use and will be removed in SciPy v2.0.0. + +from ._basic import ( + ai_zeros, + assoc_laguerre, + bei_zeros, + beip_zeros, + ber_zeros, + bernoulli, + berp_zeros, + bi_zeros, + clpmn, + comb, + digamma, + diric, + erf_zeros, + euler, + factorial, + factorial2, + factorialk, + fresnel_zeros, + fresnelc_zeros, + fresnels_zeros, + h1vp, + h2vp, + ivp, + jn_zeros, + jnjnp_zeros, + jnp_zeros, + jnyn_zeros, + jvp, + kei_zeros, + keip_zeros, + kelvin_zeros, + ker_zeros, + kerp_zeros, + kvp, + lmbda, + lpmn, + lpn, + lqmn, + lqn, + mathieu_even_coef, + mathieu_odd_coef, + obl_cv_seq, + pbdn_seq, + pbdv_seq, + pbvv_seq, + perm, + polygamma, + pro_cv_seq, + riccati_jn, + riccati_yn, + sinc, + y0_zeros, + y1_zeros, + y1p_zeros, + yn_zeros, + ynp_zeros, + yvp, + zeta, +) +from ._ufuncs import gamma, hankel1, hankel2, iv, jv, kv, mathieu_a, mathieu_b, psi, yv + +__all__ = [ + "ai_zeros", + "assoc_laguerre", + "bei_zeros", + "beip_zeros", + "ber_zeros", + "bernoulli", + "berp_zeros", + "bi_zeros", + "clpmn", + "comb", + "digamma", + "diric", + "erf_zeros", + "euler", + "factorial", + "factorial2", + "factorialk", + "fresnel_zeros", + "fresnelc_zeros", + "fresnels_zeros", + "gamma", + "h1vp", + "h2vp", + "hankel1", + "hankel2", + "iv", + "ivp", + "jn_zeros", + "jnjnp_zeros", + "jnp_zeros", + "jnyn_zeros", + "jv", + "jvp", + "kei_zeros", + "keip_zeros", + "kelvin_zeros", + "ker_zeros", + "kerp_zeros", + "kv", + "kvp", + "lmbda", + "lpmn", + "lpn", + "lqmn", + "lqn", + "mathieu_a", + "mathieu_b", + "mathieu_even_coef", + "mathieu_odd_coef", + "obl_cv_seq", + "pbdn_seq", + "pbdv_seq", + "pbvv_seq", + "perm", + "polygamma", + "pro_cv_seq", + "psi", + "riccati_jn", + "riccati_yn", + "sinc", + "y0_zeros", + "y1_zeros", + "y1p_zeros", + "yn_zeros", + "ynp_zeros", + "yv", + "yvp", + "zeta", +] diff --git a/scipy-stubs/special/orthogonal.pyi b/scipy-stubs/special/orthogonal.pyi new file mode 100644 index 00000000..ce603f22 --- /dev/null +++ b/scipy-stubs/special/orthogonal.pyi @@ -0,0 +1,53 @@ +# This file is not meant for public use and will be removed in SciPy v2.0.0. + +from ._orthogonal import * +from ._ufuncs import airy + +__all__ = [ + "airy", + "c_roots", + "cg_roots", + "chebyc", + "chebys", + "chebyt", + "chebyu", + "gegenbauer", + "genlaguerre", + "h_roots", + "he_roots", + "hermite", + "hermitenorm", + "j_roots", + "jacobi", + "js_roots", + "l_roots", + "la_roots", + "laguerre", + "legendre", + "p_roots", + "ps_roots", + "roots_chebyc", + "roots_chebys", + "roots_chebyt", + "roots_chebyu", + "roots_gegenbauer", + "roots_genlaguerre", + "roots_hermite", + "roots_hermitenorm", + "roots_jacobi", + "roots_laguerre", + "roots_legendre", + "roots_sh_chebyt", + "roots_sh_chebyu", + "roots_sh_jacobi", + "roots_sh_legendre", + "s_roots", + "sh_chebyt", + "sh_chebyu", + "sh_jacobi", + "sh_legendre", + "t_roots", + "ts_roots", + "u_roots", + "us_roots", +] diff --git a/scipy-stubs/special/sf_error.pyi b/scipy-stubs/special/sf_error.pyi new file mode 100644 index 00000000..657866cf --- /dev/null +++ b/scipy-stubs/special/sf_error.pyi @@ -0,0 +1,5 @@ +# This file is not meant for public use and will be removed in SciPy v2.0.0. + +from ._sf_error import * + +__all__ = ["SpecialFunctionError", "SpecialFunctionWarning"] diff --git a/scipy-stubs/special/specfun.pyi b/scipy-stubs/special/specfun.pyi new file mode 100644 index 00000000..e22daa43 --- /dev/null +++ b/scipy-stubs/special/specfun.pyi @@ -0,0 +1,13 @@ +# This file is not meant for public use and will be removed in SciPy v2.0.0. + +import numpy as np +import optype.numpy as onpt +from ._basic import clpmn, lpmn, lpn, lqmn + +__all__ = ["clpmn", "lpmn", "lpn", "lqmn", "pbdv"] + +# originally defined in scipy/special/_specfun.pyx +def pbdv( + v: float | np.float64, + x: float | np.float64, +) -> tuple[onpt.Array[tuple[int], np.float64], onpt.Array[tuple[int], np.float64], float, float]: ... diff --git a/scipy-stubs/special/spfun_stats.pyi b/scipy-stubs/special/spfun_stats.pyi new file mode 100644 index 00000000..19abd06a --- /dev/null +++ b/scipy-stubs/special/spfun_stats.pyi @@ -0,0 +1,3 @@ +from ._spfun_stats import multigammaln + +__all__ = ["multigammaln"] diff --git a/tests/stubtest/allowlist.txt b/tests/stubtest/allowlist.txt index 3970a050..145c1f02 100644 --- a/tests/stubtest/allowlist.txt +++ b/tests/stubtest/allowlist.txt @@ -75,6 +75,7 @@ scipy._lib.cobyqa.* scipy._lib.messagestream scipy.fft._pocketfft.pypocketfft.* scipy.special._precompute.* +scipy.special.libsf_error_state scipy.stats._rcont.rcont scipy.stats._unuran.unuran_wrapper From e4af54747f5e91023f2465e1774228b132372825 Mon Sep 17 00:00:00 2001 From: jorenham Date: Fri, 6 Sep 2024 21:08:11 +0200 Subject: [PATCH 07/13] update the development progress --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9110daab..e500698a 100644 --- a/README.md +++ b/README.md @@ -106,7 +106,7 @@ pip install scipy-stubs | `scipy.sparse.linalg` | 2: partial | | `scipy.spatial` | 2: partial | | `scipy.spatial.distance` | 3: ready | -| `scipy.special` | 3: ready | +| `scipy.special` | **4: done** | | `scipy.special.cython_special` | **4: done** | | `scipy.stats` | 2: partial | | `scipy.stats.contingency` | 1: skeleton | From 5fb5128305db4df67b8c49793229cc4eb11f924b Mon Sep 17 00:00:00 2001 From: jorenham Date: Sat, 7 Sep 2024 00:37:57 +0200 Subject: [PATCH 08/13] kinda misplaced vscode settings cleanup --- .vscode/settings.json | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index d9c27ee4..cca7065b 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,18 +1,14 @@ { - "[python]": { - "editor.rulers": [130] - }, "[markdown]": { "editor.rulers": [88] }, + "[python]": { + "editor.rulers": [130] + }, "[toml]": { "editor.rulers": [88], "editor.tabSize": 4 }, "git.branchProtection": ["master"], - "mypy-type-checker.args": [ - "--config-file=pyproject.toml" - ], - "yaml.format.printWidth": 88, - "prettier.printWidth": 88 + "mypy-type-checker.args": ["--config-file=pyproject.toml"] } From 8535d3aae2309c830f7d8280edca5b5936749d70 Mon Sep 17 00:00:00 2001 From: jorenham Date: Sat, 7 Sep 2024 00:38:33 +0200 Subject: [PATCH 09/13] improved `scipy.special._basic` type-hints --- scipy-stubs/special/_basic.pyi | 192 ++++++++++++++++++++++----------- 1 file changed, 132 insertions(+), 60 deletions(-) diff --git a/scipy-stubs/special/_basic.pyi b/scipy-stubs/special/_basic.pyi index 8b5a4ddb..15af2b85 100644 --- a/scipy-stubs/special/_basic.pyi +++ b/scipy-stubs/special/_basic.pyi @@ -1,10 +1,18 @@ -from typing import Literal +# ruff: noqa: PYI042 + +# TODO: overloads for specific scalar-types (mind the int/float/complex promotion) +# TODO: pass the literal shape sizes to the shape parameters of the `_zeroes` return types (i.e. 1d arrays) + +from typing import Any, Literal, TypeAlias, overload +from typing_extensions import TypeVar import numpy as np import numpy.typing as npt +import optype.numpy as onpt from numpy import sinc # noqa: ICN003 -from scipy._typing import Untyped -from ._ufuncs import psi as digamma +from numpy._typing import _ArrayLikeComplex_co, _ArrayLikeFloat_co, _ArrayLikeInt_co # don't try this at home, kids +import scipy._typing as spt +from ._ufuncs import psi as digamma # completely different greek letters, but oh well... __all__ = [ "ai_zeros", @@ -68,60 +76,124 @@ __all__ = [ "zeta", ] -def diric(x: npt.ArrayLike, n: int) -> Untyped: ... -def jnjnp_zeros(nt: int) -> Untyped: ... -def jnyn_zeros(n: int, nt: int) -> Untyped: ... -def jn_zeros(n: int, nt: int) -> Untyped: ... -def jnp_zeros(n: int, nt: int) -> Untyped: ... -def yn_zeros(n: int, nt: int) -> Untyped: ... -def ynp_zeros(n: int, nt: int) -> Untyped: ... -def y0_zeros(nt: int, complex: bool = ...) -> Untyped: ... -def y1_zeros(nt: int, complex: bool = ...) -> Untyped: ... -def y1p_zeros(nt: int, complex: bool = ...) -> Untyped: ... -def jvp(v: npt.ArrayLike, z: complex, n: int = ...) -> Untyped: ... -def yvp(v: npt.ArrayLike, z: complex, n: int = ...) -> Untyped: ... -def kvp(v: npt.ArrayLike, z: complex, n: int = ...) -> Untyped: ... -def ivp(v: npt.ArrayLike, z: complex, n: int = ...) -> Untyped: ... -def h1vp(v: npt.ArrayLike, z: complex, n: int = ...) -> Untyped: ... -def h2vp(v: npt.ArrayLike, z: complex, n: int = ...) -> Untyped: ... -def riccati_jn(n: int, x: float) -> Untyped: ... -def riccati_yn(n: int, x: float) -> Untyped: ... -def erf_zeros(nt: int) -> Untyped: ... -def fresnelc_zeros(nt: int) -> Untyped: ... -def fresnels_zeros(nt: int) -> Untyped: ... -def fresnel_zeros(nt: int) -> Untyped: ... -def assoc_laguerre(x: float | npt.NDArray[np.float64], n: int, k: float = ...) -> Untyped: ... -def polygamma(n: npt.ArrayLike, x: npt.ArrayLike) -> Untyped: ... -def mathieu_even_coef(m: int, q: float) -> Untyped: ... -def mathieu_odd_coef(m: int, q: float) -> Untyped: ... -def lpmn(m: int, n: int, z: npt.ArrayLike) -> Untyped: ... -def clpmn(m: int, n: int, z: npt.ArrayLike, type: Literal[2, 3] = ...) -> Untyped: ... -def lqmn(m: int, n: int, z: npt.ArrayLike) -> Untyped: ... -def bernoulli(n: int) -> Untyped: ... -def euler(n: int) -> Untyped: ... -def lpn(n: int, z: npt.ArrayLike) -> Untyped: ... -def lqn(n: int, z: npt.ArrayLike) -> Untyped: ... -def ai_zeros(nt: int) -> Untyped: ... -def bi_zeros(nt: int) -> Untyped: ... -def lmbda(v: float, x: float) -> Untyped: ... -def pbdv_seq(v: float, x: float) -> Untyped: ... -def pbvv_seq(v: float, x: float) -> Untyped: ... -def pbdn_seq(n: int, z: complex) -> Untyped: ... -def ber_zeros(nt: int) -> Untyped: ... -def bei_zeros(nt: int) -> Untyped: ... -def ker_zeros(nt: int) -> Untyped: ... -def kei_zeros(nt: int) -> Untyped: ... -def berp_zeros(nt: int) -> Untyped: ... -def beip_zeros(nt: int) -> Untyped: ... -def kerp_zeros(nt: int) -> Untyped: ... -def keip_zeros(nt: int) -> Untyped: ... -def kelvin_zeros(nt: int) -> Untyped: ... -def pro_cv_seq(m: int, n: int, c: complex) -> Untyped: ... -def obl_cv_seq(m: int, n: int, c: complex) -> Untyped: ... -def comb(N: npt.ArrayLike, k: npt.ArrayLike, *, exact: bool = ..., repetition: bool = ...) -> Untyped: ... -def perm(N: npt.ArrayLike, k: npt.ArrayLike, exact: bool = ...) -> Untyped: ... -def factorial(n: npt.ArrayLike, exact: bool = ...) -> Untyped: ... -def factorial2(n: npt.ArrayLike, exact: bool = ...) -> Untyped: ... -def factorialk(n: npt.ArrayLike, k: int, exact: bool | None = ...) -> Untyped: ... -def stirling2(N: npt.ArrayLike, K: npt.ArrayLike, *, exact: bool = ...) -> Untyped: ... -def zeta(x: npt.ArrayLike, q: npt.ArrayLike | None = ..., out: npt.NDArray[np.generic] | None = ...) -> Untyped: ... +_T0 = TypeVar("_T0") +_T1 = TypeVar("_T1", default=_T0) +_tuple2: TypeAlias = tuple[_T0, _T0] +_tuple4: TypeAlias = tuple[_T0, _T1, _T1, _T1] +_tuple8: TypeAlias = tuple[_T0, _T1, _T1, _T1, _T1, _T1, _T1, _T1] + +_ArrayT = TypeVar("_ArrayT", bound=onpt.Array) +_SCT = TypeVar("_SCT", bound=np.generic) +_scalar_or_array: TypeAlias = _SCT | onpt.Array[tuple[int, ...], _SCT] +_array_0d: TypeAlias = onpt.Array[tuple[()], _SCT] +_array_1d: TypeAlias = onpt.Array[tuple[int], _SCT] +_array_2d: TypeAlias = onpt.Array[tuple[int, int], _SCT] +_array: TypeAlias = onpt.Array[tuple[int, ...], _SCT] + +_i1: TypeAlias = np.int8 +_i2: TypeAlias = np.int16 +_i4: TypeAlias = np.int32 +_i8: TypeAlias = np.int64 +_i: TypeAlias = _i1 | _i2 | _i4 | _i8 + +_f2: TypeAlias = np.float16 +_f4: TypeAlias = np.float32 +_f8: TypeAlias = np.float64 +_f: TypeAlias = _f2 | _f4 | _f8 | np.longdouble + +_c8: TypeAlias = np.complex64 +_c16: TypeAlias = np.complex128 +_c: TypeAlias = _c8 | _c16 | np.clongdouble + +def diric(x: _ArrayLikeFloat_co, n: spt.AnyInt) -> npt.NDArray[np.floating[Any]]: ... +def jnjnp_zeros(nt: spt.AnyInt) -> _tuple4[_array_1d[_f8], _array_1d[_i4]]: ... +def jnyn_zeros(n: spt.AnyInt, nt: spt.AnyInt) -> _tuple4[_array_1d[_f8]]: ... +def jn_zeros(n: spt.AnyInt, nt: spt.AnyInt) -> _array_1d[_f8]: ... +def jnp_zeros(n: spt.AnyInt, nt: spt.AnyInt) -> _array_1d[_f8]: ... +def yn_zeros(n: spt.AnyInt, nt: spt.AnyInt) -> _array_1d[_f8]: ... +def ynp_zeros(n: spt.AnyInt, nt: spt.AnyInt) -> _array_1d[_f8]: ... +def y0_zeros(nt: spt.AnyInt, complex: spt.AnyBool = False) -> _tuple2[_array_1d[_c16]]: ... +def y1_zeros(nt: spt.AnyInt, complex: spt.AnyBool = False) -> _tuple2[_array_1d[_c16]]: ... +def y1p_zeros(nt: spt.AnyInt, complex: spt.AnyBool = False) -> _tuple2[_array_1d[_c16]]: ... +def jvp(v: _ArrayLikeFloat_co, z: spt.AnyComplex, n: spt.AnyInt = 1) -> _scalar_or_array[_f4 | _f8 | _c8 | _c16]: ... +def yvp(v: _ArrayLikeFloat_co, z: spt.AnyComplex, n: spt.AnyInt = 1) -> _scalar_or_array[_f4 | _f8 | _c8 | _c16]: ... +def kvp(v: _ArrayLikeFloat_co, z: spt.AnyComplex, n: spt.AnyInt = 1) -> _scalar_or_array[_f4 | _f8 | _c8 | _c16]: ... +def ivp(v: _ArrayLikeFloat_co, z: spt.AnyComplex, n: spt.AnyInt = 1) -> _scalar_or_array[_f4 | _f8 | _c8 | _c16]: ... +def h1vp(v: _ArrayLikeFloat_co, z: spt.AnyComplex, n: spt.AnyInt = 1) -> _scalar_or_array[_f4 | _f8 | _c8 | _c16]: ... +def h2vp(v: _ArrayLikeFloat_co, z: spt.AnyComplex, n: spt.AnyInt = 1) -> _scalar_or_array[_f4 | _f8 | _c8 | _c16]: ... +def riccati_jn(n: spt.AnyInt, x: spt.AnyReal) -> _tuple2[_array_1d[_f8]]: ... +def riccati_yn(n: spt.AnyInt, x: spt.AnyReal) -> _tuple2[_array_1d[_f8]]: ... +def erf_zeros(nt: spt.AnyInt) -> _array_1d[_c16]: ... +def fresnelc_zeros(nt: spt.AnyInt) -> _array_1d[_c16]: ... +def fresnels_zeros(nt: spt.AnyInt) -> _array_1d[_c16]: ... +def fresnel_zeros(nt: spt.AnyInt) -> _array_1d[_c16]: ... +def assoc_laguerre(x: _ArrayLikeComplex_co, n: spt.AnyInt, k: spt.AnyReal = 0.0) -> _scalar_or_array[_f4 | _f8 | _c8 | _c16]: ... +def polygamma(n: _ArrayLikeInt_co, x: _ArrayLikeFloat_co) -> _scalar_or_array[_f8]: ... +def mathieu_even_coef(m: spt.AnyInt, q: spt.AnyReal) -> _array_1d[_f8]: ... +def mathieu_odd_coef(m: spt.AnyInt, q: spt.AnyReal) -> _array_1d[_f8]: ... +def lpmn(m: spt.AnyInt, n: spt.AnyInt, z: _ArrayLikeFloat_co) -> _tuple2[_array_2d[_f8]]: ... +def clpmn(m: spt.AnyInt, n: spt.AnyInt, z: _ArrayLikeComplex_co, type: Literal[2, 3] = 3) -> _tuple2[_array_2d[_c16]]: ... +def lqmn(m: spt.AnyInt, n: spt.AnyInt, z: _ArrayLikeFloat_co) -> _tuple2[_array_2d[_f]] | _tuple2[_array_2d[_c]]: ... +def bernoulli(n: spt.AnyInt) -> _array_1d[_f8]: ... +def euler(n: spt.AnyInt) -> _array_1d[_f8]: ... +def lpn(n: spt.AnyInt, z: spt.AnyReal) -> _tuple2[_array_1d[_f]] | _tuple2[_array_1d[_c]]: ... # the dtype propagates +def lqn(n: spt.AnyInt, z: npt.ArrayLike) -> _tuple2[_array_1d[_f8]] | _tuple2[_array_1d[_c16]]: ... # either f8 or c16 +def ai_zeros(nt: spt.AnyInt) -> _tuple4[_array_1d[_f8]]: ... +def bi_zeros(nt: spt.AnyInt) -> _tuple4[_array_1d[_f8]]: ... +def lmbda(v: spt.AnyReal, x: spt.AnyReal) -> _tuple2[_array_1d[_f8]]: ... +def pbdv_seq(v: spt.AnyReal, x: spt.AnyReal) -> _tuple2[_array_1d[_f8]]: ... +def pbvv_seq(v: spt.AnyReal, x: spt.AnyReal) -> _tuple2[_array_1d[_f8]]: ... +def pbdn_seq(n: spt.AnyInt, z: spt.AnyComplex) -> _tuple2[_array_1d[_c16]]: ... +def ber_zeros(nt: spt.AnyInt) -> _array_1d[_f8]: ... +def bei_zeros(nt: spt.AnyInt) -> _array_1d[_f8]: ... +def ker_zeros(nt: spt.AnyInt) -> _array_1d[_f8]: ... +def kei_zeros(nt: spt.AnyInt) -> _array_1d[_f8]: ... +def berp_zeros(nt: spt.AnyInt) -> _array_1d[_f8]: ... +def beip_zeros(nt: spt.AnyInt) -> _array_1d[_f8]: ... +def kerp_zeros(nt: spt.AnyInt) -> _array_1d[_f8]: ... +def keip_zeros(nt: spt.AnyInt) -> _array_1d[_f8]: ... +def kelvin_zeros(nt: spt.AnyInt) -> _tuple8[_array_1d[_f8]]: ... +def pro_cv_seq(m: spt.AnyInt, n: spt.AnyInt, c: spt.AnyReal) -> _array_1d[_f8]: ... +def obl_cv_seq(m: spt.AnyInt, n: spt.AnyInt, c: spt.AnyReal) -> _array_1d[_f8]: ... +@overload +def comb( + N: spt.AnyInt | _array_0d[_i], + k: spt.AnyInt | _array_0d[_i], + *, + exact: Literal[True, 1], + repetition: spt.AnyBool = False, +) -> int: ... +@overload +def comb( + N: _ArrayLikeFloat_co, + k: _ArrayLikeFloat_co, + *, + exact: Literal[False, 0, None] = False, + repetition: spt.AnyBool = False, +) -> _scalar_or_array[_f4 | _f8]: ... +@overload +def perm(N: spt.AnyInt | _array_0d[_i], k: spt.AnyInt | _array_0d[_i], exact: Literal[True, 1]) -> int: ... +@overload +def perm(N: _ArrayLikeFloat_co, k: _ArrayLikeFloat_co, exact: Literal[False, 0, None] = False) -> _scalar_or_array[_f4 | _f8]: ... +@overload +def factorial(n: _ArrayLikeInt_co, exact: Literal[True, 1]) -> int | _array[np.int_]: ... +@overload +def factorial(n: _ArrayLikeFloat_co, exact: Literal[False, 0, None] = False) -> _scalar_or_array[_f8]: ... +@overload +def factorial2(n: _ArrayLikeInt_co, exact: Literal[True, 1]) -> _i | _array[np.int_]: ... +@overload +def factorial2(n: _ArrayLikeInt_co, exact: Literal[False, 0, None] = False) -> _scalar_or_array[_f8]: ... +@overload +def factorialk(n: _ArrayLikeInt_co, k: int | _i, exact: Literal[True, 1]) -> _i | _array[np.int_]: ... +@overload +def factorialk(n: _ArrayLikeInt_co, k: int | _i, exact: Literal[False, 0, None] = ...) -> _scalar_or_array[_f8]: ... +@overload +def stirling2(N: _ArrayLikeInt_co, K: _ArrayLikeInt_co, *, exact: Literal[True, 1]) -> int | _array[np.object_]: ... +@overload +def stirling2(N: _ArrayLikeInt_co, K: _ArrayLikeInt_co, *, exact: Literal[False, 0, None] = False) -> _scalar_or_array[_f8]: ... +@overload +def zeta(x: _ArrayLikeFloat_co, q: _ArrayLikeFloat_co | None, out: _ArrayT) -> _ArrayT: ... +@overload +def zeta(x: _ArrayLikeFloat_co, q: _ArrayLikeFloat_co | None = None, *, out: _ArrayT) -> _ArrayT: ... +@overload +def zeta(x: _ArrayLikeFloat_co, q: _ArrayLikeFloat_co | None = None, out: None = None) -> _scalar_or_array[_f8]: ... From ffbfb8e63f004fd4f800df0e0dbaaa5eaaf3a2c6 Mon Sep 17 00:00:00 2001 From: jorenham Date: Sat, 7 Sep 2024 01:02:55 +0200 Subject: [PATCH 10/13] improved `scipy.special._spherical_bessel` type-hints --- scipy-stubs/special/_spherical_bessel.pyi | 25 +++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/scipy-stubs/special/_spherical_bessel.pyi b/scipy-stubs/special/_spherical_bessel.pyi index 45fadfc5..0a41d22c 100644 --- a/scipy-stubs/special/_spherical_bessel.pyi +++ b/scipy-stubs/special/_spherical_bessel.pyi @@ -2,10 +2,27 @@ from typing import TypeAlias import numpy as np import numpy.typing as npt +from numpy._typing import _ArrayLikeComplex_co, _ArrayLikeInt_co _Scalar_fc: TypeAlias = np.float64 | np.complex128 -def spherical_jn(n: npt.ArrayLike, z: npt.ArrayLike, derivative: bool = ...) -> _Scalar_fc | npt.NDArray[_Scalar_fc]: ... -def spherical_yn(n: npt.ArrayLike, z: npt.ArrayLike, derivative: bool = ...) -> _Scalar_fc | npt.NDArray[_Scalar_fc]: ... -def spherical_in(n: npt.ArrayLike, z: npt.ArrayLike, derivative: bool = ...) -> _Scalar_fc | npt.NDArray[_Scalar_fc]: ... -def spherical_kn(n: npt.ArrayLike, z: npt.ArrayLike, derivative: bool = ...) -> _Scalar_fc | npt.NDArray[_Scalar_fc]: ... +def spherical_jn( + n: _ArrayLikeInt_co, + z: _ArrayLikeComplex_co, + derivative: bool = False, +) -> _Scalar_fc | npt.NDArray[_Scalar_fc]: ... +def spherical_yn( + n: _ArrayLikeInt_co, + z: _ArrayLikeComplex_co, + derivative: bool = False, +) -> _Scalar_fc | npt.NDArray[_Scalar_fc]: ... +def spherical_in( + n: _ArrayLikeInt_co, + z: _ArrayLikeComplex_co, + derivative: bool = False, +) -> _Scalar_fc | npt.NDArray[_Scalar_fc]: ... +def spherical_kn( + n: _ArrayLikeInt_co, + z: _ArrayLikeComplex_co, + derivative: bool = False, +) -> _Scalar_fc | npt.NDArray[_Scalar_fc]: ... From 9b32e3fc30f86262acf39632607ea55eeec7e7e9 Mon Sep 17 00:00:00 2001 From: jorenham Date: Sat, 7 Sep 2024 01:05:16 +0200 Subject: [PATCH 11/13] improved `scipy.special._spfun_stats` type-hints --- scipy-stubs/special/_spfun_stats.pyi | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scipy-stubs/special/_spfun_stats.pyi b/scipy-stubs/special/_spfun_stats.pyi index 4280fb8a..6400c62b 100644 --- a/scipy-stubs/special/_spfun_stats.pyi +++ b/scipy-stubs/special/_spfun_stats.pyi @@ -1,6 +1,8 @@ import numpy as np import numpy.typing as npt +from numpy._typing import _ArrayLikeFloat_co +import scipy._typing as spt __all__ = ["multigammaln"] -def multigammaln(a: npt.ArrayLike, d: int) -> np.float64 | npt.NDArray[np.float64]: ... +def multigammaln(a: _ArrayLikeFloat_co, d: spt.AnyInt) -> np.float64 | npt.NDArray[np.float64]: ... From 72200c85a8988542903cac0de992b2f9fe28501c Mon Sep 17 00:00:00 2001 From: jorenham Date: Sat, 7 Sep 2024 01:09:23 +0200 Subject: [PATCH 12/13] improved `scipy.special._logsumexp` type-hints --- scipy-stubs/special/_logsumexp.pyi | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/scipy-stubs/special/_logsumexp.pyi b/scipy-stubs/special/_logsumexp.pyi index ea791761..f2f8092e 100644 --- a/scipy-stubs/special/_logsumexp.pyi +++ b/scipy-stubs/special/_logsumexp.pyi @@ -1,14 +1,21 @@ import numpy as np import numpy.typing as npt +from numpy._typing import _ArrayLikeComplex_co, _ArrayLikeFloat_co __all__ = ["log_softmax", "logsumexp", "softmax"] def logsumexp( - a: npt.ArrayLike, - axis: int | tuple[int, ...] | None = ..., - b: npt.ArrayLike | None = ..., - keepdims: bool = ..., - return_sign: bool = ..., -) -> npt.NDArray[np.float64]: ... -def softmax(x: npt.ArrayLike, axis: int | tuple[int, ...] | None = ...) -> npt.NDArray[np.float64]: ... -def log_softmax(x: npt.ArrayLike, axis: int | tuple[int, ...] | None = ...) -> npt.NDArray[np.float64]: ... + a: _ArrayLikeComplex_co, + axis: int | tuple[int, ...] | None = None, + b: _ArrayLikeFloat_co | None = None, + keepdims: bool = False, + return_sign: bool = False, +) -> np.float64 | np.complex128 | npt.NDArray[np.float64 | np.complex128]: ... +def softmax( + x: _ArrayLikeComplex_co, + axis: int | tuple[int, ...] | None = None, +) -> np.float64 | np.complex128 | npt.NDArray[np.float64 | np.complex128]: ... +def log_softmax( + x: _ArrayLikeComplex_co, + axis: int | tuple[int, ...] | None = None, +) -> np.float64 | np.complex128 | npt.NDArray[np.float64 | np.complex128]: ... From 6fce218666c5cce6c4700a6dfa8e3c339f7fba89 Mon Sep 17 00:00:00 2001 From: jorenham Date: Sat, 7 Sep 2024 01:12:24 +0200 Subject: [PATCH 13/13] improved `scipy.special._lambertw` type-hints --- scipy-stubs/special/_lambertw.pyi | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/scipy-stubs/special/_lambertw.pyi b/scipy-stubs/special/_lambertw.pyi index bad95094..9c1ce576 100644 --- a/scipy-stubs/special/_lambertw.pyi +++ b/scipy-stubs/special/_lambertw.pyi @@ -1,4 +1,9 @@ import numpy as np import numpy.typing as npt +from numpy._typing import _ArrayLikeComplex_co, _ArrayLikeInt_co -def lambertw(z: npt.ArrayLike, k: int = ..., tol: float = ...) -> np.complex128 | npt.NDArray[np.complex128]: ... +def lambertw( + z: _ArrayLikeComplex_co, + k: _ArrayLikeInt_co = 0, + tol: float | np.float64 = 1e-8, +) -> np.complex128 | npt.NDArray[np.complex128]: ...