diff --git a/ckpts/universal/global_step40/zero/17.attention.query_key_value.weight/exp_avg.pt b/ckpts/universal/global_step40/zero/17.attention.query_key_value.weight/exp_avg.pt new file mode 100644 index 0000000000000000000000000000000000000000..1c09df6c33fd8119c766c6b6e6a6e9f035042775 --- /dev/null +++ b/ckpts/universal/global_step40/zero/17.attention.query_key_value.weight/exp_avg.pt @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:28e565deae49903e4e68c02c801899d7ffe7d41431886fac53debb60ac807f55 +size 50332828 diff --git a/ckpts/universal/global_step40/zero/17.attention.query_key_value.weight/exp_avg_sq.pt b/ckpts/universal/global_step40/zero/17.attention.query_key_value.weight/exp_avg_sq.pt new file mode 100644 index 0000000000000000000000000000000000000000..125fbebd17f715850058ba9255e581a6995986dd --- /dev/null +++ b/ckpts/universal/global_step40/zero/17.attention.query_key_value.weight/exp_avg_sq.pt @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:90240fedb5e43f6f5ff46c735c9021e51a30ea0ae8d308a36dd70cef798d8647 +size 50332843 diff --git a/ckpts/universal/global_step40/zero/17.attention.query_key_value.weight/fp32.pt b/ckpts/universal/global_step40/zero/17.attention.query_key_value.weight/fp32.pt new file mode 100644 index 0000000000000000000000000000000000000000..d83e6eb3a1712c40711a5ed5bd2047447b648d16 --- /dev/null +++ b/ckpts/universal/global_step40/zero/17.attention.query_key_value.weight/fp32.pt @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d8a0d1c3bdba907587a39c1fb157306d2c704c79d4d43508ef00d9b049bdd6e4 +size 50332749 diff --git a/ckpts/universal/global_step40/zero/7.attention.dense.weight/exp_avg.pt b/ckpts/universal/global_step40/zero/7.attention.dense.weight/exp_avg.pt new file mode 100644 index 0000000000000000000000000000000000000000..6ca55645e0da80a95ab627a7e8a511bd0d39192e --- /dev/null +++ b/ckpts/universal/global_step40/zero/7.attention.dense.weight/exp_avg.pt @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:94e7d0ec7249c6edaaf94ea8683e0c39efee4fd85dc0d6098779076664d9699c +size 16778396 diff --git a/venv/lib/python3.10/site-packages/scipy/special/_precompute/__init__.py b/venv/lib/python3.10/site-packages/scipy/special/_precompute/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/venv/lib/python3.10/site-packages/scipy/special/_precompute/__pycache__/__init__.cpython-310.pyc b/venv/lib/python3.10/site-packages/scipy/special/_precompute/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..e31e025715de33fb18d1f8cb5909f51cf51b24ec Binary files /dev/null and b/venv/lib/python3.10/site-packages/scipy/special/_precompute/__pycache__/__init__.cpython-310.pyc differ diff --git a/venv/lib/python3.10/site-packages/scipy/special/_precompute/__pycache__/cosine_cdf.cpython-310.pyc b/venv/lib/python3.10/site-packages/scipy/special/_precompute/__pycache__/cosine_cdf.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..98f6b80adb378c2680d6fc25e99b8fec5752c337 Binary files /dev/null and b/venv/lib/python3.10/site-packages/scipy/special/_precompute/__pycache__/cosine_cdf.cpython-310.pyc differ diff --git a/venv/lib/python3.10/site-packages/scipy/special/_precompute/__pycache__/expn_asy.cpython-310.pyc b/venv/lib/python3.10/site-packages/scipy/special/_precompute/__pycache__/expn_asy.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..9bbcc25caa0b4557396006cbb8e01d9ca33ec01e Binary files /dev/null and b/venv/lib/python3.10/site-packages/scipy/special/_precompute/__pycache__/expn_asy.cpython-310.pyc differ diff --git a/venv/lib/python3.10/site-packages/scipy/special/_precompute/__pycache__/gammainc_asy.cpython-310.pyc b/venv/lib/python3.10/site-packages/scipy/special/_precompute/__pycache__/gammainc_asy.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..1274ac6dad73783439570b0f1808bc35a183ad43 Binary files /dev/null and b/venv/lib/python3.10/site-packages/scipy/special/_precompute/__pycache__/gammainc_asy.cpython-310.pyc differ diff --git a/venv/lib/python3.10/site-packages/scipy/special/_precompute/__pycache__/gammainc_data.cpython-310.pyc b/venv/lib/python3.10/site-packages/scipy/special/_precompute/__pycache__/gammainc_data.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..57e9bc9edd40343b61c32f7c5c5c04fb9ac613f5 Binary files /dev/null and b/venv/lib/python3.10/site-packages/scipy/special/_precompute/__pycache__/gammainc_data.cpython-310.pyc differ diff --git a/venv/lib/python3.10/site-packages/scipy/special/_precompute/__pycache__/lambertw.cpython-310.pyc b/venv/lib/python3.10/site-packages/scipy/special/_precompute/__pycache__/lambertw.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..0323d6d275cc56ba62973a9eac86e020c0550e0b Binary files /dev/null and b/venv/lib/python3.10/site-packages/scipy/special/_precompute/__pycache__/lambertw.cpython-310.pyc differ diff --git a/venv/lib/python3.10/site-packages/scipy/special/_precompute/__pycache__/loggamma.cpython-310.pyc b/venv/lib/python3.10/site-packages/scipy/special/_precompute/__pycache__/loggamma.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..7fbd503d1c0e92fadcbc68f7e05efd754d64a46b Binary files /dev/null and b/venv/lib/python3.10/site-packages/scipy/special/_precompute/__pycache__/loggamma.cpython-310.pyc differ diff --git a/venv/lib/python3.10/site-packages/scipy/special/_precompute/__pycache__/struve_convergence.cpython-310.pyc b/venv/lib/python3.10/site-packages/scipy/special/_precompute/__pycache__/struve_convergence.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..8fcda55c108481472fe0f1ad8cd848d35e9e18c6 Binary files /dev/null and b/venv/lib/python3.10/site-packages/scipy/special/_precompute/__pycache__/struve_convergence.cpython-310.pyc differ diff --git a/venv/lib/python3.10/site-packages/scipy/special/_precompute/__pycache__/utils.cpython-310.pyc b/venv/lib/python3.10/site-packages/scipy/special/_precompute/__pycache__/utils.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..8b698250437a0d1658ceb4fd3205a5e4e76fcf4a Binary files /dev/null and b/venv/lib/python3.10/site-packages/scipy/special/_precompute/__pycache__/utils.cpython-310.pyc differ diff --git a/venv/lib/python3.10/site-packages/scipy/special/_precompute/__pycache__/wright_bessel.cpython-310.pyc b/venv/lib/python3.10/site-packages/scipy/special/_precompute/__pycache__/wright_bessel.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..aceae88a64ef065166335fc55dc74d0420d528e2 Binary files /dev/null and b/venv/lib/python3.10/site-packages/scipy/special/_precompute/__pycache__/wright_bessel.cpython-310.pyc differ diff --git a/venv/lib/python3.10/site-packages/scipy/special/_precompute/__pycache__/wright_bessel_data.cpython-310.pyc b/venv/lib/python3.10/site-packages/scipy/special/_precompute/__pycache__/wright_bessel_data.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..cf0c0d2260afbe79e3fcb42fe9a0b47ebc77d93f Binary files /dev/null and b/venv/lib/python3.10/site-packages/scipy/special/_precompute/__pycache__/wright_bessel_data.cpython-310.pyc differ diff --git a/venv/lib/python3.10/site-packages/scipy/special/_precompute/__pycache__/wrightomega.cpython-310.pyc b/venv/lib/python3.10/site-packages/scipy/special/_precompute/__pycache__/wrightomega.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..f0730be23b1ef8866f6e0a184dd305f983647007 Binary files /dev/null and b/venv/lib/python3.10/site-packages/scipy/special/_precompute/__pycache__/wrightomega.cpython-310.pyc differ diff --git a/venv/lib/python3.10/site-packages/scipy/special/_precompute/__pycache__/zetac.cpython-310.pyc b/venv/lib/python3.10/site-packages/scipy/special/_precompute/__pycache__/zetac.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..1945e932a22fb4a7be213894ac1e03a676f323dd Binary files /dev/null and b/venv/lib/python3.10/site-packages/scipy/special/_precompute/__pycache__/zetac.cpython-310.pyc differ diff --git a/venv/lib/python3.10/site-packages/scipy/special/_precompute/cosine_cdf.py b/venv/lib/python3.10/site-packages/scipy/special/_precompute/cosine_cdf.py new file mode 100644 index 0000000000000000000000000000000000000000..662c12bc74b31478c87471fbd1cce8bea285e765 --- /dev/null +++ b/venv/lib/python3.10/site-packages/scipy/special/_precompute/cosine_cdf.py @@ -0,0 +1,17 @@ +import mpmath + + +def f(x): + return (mpmath.pi + x + mpmath.sin(x)) / (2*mpmath.pi) + + +# Note: 40 digits might be overkill; a few more digits than the default +# might be sufficient. +mpmath.mp.dps = 40 +ts = mpmath.taylor(f, -mpmath.pi, 20) +p, q = mpmath.pade(ts, 9, 10) + +p = [float(c) for c in p] +q = [float(c) for c in q] +print('p =', p) +print('q =', q) diff --git a/venv/lib/python3.10/site-packages/scipy/special/_precompute/expn_asy.py b/venv/lib/python3.10/site-packages/scipy/special/_precompute/expn_asy.py new file mode 100644 index 0000000000000000000000000000000000000000..3491b8acd588a2cacfc48f0a3a60c6ae88c3e8c5 --- /dev/null +++ b/venv/lib/python3.10/site-packages/scipy/special/_precompute/expn_asy.py @@ -0,0 +1,54 @@ +"""Precompute the polynomials for the asymptotic expansion of the +generalized exponential integral. + +Sources +------- +[1] NIST, Digital Library of Mathematical Functions, + https://dlmf.nist.gov/8.20#ii + +""" +import os + +try: + import sympy + from sympy import Poly + x = sympy.symbols('x') +except ImportError: + pass + + +def generate_A(K): + A = [Poly(1, x)] + for k in range(K): + A.append(Poly(1 - 2*k*x, x)*A[k] + Poly(x*(x + 1))*A[k].diff()) + return A + + +WARNING = """\ +/* This file was automatically generated by _precompute/expn_asy.py. + * Do not edit it manually! + */ +""" + + +def main(): + print(__doc__) + fn = os.path.join('..', 'cephes', 'expn.h') + + K = 12 + A = generate_A(K) + with open(fn + '.new', 'w') as f: + f.write(WARNING) + f.write(f"#define nA {len(A)}\n") + for k, Ak in enumerate(A): + ', '.join([str(x.evalf(18)) for x in Ak.coeffs()]) + f.write(f"static const double A{k}[] = {{tmp}};\n") + ", ".join([f"A{k}" for k in range(K + 1)]) + f.write("static const double *A[] = {{tmp}};\n") + ", ".join([str(Ak.degree()) for Ak in A]) + f.write("static const int Adegs[] = {{tmp}};\n") + os.rename(fn + '.new', fn) + + +if __name__ == "__main__": + main() diff --git a/venv/lib/python3.10/site-packages/scipy/special/_precompute/gammainc_asy.py b/venv/lib/python3.10/site-packages/scipy/special/_precompute/gammainc_asy.py new file mode 100644 index 0000000000000000000000000000000000000000..98035457c78706ae01c02273ae1ab458b4ca140d --- /dev/null +++ b/venv/lib/python3.10/site-packages/scipy/special/_precompute/gammainc_asy.py @@ -0,0 +1,116 @@ +""" +Precompute coefficients of Temme's asymptotic expansion for gammainc. + +This takes about 8 hours to run on a 2.3 GHz Macbook Pro with 4GB ram. + +Sources: +[1] NIST, "Digital Library of Mathematical Functions", + https://dlmf.nist.gov/ + +""" +import os +from scipy.special._precompute.utils import lagrange_inversion + +try: + import mpmath as mp +except ImportError: + pass + + +def compute_a(n): + """a_k from DLMF 5.11.6""" + a = [mp.sqrt(2)/2] + for k in range(1, n): + ak = a[-1]/k + for j in range(1, len(a)): + ak -= a[j]*a[-j]/(j + 1) + ak /= a[0]*(1 + mp.mpf(1)/(k + 1)) + a.append(ak) + return a + + +def compute_g(n): + """g_k from DLMF 5.11.3/5.11.5""" + a = compute_a(2*n) + g = [mp.sqrt(2)*mp.rf(0.5, k)*a[2*k] for k in range(n)] + return g + + +def eta(lam): + """Function from DLMF 8.12.1 shifted to be centered at 0.""" + if lam > 0: + return mp.sqrt(2*(lam - mp.log(lam + 1))) + elif lam < 0: + return -mp.sqrt(2*(lam - mp.log(lam + 1))) + else: + return 0 + + +def compute_alpha(n): + """alpha_n from DLMF 8.12.13""" + coeffs = mp.taylor(eta, 0, n - 1) + return lagrange_inversion(coeffs) + + +def compute_d(K, N): + """d_{k, n} from DLMF 8.12.12""" + M = N + 2*K + d0 = [-mp.mpf(1)/3] + alpha = compute_alpha(M + 2) + for n in range(1, M): + d0.append((n + 2)*alpha[n+2]) + d = [d0] + g = compute_g(K) + for k in range(1, K): + dk = [] + for n in range(M - 2*k): + dk.append((-1)**k*g[k]*d[0][n] + (n + 2)*d[k-1][n+2]) + d.append(dk) + for k in range(K): + d[k] = d[k][:N] + return d + + +header = \ +r"""/* This file was automatically generated by _precomp/gammainc.py. + * Do not edit it manually! + */ + +#ifndef IGAM_H +#define IGAM_H + +#define K {} +#define N {} + +static const double d[K][N] = +{{""" + +footer = \ +r""" +#endif +""" + + +def main(): + print(__doc__) + K = 25 + N = 25 + with mp.workdps(50): + d = compute_d(K, N) + fn = os.path.join(os.path.dirname(__file__), '..', 'cephes', 'igam.h') + with open(fn + '.new', 'w') as f: + f.write(header.format(K, N)) + for k, row in enumerate(d): + row = [mp.nstr(x, 17, min_fixed=0, max_fixed=0) for x in row] + f.write('{') + f.write(", ".join(row)) + if k < K - 1: + f.write('},\n') + else: + f.write('}};\n') + f.write(footer) + os.rename(fn + '.new', fn) + + +if __name__ == "__main__": + main() diff --git a/venv/lib/python3.10/site-packages/scipy/special/_precompute/gammainc_data.py b/venv/lib/python3.10/site-packages/scipy/special/_precompute/gammainc_data.py new file mode 100644 index 0000000000000000000000000000000000000000..ce8ae5f51b77f37367dc26cf08f3a0e64e3429a4 --- /dev/null +++ b/venv/lib/python3.10/site-packages/scipy/special/_precompute/gammainc_data.py @@ -0,0 +1,124 @@ +"""Compute gammainc and gammaincc for large arguments and parameters +and save the values to data files for use in tests. We can't just +compare to mpmath's gammainc in test_mpmath.TestSystematic because it +would take too long. + +Note that mpmath's gammainc is computed using hypercomb, but since it +doesn't allow the user to increase the maximum number of terms used in +the series it doesn't converge for many arguments. To get around this +we copy the mpmath implementation but use more terms. + +This takes about 17 minutes to run on a 2.3 GHz Macbook Pro with 4GB +ram. + +Sources: +[1] Fredrik Johansson and others. mpmath: a Python library for + arbitrary-precision floating-point arithmetic (version 0.19), + December 2013. http://mpmath.org/. + +""" +import os +from time import time +import numpy as np +from numpy import pi + +from scipy.special._mptestutils import mpf2float + +try: + import mpmath as mp +except ImportError: + pass + + +def gammainc(a, x, dps=50, maxterms=10**8): + """Compute gammainc exactly like mpmath does but allow for more + summands in hypercomb. See + + mpmath/functions/expintegrals.py#L134 + + in the mpmath github repository. + + """ + with mp.workdps(dps): + z, a, b = mp.mpf(a), mp.mpf(x), mp.mpf(x) + G = [z] + negb = mp.fneg(b, exact=True) + + def h(z): + T1 = [mp.exp(negb), b, z], [1, z, -1], [], G, [1], [1+z], b + return (T1,) + + res = mp.hypercomb(h, [z], maxterms=maxterms) + return mpf2float(res) + + +def gammaincc(a, x, dps=50, maxterms=10**8): + """Compute gammaincc exactly like mpmath does but allow for more + terms in hypercomb. See + + mpmath/functions/expintegrals.py#L187 + + in the mpmath github repository. + + """ + with mp.workdps(dps): + z, a = a, x + + if mp.isint(z): + try: + # mpmath has a fast integer path + return mpf2float(mp.gammainc(z, a=a, regularized=True)) + except mp.libmp.NoConvergence: + pass + nega = mp.fneg(a, exact=True) + G = [z] + # Use 2F0 series when possible; fall back to lower gamma representation + try: + def h(z): + r = z-1 + return [([mp.exp(nega), a], [1, r], [], G, [1, -r], [], 1/nega)] + return mpf2float(mp.hypercomb(h, [z], force_series=True)) + except mp.libmp.NoConvergence: + def h(z): + T1 = [], [1, z-1], [z], G, [], [], 0 + T2 = [-mp.exp(nega), a, z], [1, z, -1], [], G, [1], [1+z], a + return T1, T2 + return mpf2float(mp.hypercomb(h, [z], maxterms=maxterms)) + + +def main(): + t0 = time() + # It would be nice to have data for larger values, but either this + # requires prohibitively large precision (dps > 800) or mpmath has + # a bug. For example, gammainc(1e20, 1e20, dps=800) returns a + # value around 0.03, while the true value should be close to 0.5 + # (DLMF 8.12.15). + print(__doc__) + pwd = os.path.dirname(__file__) + r = np.logspace(4, 14, 30) + ltheta = np.logspace(np.log10(pi/4), np.log10(np.arctan(0.6)), 30) + utheta = np.logspace(np.log10(pi/4), np.log10(np.arctan(1.4)), 30) + + regimes = [(gammainc, ltheta), (gammaincc, utheta)] + for func, theta in regimes: + rg, thetag = np.meshgrid(r, theta) + a, x = rg*np.cos(thetag), rg*np.sin(thetag) + a, x = a.flatten(), x.flatten() + dataset = [] + for i, (a0, x0) in enumerate(zip(a, x)): + if func == gammaincc: + # Exploit the fast integer path in gammaincc whenever + # possible so that the computation doesn't take too + # long + a0, x0 = np.floor(a0), np.floor(x0) + dataset.append((a0, x0, func(a0, x0))) + dataset = np.array(dataset) + filename = os.path.join(pwd, '..', 'tests', 'data', 'local', + f'{func.__name__}.txt') + np.savetxt(filename, dataset) + + print(f"{(time() - t0)/60} minutes elapsed") + + +if __name__ == "__main__": + main() diff --git a/venv/lib/python3.10/site-packages/scipy/special/_precompute/lambertw.py b/venv/lib/python3.10/site-packages/scipy/special/_precompute/lambertw.py new file mode 100644 index 0000000000000000000000000000000000000000..1fdbf35b2cf85f1f7a6e73579546ed5cfe508fa6 --- /dev/null +++ b/venv/lib/python3.10/site-packages/scipy/special/_precompute/lambertw.py @@ -0,0 +1,68 @@ +"""Compute a Pade approximation for the principal branch of the +Lambert W function around 0 and compare it to various other +approximations. + +""" +import numpy as np + +try: + import mpmath + import matplotlib.pyplot as plt +except ImportError: + pass + + +def lambertw_pade(): + derivs = [mpmath.diff(mpmath.lambertw, 0, n=n) for n in range(6)] + p, q = mpmath.pade(derivs, 3, 2) + return p, q + + +def main(): + print(__doc__) + with mpmath.workdps(50): + p, q = lambertw_pade() + p, q = p[::-1], q[::-1] + print(f"p = {p}") + print(f"q = {q}") + + x, y = np.linspace(-1.5, 1.5, 75), np.linspace(-1.5, 1.5, 75) + x, y = np.meshgrid(x, y) + z = x + 1j*y + lambertw_std = [] + for z0 in z.flatten(): + lambertw_std.append(complex(mpmath.lambertw(z0))) + lambertw_std = np.array(lambertw_std).reshape(x.shape) + + fig, axes = plt.subplots(nrows=3, ncols=1) + # Compare Pade approximation to true result + p = np.array([float(p0) for p0 in p]) + q = np.array([float(q0) for q0 in q]) + pade_approx = np.polyval(p, z)/np.polyval(q, z) + pade_err = abs(pade_approx - lambertw_std) + axes[0].pcolormesh(x, y, pade_err) + # Compare two terms of asymptotic series to true result + asy_approx = np.log(z) - np.log(np.log(z)) + asy_err = abs(asy_approx - lambertw_std) + axes[1].pcolormesh(x, y, asy_err) + # Compare two terms of the series around the branch point to the + # true result + p = np.sqrt(2*(np.exp(1)*z + 1)) + series_approx = -1 + p - p**2/3 + series_err = abs(series_approx - lambertw_std) + im = axes[2].pcolormesh(x, y, series_err) + + fig.colorbar(im, ax=axes.ravel().tolist()) + plt.show() + + fig, ax = plt.subplots(nrows=1, ncols=1) + pade_better = pade_err < asy_err + im = ax.pcolormesh(x, y, pade_better) + t = np.linspace(-0.3, 0.3) + ax.plot(-2.5*abs(t) - 0.2, t, 'r') + fig.colorbar(im, ax=ax) + plt.show() + + +if __name__ == '__main__': + main() diff --git a/venv/lib/python3.10/site-packages/scipy/special/_precompute/loggamma.py b/venv/lib/python3.10/site-packages/scipy/special/_precompute/loggamma.py new file mode 100644 index 0000000000000000000000000000000000000000..74051ac7b46c70dc01919a362d05a8bbbe11333a --- /dev/null +++ b/venv/lib/python3.10/site-packages/scipy/special/_precompute/loggamma.py @@ -0,0 +1,43 @@ +"""Precompute series coefficients for log-Gamma.""" + +try: + import mpmath +except ImportError: + pass + + +def stirling_series(N): + with mpmath.workdps(100): + coeffs = [mpmath.bernoulli(2*n)/(2*n*(2*n - 1)) + for n in range(1, N + 1)] + return coeffs + + +def taylor_series_at_1(N): + coeffs = [] + with mpmath.workdps(100): + coeffs.append(-mpmath.euler) + for n in range(2, N + 1): + coeffs.append((-1)**n*mpmath.zeta(n)/n) + return coeffs + + +def main(): + print(__doc__) + print() + stirling_coeffs = [mpmath.nstr(x, 20, min_fixed=0, max_fixed=0) + for x in stirling_series(8)[::-1]] + taylor_coeffs = [mpmath.nstr(x, 20, min_fixed=0, max_fixed=0) + for x in taylor_series_at_1(23)[::-1]] + print("Stirling series coefficients") + print("----------------------------") + print("\n".join(stirling_coeffs)) + print() + print("Taylor series coefficients") + print("--------------------------") + print("\n".join(taylor_coeffs)) + print() + + +if __name__ == '__main__': + main() diff --git a/venv/lib/python3.10/site-packages/scipy/special/_precompute/struve_convergence.py b/venv/lib/python3.10/site-packages/scipy/special/_precompute/struve_convergence.py new file mode 100644 index 0000000000000000000000000000000000000000..dbf6009368540dbf603b61f5b72510f0acd1a65b --- /dev/null +++ b/venv/lib/python3.10/site-packages/scipy/special/_precompute/struve_convergence.py @@ -0,0 +1,131 @@ +""" +Convergence regions of the expansions used in ``struve.c`` + +Note that for v >> z both functions tend rapidly to 0, +and for v << -z, they tend to infinity. + +The floating-point functions over/underflow in the lower left and right +corners of the figure. + + +Figure legend +============= + +Red region + Power series is close (1e-12) to the mpmath result + +Blue region + Asymptotic series is close to the mpmath result + +Green region + Bessel series is close to the mpmath result + +Dotted colored lines + Boundaries of the regions + +Solid colored lines + Boundaries estimated by the routine itself. These will be used + for determining which of the results to use. + +Black dashed line + The line z = 0.7*|v| + 12 + +""" +import numpy as np +import matplotlib.pyplot as plt + +import mpmath + + +def err_metric(a, b, atol=1e-290): + m = abs(a - b) / (atol + abs(b)) + m[np.isinf(b) & (a == b)] = 0 + return m + + +def do_plot(is_h=True): + from scipy.special._ufuncs import (_struve_power_series, + _struve_asymp_large_z, + _struve_bessel_series) + + vs = np.linspace(-1000, 1000, 91) + zs = np.sort(np.r_[1e-5, 1.0, np.linspace(0, 700, 91)[1:]]) + + rp = _struve_power_series(vs[:,None], zs[None,:], is_h) + ra = _struve_asymp_large_z(vs[:,None], zs[None,:], is_h) + rb = _struve_bessel_series(vs[:,None], zs[None,:], is_h) + + mpmath.mp.dps = 50 + if is_h: + def sh(v, z): + return float(mpmath.struveh(mpmath.mpf(v), mpmath.mpf(z))) + else: + def sh(v, z): + return float(mpmath.struvel(mpmath.mpf(v), mpmath.mpf(z))) + ex = np.vectorize(sh, otypes='d')(vs[:,None], zs[None,:]) + + err_a = err_metric(ra[0], ex) + 1e-300 + err_p = err_metric(rp[0], ex) + 1e-300 + err_b = err_metric(rb[0], ex) + 1e-300 + + err_est_a = abs(ra[1]/ra[0]) + err_est_p = abs(rp[1]/rp[0]) + err_est_b = abs(rb[1]/rb[0]) + + z_cutoff = 0.7*abs(vs) + 12 + + levels = [-1000, -12] + + plt.cla() + + plt.hold(1) + plt.contourf(vs, zs, np.log10(err_p).T, + levels=levels, colors=['r', 'r'], alpha=0.1) + plt.contourf(vs, zs, np.log10(err_a).T, + levels=levels, colors=['b', 'b'], alpha=0.1) + plt.contourf(vs, zs, np.log10(err_b).T, + levels=levels, colors=['g', 'g'], alpha=0.1) + + plt.contour(vs, zs, np.log10(err_p).T, + levels=levels, colors=['r', 'r'], linestyles=[':', ':']) + plt.contour(vs, zs, np.log10(err_a).T, + levels=levels, colors=['b', 'b'], linestyles=[':', ':']) + plt.contour(vs, zs, np.log10(err_b).T, + levels=levels, colors=['g', 'g'], linestyles=[':', ':']) + + lp = plt.contour(vs, zs, np.log10(err_est_p).T, + levels=levels, colors=['r', 'r'], linestyles=['-', '-']) + la = plt.contour(vs, zs, np.log10(err_est_a).T, + levels=levels, colors=['b', 'b'], linestyles=['-', '-']) + lb = plt.contour(vs, zs, np.log10(err_est_b).T, + levels=levels, colors=['g', 'g'], linestyles=['-', '-']) + + plt.clabel(lp, fmt={-1000: 'P', -12: 'P'}) + plt.clabel(la, fmt={-1000: 'A', -12: 'A'}) + plt.clabel(lb, fmt={-1000: 'B', -12: 'B'}) + + plt.plot(vs, z_cutoff, 'k--') + + plt.xlim(vs.min(), vs.max()) + plt.ylim(zs.min(), zs.max()) + + plt.xlabel('v') + plt.ylabel('z') + + +def main(): + plt.clf() + plt.subplot(121) + do_plot(True) + plt.title('Struve H') + + plt.subplot(122) + do_plot(False) + plt.title('Struve L') + + plt.savefig('struve_convergence.png') + plt.show() + + +if __name__ == "__main__": + main() diff --git a/venv/lib/python3.10/site-packages/scipy/special/_precompute/utils.py b/venv/lib/python3.10/site-packages/scipy/special/_precompute/utils.py new file mode 100644 index 0000000000000000000000000000000000000000..55cf4083ed5e5a6628fd3316c02ce1a5ce21a92c --- /dev/null +++ b/venv/lib/python3.10/site-packages/scipy/special/_precompute/utils.py @@ -0,0 +1,38 @@ +try: + import mpmath as mp +except ImportError: + pass + +try: + from sympy.abc import x +except ImportError: + pass + + +def lagrange_inversion(a): + """Given a series + + f(x) = a[1]*x + a[2]*x**2 + ... + a[n-1]*x**(n - 1), + + use the Lagrange inversion formula to compute a series + + g(x) = b[1]*x + b[2]*x**2 + ... + b[n-1]*x**(n - 1) + + so that f(g(x)) = g(f(x)) = x mod x**n. We must have a[0] = 0, so + necessarily b[0] = 0 too. + + The algorithm is naive and could be improved, but speed isn't an + issue here and it's easy to read. + + """ + n = len(a) + f = sum(a[i]*x**i for i in range(n)) + h = (x/f).series(x, 0, n).removeO() + hpower = [h**0] + for k in range(n): + hpower.append((hpower[-1]*h).expand()) + b = [mp.mpf(0)] + for k in range(1, n): + b.append(hpower[k].coeff(x, k - 1)/k) + b = [mp.mpf(x) for x in b] + return b diff --git a/venv/lib/python3.10/site-packages/scipy/special/_precompute/wright_bessel.py b/venv/lib/python3.10/site-packages/scipy/special/_precompute/wright_bessel.py new file mode 100644 index 0000000000000000000000000000000000000000..51d56b1cd5c47c7ef005d21aad9827a1e85ec0d9 --- /dev/null +++ b/venv/lib/python3.10/site-packages/scipy/special/_precompute/wright_bessel.py @@ -0,0 +1,342 @@ +"""Precompute coefficients of several series expansions +of Wright's generalized Bessel function Phi(a, b, x). + +See https://dlmf.nist.gov/10.46.E1 with rho=a, beta=b, z=x. +""" +from argparse import ArgumentParser, RawTextHelpFormatter +import numpy as np +from scipy.integrate import quad +from scipy.optimize import minimize_scalar, curve_fit +from time import time + +try: + import sympy + from sympy import EulerGamma, Rational, S, Sum, \ + factorial, gamma, gammasimp, pi, polygamma, symbols, zeta + from sympy.polys.polyfuncs import horner +except ImportError: + pass + + +def series_small_a(): + """Tylor series expansion of Phi(a, b, x) in a=0 up to order 5. + """ + order = 5 + a, b, x, k = symbols("a b x k") + A = [] # terms with a + X = [] # terms with x + B = [] # terms with b (polygammas) + # Phi(a, b, x) = exp(x)/gamma(b) * sum(A[i] * X[i] * B[i]) + expression = Sum(x**k/factorial(k)/gamma(a*k+b), (k, 0, S.Infinity)) + expression = gamma(b)/sympy.exp(x) * expression + + # nth term of taylor series in a=0: a^n/n! * (d^n Phi(a, b, x)/da^n at a=0) + for n in range(0, order+1): + term = expression.diff(a, n).subs(a, 0).simplify().doit() + # set the whole bracket involving polygammas to 1 + x_part = (term.subs(polygamma(0, b), 1) + .replace(polygamma, lambda *args: 0)) + # sign convention: x part always positive + x_part *= (-1)**n + + A.append(a**n/factorial(n)) + X.append(horner(x_part)) + B.append(horner((term/x_part).simplify())) + + s = "Tylor series expansion of Phi(a, b, x) in a=0 up to order 5.\n" + s += "Phi(a, b, x) = exp(x)/gamma(b) * sum(A[i] * X[i] * B[i], i=0..5)\n" + for name, c in zip(['A', 'X', 'B'], [A, X, B]): + for i in range(len(c)): + s += f"\n{name}[{i}] = " + str(c[i]) + return s + + +# expansion of digamma +def dg_series(z, n): + """Symbolic expansion of digamma(z) in z=0 to order n. + + See https://dlmf.nist.gov/5.7.E4 and with https://dlmf.nist.gov/5.5.E2 + """ + k = symbols("k") + return -1/z - EulerGamma + \ + sympy.summation((-1)**k * zeta(k) * z**(k-1), (k, 2, n+1)) + + +def pg_series(k, z, n): + """Symbolic expansion of polygamma(k, z) in z=0 to order n.""" + return sympy.diff(dg_series(z, n+k), z, k) + + +def series_small_a_small_b(): + """Tylor series expansion of Phi(a, b, x) in a=0 and b=0 up to order 5. + + Be aware of cancellation of poles in b=0 of digamma(b)/Gamma(b) and + polygamma functions. + + digamma(b)/Gamma(b) = -1 - 2*M_EG*b + O(b^2) + digamma(b)^2/Gamma(b) = 1/b + 3*M_EG + b*(-5/12*PI^2+7/2*M_EG^2) + O(b^2) + polygamma(1, b)/Gamma(b) = 1/b + M_EG + b*(1/12*PI^2 + 1/2*M_EG^2) + O(b^2) + and so on. + """ + order = 5 + a, b, x, k = symbols("a b x k") + M_PI, M_EG, M_Z3 = symbols("M_PI M_EG M_Z3") + c_subs = {pi: M_PI, EulerGamma: M_EG, zeta(3): M_Z3} + A = [] # terms with a + X = [] # terms with x + B = [] # terms with b (polygammas expanded) + C = [] # terms that generate B + # Phi(a, b, x) = exp(x) * sum(A[i] * X[i] * B[i]) + # B[0] = 1 + # B[k] = sum(C[k] * b**k/k!, k=0..) + # Note: C[k] can be obtained from a series expansion of 1/gamma(b). + expression = gamma(b)/sympy.exp(x) * \ + Sum(x**k/factorial(k)/gamma(a*k+b), (k, 0, S.Infinity)) + + # nth term of taylor series in a=0: a^n/n! * (d^n Phi(a, b, x)/da^n at a=0) + for n in range(0, order+1): + term = expression.diff(a, n).subs(a, 0).simplify().doit() + # set the whole bracket involving polygammas to 1 + x_part = (term.subs(polygamma(0, b), 1) + .replace(polygamma, lambda *args: 0)) + # sign convention: x part always positive + x_part *= (-1)**n + # expansion of polygamma part with 1/gamma(b) + pg_part = term/x_part/gamma(b) + if n >= 1: + # Note: highest term is digamma^n + pg_part = pg_part.replace(polygamma, + lambda k, x: pg_series(k, x, order+1+n)) + pg_part = (pg_part.series(b, 0, n=order+1-n) + .removeO() + .subs(polygamma(2, 1), -2*zeta(3)) + .simplify() + ) + + A.append(a**n/factorial(n)) + X.append(horner(x_part)) + B.append(pg_part) + + # Calculate C and put in the k! + C = sympy.Poly(B[1].subs(c_subs), b).coeffs() + C.reverse() + for i in range(len(C)): + C[i] = (C[i] * factorial(i)).simplify() + + s = "Tylor series expansion of Phi(a, b, x) in a=0 and b=0 up to order 5." + s += "\nPhi(a, b, x) = exp(x) * sum(A[i] * X[i] * B[i], i=0..5)\n" + s += "B[0] = 1\n" + s += "B[i] = sum(C[k+i-1] * b**k/k!, k=0..)\n" + s += "\nM_PI = pi" + s += "\nM_EG = EulerGamma" + s += "\nM_Z3 = zeta(3)" + for name, c in zip(['A', 'X'], [A, X]): + for i in range(len(c)): + s += f"\n{name}[{i}] = " + s += str(c[i]) + # For C, do also compute the values numerically + for i in range(len(C)): + s += f"\n# C[{i}] = " + s += str(C[i]) + s += f"\nC[{i}] = " + s += str(C[i].subs({M_EG: EulerGamma, M_PI: pi, M_Z3: zeta(3)}) + .evalf(17)) + + # Does B have the assumed structure? + s += "\n\nTest if B[i] does have the assumed structure." + s += "\nC[i] are derived from B[1] alone." + s += "\nTest B[2] == C[1] + b*C[2] + b^2/2*C[3] + b^3/6*C[4] + .." + test = sum([b**k/factorial(k) * C[k+1] for k in range(order-1)]) + test = (test - B[2].subs(c_subs)).simplify() + s += f"\ntest successful = {test==S(0)}" + s += "\nTest B[3] == C[2] + b*C[3] + b^2/2*C[4] + .." + test = sum([b**k/factorial(k) * C[k+2] for k in range(order-2)]) + test = (test - B[3].subs(c_subs)).simplify() + s += f"\ntest successful = {test==S(0)}" + return s + + +def asymptotic_series(): + """Asymptotic expansion for large x. + + Phi(a, b, x) ~ Z^(1/2-b) * exp((1+a)/a * Z) * sum_k (-1)^k * C_k / Z^k + Z = (a*x)^(1/(1+a)) + + Wright (1935) lists the coefficients C_0 and C_1 (he calls them a_0 and + a_1). With slightly different notation, Paris (2017) lists coefficients + c_k up to order k=3. + Paris (2017) uses ZP = (1+a)/a * Z (ZP = Z of Paris) and + C_k = C_0 * (-a/(1+a))^k * c_k + """ + order = 8 + + class g(sympy.Function): + """Helper function g according to Wright (1935) + + g(n, rho, v) = (1 + (rho+2)/3 * v + (rho+2)*(rho+3)/(2*3) * v^2 + ...) + + Note: Wright (1935) uses square root of above definition. + """ + nargs = 3 + + @classmethod + def eval(cls, n, rho, v): + if not n >= 0: + raise ValueError("must have n >= 0") + elif n == 0: + return 1 + else: + return g(n-1, rho, v) \ + + gammasimp(gamma(rho+2+n)/gamma(rho+2)) \ + / gammasimp(gamma(3+n)/gamma(3))*v**n + + class coef_C(sympy.Function): + """Calculate coefficients C_m for integer m. + + C_m is the coefficient of v^(2*m) in the Taylor expansion in v=0 of + Gamma(m+1/2)/(2*pi) * (2/(rho+1))^(m+1/2) * (1-v)^(-b) + * g(rho, v)^(-m-1/2) + """ + nargs = 3 + + @classmethod + def eval(cls, m, rho, beta): + if not m >= 0: + raise ValueError("must have m >= 0") + + v = symbols("v") + expression = (1-v)**(-beta) * g(2*m, rho, v)**(-m-Rational(1, 2)) + res = expression.diff(v, 2*m).subs(v, 0) / factorial(2*m) + res = res * (gamma(m + Rational(1, 2)) / (2*pi) + * (2/(rho+1))**(m + Rational(1, 2))) + return res + + # in order to have nice ordering/sorting of expressions, we set a = xa. + xa, b, xap1 = symbols("xa b xap1") + C0 = coef_C(0, xa, b) + # a1 = a(1, rho, beta) + s = "Asymptotic expansion for large x\n" + s += "Phi(a, b, x) = Z**(1/2-b) * exp((1+a)/a * Z) \n" + s += " * sum((-1)**k * C[k]/Z**k, k=0..6)\n\n" + s += "Z = pow(a * x, 1/(1+a))\n" + s += "A[k] = pow(a, k)\n" + s += "B[k] = pow(b, k)\n" + s += "Ap1[k] = pow(1+a, k)\n\n" + s += "C[0] = 1./sqrt(2. * M_PI * Ap1[1])\n" + for i in range(1, order+1): + expr = (coef_C(i, xa, b) / (C0/(1+xa)**i)).simplify() + factor = [x.denominator() for x in sympy.Poly(expr).coeffs()] + factor = sympy.lcm(factor) + expr = (expr * factor).simplify().collect(b, sympy.factor) + expr = expr.xreplace({xa+1: xap1}) + s += f"C[{i}] = C[0] / ({factor} * Ap1[{i}])\n" + s += f"C[{i}] *= {str(expr)}\n\n" + import re + re_a = re.compile(r'xa\*\*(\d+)') + s = re_a.sub(r'A[\1]', s) + re_b = re.compile(r'b\*\*(\d+)') + s = re_b.sub(r'B[\1]', s) + s = s.replace('xap1', 'Ap1[1]') + s = s.replace('xa', 'a') + # max integer = 2^31-1 = 2,147,483,647. Solution: Put a point after 10 + # or more digits. + re_digits = re.compile(r'(\d{10,})') + s = re_digits.sub(r'\1.', s) + return s + + +def optimal_epsilon_integral(): + """Fit optimal choice of epsilon for integral representation. + + The integrand of + int_0^pi P(eps, a, b, x, phi) * dphi + can exhibit oscillatory behaviour. It stems from the cosine of P and can be + minimized by minimizing the arc length of the argument + f(phi) = eps * sin(phi) - x * eps^(-a) * sin(a * phi) + (1 - b) * phi + of cos(f(phi)). + We minimize the arc length in eps for a grid of values (a, b, x) and fit a + parametric function to it. + """ + def fp(eps, a, b, x, phi): + """Derivative of f w.r.t. phi.""" + eps_a = np.power(1. * eps, -a) + return eps * np.cos(phi) - a * x * eps_a * np.cos(a * phi) + 1 - b + + def arclength(eps, a, b, x, epsrel=1e-2, limit=100): + """Compute Arc length of f. + + Note that the arc length of a function f from t0 to t1 is given by + int_t0^t1 sqrt(1 + f'(t)^2) dt + """ + return quad(lambda phi: np.sqrt(1 + fp(eps, a, b, x, phi)**2), + 0, np.pi, + epsrel=epsrel, limit=100)[0] + + # grid of minimal arc length values + data_a = [1e-3, 0.1, 0.5, 0.9, 1, 2, 4, 5, 6, 8] + data_b = [0, 1, 4, 7, 10] + data_x = [1, 1.5, 2, 4, 10, 20, 50, 100, 200, 500, 1e3, 5e3, 1e4] + data_a, data_b, data_x = np.meshgrid(data_a, data_b, data_x) + data_a, data_b, data_x = (data_a.flatten(), data_b.flatten(), + data_x.flatten()) + best_eps = [] + for i in range(data_x.size): + best_eps.append( + minimize_scalar(lambda eps: arclength(eps, data_a[i], data_b[i], + data_x[i]), + bounds=(1e-3, 1000), + method='Bounded', options={'xatol': 1e-3}).x + ) + best_eps = np.array(best_eps) + # pandas would be nice, but here a dictionary is enough + df = {'a': data_a, + 'b': data_b, + 'x': data_x, + 'eps': best_eps, + } + + def func(data, A0, A1, A2, A3, A4, A5): + """Compute parametric function to fit.""" + a = data['a'] + b = data['b'] + x = data['x'] + return (A0 * b * np.exp(-0.5 * a) + + np.exp(A1 + 1 / (1 + a) * np.log(x) - A2 * np.exp(-A3 * a) + + A4 / (1 + np.exp(A5 * a)))) + + func_params = list(curve_fit(func, df, df['eps'], method='trf')[0]) + + s = "Fit optimal eps for integrand P via minimal arc length\n" + s += "with parametric function:\n" + s += "optimal_eps = (A0 * b * exp(-a/2) + exp(A1 + 1 / (1 + a) * log(x)\n" + s += " - A2 * exp(-A3 * a) + A4 / (1 + exp(A5 * a)))\n\n" + s += "Fitted parameters A0 to A5 are:\n" + s += ', '.join([f'{x:.5g}' for x in func_params]) + return s + + +def main(): + t0 = time() + parser = ArgumentParser(description=__doc__, + formatter_class=RawTextHelpFormatter) + parser.add_argument('action', type=int, choices=[1, 2, 3, 4], + help='chose what expansion to precompute\n' + '1 : Series for small a\n' + '2 : Series for small a and small b\n' + '3 : Asymptotic series for large x\n' + ' This may take some time (>4h).\n' + '4 : Fit optimal eps for integral representation.' + ) + args = parser.parse_args() + + switch = {1: lambda: print(series_small_a()), + 2: lambda: print(series_small_a_small_b()), + 3: lambda: print(asymptotic_series()), + 4: lambda: print(optimal_epsilon_integral()) + } + switch.get(args.action, lambda: print("Invalid input."))() + print(f"\n{(time() - t0)/60:.1f} minutes elapsed.\n") + + +if __name__ == '__main__': + main() diff --git a/venv/lib/python3.10/site-packages/scipy/special/_precompute/wright_bessel_data.py b/venv/lib/python3.10/site-packages/scipy/special/_precompute/wright_bessel_data.py new file mode 100644 index 0000000000000000000000000000000000000000..1de9b4fe552ca9178c452194ab84af6ca5daac71 --- /dev/null +++ b/venv/lib/python3.10/site-packages/scipy/special/_precompute/wright_bessel_data.py @@ -0,0 +1,152 @@ +"""Compute a grid of values for Wright's generalized Bessel function +and save the values to data files for use in tests. Using mpmath directly in +tests would take too long. + +This takes about 10 minutes to run on a 2.7 GHz i7 Macbook Pro. +""" +from functools import lru_cache +import os +from time import time + +import numpy as np +from scipy.special._mptestutils import mpf2float + +try: + import mpmath as mp +except ImportError: + pass + +# exp_inf: smallest value x for which exp(x) == inf +exp_inf = 709.78271289338403 + + +# 64 Byte per value +@lru_cache(maxsize=100_000) +def rgamma_cached(x, dps): + with mp.workdps(dps): + return mp.rgamma(x) + + +def mp_wright_bessel(a, b, x, dps=50, maxterms=2000): + """Compute Wright's generalized Bessel function as Series with mpmath. + """ + with mp.workdps(dps): + a, b, x = mp.mpf(a), mp.mpf(b), mp.mpf(x) + res = mp.nsum(lambda k: x**k / mp.fac(k) + * rgamma_cached(a * k + b, dps=dps), + [0, mp.inf], + tol=dps, method='s', steps=[maxterms] + ) + return mpf2float(res) + + +def main(): + t0 = time() + print(__doc__) + pwd = os.path.dirname(__file__) + eps = np.finfo(float).eps * 100 + + a_range = np.array([eps, + 1e-4 * (1 - eps), 1e-4, 1e-4 * (1 + eps), + 1e-3 * (1 - eps), 1e-3, 1e-3 * (1 + eps), + 0.1, 0.5, + 1 * (1 - eps), 1, 1 * (1 + eps), + 1.5, 2, 4.999, 5, 10]) + b_range = np.array([0, eps, 1e-10, 1e-5, 0.1, 1, 2, 10, 20, 100]) + x_range = np.array([0, eps, 1 - eps, 1, 1 + eps, + 1.5, + 2 - eps, 2, 2 + eps, + 9 - eps, 9, 9 + eps, + 10 * (1 - eps), 10, 10 * (1 + eps), + 100 * (1 - eps), 100, 100 * (1 + eps), + 500, exp_inf, 1e3, 1e5, 1e10, 1e20]) + + a_range, b_range, x_range = np.meshgrid(a_range, b_range, x_range, + indexing='ij') + a_range = a_range.flatten() + b_range = b_range.flatten() + x_range = x_range.flatten() + + # filter out some values, especially too large x + bool_filter = ~((a_range < 5e-3) & (x_range >= exp_inf)) + bool_filter = bool_filter & ~((a_range < 0.2) & (x_range > exp_inf)) + bool_filter = bool_filter & ~((a_range < 0.5) & (x_range > 1e3)) + bool_filter = bool_filter & ~((a_range < 0.56) & (x_range > 5e3)) + bool_filter = bool_filter & ~((a_range < 1) & (x_range > 1e4)) + bool_filter = bool_filter & ~((a_range < 1.4) & (x_range > 1e5)) + bool_filter = bool_filter & ~((a_range < 1.8) & (x_range > 1e6)) + bool_filter = bool_filter & ~((a_range < 2.2) & (x_range > 1e7)) + bool_filter = bool_filter & ~((a_range < 2.5) & (x_range > 1e8)) + bool_filter = bool_filter & ~((a_range < 2.9) & (x_range > 1e9)) + bool_filter = bool_filter & ~((a_range < 3.3) & (x_range > 1e10)) + bool_filter = bool_filter & ~((a_range < 3.7) & (x_range > 1e11)) + bool_filter = bool_filter & ~((a_range < 4) & (x_range > 1e12)) + bool_filter = bool_filter & ~((a_range < 4.4) & (x_range > 1e13)) + bool_filter = bool_filter & ~((a_range < 4.7) & (x_range > 1e14)) + bool_filter = bool_filter & ~((a_range < 5.1) & (x_range > 1e15)) + bool_filter = bool_filter & ~((a_range < 5.4) & (x_range > 1e16)) + bool_filter = bool_filter & ~((a_range < 5.8) & (x_range > 1e17)) + bool_filter = bool_filter & ~((a_range < 6.2) & (x_range > 1e18)) + bool_filter = bool_filter & ~((a_range < 6.2) & (x_range > 1e18)) + bool_filter = bool_filter & ~((a_range < 6.5) & (x_range > 1e19)) + bool_filter = bool_filter & ~((a_range < 6.9) & (x_range > 1e20)) + + # filter out known values that do not meet the required numerical accuracy + # see test test_wright_data_grid_failures + failing = np.array([ + [0.1, 100, 709.7827128933841], + [0.5, 10, 709.7827128933841], + [0.5, 10, 1000], + [0.5, 100, 1000], + [1, 20, 100000], + [1, 100, 100000], + [1.0000000000000222, 20, 100000], + [1.0000000000000222, 100, 100000], + [1.5, 0, 500], + [1.5, 2.220446049250313e-14, 500], + [1.5, 1.e-10, 500], + [1.5, 1.e-05, 500], + [1.5, 0.1, 500], + [1.5, 20, 100000], + [1.5, 100, 100000], + ]).tolist() + + does_fail = np.full_like(a_range, False, dtype=bool) + for i in range(x_range.size): + if [a_range[i], b_range[i], x_range[i]] in failing: + does_fail[i] = True + + # filter and flatten + a_range = a_range[bool_filter] + b_range = b_range[bool_filter] + x_range = x_range[bool_filter] + does_fail = does_fail[bool_filter] + + dataset = [] + print(f"Computing {x_range.size} single points.") + print("Tests will fail for the following data points:") + for i in range(x_range.size): + a = a_range[i] + b = b_range[i] + x = x_range[i] + # take care of difficult corner cases + maxterms = 1000 + if a < 1e-6 and x >= exp_inf/10: + maxterms = 2000 + f = mp_wright_bessel(a, b, x, maxterms=maxterms) + if does_fail[i]: + print("failing data point a, b, x, value = " + f"[{a}, {b}, {x}, {f}]") + else: + dataset.append((a, b, x, f)) + dataset = np.array(dataset) + + filename = os.path.join(pwd, '..', 'tests', 'data', 'local', + 'wright_bessel.txt') + np.savetxt(filename, dataset) + + print(f"{(time() - t0)/60:.1f} minutes elapsed") + + +if __name__ == "__main__": + main() diff --git a/venv/lib/python3.10/site-packages/scipy/special/_precompute/wrightomega.py b/venv/lib/python3.10/site-packages/scipy/special/_precompute/wrightomega.py new file mode 100644 index 0000000000000000000000000000000000000000..0bcd0345a9c1b90c45b0e9e3340ab4da4ec5c6d7 --- /dev/null +++ b/venv/lib/python3.10/site-packages/scipy/special/_precompute/wrightomega.py @@ -0,0 +1,41 @@ +import numpy as np + +try: + import mpmath +except ImportError: + pass + + +def mpmath_wrightomega(x): + return mpmath.lambertw(mpmath.exp(x), mpmath.mpf('-0.5')) + + +def wrightomega_series_error(x): + series = x + desired = mpmath_wrightomega(x) + return abs(series - desired) / desired + + +def wrightomega_exp_error(x): + exponential_approx = mpmath.exp(x) + desired = mpmath_wrightomega(x) + return abs(exponential_approx - desired) / desired + + +def main(): + desired_error = 2 * np.finfo(float).eps + print('Series Error') + for x in [1e5, 1e10, 1e15, 1e20]: + with mpmath.workdps(100): + error = wrightomega_series_error(x) + print(x, error, error < desired_error) + + print('Exp error') + for x in [-10, -25, -50, -100, -200, -400, -700, -740]: + with mpmath.workdps(100): + error = wrightomega_exp_error(x) + print(x, error, error < desired_error) + + +if __name__ == '__main__': + main() diff --git a/venv/lib/python3.10/site-packages/scipy/special/_precompute/zetac.py b/venv/lib/python3.10/site-packages/scipy/special/_precompute/zetac.py new file mode 100644 index 0000000000000000000000000000000000000000..d408b1a2fffb6872287452923fcc9394adc13a7c --- /dev/null +++ b/venv/lib/python3.10/site-packages/scipy/special/_precompute/zetac.py @@ -0,0 +1,27 @@ +"""Compute the Taylor series for zeta(x) - 1 around x = 0.""" +try: + import mpmath +except ImportError: + pass + + +def zetac_series(N): + coeffs = [] + with mpmath.workdps(100): + coeffs.append(-1.5) + for n in range(1, N): + coeff = mpmath.diff(mpmath.zeta, 0, n)/mpmath.factorial(n) + coeffs.append(coeff) + return coeffs + + +def main(): + print(__doc__) + coeffs = zetac_series(10) + coeffs = [mpmath.nstr(x, 20, min_fixed=0, max_fixed=0) + for x in coeffs] + print("\n".join(coeffs[::-1])) + + +if __name__ == '__main__': + main() diff --git a/venv/lib/python3.10/site-packages/scipy/special/special/binom.h b/venv/lib/python3.10/site-packages/scipy/special/special/binom.h new file mode 100644 index 0000000000000000000000000000000000000000..0641b28a8dac29f93cac0857bf2432d4cbc0e747 --- /dev/null +++ b/venv/lib/python3.10/site-packages/scipy/special/special/binom.h @@ -0,0 +1,85 @@ +/* Translated from Cython into C++ by SciPy developers in 2024. + * + * Original authors: Pauli Virtanen, Eric Moore + */ + +// Binomial coefficient + +#pragma once + +#include "config.h" + +#include "cephes/beta.h" +#include "cephes/gamma.h" + +namespace special { + +SPECFUN_HOST_DEVICE inline double binom(double n, double k) { + double kx, nx, num, den, dk, sgn; + + if (n < 0) { + nx = std::floor(n); + if (n == nx) { + // Undefined + return std::numeric_limits::quiet_NaN(); + } + } + + kx = std::floor(k); + if (k == kx && (std::abs(n) > 1E-8 || n == 0)) { + /* Integer case: use multiplication formula for less rounding + * error for cases where the result is an integer. + * + * This cannot be used for small nonzero n due to loss of + * precision. */ + nx = std::floor(n); + if (nx == n && kx > nx / 2 && nx > 0) { + // Reduce kx by symmetry + kx = nx - kx; + } + + if (kx >= 0 && kx < 20) { + num = 1.0; + den = 1.0; + for (int i = 1; i < 1 + static_cast(kx); i++) { + num *= i + n - kx; + den *= i; + if (std::abs(num) > 1E50) { + num /= den; + den = 1.0; + } + } + return num / den; + } + } + + // general case + if (n >= 1E10 * k and k > 0) { + // avoid under/overflows intermediate results + return std::exp(-cephes::lbeta(1 + n - k, 1 + k) - std::log(n + 1)); + } + if (k > 1E8 * std::abs(n)) { + // avoid loss of precision + num = cephes::Gamma(1 + n) / std::abs(k) + cephes::Gamma(1 + n) * n / (2 * k * k); // + ... + num /= M_PI * std::pow(std::abs(k), n); + if (k > 0) { + kx = std::floor(k); + if (static_cast(kx) == kx) { + dk = k - kx; + sgn = (static_cast(kx) % 2 == 0) ? 1 : -1; + } else { + dk = k; + sgn = 1; + } + return num * std::sin((dk - n) * M_PI) * sgn; + } + kx = std::floor(k); + if (static_cast(kx) == kx) { + return 0; + } + return num * std::sin(k * M_PI); + } + return 1 / (n + 1) / cephes::beta(1 + n - k, 1 + k); +} + +} // namespace special diff --git a/venv/lib/python3.10/site-packages/scipy/special/special/cephes/beta.h b/venv/lib/python3.10/site-packages/scipy/special/special/cephes/beta.h new file mode 100644 index 0000000000000000000000000000000000000000..45acb23748f81e244b38f7374c701d8c5074c753 --- /dev/null +++ b/venv/lib/python3.10/site-packages/scipy/special/special/cephes/beta.h @@ -0,0 +1,255 @@ +/* Translated into C++ by SciPy developers in 2024. + * Original header with Copyright information appears below. + */ + +/* beta.c + * + * Beta function + * + * + * + * SYNOPSIS: + * + * double a, b, y, beta(); + * + * y = beta( a, b ); + * + * + * + * DESCRIPTION: + * + * - - + * | (a) | (b) + * beta( a, b ) = -----------. + * - + * | (a+b) + * + * For large arguments the logarithm of the function is + * evaluated using lgam(), then exponentiated. + * + * + * + * ACCURACY: + * + * Relative error: + * arithmetic domain # trials peak rms + * IEEE 0,30 30000 8.1e-14 1.1e-14 + * + * ERROR MESSAGES: + * + * message condition value returned + * beta overflow log(beta) > MAXLOG 0.0 + * a or b <0 integer 0.0 + * + */ + +/* + * Cephes Math Library Release 2.0: April, 1987 + * Copyright 1984, 1987 by Stephen L. Moshier + * Direct inquiries to 30 Frost Street, Cambridge, MA 02140 + */ +#pragma once + +#include "../config.h" +#include "const.h" +#include "gamma.h" + +namespace special { +namespace cephes { + + SPECFUN_HOST_DEVICE double beta(double, double); + SPECFUN_HOST_DEVICE double lbeta(double, double); + + namespace detail { + constexpr double beta_ASYMP_FACTOR = 1e6; + + /* + * Asymptotic expansion for ln(|B(a, b)|) for a > ASYMP_FACTOR*max(|b|, 1). + */ + SPECFUN_HOST_DEVICE inline double lbeta_asymp(double a, double b, int *sgn) { + double r = lgam_sgn(b, sgn); + r -= b * std::log(a); + + r += b * (1 - b) / (2 * a); + r += b * (1 - b) * (1 - 2 * b) / (12 * a * a); + r += -b * b * (1 - b) * (1 - b) / (12 * a * a * a); + + return r; + } + + /* + * Special case for a negative integer argument + */ + + SPECFUN_HOST_DEVICE inline double beta_negint(int a, double b) { + int sgn; + if (b == static_cast(b) && 1 - a - b > 0) { + sgn = (static_cast(b) % 2 == 0) ? 1 : -1; + return sgn * special::cephes::beta(1 - a - b, b); + } else { + set_error("lbeta", SF_ERROR_OVERFLOW, NULL); + return std::numeric_limits::infinity(); + } + } + + SPECFUN_HOST_DEVICE inline double lbeta_negint(int a, double b) { + double r; + if (b == static_cast(b) && 1 - a - b > 0) { + r = special::cephes::lbeta(1 - a - b, b); + return r; + } else { + set_error("lbeta", SF_ERROR_OVERFLOW, NULL); + return std::numeric_limits::infinity(); + } + } + } // namespace detail + + SPECFUN_HOST_DEVICE inline double beta(double a, double b) { + double y; + int sign = 1; + + if (a <= 0.0) { + if (a == std::floor(a)) { + if (a == static_cast(a)) { + return detail::beta_negint(static_cast(a), b); + } else { + goto overflow; + } + } + } + + if (b <= 0.0) { + if (b == std::floor(b)) { + if (b == static_cast(b)) { + return detail::beta_negint(static_cast(b), a); + } else { + goto overflow; + } + } + } + + if (std::abs(a) < std::abs(b)) { + y = a; + a = b; + b = y; + } + + if (std::abs(a) > detail::beta_ASYMP_FACTOR * std::abs(b) && a > detail::beta_ASYMP_FACTOR) { + /* Avoid loss of precision in lgam(a + b) - lgam(a) */ + y = detail::lbeta_asymp(a, b, &sign); + return sign * std::exp(y); + } + + y = a + b; + if (std::abs(y) > detail::MAXGAM || std::abs(a) > detail::MAXGAM || std::abs(b) > detail::MAXGAM) { + int sgngam; + y = detail::lgam_sgn(y, &sgngam); + sign *= sgngam; /* keep track of the sign */ + y = detail::lgam_sgn(b, &sgngam) - y; + sign *= sgngam; + y = detail::lgam_sgn(a, &sgngam) + y; + sign *= sgngam; + if (y > detail::MAXLOG) { + goto overflow; + } + return (sign * std::exp(y)); + } + + y = Gamma(y); + a = Gamma(a); + b = Gamma(b); + if (y == 0.0) + goto overflow; + + if (std::abs(std::abs(a) - std::abs(y)) > std::abs(std::abs(b) - std::abs(y))) { + y = b / y; + y *= a; + } else { + y = a / y; + y *= b; + } + + return (y); + + overflow: + set_error("beta", SF_ERROR_OVERFLOW, NULL); + return (sign * std::numeric_limits::infinity()); + } + + /* Natural log of |beta|. */ + + SPECFUN_HOST_DEVICE inline double lbeta(double a, double b) { + double y; + int sign; + + sign = 1; + + if (a <= 0.0) { + if (a == std::floor(a)) { + if (a == static_cast(a)) { + return detail::lbeta_negint(static_cast(a), b); + } else { + goto over; + } + } + } + + if (b <= 0.0) { + if (b == std::floor(b)) { + if (b == static_cast(b)) { + return detail::lbeta_negint(static_cast(b), a); + } else { + goto over; + } + } + } + + if (std::abs(a) < std::abs(b)) { + y = a; + a = b; + b = y; + } + + if (std::abs(a) > detail::beta_ASYMP_FACTOR * std::abs(b) && a > detail::beta_ASYMP_FACTOR) { + /* Avoid loss of precision in lgam(a + b) - lgam(a) */ + y = detail::lbeta_asymp(a, b, &sign); + return y; + } + + y = a + b; + if (std::abs(y) > detail::MAXGAM || std::abs(a) > detail::MAXGAM || std::abs(b) > detail::MAXGAM) { + int sgngam; + y = detail::lgam_sgn(y, &sgngam); + sign *= sgngam; /* keep track of the sign */ + y = detail::lgam_sgn(b, &sgngam) - y; + sign *= sgngam; + y = detail::lgam_sgn(a, &sgngam) + y; + sign *= sgngam; + return (y); + } + + y = Gamma(y); + a = Gamma(a); + b = Gamma(b); + if (y == 0.0) { + over: + set_error("lbeta", SF_ERROR_OVERFLOW, NULL); + return (sign * std::numeric_limits::infinity()); + } + + if (std::abs(std::abs(a) - std::abs(y)) > std::abs(std::abs(b) - std::abs(y))) { + y = b / y; + y *= a; + } else { + y = a / y; + y *= b; + } + + if (y < 0) { + y = -y; + } + + return (std::log(y)); + } +} // namespace cephes +} // namespace special diff --git a/venv/lib/python3.10/site-packages/scipy/special/special/cephes/gamma.h b/venv/lib/python3.10/site-packages/scipy/special/special/cephes/gamma.h new file mode 100644 index 0000000000000000000000000000000000000000..0a923bb0bc28eed010902f113888e4beb975c775 --- /dev/null +++ b/venv/lib/python3.10/site-packages/scipy/special/special/cephes/gamma.h @@ -0,0 +1,343 @@ +/* Translated into C++ by SciPy developers in 2024. + * Original header with Copyright information appears below. + */ + +/* + * Gamma function + * + * + * + * SYNOPSIS: + * + * double x, y, Gamma(); + * + * y = Gamma( x ); + * + * + * + * DESCRIPTION: + * + * Returns Gamma function of the argument. The result is + * correctly signed. + * + * Arguments |x| <= 34 are reduced by recurrence and the function + * approximated by a rational function of degree 6/7 in the + * interval (2,3). Large arguments are handled by Stirling's + * formula. Large negative arguments are made positive using + * a reflection formula. + * + * + * ACCURACY: + * + * Relative error: + * arithmetic domain # trials peak rms + * IEEE -170,-33 20000 2.3e-15 3.3e-16 + * IEEE -33, 33 20000 9.4e-16 2.2e-16 + * IEEE 33, 171.6 20000 2.3e-15 3.2e-16 + * + * Error for arguments outside the test range will be larger + * owing to error amplification by the exponential function. + * + */ + +/* lgam() + * + * Natural logarithm of Gamma function + * + * + * + * SYNOPSIS: + * + * double x, y, lgam(); + * + * y = lgam( x ); + * + * + * + * DESCRIPTION: + * + * Returns the base e (2.718...) logarithm of the absolute + * value of the Gamma function of the argument. + * + * For arguments greater than 13, the logarithm of the Gamma + * function is approximated by the logarithmic version of + * Stirling's formula using a polynomial approximation of + * degree 4. Arguments between -33 and +33 are reduced by + * recurrence to the interval [2,3] of a rational approximation. + * The cosecant reflection formula is employed for arguments + * less than -33. + * + * Arguments greater than MAXLGM return INFINITY and an error + * message. MAXLGM = 2.556348e305 for IEEE arithmetic. + * + * + * + * ACCURACY: + * + * + * arithmetic domain # trials peak rms + * IEEE 0, 3 28000 5.4e-16 1.1e-16 + * IEEE 2.718, 2.556e305 40000 3.5e-16 8.3e-17 + * The error criterion was relative when the function magnitude + * was greater than one but absolute when it was less than one. + * + * The following test used the relative error criterion, though + * at certain points the relative error could be much higher than + * indicated. + * IEEE -200, -4 10000 4.8e-16 1.3e-16 + * + */ + +/* + * Cephes Math Library Release 2.2: July, 1992 + * Copyright 1984, 1987, 1989, 1992 by Stephen L. Moshier + * Direct inquiries to 30 Frost Street, Cambridge, MA 02140 + */ +#pragma once + +#include "../config.h" +#include "../error.h" +#include "polevl.h" + +namespace special { +namespace cephes { + namespace detail { + constexpr double gamma_P[] = {1.60119522476751861407E-4, 1.19135147006586384913E-3, 1.04213797561761569935E-2, + 4.76367800457137231464E-2, 2.07448227648435975150E-1, 4.94214826801497100753E-1, + 9.99999999999999996796E-1}; + + constexpr double gamma_Q[] = {-2.31581873324120129819E-5, 5.39605580493303397842E-4, -4.45641913851797240494E-3, + 1.18139785222060435552E-2, 3.58236398605498653373E-2, -2.34591795718243348568E-1, + 7.14304917030273074085E-2, 1.00000000000000000320E0}; + + constexpr double MAXGAM = 171.624376956302725; + constexpr double LOGPI = 1.14472988584940017414; + + /* Stirling's formula for the Gamma function */ + constexpr double gamma_STIR[5] = { + 7.87311395793093628397E-4, -2.29549961613378126380E-4, -2.68132617805781232825E-3, + 3.47222221605458667310E-3, 8.33333333333482257126E-2, + }; + + constexpr double MAXSTIR = 143.01608; + constexpr double SQTPI = 2.50662827463100050242E0; + + /* Gamma function computed by Stirling's formula. + * The polynomial STIR is valid for 33 <= x <= 172. + */ + SPECFUN_HOST_DEVICE inline double stirf(double x) { + double y, w, v; + + if (x >= MAXGAM) { + return (std::numeric_limits::infinity()); + } + w = 1.0 / x; + w = 1.0 + w * special::cephes::polevl(w, gamma_STIR, 4); + y = std::exp(x); + if (x > MAXSTIR) { /* Avoid overflow in pow() */ + v = std::pow(x, 0.5 * x - 0.25); + y = v * (v / y); + } else { + y = std::pow(x, x - 0.5) / y; + } + y = SQTPI * y * w; + return (y); + } + } // namespace detail + + SPECFUN_HOST_DEVICE inline double Gamma(double x) { + double p, q, z; + int i; + int sgngam = 1; + + if (!std::isfinite(x)) { + return x; + } + q = std::abs(x); + + if (q > 33.0) { + if (x < 0.0) { + p = floor(q); + if (p == q) { + gamnan: + set_error("Gamma", SF_ERROR_OVERFLOW, NULL); + return (std::numeric_limits::infinity()); + } + i = p; + if ((i & 1) == 0) { + sgngam = -1; + } + z = q - p; + if (z > 0.5) { + p += 1.0; + z = q - p; + } + z = q * std::sin(M_PI * z); + if (z == 0.0) { + return (sgngam * std::numeric_limits::infinity()); + } + z = std::abs(z); + z = M_PI / (z * detail::stirf(q)); + } else { + z = detail::stirf(x); + } + return (sgngam * z); + } + + z = 1.0; + while (x >= 3.0) { + x -= 1.0; + z *= x; + } + + while (x < 0.0) { + if (x > -1.E-9) { + goto small; + } + z /= x; + x += 1.0; + } + + while (x < 2.0) { + if (x < 1.e-9) { + goto small; + } + z /= x; + x += 1.0; + } + + if (x == 2.0) { + return (z); + } + + x -= 2.0; + p = polevl(x, detail::gamma_P, 6); + q = polevl(x, detail::gamma_Q, 7); + return (z * p / q); + + small: + if (x == 0.0) { + goto gamnan; + } else + return (z / ((1.0 + 0.5772156649015329 * x) * x)); + } + + namespace detail { + /* A[]: Stirling's formula expansion of log Gamma + * B[], C[]: log Gamma function between 2 and 3 + */ + constexpr double gamma_A[] = {8.11614167470508450300E-4, -5.95061904284301438324E-4, 7.93650340457716943945E-4, + -2.77777777730099687205E-3, 8.33333333333331927722E-2}; + + constexpr double gamma_B[] = {-1.37825152569120859100E3, -3.88016315134637840924E4, -3.31612992738871184744E5, + -1.16237097492762307383E6, -1.72173700820839662146E6, -8.53555664245765465627E5}; + + constexpr double gamma_C[] = { + /* 1.00000000000000000000E0, */ + -3.51815701436523470549E2, -1.70642106651881159223E4, -2.20528590553854454839E5, + -1.13933444367982507207E6, -2.53252307177582951285E6, -2.01889141433532773231E6}; + + /* log( sqrt( 2*pi ) ) */ + constexpr double LS2PI = 0.91893853320467274178; + + constexpr double MAXLGM = 2.556348e305; + + SPECFUN_HOST_DEVICE double lgam_sgn(double x, int *sign) { + double p, q, u, w, z; + int i; + + *sign = 1; + + if (!std::isfinite(x)) { + return x; + } + + if (x < -34.0) { + q = -x; + w = lgam_sgn(q, sign); + p = floor(q); + if (p == q) { + lgsing: + set_error("lgam", SF_ERROR_SINGULAR, NULL); + return (std::numeric_limits::infinity()); + } + i = p; + if ((i & 1) == 0) { + *sign = -1; + } else { + *sign = 1; + } + z = q - p; + if (z > 0.5) { + p += 1.0; + z = p - q; + } + z = q * std::sin(M_PI * z); + if (z == 0.0) { + goto lgsing; + } + /* z = log(M_PI) - log( z ) - w; */ + z = LOGPI - std::log(z) - w; + return (z); + } + + if (x < 13.0) { + z = 1.0; + p = 0.0; + u = x; + while (u >= 3.0) { + p -= 1.0; + u = x + p; + z *= u; + } + while (u < 2.0) { + if (u == 0.0) { + goto lgsing; + } + z /= u; + p += 1.0; + u = x + p; + } + if (z < 0.0) { + *sign = -1; + z = -z; + } else { + *sign = 1; + } + if (u == 2.0) { + return (std::log(z)); + } + p -= 2.0; + x = x + p; + p = x * polevl(x, gamma_B, 5) / p1evl(x, gamma_C, 6); + return (std::log(z) + p); + } + + if (x > MAXLGM) { + return (*sign * std::numeric_limits::infinity()); + } + + q = (x - 0.5) * std::log(x) - x + LS2PI; + if (x > 1.0e8) { + return (q); + } + + p = 1.0 / (x * x); + if (x >= 1000.0) { + q += ((7.9365079365079365079365e-4 * p - 2.7777777777777777777778e-3) * p + 0.0833333333333333333333) / + x; + } else { + q += polevl(p, gamma_A, 4) / x; + } + return (q); + } + } // namespace detail + + /* Logarithm of Gamma function */ + SPECFUN_HOST_DEVICE double lgam(double x) { + int sign; + return detail::lgam_sgn(x, &sign); + } + +} // namespace cephes +} // namespace special diff --git a/venv/lib/python3.10/site-packages/scipy/special/special/cephes/psi.h b/venv/lib/python3.10/site-packages/scipy/special/special/cephes/psi.h new file mode 100644 index 0000000000000000000000000000000000000000..10fefeb107e1c23d4b2180af8c251dc12ce62da6 --- /dev/null +++ b/venv/lib/python3.10/site-packages/scipy/special/special/cephes/psi.h @@ -0,0 +1,194 @@ +/* Translated into C++ by SciPy developers in 2024. + * Original header with Copyright information appears below. + */ + +/* psi.c + * + * Psi (digamma) function + * + * + * SYNOPSIS: + * + * double x, y, psi(); + * + * y = psi( x ); + * + * + * DESCRIPTION: + * + * d - + * psi(x) = -- ln | (x) + * dx + * + * is the logarithmic derivative of the gamma function. + * For integer x, + * n-1 + * - + * psi(n) = -EUL + > 1/k. + * - + * k=1 + * + * This formula is used for 0 < n <= 10. If x is negative, it + * is transformed to a positive argument by the reflection + * formula psi(1-x) = psi(x) + pi cot(pi x). + * For general positive x, the argument is made greater than 10 + * using the recurrence psi(x+1) = psi(x) + 1/x. + * Then the following asymptotic expansion is applied: + * + * inf. B + * - 2k + * psi(x) = log(x) - 1/2x - > ------- + * - 2k + * k=1 2k x + * + * where the B2k are Bernoulli numbers. + * + * ACCURACY: + * Relative error (except absolute when |psi| < 1): + * arithmetic domain # trials peak rms + * IEEE 0,30 30000 1.3e-15 1.4e-16 + * IEEE -30,0 40000 1.5e-15 2.2e-16 + * + * ERROR MESSAGES: + * message condition value returned + * psi singularity x integer <=0 INFINITY + */ + +/* + * Cephes Math Library Release 2.8: June, 2000 + * Copyright 1984, 1987, 1992, 2000 by Stephen L. Moshier + */ + +/* + * Code for the rational approximation on [1, 2] is: + * + * (C) Copyright John Maddock 2006. + * Use, modification and distribution are subject to the + * Boost Software License, Version 1.0. (See accompanying file + * LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) + */ +#pragma once + +#include "../config.h" +#include "../error.h" +#include "const.h" +#include "polevl.h" + +namespace special { +namespace cephes { + namespace detail { + constexpr double psi_A[] = {8.33333333333333333333E-2, -2.10927960927960927961E-2, 7.57575757575757575758E-3, + -4.16666666666666666667E-3, 3.96825396825396825397E-3, -8.33333333333333333333E-3, + 8.33333333333333333333E-2}; + + constexpr float psi_Y = 0.99558162689208984f; + + constexpr double psi_root1 = 1569415565.0 / 1073741824.0; + constexpr double psi_root2 = (381566830.0 / 1073741824.0) / 1073741824.0; + constexpr double psi_root3 = 0.9016312093258695918615325266959189453125e-19; + + constexpr double psi_P[] = {-0.0020713321167745952, -0.045251321448739056, -0.28919126444774784, + -0.65031853770896507, -0.32555031186804491, 0.25479851061131551}; + constexpr double psi_Q[] = {-0.55789841321675513e-6, + 0.0021284987017821144, + 0.054151797245674225, + 0.43593529692665969, + 1.4606242909763515, + 2.0767117023730469, + 1.0}; + + SPECFUN_HOST_DEVICE double digamma_imp_1_2(double x) { + /* + * Rational approximation on [1, 2] taken from Boost. + * + * Now for the approximation, we use the form: + * + * digamma(x) = (x - root) * (Y + R(x-1)) + * + * Where root is the location of the positive root of digamma, + * Y is a constant, and R is optimised for low absolute error + * compared to Y. + * + * Maximum Deviation Found: 1.466e-18 + * At double precision, max error found: 2.452e-17 + */ + double r, g; + + g = x - psi_root1; + g -= psi_root2; + g -= psi_root3; + r = special::cephes::polevl(x - 1.0, psi_P, 5) / special::cephes::polevl(x - 1.0, psi_Q, 6); + + return g * psi_Y + g * r; + } + + SPECFUN_HOST_DEVICE double psi_asy(double x) { + double y, z; + + if (x < 1.0e17) { + z = 1.0 / (x * x); + y = z * special::cephes::polevl(z, psi_A, 6); + } else { + y = 0.0; + } + + return std::log(x) - (0.5 / x) - y; + } + } // namespace detail + + SPECFUN_HOST_DEVICE double psi(double x) { + double y = 0.0; + double q, r; + int i, n; + + if (std::isnan(x)) { + return x; + } else if (x == std::numeric_limits::infinity()) { + return x; + } else if (x == -std::numeric_limits::infinity()) { + return std::numeric_limits::quiet_NaN(); + } else if (x == 0) { + set_error("psi", SF_ERROR_SINGULAR, NULL); + return std::copysign(std::numeric_limits::infinity(), -x); + } else if (x < 0.0) { + /* argument reduction before evaluating tan(pi * x) */ + r = std::modf(x, &q); + if (r == 0.0) { + set_error("psi", SF_ERROR_SINGULAR, NULL); + return std::numeric_limits::quiet_NaN(); + } + y = -M_PI / std::tan(M_PI * r); + x = 1.0 - x; + } + + /* check for positive integer up to 10 */ + if ((x <= 10.0) && (x == std::floor(x))) { + n = static_cast(x); + for (i = 1; i < n; i++) { + y += 1.0 / i; + } + y -= detail::SCIPY_EULER; + return y; + } + + /* use the recurrence relation to move x into [1, 2] */ + if (x < 1.0) { + y -= 1.0 / x; + x += 1.0; + } else if (x < 10.0) { + while (x > 2.0) { + x -= 1.0; + y += 1.0 / x; + } + } + if ((1.0 <= x) && (x <= 2.0)) { + y += detail::digamma_imp_1_2(x); + return y; + } + + /* x is large, use the asymptotic series */ + y += detail::psi_asy(x); + return y; + } +} // namespace cephes +} // namespace special diff --git a/venv/lib/python3.10/site-packages/scipy/special/special/cephes/zeta.h b/venv/lib/python3.10/site-packages/scipy/special/special/cephes/zeta.h new file mode 100644 index 0000000000000000000000000000000000000000..6246865d469fcc86122dd28e056e8eea6c14d2cd --- /dev/null +++ b/venv/lib/python3.10/site-packages/scipy/special/special/cephes/zeta.h @@ -0,0 +1,172 @@ +/* Translated into C++ by SciPy developers in 2024. + * Original header with Copyright information appears below. + */ + +/* zeta.c + * + * Riemann zeta function of two arguments + * + * + * + * SYNOPSIS: + * + * double x, q, y, zeta(); + * + * y = zeta( x, q ); + * + * + * + * DESCRIPTION: + * + * + * + * inf. + * - -x + * zeta(x,q) = > (k+q) + * - + * k=0 + * + * where x > 1 and q is not a negative integer or zero. + * The Euler-Maclaurin summation formula is used to obtain + * the expansion + * + * n + * - -x + * zeta(x,q) = > (k+q) + * - + * k=1 + * + * 1-x inf. B x(x+1)...(x+2j) + * (n+q) 1 - 2j + * + --------- - ------- + > -------------------- + * x-1 x - x+2j+1 + * 2(n+q) j=1 (2j)! (n+q) + * + * where the B2j are Bernoulli numbers. Note that (see zetac.c) + * zeta(x,1) = zetac(x) + 1. + * + * + * + * ACCURACY: + * + * + * + * REFERENCE: + * + * Gradshteyn, I. S., and I. M. Ryzhik, Tables of Integrals, + * Series, and Products, p. 1073; Academic Press, 1980. + * + */ + +/* + * Cephes Math Library Release 2.0: April, 1987 + * Copyright 1984, 1987 by Stephen L. Moshier + * Direct inquiries to 30 Frost Street, Cambridge, MA 02140 + */ +#pragma once + +#include "../config.h" +#include "../error.h" +#include "const.h" + +namespace special { +namespace cephes { + + namespace detail { + /* Expansion coefficients + * for Euler-Maclaurin summation formula + * (2k)! / B2k + * where B2k are Bernoulli numbers + */ + constexpr double zeta_A[] = { + 12.0, + -720.0, + 30240.0, + -1209600.0, + 47900160.0, + -1.8924375803183791606e9, /*1.307674368e12/691 */ + 7.47242496e10, + -2.950130727918164224e12, /*1.067062284288e16/3617 */ + 1.1646782814350067249e14, /*5.109094217170944e18/43867 */ + -4.5979787224074726105e15, /*8.028576626982912e20/174611 */ + 1.8152105401943546773e17, /*1.5511210043330985984e23/854513 */ + -7.1661652561756670113e18 /*1.6938241367317436694528e27/236364091 */ + }; + + /* 30 Nov 86 -- error in third coefficient fixed */ + } // namespace detail + + SPECFUN_HOST_DEVICE double zeta(double x, double q) { + int i; + double a, b, k, s, t, w; + + if (x == 1.0) + goto retinf; + + if (x < 1.0) { + domerr: + set_error("zeta", SF_ERROR_DOMAIN, NULL); + return (std::numeric_limits::quiet_NaN()); + } + + if (q <= 0.0) { + if (q == floor(q)) { + set_error("zeta", SF_ERROR_SINGULAR, NULL); + retinf: + return (std::numeric_limits::infinity()); + } + if (x != std::floor(x)) + goto domerr; /* because q^-x not defined */ + } + + /* Asymptotic expansion + * https://dlmf.nist.gov/25.11#E43 + */ + if (q > 1e8) { + return (1 / (x - 1) + 1 / (2 * q)) * std::pow(q, 1 - x); + } + + /* Euler-Maclaurin summation formula */ + + /* Permit negative q but continue sum until n+q > +9 . + * This case should be handled by a reflection formula. + * If q<0 and x is an integer, there is a relation to + * the polyGamma function. + */ + s = std::pow(q, -x); + a = q; + i = 0; + b = 0.0; + while ((i < 9) || (a <= 9.0)) { + i += 1; + a += 1.0; + b = std::pow(a, -x); + s += b; + if (std::abs(b / s) < detail::MACHEP) + goto done; + } + + w = a; + s += b * w / (x - 1.0); + s -= 0.5 * b; + a = 1.0; + k = 0.0; + for (i = 0; i < 12; i++) { + a *= x + k; + b /= w; + t = a * b / detail::zeta_A[i]; + s = s + t; + t = std::abs(t / s); + if (t < detail::MACHEP) + goto done; + k += 1.0; + a *= x + k; + b /= w; + k += 1.0; + } + done: + return (s); + } + +} // namespace cephes +} // namespace special diff --git a/venv/lib/python3.10/site-packages/scipy/special/special/config.h b/venv/lib/python3.10/site-packages/scipy/special/special/config.h new file mode 100644 index 0000000000000000000000000000000000000000..aa899f0b4c0c2ae8166071f829970f7753b3348a --- /dev/null +++ b/venv/lib/python3.10/site-packages/scipy/special/special/config.h @@ -0,0 +1,158 @@ +#pragma once + +// Define math constants if they are not available +#ifndef M_E +#define M_E 2.71828182845904523536 +#endif + +#ifndef M_LOG2E +#define M_LOG2E 1.44269504088896340736 +#endif + +#ifndef M_LOG10E +#define M_LOG10E 0.434294481903251827651 +#endif + +#ifndef M_LN2 +#define M_LN2 0.693147180559945309417 +#endif + +#ifndef M_LN10 +#define M_LN10 2.30258509299404568402 +#endif + +#ifndef M_PI +#define M_PI 3.14159265358979323846 +#endif + +#ifndef M_PI_2 +#define M_PI_2 1.57079632679489661923 +#endif + +#ifndef M_PI_4 +#define M_PI_4 0.785398163397448309616 +#endif + +#ifndef M_1_PI +#define M_1_PI 0.318309886183790671538 +#endif + +#ifndef M_2_PI +#define M_2_PI 0.636619772367581343076 +#endif + +#ifndef M_2_SQRTPI +#define M_2_SQRTPI 1.12837916709551257390 +#endif + +#ifndef M_SQRT2 +#define M_SQRT2 1.41421356237309504880 +#endif + +#ifndef M_SQRT1_2 +#define M_SQRT1_2 0.707106781186547524401 +#endif + +#ifdef __CUDACC__ +#define SPECFUN_HOST_DEVICE __host__ __device__ + +#include +#include + +// Fallback to global namespace for functions unsupported on NVRTC Jit +#ifdef _LIBCUDACXX_COMPILER_NVRTC +#include +#endif + +namespace std { + +SPECFUN_HOST_DEVICE inline double abs(double num) { return cuda::std::abs(num); } + +SPECFUN_HOST_DEVICE inline double exp(double num) { return cuda::std::exp(num); } + +SPECFUN_HOST_DEVICE inline double log(double num) { return cuda::std::log(num); } + +SPECFUN_HOST_DEVICE inline double sqrt(double num) { return cuda::std::sqrt(num); } + +SPECFUN_HOST_DEVICE inline bool isnan(double num) { return cuda::std::isnan(num); } + +SPECFUN_HOST_DEVICE inline bool isfinite(double num) { return cuda::std::isfinite(num); } + +SPECFUN_HOST_DEVICE inline double pow(double x, double y) { return cuda::std::pow(x, y); } + +SPECFUN_HOST_DEVICE inline double sin(double x) { return cuda::std::sin(x); } + +SPECFUN_HOST_DEVICE inline double tan(double x) { return cuda::std::tan(x); } + +SPECFUN_HOST_DEVICE inline double sinh(double x) { return cuda::std::sinh(x); } + +SPECFUN_HOST_DEVICE inline double cosh(double x) { return cuda::std::cosh(x); } + +SPECFUN_HOST_DEVICE inline bool signbit(double x) { return cuda::std::signbit(x); } + +// Fallback to global namespace for functions unsupported on NVRTC +#ifndef _LIBCUDACXX_COMPILER_NVRTC +SPECFUN_HOST_DEVICE inline double ceil(double x) { return cuda::std::ceil(x); } +SPECFUN_HOST_DEVICE inline double floor(double x) { return cuda::std::floor(x); } +SPECFUN_HOST_DEVICE inline double trunc(double x) { return cuda::std::trunc(x); } +SPECFUN_HOST_DEVICE inline double fma(double x, double y, double z) { return cuda::std::fma(x, y, z); } +SPECFUN_HOST_DEVICE inline double copysign(double x, double y) { return cuda::std::copysign(x, y); } +SPECFUN_HOST_DEVICE inline double modf(double value, double *iptr) { return cuda::std::modf(value, iptr); } + +#else +SPECFUN_HOST_DEVICE inline double ceil(double x) { return ::ceil(x); } +SPECFUN_HOST_DEVICE inline double floor(double x) { return ::floor(x); } +SPECFUN_HOST_DEVICE inline double trunc(double x) { return ::trunc(x); } +SPECFUN_HOST_DEVICE inline double fma(double x, double y, double z) { return ::fma(x, y, z); } +SPECFUN_HOST_DEVICE inline double copysign(double x, double y) { return ::copysign(x, y); } +SPECFUN_HOST_DEVICE inline double modf(double value, double *iptr) { return ::modf(value, iptr); } +#endif + +template +using numeric_limits = cuda::std::numeric_limits; + +// Must use thrust for complex types in order to support CuPy +template +using complex = thrust::complex; + +template +SPECFUN_HOST_DEVICE T abs(const complex &z) { + return thrust::abs(z); +} + +template +SPECFUN_HOST_DEVICE complex exp(const complex &z) { + return thrust::exp(z); +} + +template +SPECFUN_HOST_DEVICE complex log(const complex &z) { + return thrust::log(z); +} + +template +SPECFUN_HOST_DEVICE T norm(const complex &z) { + return thrust::norm(z); +} + +template +SPECFUN_HOST_DEVICE complex sqrt(const complex &z) { + return thrust::sqrt(z); +} + +template +SPECFUN_HOST_DEVICE complex conj(const complex &z) { + return thrust::conj(z); +} + +} // namespace std + +#else +#define SPECFUN_HOST_DEVICE + +#include +#include +#include +#include + +#endif diff --git a/venv/lib/python3.10/site-packages/scipy/special/special/digamma.h b/venv/lib/python3.10/site-packages/scipy/special/special/digamma.h new file mode 100644 index 0000000000000000000000000000000000000000..e7cd669c12cef0e0024c18a81ad3c44d1f2121d3 --- /dev/null +++ b/venv/lib/python3.10/site-packages/scipy/special/special/digamma.h @@ -0,0 +1,198 @@ +/* Translated from Cython into C++ by SciPy developers in 2024. + * Original header comment appears below. + */ + +/* An implementation of the digamma function for complex arguments. + * + * Author: Josh Wilson + * + * Distributed under the same license as Scipy. + * + * Sources: + * [1] "The Digital Library of Mathematical Functions", dlmf.nist.gov + * + * [2] mpmath (version 0.19), http://mpmath.org + */ + +#pragma once + +#include "cephes/psi.h" +#include "cephes/zeta.h" +#include "config.h" +#include "error.h" +#include "trig.h" + +namespace special { +namespace detail { + // All of the following were computed with mpmath + // Location of the positive root + constexpr double digamma_posroot = 1.4616321449683623; + // Value of the positive root + constexpr double digamma_posrootval = -9.2412655217294275e-17; + // Location of the negative root + constexpr double digamma_negroot = -0.504083008264455409; + // Value of the negative root + constexpr double digamma_negrootval = 7.2897639029768949e-17; + + template + SPECFUN_HOST_DEVICE T digamma_zeta_series(T z, double root, double rootval) { + T res = rootval; + T coeff = -1.0; + + z = z - root; + T term; + for (int n = 1; n < 100; n++) { + coeff *= -z; + term = coeff * cephes::zeta(n + 1, root); + res += term; + if (std::abs(term) < std::numeric_limits::epsilon() * std::abs(res)) { + break; + } + } + return res; + } + + SPECFUN_HOST_DEVICE inline std::complex digamma_forward_recurrence(std::complex z, + std::complex psiz, int n) { + /* Compute digamma(z + n) using digamma(z) using the recurrence + * relation + * + * digamma(z + 1) = digamma(z) + 1/z. + * + * See https://dlmf.nist.gov/5.5#E2 */ + std::complex res = psiz; + + for (int k = 0; k < n; k++) { + res += 1.0 / (z + static_cast(k)); + } + return res; + } + + SPECFUN_HOST_DEVICE inline std::complex digamma_backward_recurrence(std::complex z, + std::complex psiz, int n) { + /* Compute digamma(z - n) using digamma(z) and a recurrence relation. */ + std::complex res = psiz; + + for (int k = 1; k < n + 1; k++) { + res -= 1.0 / (z - static_cast(k)); + } + return res; + } + + SPECFUN_HOST_DEVICE inline std::complex digamma_asymptotic_series(std::complex z) { + /* Evaluate digamma using an asymptotic series. See + * + * https://dlmf.nist.gov/5.11#E2 */ + double bernoulli2k[] = { + 0.166666666666666667, -0.0333333333333333333, 0.0238095238095238095, -0.0333333333333333333, + 0.0757575757575757576, -0.253113553113553114, 1.16666666666666667, -7.09215686274509804, + 54.9711779448621554, -529.124242424242424, 6192.12318840579710, -86580.2531135531136, + 1425517.16666666667, -27298231.0678160920, 601580873.900642368, -15116315767.0921569}; + std::complex rzz = 1.0 / z / z; + std::complex zfac = 1.0; + std::complex term; + std::complex res; + + if (!(std::isfinite(z.real()) && std::isfinite(z.imag()))) { + /* Check for infinity (or nan) and return early. + * Result of division by complex infinity is implementation dependent. + * and has been observed to vary between C++ stdlib and CUDA stdlib. + */ + return std::log(z); + } + + res = std::log(z) - 0.5 / z; + + for (int k = 1; k < 17; k++) { + zfac *= rzz; + term = -bernoulli2k[k - 1] * zfac / (2 * static_cast(k)); + res += term; + if (std::abs(term) < std::numeric_limits::epsilon() * std::abs(res)) { + break; + } + } + return res; + } + +} // namespace detail + +SPECFUN_HOST_DEVICE inline double digamma(double z) { + /* Wrap Cephes' psi to take advantage of the series expansion around + * the smallest negative zero. + */ + if (std::abs(z - detail::digamma_negroot) < 0.3) { + return detail::digamma_zeta_series(z, detail::digamma_negroot, detail::digamma_negrootval); + } + return cephes::psi(z); +} + +SPECFUN_HOST_DEVICE inline std::complex digamma(std::complex z) { + /* + * Compute the digamma function for complex arguments. The strategy + * is: + * + * - Around the two zeros closest to the origin (posroot and negroot) + * use a Taylor series with precomputed zero order coefficient. + * - If close to the origin, use a recurrence relation to step away + * from the origin. + * - If close to the negative real axis, use the reflection formula + * to move to the right halfplane. + * - If |z| is large (> 16), use the asymptotic series. + * - If |z| is small, use a recurrence relation to make |z| large + * enough to use the asymptotic series. + */ + double absz = std::abs(z); + std::complex res = 0; + /* Use the asymptotic series for z away from the negative real axis + * with abs(z) > smallabsz. */ + int smallabsz = 16; + /* Use the reflection principle for z with z.real < 0 that are within + * smallimag of the negative real axis. + * int smallimag = 6 # unused below except in a comment */ + + if (z.real() <= 0.0 && std::ceil(z.real()) == z) { + // Poles + set_error("digamma", SF_ERROR_SINGULAR, NULL); + return {std::numeric_limits::quiet_NaN(), std::numeric_limits::quiet_NaN()}; + } + if (std::abs(z - detail::digamma_negroot) < 0.3) { + // First negative root. + return detail::digamma_zeta_series(z, detail::digamma_negroot, detail::digamma_negrootval); + } + + if (z.real() < 0 and std::abs(z.imag()) < smallabsz) { + /* Reflection formula for digamma. See + * + *https://dlmf.nist.gov/5.5#E4 + */ + res = -M_PI * cospi(z) / sinpi(z); + z = 1.0 - z; + absz = std::abs(z); + } + + if (absz < 0.5) { + /* Use one step of the recurrence relation to step away from + * the pole. */ + res = -1.0 / z; + z += 1.0; + absz = std::abs(z); + } + + if (std::abs(z - detail::digamma_posroot) < 0.5) { + res += detail::digamma_zeta_series(z, detail::digamma_posroot, detail::digamma_posrootval); + } else if (absz > smallabsz) { + res += detail::digamma_asymptotic_series(z); + } else if (z.real() >= 0.0) { + double n = std::trunc(smallabsz - absz) + 1; + std::complex init = detail::digamma_asymptotic_series(z + n); + res += detail::digamma_backward_recurrence(z + n, init, n); + } else { + // z.real() < 0, absz < smallabsz, and z.imag() > smallimag + double n = std::trunc(smallabsz - absz) - 1; + std::complex init = detail::digamma_asymptotic_series(z - n); + res += detail::digamma_forward_recurrence(z - n, init, n); + } + return res; +} + +} // namespace special diff --git a/venv/lib/python3.10/site-packages/scipy/special/special/error.h b/venv/lib/python3.10/site-packages/scipy/special/special/error.h new file mode 100644 index 0000000000000000000000000000000000000000..11b80605881402395ce91a045efb495dac696804 --- /dev/null +++ b/venv/lib/python3.10/site-packages/scipy/special/special/error.h @@ -0,0 +1,42 @@ +#pragma once + +// should be included from config.h, but that won't work until we've cleanly separated out the C and C++ parts of the +// code +#ifdef __CUDACC__ +#define SPECFUN_HOST_DEVICE __host__ __device__ +#else +#define SPECFUN_HOST_DEVICE +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum { + SF_ERROR_OK = 0, /* no error */ + SF_ERROR_SINGULAR, /* singularity encountered */ + SF_ERROR_UNDERFLOW, /* floating point underflow */ + SF_ERROR_OVERFLOW, /* floating point overflow */ + SF_ERROR_SLOW, /* too many iterations required */ + SF_ERROR_LOSS, /* loss of precision */ + SF_ERROR_NO_RESULT, /* no result obtained */ + SF_ERROR_DOMAIN, /* out of domain */ + SF_ERROR_ARG, /* invalid input parameter */ + SF_ERROR_OTHER, /* unclassified error */ + SF_ERROR__LAST +} sf_error_t; + +#ifdef __cplusplus +namespace special { + +#ifndef SP_SPECFUN_ERROR + SPECFUN_HOST_DEVICE inline void set_error(const char *func_name, sf_error_t code, const char *fmt, ...) { + // nothing + } +#else + void set_error(const char *func_name, sf_error_t code, const char *fmt, ...); +#endif +} // namespace special + +} // closes extern "C" +#endif diff --git a/venv/lib/python3.10/site-packages/scipy/special/special/evalpoly.h b/venv/lib/python3.10/site-packages/scipy/special/special/evalpoly.h new file mode 100644 index 0000000000000000000000000000000000000000..0fcd162b58878e604185b0d2311816c963e63a0c --- /dev/null +++ b/venv/lib/python3.10/site-packages/scipy/special/special/evalpoly.h @@ -0,0 +1,47 @@ +/* Translated from Cython into C++ by SciPy developers in 2024. + * + * Original author: Josh Wilson, 2016. + */ + +/* Evaluate polynomials. + * + * All of the coefficients are stored in reverse order, i.e. if the + * polynomial is + * + * u_n x^n + u_{n - 1} x^{n - 1} + ... + u_0, + * + * then coeffs[0] = u_n, coeffs[1] = u_{n - 1}, ..., coeffs[n] = u_0. + * + * References + * ---------- + * [1] Knuth, "The Art of Computer Programming, Volume II" + */ + +#pragma once + +#include "config.h" + +namespace special { + +SPECFUN_HOST_DEVICE inline std::complex cevalpoly(const double *coeffs, int degree, std::complex z) { + /* Evaluate a polynomial with real coefficients at a complex point. + * + * Uses equation (3) in section 4.6.4 of [1]. Note that it is more + * efficient than Horner's method. + */ + double a = coeffs[0]; + double b = coeffs[1]; + double r = 2 * z.real(); + double s = std::norm(z); + double tmp; + + for (int j = 2; j < degree + 1; j++) { + tmp = b; + b = std::fma(-s, a, coeffs[j]); + a = std::fma(r, a, tmp); + } + + return z * a + b; +} + +} // namespace special diff --git a/venv/lib/python3.10/site-packages/scipy/special/special/lambertw.h b/venv/lib/python3.10/site-packages/scipy/special/special/lambertw.h new file mode 100644 index 0000000000000000000000000000000000000000..10d2c7a273f4756cb8b412cafa545c23927f9354 --- /dev/null +++ b/venv/lib/python3.10/site-packages/scipy/special/special/lambertw.h @@ -0,0 +1,145 @@ +/* Translated from Cython into C++ by SciPy developers in 2023. + * Original header with Copyright information appears below. + */ + +/* Implementation of the Lambert W function [1]. Based on MPMath + * Implementation [2], and documentation [3]. + * + * Copyright: Yosef Meller, 2009 + * Author email: mellerf@netvision.net.il + * + * Distributed under the same license as SciPy + * + * + * References: + * [1] On the Lambert W function, Adv. Comp. Math. 5 (1996) 329-359, + * available online: https://web.archive.org/web/20230123211413/https://cs.uwaterloo.ca/research/tr/1993/03/W.pdf + * [2] mpmath source code, + https://github.com/mpmath/mpmath/blob/c5939823669e1bcce151d89261b802fe0d8978b4/mpmath/functions/functions.py#L435-L461 + * [3] + https://web.archive.org/web/20230504171447/https://mpmath.org/doc/current/functions/powers.html#lambert-w-function + * + + * TODO: use a series expansion when extremely close to the branch point + * at `-1/e` and make sure that the proper branch is chosen there. + */ + +#pragma once + +#include "config.h" +#include "error.h" +#include "evalpoly.h" + +namespace special { +constexpr double EXPN1 = 0.36787944117144232159553; // exp(-1) +constexpr double OMEGA = 0.56714329040978387299997; // W(1, 0) + +namespace detail { + SPECFUN_HOST_DEVICE inline std::complex lambertw_branchpt(std::complex z) { + // Series for W(z, 0) around the branch point; see 4.22 in [1]. + double coeffs[] = {-1.0 / 3.0, 1.0, -1.0}; + std::complex p = std::sqrt(2.0 * (M_E * z + 1.0)); + + return cevalpoly(coeffs, 2, p); + } + + SPECFUN_HOST_DEVICE inline std::complex lambertw_pade0(std::complex z) { + // (3, 2) Pade approximation for W(z, 0) around 0. + double num[] = {12.85106382978723404255, 12.34042553191489361902, 1.0}; + double denom[] = {32.53191489361702127660, 14.34042553191489361702, 1.0}; + + /* This only gets evaluated close to 0, so we don't need a more + * careful algorithm that avoids overflow in the numerator for + * large z. */ + return z * cevalpoly(num, 2, z) / cevalpoly(denom, 2, z); + } + + SPECFUN_HOST_DEVICE inline std::complex lambertw_asy(std::complex z, long k) { + /* Compute the W function using the first two terms of the + * asymptotic series. See 4.20 in [1]. + */ + std::complex w = std::log(z) + 2.0 * M_PI * k * std::complex(0, 1); + return w - std::log(w); + } + +} // namespace detail + +SPECFUN_HOST_DEVICE inline std::complex lambertw(std::complex z, long k, double tol) { + double absz; + std::complex w; + std::complex ew, wew, wewz, wn; + + if (std::isnan(z.real()) || std::isnan(z.imag())) { + return z; + } + if (z.real() == std::numeric_limits::infinity()) { + return z + 2.0 * M_PI * k * std::complex(0, 1); + } + if (z.real() == -std::numeric_limits::infinity()) { + return -z + (2.0 * M_PI * k + M_PI) * std::complex(0, 1); + } + if (z == 0.0) { + if (k == 0) { + return z; + } + set_error("lambertw", SF_ERROR_SINGULAR, NULL); + return -std::numeric_limits::infinity(); + } + if (z == 1.0 && k == 0) { + // Split out this case because the asymptotic series blows up + return OMEGA; + } + + absz = std::abs(z); + // Get an initial guess for Halley's method + if (k == 0) { + if (std::abs(z + EXPN1) < 0.3) { + w = detail::lambertw_branchpt(z); + } else if (-1.0 < z.real() && z.real() < 1.5 && std::abs(z.imag()) < 1.0 && + -2.5 * std::abs(z.imag()) - 0.2 < z.real()) { + /* Empirically determined decision boundary where the Pade + * approximation is more accurate. */ + w = detail::lambertw_pade0(z); + } else { + w = detail::lambertw_asy(z, k); + } + } else if (k == -1) { + if (absz <= EXPN1 && z.imag() == 0.0 && z.real() < 0.0) { + w = std::log(-z.real()); + } else { + w = detail::lambertw_asy(z, k); + } + } else { + w = detail::lambertw_asy(z, k); + } + + // Halley's method; see 5.9 in [1] + if (w.real() >= 0) { + // Rearrange the formula to avoid overflow in exp + for (int i = 0; i < 100; i++) { + ew = std::exp(-w); + wewz = w - z * ew; + wn = w - wewz / (w + 1.0 - (w + 2.0) * wewz / (2.0 * w + 2.0)); + if (std::abs(wn - w) <= tol * std::abs(wn)) { + return wn; + } + w = wn; + } + } else { + for (int i = 0; i < 100; i++) { + ew = std::exp(w); + wew = w * ew; + wewz = wew - z; + wn = w - wewz / (wew + ew - (w + 2.0) * wewz / (2.0 * w + 2.0)); + if (std::abs(wn - w) <= tol * std::abs(wn)) { + return wn; + } + w = wn; + } + } + + set_error("lambertw", SF_ERROR_SLOW, "iteration failed to converge: %g + %gj", z.real(), z.imag()); + return {std::numeric_limits::quiet_NaN(), std::numeric_limits::quiet_NaN()}; +} + +} // namespace special diff --git a/venv/lib/python3.10/site-packages/scipy/special/special/loggamma.h b/venv/lib/python3.10/site-packages/scipy/special/special/loggamma.h new file mode 100644 index 0000000000000000000000000000000000000000..02b27873f57da735c1d6b3bbce592e7315412d3c --- /dev/null +++ b/venv/lib/python3.10/site-packages/scipy/special/special/loggamma.h @@ -0,0 +1,158 @@ +/* Translated from Cython into C++ by SciPy developers in 2024. + * Original header comment appears below. + */ + +/* An implementation of the principal branch of the logarithm of + * Gamma. Also contains implementations of Gamma and 1/Gamma which are + * easily computed from log-Gamma. + * + * Author: Josh Wilson + * + * Distributed under the same license as Scipy. + * + * References + * ---------- + * [1] Hare, "Computing the Principal Branch of log-Gamma", + * Journal of Algorithms, 1997. + * + * [2] Julia, + * https://github.com/JuliaLang/julia/blob/master/base/special/gamma.jl + */ + +#pragma once + +#include "cephes/gamma.h" +#include "config.h" +#include "error.h" +#include "evalpoly.h" +#include "trig.h" +#include "zlog1.h" + +namespace special { + +namespace detail { + constexpr double loggamma_SMALLX = 7; + constexpr double loggamma_SMALLY = 7; + constexpr double loggamma_HLOG2PI = 0.918938533204672742; // log(2*pi)/2 + constexpr double loggamma_LOGPI = 1.1447298858494001741434262; // log(pi) + constexpr double loggamma_TAYLOR_RADIUS = 0.2; + + SPECFUN_HOST_DEVICE std::complex loggamma_stirling(std::complex z) { + /* Stirling series for log-Gamma + * + * The coefficients are B[2*n]/(2*n*(2*n - 1)) where B[2*n] is the + * (2*n)th Bernoulli number. See (1.1) in [1]. + */ + double coeffs[] = {-2.955065359477124183E-2, 6.4102564102564102564E-3, -1.9175269175269175269E-3, + 8.4175084175084175084E-4, -5.952380952380952381E-4, 7.9365079365079365079E-4, + -2.7777777777777777778E-3, 8.3333333333333333333E-2}; + std::complex rz = 1.0 / z; + std::complex rzz = rz / z; + + return (z - 0.5) * std::log(z) - z + loggamma_HLOG2PI + rz * cevalpoly(coeffs, 7, rzz); + } + + SPECFUN_HOST_DEVICE std::complex loggamma_recurrence(std::complex z) { + /* Backward recurrence relation. + * + * See Proposition 2.2 in [1] and the Julia implementation [2]. + * + */ + int signflips = 0; + int sb = 0; + std::complex shiftprod = z; + + z += 1.0; + int nsb; + while (z.real() <= loggamma_SMALLX) { + shiftprod *= z; + nsb = std::signbit(shiftprod.imag()); + signflips += nsb != 0 && sb == 0 ? 1 : 0; + sb = nsb; + z += 1.0; + } + return loggamma_stirling(z) - std::log(shiftprod) - signflips * 2 * M_PI * std::complex(0, 1); + } + + SPECFUN_HOST_DEVICE std::complex loggamma_taylor(std::complex z) { + /* Taylor series for log-Gamma around z = 1. + * + * It is + * + * loggamma(z + 1) = -gamma*z + zeta(2)*z**2/2 - zeta(3)*z**3/3 ... + * + * where gamma is the Euler-Mascheroni constant. + */ + + double coeffs[] = { + -4.3478266053040259361E-2, 4.5454556293204669442E-2, -4.7619070330142227991E-2, 5.000004769810169364E-2, + -5.2631679379616660734E-2, 5.5555767627403611102E-2, -5.8823978658684582339E-2, 6.2500955141213040742E-2, + -6.6668705882420468033E-2, 7.1432946295361336059E-2, -7.6932516411352191473E-2, 8.3353840546109004025E-2, + -9.0954017145829042233E-2, 1.0009945751278180853E-1, -1.1133426586956469049E-1, 1.2550966952474304242E-1, + -1.4404989676884611812E-1, 1.6955717699740818995E-1, -2.0738555102867398527E-1, 2.7058080842778454788E-1, + -4.0068563438653142847E-1, 8.2246703342411321824E-1, -5.7721566490153286061E-1}; + + z -= 1.0; + return z * cevalpoly(coeffs, 22, z); + } +} // namespace detail + +SPECFUN_HOST_DEVICE inline double loggamma(double x) { + if (x < 0.0) { + return std::numeric_limits::quiet_NaN(); + } + return cephes::lgam(x); +} + +SPECFUN_HOST_DEVICE inline std::complex loggamma(std::complex z) { + // Compute the principal branch of log-Gamma + + if (std::isnan(z.real()) || std::isnan(z.imag())) { + return {std::numeric_limits::quiet_NaN(), std::numeric_limits::quiet_NaN()}; + } + if (z.real() <= 0 and z == std::floor(z.real())) { + set_error("loggamma", SF_ERROR_SINGULAR, NULL); + return {std::numeric_limits::quiet_NaN(), std::numeric_limits::quiet_NaN()}; + } + if (z.real() > detail::loggamma_SMALLX || std::abs(z.imag()) > detail::loggamma_SMALLY) { + return detail::loggamma_stirling(z); + } + if (std::abs(z - 1.0) < detail::loggamma_TAYLOR_RADIUS) { + return detail::loggamma_taylor(z); + } + if (std::abs(z - 2.0) < detail::loggamma_TAYLOR_RADIUS) { + // Recurrence relation and the Taylor series around 1. + return detail::zlog1(z - 1.0) + detail::loggamma_taylor(z - 1.0); + } + if (z.real() < 0.1) { + // Reflection formula; see Proposition 3.1 in [1] + double tmp = std::copysign(2 * M_PI, z.imag()) * std::floor(0.5 * z.real() + 0.25); + return std::complex(detail::loggamma_LOGPI, tmp) - std::log(sinpi(z)) - loggamma(1.0 - z); + } + if (std::signbit(z.imag()) == 0) { + // z.imag() >= 0 but is not -0.0 + return detail::loggamma_recurrence(z); + } + return std::conj(detail::loggamma_recurrence(std::conj(z))); +} + +SPECFUN_HOST_DEVICE inline std::complex gamma(std::complex z) { + // Compute Gamma(z) using loggamma. + if (z.real() <= 0 && z == std::floor(z.real())) { + // Poles + set_error("gamma", SF_ERROR_SINGULAR, NULL); + return {std::numeric_limits::quiet_NaN(), std::numeric_limits::quiet_NaN()}; + } + return std::exp(loggamma(z)); +} + +SPECFUN_HOST_DEVICE inline std::complex rgamma(std::complex z) { + // Compute 1/Gamma(z) using loggamma. + if (z.real() <= 0 && z == std::floor(z.real())) { + // Zeros at 0, -1, -2, ... + return 0.0; + } + return std::exp(-loggamma(z)); +} + +} // namespace special diff --git a/venv/lib/python3.10/site-packages/scipy/special/special/trig.h b/venv/lib/python3.10/site-packages/scipy/special/special/trig.h new file mode 100644 index 0000000000000000000000000000000000000000..ea8754428b04f6f4b627111385ace697d2eb63f4 --- /dev/null +++ b/venv/lib/python3.10/site-packages/scipy/special/special/trig.h @@ -0,0 +1,99 @@ +/* Translated from Cython into C++ by SciPy developers in 2023. + * + * Original author: Josh Wilson, 2016. + */ + +/* Implement sin(pi*z) and cos(pi*z) for complex z. Since the periods + * of these functions are integral (and thus better representable in + * floating point), it's possible to compute them with greater accuracy + * than sin(z), cos(z). + */ + +#pragma once + +#include "cephes/trig.h" +#include "config.h" +#include "evalpoly.h" + +namespace special { + +SPECFUN_HOST_DEVICE inline std::complex sinpi(std::complex z) { + double x = z.real(); + double piy = M_PI * z.imag(); + double abspiy = std::abs(piy); + double sinpix = cephes::sinpi(x); + double cospix = cephes::cospi(x); + + if (abspiy < 700) { + return {sinpix * std::cosh(piy), cospix * std::sinh(piy)}; + } + + /* Have to be careful--sinh/cosh could overflow while cos/sin are small. + * At this large of values + * + * cosh(y) ~ exp(y)/2 + * sinh(y) ~ sgn(y)*exp(y)/2 + * + * so we can compute exp(y/2), scale by the right factor of sin/cos + * and then multiply by exp(y/2) to avoid overflow. */ + double exphpiy = std::exp(abspiy / 2); + double coshfac; + double sinhfac; + if (exphpiy == std::numeric_limits::infinity()) { + if (sinpix == 0.0) { + // Preserve the sign of zero. + coshfac = std::copysign(0.0, sinpix); + } else { + coshfac = std::copysign(std::numeric_limits::infinity(), sinpix); + } + if (cospix == 0.0) { + // Preserve the sign of zero. + sinhfac = std::copysign(0.0, cospix); + } else { + sinhfac = std::copysign(std::numeric_limits::infinity(), cospix); + } + return {coshfac, sinhfac}; + } + + coshfac = 0.5 * sinpix * exphpiy; + sinhfac = 0.5 * cospix * exphpiy; + return {coshfac * exphpiy, sinhfac * exphpiy}; +} + +SPECFUN_HOST_DEVICE inline std::complex cospi(std::complex z) { + double x = z.real(); + double piy = M_PI * z.imag(); + double abspiy = std::abs(piy); + double sinpix = cephes::sinpi(x); + double cospix = cephes::cospi(x); + + if (abspiy < 700) { + return {cospix * std::cosh(piy), -sinpix * std::sinh(piy)}; + } + + // See csinpi(z) for an idea of what's going on here. + double exphpiy = std::exp(abspiy / 2); + double coshfac; + double sinhfac; + if (exphpiy == std::numeric_limits::infinity()) { + if (sinpix == 0.0) { + // Preserve the sign of zero. + coshfac = std::copysign(0.0, cospix); + } else { + coshfac = std::copysign(std::numeric_limits::infinity(), cospix); + } + if (cospix == 0.0) { + // Preserve the sign of zero. + sinhfac = std::copysign(0.0, sinpix); + } else { + sinhfac = std::copysign(std::numeric_limits::infinity(), sinpix); + } + return {coshfac, sinhfac}; + } + + coshfac = 0.5 * cospix * exphpiy; + sinhfac = 0.5 * sinpix * exphpiy; + return {coshfac * exphpiy, sinhfac * exphpiy}; +} + +} // namespace special diff --git a/venv/lib/python3.10/site-packages/scipy/special/special/zlog1.h b/venv/lib/python3.10/site-packages/scipy/special/special/zlog1.h new file mode 100644 index 0000000000000000000000000000000000000000..37a23f1387babe4dbbf6963cb348dec6a9b9c4f4 --- /dev/null +++ b/venv/lib/python3.10/site-packages/scipy/special/special/zlog1.h @@ -0,0 +1,35 @@ +/* Translated from Cython into C++ by SciPy developers in 2023. + * + * Original author: Josh Wilson, 2016. + */ + +#pragma once + +#include "config.h" + +namespace special { +namespace detail { + + SPECFUN_HOST_DEVICE inline std::complex zlog1(std::complex z) { + /* Compute log, paying special attention to accuracy around 1. We + * implement this ourselves because some systems (most notably the + * Travis CI machines) are weak in this regime. */ + std::complex coeff = -1.0; + std::complex res = 0.0; + + if (std::abs(z - 1.0) > 0.1) { + return std::log(z); + } + + z -= 1.0; + for (int n = 1; n < 17; n++) { + coeff *= -z; + res += coeff / static_cast(n); + if (std::abs(res / coeff) < std::numeric_limits::epsilon()) { + break; + } + } + return res; + } +} // namespace detail +} // namespace special diff --git a/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/__init__.cpython-310.pyc b/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..f583dda3c15e784f09d4274c06e8347395c57e4a Binary files /dev/null and b/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/__init__.cpython-310.pyc differ diff --git a/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_cdflib.cpython-310.pyc b/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_cdflib.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..9ad4e736f318451fe327dcdcd9e92c9a3ff6c6a0 Binary files /dev/null and b/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_cdflib.cpython-310.pyc differ diff --git a/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_cdft_asymptotic.cpython-310.pyc b/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_cdft_asymptotic.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..a053be2099267930ffd3635ce81f2964b624a5f9 Binary files /dev/null and b/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_cdft_asymptotic.cpython-310.pyc differ diff --git a/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_cython_special.cpython-310.pyc b/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_cython_special.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..d217e072680fc79bf4f0118ed82fe8024fa9f7bc Binary files /dev/null and b/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_cython_special.cpython-310.pyc differ diff --git a/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_dd.cpython-310.pyc b/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_dd.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..e9846e12a36b55f84ce3e9361b083b9691eac1a7 Binary files /dev/null and b/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_dd.cpython-310.pyc differ diff --git a/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_digamma.cpython-310.pyc b/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_digamma.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..35f989040f4e97f2f1de6a91fd98993ef5f86c7c Binary files /dev/null and b/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_digamma.cpython-310.pyc differ diff --git a/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_erfinv.cpython-310.pyc b/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_erfinv.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..1c14048bb16e04ece0473be4966c34de7c7c6fd4 Binary files /dev/null and b/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_erfinv.cpython-310.pyc differ diff --git a/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_exponential_integrals.cpython-310.pyc b/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_exponential_integrals.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..83efbf913628416ad6efe02753ad67af072e6397 Binary files /dev/null and b/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_exponential_integrals.cpython-310.pyc differ diff --git a/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_faddeeva.cpython-310.pyc b/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_faddeeva.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..581e8939f501724c9dec6bcaacf6846e7646e188 Binary files /dev/null and b/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_faddeeva.cpython-310.pyc differ diff --git a/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_gamma.cpython-310.pyc b/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_gamma.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..e670a75c91a2dd7cf00d834a4ed0c83eb9b7b06d Binary files /dev/null and b/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_gamma.cpython-310.pyc differ diff --git a/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_gammainc.cpython-310.pyc b/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_gammainc.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..639a224ee242cc6287be613187600b8089778594 Binary files /dev/null and b/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_gammainc.cpython-310.pyc differ diff --git a/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_hyp2f1.cpython-310.pyc b/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_hyp2f1.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..4a19507b74a31120143ce11f96a07fbf72b1bc53 Binary files /dev/null and b/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_hyp2f1.cpython-310.pyc differ diff --git a/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_lambertw.cpython-310.pyc b/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_lambertw.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..5e92e84ff8bbdfa7a81efa1bc7692f6a500b81a4 Binary files /dev/null and b/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_lambertw.cpython-310.pyc differ diff --git a/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_log_softmax.cpython-310.pyc b/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_log_softmax.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..03cb1acd984551f6f4b8dfdd0e89f0ce9c318120 Binary files /dev/null and b/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_log_softmax.cpython-310.pyc differ diff --git a/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_logit.cpython-310.pyc b/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_logit.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..c9955548ebbfe0a3a8a7d7f4d9d09cf75b5f99bc Binary files /dev/null and b/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_logit.cpython-310.pyc differ diff --git a/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_logsumexp.cpython-310.pyc b/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_logsumexp.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..54848f4c07c687cef7dd3e6931ed3e06909fa826 Binary files /dev/null and b/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_logsumexp.cpython-310.pyc differ diff --git a/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_mpmath.cpython-310.pyc b/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_mpmath.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..2b3a3654c04f7421ff9d5fd21b406bc32fbc83b1 Binary files /dev/null and b/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_mpmath.cpython-310.pyc differ diff --git a/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_nan_inputs.cpython-310.pyc b/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_nan_inputs.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..ebb476b541805c5601b08188a636297771288818 Binary files /dev/null and b/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_nan_inputs.cpython-310.pyc differ diff --git a/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_ndtr.cpython-310.pyc b/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_ndtr.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..c39455a164bfb096f6e3a916411463e4de994aef Binary files /dev/null and b/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_ndtr.cpython-310.pyc differ diff --git a/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_ndtri_exp.cpython-310.pyc b/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_ndtri_exp.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..bab6704799328c18ee94b0081b5e5e91ca244d61 Binary files /dev/null and b/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_ndtri_exp.cpython-310.pyc differ diff --git a/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_orthogonal.cpython-310.pyc b/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_orthogonal.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..307f4ba8e46d6c508555d5c9bcd8aa76e8deaaa9 Binary files /dev/null and b/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_orthogonal.cpython-310.pyc differ diff --git a/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_owens_t.cpython-310.pyc b/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_owens_t.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..d9ab29124287146c873db03c5753bbd7bb957263 Binary files /dev/null and b/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_owens_t.cpython-310.pyc differ diff --git a/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_powm1.cpython-310.pyc b/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_powm1.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..61ef4c6af16d8c2d338bfb2fe2a8c186298717f2 Binary files /dev/null and b/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_powm1.cpython-310.pyc differ diff --git a/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_precompute_expn_asy.cpython-310.pyc b/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_precompute_expn_asy.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..c11404b3fa1acb5f2a7fae16a40c38e0502ff329 Binary files /dev/null and b/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_precompute_expn_asy.cpython-310.pyc differ diff --git a/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_precompute_gammainc.cpython-310.pyc b/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_precompute_gammainc.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..6f22bcd2cf0c064b82319af97e9e23e5a27148f4 Binary files /dev/null and b/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_precompute_gammainc.cpython-310.pyc differ diff --git a/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_precompute_utils.cpython-310.pyc b/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_precompute_utils.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..c52f8fddd93f34b0bf8111a4c9f11116e132bcf6 Binary files /dev/null and b/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_precompute_utils.cpython-310.pyc differ diff --git a/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_sf_error.cpython-310.pyc b/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_sf_error.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..e5d02000bafbebc87bcf5b12449b4d82f3125caa Binary files /dev/null and b/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_sf_error.cpython-310.pyc differ diff --git a/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_sici.cpython-310.pyc b/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_sici.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..f369174132581b504d0b82477f6b6732d3b2de5c Binary files /dev/null and b/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_sici.cpython-310.pyc differ diff --git a/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_spfun_stats.cpython-310.pyc b/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_spfun_stats.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..dab7f02157d67c7da06a79f2d816964783947242 Binary files /dev/null and b/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_spfun_stats.cpython-310.pyc differ diff --git a/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_sph_harm.cpython-310.pyc b/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_sph_harm.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..aee44159c6d08ceeb313e150b865ff2a417586a7 Binary files /dev/null and b/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_sph_harm.cpython-310.pyc differ diff --git a/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_spherical_bessel.cpython-310.pyc b/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_spherical_bessel.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..66783012af404a19225d745f4abf7e956b6446c1 Binary files /dev/null and b/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_spherical_bessel.cpython-310.pyc differ diff --git a/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_support_alternative_backends.cpython-310.pyc b/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_support_alternative_backends.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..ef833774e755d0dd5d79ef779de1700018b452a5 Binary files /dev/null and b/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_support_alternative_backends.cpython-310.pyc differ diff --git a/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_trig.cpython-310.pyc b/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_trig.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..b1c1bbde6d72a0d7d0dcac85b9990b8171c07722 Binary files /dev/null and b/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_trig.cpython-310.pyc differ diff --git a/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_wright_bessel.cpython-310.pyc b/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_wright_bessel.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..82eb0a84d718171bc38e51eeb13c4186f3548d30 Binary files /dev/null and b/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_wright_bessel.cpython-310.pyc differ diff --git a/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_wrightomega.cpython-310.pyc b/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_wrightomega.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..e020a59210ec75e18e515873fdf8b81dab2ffbd1 Binary files /dev/null and b/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_wrightomega.cpython-310.pyc differ diff --git a/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_zeta.cpython-310.pyc b/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_zeta.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..8da6603daa78a5f9140104d21d52c57f36c1161c Binary files /dev/null and b/venv/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_zeta.cpython-310.pyc differ