ZTWHHH commited on
Commit
e0e1a7e
·
verified ·
1 Parent(s): 25aeca5

Add files using upload-large-folder tool

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .gitattributes +8 -0
  2. openflamingo/lib/python3.10/site-packages/scipy/fft/_pocketfft/pypocketfft.cpython-310-x86_64-linux-gnu.so +3 -0
  3. openflamingo/lib/python3.10/site-packages/scipy/linalg/_cythonized_array_utils.cpython-310-x86_64-linux-gnu.so +3 -0
  4. openflamingo/lib/python3.10/site-packages/scipy/linalg/_decomp_update.cpython-310-x86_64-linux-gnu.so +3 -0
  5. openflamingo/lib/python3.10/site-packages/scipy/linalg/_matfuncs_expm.cpython-310-x86_64-linux-gnu.so +3 -0
  6. openflamingo/lib/python3.10/site-packages/scipy/linalg/_solve_toeplitz.cpython-310-x86_64-linux-gnu.so +3 -0
  7. openflamingo/lib/python3.10/site-packages/scipy/linalg/cython_blas.cpython-310-x86_64-linux-gnu.so +3 -0
  8. openflamingo/lib/python3.10/site-packages/scipy/linalg/tests/data/gendare_20170120_data.npz +3 -0
  9. openflamingo/lib/python3.10/site-packages/scipy/spatial/_ckdtree.cpython-310-x86_64-linux-gnu.so +3 -0
  10. openflamingo/lib/python3.10/site-packages/scipy/special/_ellip_harm.py +214 -0
  11. openflamingo/lib/python3.10/site-packages/scipy/special/_lambertw.py +149 -0
  12. openflamingo/lib/python3.10/site-packages/scipy/special/_spfun_stats.py +106 -0
  13. openflamingo/lib/python3.10/site-packages/scipy/special/_test_internal.pyi +9 -0
  14. openflamingo/lib/python3.10/site-packages/scipy/special/_ufuncs.pyi +526 -0
  15. openflamingo/lib/python3.10/site-packages/scipy/special/_ufuncs_cxx.pyx +181 -0
  16. openflamingo/lib/python3.10/site-packages/scipy/special/_ufuncs_defs.h +185 -0
  17. openflamingo/lib/python3.10/site-packages/scipy/special/cython_special.pyx +0 -0
  18. openflamingo/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_boxcox.cpython-310.pyc +0 -0
  19. openflamingo/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_cdft_asymptotic.cpython-310.pyc +0 -0
  20. openflamingo/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_faddeeva.cpython-310.pyc +0 -0
  21. openflamingo/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_log_softmax.cpython-310.pyc +0 -0
  22. openflamingo/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_logit.cpython-310.pyc +0 -0
  23. openflamingo/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_logsumexp.cpython-310.pyc +0 -0
  24. openflamingo/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_sici.cpython-310.pyc +0 -0
  25. openflamingo/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_spfun_stats.cpython-310.pyc +0 -0
  26. openflamingo/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_support_alternative_backends.cpython-310.pyc +0 -0
  27. openflamingo/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_wright_bessel.cpython-310.pyc +0 -0
  28. openflamingo/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_wrightomega.cpython-310.pyc +0 -0
  29. openflamingo/lib/python3.10/site-packages/scipy/special/tests/test_basic.py +0 -0
  30. openflamingo/lib/python3.10/site-packages/scipy/special/tests/test_bdtr.py +112 -0
  31. openflamingo/lib/python3.10/site-packages/scipy/special/tests/test_boxcox.py +106 -0
  32. openflamingo/lib/python3.10/site-packages/scipy/special/tests/test_cdflib.py +527 -0
  33. openflamingo/lib/python3.10/site-packages/scipy/special/tests/test_cdft_asymptotic.py +49 -0
  34. openflamingo/lib/python3.10/site-packages/scipy/special/tests/test_cython_special.py +363 -0
  35. openflamingo/lib/python3.10/site-packages/scipy/special/tests/test_data.py +725 -0
  36. openflamingo/lib/python3.10/site-packages/scipy/special/tests/test_dd.py +46 -0
  37. openflamingo/lib/python3.10/site-packages/scipy/special/tests/test_digamma.py +45 -0
  38. openflamingo/lib/python3.10/site-packages/scipy/special/tests/test_ellip_harm.py +278 -0
  39. openflamingo/lib/python3.10/site-packages/scipy/special/tests/test_erfinv.py +89 -0
  40. openflamingo/lib/python3.10/site-packages/scipy/special/tests/test_exponential_integrals.py +118 -0
  41. openflamingo/lib/python3.10/site-packages/scipy/special/tests/test_faddeeva.py +85 -0
  42. openflamingo/lib/python3.10/site-packages/scipy/special/tests/test_gamma.py +12 -0
  43. openflamingo/lib/python3.10/site-packages/scipy/special/tests/test_gammainc.py +136 -0
  44. openflamingo/lib/python3.10/site-packages/scipy/special/tests/test_hypergeometric.py +140 -0
  45. openflamingo/lib/python3.10/site-packages/scipy/special/tests/test_kolmogorov.py +495 -0
  46. openflamingo/lib/python3.10/site-packages/scipy/special/tests/test_lambertw.py +109 -0
  47. openflamingo/lib/python3.10/site-packages/scipy/special/tests/test_loggamma.py +70 -0
  48. openflamingo/lib/python3.10/site-packages/scipy/special/tests/test_logsumexp.py +207 -0
  49. openflamingo/lib/python3.10/site-packages/scipy/special/tests/test_mpmath.py +2272 -0
  50. openflamingo/lib/python3.10/site-packages/scipy/special/tests/test_nan_inputs.py +64 -0
.gitattributes CHANGED
@@ -786,3 +786,11 @@ phi4/lib/python3.10/site-packages/numpy/_core/lib/libnpymath.a filter=lfs diff=l
786
  phi4/lib/python3.10/site-packages/numpy/_core/__pycache__/fromnumeric.cpython-310.pyc filter=lfs diff=lfs merge=lfs -text
787
  openflamingo/lib/python3.10/site-packages/scipy/io/matlab/_streams.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
788
  openflamingo/lib/python3.10/site-packages/scipy/io/matlab/_mio5_utils.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
 
 
 
 
786
  phi4/lib/python3.10/site-packages/numpy/_core/__pycache__/fromnumeric.cpython-310.pyc filter=lfs diff=lfs merge=lfs -text
787
  openflamingo/lib/python3.10/site-packages/scipy/io/matlab/_streams.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
788
  openflamingo/lib/python3.10/site-packages/scipy/io/matlab/_mio5_utils.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
789
+ phi4/lib/python3.10/site-packages/numpy/random/bit_generator.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
790
+ openflamingo/lib/python3.10/site-packages/scipy/linalg/_decomp_update.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
791
+ openflamingo/lib/python3.10/site-packages/scipy/linalg/_cythonized_array_utils.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
792
+ openflamingo/lib/python3.10/site-packages/scipy/linalg/cython_blas.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
793
+ openflamingo/lib/python3.10/site-packages/scipy/linalg/_solve_toeplitz.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
794
+ openflamingo/lib/python3.10/site-packages/scipy/spatial/_ckdtree.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
795
+ openflamingo/lib/python3.10/site-packages/scipy/fft/_pocketfft/pypocketfft.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
796
+ openflamingo/lib/python3.10/site-packages/scipy/linalg/_matfuncs_expm.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
openflamingo/lib/python3.10/site-packages/scipy/fft/_pocketfft/pypocketfft.cpython-310-x86_64-linux-gnu.so ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c39ee117a6cbc87241a50a1b1b7047fa515577945ba129a92c814fc412ee07a0
3
+ size 1201320
openflamingo/lib/python3.10/site-packages/scipy/linalg/_cythonized_array_utils.cpython-310-x86_64-linux-gnu.so ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e10940ad4a98bb79181b57eb89e4d5276eed0f3bd2a265cd3ec44cab53574076
3
+ size 633088
openflamingo/lib/python3.10/site-packages/scipy/linalg/_decomp_update.cpython-310-x86_64-linux-gnu.so ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a0e5736df7906bb83eeda658132fa48dc14e5bccb14a75bc36d9fd3e31c80095
3
+ size 372704
openflamingo/lib/python3.10/site-packages/scipy/linalg/_matfuncs_expm.cpython-310-x86_64-linux-gnu.so ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8ec6a3bda2516baea6b3fa92a36206684d7d58385879c6d7173dcd717866c619
3
+ size 525696
openflamingo/lib/python3.10/site-packages/scipy/linalg/_solve_toeplitz.cpython-310-x86_64-linux-gnu.so ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d1a4ff5e2e26f8b33cb6c9b2c4eb9e537b2bef411bd914a024f9751fe33a3063
3
+ size 300152
openflamingo/lib/python3.10/site-packages/scipy/linalg/cython_blas.cpython-310-x86_64-linux-gnu.so ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ec86a3f8443905debab4b9fc6a858e7b587767473297b3f855a8f3249f0b8cf4
3
+ size 348849
openflamingo/lib/python3.10/site-packages/scipy/linalg/tests/data/gendare_20170120_data.npz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a3dfab451d9d5c20243e0ed85cd8b6c9657669fb9a0f83b5be165585783d55b5
3
+ size 2164
openflamingo/lib/python3.10/site-packages/scipy/spatial/_ckdtree.cpython-310-x86_64-linux-gnu.so ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1031461363c3772a9a32030693341b112093ff989eab6e3d04213d6873c235d9
3
+ size 1027824
openflamingo/lib/python3.10/site-packages/scipy/special/_ellip_harm.py ADDED
@@ -0,0 +1,214 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+
3
+ from ._ufuncs import _ellip_harm
4
+ from ._ellip_harm_2 import _ellipsoid, _ellipsoid_norm
5
+
6
+
7
+ def ellip_harm(h2, k2, n, p, s, signm=1, signn=1):
8
+ r"""
9
+ Ellipsoidal harmonic functions E^p_n(l)
10
+
11
+ These are also known as Lame functions of the first kind, and are
12
+ solutions to the Lame equation:
13
+
14
+ .. math:: (s^2 - h^2)(s^2 - k^2)E''(s)
15
+ + s(2s^2 - h^2 - k^2)E'(s) + (a - q s^2)E(s) = 0
16
+
17
+ where :math:`q = (n+1)n` and :math:`a` is the eigenvalue (not
18
+ returned) corresponding to the solutions.
19
+
20
+ Parameters
21
+ ----------
22
+ h2 : float
23
+ ``h**2``
24
+ k2 : float
25
+ ``k**2``; should be larger than ``h**2``
26
+ n : int
27
+ Degree
28
+ s : float
29
+ Coordinate
30
+ p : int
31
+ Order, can range between [1,2n+1]
32
+ signm : {1, -1}, optional
33
+ Sign of prefactor of functions. Can be +/-1. See Notes.
34
+ signn : {1, -1}, optional
35
+ Sign of prefactor of functions. Can be +/-1. See Notes.
36
+
37
+ Returns
38
+ -------
39
+ E : float
40
+ the harmonic :math:`E^p_n(s)`
41
+
42
+ See Also
43
+ --------
44
+ ellip_harm_2, ellip_normal
45
+
46
+ Notes
47
+ -----
48
+ The geometric interpretation of the ellipsoidal functions is
49
+ explained in [2]_, [3]_, [4]_. The `signm` and `signn` arguments control the
50
+ sign of prefactors for functions according to their type::
51
+
52
+ K : +1
53
+ L : signm
54
+ M : signn
55
+ N : signm*signn
56
+
57
+ .. versionadded:: 0.15.0
58
+
59
+ References
60
+ ----------
61
+ .. [1] Digital Library of Mathematical Functions 29.12
62
+ https://dlmf.nist.gov/29.12
63
+ .. [2] Bardhan and Knepley, "Computational science and
64
+ re-discovery: open-source implementations of
65
+ ellipsoidal harmonics for problems in potential theory",
66
+ Comput. Sci. Disc. 5, 014006 (2012)
67
+ :doi:`10.1088/1749-4699/5/1/014006`.
68
+ .. [3] David J.and Dechambre P, "Computation of Ellipsoidal
69
+ Gravity Field Harmonics for small solar system bodies"
70
+ pp. 30-36, 2000
71
+ .. [4] George Dassios, "Ellipsoidal Harmonics: Theory and Applications"
72
+ pp. 418, 2012
73
+
74
+ Examples
75
+ --------
76
+ >>> from scipy.special import ellip_harm
77
+ >>> w = ellip_harm(5,8,1,1,2.5)
78
+ >>> w
79
+ 2.5
80
+
81
+ Check that the functions indeed are solutions to the Lame equation:
82
+
83
+ >>> import numpy as np
84
+ >>> from scipy.interpolate import UnivariateSpline
85
+ >>> def eigenvalue(f, df, ddf):
86
+ ... r = (((s**2 - h**2) * (s**2 - k**2) * ddf
87
+ ... + s * (2*s**2 - h**2 - k**2) * df
88
+ ... - n * (n + 1)*s**2*f) / f)
89
+ ... return -r.mean(), r.std()
90
+ >>> s = np.linspace(0.1, 10, 200)
91
+ >>> k, h, n, p = 8.0, 2.2, 3, 2
92
+ >>> E = ellip_harm(h**2, k**2, n, p, s)
93
+ >>> E_spl = UnivariateSpline(s, E)
94
+ >>> a, a_err = eigenvalue(E_spl(s), E_spl(s,1), E_spl(s,2))
95
+ >>> a, a_err
96
+ (583.44366156701483, 6.4580890640310646e-11)
97
+
98
+ """ # noqa: E501
99
+ return _ellip_harm(h2, k2, n, p, s, signm, signn)
100
+
101
+
102
+ _ellip_harm_2_vec = np.vectorize(_ellipsoid, otypes='d')
103
+
104
+
105
+ def ellip_harm_2(h2, k2, n, p, s):
106
+ r"""
107
+ Ellipsoidal harmonic functions F^p_n(l)
108
+
109
+ These are also known as Lame functions of the second kind, and are
110
+ solutions to the Lame equation:
111
+
112
+ .. math:: (s^2 - h^2)(s^2 - k^2)F''(s)
113
+ + s(2s^2 - h^2 - k^2)F'(s) + (a - q s^2)F(s) = 0
114
+
115
+ where :math:`q = (n+1)n` and :math:`a` is the eigenvalue (not
116
+ returned) corresponding to the solutions.
117
+
118
+ Parameters
119
+ ----------
120
+ h2 : float
121
+ ``h**2``
122
+ k2 : float
123
+ ``k**2``; should be larger than ``h**2``
124
+ n : int
125
+ Degree.
126
+ p : int
127
+ Order, can range between [1,2n+1].
128
+ s : float
129
+ Coordinate
130
+
131
+ Returns
132
+ -------
133
+ F : float
134
+ The harmonic :math:`F^p_n(s)`
135
+
136
+ See Also
137
+ --------
138
+ ellip_harm, ellip_normal
139
+
140
+ Notes
141
+ -----
142
+ Lame functions of the second kind are related to the functions of the first kind:
143
+
144
+ .. math::
145
+
146
+ F^p_n(s)=(2n + 1)E^p_n(s)\int_{0}^{1/s}
147
+ \frac{du}{(E^p_n(1/u))^2\sqrt{(1-u^2k^2)(1-u^2h^2)}}
148
+
149
+ .. versionadded:: 0.15.0
150
+
151
+ Examples
152
+ --------
153
+ >>> from scipy.special import ellip_harm_2
154
+ >>> w = ellip_harm_2(5,8,2,1,10)
155
+ >>> w
156
+ 0.00108056853382
157
+
158
+ """
159
+ with np.errstate(all='ignore'):
160
+ return _ellip_harm_2_vec(h2, k2, n, p, s)
161
+
162
+
163
+ def _ellip_normal_vec(h2, k2, n, p):
164
+ return _ellipsoid_norm(h2, k2, n, p)
165
+
166
+
167
+ _ellip_normal_vec = np.vectorize(_ellip_normal_vec, otypes='d')
168
+
169
+
170
+ def ellip_normal(h2, k2, n, p):
171
+ r"""
172
+ Ellipsoidal harmonic normalization constants gamma^p_n
173
+
174
+ The normalization constant is defined as
175
+
176
+ .. math::
177
+
178
+ \gamma^p_n=8\int_{0}^{h}dx\int_{h}^{k}dy
179
+ \frac{(y^2-x^2)(E^p_n(y)E^p_n(x))^2}{\sqrt((k^2-y^2)(y^2-h^2)(h^2-x^2)(k^2-x^2)}
180
+
181
+ Parameters
182
+ ----------
183
+ h2 : float
184
+ ``h**2``
185
+ k2 : float
186
+ ``k**2``; should be larger than ``h**2``
187
+ n : int
188
+ Degree.
189
+ p : int
190
+ Order, can range between [1,2n+1].
191
+
192
+ Returns
193
+ -------
194
+ gamma : float
195
+ The normalization constant :math:`\gamma^p_n`
196
+
197
+ See Also
198
+ --------
199
+ ellip_harm, ellip_harm_2
200
+
201
+ Notes
202
+ -----
203
+ .. versionadded:: 0.15.0
204
+
205
+ Examples
206
+ --------
207
+ >>> from scipy.special import ellip_normal
208
+ >>> w = ellip_normal(5,8,3,7)
209
+ >>> w
210
+ 1723.38796997
211
+
212
+ """
213
+ with np.errstate(all='ignore'):
214
+ return _ellip_normal_vec(h2, k2, n, p)
openflamingo/lib/python3.10/site-packages/scipy/special/_lambertw.py ADDED
@@ -0,0 +1,149 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from ._ufuncs import _lambertw
2
+
3
+ import numpy as np
4
+
5
+
6
+ def lambertw(z, k=0, tol=1e-8):
7
+ r"""
8
+ lambertw(z, k=0, tol=1e-8)
9
+
10
+ Lambert W function.
11
+
12
+ The Lambert W function `W(z)` is defined as the inverse function
13
+ of ``w * exp(w)``. In other words, the value of ``W(z)`` is
14
+ such that ``z = W(z) * exp(W(z))`` for any complex number
15
+ ``z``.
16
+
17
+ The Lambert W function is a multivalued function with infinitely
18
+ many branches. Each branch gives a separate solution of the
19
+ equation ``z = w exp(w)``. Here, the branches are indexed by the
20
+ integer `k`.
21
+
22
+ Parameters
23
+ ----------
24
+ z : array_like
25
+ Input argument.
26
+ k : int, optional
27
+ Branch index.
28
+ tol : float, optional
29
+ Evaluation tolerance.
30
+
31
+ Returns
32
+ -------
33
+ w : array
34
+ `w` will have the same shape as `z`.
35
+
36
+ See Also
37
+ --------
38
+ wrightomega : the Wright Omega function
39
+
40
+ Notes
41
+ -----
42
+ All branches are supported by `lambertw`:
43
+
44
+ * ``lambertw(z)`` gives the principal solution (branch 0)
45
+ * ``lambertw(z, k)`` gives the solution on branch `k`
46
+
47
+ The Lambert W function has two partially real branches: the
48
+ principal branch (`k = 0`) is real for real ``z > -1/e``, and the
49
+ ``k = -1`` branch is real for ``-1/e < z < 0``. All branches except
50
+ ``k = 0`` have a logarithmic singularity at ``z = 0``.
51
+
52
+ **Possible issues**
53
+
54
+ The evaluation can become inaccurate very close to the branch point
55
+ at ``-1/e``. In some corner cases, `lambertw` might currently
56
+ fail to converge, or can end up on the wrong branch.
57
+
58
+ **Algorithm**
59
+
60
+ Halley's iteration is used to invert ``w * exp(w)``, using a first-order
61
+ asymptotic approximation (O(log(w)) or `O(w)`) as the initial estimate.
62
+
63
+ The definition, implementation and choice of branches is based on [2]_.
64
+
65
+ References
66
+ ----------
67
+ .. [1] https://en.wikipedia.org/wiki/Lambert_W_function
68
+ .. [2] Corless et al, "On the Lambert W function", Adv. Comp. Math. 5
69
+ (1996) 329-359.
70
+ https://cs.uwaterloo.ca/research/tr/1993/03/W.pdf
71
+
72
+ Examples
73
+ --------
74
+ The Lambert W function is the inverse of ``w exp(w)``:
75
+
76
+ >>> import numpy as np
77
+ >>> from scipy.special import lambertw
78
+ >>> w = lambertw(1)
79
+ >>> w
80
+ (0.56714329040978384+0j)
81
+ >>> w * np.exp(w)
82
+ (1.0+0j)
83
+
84
+ Any branch gives a valid inverse:
85
+
86
+ >>> w = lambertw(1, k=3)
87
+ >>> w
88
+ (-2.8535817554090377+17.113535539412148j)
89
+ >>> w*np.exp(w)
90
+ (1.0000000000000002+1.609823385706477e-15j)
91
+
92
+ **Applications to equation-solving**
93
+
94
+ The Lambert W function may be used to solve various kinds of
95
+ equations. We give two examples here.
96
+
97
+ First, the function can be used to solve implicit equations of the
98
+ form
99
+
100
+ :math:`x = a + b e^{c x}`
101
+
102
+ for :math:`x`. We assume :math:`c` is not zero. After a little
103
+ algebra, the equation may be written
104
+
105
+ :math:`z e^z = -b c e^{a c}`
106
+
107
+ where :math:`z = c (a - x)`. :math:`z` may then be expressed using
108
+ the Lambert W function
109
+
110
+ :math:`z = W(-b c e^{a c})`
111
+
112
+ giving
113
+
114
+ :math:`x = a - W(-b c e^{a c})/c`
115
+
116
+ For example,
117
+
118
+ >>> a = 3
119
+ >>> b = 2
120
+ >>> c = -0.5
121
+
122
+ The solution to :math:`x = a + b e^{c x}` is:
123
+
124
+ >>> x = a - lambertw(-b*c*np.exp(a*c))/c
125
+ >>> x
126
+ (3.3707498368978794+0j)
127
+
128
+ Verify that it solves the equation:
129
+
130
+ >>> a + b*np.exp(c*x)
131
+ (3.37074983689788+0j)
132
+
133
+ The Lambert W function may also be used find the value of the infinite
134
+ power tower :math:`z^{z^{z^{\ldots}}}`:
135
+
136
+ >>> def tower(z, n):
137
+ ... if n == 0:
138
+ ... return z
139
+ ... return z ** tower(z, n-1)
140
+ ...
141
+ >>> tower(0.5, 100)
142
+ 0.641185744504986
143
+ >>> -lambertw(-np.log(0.5)) / np.log(0.5)
144
+ (0.64118574450498589+0j)
145
+ """
146
+ # TODO: special expert should inspect this
147
+ # interception; better place to do it?
148
+ k = np.asarray(k, dtype=np.dtype("long"))
149
+ return _lambertw(z, k, tol)
openflamingo/lib/python3.10/site-packages/scipy/special/_spfun_stats.py ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Last Change: Sat Mar 21 02:00 PM 2009 J
2
+
3
+ # Copyright (c) 2001, 2002 Enthought, Inc.
4
+ #
5
+ # All rights reserved.
6
+ #
7
+ # Redistribution and use in source and binary forms, with or without
8
+ # modification, are permitted provided that the following conditions are met:
9
+ #
10
+ # a. Redistributions of source code must retain the above copyright notice,
11
+ # this list of conditions and the following disclaimer.
12
+ # b. Redistributions in binary form must reproduce the above copyright
13
+ # notice, this list of conditions and the following disclaimer in the
14
+ # documentation and/or other materials provided with the distribution.
15
+ # c. Neither the name of the Enthought nor the names of its contributors
16
+ # may be used to endorse or promote products derived from this software
17
+ # without specific prior written permission.
18
+ #
19
+ #
20
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
24
+ # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
+ # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26
+ # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27
+ # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28
+ # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29
+ # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
30
+ # DAMAGE.
31
+
32
+ """Some more special functions which may be useful for multivariate statistical
33
+ analysis."""
34
+
35
+ import numpy as np
36
+ from scipy.special import gammaln as loggam
37
+
38
+
39
+ __all__ = ['multigammaln']
40
+
41
+
42
+ def multigammaln(a, d):
43
+ r"""Returns the log of multivariate gamma, also sometimes called the
44
+ generalized gamma.
45
+
46
+ Parameters
47
+ ----------
48
+ a : ndarray
49
+ The multivariate gamma is computed for each item of `a`.
50
+ d : int
51
+ The dimension of the space of integration.
52
+
53
+ Returns
54
+ -------
55
+ res : ndarray
56
+ The values of the log multivariate gamma at the given points `a`.
57
+
58
+ Notes
59
+ -----
60
+ The formal definition of the multivariate gamma of dimension d for a real
61
+ `a` is
62
+
63
+ .. math::
64
+
65
+ \Gamma_d(a) = \int_{A>0} e^{-tr(A)} |A|^{a - (d+1)/2} dA
66
+
67
+ with the condition :math:`a > (d-1)/2`, and :math:`A > 0` being the set of
68
+ all the positive definite matrices of dimension `d`. Note that `a` is a
69
+ scalar: the integrand only is multivariate, the argument is not (the
70
+ function is defined over a subset of the real set).
71
+
72
+ This can be proven to be equal to the much friendlier equation
73
+
74
+ .. math::
75
+
76
+ \Gamma_d(a) = \pi^{d(d-1)/4} \prod_{i=1}^{d} \Gamma(a - (i-1)/2).
77
+
78
+ References
79
+ ----------
80
+ R. J. Muirhead, Aspects of multivariate statistical theory (Wiley Series in
81
+ probability and mathematical statistics).
82
+
83
+ Examples
84
+ --------
85
+ >>> import numpy as np
86
+ >>> from scipy.special import multigammaln, gammaln
87
+ >>> a = 23.5
88
+ >>> d = 10
89
+ >>> multigammaln(a, d)
90
+ 454.1488605074416
91
+
92
+ Verify that the result agrees with the logarithm of the equation
93
+ shown above:
94
+
95
+ >>> d*(d-1)/4*np.log(np.pi) + gammaln(a - 0.5*np.arange(0, d)).sum()
96
+ 454.1488605074416
97
+ """
98
+ a = np.asarray(a)
99
+ if not np.isscalar(d) or (np.floor(d) != d):
100
+ raise ValueError("d should be a positive integer (dimension)")
101
+ if np.any(a <= 0.5 * (d - 1)):
102
+ raise ValueError(f"condition a ({a:f}) > 0.5 * (d-1) ({0.5 * (d-1):f}) not met")
103
+
104
+ res = (d * (d-1) * 0.25) * np.log(np.pi)
105
+ res += np.sum(loggam([(a - (j - 1.)/2) for j in range(1, d+1)]), axis=0)
106
+ return res
openflamingo/lib/python3.10/site-packages/scipy/special/_test_internal.pyi ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+
3
+ def have_fenv() -> bool: ...
4
+ def random_double(size: int) -> np.float64: ...
5
+ def test_add_round(size: int, mode: str): ...
6
+
7
+ def _dd_exp(xhi: float, xlo: float) -> tuple[float, float]: ...
8
+ def _dd_log(xhi: float, xlo: float) -> tuple[float, float]: ...
9
+ def _dd_expm1(xhi: float, xlo: float) -> tuple[float, float]: ...
openflamingo/lib/python3.10/site-packages/scipy/special/_ufuncs.pyi ADDED
@@ -0,0 +1,526 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # This file is automatically generated by _generate_pyx.py.
2
+ # Do not edit manually!
3
+
4
+ from typing import Any, Dict
5
+
6
+ import numpy as np
7
+
8
+ __all__ = [
9
+ 'geterr',
10
+ 'seterr',
11
+ 'errstate',
12
+ 'agm',
13
+ 'airy',
14
+ 'airye',
15
+ 'bdtr',
16
+ 'bdtrc',
17
+ 'bdtri',
18
+ 'bdtrik',
19
+ 'bdtrin',
20
+ 'bei',
21
+ 'beip',
22
+ 'ber',
23
+ 'berp',
24
+ 'besselpoly',
25
+ 'beta',
26
+ 'betainc',
27
+ 'betaincc',
28
+ 'betainccinv',
29
+ 'betaincinv',
30
+ 'betaln',
31
+ 'binom',
32
+ 'boxcox',
33
+ 'boxcox1p',
34
+ 'btdtr',
35
+ 'btdtri',
36
+ 'btdtria',
37
+ 'btdtrib',
38
+ 'cbrt',
39
+ 'chdtr',
40
+ 'chdtrc',
41
+ 'chdtri',
42
+ 'chdtriv',
43
+ 'chndtr',
44
+ 'chndtridf',
45
+ 'chndtrinc',
46
+ 'chndtrix',
47
+ 'cosdg',
48
+ 'cosm1',
49
+ 'cotdg',
50
+ 'dawsn',
51
+ 'ellipe',
52
+ 'ellipeinc',
53
+ 'ellipj',
54
+ 'ellipk',
55
+ 'ellipkinc',
56
+ 'ellipkm1',
57
+ 'elliprc',
58
+ 'elliprd',
59
+ 'elliprf',
60
+ 'elliprg',
61
+ 'elliprj',
62
+ 'entr',
63
+ 'erf',
64
+ 'erfc',
65
+ 'erfcinv',
66
+ 'erfcx',
67
+ 'erfi',
68
+ 'erfinv',
69
+ 'eval_chebyc',
70
+ 'eval_chebys',
71
+ 'eval_chebyt',
72
+ 'eval_chebyu',
73
+ 'eval_gegenbauer',
74
+ 'eval_genlaguerre',
75
+ 'eval_hermite',
76
+ 'eval_hermitenorm',
77
+ 'eval_jacobi',
78
+ 'eval_laguerre',
79
+ 'eval_legendre',
80
+ 'eval_sh_chebyt',
81
+ 'eval_sh_chebyu',
82
+ 'eval_sh_jacobi',
83
+ 'eval_sh_legendre',
84
+ 'exp1',
85
+ 'exp10',
86
+ 'exp2',
87
+ 'expi',
88
+ 'expit',
89
+ 'expm1',
90
+ 'expn',
91
+ 'exprel',
92
+ 'fdtr',
93
+ 'fdtrc',
94
+ 'fdtri',
95
+ 'fdtridfd',
96
+ 'fresnel',
97
+ 'gamma',
98
+ 'gammainc',
99
+ 'gammaincc',
100
+ 'gammainccinv',
101
+ 'gammaincinv',
102
+ 'gammaln',
103
+ 'gammasgn',
104
+ 'gdtr',
105
+ 'gdtrc',
106
+ 'gdtria',
107
+ 'gdtrib',
108
+ 'gdtrix',
109
+ 'hankel1',
110
+ 'hankel1e',
111
+ 'hankel2',
112
+ 'hankel2e',
113
+ 'huber',
114
+ 'hyp0f1',
115
+ 'hyp1f1',
116
+ 'hyp2f1',
117
+ 'hyperu',
118
+ 'i0',
119
+ 'i0e',
120
+ 'i1',
121
+ 'i1e',
122
+ 'inv_boxcox',
123
+ 'inv_boxcox1p',
124
+ 'it2i0k0',
125
+ 'it2j0y0',
126
+ 'it2struve0',
127
+ 'itairy',
128
+ 'iti0k0',
129
+ 'itj0y0',
130
+ 'itmodstruve0',
131
+ 'itstruve0',
132
+ 'iv',
133
+ 'ive',
134
+ 'j0',
135
+ 'j1',
136
+ 'jn',
137
+ 'jv',
138
+ 'jve',
139
+ 'k0',
140
+ 'k0e',
141
+ 'k1',
142
+ 'k1e',
143
+ 'kei',
144
+ 'keip',
145
+ 'kelvin',
146
+ 'ker',
147
+ 'kerp',
148
+ 'kl_div',
149
+ 'kn',
150
+ 'kolmogi',
151
+ 'kolmogorov',
152
+ 'kv',
153
+ 'kve',
154
+ 'log1p',
155
+ 'log_expit',
156
+ 'log_ndtr',
157
+ 'loggamma',
158
+ 'logit',
159
+ 'lpmv',
160
+ 'mathieu_a',
161
+ 'mathieu_b',
162
+ 'mathieu_cem',
163
+ 'mathieu_modcem1',
164
+ 'mathieu_modcem2',
165
+ 'mathieu_modsem1',
166
+ 'mathieu_modsem2',
167
+ 'mathieu_sem',
168
+ 'modfresnelm',
169
+ 'modfresnelp',
170
+ 'modstruve',
171
+ 'nbdtr',
172
+ 'nbdtrc',
173
+ 'nbdtri',
174
+ 'nbdtrik',
175
+ 'nbdtrin',
176
+ 'ncfdtr',
177
+ 'ncfdtri',
178
+ 'ncfdtridfd',
179
+ 'ncfdtridfn',
180
+ 'ncfdtrinc',
181
+ 'nctdtr',
182
+ 'nctdtridf',
183
+ 'nctdtrinc',
184
+ 'nctdtrit',
185
+ 'ndtr',
186
+ 'ndtri',
187
+ 'ndtri_exp',
188
+ 'nrdtrimn',
189
+ 'nrdtrisd',
190
+ 'obl_ang1',
191
+ 'obl_ang1_cv',
192
+ 'obl_cv',
193
+ 'obl_rad1',
194
+ 'obl_rad1_cv',
195
+ 'obl_rad2',
196
+ 'obl_rad2_cv',
197
+ 'owens_t',
198
+ 'pbdv',
199
+ 'pbvv',
200
+ 'pbwa',
201
+ 'pdtr',
202
+ 'pdtrc',
203
+ 'pdtri',
204
+ 'pdtrik',
205
+ 'poch',
206
+ 'powm1',
207
+ 'pro_ang1',
208
+ 'pro_ang1_cv',
209
+ 'pro_cv',
210
+ 'pro_rad1',
211
+ 'pro_rad1_cv',
212
+ 'pro_rad2',
213
+ 'pro_rad2_cv',
214
+ 'pseudo_huber',
215
+ 'psi',
216
+ 'radian',
217
+ 'rel_entr',
218
+ 'rgamma',
219
+ 'round',
220
+ 'shichi',
221
+ 'sici',
222
+ 'sindg',
223
+ 'smirnov',
224
+ 'smirnovi',
225
+ 'spence',
226
+ 'sph_harm',
227
+ 'stdtr',
228
+ 'stdtridf',
229
+ 'stdtrit',
230
+ 'struve',
231
+ 'tandg',
232
+ 'tklmbda',
233
+ 'voigt_profile',
234
+ 'wofz',
235
+ 'wright_bessel',
236
+ 'wrightomega',
237
+ 'xlog1py',
238
+ 'xlogy',
239
+ 'y0',
240
+ 'y1',
241
+ 'yn',
242
+ 'yv',
243
+ 'yve',
244
+ 'zetac'
245
+ ]
246
+
247
+ def geterr() -> Dict[str, str]: ...
248
+ def seterr(**kwargs: str) -> Dict[str, str]: ...
249
+
250
+ class errstate:
251
+ def __init__(self, **kargs: str) -> None: ...
252
+ def __enter__(self) -> None: ...
253
+ def __exit__(
254
+ self,
255
+ exc_type: Any, # Unused
256
+ exc_value: Any, # Unused
257
+ traceback: Any, # Unused
258
+ ) -> None: ...
259
+
260
+ _cosine_cdf: np.ufunc
261
+ _cosine_invcdf: np.ufunc
262
+ _cospi: np.ufunc
263
+ _ellip_harm: np.ufunc
264
+ _factorial: np.ufunc
265
+ _igam_fac: np.ufunc
266
+ _kolmogc: np.ufunc
267
+ _kolmogci: np.ufunc
268
+ _kolmogp: np.ufunc
269
+ _lambertw: np.ufunc
270
+ _lanczos_sum_expg_scaled: np.ufunc
271
+ _lgam1p: np.ufunc
272
+ _log1pmx: np.ufunc
273
+ _riemann_zeta: np.ufunc
274
+ _scaled_exp1: np.ufunc
275
+ _sf_error_test_function: np.ufunc
276
+ _sinpi: np.ufunc
277
+ _smirnovc: np.ufunc
278
+ _smirnovci: np.ufunc
279
+ _smirnovp: np.ufunc
280
+ _spherical_in: np.ufunc
281
+ _spherical_in_d: np.ufunc
282
+ _spherical_jn: np.ufunc
283
+ _spherical_jn_d: np.ufunc
284
+ _spherical_kn: np.ufunc
285
+ _spherical_kn_d: np.ufunc
286
+ _spherical_yn: np.ufunc
287
+ _spherical_yn_d: np.ufunc
288
+ _stirling2_inexact: np.ufunc
289
+ _struve_asymp_large_z: np.ufunc
290
+ _struve_bessel_series: np.ufunc
291
+ _struve_power_series: np.ufunc
292
+ _zeta: np.ufunc
293
+ agm: np.ufunc
294
+ airy: np.ufunc
295
+ airye: np.ufunc
296
+ bdtr: np.ufunc
297
+ bdtrc: np.ufunc
298
+ bdtri: np.ufunc
299
+ bdtrik: np.ufunc
300
+ bdtrin: np.ufunc
301
+ bei: np.ufunc
302
+ beip: np.ufunc
303
+ ber: np.ufunc
304
+ berp: np.ufunc
305
+ besselpoly: np.ufunc
306
+ beta: np.ufunc
307
+ betainc: np.ufunc
308
+ betaincc: np.ufunc
309
+ betainccinv: np.ufunc
310
+ betaincinv: np.ufunc
311
+ betaln: np.ufunc
312
+ binom: np.ufunc
313
+ boxcox1p: np.ufunc
314
+ boxcox: np.ufunc
315
+ btdtr: np.ufunc
316
+ btdtri: np.ufunc
317
+ btdtria: np.ufunc
318
+ btdtrib: np.ufunc
319
+ cbrt: np.ufunc
320
+ chdtr: np.ufunc
321
+ chdtrc: np.ufunc
322
+ chdtri: np.ufunc
323
+ chdtriv: np.ufunc
324
+ chndtr: np.ufunc
325
+ chndtridf: np.ufunc
326
+ chndtrinc: np.ufunc
327
+ chndtrix: np.ufunc
328
+ cosdg: np.ufunc
329
+ cosm1: np.ufunc
330
+ cotdg: np.ufunc
331
+ dawsn: np.ufunc
332
+ ellipe: np.ufunc
333
+ ellipeinc: np.ufunc
334
+ ellipj: np.ufunc
335
+ ellipk: np.ufunc
336
+ ellipkinc: np.ufunc
337
+ ellipkm1: np.ufunc
338
+ elliprc: np.ufunc
339
+ elliprd: np.ufunc
340
+ elliprf: np.ufunc
341
+ elliprg: np.ufunc
342
+ elliprj: np.ufunc
343
+ entr: np.ufunc
344
+ erf: np.ufunc
345
+ erfc: np.ufunc
346
+ erfcinv: np.ufunc
347
+ erfcx: np.ufunc
348
+ erfi: np.ufunc
349
+ erfinv: np.ufunc
350
+ eval_chebyc: np.ufunc
351
+ eval_chebys: np.ufunc
352
+ eval_chebyt: np.ufunc
353
+ eval_chebyu: np.ufunc
354
+ eval_gegenbauer: np.ufunc
355
+ eval_genlaguerre: np.ufunc
356
+ eval_hermite: np.ufunc
357
+ eval_hermitenorm: np.ufunc
358
+ eval_jacobi: np.ufunc
359
+ eval_laguerre: np.ufunc
360
+ eval_legendre: np.ufunc
361
+ eval_sh_chebyt: np.ufunc
362
+ eval_sh_chebyu: np.ufunc
363
+ eval_sh_jacobi: np.ufunc
364
+ eval_sh_legendre: np.ufunc
365
+ exp10: np.ufunc
366
+ exp1: np.ufunc
367
+ exp2: np.ufunc
368
+ expi: np.ufunc
369
+ expit: np.ufunc
370
+ expm1: np.ufunc
371
+ expn: np.ufunc
372
+ exprel: np.ufunc
373
+ fdtr: np.ufunc
374
+ fdtrc: np.ufunc
375
+ fdtri: np.ufunc
376
+ fdtridfd: np.ufunc
377
+ fresnel: np.ufunc
378
+ gamma: np.ufunc
379
+ gammainc: np.ufunc
380
+ gammaincc: np.ufunc
381
+ gammainccinv: np.ufunc
382
+ gammaincinv: np.ufunc
383
+ gammaln: np.ufunc
384
+ gammasgn: np.ufunc
385
+ gdtr: np.ufunc
386
+ gdtrc: np.ufunc
387
+ gdtria: np.ufunc
388
+ gdtrib: np.ufunc
389
+ gdtrix: np.ufunc
390
+ hankel1: np.ufunc
391
+ hankel1e: np.ufunc
392
+ hankel2: np.ufunc
393
+ hankel2e: np.ufunc
394
+ huber: np.ufunc
395
+ hyp0f1: np.ufunc
396
+ hyp1f1: np.ufunc
397
+ hyp2f1: np.ufunc
398
+ hyperu: np.ufunc
399
+ i0: np.ufunc
400
+ i0e: np.ufunc
401
+ i1: np.ufunc
402
+ i1e: np.ufunc
403
+ inv_boxcox1p: np.ufunc
404
+ inv_boxcox: np.ufunc
405
+ it2i0k0: np.ufunc
406
+ it2j0y0: np.ufunc
407
+ it2struve0: np.ufunc
408
+ itairy: np.ufunc
409
+ iti0k0: np.ufunc
410
+ itj0y0: np.ufunc
411
+ itmodstruve0: np.ufunc
412
+ itstruve0: np.ufunc
413
+ iv: np.ufunc
414
+ ive: np.ufunc
415
+ j0: np.ufunc
416
+ j1: np.ufunc
417
+ jn: np.ufunc
418
+ jv: np.ufunc
419
+ jve: np.ufunc
420
+ k0: np.ufunc
421
+ k0e: np.ufunc
422
+ k1: np.ufunc
423
+ k1e: np.ufunc
424
+ kei: np.ufunc
425
+ keip: np.ufunc
426
+ kelvin: np.ufunc
427
+ ker: np.ufunc
428
+ kerp: np.ufunc
429
+ kl_div: np.ufunc
430
+ kn: np.ufunc
431
+ kolmogi: np.ufunc
432
+ kolmogorov: np.ufunc
433
+ kv: np.ufunc
434
+ kve: np.ufunc
435
+ log1p: np.ufunc
436
+ log_expit: np.ufunc
437
+ log_ndtr: np.ufunc
438
+ loggamma: np.ufunc
439
+ logit: np.ufunc
440
+ lpmv: np.ufunc
441
+ mathieu_a: np.ufunc
442
+ mathieu_b: np.ufunc
443
+ mathieu_cem: np.ufunc
444
+ mathieu_modcem1: np.ufunc
445
+ mathieu_modcem2: np.ufunc
446
+ mathieu_modsem1: np.ufunc
447
+ mathieu_modsem2: np.ufunc
448
+ mathieu_sem: np.ufunc
449
+ modfresnelm: np.ufunc
450
+ modfresnelp: np.ufunc
451
+ modstruve: np.ufunc
452
+ nbdtr: np.ufunc
453
+ nbdtrc: np.ufunc
454
+ nbdtri: np.ufunc
455
+ nbdtrik: np.ufunc
456
+ nbdtrin: np.ufunc
457
+ ncfdtr: np.ufunc
458
+ ncfdtri: np.ufunc
459
+ ncfdtridfd: np.ufunc
460
+ ncfdtridfn: np.ufunc
461
+ ncfdtrinc: np.ufunc
462
+ nctdtr: np.ufunc
463
+ nctdtridf: np.ufunc
464
+ nctdtrinc: np.ufunc
465
+ nctdtrit: np.ufunc
466
+ ndtr: np.ufunc
467
+ ndtri: np.ufunc
468
+ ndtri_exp: np.ufunc
469
+ nrdtrimn: np.ufunc
470
+ nrdtrisd: np.ufunc
471
+ obl_ang1: np.ufunc
472
+ obl_ang1_cv: np.ufunc
473
+ obl_cv: np.ufunc
474
+ obl_rad1: np.ufunc
475
+ obl_rad1_cv: np.ufunc
476
+ obl_rad2: np.ufunc
477
+ obl_rad2_cv: np.ufunc
478
+ owens_t: np.ufunc
479
+ pbdv: np.ufunc
480
+ pbvv: np.ufunc
481
+ pbwa: np.ufunc
482
+ pdtr: np.ufunc
483
+ pdtrc: np.ufunc
484
+ pdtri: np.ufunc
485
+ pdtrik: np.ufunc
486
+ poch: np.ufunc
487
+ powm1: np.ufunc
488
+ pro_ang1: np.ufunc
489
+ pro_ang1_cv: np.ufunc
490
+ pro_cv: np.ufunc
491
+ pro_rad1: np.ufunc
492
+ pro_rad1_cv: np.ufunc
493
+ pro_rad2: np.ufunc
494
+ pro_rad2_cv: np.ufunc
495
+ pseudo_huber: np.ufunc
496
+ psi: np.ufunc
497
+ radian: np.ufunc
498
+ rel_entr: np.ufunc
499
+ rgamma: np.ufunc
500
+ round: np.ufunc
501
+ shichi: np.ufunc
502
+ sici: np.ufunc
503
+ sindg: np.ufunc
504
+ smirnov: np.ufunc
505
+ smirnovi: np.ufunc
506
+ spence: np.ufunc
507
+ sph_harm: np.ufunc
508
+ stdtr: np.ufunc
509
+ stdtridf: np.ufunc
510
+ stdtrit: np.ufunc
511
+ struve: np.ufunc
512
+ tandg: np.ufunc
513
+ tklmbda: np.ufunc
514
+ voigt_profile: np.ufunc
515
+ wofz: np.ufunc
516
+ wright_bessel: np.ufunc
517
+ wrightomega: np.ufunc
518
+ xlog1py: np.ufunc
519
+ xlogy: np.ufunc
520
+ y0: np.ufunc
521
+ y1: np.ufunc
522
+ yn: np.ufunc
523
+ yv: np.ufunc
524
+ yve: np.ufunc
525
+ zetac: np.ufunc
526
+
openflamingo/lib/python3.10/site-packages/scipy/special/_ufuncs_cxx.pyx ADDED
@@ -0,0 +1,181 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # This file is automatically generated by _generate_pyx.py.
2
+ # Do not edit manually!
3
+
4
+ from libc.math cimport NAN
5
+
6
+ include "_ufuncs_extra_code_common.pxi"
7
+
8
+ cdef extern from r"_ufuncs_cxx_defs.h":
9
+ cdef double complex _func_ccospi "ccospi"(double complex) noexcept nogil
10
+ cdef void *_export_ccospi = <void*>_func_ccospi
11
+ cdef extern from r"_ufuncs_cxx_defs.h":
12
+ cdef double complex _func_lambertw_scalar "lambertw_scalar"(double complex, long, double) noexcept nogil
13
+ cdef void *_export_lambertw_scalar = <void*>_func_lambertw_scalar
14
+ cdef extern from r"_ufuncs_cxx_defs.h":
15
+ cdef double complex _func_csinpi "csinpi"(double complex) noexcept nogil
16
+ cdef void *_export_csinpi = <void*>_func_csinpi
17
+ cdef extern from r"_ufuncs_cxx_defs.h":
18
+ cdef double _func__stirling2_inexact "_stirling2_inexact"(double, double) noexcept nogil
19
+ cdef void *_export__stirling2_inexact = <void*>_func__stirling2_inexact
20
+ cdef extern from r"_ufuncs_cxx_defs.h":
21
+ cdef float _func_ibeta_float "ibeta_float"(float, float, float) noexcept nogil
22
+ cdef void *_export_ibeta_float = <void*>_func_ibeta_float
23
+ cdef extern from r"_ufuncs_cxx_defs.h":
24
+ cdef double _func_ibeta_double "ibeta_double"(double, double, double) noexcept nogil
25
+ cdef void *_export_ibeta_double = <void*>_func_ibeta_double
26
+ cdef extern from r"_ufuncs_cxx_defs.h":
27
+ cdef float _func_ibetac_float "ibetac_float"(float, float, float) noexcept nogil
28
+ cdef void *_export_ibetac_float = <void*>_func_ibetac_float
29
+ cdef extern from r"_ufuncs_cxx_defs.h":
30
+ cdef double _func_ibetac_double "ibetac_double"(double, double, double) noexcept nogil
31
+ cdef void *_export_ibetac_double = <void*>_func_ibetac_double
32
+ cdef extern from r"_ufuncs_cxx_defs.h":
33
+ cdef float _func_ibetac_inv_float "ibetac_inv_float"(float, float, float) noexcept nogil
34
+ cdef void *_export_ibetac_inv_float = <void*>_func_ibetac_inv_float
35
+ cdef extern from r"_ufuncs_cxx_defs.h":
36
+ cdef double _func_ibetac_inv_double "ibetac_inv_double"(double, double, double) noexcept nogil
37
+ cdef void *_export_ibetac_inv_double = <void*>_func_ibetac_inv_double
38
+ cdef extern from r"_ufuncs_cxx_defs.h":
39
+ cdef float _func_ibeta_inv_float "ibeta_inv_float"(float, float, float) noexcept nogil
40
+ cdef void *_export_ibeta_inv_float = <void*>_func_ibeta_inv_float
41
+ cdef extern from r"_ufuncs_cxx_defs.h":
42
+ cdef double _func_ibeta_inv_double "ibeta_inv_double"(double, double, double) noexcept nogil
43
+ cdef void *_export_ibeta_inv_double = <void*>_func_ibeta_inv_double
44
+ cdef extern from r"_ufuncs_cxx_defs.h":
45
+ cdef double _func_binom "binom"(double, double) noexcept nogil
46
+ cdef void *_export_binom = <void*>_func_binom
47
+ cdef extern from r"_ufuncs_cxx_defs.h":
48
+ cdef double _func_faddeeva_dawsn "faddeeva_dawsn"(double) noexcept nogil
49
+ cdef void *_export_faddeeva_dawsn = <void*>_func_faddeeva_dawsn
50
+ cdef extern from r"_ufuncs_cxx_defs.h":
51
+ cdef double complex _func_faddeeva_dawsn_complex "faddeeva_dawsn_complex"(double complex) noexcept nogil
52
+ cdef void *_export_faddeeva_dawsn_complex = <void*>_func_faddeeva_dawsn_complex
53
+ cdef extern from r"_ufuncs_cxx_defs.h":
54
+ cdef double _func_fellint_RC "fellint_RC"(double, double) noexcept nogil
55
+ cdef void *_export_fellint_RC = <void*>_func_fellint_RC
56
+ cdef extern from r"_ufuncs_cxx_defs.h":
57
+ cdef double complex _func_cellint_RC "cellint_RC"(double complex, double complex) noexcept nogil
58
+ cdef void *_export_cellint_RC = <void*>_func_cellint_RC
59
+ cdef extern from r"_ufuncs_cxx_defs.h":
60
+ cdef double _func_fellint_RD "fellint_RD"(double, double, double) noexcept nogil
61
+ cdef void *_export_fellint_RD = <void*>_func_fellint_RD
62
+ cdef extern from r"_ufuncs_cxx_defs.h":
63
+ cdef double complex _func_cellint_RD "cellint_RD"(double complex, double complex, double complex) noexcept nogil
64
+ cdef void *_export_cellint_RD = <void*>_func_cellint_RD
65
+ cdef extern from r"_ufuncs_cxx_defs.h":
66
+ cdef double _func_fellint_RF "fellint_RF"(double, double, double) noexcept nogil
67
+ cdef void *_export_fellint_RF = <void*>_func_fellint_RF
68
+ cdef extern from r"_ufuncs_cxx_defs.h":
69
+ cdef double complex _func_cellint_RF "cellint_RF"(double complex, double complex, double complex) noexcept nogil
70
+ cdef void *_export_cellint_RF = <void*>_func_cellint_RF
71
+ cdef extern from r"_ufuncs_cxx_defs.h":
72
+ cdef double _func_fellint_RG "fellint_RG"(double, double, double) noexcept nogil
73
+ cdef void *_export_fellint_RG = <void*>_func_fellint_RG
74
+ cdef extern from r"_ufuncs_cxx_defs.h":
75
+ cdef double complex _func_cellint_RG "cellint_RG"(double complex, double complex, double complex) noexcept nogil
76
+ cdef void *_export_cellint_RG = <void*>_func_cellint_RG
77
+ cdef extern from r"_ufuncs_cxx_defs.h":
78
+ cdef double _func_fellint_RJ "fellint_RJ"(double, double, double, double) noexcept nogil
79
+ cdef void *_export_fellint_RJ = <void*>_func_fellint_RJ
80
+ cdef extern from r"_ufuncs_cxx_defs.h":
81
+ cdef double complex _func_cellint_RJ "cellint_RJ"(double complex, double complex, double complex, double complex) noexcept nogil
82
+ cdef void *_export_cellint_RJ = <void*>_func_cellint_RJ
83
+ cdef extern from r"_ufuncs_cxx_defs.h":
84
+ cdef double complex _func_faddeeva_erf "faddeeva_erf"(double complex) noexcept nogil
85
+ cdef void *_export_faddeeva_erf = <void*>_func_faddeeva_erf
86
+ cdef extern from r"_ufuncs_cxx_defs.h":
87
+ cdef double complex _func_faddeeva_erfc_complex "faddeeva_erfc_complex"(double complex) noexcept nogil
88
+ cdef void *_export_faddeeva_erfc_complex = <void*>_func_faddeeva_erfc_complex
89
+ cdef extern from r"_ufuncs_cxx_defs.h":
90
+ cdef double _func_faddeeva_erfcx "faddeeva_erfcx"(double) noexcept nogil
91
+ cdef void *_export_faddeeva_erfcx = <void*>_func_faddeeva_erfcx
92
+ cdef extern from r"_ufuncs_cxx_defs.h":
93
+ cdef double complex _func_faddeeva_erfcx_complex "faddeeva_erfcx_complex"(double complex) noexcept nogil
94
+ cdef void *_export_faddeeva_erfcx_complex = <void*>_func_faddeeva_erfcx_complex
95
+ cdef extern from r"_ufuncs_cxx_defs.h":
96
+ cdef double _func_faddeeva_erfi "faddeeva_erfi"(double) noexcept nogil
97
+ cdef void *_export_faddeeva_erfi = <void*>_func_faddeeva_erfi
98
+ cdef extern from r"_ufuncs_cxx_defs.h":
99
+ cdef double complex _func_faddeeva_erfi_complex "faddeeva_erfi_complex"(double complex) noexcept nogil
100
+ cdef void *_export_faddeeva_erfi_complex = <void*>_func_faddeeva_erfi_complex
101
+ cdef extern from r"_ufuncs_cxx_defs.h":
102
+ cdef float _func_erfinv_float "erfinv_float"(float) noexcept nogil
103
+ cdef void *_export_erfinv_float = <void*>_func_erfinv_float
104
+ cdef extern from r"_ufuncs_cxx_defs.h":
105
+ cdef double _func_erfinv_double "erfinv_double"(double) noexcept nogil
106
+ cdef void *_export_erfinv_double = <void*>_func_erfinv_double
107
+ cdef extern from r"_ufuncs_cxx_defs.h":
108
+ cdef double _func_expit "expit"(double) noexcept nogil
109
+ cdef void *_export_expit = <void*>_func_expit
110
+ cdef extern from r"_ufuncs_cxx_defs.h":
111
+ cdef float _func_expitf "expitf"(float) noexcept nogil
112
+ cdef void *_export_expitf = <void*>_func_expitf
113
+ cdef extern from r"_ufuncs_cxx_defs.h":
114
+ cdef long double _func_expitl "expitl"(long double) noexcept nogil
115
+ cdef void *_export_expitl = <void*>_func_expitl
116
+ cdef extern from r"_ufuncs_cxx_defs.h":
117
+ cdef double complex _func_cgamma "cgamma"(double complex) noexcept nogil
118
+ cdef void *_export_cgamma = <void*>_func_cgamma
119
+ cdef extern from r"_ufuncs_cxx_defs.h":
120
+ cdef double _func_hyp1f1_double "hyp1f1_double"(double, double, double) noexcept nogil
121
+ cdef void *_export_hyp1f1_double = <void*>_func_hyp1f1_double
122
+ cdef extern from r"_ufuncs_cxx_defs.h":
123
+ cdef double _func_log_expit "log_expit"(double) noexcept nogil
124
+ cdef void *_export_log_expit = <void*>_func_log_expit
125
+ cdef extern from r"_ufuncs_cxx_defs.h":
126
+ cdef float _func_log_expitf "log_expitf"(float) noexcept nogil
127
+ cdef void *_export_log_expitf = <void*>_func_log_expitf
128
+ cdef extern from r"_ufuncs_cxx_defs.h":
129
+ cdef long double _func_log_expitl "log_expitl"(long double) noexcept nogil
130
+ cdef void *_export_log_expitl = <void*>_func_log_expitl
131
+ cdef extern from r"_ufuncs_cxx_defs.h":
132
+ cdef double _func_faddeeva_log_ndtr "faddeeva_log_ndtr"(double) noexcept nogil
133
+ cdef void *_export_faddeeva_log_ndtr = <void*>_func_faddeeva_log_ndtr
134
+ cdef extern from r"_ufuncs_cxx_defs.h":
135
+ cdef double complex _func_faddeeva_log_ndtr_complex "faddeeva_log_ndtr_complex"(double complex) noexcept nogil
136
+ cdef void *_export_faddeeva_log_ndtr_complex = <void*>_func_faddeeva_log_ndtr_complex
137
+ cdef extern from r"_ufuncs_cxx_defs.h":
138
+ cdef double _func_loggamma_real "loggamma_real"(double) noexcept nogil
139
+ cdef void *_export_loggamma_real = <void*>_func_loggamma_real
140
+ cdef extern from r"_ufuncs_cxx_defs.h":
141
+ cdef double complex _func_loggamma "loggamma"(double complex) noexcept nogil
142
+ cdef void *_export_loggamma = <void*>_func_loggamma
143
+ cdef extern from r"_ufuncs_cxx_defs.h":
144
+ cdef double _func_logit "logit"(double) noexcept nogil
145
+ cdef void *_export_logit = <void*>_func_logit
146
+ cdef extern from r"_ufuncs_cxx_defs.h":
147
+ cdef float _func_logitf "logitf"(float) noexcept nogil
148
+ cdef void *_export_logitf = <void*>_func_logitf
149
+ cdef extern from r"_ufuncs_cxx_defs.h":
150
+ cdef long double _func_logitl "logitl"(long double) noexcept nogil
151
+ cdef void *_export_logitl = <void*>_func_logitl
152
+ cdef extern from r"_ufuncs_cxx_defs.h":
153
+ cdef double complex _func_faddeeva_ndtr "faddeeva_ndtr"(double complex) noexcept nogil
154
+ cdef void *_export_faddeeva_ndtr = <void*>_func_faddeeva_ndtr
155
+ cdef extern from r"_ufuncs_cxx_defs.h":
156
+ cdef float _func_powm1_float "powm1_float"(float, float) noexcept nogil
157
+ cdef void *_export_powm1_float = <void*>_func_powm1_float
158
+ cdef extern from r"_ufuncs_cxx_defs.h":
159
+ cdef double _func_powm1_double "powm1_double"(double, double) noexcept nogil
160
+ cdef void *_export_powm1_double = <void*>_func_powm1_double
161
+ cdef extern from r"_ufuncs_cxx_defs.h":
162
+ cdef double complex _func_cdigamma "cdigamma"(double complex) noexcept nogil
163
+ cdef void *_export_cdigamma = <void*>_func_cdigamma
164
+ cdef extern from r"_ufuncs_cxx_defs.h":
165
+ cdef double _func_digamma "digamma"(double) noexcept nogil
166
+ cdef void *_export_digamma = <void*>_func_digamma
167
+ cdef extern from r"_ufuncs_cxx_defs.h":
168
+ cdef double complex _func_crgamma "crgamma"(double complex) noexcept nogil
169
+ cdef void *_export_crgamma = <void*>_func_crgamma
170
+ cdef extern from r"_ufuncs_cxx_defs.h":
171
+ cdef double _func_faddeeva_voigt_profile "faddeeva_voigt_profile"(double, double, double) noexcept nogil
172
+ cdef void *_export_faddeeva_voigt_profile = <void*>_func_faddeeva_voigt_profile
173
+ cdef extern from r"_ufuncs_cxx_defs.h":
174
+ cdef double complex _func_faddeeva_w "faddeeva_w"(double complex) noexcept nogil
175
+ cdef void *_export_faddeeva_w = <void*>_func_faddeeva_w
176
+ cdef extern from r"_ufuncs_cxx_defs.h":
177
+ cdef double complex _func_wrightomega "wrightomega"(double complex) noexcept nogil
178
+ cdef void *_export_wrightomega = <void*>_func_wrightomega
179
+ cdef extern from r"_ufuncs_cxx_defs.h":
180
+ cdef double _func_wrightomega_real "wrightomega_real"(double) noexcept nogil
181
+ cdef void *_export_wrightomega_real = <void*>_func_wrightomega_real
openflamingo/lib/python3.10/site-packages/scipy/special/_ufuncs_defs.h ADDED
@@ -0,0 +1,185 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #ifndef UFUNCS_PROTO_H
2
+ #define UFUNCS_PROTO_H 1
3
+ #include "_cosine.h"
4
+ npy_double cosine_cdf(npy_double);
5
+ npy_double cosine_invcdf(npy_double);
6
+ #include "cephes.h"
7
+ npy_double cospi(npy_double);
8
+ npy_double igam_fac(npy_double, npy_double);
9
+ npy_double kolmogc(npy_double);
10
+ npy_double kolmogci(npy_double);
11
+ npy_double kolmogp(npy_double);
12
+ npy_double lanczos_sum_expg_scaled(npy_double);
13
+ npy_double lgam1p(npy_double);
14
+ npy_double log1pmx(npy_double);
15
+ npy_double riemann_zeta(npy_double);
16
+ #include "scaled_exp1.h"
17
+ npy_double scaled_exp1(npy_double);
18
+ npy_double sinpi(npy_double);
19
+ npy_double smirnovc(npy_int, npy_double);
20
+ npy_double smirnovci(npy_int, npy_double);
21
+ npy_double smirnovp(npy_int, npy_double);
22
+ npy_double struve_asymp_large_z(npy_double, npy_double, npy_int, npy_double *);
23
+ npy_double struve_bessel_series(npy_double, npy_double, npy_int, npy_double *);
24
+ npy_double struve_power_series(npy_double, npy_double, npy_int, npy_double *);
25
+ npy_double zeta(npy_double, npy_double);
26
+ #include "amos_wrappers.h"
27
+ npy_int airy_wrap(npy_double, npy_double *, npy_double *, npy_double *, npy_double *);
28
+ npy_int cairy_wrap(npy_cdouble, npy_cdouble *, npy_cdouble *, npy_cdouble *, npy_cdouble *);
29
+ npy_int cairy_wrap_e(npy_cdouble, npy_cdouble *, npy_cdouble *, npy_cdouble *, npy_cdouble *);
30
+ npy_int cairy_wrap_e_real(npy_double, npy_double *, npy_double *, npy_double *, npy_double *);
31
+ npy_double bdtr(npy_double, npy_int, npy_double);
32
+ npy_double bdtrc(npy_double, npy_int, npy_double);
33
+ npy_double bdtri(npy_double, npy_int, npy_double);
34
+ #include "specfun_wrappers.h"
35
+ npy_double bei_wrap(npy_double);
36
+ npy_double beip_wrap(npy_double);
37
+ npy_double ber_wrap(npy_double);
38
+ npy_double berp_wrap(npy_double);
39
+ npy_double besselpoly(npy_double, npy_double, npy_double);
40
+ npy_double beta(npy_double, npy_double);
41
+ npy_double lbeta(npy_double, npy_double);
42
+ npy_double btdtr(npy_double, npy_double, npy_double);
43
+ npy_double incbi(npy_double, npy_double, npy_double);
44
+ npy_double cbrt(npy_double);
45
+ npy_double chdtr(npy_double, npy_double);
46
+ npy_double chdtrc(npy_double, npy_double);
47
+ npy_double chdtri(npy_double, npy_double);
48
+ npy_double cosdg(npy_double);
49
+ npy_double cosm1(npy_double);
50
+ npy_double cotdg(npy_double);
51
+ npy_double ellpe(npy_double);
52
+ npy_double ellie(npy_double, npy_double);
53
+ npy_int ellpj(npy_double, npy_double, npy_double *, npy_double *, npy_double *, npy_double *);
54
+ npy_double ellik(npy_double, npy_double);
55
+ npy_double ellpk(npy_double);
56
+ npy_double erf(npy_double);
57
+ npy_double erfc(npy_double);
58
+ npy_double erfcinv(npy_double);
59
+ npy_cdouble cexp1_wrap(npy_cdouble);
60
+ npy_double exp1_wrap(npy_double);
61
+ npy_double exp10(npy_double);
62
+ npy_double exp2(npy_double);
63
+ npy_cdouble cexpi_wrap(npy_cdouble);
64
+ npy_double expi_wrap(npy_double);
65
+ npy_double expm1(npy_double);
66
+ npy_double expn(npy_int, npy_double);
67
+ npy_double fdtr(npy_double, npy_double, npy_double);
68
+ npy_double fdtrc(npy_double, npy_double, npy_double);
69
+ npy_double fdtri(npy_double, npy_double, npy_double);
70
+ npy_int fresnl(npy_double, npy_double *, npy_double *);
71
+ npy_int cfresnl_wrap(npy_cdouble, npy_cdouble *, npy_cdouble *);
72
+ npy_double Gamma(npy_double);
73
+ npy_double igam(npy_double, npy_double);
74
+ npy_double igamc(npy_double, npy_double);
75
+ npy_double igamci(npy_double, npy_double);
76
+ npy_double igami(npy_double, npy_double);
77
+ npy_double lgam(npy_double);
78
+ npy_double gammasgn(npy_double);
79
+ npy_double gdtr(npy_double, npy_double, npy_double);
80
+ npy_double gdtrc(npy_double, npy_double, npy_double);
81
+ npy_cdouble cbesh_wrap1(npy_double, npy_cdouble);
82
+ npy_cdouble cbesh_wrap1_e(npy_double, npy_cdouble);
83
+ npy_cdouble cbesh_wrap2(npy_double, npy_cdouble);
84
+ npy_cdouble cbesh_wrap2_e(npy_double, npy_cdouble);
85
+ npy_cdouble chyp1f1_wrap(npy_double, npy_double, npy_cdouble);
86
+ npy_double hyp2f1(npy_double, npy_double, npy_double, npy_double);
87
+ npy_double i0(npy_double);
88
+ npy_double i0e(npy_double);
89
+ npy_double i1(npy_double);
90
+ npy_double i1e(npy_double);
91
+ npy_int it2i0k0_wrap(npy_double, npy_double *, npy_double *);
92
+ npy_int it2j0y0_wrap(npy_double, npy_double *, npy_double *);
93
+ npy_double it2struve0_wrap(npy_double);
94
+ npy_int itairy_wrap(npy_double, npy_double *, npy_double *, npy_double *, npy_double *);
95
+ npy_int it1i0k0_wrap(npy_double, npy_double *, npy_double *);
96
+ npy_int it1j0y0_wrap(npy_double, npy_double *, npy_double *);
97
+ npy_double itmodstruve0_wrap(npy_double);
98
+ npy_double itstruve0_wrap(npy_double);
99
+ npy_cdouble cbesi_wrap(npy_double, npy_cdouble);
100
+ npy_double iv(npy_double, npy_double);
101
+ npy_cdouble cbesi_wrap_e(npy_double, npy_cdouble);
102
+ npy_double cbesi_wrap_e_real(npy_double, npy_double);
103
+ npy_double j0(npy_double);
104
+ npy_double j1(npy_double);
105
+ npy_cdouble cbesj_wrap(npy_double, npy_cdouble);
106
+ npy_double cbesj_wrap_real(npy_double, npy_double);
107
+ npy_cdouble cbesj_wrap_e(npy_double, npy_cdouble);
108
+ npy_double cbesj_wrap_e_real(npy_double, npy_double);
109
+ npy_double k0(npy_double);
110
+ npy_double k0e(npy_double);
111
+ npy_double k1(npy_double);
112
+ npy_double k1e(npy_double);
113
+ npy_double kei_wrap(npy_double);
114
+ npy_double keip_wrap(npy_double);
115
+ npy_int kelvin_wrap(npy_double, npy_cdouble *, npy_cdouble *, npy_cdouble *, npy_cdouble *);
116
+ npy_double ker_wrap(npy_double);
117
+ npy_double kerp_wrap(npy_double);
118
+ npy_double cbesk_wrap_real_int(npy_int, npy_double);
119
+ npy_double kolmogi(npy_double);
120
+ npy_double kolmogorov(npy_double);
121
+ npy_cdouble cbesk_wrap(npy_double, npy_cdouble);
122
+ npy_double cbesk_wrap_real(npy_double, npy_double);
123
+ npy_cdouble cbesk_wrap_e(npy_double, npy_cdouble);
124
+ npy_double cbesk_wrap_e_real(npy_double, npy_double);
125
+ npy_double log1p(npy_double);
126
+ npy_double pmv_wrap(npy_double, npy_double, npy_double);
127
+ npy_double cem_cva_wrap(npy_double, npy_double);
128
+ npy_double sem_cva_wrap(npy_double, npy_double);
129
+ npy_int cem_wrap(npy_double, npy_double, npy_double, npy_double *, npy_double *);
130
+ npy_int mcm1_wrap(npy_double, npy_double, npy_double, npy_double *, npy_double *);
131
+ npy_int mcm2_wrap(npy_double, npy_double, npy_double, npy_double *, npy_double *);
132
+ npy_int msm1_wrap(npy_double, npy_double, npy_double, npy_double *, npy_double *);
133
+ npy_int msm2_wrap(npy_double, npy_double, npy_double, npy_double *, npy_double *);
134
+ npy_int sem_wrap(npy_double, npy_double, npy_double, npy_double *, npy_double *);
135
+ npy_int modified_fresnel_minus_wrap(npy_double, npy_cdouble *, npy_cdouble *);
136
+ npy_int modified_fresnel_plus_wrap(npy_double, npy_cdouble *, npy_cdouble *);
137
+ npy_double struve_l(npy_double, npy_double);
138
+ npy_double nbdtr(npy_int, npy_int, npy_double);
139
+ npy_double nbdtrc(npy_int, npy_int, npy_double);
140
+ npy_double nbdtri(npy_int, npy_int, npy_double);
141
+ npy_double ndtr(npy_double);
142
+ npy_double ndtri(npy_double);
143
+ npy_double oblate_aswfa_nocv_wrap(npy_double, npy_double, npy_double, npy_double, npy_double *);
144
+ npy_int oblate_aswfa_wrap(npy_double, npy_double, npy_double, npy_double, npy_double, npy_double *, npy_double *);
145
+ npy_double oblate_segv_wrap(npy_double, npy_double, npy_double);
146
+ npy_double oblate_radial1_nocv_wrap(npy_double, npy_double, npy_double, npy_double, npy_double *);
147
+ npy_int oblate_radial1_wrap(npy_double, npy_double, npy_double, npy_double, npy_double, npy_double *, npy_double *);
148
+ npy_double oblate_radial2_nocv_wrap(npy_double, npy_double, npy_double, npy_double, npy_double *);
149
+ npy_int oblate_radial2_wrap(npy_double, npy_double, npy_double, npy_double, npy_double, npy_double *, npy_double *);
150
+ npy_double owens_t(npy_double, npy_double);
151
+ npy_int pbdv_wrap(npy_double, npy_double, npy_double *, npy_double *);
152
+ npy_int pbvv_wrap(npy_double, npy_double, npy_double *, npy_double *);
153
+ npy_int pbwa_wrap(npy_double, npy_double, npy_double *, npy_double *);
154
+ npy_double pdtr(npy_double, npy_double);
155
+ npy_double pdtrc(npy_double, npy_double);
156
+ npy_double pdtri(npy_int, npy_double);
157
+ npy_double poch(npy_double, npy_double);
158
+ npy_double prolate_aswfa_nocv_wrap(npy_double, npy_double, npy_double, npy_double, npy_double *);
159
+ npy_int prolate_aswfa_wrap(npy_double, npy_double, npy_double, npy_double, npy_double, npy_double *, npy_double *);
160
+ npy_double prolate_segv_wrap(npy_double, npy_double, npy_double);
161
+ npy_double prolate_radial1_nocv_wrap(npy_double, npy_double, npy_double, npy_double, npy_double *);
162
+ npy_int prolate_radial1_wrap(npy_double, npy_double, npy_double, npy_double, npy_double, npy_double *, npy_double *);
163
+ npy_double prolate_radial2_nocv_wrap(npy_double, npy_double, npy_double, npy_double, npy_double *);
164
+ npy_int prolate_radial2_wrap(npy_double, npy_double, npy_double, npy_double, npy_double, npy_double *, npy_double *);
165
+ npy_double radian(npy_double, npy_double, npy_double);
166
+ npy_double rgamma(npy_double);
167
+ npy_double round(npy_double);
168
+ npy_int shichi(npy_double, npy_double *, npy_double *);
169
+ npy_int sici(npy_double, npy_double *, npy_double *);
170
+ npy_double sindg(npy_double);
171
+ npy_double smirnov(npy_int, npy_double);
172
+ npy_double smirnovi(npy_int, npy_double);
173
+ npy_double spence(npy_double);
174
+ npy_double struve_h(npy_double, npy_double);
175
+ npy_double tandg(npy_double);
176
+ npy_double tukeylambdacdf(npy_double, npy_double);
177
+ npy_double y0(npy_double);
178
+ npy_double y1(npy_double);
179
+ npy_double yn(npy_int, npy_double);
180
+ npy_cdouble cbesy_wrap(npy_double, npy_cdouble);
181
+ npy_double cbesy_wrap_real(npy_double, npy_double);
182
+ npy_cdouble cbesy_wrap_e(npy_double, npy_cdouble);
183
+ npy_double cbesy_wrap_e_real(npy_double, npy_double);
184
+ npy_double zetac(npy_double);
185
+ #endif
openflamingo/lib/python3.10/site-packages/scipy/special/cython_special.pyx ADDED
The diff for this file is too large to render. See raw diff
 
openflamingo/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_boxcox.cpython-310.pyc ADDED
Binary file (2.74 kB). View file
 
openflamingo/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_cdft_asymptotic.cpython-310.pyc ADDED
Binary file (1.33 kB). View file
 
openflamingo/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_faddeeva.cpython-310.pyc ADDED
Binary file (2.84 kB). View file
 
openflamingo/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_log_softmax.cpython-310.pyc ADDED
Binary file (2.79 kB). View file
 
openflamingo/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_logit.cpython-310.pyc ADDED
Binary file (4.57 kB). View file
 
openflamingo/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_logsumexp.cpython-310.pyc ADDED
Binary file (5.01 kB). View file
 
openflamingo/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_sici.cpython-310.pyc ADDED
Binary file (1.32 kB). View file
 
openflamingo/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_spfun_stats.cpython-310.pyc ADDED
Binary file (2.01 kB). View file
 
openflamingo/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_support_alternative_backends.cpython-310.pyc ADDED
Binary file (2.56 kB). View file
 
openflamingo/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_wright_bessel.cpython-310.pyc ADDED
Binary file (3.36 kB). View file
 
openflamingo/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_wrightomega.cpython-310.pyc ADDED
Binary file (3.2 kB). View file
 
openflamingo/lib/python3.10/site-packages/scipy/special/tests/test_basic.py ADDED
The diff for this file is too large to render. See raw diff
 
openflamingo/lib/python3.10/site-packages/scipy/special/tests/test_bdtr.py ADDED
@@ -0,0 +1,112 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import scipy.special as sc
3
+ import pytest
4
+ from numpy.testing import assert_allclose, assert_array_equal, suppress_warnings
5
+
6
+
7
+ class TestBdtr:
8
+ def test(self):
9
+ val = sc.bdtr(0, 1, 0.5)
10
+ assert_allclose(val, 0.5)
11
+
12
+ def test_sum_is_one(self):
13
+ val = sc.bdtr([0, 1, 2], 2, 0.5)
14
+ assert_array_equal(val, [0.25, 0.75, 1.0])
15
+
16
+ def test_rounding(self):
17
+ double_val = sc.bdtr([0.1, 1.1, 2.1], 2, 0.5)
18
+ int_val = sc.bdtr([0, 1, 2], 2, 0.5)
19
+ assert_array_equal(double_val, int_val)
20
+
21
+ @pytest.mark.parametrize('k, n, p', [
22
+ (np.inf, 2, 0.5),
23
+ (1.0, np.inf, 0.5),
24
+ (1.0, 2, np.inf)
25
+ ])
26
+ def test_inf(self, k, n, p):
27
+ with suppress_warnings() as sup:
28
+ sup.filter(DeprecationWarning)
29
+ val = sc.bdtr(k, n, p)
30
+ assert np.isnan(val)
31
+
32
+ def test_domain(self):
33
+ val = sc.bdtr(-1.1, 1, 0.5)
34
+ assert np.isnan(val)
35
+
36
+
37
+ class TestBdtrc:
38
+ def test_value(self):
39
+ val = sc.bdtrc(0, 1, 0.5)
40
+ assert_allclose(val, 0.5)
41
+
42
+ def test_sum_is_one(self):
43
+ val = sc.bdtrc([0, 1, 2], 2, 0.5)
44
+ assert_array_equal(val, [0.75, 0.25, 0.0])
45
+
46
+ def test_rounding(self):
47
+ double_val = sc.bdtrc([0.1, 1.1, 2.1], 2, 0.5)
48
+ int_val = sc.bdtrc([0, 1, 2], 2, 0.5)
49
+ assert_array_equal(double_val, int_val)
50
+
51
+ @pytest.mark.parametrize('k, n, p', [
52
+ (np.inf, 2, 0.5),
53
+ (1.0, np.inf, 0.5),
54
+ (1.0, 2, np.inf)
55
+ ])
56
+ def test_inf(self, k, n, p):
57
+ with suppress_warnings() as sup:
58
+ sup.filter(DeprecationWarning)
59
+ val = sc.bdtrc(k, n, p)
60
+ assert np.isnan(val)
61
+
62
+ def test_domain(self):
63
+ val = sc.bdtrc(-1.1, 1, 0.5)
64
+ val2 = sc.bdtrc(2.1, 1, 0.5)
65
+ assert np.isnan(val2)
66
+ assert_allclose(val, 1.0)
67
+
68
+ def test_bdtr_bdtrc_sum_to_one(self):
69
+ bdtr_vals = sc.bdtr([0, 1, 2], 2, 0.5)
70
+ bdtrc_vals = sc.bdtrc([0, 1, 2], 2, 0.5)
71
+ vals = bdtr_vals + bdtrc_vals
72
+ assert_allclose(vals, [1.0, 1.0, 1.0])
73
+
74
+
75
+ class TestBdtri:
76
+ def test_value(self):
77
+ val = sc.bdtri(0, 1, 0.5)
78
+ assert_allclose(val, 0.5)
79
+
80
+ def test_sum_is_one(self):
81
+ val = sc.bdtri([0, 1], 2, 0.5)
82
+ actual = np.asarray([1 - 1/np.sqrt(2), 1/np.sqrt(2)])
83
+ assert_allclose(val, actual)
84
+
85
+ def test_rounding(self):
86
+ double_val = sc.bdtri([0.1, 1.1], 2, 0.5)
87
+ int_val = sc.bdtri([0, 1], 2, 0.5)
88
+ assert_allclose(double_val, int_val)
89
+
90
+ @pytest.mark.parametrize('k, n, p', [
91
+ (np.inf, 2, 0.5),
92
+ (1.0, np.inf, 0.5),
93
+ (1.0, 2, np.inf)
94
+ ])
95
+ def test_inf(self, k, n, p):
96
+ with suppress_warnings() as sup:
97
+ sup.filter(DeprecationWarning)
98
+ val = sc.bdtri(k, n, p)
99
+ assert np.isnan(val)
100
+
101
+ @pytest.mark.parametrize('k, n, p', [
102
+ (-1.1, 1, 0.5),
103
+ (2.1, 1, 0.5)
104
+ ])
105
+ def test_domain(self, k, n, p):
106
+ val = sc.bdtri(k, n, p)
107
+ assert np.isnan(val)
108
+
109
+ def test_bdtr_bdtri_roundtrip(self):
110
+ bdtr_vals = sc.bdtr([0, 1, 2], 2, 0.5)
111
+ roundtrip_vals = sc.bdtri([0, 1, 2], 2, bdtr_vals)
112
+ assert_allclose(roundtrip_vals, [0.5, 0.5, np.nan])
openflamingo/lib/python3.10/site-packages/scipy/special/tests/test_boxcox.py ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ from numpy.testing import assert_equal, assert_almost_equal, assert_allclose
3
+ from scipy.special import boxcox, boxcox1p, inv_boxcox, inv_boxcox1p
4
+
5
+
6
+ # There are more tests of boxcox and boxcox1p in test_mpmath.py.
7
+
8
+ def test_boxcox_basic():
9
+ x = np.array([0.5, 1, 2, 4])
10
+
11
+ # lambda = 0 => y = log(x)
12
+ y = boxcox(x, 0)
13
+ assert_almost_equal(y, np.log(x))
14
+
15
+ # lambda = 1 => y = x - 1
16
+ y = boxcox(x, 1)
17
+ assert_almost_equal(y, x - 1)
18
+
19
+ # lambda = 2 => y = 0.5*(x**2 - 1)
20
+ y = boxcox(x, 2)
21
+ assert_almost_equal(y, 0.5*(x**2 - 1))
22
+
23
+ # x = 0 and lambda > 0 => y = -1 / lambda
24
+ lam = np.array([0.5, 1, 2])
25
+ y = boxcox(0, lam)
26
+ assert_almost_equal(y, -1.0 / lam)
27
+
28
+ def test_boxcox_underflow():
29
+ x = 1 + 1e-15
30
+ lmbda = 1e-306
31
+ y = boxcox(x, lmbda)
32
+ assert_allclose(y, np.log(x), rtol=1e-14)
33
+
34
+
35
+ def test_boxcox_nonfinite():
36
+ # x < 0 => y = nan
37
+ x = np.array([-1, -1, -0.5])
38
+ y = boxcox(x, [0.5, 2.0, -1.5])
39
+ assert_equal(y, np.array([np.nan, np.nan, np.nan]))
40
+
41
+ # x = 0 and lambda <= 0 => y = -inf
42
+ x = 0
43
+ y = boxcox(x, [-2.5, 0])
44
+ assert_equal(y, np.array([-np.inf, -np.inf]))
45
+
46
+
47
+ def test_boxcox1p_basic():
48
+ x = np.array([-0.25, -1e-20, 0, 1e-20, 0.25, 1, 3])
49
+
50
+ # lambda = 0 => y = log(1+x)
51
+ y = boxcox1p(x, 0)
52
+ assert_almost_equal(y, np.log1p(x))
53
+
54
+ # lambda = 1 => y = x
55
+ y = boxcox1p(x, 1)
56
+ assert_almost_equal(y, x)
57
+
58
+ # lambda = 2 => y = 0.5*((1+x)**2 - 1) = 0.5*x*(2 + x)
59
+ y = boxcox1p(x, 2)
60
+ assert_almost_equal(y, 0.5*x*(2 + x))
61
+
62
+ # x = -1 and lambda > 0 => y = -1 / lambda
63
+ lam = np.array([0.5, 1, 2])
64
+ y = boxcox1p(-1, lam)
65
+ assert_almost_equal(y, -1.0 / lam)
66
+
67
+
68
+ def test_boxcox1p_underflow():
69
+ x = np.array([1e-15, 1e-306])
70
+ lmbda = np.array([1e-306, 1e-18])
71
+ y = boxcox1p(x, lmbda)
72
+ assert_allclose(y, np.log1p(x), rtol=1e-14)
73
+
74
+
75
+ def test_boxcox1p_nonfinite():
76
+ # x < -1 => y = nan
77
+ x = np.array([-2, -2, -1.5])
78
+ y = boxcox1p(x, [0.5, 2.0, -1.5])
79
+ assert_equal(y, np.array([np.nan, np.nan, np.nan]))
80
+
81
+ # x = -1 and lambda <= 0 => y = -inf
82
+ x = -1
83
+ y = boxcox1p(x, [-2.5, 0])
84
+ assert_equal(y, np.array([-np.inf, -np.inf]))
85
+
86
+
87
+ def test_inv_boxcox():
88
+ x = np.array([0., 1., 2.])
89
+ lam = np.array([0., 1., 2.])
90
+ y = boxcox(x, lam)
91
+ x2 = inv_boxcox(y, lam)
92
+ assert_almost_equal(x, x2)
93
+
94
+ x = np.array([0., 1., 2.])
95
+ lam = np.array([0., 1., 2.])
96
+ y = boxcox1p(x, lam)
97
+ x2 = inv_boxcox1p(y, lam)
98
+ assert_almost_equal(x, x2)
99
+
100
+
101
+ def test_inv_boxcox1p_underflow():
102
+ x = 1e-15
103
+ lam = 1e-306
104
+ y = inv_boxcox1p(x, lam)
105
+ assert_allclose(y, x, rtol=1e-14)
106
+
openflamingo/lib/python3.10/site-packages/scipy/special/tests/test_cdflib.py ADDED
@@ -0,0 +1,527 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Test cdflib functions versus mpmath, if available.
3
+
4
+ The following functions still need tests:
5
+
6
+ - ncfdtr
7
+ - ncfdtri
8
+ - ncfdtridfn
9
+ - ncfdtridfd
10
+ - ncfdtrinc
11
+ - nbdtrik
12
+ - nbdtrin
13
+ - pdtrik
14
+ - nctdtr
15
+ - nctdtrit
16
+ - nctdtridf
17
+ - nctdtrinc
18
+
19
+ """
20
+ import itertools
21
+
22
+ import numpy as np
23
+ from numpy.testing import assert_equal, assert_allclose
24
+ import pytest
25
+
26
+ import scipy.special as sp
27
+ from scipy.special._testutils import (
28
+ MissingModule, check_version, FuncData)
29
+ from scipy.special._mptestutils import (
30
+ Arg, IntArg, get_args, mpf2float, assert_mpmath_equal)
31
+
32
+ try:
33
+ import mpmath
34
+ except ImportError:
35
+ mpmath = MissingModule('mpmath')
36
+
37
+
38
+ class ProbArg:
39
+ """Generate a set of probabilities on [0, 1]."""
40
+
41
+ def __init__(self):
42
+ # Include the endpoints for compatibility with Arg et. al.
43
+ self.a = 0
44
+ self.b = 1
45
+
46
+ def values(self, n):
47
+ """Return an array containing approximately n numbers."""
48
+ m = max(1, n//3)
49
+ v1 = np.logspace(-30, np.log10(0.3), m)
50
+ v2 = np.linspace(0.3, 0.7, m + 1, endpoint=False)[1:]
51
+ v3 = 1 - np.logspace(np.log10(0.3), -15, m)
52
+ v = np.r_[v1, v2, v3]
53
+ return np.unique(v)
54
+
55
+
56
+ class EndpointFilter:
57
+ def __init__(self, a, b, rtol, atol):
58
+ self.a = a
59
+ self.b = b
60
+ self.rtol = rtol
61
+ self.atol = atol
62
+
63
+ def __call__(self, x):
64
+ mask1 = np.abs(x - self.a) < self.rtol*np.abs(self.a) + self.atol
65
+ mask2 = np.abs(x - self.b) < self.rtol*np.abs(self.b) + self.atol
66
+ return np.where(mask1 | mask2, False, True)
67
+
68
+
69
+ class _CDFData:
70
+ def __init__(self, spfunc, mpfunc, index, argspec, spfunc_first=True,
71
+ dps=20, n=5000, rtol=None, atol=None,
72
+ endpt_rtol=None, endpt_atol=None):
73
+ self.spfunc = spfunc
74
+ self.mpfunc = mpfunc
75
+ self.index = index
76
+ self.argspec = argspec
77
+ self.spfunc_first = spfunc_first
78
+ self.dps = dps
79
+ self.n = n
80
+ self.rtol = rtol
81
+ self.atol = atol
82
+
83
+ if not isinstance(argspec, list):
84
+ self.endpt_rtol = None
85
+ self.endpt_atol = None
86
+ elif endpt_rtol is not None or endpt_atol is not None:
87
+ if isinstance(endpt_rtol, list):
88
+ self.endpt_rtol = endpt_rtol
89
+ else:
90
+ self.endpt_rtol = [endpt_rtol]*len(self.argspec)
91
+ if isinstance(endpt_atol, list):
92
+ self.endpt_atol = endpt_atol
93
+ else:
94
+ self.endpt_atol = [endpt_atol]*len(self.argspec)
95
+ else:
96
+ self.endpt_rtol = None
97
+ self.endpt_atol = None
98
+
99
+ def idmap(self, *args):
100
+ if self.spfunc_first:
101
+ res = self.spfunc(*args)
102
+ if np.isnan(res):
103
+ return np.nan
104
+ args = list(args)
105
+ args[self.index] = res
106
+ with mpmath.workdps(self.dps):
107
+ res = self.mpfunc(*tuple(args))
108
+ # Imaginary parts are spurious
109
+ res = mpf2float(res.real)
110
+ else:
111
+ with mpmath.workdps(self.dps):
112
+ res = self.mpfunc(*args)
113
+ res = mpf2float(res.real)
114
+ args = list(args)
115
+ args[self.index] = res
116
+ res = self.spfunc(*tuple(args))
117
+ return res
118
+
119
+ def get_param_filter(self):
120
+ if self.endpt_rtol is None and self.endpt_atol is None:
121
+ return None
122
+
123
+ filters = []
124
+ for rtol, atol, spec in zip(self.endpt_rtol, self.endpt_atol, self.argspec):
125
+ if rtol is None and atol is None:
126
+ filters.append(None)
127
+ continue
128
+ elif rtol is None:
129
+ rtol = 0.0
130
+ elif atol is None:
131
+ atol = 0.0
132
+
133
+ filters.append(EndpointFilter(spec.a, spec.b, rtol, atol))
134
+ return filters
135
+
136
+ def check(self):
137
+ # Generate values for the arguments
138
+ args = get_args(self.argspec, self.n)
139
+ param_filter = self.get_param_filter()
140
+ param_columns = tuple(range(args.shape[1]))
141
+ result_columns = args.shape[1]
142
+ args = np.hstack((args, args[:, self.index].reshape(args.shape[0], 1)))
143
+ FuncData(self.idmap, args,
144
+ param_columns=param_columns, result_columns=result_columns,
145
+ rtol=self.rtol, atol=self.atol, vectorized=False,
146
+ param_filter=param_filter).check()
147
+
148
+
149
+ def _assert_inverts(*a, **kw):
150
+ d = _CDFData(*a, **kw)
151
+ d.check()
152
+
153
+
154
+ def _binomial_cdf(k, n, p):
155
+ k, n, p = mpmath.mpf(k), mpmath.mpf(n), mpmath.mpf(p)
156
+ if k <= 0:
157
+ return mpmath.mpf(0)
158
+ elif k >= n:
159
+ return mpmath.mpf(1)
160
+
161
+ onemp = mpmath.fsub(1, p, exact=True)
162
+ return mpmath.betainc(n - k, k + 1, x2=onemp, regularized=True)
163
+
164
+
165
+ def _f_cdf(dfn, dfd, x):
166
+ if x < 0:
167
+ return mpmath.mpf(0)
168
+ dfn, dfd, x = mpmath.mpf(dfn), mpmath.mpf(dfd), mpmath.mpf(x)
169
+ ub = dfn*x/(dfn*x + dfd)
170
+ res = mpmath.betainc(dfn/2, dfd/2, x2=ub, regularized=True)
171
+ return res
172
+
173
+
174
+ def _student_t_cdf(df, t, dps=None):
175
+ if dps is None:
176
+ dps = mpmath.mp.dps
177
+ with mpmath.workdps(dps):
178
+ df, t = mpmath.mpf(df), mpmath.mpf(t)
179
+ fac = mpmath.hyp2f1(0.5, 0.5*(df + 1), 1.5, -t**2/df)
180
+ fac *= t*mpmath.gamma(0.5*(df + 1))
181
+ fac /= mpmath.sqrt(mpmath.pi*df)*mpmath.gamma(0.5*df)
182
+ return 0.5 + fac
183
+
184
+
185
+ def _noncentral_chi_pdf(t, df, nc):
186
+ res = mpmath.besseli(df/2 - 1, mpmath.sqrt(nc*t))
187
+ res *= mpmath.exp(-(t + nc)/2)*(t/nc)**(df/4 - 1/2)/2
188
+ return res
189
+
190
+
191
+ def _noncentral_chi_cdf(x, df, nc, dps=None):
192
+ if dps is None:
193
+ dps = mpmath.mp.dps
194
+ x, df, nc = mpmath.mpf(x), mpmath.mpf(df), mpmath.mpf(nc)
195
+ with mpmath.workdps(dps):
196
+ res = mpmath.quad(lambda t: _noncentral_chi_pdf(t, df, nc), [0, x])
197
+ return res
198
+
199
+
200
+ def _tukey_lmbda_quantile(p, lmbda):
201
+ # For lmbda != 0
202
+ return (p**lmbda - (1 - p)**lmbda)/lmbda
203
+
204
+
205
+ @pytest.mark.slow
206
+ @check_version(mpmath, '0.19')
207
+ class TestCDFlib:
208
+
209
+ @pytest.mark.xfail(run=False)
210
+ def test_bdtrik(self):
211
+ _assert_inverts(
212
+ sp.bdtrik,
213
+ _binomial_cdf,
214
+ 0, [ProbArg(), IntArg(1, 1000), ProbArg()],
215
+ rtol=1e-4)
216
+
217
+ def test_bdtrin(self):
218
+ _assert_inverts(
219
+ sp.bdtrin,
220
+ _binomial_cdf,
221
+ 1, [IntArg(1, 1000), ProbArg(), ProbArg()],
222
+ rtol=1e-4, endpt_atol=[None, None, 1e-6])
223
+
224
+ def test_btdtria(self):
225
+ _assert_inverts(
226
+ sp.btdtria,
227
+ lambda a, b, x: mpmath.betainc(a, b, x2=x, regularized=True),
228
+ 0, [ProbArg(), Arg(0, 1e2, inclusive_a=False),
229
+ Arg(0, 1, inclusive_a=False, inclusive_b=False)],
230
+ rtol=1e-6)
231
+
232
+ def test_btdtrib(self):
233
+ # Use small values of a or mpmath doesn't converge
234
+ _assert_inverts(
235
+ sp.btdtrib,
236
+ lambda a, b, x: mpmath.betainc(a, b, x2=x, regularized=True),
237
+ 1,
238
+ [Arg(0, 1e2, inclusive_a=False), ProbArg(),
239
+ Arg(0, 1, inclusive_a=False, inclusive_b=False)],
240
+ rtol=1e-7,
241
+ endpt_atol=[None, 1e-18, 1e-15])
242
+
243
+ @pytest.mark.xfail(run=False)
244
+ def test_fdtridfd(self):
245
+ _assert_inverts(
246
+ sp.fdtridfd,
247
+ _f_cdf,
248
+ 1,
249
+ [IntArg(1, 100), ProbArg(), Arg(0, 100, inclusive_a=False)],
250
+ rtol=1e-7)
251
+
252
+ def test_gdtria(self):
253
+ _assert_inverts(
254
+ sp.gdtria,
255
+ lambda a, b, x: mpmath.gammainc(b, b=a*x, regularized=True),
256
+ 0,
257
+ [ProbArg(), Arg(0, 1e3, inclusive_a=False),
258
+ Arg(0, 1e4, inclusive_a=False)],
259
+ rtol=1e-7,
260
+ endpt_atol=[None, 1e-7, 1e-10])
261
+
262
+ def test_gdtrib(self):
263
+ # Use small values of a and x or mpmath doesn't converge
264
+ _assert_inverts(
265
+ sp.gdtrib,
266
+ lambda a, b, x: mpmath.gammainc(b, b=a*x, regularized=True),
267
+ 1,
268
+ [Arg(0, 1e2, inclusive_a=False), ProbArg(),
269
+ Arg(0, 1e3, inclusive_a=False)],
270
+ rtol=1e-5)
271
+
272
+ def test_gdtrix(self):
273
+ _assert_inverts(
274
+ sp.gdtrix,
275
+ lambda a, b, x: mpmath.gammainc(b, b=a*x, regularized=True),
276
+ 2,
277
+ [Arg(0, 1e3, inclusive_a=False), Arg(0, 1e3, inclusive_a=False),
278
+ ProbArg()],
279
+ rtol=1e-7,
280
+ endpt_atol=[None, 1e-7, 1e-10])
281
+
282
+ # Overall nrdtrimn and nrdtrisd are not performing well with infeasible/edge
283
+ # combinations of sigma and x, hence restricted the domains to still use the
284
+ # testing machinery, also see gh-20069
285
+
286
+ # nrdtrimn signature: p, sd, x
287
+ # nrdtrisd signature: mn, p, x
288
+ def test_nrdtrimn(self):
289
+ _assert_inverts(
290
+ sp.nrdtrimn,
291
+ lambda x, y, z: mpmath.ncdf(z, x, y),
292
+ 0,
293
+ [ProbArg(), # CDF value p
294
+ Arg(0.1, np.inf, inclusive_a=False, inclusive_b=False), # sigma
295
+ Arg(-1e10, 1e10)], # x
296
+ rtol=1e-5)
297
+
298
+ def test_nrdtrisd(self):
299
+ _assert_inverts(
300
+ sp.nrdtrisd,
301
+ lambda x, y, z: mpmath.ncdf(z, x, y),
302
+ 1,
303
+ [Arg(-np.inf, 10, inclusive_a=False, inclusive_b=False), # mn
304
+ ProbArg(), # CDF value p
305
+ Arg(10, 1e100)], # x
306
+ rtol=1e-5)
307
+
308
+ def test_stdtr(self):
309
+ # Ideally the left endpoint for Arg() should be 0.
310
+ assert_mpmath_equal(
311
+ sp.stdtr,
312
+ _student_t_cdf,
313
+ [IntArg(1, 100), Arg(1e-10, np.inf)], rtol=1e-7)
314
+
315
+ @pytest.mark.xfail(run=False)
316
+ def test_stdtridf(self):
317
+ _assert_inverts(
318
+ sp.stdtridf,
319
+ _student_t_cdf,
320
+ 0, [ProbArg(), Arg()], rtol=1e-7)
321
+
322
+ def test_stdtrit(self):
323
+ _assert_inverts(
324
+ sp.stdtrit,
325
+ _student_t_cdf,
326
+ 1, [IntArg(1, 100), ProbArg()], rtol=1e-7,
327
+ endpt_atol=[None, 1e-10])
328
+
329
+ def test_chdtriv(self):
330
+ _assert_inverts(
331
+ sp.chdtriv,
332
+ lambda v, x: mpmath.gammainc(v/2, b=x/2, regularized=True),
333
+ 0, [ProbArg(), IntArg(1, 100)], rtol=1e-4)
334
+
335
+ @pytest.mark.xfail(run=False)
336
+ def test_chndtridf(self):
337
+ # Use a larger atol since mpmath is doing numerical integration
338
+ _assert_inverts(
339
+ sp.chndtridf,
340
+ _noncentral_chi_cdf,
341
+ 1, [Arg(0, 100, inclusive_a=False), ProbArg(),
342
+ Arg(0, 100, inclusive_a=False)],
343
+ n=1000, rtol=1e-4, atol=1e-15)
344
+
345
+ @pytest.mark.xfail(run=False)
346
+ def test_chndtrinc(self):
347
+ # Use a larger atol since mpmath is doing numerical integration
348
+ _assert_inverts(
349
+ sp.chndtrinc,
350
+ _noncentral_chi_cdf,
351
+ 2, [Arg(0, 100, inclusive_a=False), IntArg(1, 100), ProbArg()],
352
+ n=1000, rtol=1e-4, atol=1e-15)
353
+
354
+ def test_chndtrix(self):
355
+ # Use a larger atol since mpmath is doing numerical integration
356
+ _assert_inverts(
357
+ sp.chndtrix,
358
+ _noncentral_chi_cdf,
359
+ 0, [ProbArg(), IntArg(1, 100), Arg(0, 100, inclusive_a=False)],
360
+ n=1000, rtol=1e-4, atol=1e-15,
361
+ endpt_atol=[1e-6, None, None])
362
+
363
+ def test_tklmbda_zero_shape(self):
364
+ # When lmbda = 0 the CDF has a simple closed form
365
+ one = mpmath.mpf(1)
366
+ assert_mpmath_equal(
367
+ lambda x: sp.tklmbda(x, 0),
368
+ lambda x: one/(mpmath.exp(-x) + one),
369
+ [Arg()], rtol=1e-7)
370
+
371
+ def test_tklmbda_neg_shape(self):
372
+ _assert_inverts(
373
+ sp.tklmbda,
374
+ _tukey_lmbda_quantile,
375
+ 0, [ProbArg(), Arg(-25, 0, inclusive_b=False)],
376
+ spfunc_first=False, rtol=1e-5,
377
+ endpt_atol=[1e-9, 1e-5])
378
+
379
+ @pytest.mark.xfail(run=False)
380
+ def test_tklmbda_pos_shape(self):
381
+ _assert_inverts(
382
+ sp.tklmbda,
383
+ _tukey_lmbda_quantile,
384
+ 0, [ProbArg(), Arg(0, 100, inclusive_a=False)],
385
+ spfunc_first=False, rtol=1e-5)
386
+
387
+ # The values of lmdba are chosen so that 1/lmbda is exact.
388
+ @pytest.mark.parametrize('lmbda', [0.5, 1.0, 8.0])
389
+ def test_tklmbda_lmbda1(self, lmbda):
390
+ bound = 1/lmbda
391
+ assert_equal(sp.tklmbda([-bound, bound], lmbda), [0.0, 1.0])
392
+
393
+
394
+ funcs = [
395
+ ("btdtria", 3),
396
+ ("btdtrib", 3),
397
+ ("bdtrik", 3),
398
+ ("bdtrin", 3),
399
+ ("chdtriv", 2),
400
+ ("chndtr", 3),
401
+ ("chndtrix", 3),
402
+ ("chndtridf", 3),
403
+ ("chndtrinc", 3),
404
+ ("fdtridfd", 3),
405
+ ("ncfdtr", 4),
406
+ ("ncfdtri", 4),
407
+ ("ncfdtridfn", 4),
408
+ ("ncfdtridfd", 4),
409
+ ("ncfdtrinc", 4),
410
+ ("gdtrix", 3),
411
+ ("gdtrib", 3),
412
+ ("gdtria", 3),
413
+ ("nbdtrik", 3),
414
+ ("nbdtrin", 3),
415
+ ("nrdtrimn", 3),
416
+ ("nrdtrisd", 3),
417
+ ("pdtrik", 2),
418
+ ("stdtr", 2),
419
+ ("stdtrit", 2),
420
+ ("stdtridf", 2),
421
+ ("nctdtr", 3),
422
+ ("nctdtrit", 3),
423
+ ("nctdtridf", 3),
424
+ ("nctdtrinc", 3),
425
+ ("tklmbda", 2),
426
+ ]
427
+
428
+
429
+ @pytest.mark.parametrize('func,numargs', funcs, ids=[x[0] for x in funcs])
430
+ def test_nonfinite(func, numargs):
431
+
432
+ rng = np.random.default_rng(1701299355559735)
433
+ func = getattr(sp, func)
434
+ args_choices = [(float(x), np.nan, np.inf, -np.inf) for x in rng.random(numargs)]
435
+
436
+ for args in itertools.product(*args_choices):
437
+ res = func(*args)
438
+
439
+ if any(np.isnan(x) for x in args):
440
+ # Nan inputs should result to nan output
441
+ assert_equal(res, np.nan)
442
+ else:
443
+ # All other inputs should return something (but not
444
+ # raise exceptions or cause hangs)
445
+ pass
446
+
447
+
448
+ def test_chndtrix_gh2158():
449
+ # test that gh-2158 is resolved; previously this blew up
450
+ res = sp.chndtrix(0.999999, 2, np.arange(20.)+1e-6)
451
+
452
+ # Generated in R
453
+ # options(digits=16)
454
+ # ncp <- seq(0, 19) + 1e-6
455
+ # print(qchisq(0.999999, df = 2, ncp = ncp))
456
+ res_exp = [27.63103493142305, 35.25728589950540, 39.97396073236288,
457
+ 43.88033702110538, 47.35206403482798, 50.54112500166103,
458
+ 53.52720257322766, 56.35830042867810, 59.06600769498512,
459
+ 61.67243118946381, 64.19376191277179, 66.64228141346548,
460
+ 69.02756927200180, 71.35726934749408, 73.63759723904816,
461
+ 75.87368842650227, 78.06984431185720, 80.22971052389806,
462
+ 82.35640899964173, 84.45263768373256]
463
+ assert_allclose(res, res_exp)
464
+
465
+ @pytest.mark.xfail_on_32bit("32bit fails due to algorithm threshold")
466
+ def test_nctdtr_gh19896():
467
+ # test that gh-19896 is resolved.
468
+ # Compared to SciPy 1.11 results from Fortran code.
469
+ dfarr = [0.98, 9.8, 98, 980]
470
+ pnoncarr = [-3.8, 0.38, 3.8, 38]
471
+ tarr = [0.0015, 0.15, 1.5, 15]
472
+ resarr = [0.9999276519560749, 0.9999276519560749, 0.9999908831755221,
473
+ 0.9999990265452424, 0.3524153312279712, 0.39749697267251416,
474
+ 0.7168629634895805, 0.9656246449259646, 7.234804392512006e-05,
475
+ 7.234804392512006e-05, 0.03538804607509127, 0.795482701508521,
476
+ 0.0, 0.0, 0.0,
477
+ 0.011927908523093889, 0.9999276519560749, 0.9999276519560749,
478
+ 0.9999997441133123, 1.0, 0.3525155979118013,
479
+ 0.4076312014048369, 0.8476794017035086, 0.9999999297116268,
480
+ 7.234804392512006e-05, 7.234804392512006e-05, 0.013477443099785824,
481
+ 0.9998501512331494, 0.0, 0.0,
482
+ 0.0, 6.561112613212572e-07, 0.9999276519560749,
483
+ 0.9999276519560749, 0.9999999313496014, 1.0,
484
+ 0.3525281784865706, 0.40890253001898014, 0.8664672830017024,
485
+ 1.0, 7.234804392512006e-05, 7.234804392512006e-05,
486
+ 0.010990889489704836, 1.0, 0.0,
487
+ 0.0, 0.0, 0.0,
488
+ 0.9999276519560749, 0.9999276519560749, 0.9999999418789304,
489
+ 1.0, 0.35252945487817355, 0.40903153246690993,
490
+ 0.8684247068528264, 1.0, 7.234804392512006e-05,
491
+ 7.234804392512006e-05, 0.01075068918582911, 1.0,
492
+ 0.0, 0.0, 0.0, 0.0]
493
+ actarr = []
494
+ for df, p, t in itertools.product(dfarr, pnoncarr, tarr):
495
+ actarr += [sp.nctdtr(df, p, t)]
496
+ # The rtol is kept high on purpose to make it pass on 32bit systems
497
+ assert_allclose(actarr, resarr, rtol=1e-6, atol=0.0)
498
+
499
+
500
+ def test_nctdtrinc_gh19896():
501
+ # test that gh-19896 is resolved.
502
+ # Compared to SciPy 1.11 results from Fortran code.
503
+ dfarr = [0.001, 0.98, 9.8, 98, 980, 10000, 98, 9.8, 0.98, 0.001]
504
+ parr = [0.001, 0.1, 0.3, 0.8, 0.999, 0.001, 0.1, 0.3, 0.8, 0.999]
505
+ tarr = [0.0015, 0.15, 1.5, 15, 300, 0.0015, 0.15, 1.5, 15, 300]
506
+ desired = [3.090232306168629, 1.406141304556198, 2.014225177124157,
507
+ 13.727067118283456, 278.9765683871208, 3.090232306168629,
508
+ 1.4312427877936222, 2.014225177124157, 3.712743137978295,
509
+ -3.086951096691082]
510
+ actual = sp.nctdtrinc(dfarr, parr, tarr)
511
+ assert_allclose(actual, desired, rtol=5e-12, atol=0.0)
512
+
513
+
514
+ def test_stdtr_stdtrit_neg_inf():
515
+ # -inf was treated as +inf and values from the normal were returned
516
+ assert np.all(np.isnan(sp.stdtr(-np.inf, [-np.inf, -1.0, 0.0, 1.0, np.inf])))
517
+ assert np.all(np.isnan(sp.stdtrit(-np.inf, [0.0, 0.25, 0.5, 0.75, 1.0])))
518
+
519
+
520
+ def test_bdtrik_nbdtrik_inf():
521
+ y = np.array(
522
+ [np.nan,-np.inf,-10.0, -1.0, 0.0, .00001, .5, 0.9999, 1.0, 10.0, np.inf])
523
+ y = y[:,None]
524
+ p = np.atleast_2d(
525
+ [np.nan, -np.inf, -10.0, -1.0, 0.0, .00001, .5, 1.0, np.inf])
526
+ assert np.all(np.isnan(sp.bdtrik(y, np.inf, p)))
527
+ assert np.all(np.isnan(sp.nbdtrik(y, np.inf, p)))
openflamingo/lib/python3.10/site-packages/scipy/special/tests/test_cdft_asymptotic.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # gh-14777 regression tests
2
+ # Test stdtr and stdtrit with infinite df and large values of df
3
+
4
+ import numpy as np
5
+ from numpy.testing import assert_allclose, assert_equal
6
+ from scipy.special import stdtr, stdtrit, ndtr, ndtri
7
+
8
+
9
+ def test_stdtr_vs_R_large_df():
10
+ df = [1e10, 1e12, 1e120, np.inf]
11
+ t = 1.
12
+ res = stdtr(df, t)
13
+ # R Code:
14
+ # options(digits=20)
15
+ # pt(1., c(1e10, 1e12, 1e120, Inf))
16
+ res_R = [0.84134474605644460343,
17
+ 0.84134474606842180044,
18
+ 0.84134474606854281475,
19
+ 0.84134474606854292578]
20
+ assert_allclose(res, res_R, rtol=2e-15)
21
+ # last value should also agree with ndtr
22
+ assert_equal(res[3], ndtr(1.))
23
+
24
+
25
+ def test_stdtrit_vs_R_large_df():
26
+ df = [1e10, 1e12, 1e120, np.inf]
27
+ p = 0.1
28
+ res = stdtrit(df, p)
29
+ # R Code:
30
+ # options(digits=20)
31
+ # qt(0.1, c(1e10, 1e12, 1e120, Inf))
32
+ res_R = [-1.2815515656292593150,
33
+ -1.2815515655454472466,
34
+ -1.2815515655446008125,
35
+ -1.2815515655446008125]
36
+ assert_allclose(res, res_R, rtol=1e-14, atol=1e-15)
37
+ # last value should also agree with ndtri
38
+ assert_equal(res[3], ndtri(0.1))
39
+
40
+
41
+ def test_stdtr_stdtri_invalid():
42
+ # a mix of large and inf df with t/p equal to nan
43
+ df = [1e10, 1e12, 1e120, np.inf]
44
+ x = np.nan
45
+ res1 = stdtr(df, x)
46
+ res2 = stdtrit(df, x)
47
+ res_ex = 4*[np.nan]
48
+ assert_equal(res1, res_ex)
49
+ assert_equal(res2, res_ex)
openflamingo/lib/python3.10/site-packages/scipy/special/tests/test_cython_special.py ADDED
@@ -0,0 +1,363 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+ from typing import Callable
3
+
4
+ import pytest
5
+ from itertools import product
6
+ from numpy.testing import assert_allclose, suppress_warnings
7
+ from scipy import special
8
+ from scipy.special import cython_special
9
+
10
+
11
+ bint_points = [True, False]
12
+ int_points = [-10, -1, 1, 10]
13
+ real_points = [-10.0, -1.0, 1.0, 10.0]
14
+ complex_points = [complex(*tup) for tup in product(real_points, repeat=2)]
15
+
16
+
17
+ CYTHON_SIGNATURE_MAP = {
18
+ 'b': 'bint',
19
+ 'f': 'float',
20
+ 'd': 'double',
21
+ 'g': 'long double',
22
+ 'F': 'float complex',
23
+ 'D': 'double complex',
24
+ 'G': 'long double complex',
25
+ 'i': 'int',
26
+ 'l': 'long'
27
+ }
28
+
29
+
30
+ TEST_POINTS = {
31
+ 'b': bint_points,
32
+ 'f': real_points,
33
+ 'd': real_points,
34
+ 'g': real_points,
35
+ 'F': complex_points,
36
+ 'D': complex_points,
37
+ 'G': complex_points,
38
+ 'i': int_points,
39
+ 'l': int_points,
40
+ }
41
+
42
+
43
+ PARAMS: list[tuple[Callable, Callable, tuple[str, ...], str | None]] = [
44
+ (special.agm, cython_special.agm, ('dd',), None),
45
+ (special.airy, cython_special._airy_pywrap, ('d', 'D'), None),
46
+ (special.airye, cython_special._airye_pywrap, ('d', 'D'), None),
47
+ (special.bdtr, cython_special.bdtr, ('dld', 'ddd'), None),
48
+ (special.bdtrc, cython_special.bdtrc, ('dld', 'ddd'), None),
49
+ (special.bdtri, cython_special.bdtri, ('dld', 'ddd'), None),
50
+ (special.bdtrik, cython_special.bdtrik, ('ddd',), None),
51
+ (special.bdtrin, cython_special.bdtrin, ('ddd',), None),
52
+ (special.bei, cython_special.bei, ('d',), None),
53
+ (special.beip, cython_special.beip, ('d',), None),
54
+ (special.ber, cython_special.ber, ('d',), None),
55
+ (special.berp, cython_special.berp, ('d',), None),
56
+ (special.besselpoly, cython_special.besselpoly, ('ddd',), None),
57
+ (special.beta, cython_special.beta, ('dd',), None),
58
+ (special.betainc, cython_special.betainc, ('ddd',), None),
59
+ (special.betaincc, cython_special.betaincc, ('ddd',), None),
60
+ (special.betaincinv, cython_special.betaincinv, ('ddd',), None),
61
+ (special.betainccinv, cython_special.betainccinv, ('ddd',), None),
62
+ (special.betaln, cython_special.betaln, ('dd',), None),
63
+ (special.binom, cython_special.binom, ('dd',), None),
64
+ (special.boxcox, cython_special.boxcox, ('dd',), None),
65
+ (special.boxcox1p, cython_special.boxcox1p, ('dd',), None),
66
+ (special.btdtr, cython_special.btdtr, ('ddd',), None),
67
+ (special.btdtri, cython_special.btdtri, ('ddd',), None),
68
+ (special.btdtria, cython_special.btdtria, ('ddd',), None),
69
+ (special.btdtrib, cython_special.btdtrib, ('ddd',), None),
70
+ (special.cbrt, cython_special.cbrt, ('d',), None),
71
+ (special.chdtr, cython_special.chdtr, ('dd',), None),
72
+ (special.chdtrc, cython_special.chdtrc, ('dd',), None),
73
+ (special.chdtri, cython_special.chdtri, ('dd',), None),
74
+ (special.chdtriv, cython_special.chdtriv, ('dd',), None),
75
+ (special.chndtr, cython_special.chndtr, ('ddd',), None),
76
+ (special.chndtridf, cython_special.chndtridf, ('ddd',), None),
77
+ (special.chndtrinc, cython_special.chndtrinc, ('ddd',), None),
78
+ (special.chndtrix, cython_special.chndtrix, ('ddd',), None),
79
+ (special.cosdg, cython_special.cosdg, ('d',), None),
80
+ (special.cosm1, cython_special.cosm1, ('d',), None),
81
+ (special.cotdg, cython_special.cotdg, ('d',), None),
82
+ (special.dawsn, cython_special.dawsn, ('d', 'D'), None),
83
+ (special.ellipe, cython_special.ellipe, ('d',), None),
84
+ (special.ellipeinc, cython_special.ellipeinc, ('dd',), None),
85
+ (special.ellipj, cython_special._ellipj_pywrap, ('dd',), None),
86
+ (special.ellipkinc, cython_special.ellipkinc, ('dd',), None),
87
+ (special.ellipkm1, cython_special.ellipkm1, ('d',), None),
88
+ (special.ellipk, cython_special.ellipk, ('d',), None),
89
+ (special.elliprc, cython_special.elliprc, ('dd', 'DD'), None),
90
+ (special.elliprd, cython_special.elliprd, ('ddd', 'DDD'), None),
91
+ (special.elliprf, cython_special.elliprf, ('ddd', 'DDD'), None),
92
+ (special.elliprg, cython_special.elliprg, ('ddd', 'DDD'), None),
93
+ (special.elliprj, cython_special.elliprj, ('dddd', 'DDDD'), None),
94
+ (special.entr, cython_special.entr, ('d',), None),
95
+ (special.erf, cython_special.erf, ('d', 'D'), None),
96
+ (special.erfc, cython_special.erfc, ('d', 'D'), None),
97
+ (special.erfcx, cython_special.erfcx, ('d', 'D'), None),
98
+ (special.erfi, cython_special.erfi, ('d', 'D'), None),
99
+ (special.erfinv, cython_special.erfinv, ('d',), None),
100
+ (special.erfcinv, cython_special.erfcinv, ('d',), None),
101
+ (special.eval_chebyc, cython_special.eval_chebyc, ('dd', 'dD', 'ld'), None),
102
+ (special.eval_chebys, cython_special.eval_chebys, ('dd', 'dD', 'ld'),
103
+ 'd and l differ for negative int'),
104
+ (special.eval_chebyt, cython_special.eval_chebyt, ('dd', 'dD', 'ld'),
105
+ 'd and l differ for negative int'),
106
+ (special.eval_chebyu, cython_special.eval_chebyu, ('dd', 'dD', 'ld'),
107
+ 'd and l differ for negative int'),
108
+ (special.eval_gegenbauer, cython_special.eval_gegenbauer, ('ddd', 'ddD', 'ldd'),
109
+ 'd and l differ for negative int'),
110
+ (special.eval_genlaguerre, cython_special.eval_genlaguerre, ('ddd', 'ddD', 'ldd'),
111
+ 'd and l differ for negative int'),
112
+ (special.eval_hermite, cython_special.eval_hermite, ('ld',), None),
113
+ (special.eval_hermitenorm, cython_special.eval_hermitenorm, ('ld',), None),
114
+ (special.eval_jacobi, cython_special.eval_jacobi, ('dddd', 'dddD', 'lddd'),
115
+ 'd and l differ for negative int'),
116
+ (special.eval_laguerre, cython_special.eval_laguerre, ('dd', 'dD', 'ld'),
117
+ 'd and l differ for negative int'),
118
+ (special.eval_legendre, cython_special.eval_legendre, ('dd', 'dD', 'ld'), None),
119
+ (special.eval_sh_chebyt, cython_special.eval_sh_chebyt, ('dd', 'dD', 'ld'), None),
120
+ (special.eval_sh_chebyu, cython_special.eval_sh_chebyu, ('dd', 'dD', 'ld'),
121
+ 'd and l differ for negative int'),
122
+ (special.eval_sh_jacobi, cython_special.eval_sh_jacobi, ('dddd', 'dddD', 'lddd'),
123
+ 'd and l differ for negative int'),
124
+ (special.eval_sh_legendre, cython_special.eval_sh_legendre, ('dd', 'dD', 'ld'),
125
+ None),
126
+ (special.exp1, cython_special.exp1, ('d', 'D'), None),
127
+ (special.exp10, cython_special.exp10, ('d',), None),
128
+ (special.exp2, cython_special.exp2, ('d',), None),
129
+ (special.expi, cython_special.expi, ('d', 'D'), None),
130
+ (special.expit, cython_special.expit, ('f', 'd', 'g'), None),
131
+ (special.expm1, cython_special.expm1, ('d', 'D'), None),
132
+ (special.expn, cython_special.expn, ('ld', 'dd'), None),
133
+ (special.exprel, cython_special.exprel, ('d',), None),
134
+ (special.fdtr, cython_special.fdtr, ('ddd',), None),
135
+ (special.fdtrc, cython_special.fdtrc, ('ddd',), None),
136
+ (special.fdtri, cython_special.fdtri, ('ddd',), None),
137
+ (special.fdtridfd, cython_special.fdtridfd, ('ddd',), None),
138
+ (special.fresnel, cython_special._fresnel_pywrap, ('d', 'D'), None),
139
+ (special.gamma, cython_special.gamma, ('d', 'D'), None),
140
+ (special.gammainc, cython_special.gammainc, ('dd',), None),
141
+ (special.gammaincc, cython_special.gammaincc, ('dd',), None),
142
+ (special.gammainccinv, cython_special.gammainccinv, ('dd',), None),
143
+ (special.gammaincinv, cython_special.gammaincinv, ('dd',), None),
144
+ (special.gammaln, cython_special.gammaln, ('d',), None),
145
+ (special.gammasgn, cython_special.gammasgn, ('d',), None),
146
+ (special.gdtr, cython_special.gdtr, ('ddd',), None),
147
+ (special.gdtrc, cython_special.gdtrc, ('ddd',), None),
148
+ (special.gdtria, cython_special.gdtria, ('ddd',), None),
149
+ (special.gdtrib, cython_special.gdtrib, ('ddd',), None),
150
+ (special.gdtrix, cython_special.gdtrix, ('ddd',), None),
151
+ (special.hankel1, cython_special.hankel1, ('dD',), None),
152
+ (special.hankel1e, cython_special.hankel1e, ('dD',), None),
153
+ (special.hankel2, cython_special.hankel2, ('dD',), None),
154
+ (special.hankel2e, cython_special.hankel2e, ('dD',), None),
155
+ (special.huber, cython_special.huber, ('dd',), None),
156
+ (special.hyp0f1, cython_special.hyp0f1, ('dd', 'dD'), None),
157
+ (special.hyp1f1, cython_special.hyp1f1, ('ddd', 'ddD'), None),
158
+ (special.hyp2f1, cython_special.hyp2f1, ('dddd', 'dddD'), None),
159
+ (special.hyperu, cython_special.hyperu, ('ddd',), None),
160
+ (special.i0, cython_special.i0, ('d',), None),
161
+ (special.i0e, cython_special.i0e, ('d',), None),
162
+ (special.i1, cython_special.i1, ('d',), None),
163
+ (special.i1e, cython_special.i1e, ('d',), None),
164
+ (special.inv_boxcox, cython_special.inv_boxcox, ('dd',), None),
165
+ (special.inv_boxcox1p, cython_special.inv_boxcox1p, ('dd',), None),
166
+ (special.it2i0k0, cython_special._it2i0k0_pywrap, ('d',), None),
167
+ (special.it2j0y0, cython_special._it2j0y0_pywrap, ('d',), None),
168
+ (special.it2struve0, cython_special.it2struve0, ('d',), None),
169
+ (special.itairy, cython_special._itairy_pywrap, ('d',), None),
170
+ (special.iti0k0, cython_special._iti0k0_pywrap, ('d',), None),
171
+ (special.itj0y0, cython_special._itj0y0_pywrap, ('d',), None),
172
+ (special.itmodstruve0, cython_special.itmodstruve0, ('d',), None),
173
+ (special.itstruve0, cython_special.itstruve0, ('d',), None),
174
+ (special.iv, cython_special.iv, ('dd', 'dD'), None),
175
+ (special.ive, cython_special.ive, ('dd', 'dD'), None),
176
+ (special.j0, cython_special.j0, ('d',), None),
177
+ (special.j1, cython_special.j1, ('d',), None),
178
+ (special.jv, cython_special.jv, ('dd', 'dD'), None),
179
+ (special.jve, cython_special.jve, ('dd', 'dD'), None),
180
+ (special.k0, cython_special.k0, ('d',), None),
181
+ (special.k0e, cython_special.k0e, ('d',), None),
182
+ (special.k1, cython_special.k1, ('d',), None),
183
+ (special.k1e, cython_special.k1e, ('d',), None),
184
+ (special.kei, cython_special.kei, ('d',), None),
185
+ (special.keip, cython_special.keip, ('d',), None),
186
+ (special.kelvin, cython_special._kelvin_pywrap, ('d',), None),
187
+ (special.ker, cython_special.ker, ('d',), None),
188
+ (special.kerp, cython_special.kerp, ('d',), None),
189
+ (special.kl_div, cython_special.kl_div, ('dd',), None),
190
+ (special.kn, cython_special.kn, ('ld', 'dd'), None),
191
+ (special.kolmogi, cython_special.kolmogi, ('d',), None),
192
+ (special.kolmogorov, cython_special.kolmogorov, ('d',), None),
193
+ (special.kv, cython_special.kv, ('dd', 'dD'), None),
194
+ (special.kve, cython_special.kve, ('dd', 'dD'), None),
195
+ (special.log1p, cython_special.log1p, ('d', 'D'), None),
196
+ (special.log_expit, cython_special.log_expit, ('f', 'd', 'g'), None),
197
+ (special.log_ndtr, cython_special.log_ndtr, ('d', 'D'), None),
198
+ (special.ndtri_exp, cython_special.ndtri_exp, ('d',), None),
199
+ (special.loggamma, cython_special.loggamma, ('D',), None),
200
+ (special.logit, cython_special.logit, ('f', 'd', 'g'), None),
201
+ (special.lpmv, cython_special.lpmv, ('ddd',), None),
202
+ (special.mathieu_a, cython_special.mathieu_a, ('dd',), None),
203
+ (special.mathieu_b, cython_special.mathieu_b, ('dd',), None),
204
+ (special.mathieu_cem, cython_special._mathieu_cem_pywrap, ('ddd',), None),
205
+ (special.mathieu_modcem1, cython_special._mathieu_modcem1_pywrap, ('ddd',), None),
206
+ (special.mathieu_modcem2, cython_special._mathieu_modcem2_pywrap, ('ddd',), None),
207
+ (special.mathieu_modsem1, cython_special._mathieu_modsem1_pywrap, ('ddd',), None),
208
+ (special.mathieu_modsem2, cython_special._mathieu_modsem2_pywrap, ('ddd',), None),
209
+ (special.mathieu_sem, cython_special._mathieu_sem_pywrap, ('ddd',), None),
210
+ (special.modfresnelm, cython_special._modfresnelm_pywrap, ('d',), None),
211
+ (special.modfresnelp, cython_special._modfresnelp_pywrap, ('d',), None),
212
+ (special.modstruve, cython_special.modstruve, ('dd',), None),
213
+ (special.nbdtr, cython_special.nbdtr, ('lld', 'ddd'), None),
214
+ (special.nbdtrc, cython_special.nbdtrc, ('lld', 'ddd'), None),
215
+ (special.nbdtri, cython_special.nbdtri, ('lld', 'ddd'), None),
216
+ (special.nbdtrik, cython_special.nbdtrik, ('ddd',), None),
217
+ (special.nbdtrin, cython_special.nbdtrin, ('ddd',), None),
218
+ (special.ncfdtr, cython_special.ncfdtr, ('dddd',), None),
219
+ (special.ncfdtri, cython_special.ncfdtri, ('dddd',), None),
220
+ (special.ncfdtridfd, cython_special.ncfdtridfd, ('dddd',), None),
221
+ (special.ncfdtridfn, cython_special.ncfdtridfn, ('dddd',), None),
222
+ (special.ncfdtrinc, cython_special.ncfdtrinc, ('dddd',), None),
223
+ (special.nctdtr, cython_special.nctdtr, ('ddd',), None),
224
+ (special.nctdtridf, cython_special.nctdtridf, ('ddd',), None),
225
+ (special.nctdtrinc, cython_special.nctdtrinc, ('ddd',), None),
226
+ (special.nctdtrit, cython_special.nctdtrit, ('ddd',), None),
227
+ (special.ndtr, cython_special.ndtr, ('d', 'D'), None),
228
+ (special.ndtri, cython_special.ndtri, ('d',), None),
229
+ (special.nrdtrimn, cython_special.nrdtrimn, ('ddd',), None),
230
+ (special.nrdtrisd, cython_special.nrdtrisd, ('ddd',), None),
231
+ (special.obl_ang1, cython_special._obl_ang1_pywrap, ('dddd',), None),
232
+ (special.obl_ang1_cv, cython_special._obl_ang1_cv_pywrap, ('ddddd',), None),
233
+ (special.obl_cv, cython_special.obl_cv, ('ddd',), None),
234
+ (special.obl_rad1, cython_special._obl_rad1_pywrap, ('dddd',), "see gh-6211"),
235
+ (special.obl_rad1_cv, cython_special._obl_rad1_cv_pywrap, ('ddddd',),
236
+ "see gh-6211"),
237
+ (special.obl_rad2, cython_special._obl_rad2_pywrap, ('dddd',), "see gh-6211"),
238
+ (special.obl_rad2_cv, cython_special._obl_rad2_cv_pywrap, ('ddddd',),
239
+ "see gh-6211"),
240
+ (special.pbdv, cython_special._pbdv_pywrap, ('dd',), None),
241
+ (special.pbvv, cython_special._pbvv_pywrap, ('dd',), None),
242
+ (special.pbwa, cython_special._pbwa_pywrap, ('dd',), None),
243
+ (special.pdtr, cython_special.pdtr, ('dd', 'dd'), None),
244
+ (special.pdtrc, cython_special.pdtrc, ('dd', 'dd'), None),
245
+ (special.pdtri, cython_special.pdtri, ('ld', 'dd'), None),
246
+ (special.pdtrik, cython_special.pdtrik, ('dd',), None),
247
+ (special.poch, cython_special.poch, ('dd',), None),
248
+ (special.powm1, cython_special.powm1, ('dd',), None),
249
+ (special.pro_ang1, cython_special._pro_ang1_pywrap, ('dddd',), None),
250
+ (special.pro_ang1_cv, cython_special._pro_ang1_cv_pywrap, ('ddddd',), None),
251
+ (special.pro_cv, cython_special.pro_cv, ('ddd',), None),
252
+ (special.pro_rad1, cython_special._pro_rad1_pywrap, ('dddd',), "see gh-6211"),
253
+ (special.pro_rad1_cv, cython_special._pro_rad1_cv_pywrap, ('ddddd',),
254
+ "see gh-6211"),
255
+ (special.pro_rad2, cython_special._pro_rad2_pywrap, ('dddd',), "see gh-6211"),
256
+ (special.pro_rad2_cv, cython_special._pro_rad2_cv_pywrap, ('ddddd',),
257
+ "see gh-6211"),
258
+ (special.pseudo_huber, cython_special.pseudo_huber, ('dd',), None),
259
+ (special.psi, cython_special.psi, ('d', 'D'), None),
260
+ (special.radian, cython_special.radian, ('ddd',), None),
261
+ (special.rel_entr, cython_special.rel_entr, ('dd',), None),
262
+ (special.rgamma, cython_special.rgamma, ('d', 'D'), None),
263
+ (special.round, cython_special.round, ('d',), None),
264
+ (special.spherical_jn, cython_special.spherical_jn, ('ld', 'ldb', 'lD', 'lDb'),
265
+ None),
266
+ (special.spherical_yn, cython_special.spherical_yn, ('ld', 'ldb', 'lD', 'lDb'),
267
+ None),
268
+ (special.spherical_in, cython_special.spherical_in, ('ld', 'ldb', 'lD', 'lDb'),
269
+ None),
270
+ (special.spherical_kn, cython_special.spherical_kn, ('ld', 'ldb', 'lD', 'lDb'),
271
+ None),
272
+ (special.shichi, cython_special._shichi_pywrap, ('d', 'D'), None),
273
+ (special.sici, cython_special._sici_pywrap, ('d', 'D'), None),
274
+ (special.sindg, cython_special.sindg, ('d',), None),
275
+ (special.smirnov, cython_special.smirnov, ('ld', 'dd'), None),
276
+ (special.smirnovi, cython_special.smirnovi, ('ld', 'dd'), None),
277
+ (special.spence, cython_special.spence, ('d', 'D'), None),
278
+ (special.sph_harm, cython_special.sph_harm, ('lldd', 'dddd'), None),
279
+ (special.stdtr, cython_special.stdtr, ('dd',), None),
280
+ (special.stdtridf, cython_special.stdtridf, ('dd',), None),
281
+ (special.stdtrit, cython_special.stdtrit, ('dd',), None),
282
+ (special.struve, cython_special.struve, ('dd',), None),
283
+ (special.tandg, cython_special.tandg, ('d',), None),
284
+ (special.tklmbda, cython_special.tklmbda, ('dd',), None),
285
+ (special.voigt_profile, cython_special.voigt_profile, ('ddd',), None),
286
+ (special.wofz, cython_special.wofz, ('D',), None),
287
+ (special.wright_bessel, cython_special.wright_bessel, ('ddd',), None),
288
+ (special.wrightomega, cython_special.wrightomega, ('D',), None),
289
+ (special.xlog1py, cython_special.xlog1py, ('dd', 'DD'), None),
290
+ (special.xlogy, cython_special.xlogy, ('dd', 'DD'), None),
291
+ (special.y0, cython_special.y0, ('d',), None),
292
+ (special.y1, cython_special.y1, ('d',), None),
293
+ (special.yn, cython_special.yn, ('ld', 'dd'), None),
294
+ (special.yv, cython_special.yv, ('dd', 'dD'), None),
295
+ (special.yve, cython_special.yve, ('dd', 'dD'), None),
296
+ (special.zetac, cython_special.zetac, ('d',), None),
297
+ (special.owens_t, cython_special.owens_t, ('dd',), None)
298
+ ]
299
+
300
+
301
+ IDS = [x[0].__name__ for x in PARAMS]
302
+
303
+
304
+ def _generate_test_points(typecodes):
305
+ axes = tuple(TEST_POINTS[x] for x in typecodes)
306
+ pts = list(product(*axes))
307
+ return pts
308
+
309
+
310
+ def test_cython_api_completeness():
311
+ # Check that everything is tested
312
+ for name in dir(cython_special):
313
+ func = getattr(cython_special, name)
314
+ if callable(func) and not name.startswith('_'):
315
+ for _, cyfun, _, _ in PARAMS:
316
+ if cyfun is func:
317
+ break
318
+ else:
319
+ raise RuntimeError(f"{name} missing from tests!")
320
+
321
+
322
+ @pytest.mark.parametrize("param", PARAMS, ids=IDS)
323
+ def test_cython_api(param):
324
+ pyfunc, cyfunc, specializations, knownfailure = param
325
+ if knownfailure:
326
+ pytest.xfail(reason=knownfailure)
327
+
328
+ # Check which parameters are expected to be fused types
329
+ max_params = max(len(spec) for spec in specializations)
330
+ values = [set() for _ in range(max_params)]
331
+ for typecodes in specializations:
332
+ for j, v in enumerate(typecodes):
333
+ values[j].add(v)
334
+ seen = set()
335
+ is_fused_code = [False] * len(values)
336
+ for j, v in enumerate(values):
337
+ vv = tuple(sorted(v))
338
+ if vv in seen:
339
+ continue
340
+ is_fused_code[j] = (len(v) > 1)
341
+ seen.add(vv)
342
+
343
+ # Check results
344
+ for typecodes in specializations:
345
+ # Pick the correct specialized function
346
+ signature = [CYTHON_SIGNATURE_MAP[code]
347
+ for j, code in enumerate(typecodes)
348
+ if is_fused_code[j]]
349
+
350
+ if signature:
351
+ cy_spec_func = cyfunc[tuple(signature)]
352
+ else:
353
+ signature = None
354
+ cy_spec_func = cyfunc
355
+
356
+ # Test it
357
+ pts = _generate_test_points(typecodes)
358
+ for pt in pts:
359
+ with suppress_warnings() as sup:
360
+ sup.filter(DeprecationWarning)
361
+ pyval = pyfunc(*pt)
362
+ cyval = cy_spec_func(*pt)
363
+ assert_allclose(cyval, pyval, err_msg=f"{pt} {typecodes} {signature}")
openflamingo/lib/python3.10/site-packages/scipy/special/tests/test_data.py ADDED
@@ -0,0 +1,725 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import importlib.resources
2
+
3
+ import numpy as np
4
+ from numpy.testing import suppress_warnings
5
+ import pytest
6
+
7
+ from scipy.special import (
8
+ lpn, lpmn, lpmv, lqn, lqmn, sph_harm, eval_legendre, eval_hermite,
9
+ eval_laguerre, eval_genlaguerre, binom, cbrt, expm1, log1p, zeta,
10
+ jn, jv, jvp, yn, yv, yvp, iv, ivp, kn, kv, kvp,
11
+ gamma, gammaln, gammainc, gammaincc, gammaincinv, gammainccinv, digamma,
12
+ beta, betainc, betaincinv, poch,
13
+ ellipe, ellipeinc, ellipk, ellipkm1, ellipkinc,
14
+ elliprc, elliprd, elliprf, elliprg, elliprj,
15
+ erf, erfc, erfinv, erfcinv, exp1, expi, expn,
16
+ bdtrik, btdtr, btdtri, btdtria, btdtrib, chndtr, gdtr, gdtrc, gdtrix, gdtrib,
17
+ nbdtrik, pdtrik, owens_t,
18
+ mathieu_a, mathieu_b, mathieu_cem, mathieu_sem, mathieu_modcem1,
19
+ mathieu_modsem1, mathieu_modcem2, mathieu_modsem2,
20
+ ellip_harm, ellip_harm_2, spherical_jn, spherical_yn, wright_bessel
21
+ )
22
+ from scipy.integrate import IntegrationWarning
23
+
24
+ from scipy.special._testutils import FuncData
25
+
26
+
27
+ # The npz files are generated, and hence may live in the build dir. We can only
28
+ # access them through `importlib.resources`, not an explicit path from `__file__`
29
+ _datadir = importlib.resources.files('scipy.special.tests.data')
30
+
31
+ _boost_npz = _datadir.joinpath('boost.npz')
32
+ with importlib.resources.as_file(_boost_npz) as f:
33
+ DATASETS_BOOST = np.load(f)
34
+
35
+ _gsl_npz = _datadir.joinpath('gsl.npz')
36
+ with importlib.resources.as_file(_gsl_npz) as f:
37
+ DATASETS_GSL = np.load(f)
38
+
39
+ _local_npz = _datadir.joinpath('local.npz')
40
+ with importlib.resources.as_file(_local_npz) as f:
41
+ DATASETS_LOCAL = np.load(f)
42
+
43
+
44
+ def data(func, dataname, *a, **kw):
45
+ kw.setdefault('dataname', dataname)
46
+ return FuncData(func, DATASETS_BOOST[dataname], *a, **kw)
47
+
48
+
49
+ def data_gsl(func, dataname, *a, **kw):
50
+ kw.setdefault('dataname', dataname)
51
+ return FuncData(func, DATASETS_GSL[dataname], *a, **kw)
52
+
53
+
54
+ def data_local(func, dataname, *a, **kw):
55
+ kw.setdefault('dataname', dataname)
56
+ return FuncData(func, DATASETS_LOCAL[dataname], *a, **kw)
57
+
58
+
59
+ def ellipk_(k):
60
+ return ellipk(k*k)
61
+
62
+
63
+ def ellipkinc_(f, k):
64
+ return ellipkinc(f, k*k)
65
+
66
+
67
+ def ellipe_(k):
68
+ return ellipe(k*k)
69
+
70
+
71
+ def ellipeinc_(f, k):
72
+ return ellipeinc(f, k*k)
73
+
74
+
75
+ def zeta_(x):
76
+ return zeta(x, 1.)
77
+
78
+
79
+ def assoc_legendre_p_boost_(nu, mu, x):
80
+ # the boost test data is for integer orders only
81
+ return lpmv(mu, nu.astype(int), x)
82
+
83
+ def legendre_p_via_assoc_(nu, x):
84
+ return lpmv(0, nu, x)
85
+
86
+ def lpn_(n, x):
87
+ return lpn(n.astype('l'), x)[0][-1]
88
+
89
+ def lqn_(n, x):
90
+ return lqn(n.astype('l'), x)[0][-1]
91
+
92
+ def legendre_p_via_lpmn(n, x):
93
+ return lpmn(0, n, x)[0][0,-1]
94
+
95
+ def legendre_q_via_lqmn(n, x):
96
+ return lqmn(0, n, x)[0][0,-1]
97
+
98
+ def mathieu_ce_rad(m, q, x):
99
+ return mathieu_cem(m, q, x*180/np.pi)[0]
100
+
101
+
102
+ def mathieu_se_rad(m, q, x):
103
+ return mathieu_sem(m, q, x*180/np.pi)[0]
104
+
105
+
106
+ def mathieu_mc1_scaled(m, q, x):
107
+ # GSL follows a different normalization.
108
+ # We follow Abramowitz & Stegun, they apparently something else.
109
+ return mathieu_modcem1(m, q, x)[0] * np.sqrt(np.pi/2)
110
+
111
+
112
+ def mathieu_ms1_scaled(m, q, x):
113
+ return mathieu_modsem1(m, q, x)[0] * np.sqrt(np.pi/2)
114
+
115
+
116
+ def mathieu_mc2_scaled(m, q, x):
117
+ return mathieu_modcem2(m, q, x)[0] * np.sqrt(np.pi/2)
118
+
119
+
120
+ def mathieu_ms2_scaled(m, q, x):
121
+ return mathieu_modsem2(m, q, x)[0] * np.sqrt(np.pi/2)
122
+
123
+ def eval_legendre_ld(n, x):
124
+ return eval_legendre(n.astype('l'), x)
125
+
126
+ def eval_legendre_dd(n, x):
127
+ return eval_legendre(n.astype('d'), x)
128
+
129
+ def eval_hermite_ld(n, x):
130
+ return eval_hermite(n.astype('l'), x)
131
+
132
+ def eval_laguerre_ld(n, x):
133
+ return eval_laguerre(n.astype('l'), x)
134
+
135
+ def eval_laguerre_dd(n, x):
136
+ return eval_laguerre(n.astype('d'), x)
137
+
138
+ def eval_genlaguerre_ldd(n, a, x):
139
+ return eval_genlaguerre(n.astype('l'), a, x)
140
+
141
+ def eval_genlaguerre_ddd(n, a, x):
142
+ return eval_genlaguerre(n.astype('d'), a, x)
143
+
144
+ def bdtrik_comp(y, n, p):
145
+ return bdtrik(1-y, n, p)
146
+
147
+ def btdtri_comp(a, b, p):
148
+ return btdtri(a, b, 1-p)
149
+
150
+ def btdtria_comp(p, b, x):
151
+ return btdtria(1-p, b, x)
152
+
153
+ def btdtrib_comp(a, p, x):
154
+ return btdtrib(a, 1-p, x)
155
+
156
+ def gdtr_(p, x):
157
+ return gdtr(1.0, p, x)
158
+
159
+ def gdtrc_(p, x):
160
+ return gdtrc(1.0, p, x)
161
+
162
+ def gdtrix_(b, p):
163
+ return gdtrix(1.0, b, p)
164
+
165
+ def gdtrix_comp(b, p):
166
+ return gdtrix(1.0, b, 1-p)
167
+
168
+ def gdtrib_(p, x):
169
+ return gdtrib(1.0, p, x)
170
+
171
+ def gdtrib_comp(p, x):
172
+ return gdtrib(1.0, 1-p, x)
173
+
174
+ def nbdtrik_comp(y, n, p):
175
+ return nbdtrik(1-y, n, p)
176
+
177
+ def pdtrik_comp(p, m):
178
+ return pdtrik(1-p, m)
179
+
180
+ def poch_(z, m):
181
+ return 1.0 / poch(z, m)
182
+
183
+ def poch_minus(z, m):
184
+ return 1.0 / poch(z, -m)
185
+
186
+ def spherical_jn_(n, x):
187
+ return spherical_jn(n.astype('l'), x)
188
+
189
+ def spherical_yn_(n, x):
190
+ return spherical_yn(n.astype('l'), x)
191
+
192
+ def sph_harm_(m, n, theta, phi):
193
+ y = sph_harm(m, n, theta, phi)
194
+ return (y.real, y.imag)
195
+
196
+ def cexpm1(x, y):
197
+ z = expm1(x + 1j*y)
198
+ return z.real, z.imag
199
+
200
+ def clog1p(x, y):
201
+ z = log1p(x + 1j*y)
202
+ return z.real, z.imag
203
+
204
+
205
+ BOOST_TESTS = [
206
+ data(assoc_legendre_p_boost_, 'assoc_legendre_p_ipp-assoc_legendre_p',
207
+ (0,1,2), 3, rtol=1e-11),
208
+
209
+ data(legendre_p_via_assoc_, 'legendre_p_ipp-legendre_p',
210
+ (0,1), 2, rtol=1e-11),
211
+ data(legendre_p_via_assoc_, 'legendre_p_large_ipp-legendre_p_large',
212
+ (0,1), 2, rtol=9.6e-14),
213
+ data(legendre_p_via_lpmn, 'legendre_p_ipp-legendre_p',
214
+ (0,1), 2, rtol=5e-14, vectorized=False),
215
+ data(legendre_p_via_lpmn, 'legendre_p_large_ipp-legendre_p_large',
216
+ (0,1), 2, rtol=9.6e-14, vectorized=False),
217
+ data(lpn_, 'legendre_p_ipp-legendre_p',
218
+ (0,1), 2, rtol=5e-14, vectorized=False),
219
+ data(lpn_, 'legendre_p_large_ipp-legendre_p_large',
220
+ (0,1), 2, rtol=3e-13, vectorized=False),
221
+ data(eval_legendre_ld, 'legendre_p_ipp-legendre_p',
222
+ (0,1), 2, rtol=6e-14),
223
+ data(eval_legendre_ld, 'legendre_p_large_ipp-legendre_p_large',
224
+ (0,1), 2, rtol=2e-13),
225
+ data(eval_legendre_dd, 'legendre_p_ipp-legendre_p',
226
+ (0,1), 2, rtol=2e-14),
227
+ data(eval_legendre_dd, 'legendre_p_large_ipp-legendre_p_large',
228
+ (0,1), 2, rtol=2e-13),
229
+
230
+ data(lqn_, 'legendre_p_ipp-legendre_p',
231
+ (0,1), 3, rtol=2e-14, vectorized=False),
232
+ data(lqn_, 'legendre_p_large_ipp-legendre_p_large',
233
+ (0,1), 3, rtol=2e-12, vectorized=False),
234
+ data(legendre_q_via_lqmn, 'legendre_p_ipp-legendre_p',
235
+ (0,1), 3, rtol=2e-14, vectorized=False),
236
+ data(legendre_q_via_lqmn, 'legendre_p_large_ipp-legendre_p_large',
237
+ (0,1), 3, rtol=2e-12, vectorized=False),
238
+
239
+ data(beta, 'beta_exp_data_ipp-beta_exp_data',
240
+ (0,1), 2, rtol=1e-13),
241
+ data(beta, 'beta_exp_data_ipp-beta_exp_data',
242
+ (0,1), 2, rtol=1e-13),
243
+ data(beta, 'beta_med_data_ipp-beta_med_data',
244
+ (0,1), 2, rtol=5e-13),
245
+
246
+ data(betainc, 'ibeta_small_data_ipp-ibeta_small_data',
247
+ (0,1,2), 5, rtol=6e-15),
248
+ data(betainc, 'ibeta_data_ipp-ibeta_data',
249
+ (0,1,2), 5, rtol=5e-13),
250
+ data(betainc, 'ibeta_int_data_ipp-ibeta_int_data',
251
+ (0,1,2), 5, rtol=2e-14),
252
+ data(betainc, 'ibeta_large_data_ipp-ibeta_large_data',
253
+ (0,1,2), 5, rtol=4e-10),
254
+
255
+ data(betaincinv, 'ibeta_inv_data_ipp-ibeta_inv_data',
256
+ (0,1,2), 3, rtol=1e-5),
257
+
258
+ data(btdtr, 'ibeta_small_data_ipp-ibeta_small_data',
259
+ (0,1,2), 5, rtol=6e-15),
260
+ data(btdtr, 'ibeta_data_ipp-ibeta_data',
261
+ (0,1,2), 5, rtol=4e-13),
262
+ data(btdtr, 'ibeta_int_data_ipp-ibeta_int_data',
263
+ (0,1,2), 5, rtol=2e-14),
264
+ data(btdtr, 'ibeta_large_data_ipp-ibeta_large_data',
265
+ (0,1,2), 5, rtol=4e-10),
266
+
267
+ data(btdtri, 'ibeta_inv_data_ipp-ibeta_inv_data',
268
+ (0,1,2), 3, rtol=1e-5),
269
+ data(btdtri_comp, 'ibeta_inv_data_ipp-ibeta_inv_data',
270
+ (0,1,2), 4, rtol=8e-7),
271
+
272
+ data(btdtria, 'ibeta_inva_data_ipp-ibeta_inva_data',
273
+ (2,0,1), 3, rtol=5e-9),
274
+ data(btdtria_comp, 'ibeta_inva_data_ipp-ibeta_inva_data',
275
+ (2,0,1), 4, rtol=5e-9),
276
+
277
+ data(btdtrib, 'ibeta_inva_data_ipp-ibeta_inva_data',
278
+ (0,2,1), 5, rtol=5e-9),
279
+ data(btdtrib_comp, 'ibeta_inva_data_ipp-ibeta_inva_data',
280
+ (0,2,1), 6, rtol=5e-9),
281
+
282
+ data(binom, 'binomial_data_ipp-binomial_data',
283
+ (0,1), 2, rtol=1e-13),
284
+ data(binom, 'binomial_large_data_ipp-binomial_large_data',
285
+ (0,1), 2, rtol=5e-13),
286
+
287
+ data(bdtrik, 'binomial_quantile_ipp-binomial_quantile_data',
288
+ (2,0,1), 3, rtol=5e-9),
289
+ data(bdtrik_comp, 'binomial_quantile_ipp-binomial_quantile_data',
290
+ (2,0,1), 4, rtol=5e-9),
291
+
292
+ data(nbdtrik, 'negative_binomial_quantile_ipp-negative_binomial_quantile_data',
293
+ (2,0,1), 3, rtol=4e-9),
294
+ data(nbdtrik_comp,
295
+ 'negative_binomial_quantile_ipp-negative_binomial_quantile_data',
296
+ (2,0,1), 4, rtol=4e-9),
297
+
298
+ data(pdtrik, 'poisson_quantile_ipp-poisson_quantile_data',
299
+ (1,0), 2, rtol=3e-9),
300
+ data(pdtrik_comp, 'poisson_quantile_ipp-poisson_quantile_data',
301
+ (1,0), 3, rtol=4e-9),
302
+
303
+ data(cbrt, 'cbrt_data_ipp-cbrt_data', 1, 0),
304
+
305
+ data(digamma, 'digamma_data_ipp-digamma_data', 0, 1),
306
+ data(digamma, 'digamma_data_ipp-digamma_data', 0j, 1),
307
+ data(digamma, 'digamma_neg_data_ipp-digamma_neg_data', 0, 1, rtol=2e-13),
308
+ data(digamma, 'digamma_neg_data_ipp-digamma_neg_data', 0j, 1, rtol=1e-13),
309
+ data(digamma, 'digamma_root_data_ipp-digamma_root_data', 0, 1, rtol=1e-15),
310
+ data(digamma, 'digamma_root_data_ipp-digamma_root_data', 0j, 1, rtol=1e-15),
311
+ data(digamma, 'digamma_small_data_ipp-digamma_small_data', 0, 1, rtol=1e-15),
312
+ data(digamma, 'digamma_small_data_ipp-digamma_small_data', 0j, 1, rtol=1e-14),
313
+
314
+ data(ellipk_, 'ellint_k_data_ipp-ellint_k_data', 0, 1),
315
+ data(ellipkinc_, 'ellint_f_data_ipp-ellint_f_data', (0,1), 2, rtol=1e-14),
316
+ data(ellipe_, 'ellint_e_data_ipp-ellint_e_data', 0, 1),
317
+ data(ellipeinc_, 'ellint_e2_data_ipp-ellint_e2_data', (0,1), 2, rtol=1e-14),
318
+
319
+ data(erf, 'erf_data_ipp-erf_data', 0, 1),
320
+ data(erf, 'erf_data_ipp-erf_data', 0j, 1, rtol=1e-13),
321
+ data(erfc, 'erf_data_ipp-erf_data', 0, 2, rtol=6e-15),
322
+ data(erf, 'erf_large_data_ipp-erf_large_data', 0, 1),
323
+ data(erf, 'erf_large_data_ipp-erf_large_data', 0j, 1),
324
+ data(erfc, 'erf_large_data_ipp-erf_large_data', 0, 2, rtol=4e-14),
325
+ data(erf, 'erf_small_data_ipp-erf_small_data', 0, 1),
326
+ data(erf, 'erf_small_data_ipp-erf_small_data', 0j, 1, rtol=1e-13),
327
+ data(erfc, 'erf_small_data_ipp-erf_small_data', 0, 2),
328
+
329
+ data(erfinv, 'erf_inv_data_ipp-erf_inv_data', 0, 1),
330
+ data(erfcinv, 'erfc_inv_data_ipp-erfc_inv_data', 0, 1),
331
+ data(erfcinv, 'erfc_inv_big_data_ipp-erfc_inv_big_data', 0, 1,
332
+ param_filter=(lambda s: s > 0)),
333
+
334
+ data(exp1, 'expint_1_data_ipp-expint_1_data', 1, 2, rtol=1e-13),
335
+ data(exp1, 'expint_1_data_ipp-expint_1_data', 1j, 2, rtol=5e-9),
336
+ data(expi, 'expinti_data_ipp-expinti_data', 0, 1, rtol=1e-13),
337
+ data(expi, 'expinti_data_double_ipp-expinti_data_double', 0, 1, rtol=1e-13),
338
+ data(expi, 'expinti_data_long_ipp-expinti_data_long', 0, 1),
339
+
340
+ data(expn, 'expint_small_data_ipp-expint_small_data', (0,1), 2),
341
+ data(expn, 'expint_data_ipp-expint_data', (0,1), 2, rtol=1e-14),
342
+
343
+ data(gamma, 'test_gamma_data_ipp-near_0', 0, 1),
344
+ data(gamma, 'test_gamma_data_ipp-near_1', 0, 1),
345
+ data(gamma, 'test_gamma_data_ipp-near_2', 0, 1),
346
+ data(gamma, 'test_gamma_data_ipp-near_m10', 0, 1),
347
+ data(gamma, 'test_gamma_data_ipp-near_m55', 0, 1, rtol=7e-12),
348
+ data(gamma, 'test_gamma_data_ipp-factorials', 0, 1, rtol=4e-14),
349
+ data(gamma, 'test_gamma_data_ipp-near_0', 0j, 1, rtol=2e-9),
350
+ data(gamma, 'test_gamma_data_ipp-near_1', 0j, 1, rtol=2e-9),
351
+ data(gamma, 'test_gamma_data_ipp-near_2', 0j, 1, rtol=2e-9),
352
+ data(gamma, 'test_gamma_data_ipp-near_m10', 0j, 1, rtol=2e-9),
353
+ data(gamma, 'test_gamma_data_ipp-near_m55', 0j, 1, rtol=2e-9),
354
+ data(gamma, 'test_gamma_data_ipp-factorials', 0j, 1, rtol=2e-13),
355
+ data(gammaln, 'test_gamma_data_ipp-near_0', 0, 2, rtol=5e-11),
356
+ data(gammaln, 'test_gamma_data_ipp-near_1', 0, 2, rtol=5e-11),
357
+ data(gammaln, 'test_gamma_data_ipp-near_2', 0, 2, rtol=2e-10),
358
+ data(gammaln, 'test_gamma_data_ipp-near_m10', 0, 2, rtol=5e-11),
359
+ data(gammaln, 'test_gamma_data_ipp-near_m55', 0, 2, rtol=5e-11),
360
+ data(gammaln, 'test_gamma_data_ipp-factorials', 0, 2),
361
+
362
+ data(gammainc, 'igamma_small_data_ipp-igamma_small_data', (0,1), 5, rtol=5e-15),
363
+ data(gammainc, 'igamma_med_data_ipp-igamma_med_data', (0,1), 5, rtol=2e-13),
364
+ data(gammainc, 'igamma_int_data_ipp-igamma_int_data', (0,1), 5, rtol=2e-13),
365
+ data(gammainc, 'igamma_big_data_ipp-igamma_big_data', (0,1), 5, rtol=1e-12),
366
+
367
+ data(gdtr_, 'igamma_small_data_ipp-igamma_small_data', (0,1), 5, rtol=1e-13),
368
+ data(gdtr_, 'igamma_med_data_ipp-igamma_med_data', (0,1), 5, rtol=2e-13),
369
+ data(gdtr_, 'igamma_int_data_ipp-igamma_int_data', (0,1), 5, rtol=2e-13),
370
+ data(gdtr_, 'igamma_big_data_ipp-igamma_big_data', (0,1), 5, rtol=2e-9),
371
+
372
+ data(gammaincc, 'igamma_small_data_ipp-igamma_small_data',
373
+ (0,1), 3, rtol=1e-13),
374
+ data(gammaincc, 'igamma_med_data_ipp-igamma_med_data',
375
+ (0,1), 3, rtol=2e-13),
376
+ data(gammaincc, 'igamma_int_data_ipp-igamma_int_data',
377
+ (0,1), 3, rtol=4e-14),
378
+ data(gammaincc, 'igamma_big_data_ipp-igamma_big_data',
379
+ (0,1), 3, rtol=1e-11),
380
+
381
+ data(gdtrc_, 'igamma_small_data_ipp-igamma_small_data', (0,1), 3, rtol=1e-13),
382
+ data(gdtrc_, 'igamma_med_data_ipp-igamma_med_data', (0,1), 3, rtol=2e-13),
383
+ data(gdtrc_, 'igamma_int_data_ipp-igamma_int_data', (0,1), 3, rtol=4e-14),
384
+ data(gdtrc_, 'igamma_big_data_ipp-igamma_big_data', (0,1), 3, rtol=1e-11),
385
+
386
+ data(gdtrib_, 'igamma_inva_data_ipp-igamma_inva_data', (1,0), 2, rtol=5e-9),
387
+ data(gdtrib_comp, 'igamma_inva_data_ipp-igamma_inva_data', (1,0), 3, rtol=5e-9),
388
+
389
+ data(poch_, 'tgamma_delta_ratio_data_ipp-tgamma_delta_ratio_data',
390
+ (0,1), 2, rtol=2e-13),
391
+ data(poch_, 'tgamma_delta_ratio_int_ipp-tgamma_delta_ratio_int',
392
+ (0,1), 2,),
393
+ data(poch_, 'tgamma_delta_ratio_int2_ipp-tgamma_delta_ratio_int2',
394
+ (0,1), 2,),
395
+ data(poch_minus, 'tgamma_delta_ratio_data_ipp-tgamma_delta_ratio_data',
396
+ (0,1), 3, rtol=2e-13),
397
+ data(poch_minus, 'tgamma_delta_ratio_int_ipp-tgamma_delta_ratio_int',
398
+ (0,1), 3),
399
+ data(poch_minus, 'tgamma_delta_ratio_int2_ipp-tgamma_delta_ratio_int2',
400
+ (0,1), 3),
401
+
402
+ data(eval_hermite_ld, 'hermite_ipp-hermite',
403
+ (0,1), 2, rtol=2e-14),
404
+
405
+ data(eval_laguerre_ld, 'laguerre2_ipp-laguerre2',
406
+ (0,1), 2, rtol=7e-12),
407
+ data(eval_laguerre_dd, 'laguerre2_ipp-laguerre2',
408
+ (0,1), 2, knownfailure='hyp2f1 insufficiently accurate.'),
409
+ data(eval_genlaguerre_ldd, 'laguerre3_ipp-laguerre3',
410
+ (0,1,2), 3, rtol=2e-13),
411
+ data(eval_genlaguerre_ddd, 'laguerre3_ipp-laguerre3',
412
+ (0,1,2), 3, knownfailure='hyp2f1 insufficiently accurate.'),
413
+
414
+ data(log1p, 'log1p_expm1_data_ipp-log1p_expm1_data', 0, 1),
415
+ data(expm1, 'log1p_expm1_data_ipp-log1p_expm1_data', 0, 2),
416
+
417
+ data(iv, 'bessel_i_data_ipp-bessel_i_data',
418
+ (0,1), 2, rtol=1e-12),
419
+ data(iv, 'bessel_i_data_ipp-bessel_i_data',
420
+ (0,1j), 2, rtol=2e-10, atol=1e-306),
421
+ data(iv, 'bessel_i_int_data_ipp-bessel_i_int_data',
422
+ (0,1), 2, rtol=1e-9),
423
+ data(iv, 'bessel_i_int_data_ipp-bessel_i_int_data',
424
+ (0,1j), 2, rtol=2e-10),
425
+
426
+ data(ivp, 'bessel_i_prime_int_data_ipp-bessel_i_prime_int_data',
427
+ (0,1), 2, rtol=1.2e-13),
428
+ data(ivp, 'bessel_i_prime_int_data_ipp-bessel_i_prime_int_data',
429
+ (0,1j), 2, rtol=1.2e-13, atol=1e-300),
430
+
431
+ data(jn, 'bessel_j_int_data_ipp-bessel_j_int_data', (0,1), 2, rtol=1e-12),
432
+ data(jn, 'bessel_j_int_data_ipp-bessel_j_int_data', (0,1j), 2, rtol=1e-12),
433
+ data(jn, 'bessel_j_large_data_ipp-bessel_j_large_data', (0,1), 2, rtol=6e-11),
434
+ data(jn, 'bessel_j_large_data_ipp-bessel_j_large_data', (0,1j), 2, rtol=6e-11),
435
+
436
+ data(jv, 'bessel_j_int_data_ipp-bessel_j_int_data', (0,1), 2, rtol=1e-12),
437
+ data(jv, 'bessel_j_int_data_ipp-bessel_j_int_data', (0,1j), 2, rtol=1e-12),
438
+ data(jv, 'bessel_j_data_ipp-bessel_j_data', (0,1), 2, rtol=1e-12),
439
+ data(jv, 'bessel_j_data_ipp-bessel_j_data', (0,1j), 2, rtol=1e-12),
440
+
441
+ data(jvp, 'bessel_j_prime_int_data_ipp-bessel_j_prime_int_data',
442
+ (0,1), 2, rtol=1e-13),
443
+ data(jvp, 'bessel_j_prime_int_data_ipp-bessel_j_prime_int_data',
444
+ (0,1j), 2, rtol=1e-13),
445
+ data(jvp, 'bessel_j_prime_large_data_ipp-bessel_j_prime_large_data',
446
+ (0,1), 2, rtol=1e-11),
447
+ data(jvp, 'bessel_j_prime_large_data_ipp-bessel_j_prime_large_data',
448
+ (0,1j), 2, rtol=2e-11),
449
+
450
+ data(kn, 'bessel_k_int_data_ipp-bessel_k_int_data', (0,1), 2, rtol=1e-12),
451
+
452
+ data(kv, 'bessel_k_int_data_ipp-bessel_k_int_data', (0,1), 2, rtol=1e-12),
453
+ data(kv, 'bessel_k_int_data_ipp-bessel_k_int_data', (0,1j), 2, rtol=1e-12),
454
+ data(kv, 'bessel_k_data_ipp-bessel_k_data', (0,1), 2, rtol=1e-12),
455
+ data(kv, 'bessel_k_data_ipp-bessel_k_data', (0,1j), 2, rtol=1e-12),
456
+
457
+ data(kvp, 'bessel_k_prime_int_data_ipp-bessel_k_prime_int_data',
458
+ (0,1), 2, rtol=3e-14),
459
+ data(kvp, 'bessel_k_prime_int_data_ipp-bessel_k_prime_int_data',
460
+ (0,1j), 2, rtol=3e-14),
461
+ data(kvp, 'bessel_k_prime_data_ipp-bessel_k_prime_data', (0,1), 2, rtol=7e-14),
462
+ data(kvp, 'bessel_k_prime_data_ipp-bessel_k_prime_data', (0,1j), 2, rtol=7e-14),
463
+
464
+ data(yn, 'bessel_y01_data_ipp-bessel_y01_data', (0,1), 2, rtol=1e-12),
465
+ data(yn, 'bessel_yn_data_ipp-bessel_yn_data', (0,1), 2, rtol=1e-12),
466
+
467
+ data(yv, 'bessel_yn_data_ipp-bessel_yn_data', (0,1), 2, rtol=1e-12),
468
+ data(yv, 'bessel_yn_data_ipp-bessel_yn_data', (0,1j), 2, rtol=1e-12),
469
+ data(yv, 'bessel_yv_data_ipp-bessel_yv_data', (0,1), 2, rtol=1e-10),
470
+ data(yv, 'bessel_yv_data_ipp-bessel_yv_data', (0,1j), 2, rtol=1e-10),
471
+
472
+ data(yvp, 'bessel_yv_prime_data_ipp-bessel_yv_prime_data',
473
+ (0, 1), 2, rtol=4e-9),
474
+ data(yvp, 'bessel_yv_prime_data_ipp-bessel_yv_prime_data',
475
+ (0, 1j), 2, rtol=4e-9),
476
+
477
+ data(zeta_, 'zeta_data_ipp-zeta_data', 0, 1,
478
+ param_filter=(lambda s: s > 1)),
479
+ data(zeta_, 'zeta_neg_data_ipp-zeta_neg_data', 0, 1,
480
+ param_filter=(lambda s: s > 1)),
481
+ data(zeta_, 'zeta_1_up_data_ipp-zeta_1_up_data', 0, 1,
482
+ param_filter=(lambda s: s > 1)),
483
+ data(zeta_, 'zeta_1_below_data_ipp-zeta_1_below_data', 0, 1,
484
+ param_filter=(lambda s: s > 1)),
485
+
486
+ data(gammaincinv, 'gamma_inv_small_data_ipp-gamma_inv_small_data',
487
+ (0,1), 2, rtol=1e-11),
488
+ data(gammaincinv, 'gamma_inv_data_ipp-gamma_inv_data',
489
+ (0,1), 2, rtol=1e-14),
490
+ data(gammaincinv, 'gamma_inv_big_data_ipp-gamma_inv_big_data',
491
+ (0,1), 2, rtol=1e-11),
492
+
493
+ data(gammainccinv, 'gamma_inv_small_data_ipp-gamma_inv_small_data',
494
+ (0,1), 3, rtol=1e-12),
495
+ data(gammainccinv, 'gamma_inv_data_ipp-gamma_inv_data',
496
+ (0,1), 3, rtol=1e-14),
497
+ data(gammainccinv, 'gamma_inv_big_data_ipp-gamma_inv_big_data',
498
+ (0,1), 3, rtol=1e-14),
499
+
500
+ data(gdtrix_, 'gamma_inv_small_data_ipp-gamma_inv_small_data',
501
+ (0,1), 2, rtol=3e-13, knownfailure='gdtrix unflow some points'),
502
+ data(gdtrix_, 'gamma_inv_data_ipp-gamma_inv_data',
503
+ (0,1), 2, rtol=3e-15),
504
+ data(gdtrix_, 'gamma_inv_big_data_ipp-gamma_inv_big_data',
505
+ (0,1), 2),
506
+ data(gdtrix_comp, 'gamma_inv_small_data_ipp-gamma_inv_small_data',
507
+ (0,1), 2, knownfailure='gdtrix bad some points'),
508
+ data(gdtrix_comp, 'gamma_inv_data_ipp-gamma_inv_data',
509
+ (0,1), 3, rtol=6e-15),
510
+ data(gdtrix_comp, 'gamma_inv_big_data_ipp-gamma_inv_big_data',
511
+ (0,1), 3),
512
+
513
+ data(chndtr, 'nccs_ipp-nccs',
514
+ (2,0,1), 3, rtol=3e-5),
515
+ data(chndtr, 'nccs_big_ipp-nccs_big',
516
+ (2,0,1), 3, rtol=5e-4, knownfailure='chndtr inaccurate some points'),
517
+
518
+ data(sph_harm_, 'spherical_harmonic_ipp-spherical_harmonic',
519
+ (1,0,3,2), (4,5), rtol=5e-11,
520
+ param_filter=(lambda p: np.ones(p.shape, '?'),
521
+ lambda p: np.ones(p.shape, '?'),
522
+ lambda p: np.logical_and(p < 2*np.pi, p >= 0),
523
+ lambda p: np.logical_and(p < np.pi, p >= 0))),
524
+
525
+ data(spherical_jn_, 'sph_bessel_data_ipp-sph_bessel_data',
526
+ (0,1), 2, rtol=1e-13),
527
+ data(spherical_yn_, 'sph_neumann_data_ipp-sph_neumann_data',
528
+ (0,1), 2, rtol=8e-15),
529
+
530
+ data(owens_t, 'owens_t_ipp-owens_t',
531
+ (0, 1), 2, rtol=5e-14),
532
+ data(owens_t, 'owens_t_large_data_ipp-owens_t_large_data',
533
+ (0, 1), 2, rtol=8e-12),
534
+
535
+ # -- test data exists in boost but is not used in scipy --
536
+
537
+ # ibeta_derivative_data_ipp/ibeta_derivative_data.txt
538
+ # ibeta_derivative_int_data_ipp/ibeta_derivative_int_data.txt
539
+ # ibeta_derivative_large_data_ipp/ibeta_derivative_large_data.txt
540
+ # ibeta_derivative_small_data_ipp/ibeta_derivative_small_data.txt
541
+
542
+ # bessel_y01_prime_data_ipp/bessel_y01_prime_data.txt
543
+ # bessel_yn_prime_data_ipp/bessel_yn_prime_data.txt
544
+ # sph_bessel_prime_data_ipp/sph_bessel_prime_data.txt
545
+ # sph_neumann_prime_data_ipp/sph_neumann_prime_data.txt
546
+
547
+ # ellint_d2_data_ipp/ellint_d2_data.txt
548
+ # ellint_d_data_ipp/ellint_d_data.txt
549
+ # ellint_pi2_data_ipp/ellint_pi2_data.txt
550
+ # ellint_pi3_data_ipp/ellint_pi3_data.txt
551
+ # ellint_pi3_large_data_ipp/ellint_pi3_large_data.txt
552
+ data(elliprc, 'ellint_rc_data_ipp-ellint_rc_data', (0, 1), 2,
553
+ rtol=5e-16),
554
+ data(elliprd, 'ellint_rd_data_ipp-ellint_rd_data', (0, 1, 2), 3,
555
+ rtol=5e-16),
556
+ data(elliprd, 'ellint_rd_0xy_ipp-ellint_rd_0xy', (0, 1, 2), 3,
557
+ rtol=5e-16),
558
+ data(elliprd, 'ellint_rd_0yy_ipp-ellint_rd_0yy', (0, 1, 2), 3,
559
+ rtol=5e-16),
560
+ data(elliprd, 'ellint_rd_xxx_ipp-ellint_rd_xxx', (0, 1, 2), 3,
561
+ rtol=5e-16),
562
+ # Some of the following rtol for elliprd may be larger than 5e-16 to
563
+ # work around some hard cases in the Boost test where we get slightly
564
+ # larger error than the ideal bound when the x (==y) input is close to
565
+ # zero.
566
+ # Also the accuracy on 32-bit builds with g++ may suffer from excess
567
+ # loss of precision; see GCC bugzilla 323
568
+ # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=323
569
+ data(elliprd, 'ellint_rd_xxz_ipp-ellint_rd_xxz', (0, 1, 2), 3,
570
+ rtol=6.5e-16),
571
+ data(elliprd, 'ellint_rd_xyy_ipp-ellint_rd_xyy', (0, 1, 2), 3,
572
+ rtol=6e-16),
573
+ data(elliprf, 'ellint_rf_data_ipp-ellint_rf_data', (0, 1, 2), 3,
574
+ rtol=5e-16),
575
+ data(elliprf, 'ellint_rf_xxx_ipp-ellint_rf_xxx', (0, 1, 2), 3,
576
+ rtol=5e-16),
577
+ data(elliprf, 'ellint_rf_xyy_ipp-ellint_rf_xyy', (0, 1, 2), 3,
578
+ rtol=5e-16),
579
+ data(elliprf, 'ellint_rf_xy0_ipp-ellint_rf_xy0', (0, 1, 2), 3,
580
+ rtol=5e-16),
581
+ data(elliprf, 'ellint_rf_0yy_ipp-ellint_rf_0yy', (0, 1, 2), 3,
582
+ rtol=5e-16),
583
+ # The accuracy of R_G is primarily limited by R_D that is used
584
+ # internally. It is generally worse than R_D. Notice that we increased
585
+ # the rtol for R_G here. The cases with duplicate arguments are
586
+ # slightly less likely to be unbalanced (at least two arguments are
587
+ # already balanced) so the error bound is slightly better. Again,
588
+ # precision with g++ 32-bit is even worse.
589
+ data(elliprg, 'ellint_rg_ipp-ellint_rg', (0, 1, 2), 3,
590
+ rtol=8.0e-16),
591
+ data(elliprg, 'ellint_rg_xxx_ipp-ellint_rg_xxx', (0, 1, 2), 3,
592
+ rtol=6e-16),
593
+ data(elliprg, 'ellint_rg_xyy_ipp-ellint_rg_xyy', (0, 1, 2), 3,
594
+ rtol=7.5e-16),
595
+ data(elliprg, 'ellint_rg_xy0_ipp-ellint_rg_xy0', (0, 1, 2), 3,
596
+ rtol=5e-16),
597
+ data(elliprg, 'ellint_rg_00x_ipp-ellint_rg_00x', (0, 1, 2), 3,
598
+ rtol=5e-16),
599
+ data(elliprj, 'ellint_rj_data_ipp-ellint_rj_data', (0, 1, 2, 3), 4,
600
+ rtol=5e-16, atol=1e-25,
601
+ param_filter=(lambda s: s <= 5e-26,)),
602
+ # ellint_rc_data_ipp/ellint_rc_data.txt
603
+ # ellint_rd_0xy_ipp/ellint_rd_0xy.txt
604
+ # ellint_rd_0yy_ipp/ellint_rd_0yy.txt
605
+ # ellint_rd_data_ipp/ellint_rd_data.txt
606
+ # ellint_rd_xxx_ipp/ellint_rd_xxx.txt
607
+ # ellint_rd_xxz_ipp/ellint_rd_xxz.txt
608
+ # ellint_rd_xyy_ipp/ellint_rd_xyy.txt
609
+ # ellint_rf_0yy_ipp/ellint_rf_0yy.txt
610
+ # ellint_rf_data_ipp/ellint_rf_data.txt
611
+ # ellint_rf_xxx_ipp/ellint_rf_xxx.txt
612
+ # ellint_rf_xy0_ipp/ellint_rf_xy0.txt
613
+ # ellint_rf_xyy_ipp/ellint_rf_xyy.txt
614
+ # ellint_rg_00x_ipp/ellint_rg_00x.txt
615
+ # ellint_rg_ipp/ellint_rg.txt
616
+ # ellint_rg_xxx_ipp/ellint_rg_xxx.txt
617
+ # ellint_rg_xy0_ipp/ellint_rg_xy0.txt
618
+ # ellint_rg_xyy_ipp/ellint_rg_xyy.txt
619
+ # ellint_rj_data_ipp/ellint_rj_data.txt
620
+ # ellint_rj_e2_ipp/ellint_rj_e2.txt
621
+ # ellint_rj_e3_ipp/ellint_rj_e3.txt
622
+ # ellint_rj_e4_ipp/ellint_rj_e4.txt
623
+ # ellint_rj_zp_ipp/ellint_rj_zp.txt
624
+
625
+ # jacobi_elliptic_ipp/jacobi_elliptic.txt
626
+ # jacobi_elliptic_small_ipp/jacobi_elliptic_small.txt
627
+ # jacobi_large_phi_ipp/jacobi_large_phi.txt
628
+ # jacobi_near_1_ipp/jacobi_near_1.txt
629
+ # jacobi_zeta_big_phi_ipp/jacobi_zeta_big_phi.txt
630
+ # jacobi_zeta_data_ipp/jacobi_zeta_data.txt
631
+
632
+ # heuman_lambda_data_ipp/heuman_lambda_data.txt
633
+
634
+ # hypergeometric_0F2_ipp/hypergeometric_0F2.txt
635
+ # hypergeometric_1F1_big_ipp/hypergeometric_1F1_big.txt
636
+ # hypergeometric_1F1_ipp/hypergeometric_1F1.txt
637
+ # hypergeometric_1F1_small_random_ipp/hypergeometric_1F1_small_random.txt
638
+ # hypergeometric_1F2_ipp/hypergeometric_1F2.txt
639
+ # hypergeometric_1f1_large_regularized_ipp/hypergeometric_1f1_large_regularized.txt # noqa: E501
640
+ # hypergeometric_1f1_log_large_unsolved_ipp/hypergeometric_1f1_log_large_unsolved.txt # noqa: E501
641
+ # hypergeometric_2F0_half_ipp/hypergeometric_2F0_half.txt
642
+ # hypergeometric_2F0_integer_a2_ipp/hypergeometric_2F0_integer_a2.txt
643
+ # hypergeometric_2F0_ipp/hypergeometric_2F0.txt
644
+ # hypergeometric_2F0_large_z_ipp/hypergeometric_2F0_large_z.txt
645
+ # hypergeometric_2F1_ipp/hypergeometric_2F1.txt
646
+ # hypergeometric_2F2_ipp/hypergeometric_2F2.txt
647
+
648
+ # ncbeta_big_ipp/ncbeta_big.txt
649
+ # nct_small_delta_ipp/nct_small_delta.txt
650
+ # nct_asym_ipp/nct_asym.txt
651
+ # ncbeta_ipp/ncbeta.txt
652
+
653
+ # powm1_data_ipp/powm1_big_data.txt
654
+ # powm1_sqrtp1m1_test_hpp/sqrtp1m1_data.txt
655
+
656
+ # sinc_data_ipp/sinc_data.txt
657
+
658
+ # test_gamma_data_ipp/gammap1m1_data.txt
659
+ # tgamma_ratio_data_ipp/tgamma_ratio_data.txt
660
+
661
+ # trig_data_ipp/trig_data.txt
662
+ # trig_data2_ipp/trig_data2.txt
663
+ ]
664
+
665
+
666
+ @pytest.mark.parametrize('test', BOOST_TESTS, ids=repr)
667
+ def test_boost(test):
668
+ # Filter deprecation warnings of any deprecated functions.
669
+ if test.func in [btdtr, btdtri, btdtri_comp]:
670
+ with pytest.deprecated_call():
671
+ _test_factory(test)
672
+ else:
673
+ _test_factory(test)
674
+
675
+
676
+ GSL_TESTS = [
677
+ data_gsl(mathieu_a, 'mathieu_ab', (0, 1), 2, rtol=1e-13, atol=1e-13),
678
+ data_gsl(mathieu_b, 'mathieu_ab', (0, 1), 3, rtol=1e-13, atol=1e-13),
679
+
680
+ # Also the GSL output has limited accuracy...
681
+ data_gsl(mathieu_ce_rad, 'mathieu_ce_se', (0, 1, 2), 3, rtol=1e-7, atol=1e-13),
682
+ data_gsl(mathieu_se_rad, 'mathieu_ce_se', (0, 1, 2), 4, rtol=1e-7, atol=1e-13),
683
+
684
+ data_gsl(mathieu_mc1_scaled, 'mathieu_mc_ms',
685
+ (0, 1, 2), 3, rtol=1e-7, atol=1e-13),
686
+ data_gsl(mathieu_ms1_scaled, 'mathieu_mc_ms',
687
+ (0, 1, 2), 4, rtol=1e-7, atol=1e-13),
688
+
689
+ data_gsl(mathieu_mc2_scaled, 'mathieu_mc_ms',
690
+ (0, 1, 2), 5, rtol=1e-7, atol=1e-13),
691
+ data_gsl(mathieu_ms2_scaled, 'mathieu_mc_ms',
692
+ (0, 1, 2), 6, rtol=1e-7, atol=1e-13),
693
+ ]
694
+
695
+
696
+ @pytest.mark.parametrize('test', GSL_TESTS, ids=repr)
697
+ def test_gsl(test):
698
+ _test_factory(test)
699
+
700
+
701
+ LOCAL_TESTS = [
702
+ data_local(ellipkinc, 'ellipkinc_neg_m', (0, 1), 2),
703
+ data_local(ellipkm1, 'ellipkm1', 0, 1),
704
+ data_local(ellipeinc, 'ellipeinc_neg_m', (0, 1), 2),
705
+ data_local(clog1p, 'log1p_expm1_complex', (0,1), (2,3), rtol=1e-14),
706
+ data_local(cexpm1, 'log1p_expm1_complex', (0,1), (4,5), rtol=1e-14),
707
+ data_local(gammainc, 'gammainc', (0, 1), 2, rtol=1e-12),
708
+ data_local(gammaincc, 'gammaincc', (0, 1), 2, rtol=1e-11),
709
+ data_local(ellip_harm_2, 'ellip',(0, 1, 2, 3, 4), 6, rtol=1e-10, atol=1e-13),
710
+ data_local(ellip_harm, 'ellip',(0, 1, 2, 3, 4), 5, rtol=1e-10, atol=1e-13),
711
+ data_local(wright_bessel, 'wright_bessel', (0, 1, 2), 3, rtol=1e-11),
712
+ ]
713
+
714
+
715
+ @pytest.mark.parametrize('test', LOCAL_TESTS, ids=repr)
716
+ def test_local(test):
717
+ _test_factory(test)
718
+
719
+
720
+ def _test_factory(test, dtype=np.float64):
721
+ """Boost test"""
722
+ with suppress_warnings() as sup:
723
+ sup.filter(IntegrationWarning, "The occurrence of roundoff error is detected")
724
+ with np.errstate(all='ignore'):
725
+ test.check(dtype=dtype)
openflamingo/lib/python3.10/site-packages/scipy/special/tests/test_dd.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Tests for a few of the "double-double" C functions defined in cephes/dd_*.
2
+
3
+ import pytest
4
+ from numpy.testing import assert_allclose
5
+ from scipy.special._test_internal import _dd_exp, _dd_log, _dd_expm1
6
+
7
+
8
+ # Each tuple in test_data contains:
9
+ # (dd_func, xhi, xlo, expected_yhi, expected_ylo)
10
+ # The expected values were computed with mpmath, e.g.
11
+ #
12
+ # import mpmath
13
+ # mpmath.mp.dps = 100
14
+ # xhi = 10.0
15
+ # xlo = 0.0
16
+ # x = mpmath.mpf(xhi) + mpmath.mpf(xlo)
17
+ # y = mpmath.log(x)
18
+ # expected_yhi = float(y)
19
+ # expected_ylo = float(y - expected_yhi)
20
+ #
21
+ test_data = [
22
+ (_dd_exp, -0.3333333333333333, -1.850371707708594e-17,
23
+ 0.7165313105737893, -2.0286948382455594e-17),
24
+ (_dd_exp, 0.0, 0.0, 1.0, 0.0),
25
+ (_dd_exp, 10.0, 0.0, 22026.465794806718, -1.3780134700517372e-12),
26
+ (_dd_log, 0.03125, 0.0, -3.4657359027997265, -4.930038229799327e-18),
27
+ (_dd_log, 10.0, 0.0, 2.302585092994046, -2.1707562233822494e-16),
28
+ (_dd_expm1, -1.25, 0.0, -0.7134952031398099, -4.7031321153650186e-17),
29
+ (_dd_expm1, -0.484375, 0.0, -0.3839178722093218, 7.609376052156984e-18),
30
+ (_dd_expm1, -0.25, 0.0, -0.22119921692859512, -1.0231869534531498e-17),
31
+ (_dd_expm1, -0.0625, 0.0, -0.06058693718652421, -7.077887227488846e-19),
32
+ (_dd_expm1, 0.0, 0.0, 0.0, 0.0),
33
+ (_dd_expm1, 0.0625, 3.5e-18, 0.06449445891785943, 1.4323095758164254e-18),
34
+ (_dd_expm1, 0.25, 0.0, 0.2840254166877415, -2.133257464457841e-17),
35
+ (_dd_expm1, 0.498046875, 0.0, 0.645504254608231, -9.198435524984236e-18),
36
+ (_dd_expm1, 1.25, 0.0, 2.4903429574618414, -4.604261945372796e-17)
37
+ ]
38
+
39
+
40
+ @pytest.mark.parametrize('dd_func, xhi, xlo, expected_yhi, expected_ylo',
41
+ test_data)
42
+ def test_dd(dd_func, xhi, xlo, expected_yhi, expected_ylo):
43
+ yhi, ylo = dd_func(xhi, xlo)
44
+ assert yhi == expected_yhi, (f"high double ({yhi}) does not equal the "
45
+ f"expected value {expected_yhi}")
46
+ assert_allclose(ylo, expected_ylo, rtol=5e-15)
openflamingo/lib/python3.10/site-packages/scipy/special/tests/test_digamma.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ from numpy import pi, log, sqrt
3
+ from numpy.testing import assert_, assert_equal
4
+
5
+ from scipy.special._testutils import FuncData
6
+ import scipy.special as sc
7
+
8
+ # Euler-Mascheroni constant
9
+ euler = 0.57721566490153286
10
+
11
+
12
+ def test_consistency():
13
+ # Make sure the implementation of digamma for real arguments
14
+ # agrees with the implementation of digamma for complex arguments.
15
+
16
+ # It's all poles after -1e16
17
+ x = np.r_[-np.logspace(15, -30, 200), np.logspace(-30, 300, 200)]
18
+ dataset = np.vstack((x + 0j, sc.digamma(x))).T
19
+ FuncData(sc.digamma, dataset, 0, 1, rtol=5e-14, nan_ok=True).check()
20
+
21
+
22
+ def test_special_values():
23
+ # Test special values from Gauss's digamma theorem. See
24
+ #
25
+ # https://en.wikipedia.org/wiki/Digamma_function
26
+
27
+ dataset = [
28
+ (1, -euler),
29
+ (0.5, -2*log(2) - euler),
30
+ (1/3, -pi/(2*sqrt(3)) - 3*log(3)/2 - euler),
31
+ (1/4, -pi/2 - 3*log(2) - euler),
32
+ (1/6, -pi*sqrt(3)/2 - 2*log(2) - 3*log(3)/2 - euler),
33
+ (1/8,
34
+ -pi/2 - 4*log(2) - (pi + log(2 + sqrt(2)) - log(2 - sqrt(2)))/sqrt(2) - euler)
35
+ ]
36
+
37
+ dataset = np.asarray(dataset)
38
+ FuncData(sc.digamma, dataset, 0, 1, rtol=1e-14).check()
39
+
40
+
41
+ def test_nonfinite():
42
+ pts = [0.0, -0.0, np.inf]
43
+ std = [-np.inf, np.inf, np.inf]
44
+ assert_equal(sc.digamma(pts), std)
45
+ assert_(all(np.isnan(sc.digamma([-np.inf, -1]))))
openflamingo/lib/python3.10/site-packages/scipy/special/tests/test_ellip_harm.py ADDED
@@ -0,0 +1,278 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #
2
+ # Tests for the Ellipsoidal Harmonic Function,
3
+ # Distributed under the same license as SciPy itself.
4
+ #
5
+
6
+ import numpy as np
7
+ from numpy.testing import (assert_equal, assert_almost_equal, assert_allclose,
8
+ assert_, suppress_warnings)
9
+ from scipy.special._testutils import assert_func_equal
10
+ from scipy.special import ellip_harm, ellip_harm_2, ellip_normal
11
+ from scipy.integrate import IntegrationWarning
12
+ from numpy import sqrt, pi
13
+
14
+
15
+ def test_ellip_potential():
16
+ def change_coefficient(lambda1, mu, nu, h2, k2):
17
+ x = sqrt(lambda1**2*mu**2*nu**2/(h2*k2))
18
+ y = sqrt((lambda1**2 - h2)*(mu**2 - h2)*(h2 - nu**2)/(h2*(k2 - h2)))
19
+ z = sqrt((lambda1**2 - k2)*(k2 - mu**2)*(k2 - nu**2)/(k2*(k2 - h2)))
20
+ return x, y, z
21
+
22
+ def solid_int_ellip(lambda1, mu, nu, n, p, h2, k2):
23
+ return (ellip_harm(h2, k2, n, p, lambda1)*ellip_harm(h2, k2, n, p, mu)
24
+ * ellip_harm(h2, k2, n, p, nu))
25
+
26
+ def solid_int_ellip2(lambda1, mu, nu, n, p, h2, k2):
27
+ return (ellip_harm_2(h2, k2, n, p, lambda1)
28
+ * ellip_harm(h2, k2, n, p, mu)*ellip_harm(h2, k2, n, p, nu))
29
+
30
+ def summation(lambda1, mu1, nu1, lambda2, mu2, nu2, h2, k2):
31
+ tol = 1e-8
32
+ sum1 = 0
33
+ for n in range(20):
34
+ xsum = 0
35
+ for p in range(1, 2*n+2):
36
+ xsum += (4*pi*(solid_int_ellip(lambda2, mu2, nu2, n, p, h2, k2)
37
+ * solid_int_ellip2(lambda1, mu1, nu1, n, p, h2, k2)) /
38
+ (ellip_normal(h2, k2, n, p)*(2*n + 1)))
39
+ if abs(xsum) < 0.1*tol*abs(sum1):
40
+ break
41
+ sum1 += xsum
42
+ return sum1, xsum
43
+
44
+ def potential(lambda1, mu1, nu1, lambda2, mu2, nu2, h2, k2):
45
+ x1, y1, z1 = change_coefficient(lambda1, mu1, nu1, h2, k2)
46
+ x2, y2, z2 = change_coefficient(lambda2, mu2, nu2, h2, k2)
47
+ res = sqrt((x2 - x1)**2 + (y2 - y1)**2 + (z2 - z1)**2)
48
+ return 1/res
49
+
50
+ pts = [
51
+ (120, sqrt(19), 2, 41, sqrt(17), 2, 15, 25),
52
+ (120, sqrt(16), 3.2, 21, sqrt(11), 2.9, 11, 20),
53
+ ]
54
+
55
+ with suppress_warnings() as sup:
56
+ sup.filter(IntegrationWarning, "The occurrence of roundoff error")
57
+ sup.filter(IntegrationWarning, "The maximum number of subdivisions")
58
+
59
+ for p in pts:
60
+ err_msg = repr(p)
61
+ exact = potential(*p)
62
+ result, last_term = summation(*p)
63
+ assert_allclose(exact, result, atol=0, rtol=1e-8, err_msg=err_msg)
64
+ assert_(abs(result - exact) < 10*abs(last_term), err_msg)
65
+
66
+
67
+ def test_ellip_norm():
68
+
69
+ def G01(h2, k2):
70
+ return 4*pi
71
+
72
+ def G11(h2, k2):
73
+ return 4*pi*h2*k2/3
74
+
75
+ def G12(h2, k2):
76
+ return 4*pi*h2*(k2 - h2)/3
77
+
78
+ def G13(h2, k2):
79
+ return 4*pi*k2*(k2 - h2)/3
80
+
81
+ def G22(h2, k2):
82
+ res = (2*(h2**4 + k2**4) - 4*h2*k2*(h2**2 + k2**2) + 6*h2**2*k2**2 +
83
+ sqrt(h2**2 + k2**2 - h2*k2)*(-2*(h2**3 + k2**3) + 3*h2*k2*(h2 + k2)))
84
+ return 16*pi/405*res
85
+
86
+ def G21(h2, k2):
87
+ res = (2*(h2**4 + k2**4) - 4*h2*k2*(h2**2 + k2**2) + 6*h2**2*k2**2
88
+ + sqrt(h2**2 + k2**2 - h2*k2)*(2*(h2**3 + k2**3) - 3*h2*k2*(h2 + k2)))
89
+ return 16*pi/405*res
90
+
91
+ def G23(h2, k2):
92
+ return 4*pi*h2**2*k2*(k2 - h2)/15
93
+
94
+ def G24(h2, k2):
95
+ return 4*pi*h2*k2**2*(k2 - h2)/15
96
+
97
+ def G25(h2, k2):
98
+ return 4*pi*h2*k2*(k2 - h2)**2/15
99
+
100
+ def G32(h2, k2):
101
+ res = (16*(h2**4 + k2**4) - 36*h2*k2*(h2**2 + k2**2) + 46*h2**2*k2**2
102
+ + sqrt(4*(h2**2 + k2**2) - 7*h2*k2)*(-8*(h2**3 + k2**3) +
103
+ 11*h2*k2*(h2 + k2)))
104
+ return 16*pi/13125*k2*h2*res
105
+
106
+ def G31(h2, k2):
107
+ res = (16*(h2**4 + k2**4) - 36*h2*k2*(h2**2 + k2**2) + 46*h2**2*k2**2
108
+ + sqrt(4*(h2**2 + k2**2) - 7*h2*k2)*(8*(h2**3 + k2**3) -
109
+ 11*h2*k2*(h2 + k2)))
110
+ return 16*pi/13125*h2*k2*res
111
+
112
+ def G34(h2, k2):
113
+ res = (6*h2**4 + 16*k2**4 - 12*h2**3*k2 - 28*h2*k2**3 + 34*h2**2*k2**2
114
+ + sqrt(h2**2 + 4*k2**2 - h2*k2)*(-6*h2**3 - 8*k2**3 + 9*h2**2*k2 +
115
+ 13*h2*k2**2))
116
+ return 16*pi/13125*h2*(k2 - h2)*res
117
+
118
+ def G33(h2, k2):
119
+ res = (6*h2**4 + 16*k2**4 - 12*h2**3*k2 - 28*h2*k2**3 + 34*h2**2*k2**2
120
+ + sqrt(h2**2 + 4*k2**2 - h2*k2)*(6*h2**3 + 8*k2**3 - 9*h2**2*k2 -
121
+ 13*h2*k2**2))
122
+ return 16*pi/13125*h2*(k2 - h2)*res
123
+
124
+ def G36(h2, k2):
125
+ res = (16*h2**4 + 6*k2**4 - 28*h2**3*k2 - 12*h2*k2**3 + 34*h2**2*k2**2
126
+ + sqrt(4*h2**2 + k2**2 - h2*k2)*(-8*h2**3 - 6*k2**3 + 13*h2**2*k2 +
127
+ 9*h2*k2**2))
128
+ return 16*pi/13125*k2*(k2 - h2)*res
129
+
130
+ def G35(h2, k2):
131
+ res = (16*h2**4 + 6*k2**4 - 28*h2**3*k2 - 12*h2*k2**3 + 34*h2**2*k2**2
132
+ + sqrt(4*h2**2 + k2**2 - h2*k2)*(8*h2**3 + 6*k2**3 - 13*h2**2*k2 -
133
+ 9*h2*k2**2))
134
+ return 16*pi/13125*k2*(k2 - h2)*res
135
+
136
+ def G37(h2, k2):
137
+ return 4*pi*h2**2*k2**2*(k2 - h2)**2/105
138
+
139
+ known_funcs = {(0, 1): G01, (1, 1): G11, (1, 2): G12, (1, 3): G13,
140
+ (2, 1): G21, (2, 2): G22, (2, 3): G23, (2, 4): G24,
141
+ (2, 5): G25, (3, 1): G31, (3, 2): G32, (3, 3): G33,
142
+ (3, 4): G34, (3, 5): G35, (3, 6): G36, (3, 7): G37}
143
+
144
+ def _ellip_norm(n, p, h2, k2):
145
+ func = known_funcs[n, p]
146
+ return func(h2, k2)
147
+ _ellip_norm = np.vectorize(_ellip_norm)
148
+
149
+ def ellip_normal_known(h2, k2, n, p):
150
+ return _ellip_norm(n, p, h2, k2)
151
+
152
+ # generate both large and small h2 < k2 pairs
153
+ np.random.seed(1234)
154
+ h2 = np.random.pareto(0.5, size=1)
155
+ k2 = h2 * (1 + np.random.pareto(0.5, size=h2.size))
156
+
157
+ points = []
158
+ for n in range(4):
159
+ for p in range(1, 2*n+2):
160
+ points.append((h2, k2, np.full(h2.size, n), np.full(h2.size, p)))
161
+ points = np.array(points)
162
+ with suppress_warnings() as sup:
163
+ sup.filter(IntegrationWarning, "The occurrence of roundoff error")
164
+ assert_func_equal(ellip_normal, ellip_normal_known, points, rtol=1e-12)
165
+
166
+
167
+ def test_ellip_harm_2():
168
+
169
+ def I1(h2, k2, s):
170
+ res = (ellip_harm_2(h2, k2, 1, 1, s)/(3 * ellip_harm(h2, k2, 1, 1, s))
171
+ + ellip_harm_2(h2, k2, 1, 2, s)/(3 * ellip_harm(h2, k2, 1, 2, s)) +
172
+ ellip_harm_2(h2, k2, 1, 3, s)/(3 * ellip_harm(h2, k2, 1, 3, s)))
173
+ return res
174
+
175
+ with suppress_warnings() as sup:
176
+ sup.filter(IntegrationWarning, "The occurrence of roundoff error")
177
+ assert_almost_equal(I1(5, 8, 10), 1/(10*sqrt((100-5)*(100-8))))
178
+
179
+ # Values produced by code from arXiv:1204.0267
180
+ assert_almost_equal(ellip_harm_2(5, 8, 2, 1, 10), 0.00108056853382)
181
+ assert_almost_equal(ellip_harm_2(5, 8, 2, 2, 10), 0.00105820513809)
182
+ assert_almost_equal(ellip_harm_2(5, 8, 2, 3, 10), 0.00106058384743)
183
+ assert_almost_equal(ellip_harm_2(5, 8, 2, 4, 10), 0.00106774492306)
184
+ assert_almost_equal(ellip_harm_2(5, 8, 2, 5, 10), 0.00107976356454)
185
+
186
+
187
+ def test_ellip_harm():
188
+
189
+ def E01(h2, k2, s):
190
+ return 1
191
+
192
+ def E11(h2, k2, s):
193
+ return s
194
+
195
+ def E12(h2, k2, s):
196
+ return sqrt(abs(s*s - h2))
197
+
198
+ def E13(h2, k2, s):
199
+ return sqrt(abs(s*s - k2))
200
+
201
+ def E21(h2, k2, s):
202
+ return s*s - 1/3*((h2 + k2) + sqrt(abs((h2 + k2)*(h2 + k2)-3*h2*k2)))
203
+
204
+ def E22(h2, k2, s):
205
+ return s*s - 1/3*((h2 + k2) - sqrt(abs((h2 + k2)*(h2 + k2)-3*h2*k2)))
206
+
207
+ def E23(h2, k2, s):
208
+ return s * sqrt(abs(s*s - h2))
209
+
210
+ def E24(h2, k2, s):
211
+ return s * sqrt(abs(s*s - k2))
212
+
213
+ def E25(h2, k2, s):
214
+ return sqrt(abs((s*s - h2)*(s*s - k2)))
215
+
216
+ def E31(h2, k2, s):
217
+ return s*s*s - (s/5)*(2*(h2 + k2) + sqrt(4*(h2 + k2)*(h2 + k2) -
218
+ 15*h2*k2))
219
+
220
+ def E32(h2, k2, s):
221
+ return s*s*s - (s/5)*(2*(h2 + k2) - sqrt(4*(h2 + k2)*(h2 + k2) -
222
+ 15*h2*k2))
223
+
224
+ def E33(h2, k2, s):
225
+ return sqrt(abs(s*s - h2))*(s*s - 1/5*((h2 + 2*k2) + sqrt(abs((h2 +
226
+ 2*k2)*(h2 + 2*k2) - 5*h2*k2))))
227
+
228
+ def E34(h2, k2, s):
229
+ return sqrt(abs(s*s - h2))*(s*s - 1/5*((h2 + 2*k2) - sqrt(abs((h2 +
230
+ 2*k2)*(h2 + 2*k2) - 5*h2*k2))))
231
+
232
+ def E35(h2, k2, s):
233
+ return sqrt(abs(s*s - k2))*(s*s - 1/5*((2*h2 + k2) + sqrt(abs((2*h2
234
+ + k2)*(2*h2 + k2) - 5*h2*k2))))
235
+
236
+ def E36(h2, k2, s):
237
+ return sqrt(abs(s*s - k2))*(s*s - 1/5*((2*h2 + k2) - sqrt(abs((2*h2
238
+ + k2)*(2*h2 + k2) - 5*h2*k2))))
239
+
240
+ def E37(h2, k2, s):
241
+ return s * sqrt(abs((s*s - h2)*(s*s - k2)))
242
+
243
+ assert_equal(ellip_harm(5, 8, 1, 2, 2.5, 1, 1),
244
+ ellip_harm(5, 8, 1, 2, 2.5))
245
+
246
+ known_funcs = {(0, 1): E01, (1, 1): E11, (1, 2): E12, (1, 3): E13,
247
+ (2, 1): E21, (2, 2): E22, (2, 3): E23, (2, 4): E24,
248
+ (2, 5): E25, (3, 1): E31, (3, 2): E32, (3, 3): E33,
249
+ (3, 4): E34, (3, 5): E35, (3, 6): E36, (3, 7): E37}
250
+
251
+ point_ref = []
252
+
253
+ def ellip_harm_known(h2, k2, n, p, s):
254
+ for i in range(h2.size):
255
+ func = known_funcs[(int(n[i]), int(p[i]))]
256
+ point_ref.append(func(h2[i], k2[i], s[i]))
257
+ return point_ref
258
+
259
+ np.random.seed(1234)
260
+ h2 = np.random.pareto(0.5, size=30)
261
+ k2 = h2*(1 + np.random.pareto(0.5, size=h2.size))
262
+ s = np.random.pareto(0.5, size=h2.size)
263
+ points = []
264
+ for i in range(h2.size):
265
+ for n in range(4):
266
+ for p in range(1, 2*n+2):
267
+ points.append((h2[i], k2[i], n, p, s[i]))
268
+ points = np.array(points)
269
+ assert_func_equal(ellip_harm, ellip_harm_known, points, rtol=1e-12)
270
+
271
+
272
+ def test_ellip_harm_invalid_p():
273
+ # Regression test. This should return nan.
274
+ n = 4
275
+ # Make p > 2*n + 1.
276
+ p = 2*n + 2
277
+ result = ellip_harm(0.5, 2.0, n, p, 0.2)
278
+ assert np.isnan(result)
openflamingo/lib/python3.10/site-packages/scipy/special/tests/test_erfinv.py ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ from numpy.testing import assert_allclose, assert_equal
3
+ import pytest
4
+
5
+ import scipy.special as sc
6
+
7
+
8
+ class TestInverseErrorFunction:
9
+ def test_compliment(self):
10
+ # Test erfcinv(1 - x) == erfinv(x)
11
+ x = np.linspace(-1, 1, 101)
12
+ assert_allclose(sc.erfcinv(1 - x), sc.erfinv(x), rtol=0, atol=1e-15)
13
+
14
+ def test_literal_values(self):
15
+ # The expected values were calculated with mpmath:
16
+ #
17
+ # import mpmath
18
+ # mpmath.mp.dps = 200
19
+ # for y in [0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9]:
20
+ # x = mpmath.erfinv(y)
21
+ # print(x)
22
+ #
23
+ y = np.array([0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9])
24
+ actual = sc.erfinv(y)
25
+ expected = [
26
+ 0.0,
27
+ 0.08885599049425769,
28
+ 0.1791434546212917,
29
+ 0.2724627147267543,
30
+ 0.37080715859355795,
31
+ 0.4769362762044699,
32
+ 0.5951160814499948,
33
+ 0.7328690779592167,
34
+ 0.9061938024368233,
35
+ 1.1630871536766743,
36
+ ]
37
+ assert_allclose(actual, expected, rtol=0, atol=1e-15)
38
+
39
+ @pytest.mark.parametrize(
40
+ 'f, x, y',
41
+ [
42
+ (sc.erfinv, -1, -np.inf),
43
+ (sc.erfinv, 0, 0),
44
+ (sc.erfinv, 1, np.inf),
45
+ (sc.erfinv, -100, np.nan),
46
+ (sc.erfinv, 100, np.nan),
47
+ (sc.erfcinv, 0, np.inf),
48
+ (sc.erfcinv, 1, -0.0),
49
+ (sc.erfcinv, 2, -np.inf),
50
+ (sc.erfcinv, -100, np.nan),
51
+ (sc.erfcinv, 100, np.nan),
52
+ ],
53
+ ids=[
54
+ 'erfinv at lower bound',
55
+ 'erfinv at midpoint',
56
+ 'erfinv at upper bound',
57
+ 'erfinv below lower bound',
58
+ 'erfinv above upper bound',
59
+ 'erfcinv at lower bound',
60
+ 'erfcinv at midpoint',
61
+ 'erfcinv at upper bound',
62
+ 'erfcinv below lower bound',
63
+ 'erfcinv above upper bound',
64
+ ]
65
+ )
66
+ def test_domain_bounds(self, f, x, y):
67
+ assert_equal(f(x), y)
68
+
69
+ def test_erfinv_asympt(self):
70
+ # regression test for gh-12758: erfinv(x) loses precision at small x
71
+ # expected values precomputed with mpmath:
72
+ # >>> mpmath.mp.dps = 100
73
+ # >>> expected = [float(mpmath.erfinv(t)) for t in x]
74
+ x = np.array([1e-20, 1e-15, 1e-14, 1e-10, 1e-8, 0.9e-7, 1.1e-7, 1e-6])
75
+ expected = np.array([8.86226925452758e-21,
76
+ 8.862269254527581e-16,
77
+ 8.86226925452758e-15,
78
+ 8.862269254527581e-11,
79
+ 8.86226925452758e-09,
80
+ 7.97604232907484e-08,
81
+ 9.74849617998037e-08,
82
+ 8.8622692545299e-07])
83
+ assert_allclose(sc.erfinv(x), expected,
84
+ rtol=1e-15)
85
+
86
+ # also test the roundtrip consistency
87
+ assert_allclose(sc.erf(sc.erfinv(x)),
88
+ x,
89
+ rtol=5e-15)
openflamingo/lib/python3.10/site-packages/scipy/special/tests/test_exponential_integrals.py ADDED
@@ -0,0 +1,118 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pytest
2
+
3
+ import numpy as np
4
+ from numpy.testing import assert_allclose
5
+ import scipy.special as sc
6
+
7
+
8
+ class TestExp1:
9
+
10
+ def test_branch_cut(self):
11
+ assert np.isnan(sc.exp1(-1))
12
+ assert sc.exp1(complex(-1, 0)).imag == (
13
+ -sc.exp1(complex(-1, -0.0)).imag
14
+ )
15
+
16
+ assert_allclose(
17
+ sc.exp1(complex(-1, 0)),
18
+ sc.exp1(-1 + 1e-20j),
19
+ atol=0,
20
+ rtol=1e-15
21
+ )
22
+ assert_allclose(
23
+ sc.exp1(complex(-1, -0.0)),
24
+ sc.exp1(-1 - 1e-20j),
25
+ atol=0,
26
+ rtol=1e-15
27
+ )
28
+
29
+ def test_834(self):
30
+ # Regression test for #834
31
+ a = sc.exp1(-complex(19.9999990))
32
+ b = sc.exp1(-complex(19.9999991))
33
+ assert_allclose(a.imag, b.imag, atol=0, rtol=1e-15)
34
+
35
+
36
+ class TestScaledExp1:
37
+
38
+ @pytest.mark.parametrize('x, expected', [(0, 0), (np.inf, 1)])
39
+ def test_limits(self, x, expected):
40
+ y = sc._ufuncs._scaled_exp1(x)
41
+ assert y == expected
42
+
43
+ # The expected values were computed with mpmath, e.g.:
44
+ #
45
+ # from mpmath import mp
46
+ # mp.dps = 80
47
+ # x = 1e-25
48
+ # print(float(x*mp.exp(x)*np.expint(1, x)))
49
+ #
50
+ # prints 5.698741165994961e-24
51
+ #
52
+ # The method used to compute _scaled_exp1 changes at x=1
53
+ # and x=1250, so values at those inputs, and values just
54
+ # above and below them, are included in the test data.
55
+ @pytest.mark.parametrize('x, expected',
56
+ [(1e-25, 5.698741165994961e-24),
57
+ (0.1, 0.20146425447084518),
58
+ (0.9995, 0.5962509885831002),
59
+ (1.0, 0.5963473623231941),
60
+ (1.0005, 0.5964436833238044),
61
+ (2.5, 0.7588145912149602),
62
+ (10.0, 0.9156333393978808),
63
+ (100.0, 0.9901942286733019),
64
+ (500.0, 0.9980079523802055),
65
+ (1000.0, 0.9990019940238807),
66
+ (1249.5, 0.9992009578306811),
67
+ (1250.0, 0.9992012769377913),
68
+ (1250.25, 0.9992014363957858),
69
+ (2000.0, 0.9995004992514963),
70
+ (1e4, 0.9999000199940024),
71
+ (1e10, 0.9999999999),
72
+ (1e15, 0.999999999999999),
73
+ ])
74
+ def test_scaled_exp1(self, x, expected):
75
+ y = sc._ufuncs._scaled_exp1(x)
76
+ assert_allclose(y, expected, rtol=2e-15)
77
+
78
+
79
+ class TestExpi:
80
+
81
+ @pytest.mark.parametrize('result', [
82
+ sc.expi(complex(-1, 0)),
83
+ sc.expi(complex(-1, -0.0)),
84
+ sc.expi(-1)
85
+ ])
86
+ def test_branch_cut(self, result):
87
+ desired = -0.21938393439552027368 # Computed using Mpmath
88
+ assert_allclose(result, desired, atol=0, rtol=1e-14)
89
+
90
+ def test_near_branch_cut(self):
91
+ lim_from_above = sc.expi(-1 + 1e-20j)
92
+ lim_from_below = sc.expi(-1 - 1e-20j)
93
+ assert_allclose(
94
+ lim_from_above.real,
95
+ lim_from_below.real,
96
+ atol=0,
97
+ rtol=1e-15
98
+ )
99
+ assert_allclose(
100
+ lim_from_above.imag,
101
+ -lim_from_below.imag,
102
+ atol=0,
103
+ rtol=1e-15
104
+ )
105
+
106
+ def test_continuity_on_positive_real_axis(self):
107
+ assert_allclose(
108
+ sc.expi(complex(1, 0)),
109
+ sc.expi(complex(1, -0.0)),
110
+ atol=0,
111
+ rtol=1e-15
112
+ )
113
+
114
+
115
+ class TestExpn:
116
+
117
+ def test_out_of_domain(self):
118
+ assert all(np.isnan([sc.expn(-1, 1.0), sc.expn(1, -1.0)]))
openflamingo/lib/python3.10/site-packages/scipy/special/tests/test_faddeeva.py ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pytest
2
+
3
+ import numpy as np
4
+ from numpy.testing import assert_allclose
5
+ import scipy.special as sc
6
+ from scipy.special._testutils import FuncData
7
+
8
+
9
+ class TestVoigtProfile:
10
+
11
+ @pytest.mark.parametrize('x, sigma, gamma', [
12
+ (np.nan, 1, 1),
13
+ (0, np.nan, 1),
14
+ (0, 1, np.nan),
15
+ (1, np.nan, 0),
16
+ (np.nan, 1, 0),
17
+ (1, 0, np.nan),
18
+ (np.nan, 0, 1),
19
+ (np.nan, 0, 0)
20
+ ])
21
+ def test_nan(self, x, sigma, gamma):
22
+ assert np.isnan(sc.voigt_profile(x, sigma, gamma))
23
+
24
+ @pytest.mark.parametrize('x, desired', [
25
+ (-np.inf, 0),
26
+ (np.inf, 0)
27
+ ])
28
+ def test_inf(self, x, desired):
29
+ assert sc.voigt_profile(x, 1, 1) == desired
30
+
31
+ def test_against_mathematica(self):
32
+ # Results obtained from Mathematica by computing
33
+ #
34
+ # PDF[VoigtDistribution[gamma, sigma], x]
35
+ #
36
+ points = np.array([
37
+ [-7.89, 45.06, 6.66, 0.0077921073660388806401],
38
+ [-0.05, 7.98, 24.13, 0.012068223646769913478],
39
+ [-13.98, 16.83, 42.37, 0.0062442236362132357833],
40
+ [-12.66, 0.21, 6.32, 0.010052516161087379402],
41
+ [11.34, 4.25, 21.96, 0.0113698923627278917805],
42
+ [-11.56, 20.40, 30.53, 0.0076332760432097464987],
43
+ [-9.17, 25.61, 8.32, 0.011646345779083005429],
44
+ [16.59, 18.05, 2.50, 0.013637768837526809181],
45
+ [9.11, 2.12, 39.33, 0.0076644040807277677585],
46
+ [-43.33, 0.30, 45.68, 0.0036680463875330150996]
47
+ ])
48
+ FuncData(
49
+ sc.voigt_profile,
50
+ points,
51
+ (0, 1, 2),
52
+ 3,
53
+ atol=0,
54
+ rtol=1e-15
55
+ ).check()
56
+
57
+ def test_symmetry(self):
58
+ x = np.linspace(0, 10, 20)
59
+ assert_allclose(
60
+ sc.voigt_profile(x, 1, 1),
61
+ sc.voigt_profile(-x, 1, 1),
62
+ rtol=1e-15,
63
+ atol=0
64
+ )
65
+
66
+ @pytest.mark.parametrize('x, sigma, gamma, desired', [
67
+ (0, 0, 0, np.inf),
68
+ (1, 0, 0, 0)
69
+ ])
70
+ def test_corner_cases(self, x, sigma, gamma, desired):
71
+ assert sc.voigt_profile(x, sigma, gamma) == desired
72
+
73
+ @pytest.mark.parametrize('sigma1, gamma1, sigma2, gamma2', [
74
+ (0, 1, 1e-16, 1),
75
+ (1, 0, 1, 1e-16),
76
+ (0, 0, 1e-16, 1e-16)
77
+ ])
78
+ def test_continuity(self, sigma1, gamma1, sigma2, gamma2):
79
+ x = np.linspace(1, 10, 20)
80
+ assert_allclose(
81
+ sc.voigt_profile(x, sigma1, gamma1),
82
+ sc.voigt_profile(x, sigma2, gamma2),
83
+ rtol=1e-16,
84
+ atol=1e-16
85
+ )
openflamingo/lib/python3.10/site-packages/scipy/special/tests/test_gamma.py ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import scipy.special as sc
3
+
4
+
5
+ class TestRgamma:
6
+
7
+ def test_gh_11315(self):
8
+ assert sc.rgamma(-35) == 0
9
+
10
+ def test_rgamma_zeros(self):
11
+ x = np.array([0, -10, -100, -1000, -10000])
12
+ assert np.all(sc.rgamma(x) == 0)
openflamingo/lib/python3.10/site-packages/scipy/special/tests/test_gammainc.py ADDED
@@ -0,0 +1,136 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pytest
2
+
3
+ import numpy as np
4
+ from numpy.testing import assert_allclose, assert_array_equal
5
+
6
+ import scipy.special as sc
7
+ from scipy.special._testutils import FuncData
8
+
9
+
10
+ INVALID_POINTS = [
11
+ (1, -1),
12
+ (0, 0),
13
+ (-1, 1),
14
+ (np.nan, 1),
15
+ (1, np.nan)
16
+ ]
17
+
18
+
19
+ class TestGammainc:
20
+
21
+ @pytest.mark.parametrize('a, x', INVALID_POINTS)
22
+ def test_domain(self, a, x):
23
+ assert np.isnan(sc.gammainc(a, x))
24
+
25
+ def test_a_eq_0_x_gt_0(self):
26
+ assert sc.gammainc(0, 1) == 1
27
+
28
+ @pytest.mark.parametrize('a, x, desired', [
29
+ (np.inf, 1, 0),
30
+ (np.inf, 0, 0),
31
+ (np.inf, np.inf, np.nan),
32
+ (1, np.inf, 1)
33
+ ])
34
+ def test_infinite_arguments(self, a, x, desired):
35
+ result = sc.gammainc(a, x)
36
+ if np.isnan(desired):
37
+ assert np.isnan(result)
38
+ else:
39
+ assert result == desired
40
+
41
+ def test_infinite_limits(self):
42
+ # Test that large arguments converge to the hard-coded limits
43
+ # at infinity.
44
+ assert_allclose(
45
+ sc.gammainc(1000, 100),
46
+ sc.gammainc(np.inf, 100),
47
+ atol=1e-200, # Use `atol` since the function converges to 0.
48
+ rtol=0
49
+ )
50
+ assert sc.gammainc(100, 1000) == sc.gammainc(100, np.inf)
51
+
52
+ def test_x_zero(self):
53
+ a = np.arange(1, 10)
54
+ assert_array_equal(sc.gammainc(a, 0), 0)
55
+
56
+ def test_limit_check(self):
57
+ result = sc.gammainc(1e-10, 1)
58
+ limit = sc.gammainc(0, 1)
59
+ assert np.isclose(result, limit)
60
+
61
+ def gammainc_line(self, x):
62
+ # The line a = x where a simpler asymptotic expansion (analog
63
+ # of DLMF 8.12.15) is available.
64
+ c = np.array([-1/3, -1/540, 25/6048, 101/155520,
65
+ -3184811/3695155200, -2745493/8151736420])
66
+ res = 0
67
+ xfac = 1
68
+ for ck in c:
69
+ res -= ck*xfac
70
+ xfac /= x
71
+ res /= np.sqrt(2*np.pi*x)
72
+ res += 0.5
73
+ return res
74
+
75
+ def test_line(self):
76
+ x = np.logspace(np.log10(25), 300, 500)
77
+ a = x
78
+ dataset = np.vstack((a, x, self.gammainc_line(x))).T
79
+ FuncData(sc.gammainc, dataset, (0, 1), 2, rtol=1e-11).check()
80
+
81
+ def test_roundtrip(self):
82
+ a = np.logspace(-5, 10, 100)
83
+ x = np.logspace(-5, 10, 100)
84
+
85
+ y = sc.gammaincinv(a, sc.gammainc(a, x))
86
+ assert_allclose(x, y, rtol=1e-10)
87
+
88
+
89
+ class TestGammaincc:
90
+
91
+ @pytest.mark.parametrize('a, x', INVALID_POINTS)
92
+ def test_domain(self, a, x):
93
+ assert np.isnan(sc.gammaincc(a, x))
94
+
95
+ def test_a_eq_0_x_gt_0(self):
96
+ assert sc.gammaincc(0, 1) == 0
97
+
98
+ @pytest.mark.parametrize('a, x, desired', [
99
+ (np.inf, 1, 1),
100
+ (np.inf, 0, 1),
101
+ (np.inf, np.inf, np.nan),
102
+ (1, np.inf, 0)
103
+ ])
104
+ def test_infinite_arguments(self, a, x, desired):
105
+ result = sc.gammaincc(a, x)
106
+ if np.isnan(desired):
107
+ assert np.isnan(result)
108
+ else:
109
+ assert result == desired
110
+
111
+ def test_infinite_limits(self):
112
+ # Test that large arguments converge to the hard-coded limits
113
+ # at infinity.
114
+ assert sc.gammaincc(1000, 100) == sc.gammaincc(np.inf, 100)
115
+ assert_allclose(
116
+ sc.gammaincc(100, 1000),
117
+ sc.gammaincc(100, np.inf),
118
+ atol=1e-200, # Use `atol` since the function converges to 0.
119
+ rtol=0
120
+ )
121
+
122
+ def test_limit_check(self):
123
+ result = sc.gammaincc(1e-10,1)
124
+ limit = sc.gammaincc(0,1)
125
+ assert np.isclose(result, limit)
126
+
127
+ def test_x_zero(self):
128
+ a = np.arange(1, 10)
129
+ assert_array_equal(sc.gammaincc(a, 0), 1)
130
+
131
+ def test_roundtrip(self):
132
+ a = np.logspace(-5, 10, 100)
133
+ x = np.logspace(-5, 10, 100)
134
+
135
+ y = sc.gammainccinv(a, sc.gammaincc(a, x))
136
+ assert_allclose(x, y, rtol=1e-14)
openflamingo/lib/python3.10/site-packages/scipy/special/tests/test_hypergeometric.py ADDED
@@ -0,0 +1,140 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pytest
2
+ import numpy as np
3
+ from numpy.testing import assert_allclose, assert_equal
4
+ import scipy.special as sc
5
+
6
+
7
+ class TestHyperu:
8
+
9
+ def test_negative_x(self):
10
+ a, b, x = np.meshgrid(
11
+ [-1, -0.5, 0, 0.5, 1],
12
+ [-1, -0.5, 0, 0.5, 1],
13
+ np.linspace(-100, -1, 10),
14
+ )
15
+ assert np.all(np.isnan(sc.hyperu(a, b, x)))
16
+
17
+ def test_special_cases(self):
18
+ assert sc.hyperu(0, 1, 1) == 1.0
19
+
20
+ @pytest.mark.parametrize('a', [0.5, 1, np.nan])
21
+ @pytest.mark.parametrize('b', [1, 2, np.nan])
22
+ @pytest.mark.parametrize('x', [0.25, 3, np.nan])
23
+ def test_nan_inputs(self, a, b, x):
24
+ assert np.isnan(sc.hyperu(a, b, x)) == np.any(np.isnan([a, b, x]))
25
+
26
+
27
+ class TestHyp1f1:
28
+
29
+ @pytest.mark.parametrize('a, b, x', [
30
+ (np.nan, 1, 1),
31
+ (1, np.nan, 1),
32
+ (1, 1, np.nan)
33
+ ])
34
+ def test_nan_inputs(self, a, b, x):
35
+ assert np.isnan(sc.hyp1f1(a, b, x))
36
+
37
+ def test_poles(self):
38
+ assert_equal(sc.hyp1f1(1, [0, -1, -2, -3, -4], 0.5), np.inf)
39
+
40
+ @pytest.mark.parametrize('a, b, x, result', [
41
+ (-1, 1, 0.5, 0.5),
42
+ (1, 1, 0.5, 1.6487212707001281468),
43
+ (2, 1, 0.5, 2.4730819060501922203),
44
+ (1, 2, 0.5, 1.2974425414002562937),
45
+ (-10, 1, 0.5, -0.38937441413785204475)
46
+ ])
47
+ def test_special_cases(self, a, b, x, result):
48
+ # Hit all the special case branches at the beginning of the
49
+ # function. Desired answers computed using Mpmath.
50
+ assert_allclose(sc.hyp1f1(a, b, x), result, atol=0, rtol=1e-15)
51
+
52
+ @pytest.mark.parametrize('a, b, x, result', [
53
+ (1, 1, 0.44, 1.5527072185113360455),
54
+ (-1, 1, 0.44, 0.55999999999999999778),
55
+ (100, 100, 0.89, 2.4351296512898745592),
56
+ (-100, 100, 0.89, 0.40739062490768104667),
57
+ (1.5, 100, 59.99, 3.8073513625965598107),
58
+ (-1.5, 100, 59.99, 0.25099240047125826943)
59
+ ])
60
+ def test_geometric_convergence(self, a, b, x, result):
61
+ # Test the region where we are relying on the ratio of
62
+ #
63
+ # (|a| + 1) * |x| / |b|
64
+ #
65
+ # being small. Desired answers computed using Mpmath
66
+ assert_allclose(sc.hyp1f1(a, b, x), result, atol=0, rtol=1e-15)
67
+
68
+ @pytest.mark.parametrize('a, b, x, result', [
69
+ (-1, 1, 1.5, -0.5),
70
+ (-10, 1, 1.5, 0.41801777430943080357),
71
+ (-25, 1, 1.5, 0.25114491646037839809),
72
+ (-50, 1, 1.5, -0.25683643975194756115),
73
+ (-80, 1, 1.5, -0.24554329325751503601),
74
+ (-150, 1, 1.5, -0.173364795515420454496),
75
+ ])
76
+ def test_a_negative_integer(self, a, b, x, result):
77
+ # Desired answers computed using Mpmath.
78
+ assert_allclose(sc.hyp1f1(a, b, x), result, atol=0, rtol=2e-14)
79
+
80
+ @pytest.mark.parametrize('a, b, x, expected', [
81
+ (0.01, 150, -4, 0.99973683897677527773), # gh-3492
82
+ (1, 5, 0.01, 1.0020033381011970966), # gh-3593
83
+ (50, 100, 0.01, 1.0050126452421463411), # gh-3593
84
+ (1, 0.3, -1e3, -7.011932249442947651455e-04), # gh-14149
85
+ (1, 0.3, -1e4, -7.001190321418937164734e-05), # gh-14149
86
+ (9, 8.5, -350, -5.224090831922378361082e-20), # gh-17120
87
+ (9, 8.5, -355, -4.595407159813368193322e-20), # gh-17120
88
+ (75, -123.5, 15, 3.425753920814889017493e+06),
89
+ ])
90
+ def test_assorted_cases(self, a, b, x, expected):
91
+ # Expected values were computed with mpmath.hyp1f1(a, b, x).
92
+ assert_allclose(sc.hyp1f1(a, b, x), expected, atol=0, rtol=1e-14)
93
+
94
+ def test_a_neg_int_and_b_equal_x(self):
95
+ # This is a case where the Boost wrapper will call hypergeometric_pFq
96
+ # instead of hypergeometric_1F1. When we use a version of Boost in
97
+ # which https://github.com/boostorg/math/issues/833 is fixed, this
98
+ # test case can probably be moved into test_assorted_cases.
99
+ # The expected value was computed with mpmath.hyp1f1(a, b, x).
100
+ a = -10.0
101
+ b = 2.5
102
+ x = 2.5
103
+ expected = 0.0365323664364104338721
104
+ computed = sc.hyp1f1(a, b, x)
105
+ assert_allclose(computed, expected, atol=0, rtol=1e-13)
106
+
107
+ @pytest.mark.parametrize('a, b, x, desired', [
108
+ (-1, -2, 2, 2),
109
+ (-1, -4, 10, 3.5),
110
+ (-2, -2, 1, 2.5)
111
+ ])
112
+ def test_gh_11099(self, a, b, x, desired):
113
+ # All desired results computed using Mpmath
114
+ assert sc.hyp1f1(a, b, x) == desired
115
+
116
+ @pytest.mark.parametrize('a', [-3, -2])
117
+ def test_x_zero_a_and_b_neg_ints_and_a_ge_b(self, a):
118
+ assert sc.hyp1f1(a, -3, 0) == 1
119
+
120
+ # The "legacy edge cases" mentioned in the comments in the following
121
+ # tests refers to the behavior of hyp1f1(a, b, x) when b is a nonpositive
122
+ # integer. In some subcases, the behavior of SciPy does not match that
123
+ # of Boost (1.81+), mpmath and Mathematica (via Wolfram Alpha online).
124
+ # If the handling of these edges cases is changed to agree with those
125
+ # libraries, these test will have to be updated.
126
+
127
+ @pytest.mark.parametrize('b', [0, -1, -5])
128
+ def test_legacy_case1(self, b):
129
+ # Test results of hyp1f1(0, n, x) for n <= 0.
130
+ # This is a legacy edge case.
131
+ # Boost (versions greater than 1.80), Mathematica (via Wolfram Alpha
132
+ # online) and mpmath all return 1 in this case, but SciPy's hyp1f1
133
+ # returns inf.
134
+ assert_equal(sc.hyp1f1(0, b, [-1.5, 0, 1.5]), [np.inf, np.inf, np.inf])
135
+
136
+ def test_legacy_case2(self):
137
+ # This is a legacy edge case.
138
+ # In software such as boost (1.81+), mpmath and Mathematica,
139
+ # the value is 1.
140
+ assert sc.hyp1f1(-4, -3, 0) == np.inf
openflamingo/lib/python3.10/site-packages/scipy/special/tests/test_kolmogorov.py ADDED
@@ -0,0 +1,495 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import itertools
2
+ import sys
3
+ import pytest
4
+
5
+ import numpy as np
6
+ from numpy.testing import assert_
7
+ from scipy.special._testutils import FuncData
8
+
9
+ from scipy.special import kolmogorov, kolmogi, smirnov, smirnovi
10
+ from scipy.special._ufuncs import (_kolmogc, _kolmogci, _kolmogp,
11
+ _smirnovc, _smirnovci, _smirnovp)
12
+
13
+ _rtol = 1e-10
14
+
15
+ class TestSmirnov:
16
+ def test_nan(self):
17
+ assert_(np.isnan(smirnov(1, np.nan)))
18
+
19
+ def test_basic(self):
20
+ dataset = [(1, 0.1, 0.9),
21
+ (1, 0.875, 0.125),
22
+ (2, 0.875, 0.125 * 0.125),
23
+ (3, 0.875, 0.125 * 0.125 * 0.125)]
24
+
25
+ dataset = np.asarray(dataset)
26
+ FuncData(
27
+ smirnov, dataset, (0, 1), 2, rtol=_rtol
28
+ ).check(dtypes=[int, float, float])
29
+ dataset[:, -1] = 1 - dataset[:, -1]
30
+ FuncData(
31
+ _smirnovc, dataset, (0, 1), 2, rtol=_rtol
32
+ ).check(dtypes=[int, float, float])
33
+
34
+ def test_x_equals_0(self):
35
+ dataset = [(n, 0, 1) for n in itertools.chain(range(2, 20), range(1010, 1020))]
36
+ dataset = np.asarray(dataset)
37
+ FuncData(
38
+ smirnov, dataset, (0, 1), 2, rtol=_rtol
39
+ ).check(dtypes=[int, float, float])
40
+ dataset[:, -1] = 1 - dataset[:, -1]
41
+ FuncData(
42
+ _smirnovc, dataset, (0, 1), 2, rtol=_rtol
43
+ ).check(dtypes=[int, float, float])
44
+
45
+ def test_x_equals_1(self):
46
+ dataset = [(n, 1, 0) for n in itertools.chain(range(2, 20), range(1010, 1020))]
47
+ dataset = np.asarray(dataset)
48
+ FuncData(
49
+ smirnov, dataset, (0, 1), 2, rtol=_rtol
50
+ ).check(dtypes=[int, float, float])
51
+ dataset[:, -1] = 1 - dataset[:, -1]
52
+ FuncData(
53
+ _smirnovc, dataset, (0, 1), 2, rtol=_rtol
54
+ ).check(dtypes=[int, float, float])
55
+
56
+ def test_x_equals_0point5(self):
57
+ dataset = [(1, 0.5, 0.5),
58
+ (2, 0.5, 0.25),
59
+ (3, 0.5, 0.166666666667),
60
+ (4, 0.5, 0.09375),
61
+ (5, 0.5, 0.056),
62
+ (6, 0.5, 0.0327932098765),
63
+ (7, 0.5, 0.0191958707681),
64
+ (8, 0.5, 0.0112953186035),
65
+ (9, 0.5, 0.00661933257355),
66
+ (10, 0.5, 0.003888705)]
67
+
68
+ dataset = np.asarray(dataset)
69
+ FuncData(
70
+ smirnov, dataset, (0, 1), 2, rtol=_rtol
71
+ ).check(dtypes=[int, float, float])
72
+ dataset[:, -1] = 1 - dataset[:, -1]
73
+ FuncData(
74
+ _smirnovc, dataset, (0, 1), 2, rtol=_rtol
75
+ ).check(dtypes=[int, float, float])
76
+
77
+ def test_n_equals_1(self):
78
+ x = np.linspace(0, 1, 101, endpoint=True)
79
+ dataset = np.column_stack([[1]*len(x), x, 1-x])
80
+ FuncData(
81
+ smirnov, dataset, (0, 1), 2, rtol=_rtol
82
+ ).check(dtypes=[int, float, float])
83
+ dataset[:, -1] = 1 - dataset[:, -1]
84
+ FuncData(
85
+ _smirnovc, dataset, (0, 1), 2, rtol=_rtol
86
+ ).check(dtypes=[int, float, float])
87
+
88
+ def test_n_equals_2(self):
89
+ x = np.linspace(0.5, 1, 101, endpoint=True)
90
+ p = np.power(1-x, 2)
91
+ n = np.array([2] * len(x))
92
+ dataset = np.column_stack([n, x, p])
93
+ FuncData(
94
+ smirnov, dataset, (0, 1), 2, rtol=_rtol
95
+ ).check(dtypes=[int, float, float])
96
+ dataset[:, -1] = 1 - dataset[:, -1]
97
+ FuncData(
98
+ _smirnovc, dataset, (0, 1), 2, rtol=_rtol
99
+ ).check(dtypes=[int, float, float])
100
+
101
+ def test_n_equals_3(self):
102
+ x = np.linspace(0.7, 1, 31, endpoint=True)
103
+ p = np.power(1-x, 3)
104
+ n = np.array([3] * len(x))
105
+ dataset = np.column_stack([n, x, p])
106
+ FuncData(
107
+ smirnov, dataset, (0, 1), 2, rtol=_rtol
108
+ ).check(dtypes=[int, float, float])
109
+ dataset[:, -1] = 1 - dataset[:, -1]
110
+ FuncData(
111
+ _smirnovc, dataset, (0, 1), 2, rtol=_rtol
112
+ ).check(dtypes=[int, float, float])
113
+
114
+ def test_n_large(self):
115
+ # test for large values of n
116
+ # Probabilities should go down as n goes up
117
+ x = 0.4
118
+ pvals = np.array([smirnov(n, x) for n in range(400, 1100, 20)])
119
+ dfs = np.diff(pvals)
120
+ assert_(np.all(dfs <= 0), msg='Not all diffs negative %s' % dfs)
121
+
122
+
123
+ class TestSmirnovi:
124
+ def test_nan(self):
125
+ assert_(np.isnan(smirnovi(1, np.nan)))
126
+
127
+ def test_basic(self):
128
+ dataset = [(1, 0.4, 0.6),
129
+ (1, 0.6, 0.4),
130
+ (1, 0.99, 0.01),
131
+ (1, 0.01, 0.99),
132
+ (2, 0.125 * 0.125, 0.875),
133
+ (3, 0.125 * 0.125 * 0.125, 0.875),
134
+ (10, 1.0 / 16 ** 10, 1 - 1.0 / 16)]
135
+
136
+ dataset = np.asarray(dataset)
137
+ FuncData(
138
+ smirnovi, dataset, (0, 1), 2, rtol=_rtol
139
+ ).check(dtypes=[int, float, float])
140
+ dataset[:, 1] = 1 - dataset[:, 1]
141
+ FuncData(
142
+ _smirnovci, dataset, (0, 1), 2, rtol=_rtol
143
+ ).check(dtypes=[int, float, float])
144
+
145
+ def test_x_equals_0(self):
146
+ dataset = [(n, 0, 1) for n in itertools.chain(range(2, 20), range(1010, 1020))]
147
+ dataset = np.asarray(dataset)
148
+ FuncData(
149
+ smirnovi, dataset, (0, 1), 2, rtol=_rtol
150
+ ).check(dtypes=[int, float, float])
151
+ dataset[:, 1] = 1 - dataset[:, 1]
152
+ FuncData(
153
+ _smirnovci, dataset, (0, 1), 2, rtol=_rtol
154
+ ).check(dtypes=[int, float, float])
155
+
156
+ def test_x_equals_1(self):
157
+ dataset = [(n, 1, 0) for n in itertools.chain(range(2, 20), range(1010, 1020))]
158
+ dataset = np.asarray(dataset)
159
+ FuncData(
160
+ smirnovi, dataset, (0, 1), 2, rtol=_rtol
161
+ ).check(dtypes=[int, float, float])
162
+ dataset[:, 1] = 1 - dataset[:, 1]
163
+ FuncData(
164
+ _smirnovci, dataset, (0, 1), 2, rtol=_rtol
165
+ ).check(dtypes=[int, float, float])
166
+
167
+ def test_n_equals_1(self):
168
+ pp = np.linspace(0, 1, 101, endpoint=True)
169
+ # dataset = np.array([(1, p, 1-p) for p in pp])
170
+ dataset = np.column_stack([[1]*len(pp), pp, 1-pp])
171
+ FuncData(
172
+ smirnovi, dataset, (0, 1), 2, rtol=_rtol
173
+ ).check(dtypes=[int, float, float])
174
+ dataset[:, 1] = 1 - dataset[:, 1]
175
+ FuncData(
176
+ _smirnovci, dataset, (0, 1), 2, rtol=_rtol
177
+ ).check(dtypes=[int, float, float])
178
+
179
+ def test_n_equals_2(self):
180
+ x = np.linspace(0.5, 1, 101, endpoint=True)
181
+ p = np.power(1-x, 2)
182
+ n = np.array([2] * len(x))
183
+ dataset = np.column_stack([n, p, x])
184
+ FuncData(
185
+ smirnovi, dataset, (0, 1), 2, rtol=_rtol
186
+ ).check(dtypes=[int, float, float])
187
+ dataset[:, 1] = 1 - dataset[:, 1]
188
+ FuncData(
189
+ _smirnovci, dataset, (0, 1), 2, rtol=_rtol
190
+ ).check(dtypes=[int, float, float])
191
+
192
+ def test_n_equals_3(self):
193
+ x = np.linspace(0.7, 1, 31, endpoint=True)
194
+ p = np.power(1-x, 3)
195
+ n = np.array([3] * len(x))
196
+ dataset = np.column_stack([n, p, x])
197
+ FuncData(
198
+ smirnovi, dataset, (0, 1), 2, rtol=_rtol
199
+ ).check(dtypes=[int, float, float])
200
+ dataset[:, 1] = 1 - dataset[:, 1]
201
+ FuncData(
202
+ _smirnovci, dataset, (0, 1), 2, rtol=_rtol
203
+ ).check(dtypes=[int, float, float])
204
+
205
+ def test_round_trip(self):
206
+ def _sm_smi(n, p):
207
+ return smirnov(n, smirnovi(n, p))
208
+
209
+ def _smc_smci(n, p):
210
+ return _smirnovc(n, _smirnovci(n, p))
211
+
212
+ dataset = [(1, 0.4, 0.4),
213
+ (1, 0.6, 0.6),
214
+ (2, 0.875, 0.875),
215
+ (3, 0.875, 0.875),
216
+ (3, 0.125, 0.125),
217
+ (10, 0.999, 0.999),
218
+ (10, 0.0001, 0.0001)]
219
+
220
+ dataset = np.asarray(dataset)
221
+ FuncData(
222
+ _sm_smi, dataset, (0, 1), 2, rtol=_rtol
223
+ ).check(dtypes=[int, float, float])
224
+ FuncData(
225
+ _smc_smci, dataset, (0, 1), 2, rtol=_rtol
226
+ ).check(dtypes=[int, float, float])
227
+
228
+ def test_x_equals_0point5(self):
229
+ dataset = [(1, 0.5, 0.5),
230
+ (2, 0.5, 0.366025403784),
231
+ (2, 0.25, 0.5),
232
+ (3, 0.5, 0.297156508177),
233
+ (4, 0.5, 0.255520481121),
234
+ (5, 0.5, 0.234559536069),
235
+ (6, 0.5, 0.21715965898),
236
+ (7, 0.5, 0.202722580034),
237
+ (8, 0.5, 0.190621765256),
238
+ (9, 0.5, 0.180363501362),
239
+ (10, 0.5, 0.17157867006)]
240
+
241
+ dataset = np.asarray(dataset)
242
+ FuncData(
243
+ smirnovi, dataset, (0, 1), 2, rtol=_rtol
244
+ ).check(dtypes=[int, float, float])
245
+ dataset[:, 1] = 1 - dataset[:, 1]
246
+ FuncData(
247
+ _smirnovci, dataset, (0, 1), 2, rtol=_rtol
248
+ ).check(dtypes=[int, float, float])
249
+
250
+
251
+ class TestSmirnovp:
252
+ def test_nan(self):
253
+ assert_(np.isnan(_smirnovp(1, np.nan)))
254
+
255
+ def test_basic(self):
256
+ # Check derivative at endpoints
257
+ n1_10 = np.arange(1, 10)
258
+ dataset0 = np.column_stack([n1_10,
259
+ np.full_like(n1_10, 0),
260
+ np.full_like(n1_10, -1)])
261
+ FuncData(
262
+ _smirnovp, dataset0, (0, 1), 2, rtol=_rtol
263
+ ).check(dtypes=[int, float, float])
264
+
265
+ n2_10 = np.arange(2, 10)
266
+ dataset1 = np.column_stack([n2_10,
267
+ np.full_like(n2_10, 1.0),
268
+ np.full_like(n2_10, 0)])
269
+ FuncData(
270
+ _smirnovp, dataset1, (0, 1), 2, rtol=_rtol
271
+ ).check(dtypes=[int, float, float])
272
+
273
+ def test_oneminusoneovern(self):
274
+ # Check derivative at x=1-1/n
275
+ n = np.arange(1, 20)
276
+ x = 1.0/n
277
+ xm1 = 1-1.0/n
278
+ pp1 = -n * x**(n-1)
279
+ pp1 -= (1-np.sign(n-2)**2) * 0.5 # n=2, x=0.5, 1-1/n = 0.5, need to adjust
280
+ dataset1 = np.column_stack([n, xm1, pp1])
281
+ FuncData(
282
+ _smirnovp, dataset1, (0, 1), 2, rtol=_rtol
283
+ ).check(dtypes=[int, float, float])
284
+
285
+ def test_oneovertwon(self):
286
+ # Check derivative at x=1/2n (Discontinuous at x=1/n, so check at x=1/2n)
287
+ n = np.arange(1, 20)
288
+ x = 1.0/2/n
289
+ pp = -(n*x+1) * (1+x)**(n-2)
290
+ dataset0 = np.column_stack([n, x, pp])
291
+ FuncData(
292
+ _smirnovp, dataset0, (0, 1), 2, rtol=_rtol
293
+ ).check(dtypes=[int, float, float])
294
+
295
+ def test_oneovern(self):
296
+ # Check derivative at x=1/n
297
+ # (Discontinuous at x=1/n, hard to tell if x==1/n, only use n=power of 2)
298
+ n = 2**np.arange(1, 10)
299
+ x = 1.0/n
300
+ pp = -(n*x+1) * (1+x)**(n-2) + 0.5
301
+ dataset0 = np.column_stack([n, x, pp])
302
+ FuncData(
303
+ _smirnovp, dataset0, (0, 1), 2, rtol=_rtol
304
+ ).check(dtypes=[int, float, float])
305
+
306
+ @pytest.mark.xfail(sys.maxsize <= 2**32,
307
+ reason="requires 64-bit platform")
308
+ def test_oneovernclose(self):
309
+ # Check derivative at x=1/n
310
+ # (Discontinuous at x=1/n, test on either side: x=1/n +/- 2epsilon)
311
+ n = np.arange(3, 20)
312
+
313
+ x = 1.0/n - 2*np.finfo(float).eps
314
+ pp = -(n*x+1) * (1+x)**(n-2)
315
+ dataset0 = np.column_stack([n, x, pp])
316
+ FuncData(
317
+ _smirnovp, dataset0, (0, 1), 2, rtol=_rtol
318
+ ).check(dtypes=[int, float, float])
319
+
320
+ x = 1.0/n + 2*np.finfo(float).eps
321
+ pp = -(n*x+1) * (1+x)**(n-2) + 1
322
+ dataset1 = np.column_stack([n, x, pp])
323
+ FuncData(
324
+ _smirnovp, dataset1, (0, 1), 2, rtol=_rtol
325
+ ).check(dtypes=[int, float, float])
326
+
327
+
328
+ class TestKolmogorov:
329
+ def test_nan(self):
330
+ assert_(np.isnan(kolmogorov(np.nan)))
331
+
332
+ def test_basic(self):
333
+ dataset = [(0, 1.0),
334
+ (0.5, 0.96394524366487511),
335
+ (0.8275735551899077, 0.5000000000000000),
336
+ (1, 0.26999967167735456),
337
+ (2, 0.00067092525577969533)]
338
+
339
+ dataset = np.asarray(dataset)
340
+ FuncData(kolmogorov, dataset, (0,), 1, rtol=_rtol).check()
341
+
342
+ def test_linspace(self):
343
+ x = np.linspace(0, 2.0, 21)
344
+ dataset = [1.0000000000000000, 1.0000000000000000, 0.9999999999994950,
345
+ 0.9999906941986655, 0.9971923267772983, 0.9639452436648751,
346
+ 0.8642827790506042, 0.7112351950296890, 0.5441424115741981,
347
+ 0.3927307079406543, 0.2699996716773546, 0.1777181926064012,
348
+ 0.1122496666707249, 0.0680922218447664, 0.0396818795381144,
349
+ 0.0222179626165251, 0.0119520432391966, 0.0061774306344441,
350
+ 0.0030676213475797, 0.0014636048371873, 0.0006709252557797]
351
+
352
+ dataset_c = [0.0000000000000000, 6.609305242245699e-53, 5.050407338670114e-13,
353
+ 9.305801334566668e-06, 0.0028076732227017, 0.0360547563351249,
354
+ 0.1357172209493958, 0.2887648049703110, 0.4558575884258019,
355
+ 0.6072692920593457, 0.7300003283226455, 0.8222818073935988,
356
+ 0.8877503333292751, 0.9319077781552336, 0.9603181204618857,
357
+ 0.9777820373834749, 0.9880479567608034, 0.9938225693655559,
358
+ 0.9969323786524203, 0.9985363951628127, 0.9993290747442203]
359
+
360
+ dataset = np.column_stack([x, dataset])
361
+ FuncData(kolmogorov, dataset, (0,), 1, rtol=_rtol).check()
362
+ dataset_c = np.column_stack([x, dataset_c])
363
+ FuncData(_kolmogc, dataset_c, (0,), 1, rtol=_rtol).check()
364
+
365
+ def test_linspacei(self):
366
+ p = np.linspace(0, 1.0, 21, endpoint=True)
367
+ dataset = [np.inf, 1.3580986393225507, 1.2238478702170823,
368
+ 1.1379465424937751, 1.0727491749396481, 1.0191847202536859,
369
+ 0.9730633753323726, 0.9320695842357622, 0.8947644549851197,
370
+ 0.8601710725555463, 0.8275735551899077, 0.7964065373291559,
371
+ 0.7661855555617682, 0.7364542888171910, 0.7067326523068980,
372
+ 0.6764476915028201, 0.6448126061663567, 0.6105590999244391,
373
+ 0.5711732651063401, 0.5196103791686224, 0.0000000000000000]
374
+
375
+ dataset_c = [0.0000000000000000, 0.5196103791686225, 0.5711732651063401,
376
+ 0.6105590999244391, 0.6448126061663567, 0.6764476915028201,
377
+ 0.7067326523068980, 0.7364542888171910, 0.7661855555617682,
378
+ 0.7964065373291559, 0.8275735551899077, 0.8601710725555463,
379
+ 0.8947644549851196, 0.9320695842357622, 0.9730633753323727,
380
+ 1.0191847202536859, 1.0727491749396481, 1.1379465424937754,
381
+ 1.2238478702170825, 1.3580986393225509, np.inf]
382
+
383
+ dataset = np.column_stack([p[1:], dataset[1:]])
384
+ FuncData(kolmogi, dataset, (0,), 1, rtol=_rtol).check()
385
+ dataset_c = np.column_stack([p[:-1], dataset_c[:-1]])
386
+ FuncData(_kolmogci, dataset_c, (0,), 1, rtol=_rtol).check()
387
+
388
+ def test_smallx(self):
389
+ epsilon = 0.1 ** np.arange(1, 14)
390
+ x = np.array([0.571173265106, 0.441027698518, 0.374219690278, 0.331392659217,
391
+ 0.300820537459, 0.277539353999, 0.259023494805, 0.243829561254,
392
+ 0.231063086389, 0.220135543236, 0.210641372041, 0.202290283658,
393
+ 0.19487060742])
394
+
395
+ dataset = np.column_stack([x, 1-epsilon])
396
+ FuncData(kolmogorov, dataset, (0,), 1, rtol=_rtol).check()
397
+
398
+ def test_round_trip(self):
399
+ def _ki_k(_x):
400
+ return kolmogi(kolmogorov(_x))
401
+
402
+ def _kci_kc(_x):
403
+ return _kolmogci(_kolmogc(_x))
404
+
405
+ x = np.linspace(0.0, 2.0, 21, endpoint=True)
406
+ # Exclude 0.1, 0.2. 0.2 almost makes succeeds, but 0.1 has no chance.
407
+ x02 = x[(x == 0) | (x > 0.21)]
408
+ dataset02 = np.column_stack([x02, x02])
409
+ FuncData(_ki_k, dataset02, (0,), 1, rtol=_rtol).check()
410
+
411
+ dataset = np.column_stack([x, x])
412
+ FuncData(_kci_kc, dataset, (0,), 1, rtol=_rtol).check()
413
+
414
+
415
+ class TestKolmogi:
416
+ def test_nan(self):
417
+ assert_(np.isnan(kolmogi(np.nan)))
418
+
419
+ def test_basic(self):
420
+ dataset = [(1.0, 0),
421
+ (0.96394524366487511, 0.5),
422
+ (0.9, 0.571173265106),
423
+ (0.5000000000000000, 0.8275735551899077),
424
+ (0.26999967167735456, 1),
425
+ (0.00067092525577969533, 2)]
426
+
427
+ dataset = np.asarray(dataset)
428
+ FuncData(kolmogi, dataset, (0,), 1, rtol=_rtol).check()
429
+
430
+ def test_smallpcdf(self):
431
+ epsilon = 0.5 ** np.arange(1, 55, 3)
432
+ # kolmogi(1-p) == _kolmogci(p) if 1-(1-p) == p, but not necessarily otherwise
433
+ # Use epsilon s.t. 1-(1-epsilon)) == epsilon,
434
+ # so can use same x-array for both results
435
+
436
+ x = np.array([0.8275735551899077, 0.5345255069097583, 0.4320114038786941,
437
+ 0.3736868442620478, 0.3345161714909591, 0.3057833329315859,
438
+ 0.2835052890528936, 0.2655578150208676, 0.2506869966107999,
439
+ 0.2380971058736669, 0.2272549289962079, 0.2177876361600040,
440
+ 0.2094254686862041, 0.2019676748836232, 0.1952612948137504,
441
+ 0.1891874239646641, 0.1836520225050326, 0.1785795904846466])
442
+
443
+ dataset = np.column_stack([1-epsilon, x])
444
+ FuncData(kolmogi, dataset, (0,), 1, rtol=_rtol).check()
445
+
446
+ dataset = np.column_stack([epsilon, x])
447
+ FuncData(_kolmogci, dataset, (0,), 1, rtol=_rtol).check()
448
+
449
+ def test_smallpsf(self):
450
+ epsilon = 0.5 ** np.arange(1, 55, 3)
451
+ # kolmogi(p) == _kolmogci(1-p) if 1-(1-p) == p, but not necessarily otherwise
452
+ # Use epsilon s.t. 1-(1-epsilon)) == epsilon,
453
+ # so can use same x-array for both results
454
+
455
+ x = np.array([0.8275735551899077, 1.3163786275161036, 1.6651092133663343,
456
+ 1.9525136345289607, 2.2027324540033235, 2.4272929437460848,
457
+ 2.6327688477341593, 2.8233300509220260, 3.0018183401530627,
458
+ 3.1702735084088891, 3.3302184446307912, 3.4828258153113318,
459
+ 3.6290214150152051, 3.7695513262825959, 3.9050272690877326,
460
+ 4.0359582187082550, 4.1627730557884890, 4.2858371743264527])
461
+
462
+ dataset = np.column_stack([epsilon, x])
463
+ FuncData(kolmogi, dataset, (0,), 1, rtol=_rtol).check()
464
+
465
+ dataset = np.column_stack([1-epsilon, x])
466
+ FuncData(_kolmogci, dataset, (0,), 1, rtol=_rtol).check()
467
+
468
+ def test_round_trip(self):
469
+ def _k_ki(_p):
470
+ return kolmogorov(kolmogi(_p))
471
+
472
+ p = np.linspace(0.1, 1.0, 10, endpoint=True)
473
+ dataset = np.column_stack([p, p])
474
+ FuncData(_k_ki, dataset, (0,), 1, rtol=_rtol).check()
475
+
476
+
477
+ class TestKolmogp:
478
+ def test_nan(self):
479
+ assert_(np.isnan(_kolmogp(np.nan)))
480
+
481
+ def test_basic(self):
482
+ dataset = [(0.000000, -0.0),
483
+ (0.200000, -1.532420541338916e-10),
484
+ (0.400000, -0.1012254419260496),
485
+ (0.600000, -1.324123244249925),
486
+ (0.800000, -1.627024345636592),
487
+ (1.000000, -1.071948558356941),
488
+ (1.200000, -0.538512430720529),
489
+ (1.400000, -0.2222133182429472),
490
+ (1.600000, -0.07649302775520538),
491
+ (1.800000, -0.02208687346347873),
492
+ (2.000000, -0.005367402045629683)]
493
+
494
+ dataset = np.asarray(dataset)
495
+ FuncData(_kolmogp, dataset, (0,), 1, rtol=_rtol).check()
openflamingo/lib/python3.10/site-packages/scipy/special/tests/test_lambertw.py ADDED
@@ -0,0 +1,109 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #
2
+ # Tests for the lambertw function,
3
+ # Adapted from the MPMath tests [1] by Yosef Meller, mellerf@netvision.net.il
4
+ # Distributed under the same license as SciPy itself.
5
+ #
6
+ # [1] mpmath source code, Subversion revision 992
7
+ # http://code.google.com/p/mpmath/source/browse/trunk/mpmath/tests/test_functions2.py?spec=svn994&r=992
8
+
9
+ import pytest
10
+ import numpy as np
11
+ from numpy.testing import assert_, assert_equal, assert_array_almost_equal
12
+ from scipy.special import lambertw
13
+ from numpy import nan, inf, pi, e, isnan, log, r_, array, complex128
14
+
15
+ from scipy.special._testutils import FuncData
16
+
17
+
18
+ def test_values():
19
+ assert_(isnan(lambertw(nan)))
20
+ assert_equal(lambertw(inf,1).real, inf)
21
+ assert_equal(lambertw(inf,1).imag, 2*pi)
22
+ assert_equal(lambertw(-inf,1).real, inf)
23
+ assert_equal(lambertw(-inf,1).imag, 3*pi)
24
+
25
+ assert_equal(lambertw(1.), lambertw(1., 0))
26
+
27
+ data = [
28
+ (0,0, 0),
29
+ (0+0j,0, 0),
30
+ (inf,0, inf),
31
+ (0,-1, -inf),
32
+ (0,1, -inf),
33
+ (0,3, -inf),
34
+ (e,0, 1),
35
+ (1,0, 0.567143290409783873),
36
+ (-pi/2,0, 1j*pi/2),
37
+ (-log(2)/2,0, -log(2)),
38
+ (0.25,0, 0.203888354702240164),
39
+ (-0.25,0, -0.357402956181388903),
40
+ (-1./10000,0, -0.000100010001500266719),
41
+ (-0.25,-1, -2.15329236411034965),
42
+ (0.25,-1, -3.00899800997004620-4.07652978899159763j),
43
+ (-0.25,-1, -2.15329236411034965),
44
+ (0.25,1, -3.00899800997004620+4.07652978899159763j),
45
+ (-0.25,1, -3.48973228422959210+7.41405453009603664j),
46
+ (-4,0, 0.67881197132094523+1.91195078174339937j),
47
+ (-4,1, -0.66743107129800988+7.76827456802783084j),
48
+ (-4,-1, 0.67881197132094523-1.91195078174339937j),
49
+ (1000,0, 5.24960285240159623),
50
+ (1000,1, 4.91492239981054535+5.44652615979447070j),
51
+ (1000,-1, 4.91492239981054535-5.44652615979447070j),
52
+ (1000,5, 3.5010625305312892+29.9614548941181328j),
53
+ (3+4j,0, 1.281561806123775878+0.533095222020971071j),
54
+ (-0.4+0.4j,0, -0.10396515323290657+0.61899273315171632j),
55
+ (3+4j,1, -0.11691092896595324+5.61888039871282334j),
56
+ (3+4j,-1, 0.25856740686699742-3.85211668616143559j),
57
+ (-0.5,-1, -0.794023632344689368-0.770111750510379110j),
58
+ (-1./10000,1, -11.82350837248724344+6.80546081842002101j),
59
+ (-1./10000,-1, -11.6671145325663544),
60
+ (-1./10000,-2, -11.82350837248724344-6.80546081842002101j),
61
+ (-1./100000,4, -14.9186890769540539+26.1856750178782046j),
62
+ (-1./100000,5, -15.0931437726379218666+32.5525721210262290086j),
63
+ ((2+1j)/10,0, 0.173704503762911669+0.071781336752835511j),
64
+ ((2+1j)/10,1, -3.21746028349820063+4.56175438896292539j),
65
+ ((2+1j)/10,-1, -3.03781405002993088-3.53946629633505737j),
66
+ ((2+1j)/10,4, -4.6878509692773249+23.8313630697683291j),
67
+ (-(2+1j)/10,0, -0.226933772515757933-0.164986470020154580j),
68
+ (-(2+1j)/10,1, -2.43569517046110001+0.76974067544756289j),
69
+ (-(2+1j)/10,-1, -3.54858738151989450-6.91627921869943589j),
70
+ (-(2+1j)/10,4, -4.5500846928118151+20.6672982215434637j),
71
+ (pi,0, 1.073658194796149172092178407024821347547745350410314531),
72
+
73
+ # Former bug in generated branch,
74
+ (-0.5+0.002j,0, -0.78917138132659918344 + 0.76743539379990327749j),
75
+ (-0.5-0.002j,0, -0.78917138132659918344 - 0.76743539379990327749j),
76
+ (-0.448+0.4j,0, -0.11855133765652382241 + 0.66570534313583423116j),
77
+ (-0.448-0.4j,0, -0.11855133765652382241 - 0.66570534313583423116j),
78
+ ]
79
+ data = array(data, dtype=complex128)
80
+
81
+ def w(x, y):
82
+ return lambertw(x, y.real.astype(int))
83
+ with np.errstate(all='ignore'):
84
+ FuncData(w, data, (0,1), 2, rtol=1e-10, atol=1e-13).check()
85
+
86
+
87
+ def test_ufunc():
88
+ assert_array_almost_equal(
89
+ lambertw(r_[0., e, 1.]), r_[0., 1., 0.567143290409783873])
90
+
91
+
92
+ def test_lambertw_ufunc_loop_selection():
93
+ # see https://github.com/scipy/scipy/issues/4895
94
+ dt = np.dtype(np.complex128)
95
+ assert_equal(lambertw(0, 0, 0).dtype, dt)
96
+ assert_equal(lambertw([0], 0, 0).dtype, dt)
97
+ assert_equal(lambertw(0, [0], 0).dtype, dt)
98
+ assert_equal(lambertw(0, 0, [0]).dtype, dt)
99
+ assert_equal(lambertw([0], [0], [0]).dtype, dt)
100
+
101
+
102
+ @pytest.mark.parametrize('z', [1e-316, -2e-320j, -5e-318+1e-320j])
103
+ def test_lambertw_subnormal_k0(z):
104
+ # Verify that subnormal inputs are handled correctly on
105
+ # the branch k=0 (regression test for gh-16291).
106
+ w = lambertw(z)
107
+ # For values this small, we can be sure that numerically,
108
+ # lambertw(z) is z.
109
+ assert w == z
openflamingo/lib/python3.10/site-packages/scipy/special/tests/test_loggamma.py ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ from numpy.testing import assert_allclose, assert_
3
+
4
+ from scipy.special._testutils import FuncData
5
+ from scipy.special import gamma, gammaln, loggamma
6
+
7
+
8
+ def test_identities1():
9
+ # test the identity exp(loggamma(z)) = gamma(z)
10
+ x = np.array([-99.5, -9.5, -0.5, 0.5, 9.5, 99.5])
11
+ y = x.copy()
12
+ x, y = np.meshgrid(x, y)
13
+ z = (x + 1J*y).flatten()
14
+ dataset = np.vstack((z, gamma(z))).T
15
+
16
+ def f(z):
17
+ return np.exp(loggamma(z))
18
+
19
+ FuncData(f, dataset, 0, 1, rtol=1e-14, atol=1e-14).check()
20
+
21
+
22
+ def test_identities2():
23
+ # test the identity loggamma(z + 1) = log(z) + loggamma(z)
24
+ x = np.array([-99.5, -9.5, -0.5, 0.5, 9.5, 99.5])
25
+ y = x.copy()
26
+ x, y = np.meshgrid(x, y)
27
+ z = (x + 1J*y).flatten()
28
+ dataset = np.vstack((z, np.log(z) + loggamma(z))).T
29
+
30
+ def f(z):
31
+ return loggamma(z + 1)
32
+
33
+ FuncData(f, dataset, 0, 1, rtol=1e-14, atol=1e-14).check()
34
+
35
+
36
+ def test_complex_dispatch_realpart():
37
+ # Test that the real parts of loggamma and gammaln agree on the
38
+ # real axis.
39
+ x = np.r_[-np.logspace(10, -10), np.logspace(-10, 10)] + 0.5
40
+
41
+ dataset = np.vstack((x, gammaln(x))).T
42
+
43
+ def f(z):
44
+ z = np.array(z, dtype='complex128')
45
+ return loggamma(z).real
46
+
47
+ FuncData(f, dataset, 0, 1, rtol=1e-14, atol=1e-14).check()
48
+
49
+
50
+ def test_real_dispatch():
51
+ x = np.logspace(-10, 10) + 0.5
52
+ dataset = np.vstack((x, gammaln(x))).T
53
+
54
+ FuncData(loggamma, dataset, 0, 1, rtol=1e-14, atol=1e-14).check()
55
+ assert_(loggamma(0) == np.inf)
56
+ assert_(np.isnan(loggamma(-1)))
57
+
58
+
59
+ def test_gh_6536():
60
+ z = loggamma(complex(-3.4, +0.0))
61
+ zbar = loggamma(complex(-3.4, -0.0))
62
+ assert_allclose(z, zbar.conjugate(), rtol=1e-15, atol=0)
63
+
64
+
65
+ def test_branch_cut():
66
+ # Make sure negative zero is treated correctly
67
+ x = -np.logspace(300, -30, 100)
68
+ z = np.asarray([complex(x0, 0.0) for x0 in x])
69
+ zbar = np.asarray([complex(x0, -0.0) for x0 in x])
70
+ assert_allclose(z, zbar.conjugate(), rtol=1e-15, atol=0)
openflamingo/lib/python3.10/site-packages/scipy/special/tests/test_logsumexp.py ADDED
@@ -0,0 +1,207 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ from numpy.testing import (assert_almost_equal, assert_equal, assert_allclose,
3
+ assert_array_almost_equal, assert_)
4
+
5
+ from scipy.special import logsumexp, softmax
6
+
7
+
8
+ def test_logsumexp():
9
+ # Test whether logsumexp() function correctly handles large inputs.
10
+ a = np.arange(200)
11
+ desired = np.log(np.sum(np.exp(a)))
12
+ assert_almost_equal(logsumexp(a), desired)
13
+
14
+ # Now test with large numbers
15
+ b = [1000, 1000]
16
+ desired = 1000.0 + np.log(2.0)
17
+ assert_almost_equal(logsumexp(b), desired)
18
+
19
+ n = 1000
20
+ b = np.full(n, 10000, dtype='float64')
21
+ desired = 10000.0 + np.log(n)
22
+ assert_almost_equal(logsumexp(b), desired)
23
+
24
+ x = np.array([1e-40] * 1000000)
25
+ logx = np.log(x)
26
+
27
+ X = np.vstack([x, x])
28
+ logX = np.vstack([logx, logx])
29
+ assert_array_almost_equal(np.exp(logsumexp(logX)), X.sum())
30
+ assert_array_almost_equal(np.exp(logsumexp(logX, axis=0)), X.sum(axis=0))
31
+ assert_array_almost_equal(np.exp(logsumexp(logX, axis=1)), X.sum(axis=1))
32
+
33
+ # Handling special values properly
34
+ assert_equal(logsumexp(np.inf), np.inf)
35
+ assert_equal(logsumexp(-np.inf), -np.inf)
36
+ assert_equal(logsumexp(np.nan), np.nan)
37
+ assert_equal(logsumexp([-np.inf, -np.inf]), -np.inf)
38
+
39
+ # Handling an array with different magnitudes on the axes
40
+ assert_array_almost_equal(logsumexp([[1e10, 1e-10],
41
+ [-1e10, -np.inf]], axis=-1),
42
+ [1e10, -1e10])
43
+
44
+ # Test keeping dimensions
45
+ assert_array_almost_equal(logsumexp([[1e10, 1e-10],
46
+ [-1e10, -np.inf]],
47
+ axis=-1,
48
+ keepdims=True),
49
+ [[1e10], [-1e10]])
50
+
51
+ # Test multiple axes
52
+ assert_array_almost_equal(logsumexp([[1e10, 1e-10],
53
+ [-1e10, -np.inf]],
54
+ axis=(-1,-2)),
55
+ 1e10)
56
+
57
+
58
+ def test_logsumexp_b():
59
+ a = np.arange(200)
60
+ b = np.arange(200, 0, -1)
61
+ desired = np.log(np.sum(b*np.exp(a)))
62
+ assert_almost_equal(logsumexp(a, b=b), desired)
63
+
64
+ a = [1000, 1000]
65
+ b = [1.2, 1.2]
66
+ desired = 1000 + np.log(2 * 1.2)
67
+ assert_almost_equal(logsumexp(a, b=b), desired)
68
+
69
+ x = np.array([1e-40] * 100000)
70
+ b = np.linspace(1, 1000, 100000)
71
+ logx = np.log(x)
72
+
73
+ X = np.vstack((x, x))
74
+ logX = np.vstack((logx, logx))
75
+ B = np.vstack((b, b))
76
+ assert_array_almost_equal(np.exp(logsumexp(logX, b=B)), (B * X).sum())
77
+ assert_array_almost_equal(np.exp(logsumexp(logX, b=B, axis=0)),
78
+ (B * X).sum(axis=0))
79
+ assert_array_almost_equal(np.exp(logsumexp(logX, b=B, axis=1)),
80
+ (B * X).sum(axis=1))
81
+
82
+
83
+ def test_logsumexp_sign():
84
+ a = [1,1,1]
85
+ b = [1,-1,-1]
86
+
87
+ r, s = logsumexp(a, b=b, return_sign=True)
88
+ assert_almost_equal(r,1)
89
+ assert_equal(s,-1)
90
+
91
+
92
+ def test_logsumexp_sign_zero():
93
+ a = [1,1]
94
+ b = [1,-1]
95
+
96
+ r, s = logsumexp(a, b=b, return_sign=True)
97
+ assert_(not np.isfinite(r))
98
+ assert_(not np.isnan(r))
99
+ assert_(r < 0)
100
+ assert_equal(s,0)
101
+
102
+
103
+ def test_logsumexp_sign_shape():
104
+ a = np.ones((1,2,3,4))
105
+ b = np.ones_like(a)
106
+
107
+ r, s = logsumexp(a, axis=2, b=b, return_sign=True)
108
+
109
+ assert_equal(r.shape, s.shape)
110
+ assert_equal(r.shape, (1,2,4))
111
+
112
+ r, s = logsumexp(a, axis=(1,3), b=b, return_sign=True)
113
+
114
+ assert_equal(r.shape, s.shape)
115
+ assert_equal(r.shape, (1,3))
116
+
117
+
118
+ def test_logsumexp_complex_sign():
119
+ a = np.array([1 + 1j, 2 - 1j, -2 + 3j])
120
+
121
+ r, s = logsumexp(a, return_sign=True)
122
+
123
+ expected_sumexp = np.exp(a).sum()
124
+ # This is the numpy>=2.0 convention for np.sign
125
+ expected_sign = expected_sumexp / abs(expected_sumexp)
126
+
127
+ assert_allclose(s, expected_sign)
128
+ assert_allclose(s * np.exp(r), expected_sumexp)
129
+
130
+
131
+ def test_logsumexp_shape():
132
+ a = np.ones((1, 2, 3, 4))
133
+ b = np.ones_like(a)
134
+
135
+ r = logsumexp(a, axis=2, b=b)
136
+ assert_equal(r.shape, (1, 2, 4))
137
+
138
+ r = logsumexp(a, axis=(1, 3), b=b)
139
+ assert_equal(r.shape, (1, 3))
140
+
141
+
142
+ def test_logsumexp_b_zero():
143
+ a = [1,10000]
144
+ b = [1,0]
145
+
146
+ assert_almost_equal(logsumexp(a, b=b), 1)
147
+
148
+
149
+ def test_logsumexp_b_shape():
150
+ a = np.zeros((4,1,2,1))
151
+ b = np.ones((3,1,5))
152
+
153
+ logsumexp(a, b=b)
154
+
155
+
156
+ def test_softmax_fixtures():
157
+ assert_allclose(softmax([1000, 0, 0, 0]), np.array([1, 0, 0, 0]),
158
+ rtol=1e-13)
159
+ assert_allclose(softmax([1, 1]), np.array([.5, .5]), rtol=1e-13)
160
+ assert_allclose(softmax([0, 1]), np.array([1, np.e])/(1 + np.e),
161
+ rtol=1e-13)
162
+
163
+ # Expected value computed using mpmath (with mpmath.mp.dps = 200) and then
164
+ # converted to float.
165
+ x = np.arange(4)
166
+ expected = np.array([0.03205860328008499,
167
+ 0.08714431874203256,
168
+ 0.23688281808991013,
169
+ 0.6439142598879722])
170
+
171
+ assert_allclose(softmax(x), expected, rtol=1e-13)
172
+
173
+ # Translation property. If all the values are changed by the same amount,
174
+ # the softmax result does not change.
175
+ assert_allclose(softmax(x + 100), expected, rtol=1e-13)
176
+
177
+ # When axis=None, softmax operates on the entire array, and preserves
178
+ # the shape.
179
+ assert_allclose(softmax(x.reshape(2, 2)), expected.reshape(2, 2),
180
+ rtol=1e-13)
181
+
182
+
183
+ def test_softmax_multi_axes():
184
+ assert_allclose(softmax([[1000, 0], [1000, 0]], axis=0),
185
+ np.array([[.5, .5], [.5, .5]]), rtol=1e-13)
186
+ assert_allclose(softmax([[1000, 0], [1000, 0]], axis=1),
187
+ np.array([[1, 0], [1, 0]]), rtol=1e-13)
188
+
189
+ # Expected value computed using mpmath (with mpmath.mp.dps = 200) and then
190
+ # converted to float.
191
+ x = np.array([[-25, 0, 25, 50],
192
+ [1, 325, 749, 750]])
193
+ expected = np.array([[2.678636961770877e-33,
194
+ 1.9287498479371314e-22,
195
+ 1.3887943864771144e-11,
196
+ 0.999999999986112],
197
+ [0.0,
198
+ 1.9444526359919372e-185,
199
+ 0.2689414213699951,
200
+ 0.7310585786300048]])
201
+ assert_allclose(softmax(x, axis=1), expected, rtol=1e-13)
202
+ assert_allclose(softmax(x.T, axis=0), expected.T, rtol=1e-13)
203
+
204
+ # 3-d input, with a tuple for the axis.
205
+ x3d = x.reshape(2, 2, 2)
206
+ assert_allclose(softmax(x3d, axis=(1, 2)), expected.reshape(2, 2, 2),
207
+ rtol=1e-13)
openflamingo/lib/python3.10/site-packages/scipy/special/tests/test_mpmath.py ADDED
@@ -0,0 +1,2272 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Test SciPy functions versus mpmath, if available.
3
+
4
+ """
5
+ import numpy as np
6
+ from numpy.testing import assert_, assert_allclose
7
+ from numpy import pi
8
+ import pytest
9
+ import itertools
10
+
11
+ from scipy._lib import _pep440
12
+
13
+ import scipy.special as sc
14
+ from scipy.special._testutils import (
15
+ MissingModule, check_version, FuncData,
16
+ assert_func_equal)
17
+ from scipy.special._mptestutils import (
18
+ Arg, FixedArg, ComplexArg, IntArg, assert_mpmath_equal,
19
+ nonfunctional_tooslow, trace_args, time_limited, exception_to_nan,
20
+ inf_to_nan)
21
+ from scipy.special._ufuncs import (
22
+ _sinpi, _cospi, _lgam1p, _lanczos_sum_expg_scaled, _log1pmx,
23
+ _igam_fac)
24
+
25
+ try:
26
+ import mpmath
27
+ except ImportError:
28
+ mpmath = MissingModule('mpmath')
29
+
30
+
31
+ # ------------------------------------------------------------------------------
32
+ # expi
33
+ # ------------------------------------------------------------------------------
34
+
35
+ @check_version(mpmath, '0.10')
36
+ def test_expi_complex():
37
+ dataset = []
38
+ for r in np.logspace(-99, 2, 10):
39
+ for p in np.linspace(0, 2*np.pi, 30):
40
+ z = r*np.exp(1j*p)
41
+ dataset.append((z, complex(mpmath.ei(z))))
42
+ dataset = np.array(dataset, dtype=np.cdouble)
43
+
44
+ FuncData(sc.expi, dataset, 0, 1).check()
45
+
46
+
47
+ # ------------------------------------------------------------------------------
48
+ # expn
49
+ # ------------------------------------------------------------------------------
50
+
51
+ @check_version(mpmath, '0.19')
52
+ def test_expn_large_n():
53
+ # Test the transition to the asymptotic regime of n.
54
+ dataset = []
55
+ for n in [50, 51]:
56
+ for x in np.logspace(0, 4, 200):
57
+ with mpmath.workdps(100):
58
+ dataset.append((n, x, float(mpmath.expint(n, x))))
59
+ dataset = np.asarray(dataset)
60
+
61
+ FuncData(sc.expn, dataset, (0, 1), 2, rtol=1e-13).check()
62
+
63
+ # ------------------------------------------------------------------------------
64
+ # hyp0f1
65
+ # ------------------------------------------------------------------------------
66
+
67
+
68
+ @check_version(mpmath, '0.19')
69
+ def test_hyp0f1_gh5764():
70
+ # Do a small and somewhat systematic test that runs quickly
71
+ dataset = []
72
+ axis = [-99.5, -9.5, -0.5, 0.5, 9.5, 99.5]
73
+ for v in axis:
74
+ for x in axis:
75
+ for y in axis:
76
+ z = x + 1j*y
77
+ # mpmath computes the answer correctly at dps ~ 17 but
78
+ # fails for 20 < dps < 120 (uses a different method);
79
+ # set the dps high enough that this isn't an issue
80
+ with mpmath.workdps(120):
81
+ res = complex(mpmath.hyp0f1(v, z))
82
+ dataset.append((v, z, res))
83
+ dataset = np.array(dataset)
84
+
85
+ FuncData(lambda v, z: sc.hyp0f1(v.real, z), dataset, (0, 1), 2,
86
+ rtol=1e-13).check()
87
+
88
+
89
+ @check_version(mpmath, '0.19')
90
+ def test_hyp0f1_gh_1609():
91
+ # this is a regression test for gh-1609
92
+ vv = np.linspace(150, 180, 21)
93
+ af = sc.hyp0f1(vv, 0.5)
94
+ mf = np.array([mpmath.hyp0f1(v, 0.5) for v in vv])
95
+ assert_allclose(af, mf.astype(float), rtol=1e-12)
96
+
97
+
98
+ # ------------------------------------------------------------------------------
99
+ # hyperu
100
+ # ------------------------------------------------------------------------------
101
+
102
+ @check_version(mpmath, '1.1.0')
103
+ def test_hyperu_around_0():
104
+ dataset = []
105
+ # DLMF 13.2.14-15 test points.
106
+ for n in np.arange(-5, 5):
107
+ for b in np.linspace(-5, 5, 20):
108
+ a = -n
109
+ dataset.append((a, b, 0, float(mpmath.hyperu(a, b, 0))))
110
+ a = -n + b - 1
111
+ dataset.append((a, b, 0, float(mpmath.hyperu(a, b, 0))))
112
+ # DLMF 13.2.16-22 test points.
113
+ for a in [-10.5, -1.5, -0.5, 0, 0.5, 1, 10]:
114
+ for b in [-1.0, -0.5, 0, 0.5, 1, 1.5, 2, 2.5]:
115
+ dataset.append((a, b, 0, float(mpmath.hyperu(a, b, 0))))
116
+ dataset = np.array(dataset)
117
+
118
+ FuncData(sc.hyperu, dataset, (0, 1, 2), 3, rtol=1e-15, atol=5e-13).check()
119
+
120
+
121
+ # ------------------------------------------------------------------------------
122
+ # hyp2f1
123
+ # ------------------------------------------------------------------------------
124
+
125
+ @check_version(mpmath, '1.0.0')
126
+ def test_hyp2f1_strange_points():
127
+ pts = [
128
+ (2, -1, -1, 0.7), # expected: 2.4
129
+ (2, -2, -2, 0.7), # expected: 3.87
130
+ ]
131
+ pts += list(itertools.product([2, 1, -0.7, -1000], repeat=4))
132
+ pts = [
133
+ (a, b, c, x) for a, b, c, x in pts
134
+ if b == c and round(b) == b and b < 0 and b != -1000
135
+ ]
136
+ kw = dict(eliminate=True)
137
+ dataset = [p + (float(mpmath.hyp2f1(*p, **kw)),) for p in pts]
138
+ dataset = np.array(dataset, dtype=np.float64)
139
+
140
+ FuncData(sc.hyp2f1, dataset, (0,1,2,3), 4, rtol=1e-10).check()
141
+
142
+
143
+ @check_version(mpmath, '0.13')
144
+ def test_hyp2f1_real_some_points():
145
+ pts = [
146
+ (1, 2, 3, 0),
147
+ (1./3, 2./3, 5./6, 27./32),
148
+ (1./4, 1./2, 3./4, 80./81),
149
+ (2,-2, -3, 3),
150
+ (2, -3, -2, 3),
151
+ (2, -1.5, -1.5, 3),
152
+ (1, 2, 3, 0),
153
+ (0.7235, -1, -5, 0.3),
154
+ (0.25, 1./3, 2, 0.999),
155
+ (0.25, 1./3, 2, -1),
156
+ (2, 3, 5, 0.99),
157
+ (3./2, -0.5, 3, 0.99),
158
+ (2, 2.5, -3.25, 0.999),
159
+ (-8, 18.016500331508873, 10.805295997850628, 0.90875647507000001),
160
+ (-10, 900, -10.5, 0.99),
161
+ (-10, 900, 10.5, 0.99),
162
+ (-1, 2, 1, 1.0),
163
+ (-1, 2, 1, -1.0),
164
+ (-3, 13, 5, 1.0),
165
+ (-3, 13, 5, -1.0),
166
+ (0.5, 1 - 270.5, 1.5, 0.999**2), # from issue 1561
167
+ ]
168
+ dataset = [p + (float(mpmath.hyp2f1(*p)),) for p in pts]
169
+ dataset = np.array(dataset, dtype=np.float64)
170
+
171
+ with np.errstate(invalid='ignore'):
172
+ FuncData(sc.hyp2f1, dataset, (0,1,2,3), 4, rtol=1e-10).check()
173
+
174
+
175
+ @check_version(mpmath, '0.14')
176
+ def test_hyp2f1_some_points_2():
177
+ # Taken from mpmath unit tests -- this point failed for mpmath 0.13 but
178
+ # was fixed in their SVN since then
179
+ pts = [
180
+ (112, (51,10), (-9,10), -0.99999),
181
+ (10,-900,10.5,0.99),
182
+ (10,-900,-10.5,0.99),
183
+ ]
184
+
185
+ def fev(x):
186
+ if isinstance(x, tuple):
187
+ return float(x[0]) / x[1]
188
+ else:
189
+ return x
190
+
191
+ dataset = [tuple(map(fev, p)) + (float(mpmath.hyp2f1(*p)),) for p in pts]
192
+ dataset = np.array(dataset, dtype=np.float64)
193
+
194
+ FuncData(sc.hyp2f1, dataset, (0,1,2,3), 4, rtol=1e-10).check()
195
+
196
+
197
+ @check_version(mpmath, '0.13')
198
+ def test_hyp2f1_real_some():
199
+ dataset = []
200
+ for a in [-10, -5, -1.8, 1.8, 5, 10]:
201
+ for b in [-2.5, -1, 1, 7.4]:
202
+ for c in [-9, -1.8, 5, 20.4]:
203
+ for z in [-10, -1.01, -0.99, 0, 0.6, 0.95, 1.5, 10]:
204
+ try:
205
+ v = float(mpmath.hyp2f1(a, b, c, z))
206
+ except Exception:
207
+ continue
208
+ dataset.append((a, b, c, z, v))
209
+ dataset = np.array(dataset, dtype=np.float64)
210
+
211
+ with np.errstate(invalid='ignore'):
212
+ FuncData(sc.hyp2f1, dataset, (0,1,2,3), 4, rtol=1e-9,
213
+ ignore_inf_sign=True).check()
214
+
215
+
216
+ @check_version(mpmath, '0.12')
217
+ @pytest.mark.slow
218
+ def test_hyp2f1_real_random():
219
+ npoints = 500
220
+ dataset = np.zeros((npoints, 5), np.float64)
221
+
222
+ np.random.seed(1234)
223
+ dataset[:, 0] = np.random.pareto(1.5, npoints)
224
+ dataset[:, 1] = np.random.pareto(1.5, npoints)
225
+ dataset[:, 2] = np.random.pareto(1.5, npoints)
226
+ dataset[:, 3] = 2*np.random.rand(npoints) - 1
227
+
228
+ dataset[:, 0] *= (-1)**np.random.randint(2, npoints)
229
+ dataset[:, 1] *= (-1)**np.random.randint(2, npoints)
230
+ dataset[:, 2] *= (-1)**np.random.randint(2, npoints)
231
+
232
+ for ds in dataset:
233
+ if mpmath.__version__ < '0.14':
234
+ # mpmath < 0.14 fails for c too much smaller than a, b
235
+ if abs(ds[:2]).max() > abs(ds[2]):
236
+ ds[2] = abs(ds[:2]).max()
237
+ ds[4] = float(mpmath.hyp2f1(*tuple(ds[:4])))
238
+
239
+ FuncData(sc.hyp2f1, dataset, (0, 1, 2, 3), 4, rtol=1e-9).check()
240
+
241
+
242
+ # ------------------------------------------------------------------------------
243
+ # erf (complex)
244
+ # ------------------------------------------------------------------------------
245
+
246
+ @check_version(mpmath, '0.14')
247
+ def test_erf_complex():
248
+ # need to increase mpmath precision for this test
249
+ old_dps, old_prec = mpmath.mp.dps, mpmath.mp.prec
250
+ try:
251
+ mpmath.mp.dps = 70
252
+ x1, y1 = np.meshgrid(np.linspace(-10, 1, 31), np.linspace(-10, 1, 11))
253
+ x2, y2 = np.meshgrid(np.logspace(-80, .8, 31), np.logspace(-80, .8, 11))
254
+ points = np.r_[x1.ravel(),x2.ravel()] + 1j*np.r_[y1.ravel(), y2.ravel()]
255
+
256
+ assert_func_equal(sc.erf, lambda x: complex(mpmath.erf(x)), points,
257
+ vectorized=False, rtol=1e-13)
258
+ assert_func_equal(sc.erfc, lambda x: complex(mpmath.erfc(x)), points,
259
+ vectorized=False, rtol=1e-13)
260
+ finally:
261
+ mpmath.mp.dps, mpmath.mp.prec = old_dps, old_prec
262
+
263
+
264
+ # ------------------------------------------------------------------------------
265
+ # lpmv
266
+ # ------------------------------------------------------------------------------
267
+
268
+ @check_version(mpmath, '0.15')
269
+ def test_lpmv():
270
+ pts = []
271
+ for x in [-0.99, -0.557, 1e-6, 0.132, 1]:
272
+ pts.extend([
273
+ (1, 1, x),
274
+ (1, -1, x),
275
+ (-1, 1, x),
276
+ (-1, -2, x),
277
+ (1, 1.7, x),
278
+ (1, -1.7, x),
279
+ (-1, 1.7, x),
280
+ (-1, -2.7, x),
281
+ (1, 10, x),
282
+ (1, 11, x),
283
+ (3, 8, x),
284
+ (5, 11, x),
285
+ (-3, 8, x),
286
+ (-5, 11, x),
287
+ (3, -8, x),
288
+ (5, -11, x),
289
+ (-3, -8, x),
290
+ (-5, -11, x),
291
+ (3, 8.3, x),
292
+ (5, 11.3, x),
293
+ (-3, 8.3, x),
294
+ (-5, 11.3, x),
295
+ (3, -8.3, x),
296
+ (5, -11.3, x),
297
+ (-3, -8.3, x),
298
+ (-5, -11.3, x),
299
+ ])
300
+
301
+ def mplegenp(nu, mu, x):
302
+ if mu == int(mu) and x == 1:
303
+ # mpmath 0.17 gets this wrong
304
+ if mu == 0:
305
+ return 1
306
+ else:
307
+ return 0
308
+ return mpmath.legenp(nu, mu, x)
309
+
310
+ dataset = [p + (mplegenp(p[1], p[0], p[2]),) for p in pts]
311
+ dataset = np.array(dataset, dtype=np.float64)
312
+
313
+ def evf(mu, nu, x):
314
+ return sc.lpmv(mu.astype(int), nu, x)
315
+
316
+ with np.errstate(invalid='ignore'):
317
+ FuncData(evf, dataset, (0,1,2), 3, rtol=1e-10, atol=1e-14).check()
318
+
319
+
320
+ # ------------------------------------------------------------------------------
321
+ # beta
322
+ # ------------------------------------------------------------------------------
323
+
324
+ @check_version(mpmath, '0.15')
325
+ def test_beta():
326
+ np.random.seed(1234)
327
+
328
+ b = np.r_[np.logspace(-200, 200, 4),
329
+ np.logspace(-10, 10, 4),
330
+ np.logspace(-1, 1, 4),
331
+ np.arange(-10, 11, 1),
332
+ np.arange(-10, 11, 1) + 0.5,
333
+ -1, -2.3, -3, -100.3, -10003.4]
334
+ a = b
335
+
336
+ ab = np.array(np.broadcast_arrays(a[:,None], b[None,:])).reshape(2, -1).T
337
+
338
+ old_dps, old_prec = mpmath.mp.dps, mpmath.mp.prec
339
+ try:
340
+ mpmath.mp.dps = 400
341
+
342
+ assert_func_equal(sc.beta,
343
+ lambda a, b: float(mpmath.beta(a, b)),
344
+ ab,
345
+ vectorized=False,
346
+ rtol=1e-10,
347
+ ignore_inf_sign=True)
348
+
349
+ assert_func_equal(
350
+ sc.betaln,
351
+ lambda a, b: float(mpmath.log(abs(mpmath.beta(a, b)))),
352
+ ab,
353
+ vectorized=False,
354
+ rtol=1e-10)
355
+ finally:
356
+ mpmath.mp.dps, mpmath.mp.prec = old_dps, old_prec
357
+
358
+
359
+ # ------------------------------------------------------------------------------
360
+ # loggamma
361
+ # ------------------------------------------------------------------------------
362
+
363
+ LOGGAMMA_TAYLOR_RADIUS = 0.2
364
+
365
+
366
+ @check_version(mpmath, '0.19')
367
+ def test_loggamma_taylor_transition():
368
+ # Make sure there isn't a big jump in accuracy when we move from
369
+ # using the Taylor series to using the recurrence relation.
370
+
371
+ r = LOGGAMMA_TAYLOR_RADIUS + np.array([-0.1, -0.01, 0, 0.01, 0.1])
372
+ theta = np.linspace(0, 2*np.pi, 20)
373
+ r, theta = np.meshgrid(r, theta)
374
+ dz = r*np.exp(1j*theta)
375
+ z = np.r_[1 + dz, 2 + dz].flatten()
376
+
377
+ dataset = [(z0, complex(mpmath.loggamma(z0))) for z0 in z]
378
+ dataset = np.array(dataset)
379
+
380
+ FuncData(sc.loggamma, dataset, 0, 1, rtol=5e-14).check()
381
+
382
+
383
+ @check_version(mpmath, '0.19')
384
+ def test_loggamma_taylor():
385
+ # Test around the zeros at z = 1, 2.
386
+
387
+ r = np.logspace(-16, np.log10(LOGGAMMA_TAYLOR_RADIUS), 10)
388
+ theta = np.linspace(0, 2*np.pi, 20)
389
+ r, theta = np.meshgrid(r, theta)
390
+ dz = r*np.exp(1j*theta)
391
+ z = np.r_[1 + dz, 2 + dz].flatten()
392
+
393
+ dataset = [(z0, complex(mpmath.loggamma(z0))) for z0 in z]
394
+ dataset = np.array(dataset)
395
+
396
+ FuncData(sc.loggamma, dataset, 0, 1, rtol=5e-14).check()
397
+
398
+
399
+ # ------------------------------------------------------------------------------
400
+ # rgamma
401
+ # ------------------------------------------------------------------------------
402
+
403
+ @check_version(mpmath, '0.19')
404
+ @pytest.mark.slow
405
+ def test_rgamma_zeros():
406
+ # Test around the zeros at z = 0, -1, -2, ..., -169. (After -169 we
407
+ # get values that are out of floating point range even when we're
408
+ # within 0.1 of the zero.)
409
+
410
+ # Can't use too many points here or the test takes forever.
411
+ dx = np.r_[-np.logspace(-1, -13, 3), 0, np.logspace(-13, -1, 3)]
412
+ dy = dx.copy()
413
+ dx, dy = np.meshgrid(dx, dy)
414
+ dz = dx + 1j*dy
415
+ zeros = np.arange(0, -170, -1).reshape(1, 1, -1)
416
+ z = (zeros + np.dstack((dz,)*zeros.size)).flatten()
417
+ with mpmath.workdps(100):
418
+ dataset = [(z0, complex(mpmath.rgamma(z0))) for z0 in z]
419
+
420
+ dataset = np.array(dataset)
421
+ FuncData(sc.rgamma, dataset, 0, 1, rtol=1e-12).check()
422
+
423
+
424
+ # ------------------------------------------------------------------------------
425
+ # digamma
426
+ # ------------------------------------------------------------------------------
427
+
428
+ @check_version(mpmath, '0.19')
429
+ @pytest.mark.slow
430
+ def test_digamma_roots():
431
+ # Test the special-cased roots for digamma.
432
+ root = mpmath.findroot(mpmath.digamma, 1.5)
433
+ roots = [float(root)]
434
+ root = mpmath.findroot(mpmath.digamma, -0.5)
435
+ roots.append(float(root))
436
+ roots = np.array(roots)
437
+
438
+ # If we test beyond a radius of 0.24 mpmath will take forever.
439
+ dx = np.r_[-0.24, -np.logspace(-1, -15, 10), 0, np.logspace(-15, -1, 10), 0.24]
440
+ dy = dx.copy()
441
+ dx, dy = np.meshgrid(dx, dy)
442
+ dz = dx + 1j*dy
443
+ z = (roots + np.dstack((dz,)*roots.size)).flatten()
444
+ with mpmath.workdps(30):
445
+ dataset = [(z0, complex(mpmath.digamma(z0))) for z0 in z]
446
+
447
+ dataset = np.array(dataset)
448
+ FuncData(sc.digamma, dataset, 0, 1, rtol=1e-14).check()
449
+
450
+
451
+ @check_version(mpmath, '0.19')
452
+ def test_digamma_negreal():
453
+ # Test digamma around the negative real axis. Don't do this in
454
+ # TestSystematic because the points need some jiggering so that
455
+ # mpmath doesn't take forever.
456
+
457
+ digamma = exception_to_nan(mpmath.digamma)
458
+
459
+ x = -np.logspace(300, -30, 100)
460
+ y = np.r_[-np.logspace(0, -3, 5), 0, np.logspace(-3, 0, 5)]
461
+ x, y = np.meshgrid(x, y)
462
+ z = (x + 1j*y).flatten()
463
+
464
+ with mpmath.workdps(40):
465
+ dataset = [(z0, complex(digamma(z0))) for z0 in z]
466
+ dataset = np.asarray(dataset)
467
+
468
+ FuncData(sc.digamma, dataset, 0, 1, rtol=1e-13).check()
469
+
470
+
471
+ @check_version(mpmath, '0.19')
472
+ def test_digamma_boundary():
473
+ # Check that there isn't a jump in accuracy when we switch from
474
+ # using the asymptotic series to the reflection formula.
475
+
476
+ x = -np.logspace(300, -30, 100)
477
+ y = np.array([-6.1, -5.9, 5.9, 6.1])
478
+ x, y = np.meshgrid(x, y)
479
+ z = (x + 1j*y).flatten()
480
+
481
+ with mpmath.workdps(30):
482
+ dataset = [(z0, complex(mpmath.digamma(z0))) for z0 in z]
483
+ dataset = np.asarray(dataset)
484
+
485
+ FuncData(sc.digamma, dataset, 0, 1, rtol=1e-13).check()
486
+
487
+
488
+ # ------------------------------------------------------------------------------
489
+ # gammainc
490
+ # ------------------------------------------------------------------------------
491
+
492
+ @check_version(mpmath, '0.19')
493
+ @pytest.mark.slow
494
+ def test_gammainc_boundary():
495
+ # Test the transition to the asymptotic series.
496
+ small = 20
497
+ a = np.linspace(0.5*small, 2*small, 50)
498
+ x = a.copy()
499
+ a, x = np.meshgrid(a, x)
500
+ a, x = a.flatten(), x.flatten()
501
+ with mpmath.workdps(100):
502
+ dataset = [(a0, x0, float(mpmath.gammainc(a0, b=x0, regularized=True)))
503
+ for a0, x0 in zip(a, x)]
504
+ dataset = np.array(dataset)
505
+
506
+ FuncData(sc.gammainc, dataset, (0, 1), 2, rtol=1e-12).check()
507
+
508
+
509
+ # ------------------------------------------------------------------------------
510
+ # spence
511
+ # ------------------------------------------------------------------------------
512
+
513
+ @check_version(mpmath, '0.19')
514
+ @pytest.mark.slow
515
+ def test_spence_circle():
516
+ # The trickiest region for spence is around the circle |z - 1| = 1,
517
+ # so test that region carefully.
518
+
519
+ def spence(z):
520
+ return complex(mpmath.polylog(2, 1 - z))
521
+
522
+ r = np.linspace(0.5, 1.5)
523
+ theta = np.linspace(0, 2*pi)
524
+ z = (1 + np.outer(r, np.exp(1j*theta))).flatten()
525
+ dataset = np.asarray([(z0, spence(z0)) for z0 in z])
526
+
527
+ FuncData(sc.spence, dataset, 0, 1, rtol=1e-14).check()
528
+
529
+
530
+ # ------------------------------------------------------------------------------
531
+ # sinpi and cospi
532
+ # ------------------------------------------------------------------------------
533
+
534
+ @check_version(mpmath, '0.19')
535
+ def test_sinpi_zeros():
536
+ eps = np.finfo(float).eps
537
+ dx = np.r_[-np.logspace(0, -13, 3), 0, np.logspace(-13, 0, 3)]
538
+ dy = dx.copy()
539
+ dx, dy = np.meshgrid(dx, dy)
540
+ dz = dx + 1j*dy
541
+ zeros = np.arange(-100, 100, 1).reshape(1, 1, -1)
542
+ z = (zeros + np.dstack((dz,)*zeros.size)).flatten()
543
+ dataset = np.asarray([(z0, complex(mpmath.sinpi(z0)))
544
+ for z0 in z])
545
+ FuncData(_sinpi, dataset, 0, 1, rtol=2*eps).check()
546
+
547
+
548
+ @check_version(mpmath, '0.19')
549
+ def test_cospi_zeros():
550
+ eps = np.finfo(float).eps
551
+ dx = np.r_[-np.logspace(0, -13, 3), 0, np.logspace(-13, 0, 3)]
552
+ dy = dx.copy()
553
+ dx, dy = np.meshgrid(dx, dy)
554
+ dz = dx + 1j*dy
555
+ zeros = (np.arange(-100, 100, 1) + 0.5).reshape(1, 1, -1)
556
+ z = (zeros + np.dstack((dz,)*zeros.size)).flatten()
557
+ dataset = np.asarray([(z0, complex(mpmath.cospi(z0)))
558
+ for z0 in z])
559
+
560
+ FuncData(_cospi, dataset, 0, 1, rtol=2*eps).check()
561
+
562
+
563
+ # ------------------------------------------------------------------------------
564
+ # ellipj
565
+ # ------------------------------------------------------------------------------
566
+
567
+ @check_version(mpmath, '0.19')
568
+ def test_dn_quarter_period():
569
+ def dn(u, m):
570
+ return sc.ellipj(u, m)[2]
571
+
572
+ def mpmath_dn(u, m):
573
+ return float(mpmath.ellipfun("dn", u=u, m=m))
574
+
575
+ m = np.linspace(0, 1, 20)
576
+ du = np.r_[-np.logspace(-1, -15, 10), 0, np.logspace(-15, -1, 10)]
577
+ dataset = []
578
+ for m0 in m:
579
+ u0 = float(mpmath.ellipk(m0))
580
+ for du0 in du:
581
+ p = u0 + du0
582
+ dataset.append((p, m0, mpmath_dn(p, m0)))
583
+ dataset = np.asarray(dataset)
584
+
585
+ FuncData(dn, dataset, (0, 1), 2, rtol=1e-10).check()
586
+
587
+
588
+ # ------------------------------------------------------------------------------
589
+ # Wright Omega
590
+ # ------------------------------------------------------------------------------
591
+
592
+ def _mpmath_wrightomega(z, dps):
593
+ with mpmath.workdps(dps):
594
+ z = mpmath.mpc(z)
595
+ unwind = mpmath.ceil((z.imag - mpmath.pi)/(2*mpmath.pi))
596
+ res = mpmath.lambertw(mpmath.exp(z), unwind)
597
+ return res
598
+
599
+
600
+ @pytest.mark.slow
601
+ @check_version(mpmath, '0.19')
602
+ def test_wrightomega_branch():
603
+ x = -np.logspace(10, 0, 25)
604
+ picut_above = [np.nextafter(np.pi, np.inf)]
605
+ picut_below = [np.nextafter(np.pi, -np.inf)]
606
+ npicut_above = [np.nextafter(-np.pi, np.inf)]
607
+ npicut_below = [np.nextafter(-np.pi, -np.inf)]
608
+ for i in range(50):
609
+ picut_above.append(np.nextafter(picut_above[-1], np.inf))
610
+ picut_below.append(np.nextafter(picut_below[-1], -np.inf))
611
+ npicut_above.append(np.nextafter(npicut_above[-1], np.inf))
612
+ npicut_below.append(np.nextafter(npicut_below[-1], -np.inf))
613
+ y = np.hstack((picut_above, picut_below, npicut_above, npicut_below))
614
+ x, y = np.meshgrid(x, y)
615
+ z = (x + 1j*y).flatten()
616
+
617
+ dataset = np.asarray([(z0, complex(_mpmath_wrightomega(z0, 25)))
618
+ for z0 in z])
619
+
620
+ FuncData(sc.wrightomega, dataset, 0, 1, rtol=1e-8).check()
621
+
622
+
623
+ @pytest.mark.slow
624
+ @check_version(mpmath, '0.19')
625
+ def test_wrightomega_region1():
626
+ # This region gets less coverage in the TestSystematic test
627
+ x = np.linspace(-2, 1)
628
+ y = np.linspace(1, 2*np.pi)
629
+ x, y = np.meshgrid(x, y)
630
+ z = (x + 1j*y).flatten()
631
+
632
+ dataset = np.asarray([(z0, complex(_mpmath_wrightomega(z0, 25)))
633
+ for z0 in z])
634
+
635
+ FuncData(sc.wrightomega, dataset, 0, 1, rtol=1e-15).check()
636
+
637
+
638
+ @pytest.mark.slow
639
+ @check_version(mpmath, '0.19')
640
+ def test_wrightomega_region2():
641
+ # This region gets less coverage in the TestSystematic test
642
+ x = np.linspace(-2, 1)
643
+ y = np.linspace(-2*np.pi, -1)
644
+ x, y = np.meshgrid(x, y)
645
+ z = (x + 1j*y).flatten()
646
+
647
+ dataset = np.asarray([(z0, complex(_mpmath_wrightomega(z0, 25)))
648
+ for z0 in z])
649
+
650
+ FuncData(sc.wrightomega, dataset, 0, 1, rtol=1e-15).check()
651
+
652
+
653
+ # ------------------------------------------------------------------------------
654
+ # lambertw
655
+ # ------------------------------------------------------------------------------
656
+
657
+ @pytest.mark.slow
658
+ @check_version(mpmath, '0.19')
659
+ def test_lambertw_smallz():
660
+ x, y = np.linspace(-1, 1, 25), np.linspace(-1, 1, 25)
661
+ x, y = np.meshgrid(x, y)
662
+ z = (x + 1j*y).flatten()
663
+
664
+ dataset = np.asarray([(z0, complex(mpmath.lambertw(z0)))
665
+ for z0 in z])
666
+
667
+ FuncData(sc.lambertw, dataset, 0, 1, rtol=1e-13).check()
668
+
669
+
670
+ # ------------------------------------------------------------------------------
671
+ # Systematic tests
672
+ # ------------------------------------------------------------------------------
673
+
674
+ HYPERKW = dict(maxprec=200, maxterms=200)
675
+
676
+
677
+ @pytest.mark.slow
678
+ @check_version(mpmath, '0.17')
679
+ class TestSystematic:
680
+
681
+ def test_airyai(self):
682
+ # oscillating function, limit range
683
+ assert_mpmath_equal(lambda z: sc.airy(z)[0],
684
+ mpmath.airyai,
685
+ [Arg(-1e8, 1e8)],
686
+ rtol=1e-5)
687
+ assert_mpmath_equal(lambda z: sc.airy(z)[0],
688
+ mpmath.airyai,
689
+ [Arg(-1e3, 1e3)])
690
+
691
+ def test_airyai_complex(self):
692
+ assert_mpmath_equal(lambda z: sc.airy(z)[0],
693
+ mpmath.airyai,
694
+ [ComplexArg()])
695
+
696
+ def test_airyai_prime(self):
697
+ # oscillating function, limit range
698
+ assert_mpmath_equal(lambda z: sc.airy(z)[1], lambda z:
699
+ mpmath.airyai(z, derivative=1),
700
+ [Arg(-1e8, 1e8)],
701
+ rtol=1e-5)
702
+ assert_mpmath_equal(lambda z: sc.airy(z)[1], lambda z:
703
+ mpmath.airyai(z, derivative=1),
704
+ [Arg(-1e3, 1e3)])
705
+
706
+ def test_airyai_prime_complex(self):
707
+ assert_mpmath_equal(lambda z: sc.airy(z)[1], lambda z:
708
+ mpmath.airyai(z, derivative=1),
709
+ [ComplexArg()])
710
+
711
+ def test_airybi(self):
712
+ # oscillating function, limit range
713
+ assert_mpmath_equal(lambda z: sc.airy(z)[2], lambda z:
714
+ mpmath.airybi(z),
715
+ [Arg(-1e8, 1e8)],
716
+ rtol=1e-5)
717
+ assert_mpmath_equal(lambda z: sc.airy(z)[2], lambda z:
718
+ mpmath.airybi(z),
719
+ [Arg(-1e3, 1e3)])
720
+
721
+ def test_airybi_complex(self):
722
+ assert_mpmath_equal(lambda z: sc.airy(z)[2], lambda z:
723
+ mpmath.airybi(z),
724
+ [ComplexArg()])
725
+
726
+ def test_airybi_prime(self):
727
+ # oscillating function, limit range
728
+ assert_mpmath_equal(lambda z: sc.airy(z)[3], lambda z:
729
+ mpmath.airybi(z, derivative=1),
730
+ [Arg(-1e8, 1e8)],
731
+ rtol=1e-5)
732
+ assert_mpmath_equal(lambda z: sc.airy(z)[3], lambda z:
733
+ mpmath.airybi(z, derivative=1),
734
+ [Arg(-1e3, 1e3)])
735
+
736
+ def test_airybi_prime_complex(self):
737
+ assert_mpmath_equal(lambda z: sc.airy(z)[3], lambda z:
738
+ mpmath.airybi(z, derivative=1),
739
+ [ComplexArg()])
740
+
741
+ def test_bei(self):
742
+ assert_mpmath_equal(sc.bei,
743
+ exception_to_nan(lambda z: mpmath.bei(0, z, **HYPERKW)),
744
+ [Arg(-1e3, 1e3)])
745
+
746
+ def test_ber(self):
747
+ assert_mpmath_equal(sc.ber,
748
+ exception_to_nan(lambda z: mpmath.ber(0, z, **HYPERKW)),
749
+ [Arg(-1e3, 1e3)])
750
+
751
+ def test_bernoulli(self):
752
+ assert_mpmath_equal(lambda n: sc.bernoulli(int(n))[int(n)],
753
+ lambda n: float(mpmath.bernoulli(int(n))),
754
+ [IntArg(0, 13000)],
755
+ rtol=1e-9, n=13000)
756
+
757
+ def test_besseli(self):
758
+ assert_mpmath_equal(
759
+ sc.iv,
760
+ exception_to_nan(lambda v, z: mpmath.besseli(v, z, **HYPERKW)),
761
+ [Arg(-1e100, 1e100), Arg()],
762
+ atol=1e-270,
763
+ )
764
+
765
+ def test_besseli_complex(self):
766
+ assert_mpmath_equal(
767
+ lambda v, z: sc.iv(v.real, z),
768
+ exception_to_nan(lambda v, z: mpmath.besseli(v, z, **HYPERKW)),
769
+ [Arg(-1e100, 1e100), ComplexArg()],
770
+ )
771
+
772
+ def test_besselj(self):
773
+ assert_mpmath_equal(
774
+ sc.jv,
775
+ exception_to_nan(lambda v, z: mpmath.besselj(v, z, **HYPERKW)),
776
+ [Arg(-1e100, 1e100), Arg(-1e3, 1e3)],
777
+ ignore_inf_sign=True,
778
+ )
779
+
780
+ # loss of precision at large arguments due to oscillation
781
+ assert_mpmath_equal(
782
+ sc.jv,
783
+ exception_to_nan(lambda v, z: mpmath.besselj(v, z, **HYPERKW)),
784
+ [Arg(-1e100, 1e100), Arg(-1e8, 1e8)],
785
+ ignore_inf_sign=True,
786
+ rtol=1e-5,
787
+ )
788
+
789
+ def test_besselj_complex(self):
790
+ assert_mpmath_equal(
791
+ lambda v, z: sc.jv(v.real, z),
792
+ exception_to_nan(lambda v, z: mpmath.besselj(v, z, **HYPERKW)),
793
+ [Arg(), ComplexArg()]
794
+ )
795
+
796
+ def test_besselk(self):
797
+ assert_mpmath_equal(
798
+ sc.kv,
799
+ mpmath.besselk,
800
+ [Arg(-200, 200), Arg(0, np.inf)],
801
+ nan_ok=False,
802
+ rtol=1e-12,
803
+ )
804
+
805
+ def test_besselk_int(self):
806
+ assert_mpmath_equal(
807
+ sc.kn,
808
+ mpmath.besselk,
809
+ [IntArg(-200, 200), Arg(0, np.inf)],
810
+ nan_ok=False,
811
+ rtol=1e-12,
812
+ )
813
+
814
+ def test_besselk_complex(self):
815
+ assert_mpmath_equal(
816
+ lambda v, z: sc.kv(v.real, z),
817
+ exception_to_nan(lambda v, z: mpmath.besselk(v, z, **HYPERKW)),
818
+ [Arg(-1e100, 1e100), ComplexArg()],
819
+ )
820
+
821
+ def test_bessely(self):
822
+ def mpbessely(v, x):
823
+ r = float(mpmath.bessely(v, x, **HYPERKW))
824
+ if abs(r) > 1e305:
825
+ # overflowing to inf a bit earlier is OK
826
+ r = np.inf * np.sign(r)
827
+ if abs(r) == 0 and x == 0:
828
+ # invalid result from mpmath, point x=0 is a divergence
829
+ return np.nan
830
+ return r
831
+ assert_mpmath_equal(
832
+ sc.yv,
833
+ exception_to_nan(mpbessely),
834
+ [Arg(-1e100, 1e100), Arg(-1e8, 1e8)],
835
+ n=5000,
836
+ )
837
+
838
+ def test_bessely_complex(self):
839
+ def mpbessely(v, x):
840
+ r = complex(mpmath.bessely(v, x, **HYPERKW))
841
+ if abs(r) > 1e305:
842
+ # overflowing to inf a bit earlier is OK
843
+ with np.errstate(invalid='ignore'):
844
+ r = np.inf * np.sign(r)
845
+ return r
846
+ assert_mpmath_equal(
847
+ lambda v, z: sc.yv(v.real, z),
848
+ exception_to_nan(mpbessely),
849
+ [Arg(), ComplexArg()],
850
+ n=15000,
851
+ )
852
+
853
+ def test_bessely_int(self):
854
+ def mpbessely(v, x):
855
+ r = float(mpmath.bessely(v, x))
856
+ if abs(r) == 0 and x == 0:
857
+ # invalid result from mpmath, point x=0 is a divergence
858
+ return np.nan
859
+ return r
860
+ assert_mpmath_equal(
861
+ lambda v, z: sc.yn(int(v), z),
862
+ exception_to_nan(mpbessely),
863
+ [IntArg(-1000, 1000), Arg(-1e8, 1e8)],
864
+ )
865
+
866
+ def test_beta(self):
867
+ bad_points = []
868
+
869
+ def beta(a, b, nonzero=False):
870
+ if a < -1e12 or b < -1e12:
871
+ # Function is defined here only at integers, but due
872
+ # to loss of precision this is numerically
873
+ # ill-defined. Don't compare values here.
874
+ return np.nan
875
+ if (a < 0 or b < 0) and (abs(float(a + b)) % 1) == 0:
876
+ # close to a zero of the function: mpmath and scipy
877
+ # will not round here the same, so the test needs to be
878
+ # run with an absolute tolerance
879
+ if nonzero:
880
+ bad_points.append((float(a), float(b)))
881
+ return np.nan
882
+ return mpmath.beta(a, b)
883
+
884
+ assert_mpmath_equal(
885
+ sc.beta,
886
+ lambda a, b: beta(a, b, nonzero=True),
887
+ [Arg(), Arg()],
888
+ dps=400,
889
+ ignore_inf_sign=True,
890
+ )
891
+
892
+ assert_mpmath_equal(
893
+ sc.beta,
894
+ beta,
895
+ np.array(bad_points),
896
+ dps=400,
897
+ ignore_inf_sign=True,
898
+ atol=1e-11,
899
+ )
900
+
901
+ def test_betainc(self):
902
+ assert_mpmath_equal(
903
+ sc.betainc,
904
+ time_limited()(
905
+ exception_to_nan(
906
+ lambda a, b, x: mpmath.betainc(a, b, 0, x, regularized=True)
907
+ )
908
+ ),
909
+ [Arg(), Arg(), Arg()],
910
+ )
911
+
912
+ def test_betaincc(self):
913
+ assert_mpmath_equal(
914
+ sc.betaincc,
915
+ time_limited()(
916
+ exception_to_nan(
917
+ lambda a, b, x: mpmath.betainc(a, b, x, 1, regularized=True)
918
+ )
919
+ ),
920
+ [Arg(), Arg(), Arg()],
921
+ dps=400,
922
+ )
923
+
924
+ def test_binom(self):
925
+ bad_points = []
926
+
927
+ def binomial(n, k, nonzero=False):
928
+ if abs(k) > 1e8*(abs(n) + 1):
929
+ # The binomial is rapidly oscillating in this region,
930
+ # and the function is numerically ill-defined. Don't
931
+ # compare values here.
932
+ return np.nan
933
+ if n < k and abs(float(n-k) - np.round(float(n-k))) < 1e-15:
934
+ # close to a zero of the function: mpmath and scipy
935
+ # will not round here the same, so the test needs to be
936
+ # run with an absolute tolerance
937
+ if nonzero:
938
+ bad_points.append((float(n), float(k)))
939
+ return np.nan
940
+ return mpmath.binomial(n, k)
941
+
942
+ assert_mpmath_equal(
943
+ sc.binom,
944
+ lambda n, k: binomial(n, k, nonzero=True),
945
+ [Arg(), Arg()],
946
+ dps=400,
947
+ )
948
+
949
+ assert_mpmath_equal(
950
+ sc.binom,
951
+ binomial,
952
+ np.array(bad_points),
953
+ dps=400,
954
+ atol=1e-14,
955
+ )
956
+
957
+ def test_chebyt_int(self):
958
+ assert_mpmath_equal(
959
+ lambda n, x: sc.eval_chebyt(int(n), x),
960
+ exception_to_nan(lambda n, x: mpmath.chebyt(n, x, **HYPERKW)),
961
+ [IntArg(), Arg()],
962
+ dps=50,
963
+ )
964
+
965
+ @pytest.mark.xfail(run=False, reason="some cases in hyp2f1 not fully accurate")
966
+ def test_chebyt(self):
967
+ assert_mpmath_equal(
968
+ sc.eval_chebyt,
969
+ lambda n, x: time_limited()(
970
+ exception_to_nan(mpmath.chebyt)
971
+ )(n, x, **HYPERKW),
972
+ [Arg(-101, 101), Arg()],
973
+ n=10000,
974
+ )
975
+
976
+ def test_chebyu_int(self):
977
+ assert_mpmath_equal(
978
+ lambda n, x: sc.eval_chebyu(int(n), x),
979
+ exception_to_nan(lambda n, x: mpmath.chebyu(n, x, **HYPERKW)),
980
+ [IntArg(), Arg()],
981
+ dps=50,
982
+ )
983
+
984
+ @pytest.mark.xfail(run=False, reason="some cases in hyp2f1 not fully accurate")
985
+ def test_chebyu(self):
986
+ assert_mpmath_equal(
987
+ sc.eval_chebyu,
988
+ lambda n, x: time_limited()(
989
+ exception_to_nan(mpmath.chebyu)
990
+ )(n, x, **HYPERKW),
991
+ [Arg(-101, 101), Arg()],
992
+ )
993
+
994
+ def test_chi(self):
995
+ def chi(x):
996
+ return sc.shichi(x)[1]
997
+ assert_mpmath_equal(chi, mpmath.chi, [Arg()])
998
+ # check asymptotic series cross-over
999
+ assert_mpmath_equal(chi, mpmath.chi, [FixedArg([88 - 1e-9, 88, 88 + 1e-9])])
1000
+
1001
+ def test_chi_complex(self):
1002
+ def chi(z):
1003
+ return sc.shichi(z)[1]
1004
+ # chi oscillates as Im[z] -> +- inf, so limit range
1005
+ assert_mpmath_equal(
1006
+ chi,
1007
+ mpmath.chi,
1008
+ [ComplexArg(complex(-np.inf, -1e8), complex(np.inf, 1e8))],
1009
+ rtol=1e-12,
1010
+ )
1011
+
1012
+ def test_ci(self):
1013
+ def ci(x):
1014
+ return sc.sici(x)[1]
1015
+ # oscillating function: limit range
1016
+ assert_mpmath_equal(ci, mpmath.ci, [Arg(-1e8, 1e8)])
1017
+
1018
+ def test_ci_complex(self):
1019
+ def ci(z):
1020
+ return sc.sici(z)[1]
1021
+ # ci oscillates as Re[z] -> +- inf, so limit range
1022
+ assert_mpmath_equal(
1023
+ ci,
1024
+ mpmath.ci,
1025
+ [ComplexArg(complex(-1e8, -np.inf), complex(1e8, np.inf))],
1026
+ rtol=1e-8,
1027
+ )
1028
+
1029
+ def test_cospi(self):
1030
+ eps = np.finfo(float).eps
1031
+ assert_mpmath_equal(_cospi, mpmath.cospi, [Arg()], nan_ok=False, rtol=2*eps)
1032
+
1033
+ def test_cospi_complex(self):
1034
+ assert_mpmath_equal(
1035
+ _cospi,
1036
+ mpmath.cospi,
1037
+ [ComplexArg()],
1038
+ nan_ok=False,
1039
+ rtol=1e-13,
1040
+ )
1041
+
1042
+ def test_digamma(self):
1043
+ assert_mpmath_equal(
1044
+ sc.digamma,
1045
+ exception_to_nan(mpmath.digamma),
1046
+ [Arg()],
1047
+ rtol=1e-12,
1048
+ dps=50,
1049
+ )
1050
+
1051
+ def test_digamma_complex(self):
1052
+ # Test on a cut plane because mpmath will hang. See
1053
+ # test_digamma_negreal for tests on the negative real axis.
1054
+ def param_filter(z):
1055
+ return np.where((z.real < 0) & (np.abs(z.imag) < 1.12), False, True)
1056
+
1057
+ assert_mpmath_equal(
1058
+ sc.digamma,
1059
+ exception_to_nan(mpmath.digamma),
1060
+ [ComplexArg()],
1061
+ rtol=1e-13,
1062
+ dps=40,
1063
+ param_filter=param_filter
1064
+ )
1065
+
1066
+ def test_e1(self):
1067
+ assert_mpmath_equal(
1068
+ sc.exp1,
1069
+ mpmath.e1,
1070
+ [Arg()],
1071
+ rtol=1e-14,
1072
+ )
1073
+
1074
+ def test_e1_complex(self):
1075
+ # E_1 oscillates as Im[z] -> +- inf, so limit range
1076
+ assert_mpmath_equal(
1077
+ sc.exp1,
1078
+ mpmath.e1,
1079
+ [ComplexArg(complex(-np.inf, -1e8), complex(np.inf, 1e8))],
1080
+ rtol=1e-11,
1081
+ )
1082
+
1083
+ # Check cross-over region
1084
+ assert_mpmath_equal(
1085
+ sc.exp1,
1086
+ mpmath.e1,
1087
+ (np.linspace(-50, 50, 171)[:, None]
1088
+ + np.r_[0, np.logspace(-3, 2, 61), -np.logspace(-3, 2, 11)]*1j).ravel(),
1089
+ rtol=1e-11,
1090
+ )
1091
+ assert_mpmath_equal(
1092
+ sc.exp1,
1093
+ mpmath.e1,
1094
+ (np.linspace(-50, -35, 10000) + 0j),
1095
+ rtol=1e-11,
1096
+ )
1097
+
1098
+ def test_exprel(self):
1099
+ assert_mpmath_equal(
1100
+ sc.exprel,
1101
+ lambda x: mpmath.expm1(x)/x if x != 0 else mpmath.mpf('1.0'),
1102
+ [Arg(a=-np.log(np.finfo(np.float64).max),
1103
+ b=np.log(np.finfo(np.float64).max))],
1104
+ )
1105
+ assert_mpmath_equal(
1106
+ sc.exprel,
1107
+ lambda x: mpmath.expm1(x)/x if x != 0 else mpmath.mpf('1.0'),
1108
+ np.array([1e-12, 1e-24, 0, 1e12, 1e24, np.inf]),
1109
+ rtol=1e-11,
1110
+ )
1111
+ assert_(np.isinf(sc.exprel(np.inf)))
1112
+ assert_(sc.exprel(-np.inf) == 0)
1113
+
1114
+ def test_expm1_complex(self):
1115
+ # Oscillates as a function of Im[z], so limit range to avoid loss of precision
1116
+ assert_mpmath_equal(
1117
+ sc.expm1,
1118
+ mpmath.expm1,
1119
+ [ComplexArg(complex(-np.inf, -1e7), complex(np.inf, 1e7))],
1120
+ )
1121
+
1122
+ def test_log1p_complex(self):
1123
+ assert_mpmath_equal(
1124
+ sc.log1p,
1125
+ lambda x: mpmath.log(x+1),
1126
+ [ComplexArg()],
1127
+ dps=60,
1128
+ )
1129
+
1130
+ def test_log1pmx(self):
1131
+ assert_mpmath_equal(
1132
+ _log1pmx,
1133
+ lambda x: mpmath.log(x + 1) - x,
1134
+ [Arg()],
1135
+ dps=60,
1136
+ rtol=1e-14,
1137
+ )
1138
+
1139
+ def test_ei(self):
1140
+ assert_mpmath_equal(sc.expi, mpmath.ei, [Arg()], rtol=1e-11)
1141
+
1142
+ def test_ei_complex(self):
1143
+ # Ei oscillates as Im[z] -> +- inf, so limit range
1144
+ assert_mpmath_equal(
1145
+ sc.expi,
1146
+ mpmath.ei,
1147
+ [ComplexArg(complex(-np.inf, -1e8), complex(np.inf, 1e8))],
1148
+ rtol=1e-9,
1149
+ )
1150
+
1151
+ def test_ellipe(self):
1152
+ assert_mpmath_equal(sc.ellipe, mpmath.ellipe, [Arg(b=1.0)])
1153
+
1154
+ def test_ellipeinc(self):
1155
+ assert_mpmath_equal(sc.ellipeinc, mpmath.ellipe, [Arg(-1e3, 1e3), Arg(b=1.0)])
1156
+
1157
+ def test_ellipeinc_largephi(self):
1158
+ assert_mpmath_equal(sc.ellipeinc, mpmath.ellipe, [Arg(), Arg()])
1159
+
1160
+ def test_ellipf(self):
1161
+ assert_mpmath_equal(sc.ellipkinc, mpmath.ellipf, [Arg(-1e3, 1e3), Arg()])
1162
+
1163
+ def test_ellipf_largephi(self):
1164
+ assert_mpmath_equal(sc.ellipkinc, mpmath.ellipf, [Arg(), Arg()])
1165
+
1166
+ def test_ellipk(self):
1167
+ assert_mpmath_equal(sc.ellipk, mpmath.ellipk, [Arg(b=1.0)])
1168
+ assert_mpmath_equal(
1169
+ sc.ellipkm1,
1170
+ lambda m: mpmath.ellipk(1 - m),
1171
+ [Arg(a=0.0)],
1172
+ dps=400,
1173
+ )
1174
+
1175
+ def test_ellipkinc(self):
1176
+ def ellipkinc(phi, m):
1177
+ return mpmath.ellippi(0, phi, m)
1178
+ assert_mpmath_equal(
1179
+ sc.ellipkinc,
1180
+ ellipkinc,
1181
+ [Arg(-1e3, 1e3), Arg(b=1.0)],
1182
+ ignore_inf_sign=True,
1183
+ )
1184
+
1185
+ def test_ellipkinc_largephi(self):
1186
+ def ellipkinc(phi, m):
1187
+ return mpmath.ellippi(0, phi, m)
1188
+ assert_mpmath_equal(
1189
+ sc.ellipkinc,
1190
+ ellipkinc,
1191
+ [Arg(), Arg(b=1.0)],
1192
+ ignore_inf_sign=True,
1193
+ )
1194
+
1195
+ def test_ellipfun_sn(self):
1196
+ def sn(u, m):
1197
+ # mpmath doesn't get the zero at u = 0--fix that
1198
+ if u == 0:
1199
+ return 0
1200
+ else:
1201
+ return mpmath.ellipfun("sn", u=u, m=m)
1202
+
1203
+ # Oscillating function --- limit range of first argument; the
1204
+ # loss of precision there is an expected numerical feature
1205
+ # rather than an actual bug
1206
+ assert_mpmath_equal(
1207
+ lambda u, m: sc.ellipj(u, m)[0],
1208
+ sn,
1209
+ [Arg(-1e6, 1e6), Arg(a=0, b=1)],
1210
+ rtol=1e-8,
1211
+ )
1212
+
1213
+ def test_ellipfun_cn(self):
1214
+ # see comment in ellipfun_sn
1215
+ assert_mpmath_equal(
1216
+ lambda u, m: sc.ellipj(u, m)[1],
1217
+ lambda u, m: mpmath.ellipfun("cn", u=u, m=m),
1218
+ [Arg(-1e6, 1e6), Arg(a=0, b=1)],
1219
+ rtol=1e-8,
1220
+ )
1221
+
1222
+ def test_ellipfun_dn(self):
1223
+ # see comment in ellipfun_sn
1224
+ assert_mpmath_equal(
1225
+ lambda u, m: sc.ellipj(u, m)[2],
1226
+ lambda u, m: mpmath.ellipfun("dn", u=u, m=m),
1227
+ [Arg(-1e6, 1e6), Arg(a=0, b=1)],
1228
+ rtol=1e-8,
1229
+ )
1230
+
1231
+ def test_erf(self):
1232
+ assert_mpmath_equal(sc.erf, lambda z: mpmath.erf(z), [Arg()])
1233
+
1234
+ def test_erf_complex(self):
1235
+ assert_mpmath_equal(sc.erf, lambda z: mpmath.erf(z), [ComplexArg()], n=200)
1236
+
1237
+ def test_erfc(self):
1238
+ assert_mpmath_equal(
1239
+ sc.erfc,
1240
+ exception_to_nan(lambda z: mpmath.erfc(z)),
1241
+ [Arg()],
1242
+ rtol=1e-13,
1243
+ )
1244
+
1245
+ def test_erfc_complex(self):
1246
+ assert_mpmath_equal(
1247
+ sc.erfc,
1248
+ exception_to_nan(lambda z: mpmath.erfc(z)),
1249
+ [ComplexArg()],
1250
+ n=200,
1251
+ )
1252
+
1253
+ def test_erfi(self):
1254
+ assert_mpmath_equal(sc.erfi, mpmath.erfi, [Arg()], n=200)
1255
+
1256
+ def test_erfi_complex(self):
1257
+ assert_mpmath_equal(sc.erfi, mpmath.erfi, [ComplexArg()], n=200)
1258
+
1259
+ def test_ndtr(self):
1260
+ assert_mpmath_equal(
1261
+ sc.ndtr,
1262
+ exception_to_nan(lambda z: mpmath.ncdf(z)),
1263
+ [Arg()],
1264
+ n=200,
1265
+ )
1266
+
1267
+ def test_ndtr_complex(self):
1268
+ assert_mpmath_equal(
1269
+ sc.ndtr,
1270
+ lambda z: mpmath.erfc(-z/np.sqrt(2.))/2.,
1271
+ [ComplexArg(a=complex(-10000, -10000), b=complex(10000, 10000))],
1272
+ n=400,
1273
+ )
1274
+
1275
+ def test_log_ndtr(self):
1276
+ assert_mpmath_equal(
1277
+ sc.log_ndtr,
1278
+ exception_to_nan(lambda z: mpmath.log(mpmath.ncdf(z))),
1279
+ [Arg()], n=600, dps=300, rtol=1e-13,
1280
+ )
1281
+
1282
+ def test_log_ndtr_complex(self):
1283
+ assert_mpmath_equal(
1284
+ sc.log_ndtr,
1285
+ exception_to_nan(lambda z: mpmath.log(mpmath.erfc(-z/np.sqrt(2.))/2.)),
1286
+ [ComplexArg(a=complex(-10000, -100), b=complex(10000, 100))],
1287
+ n=200, dps=300,
1288
+ )
1289
+
1290
+ def test_eulernum(self):
1291
+ assert_mpmath_equal(
1292
+ lambda n: sc.euler(n)[-1],
1293
+ mpmath.eulernum,
1294
+ [IntArg(1, 10000)],
1295
+ n=10000,
1296
+ )
1297
+
1298
+ def test_expint(self):
1299
+ assert_mpmath_equal(
1300
+ sc.expn,
1301
+ mpmath.expint,
1302
+ [IntArg(0, 200), Arg(0, np.inf)],
1303
+ rtol=1e-13,
1304
+ dps=160,
1305
+ )
1306
+
1307
+ def test_fresnels(self):
1308
+ def fresnels(x):
1309
+ return sc.fresnel(x)[0]
1310
+ assert_mpmath_equal(fresnels, mpmath.fresnels, [Arg()])
1311
+
1312
+ def test_fresnelc(self):
1313
+ def fresnelc(x):
1314
+ return sc.fresnel(x)[1]
1315
+ assert_mpmath_equal(fresnelc, mpmath.fresnelc, [Arg()])
1316
+
1317
+ def test_gamma(self):
1318
+ assert_mpmath_equal(sc.gamma, exception_to_nan(mpmath.gamma), [Arg()])
1319
+
1320
+ def test_gamma_complex(self):
1321
+ assert_mpmath_equal(
1322
+ sc.gamma,
1323
+ exception_to_nan(mpmath.gamma),
1324
+ [ComplexArg()],
1325
+ rtol=5e-13,
1326
+ )
1327
+
1328
+ def test_gammainc(self):
1329
+ # Larger arguments are tested in test_data.py:test_local
1330
+ assert_mpmath_equal(
1331
+ sc.gammainc,
1332
+ lambda z, b: mpmath.gammainc(z, b=b, regularized=True),
1333
+ [Arg(0, 1e4, inclusive_a=False), Arg(0, 1e4)],
1334
+ nan_ok=False,
1335
+ rtol=1e-11,
1336
+ )
1337
+
1338
+ def test_gammaincc(self):
1339
+ # Larger arguments are tested in test_data.py:test_local
1340
+ assert_mpmath_equal(
1341
+ sc.gammaincc,
1342
+ lambda z, a: mpmath.gammainc(z, a=a, regularized=True),
1343
+ [Arg(0, 1e4, inclusive_a=False), Arg(0, 1e4)],
1344
+ nan_ok=False,
1345
+ rtol=1e-11,
1346
+ )
1347
+
1348
+ def test_gammaln(self):
1349
+ # The real part of loggamma is log(|gamma(z)|).
1350
+ def f(z):
1351
+ return mpmath.loggamma(z).real
1352
+
1353
+ assert_mpmath_equal(sc.gammaln, exception_to_nan(f), [Arg()])
1354
+
1355
+ @pytest.mark.xfail(run=False)
1356
+ def test_gegenbauer(self):
1357
+ assert_mpmath_equal(
1358
+ sc.eval_gegenbauer,
1359
+ exception_to_nan(mpmath.gegenbauer),
1360
+ [Arg(-1e3, 1e3), Arg(), Arg()],
1361
+ )
1362
+
1363
+ def test_gegenbauer_int(self):
1364
+ # Redefine functions to deal with numerical + mpmath issues
1365
+ def gegenbauer(n, a, x):
1366
+ # Avoid overflow at large `a` (mpmath would need an even larger
1367
+ # dps to handle this correctly, so just skip this region)
1368
+ if abs(a) > 1e100:
1369
+ return np.nan
1370
+
1371
+ # Deal with n=0, n=1 correctly; mpmath 0.17 doesn't do these
1372
+ # always correctly
1373
+ if n == 0:
1374
+ r = 1.0
1375
+ elif n == 1:
1376
+ r = 2*a*x
1377
+ else:
1378
+ r = mpmath.gegenbauer(n, a, x)
1379
+
1380
+ # Mpmath 0.17 gives wrong results (spurious zero) in some cases, so
1381
+ # compute the value by perturbing the result
1382
+ if float(r) == 0 and a < -1 and float(a) == int(float(a)):
1383
+ r = mpmath.gegenbauer(n, a + mpmath.mpf('1e-50'), x)
1384
+ if abs(r) < mpmath.mpf('1e-50'):
1385
+ r = mpmath.mpf('0.0')
1386
+
1387
+ # Differing overflow thresholds in scipy vs. mpmath
1388
+ if abs(r) > 1e270:
1389
+ return np.inf
1390
+ return r
1391
+
1392
+ def sc_gegenbauer(n, a, x):
1393
+ r = sc.eval_gegenbauer(int(n), a, x)
1394
+ # Differing overflow thresholds in scipy vs. mpmath
1395
+ if abs(r) > 1e270:
1396
+ return np.inf
1397
+ return r
1398
+ assert_mpmath_equal(
1399
+ sc_gegenbauer,
1400
+ exception_to_nan(gegenbauer),
1401
+ [IntArg(0, 100), Arg(-1e9, 1e9), Arg()],
1402
+ n=40000, dps=100, ignore_inf_sign=True, rtol=1e-6,
1403
+ )
1404
+
1405
+ # Check the small-x expansion
1406
+ assert_mpmath_equal(
1407
+ sc_gegenbauer,
1408
+ exception_to_nan(gegenbauer),
1409
+ [IntArg(0, 100), Arg(), FixedArg(np.logspace(-30, -4, 30))],
1410
+ dps=100, ignore_inf_sign=True,
1411
+ )
1412
+
1413
+ @pytest.mark.xfail(run=False)
1414
+ def test_gegenbauer_complex(self):
1415
+ assert_mpmath_equal(
1416
+ lambda n, a, x: sc.eval_gegenbauer(int(n), a.real, x),
1417
+ exception_to_nan(mpmath.gegenbauer),
1418
+ [IntArg(0, 100), Arg(), ComplexArg()],
1419
+ )
1420
+
1421
+ @nonfunctional_tooslow
1422
+ def test_gegenbauer_complex_general(self):
1423
+ assert_mpmath_equal(
1424
+ lambda n, a, x: sc.eval_gegenbauer(n.real, a.real, x),
1425
+ exception_to_nan(mpmath.gegenbauer),
1426
+ [Arg(-1e3, 1e3), Arg(), ComplexArg()],
1427
+ )
1428
+
1429
+ def test_hankel1(self):
1430
+ assert_mpmath_equal(
1431
+ sc.hankel1,
1432
+ exception_to_nan(lambda v, x: mpmath.hankel1(v, x, **HYPERKW)),
1433
+ [Arg(-1e20, 1e20), Arg()],
1434
+ )
1435
+
1436
+ def test_hankel2(self):
1437
+ assert_mpmath_equal(
1438
+ sc.hankel2,
1439
+ exception_to_nan(lambda v, x: mpmath.hankel2(v, x, **HYPERKW)),
1440
+ [Arg(-1e20, 1e20), Arg()],
1441
+ )
1442
+
1443
+ @pytest.mark.xfail(run=False, reason="issues at intermediately large orders")
1444
+ def test_hermite(self):
1445
+ assert_mpmath_equal(
1446
+ lambda n, x: sc.eval_hermite(int(n), x),
1447
+ exception_to_nan(mpmath.hermite),
1448
+ [IntArg(0, 10000), Arg()],
1449
+ )
1450
+
1451
+ # hurwitz: same as zeta
1452
+
1453
+ def test_hyp0f1(self):
1454
+ # mpmath reports no convergence unless maxterms is large enough
1455
+ KW = dict(maxprec=400, maxterms=1500)
1456
+ # n=500 (non-xslow default) fails for one bad point
1457
+ assert_mpmath_equal(
1458
+ sc.hyp0f1,
1459
+ lambda a, x: mpmath.hyp0f1(a, x, **KW),
1460
+ [Arg(-1e7, 1e7), Arg(0, 1e5)],
1461
+ n=5000,
1462
+ )
1463
+ # NB: The range of the second parameter ("z") is limited from below
1464
+ # because of an overflow in the intermediate calculations. The way
1465
+ # for fix it is to implement an asymptotic expansion for Bessel J
1466
+ # (similar to what is implemented for Bessel I here).
1467
+
1468
+ def test_hyp0f1_complex(self):
1469
+ assert_mpmath_equal(
1470
+ lambda a, z: sc.hyp0f1(a.real, z),
1471
+ exception_to_nan(lambda a, x: mpmath.hyp0f1(a, x, **HYPERKW)),
1472
+ [Arg(-10, 10), ComplexArg(complex(-120, -120), complex(120, 120))],
1473
+ )
1474
+ # NB: The range of the first parameter ("v") are limited by an overflow
1475
+ # in the intermediate calculations. Can be fixed by implementing an
1476
+ # asymptotic expansion for Bessel functions for large order.
1477
+
1478
+ def test_hyp1f1(self):
1479
+ def mpmath_hyp1f1(a, b, x):
1480
+ try:
1481
+ return mpmath.hyp1f1(a, b, x)
1482
+ except ZeroDivisionError:
1483
+ return np.inf
1484
+
1485
+ assert_mpmath_equal(
1486
+ sc.hyp1f1,
1487
+ mpmath_hyp1f1,
1488
+ [Arg(-50, 50), Arg(1, 50, inclusive_a=False), Arg(-50, 50)],
1489
+ n=500,
1490
+ nan_ok=False,
1491
+ )
1492
+
1493
+ @pytest.mark.xfail(run=False)
1494
+ def test_hyp1f1_complex(self):
1495
+ assert_mpmath_equal(
1496
+ inf_to_nan(lambda a, b, x: sc.hyp1f1(a.real, b.real, x)),
1497
+ exception_to_nan(lambda a, b, x: mpmath.hyp1f1(a, b, x, **HYPERKW)),
1498
+ [Arg(-1e3, 1e3), Arg(-1e3, 1e3), ComplexArg()],
1499
+ n=2000,
1500
+ )
1501
+
1502
+ @nonfunctional_tooslow
1503
+ def test_hyp2f1_complex(self):
1504
+ # SciPy's hyp2f1 seems to have performance and accuracy problems
1505
+ assert_mpmath_equal(
1506
+ lambda a, b, c, x: sc.hyp2f1(a.real, b.real, c.real, x),
1507
+ exception_to_nan(lambda a, b, c, x: mpmath.hyp2f1(a, b, c, x, **HYPERKW)),
1508
+ [Arg(-1e2, 1e2), Arg(-1e2, 1e2), Arg(-1e2, 1e2), ComplexArg()],
1509
+ n=10,
1510
+ )
1511
+
1512
+ @pytest.mark.xfail(run=False)
1513
+ def test_hyperu(self):
1514
+ assert_mpmath_equal(
1515
+ sc.hyperu,
1516
+ exception_to_nan(lambda a, b, x: mpmath.hyperu(a, b, x, **HYPERKW)),
1517
+ [Arg(), Arg(), Arg()],
1518
+ )
1519
+
1520
+ @pytest.mark.xfail_on_32bit("mpmath issue gh-342: "
1521
+ "unsupported operand mpz, long for pow")
1522
+ def test_igam_fac(self):
1523
+ def mp_igam_fac(a, x):
1524
+ return mpmath.power(x, a)*mpmath.exp(-x)/mpmath.gamma(a)
1525
+
1526
+ assert_mpmath_equal(
1527
+ _igam_fac,
1528
+ mp_igam_fac,
1529
+ [Arg(0, 1e14, inclusive_a=False), Arg(0, 1e14)],
1530
+ rtol=1e-10,
1531
+ )
1532
+
1533
+ def test_j0(self):
1534
+ # The Bessel function at large arguments is j0(x) ~ cos(x + phi)/sqrt(x)
1535
+ # and at large arguments the phase of the cosine loses precision.
1536
+ #
1537
+ # This is numerically expected behavior, so we compare only up to
1538
+ # 1e8 = 1e15 * 1e-7
1539
+ assert_mpmath_equal(sc.j0, mpmath.j0, [Arg(-1e3, 1e3)])
1540
+ assert_mpmath_equal(sc.j0, mpmath.j0, [Arg(-1e8, 1e8)], rtol=1e-5)
1541
+
1542
+ def test_j1(self):
1543
+ # See comment in test_j0
1544
+ assert_mpmath_equal(sc.j1, mpmath.j1, [Arg(-1e3, 1e3)])
1545
+ assert_mpmath_equal(sc.j1, mpmath.j1, [Arg(-1e8, 1e8)], rtol=1e-5)
1546
+
1547
+ @pytest.mark.xfail(run=False)
1548
+ def test_jacobi(self):
1549
+ assert_mpmath_equal(
1550
+ sc.eval_jacobi,
1551
+ exception_to_nan(lambda a, b, c, x: mpmath.jacobi(a, b, c, x, **HYPERKW)),
1552
+ [Arg(), Arg(), Arg(), Arg()],
1553
+ )
1554
+ assert_mpmath_equal(
1555
+ lambda n, b, c, x: sc.eval_jacobi(int(n), b, c, x),
1556
+ exception_to_nan(lambda a, b, c, x: mpmath.jacobi(a, b, c, x, **HYPERKW)),
1557
+ [IntArg(), Arg(), Arg(), Arg()],
1558
+ )
1559
+
1560
+ def test_jacobi_int(self):
1561
+ # Redefine functions to deal with numerical + mpmath issues
1562
+ def jacobi(n, a, b, x):
1563
+ # Mpmath does not handle n=0 case always correctly
1564
+ if n == 0:
1565
+ return 1.0
1566
+ return mpmath.jacobi(n, a, b, x)
1567
+ assert_mpmath_equal(
1568
+ lambda n, a, b, x: sc.eval_jacobi(int(n), a, b, x),
1569
+ lambda n, a, b, x: exception_to_nan(jacobi)(n, a, b, x, **HYPERKW),
1570
+ [IntArg(), Arg(), Arg(), Arg()],
1571
+ n=20000,
1572
+ dps=50,
1573
+ )
1574
+
1575
+ def test_kei(self):
1576
+ def kei(x):
1577
+ if x == 0:
1578
+ # work around mpmath issue at x=0
1579
+ return -pi/4
1580
+ return exception_to_nan(mpmath.kei)(0, x, **HYPERKW)
1581
+ assert_mpmath_equal(sc.kei, kei, [Arg(-1e30, 1e30)], n=1000)
1582
+
1583
+ def test_ker(self):
1584
+ assert_mpmath_equal(
1585
+ sc.ker,
1586
+ exception_to_nan(lambda x: mpmath.ker(0, x, **HYPERKW)),
1587
+ [Arg(-1e30, 1e30)],
1588
+ n=1000,
1589
+ )
1590
+
1591
+ @nonfunctional_tooslow
1592
+ def test_laguerre(self):
1593
+ assert_mpmath_equal(
1594
+ trace_args(sc.eval_laguerre),
1595
+ lambda n, x: exception_to_nan(mpmath.laguerre)(n, x, **HYPERKW),
1596
+ [Arg(), Arg()],
1597
+ )
1598
+
1599
+ def test_laguerre_int(self):
1600
+ assert_mpmath_equal(
1601
+ lambda n, x: sc.eval_laguerre(int(n), x),
1602
+ lambda n, x: exception_to_nan(mpmath.laguerre)(n, x, **HYPERKW),
1603
+ [IntArg(), Arg()],
1604
+ n=20000,
1605
+ )
1606
+
1607
+ @pytest.mark.xfail_on_32bit("see gh-3551 for bad points")
1608
+ def test_lambertw_real(self):
1609
+ assert_mpmath_equal(
1610
+ lambda x, k: sc.lambertw(x, int(k.real)),
1611
+ lambda x, k: mpmath.lambertw(x, int(k.real)),
1612
+ [ComplexArg(-np.inf, np.inf), IntArg(0, 10)],
1613
+ rtol=1e-13, nan_ok=False,
1614
+ )
1615
+
1616
+ def test_lanczos_sum_expg_scaled(self):
1617
+ maxgamma = 171.624376956302725
1618
+ e = np.exp(1)
1619
+ g = 6.024680040776729583740234375
1620
+
1621
+ def gamma(x):
1622
+ with np.errstate(over='ignore'):
1623
+ fac = ((x + g - 0.5)/e)**(x - 0.5)
1624
+ if fac != np.inf:
1625
+ res = fac*_lanczos_sum_expg_scaled(x)
1626
+ else:
1627
+ fac = ((x + g - 0.5)/e)**(0.5*(x - 0.5))
1628
+ res = fac*_lanczos_sum_expg_scaled(x)
1629
+ res *= fac
1630
+ return res
1631
+
1632
+ assert_mpmath_equal(
1633
+ gamma,
1634
+ mpmath.gamma,
1635
+ [Arg(0, maxgamma, inclusive_a=False)],
1636
+ rtol=1e-13,
1637
+ )
1638
+
1639
+ @nonfunctional_tooslow
1640
+ def test_legendre(self):
1641
+ assert_mpmath_equal(sc.eval_legendre, mpmath.legendre, [Arg(), Arg()])
1642
+
1643
+ def test_legendre_int(self):
1644
+ assert_mpmath_equal(
1645
+ lambda n, x: sc.eval_legendre(int(n), x),
1646
+ lambda n, x: exception_to_nan(mpmath.legendre)(n, x, **HYPERKW),
1647
+ [IntArg(), Arg()],
1648
+ n=20000,
1649
+ )
1650
+
1651
+ # Check the small-x expansion
1652
+ assert_mpmath_equal(
1653
+ lambda n, x: sc.eval_legendre(int(n), x),
1654
+ lambda n, x: exception_to_nan(mpmath.legendre)(n, x, **HYPERKW),
1655
+ [IntArg(), FixedArg(np.logspace(-30, -4, 20))],
1656
+ )
1657
+
1658
+ def test_legenp(self):
1659
+ def lpnm(n, m, z):
1660
+ try:
1661
+ v = sc.lpmn(m, n, z)[0][-1,-1]
1662
+ except ValueError:
1663
+ return np.nan
1664
+ if abs(v) > 1e306:
1665
+ # harmonize overflow to inf
1666
+ v = np.inf * np.sign(v.real)
1667
+ return v
1668
+
1669
+ def lpnm_2(n, m, z):
1670
+ v = sc.lpmv(m, n, z)
1671
+ if abs(v) > 1e306:
1672
+ # harmonize overflow to inf
1673
+ v = np.inf * np.sign(v.real)
1674
+ return v
1675
+
1676
+ def legenp(n, m, z):
1677
+ if (z == 1 or z == -1) and int(n) == n:
1678
+ # Special case (mpmath may give inf, we take the limit by
1679
+ # continuity)
1680
+ if m == 0:
1681
+ if n < 0:
1682
+ n = -n - 1
1683
+ return mpmath.power(mpmath.sign(z), n)
1684
+ else:
1685
+ return 0
1686
+
1687
+ if abs(z) < 1e-15:
1688
+ # mpmath has bad performance here
1689
+ return np.nan
1690
+
1691
+ typ = 2 if abs(z) < 1 else 3
1692
+ v = exception_to_nan(mpmath.legenp)(n, m, z, type=typ)
1693
+
1694
+ if abs(v) > 1e306:
1695
+ # harmonize overflow to inf
1696
+ v = mpmath.inf * mpmath.sign(v.real)
1697
+
1698
+ return v
1699
+
1700
+ assert_mpmath_equal(lpnm, legenp, [IntArg(-100, 100), IntArg(-100, 100), Arg()])
1701
+
1702
+ assert_mpmath_equal(
1703
+ lpnm_2,
1704
+ legenp,
1705
+ [IntArg(-100, 100), Arg(-100, 100), Arg(-1, 1)],
1706
+ atol=1e-10,
1707
+ )
1708
+
1709
+ def test_legenp_complex_2(self):
1710
+ def clpnm(n, m, z):
1711
+ try:
1712
+ return sc.clpmn(m.real, n.real, z, type=2)[0][-1,-1]
1713
+ except ValueError:
1714
+ return np.nan
1715
+
1716
+ def legenp(n, m, z):
1717
+ if abs(z) < 1e-15:
1718
+ # mpmath has bad performance here
1719
+ return np.nan
1720
+ return exception_to_nan(mpmath.legenp)(int(n.real), int(m.real), z, type=2)
1721
+
1722
+ # mpmath is quite slow here
1723
+ x = np.array([-2, -0.99, -0.5, 0, 1e-5, 0.5, 0.99, 20, 2e3])
1724
+ y = np.array([-1e3, -0.5, 0.5, 1.3])
1725
+ z = (x[:,None] + 1j*y[None,:]).ravel()
1726
+
1727
+ assert_mpmath_equal(
1728
+ clpnm,
1729
+ legenp,
1730
+ [FixedArg([-2, -1, 0, 1, 2, 10]),
1731
+ FixedArg([-2, -1, 0, 1, 2, 10]),
1732
+ FixedArg(z)],
1733
+ rtol=1e-6,
1734
+ n=500,
1735
+ )
1736
+
1737
+ def test_legenp_complex_3(self):
1738
+ def clpnm(n, m, z):
1739
+ try:
1740
+ return sc.clpmn(m.real, n.real, z, type=3)[0][-1,-1]
1741
+ except ValueError:
1742
+ return np.nan
1743
+
1744
+ def legenp(n, m, z):
1745
+ if abs(z) < 1e-15:
1746
+ # mpmath has bad performance here
1747
+ return np.nan
1748
+ return exception_to_nan(mpmath.legenp)(int(n.real), int(m.real), z, type=3)
1749
+
1750
+ # mpmath is quite slow here
1751
+ x = np.array([-2, -0.99, -0.5, 0, 1e-5, 0.5, 0.99, 20, 2e3])
1752
+ y = np.array([-1e3, -0.5, 0.5, 1.3])
1753
+ z = (x[:,None] + 1j*y[None,:]).ravel()
1754
+
1755
+ assert_mpmath_equal(
1756
+ clpnm,
1757
+ legenp,
1758
+ [FixedArg([-2, -1, 0, 1, 2, 10]),
1759
+ FixedArg([-2, -1, 0, 1, 2, 10]),
1760
+ FixedArg(z)],
1761
+ rtol=1e-6,
1762
+ n=500,
1763
+ )
1764
+
1765
+ @pytest.mark.xfail(run=False, reason="apparently picks wrong function at |z| > 1")
1766
+ def test_legenq(self):
1767
+ def lqnm(n, m, z):
1768
+ return sc.lqmn(m, n, z)[0][-1,-1]
1769
+
1770
+ def legenq(n, m, z):
1771
+ if abs(z) < 1e-15:
1772
+ # mpmath has bad performance here
1773
+ return np.nan
1774
+ return exception_to_nan(mpmath.legenq)(n, m, z, type=2)
1775
+
1776
+ assert_mpmath_equal(
1777
+ lqnm,
1778
+ legenq,
1779
+ [IntArg(0, 100), IntArg(0, 100), Arg()],
1780
+ )
1781
+
1782
+ @nonfunctional_tooslow
1783
+ def test_legenq_complex(self):
1784
+ def lqnm(n, m, z):
1785
+ return sc.lqmn(int(m.real), int(n.real), z)[0][-1,-1]
1786
+
1787
+ def legenq(n, m, z):
1788
+ if abs(z) < 1e-15:
1789
+ # mpmath has bad performance here
1790
+ return np.nan
1791
+ return exception_to_nan(mpmath.legenq)(int(n.real), int(m.real), z, type=2)
1792
+
1793
+ assert_mpmath_equal(
1794
+ lqnm,
1795
+ legenq,
1796
+ [IntArg(0, 100), IntArg(0, 100), ComplexArg()],
1797
+ n=100,
1798
+ )
1799
+
1800
+ def test_lgam1p(self):
1801
+ def param_filter(x):
1802
+ # Filter the poles
1803
+ return np.where((np.floor(x) == x) & (x <= 0), False, True)
1804
+
1805
+ def mp_lgam1p(z):
1806
+ # The real part of loggamma is log(|gamma(z)|)
1807
+ return mpmath.loggamma(1 + z).real
1808
+
1809
+ assert_mpmath_equal(
1810
+ _lgam1p,
1811
+ mp_lgam1p,
1812
+ [Arg()],
1813
+ rtol=1e-13,
1814
+ dps=100,
1815
+ param_filter=param_filter,
1816
+ )
1817
+
1818
+ def test_loggamma(self):
1819
+ def mpmath_loggamma(z):
1820
+ try:
1821
+ res = mpmath.loggamma(z)
1822
+ except ValueError:
1823
+ res = complex(np.nan, np.nan)
1824
+ return res
1825
+
1826
+ assert_mpmath_equal(
1827
+ sc.loggamma,
1828
+ mpmath_loggamma,
1829
+ [ComplexArg()],
1830
+ nan_ok=False,
1831
+ distinguish_nan_and_inf=False,
1832
+ rtol=5e-14,
1833
+ )
1834
+
1835
+ @pytest.mark.xfail(run=False)
1836
+ def test_pcfd(self):
1837
+ def pcfd(v, x):
1838
+ return sc.pbdv(v, x)[0]
1839
+ assert_mpmath_equal(
1840
+ pcfd,
1841
+ exception_to_nan(lambda v, x: mpmath.pcfd(v, x, **HYPERKW)),
1842
+ [Arg(), Arg()],
1843
+ )
1844
+
1845
+ @pytest.mark.xfail(run=False, reason="it's not the same as the mpmath function --- "
1846
+ "maybe different definition?")
1847
+ def test_pcfv(self):
1848
+ def pcfv(v, x):
1849
+ return sc.pbvv(v, x)[0]
1850
+ assert_mpmath_equal(
1851
+ pcfv,
1852
+ lambda v, x: time_limited()(exception_to_nan(mpmath.pcfv))(v, x, **HYPERKW),
1853
+ [Arg(), Arg()],
1854
+ n=1000,
1855
+ )
1856
+
1857
+ def test_pcfw(self):
1858
+ def pcfw(a, x):
1859
+ return sc.pbwa(a, x)[0]
1860
+
1861
+ def dpcfw(a, x):
1862
+ return sc.pbwa(a, x)[1]
1863
+
1864
+ def mpmath_dpcfw(a, x):
1865
+ return mpmath.diff(mpmath.pcfw, (a, x), (0, 1))
1866
+
1867
+ # The Zhang and Jin implementation only uses Taylor series and
1868
+ # is thus accurate in only a very small range.
1869
+ assert_mpmath_equal(
1870
+ pcfw,
1871
+ mpmath.pcfw,
1872
+ [Arg(-5, 5), Arg(-5, 5)],
1873
+ rtol=2e-8,
1874
+ n=100,
1875
+ )
1876
+
1877
+ assert_mpmath_equal(
1878
+ dpcfw,
1879
+ mpmath_dpcfw,
1880
+ [Arg(-5, 5), Arg(-5, 5)],
1881
+ rtol=2e-9,
1882
+ n=100,
1883
+ )
1884
+
1885
+ @pytest.mark.xfail(run=False,
1886
+ reason="issues at large arguments (atol OK, rtol not) "
1887
+ "and <eps-close to z=0")
1888
+ def test_polygamma(self):
1889
+ assert_mpmath_equal(
1890
+ sc.polygamma,
1891
+ time_limited()(exception_to_nan(mpmath.polygamma)),
1892
+ [IntArg(0, 1000), Arg()],
1893
+ )
1894
+
1895
+ def test_rgamma(self):
1896
+ assert_mpmath_equal(
1897
+ sc.rgamma,
1898
+ mpmath.rgamma,
1899
+ [Arg(-8000, np.inf)],
1900
+ n=5000,
1901
+ nan_ok=False,
1902
+ ignore_inf_sign=True,
1903
+ )
1904
+
1905
+ def test_rgamma_complex(self):
1906
+ assert_mpmath_equal(
1907
+ sc.rgamma,
1908
+ exception_to_nan(mpmath.rgamma),
1909
+ [ComplexArg()],
1910
+ rtol=5e-13,
1911
+ )
1912
+
1913
+ @pytest.mark.xfail(reason=("see gh-3551 for bad points on 32 bit "
1914
+ "systems and gh-8095 for another bad "
1915
+ "point"))
1916
+ def test_rf(self):
1917
+ if _pep440.parse(mpmath.__version__) >= _pep440.Version("1.0.0"):
1918
+ # no workarounds needed
1919
+ mppoch = mpmath.rf
1920
+ else:
1921
+ def mppoch(a, m):
1922
+ # deal with cases where the result in double precision
1923
+ # hits exactly a non-positive integer, but the
1924
+ # corresponding extended-precision mpf floats don't
1925
+ if float(a + m) == int(a + m) and float(a + m) <= 0:
1926
+ a = mpmath.mpf(a)
1927
+ m = int(a + m) - a
1928
+ return mpmath.rf(a, m)
1929
+
1930
+ assert_mpmath_equal(sc.poch, mppoch, [Arg(), Arg()], dps=400)
1931
+
1932
+ def test_sinpi(self):
1933
+ eps = np.finfo(float).eps
1934
+ assert_mpmath_equal(
1935
+ _sinpi,
1936
+ mpmath.sinpi,
1937
+ [Arg()],
1938
+ nan_ok=False,
1939
+ rtol=2*eps,
1940
+ )
1941
+
1942
+ def test_sinpi_complex(self):
1943
+ assert_mpmath_equal(
1944
+ _sinpi,
1945
+ mpmath.sinpi,
1946
+ [ComplexArg()],
1947
+ nan_ok=False,
1948
+ rtol=2e-14,
1949
+ )
1950
+
1951
+ def test_shi(self):
1952
+ def shi(x):
1953
+ return sc.shichi(x)[0]
1954
+ assert_mpmath_equal(shi, mpmath.shi, [Arg()])
1955
+ # check asymptotic series cross-over
1956
+ assert_mpmath_equal(shi, mpmath.shi, [FixedArg([88 - 1e-9, 88, 88 + 1e-9])])
1957
+
1958
+ def test_shi_complex(self):
1959
+ def shi(z):
1960
+ return sc.shichi(z)[0]
1961
+ # shi oscillates as Im[z] -> +- inf, so limit range
1962
+ assert_mpmath_equal(
1963
+ shi,
1964
+ mpmath.shi,
1965
+ [ComplexArg(complex(-np.inf, -1e8), complex(np.inf, 1e8))],
1966
+ rtol=1e-12,
1967
+ )
1968
+
1969
+ def test_si(self):
1970
+ def si(x):
1971
+ return sc.sici(x)[0]
1972
+ assert_mpmath_equal(si, mpmath.si, [Arg()])
1973
+
1974
+ def test_si_complex(self):
1975
+ def si(z):
1976
+ return sc.sici(z)[0]
1977
+ # si oscillates as Re[z] -> +- inf, so limit range
1978
+ assert_mpmath_equal(
1979
+ si,
1980
+ mpmath.si,
1981
+ [ComplexArg(complex(-1e8, -np.inf), complex(1e8, np.inf))],
1982
+ rtol=1e-12,
1983
+ )
1984
+
1985
+ def test_spence(self):
1986
+ # mpmath uses a different convention for the dilogarithm
1987
+ def dilog(x):
1988
+ return mpmath.polylog(2, 1 - x)
1989
+ # Spence has a branch cut on the negative real axis
1990
+ assert_mpmath_equal(
1991
+ sc.spence,
1992
+ exception_to_nan(dilog),
1993
+ [Arg(0, np.inf)],
1994
+ rtol=1e-14,
1995
+ )
1996
+
1997
+ def test_spence_complex(self):
1998
+ def dilog(z):
1999
+ return mpmath.polylog(2, 1 - z)
2000
+ assert_mpmath_equal(
2001
+ sc.spence,
2002
+ exception_to_nan(dilog),
2003
+ [ComplexArg()],
2004
+ rtol=1e-14,
2005
+ )
2006
+
2007
+ def test_spherharm(self):
2008
+ def spherharm(l, m, theta, phi):
2009
+ if m > l:
2010
+ return np.nan
2011
+ return sc.sph_harm(m, l, phi, theta)
2012
+ assert_mpmath_equal(
2013
+ spherharm,
2014
+ mpmath.spherharm,
2015
+ [IntArg(0, 100), IntArg(0, 100), Arg(a=0, b=pi), Arg(a=0, b=2*pi)],
2016
+ atol=1e-8,
2017
+ n=6000,
2018
+ dps=150,
2019
+ )
2020
+
2021
+ def test_struveh(self):
2022
+ assert_mpmath_equal(
2023
+ sc.struve,
2024
+ exception_to_nan(mpmath.struveh),
2025
+ [Arg(-1e4, 1e4), Arg(0, 1e4)],
2026
+ rtol=5e-10,
2027
+ )
2028
+
2029
+ def test_struvel(self):
2030
+ def mp_struvel(v, z):
2031
+ if v < 0 and z < -v and abs(v) > 1000:
2032
+ # larger DPS needed for correct results
2033
+ old_dps = mpmath.mp.dps
2034
+ try:
2035
+ mpmath.mp.dps = 300
2036
+ return mpmath.struvel(v, z)
2037
+ finally:
2038
+ mpmath.mp.dps = old_dps
2039
+ return mpmath.struvel(v, z)
2040
+
2041
+ assert_mpmath_equal(
2042
+ sc.modstruve,
2043
+ exception_to_nan(mp_struvel),
2044
+ [Arg(-1e4, 1e4), Arg(0, 1e4)],
2045
+ rtol=5e-10,
2046
+ ignore_inf_sign=True,
2047
+ )
2048
+
2049
+ def test_wrightomega_real(self):
2050
+ def mpmath_wrightomega_real(x):
2051
+ return mpmath.lambertw(mpmath.exp(x), mpmath.mpf('-0.5'))
2052
+
2053
+ # For x < -1000 the Wright Omega function is just 0 to double
2054
+ # precision, and for x > 1e21 it is just x to double
2055
+ # precision.
2056
+ assert_mpmath_equal(
2057
+ sc.wrightomega,
2058
+ mpmath_wrightomega_real,
2059
+ [Arg(-1000, 1e21)],
2060
+ rtol=5e-15,
2061
+ atol=0,
2062
+ nan_ok=False,
2063
+ )
2064
+
2065
+ def test_wrightomega(self):
2066
+ assert_mpmath_equal(
2067
+ sc.wrightomega,
2068
+ lambda z: _mpmath_wrightomega(z, 25),
2069
+ [ComplexArg()],
2070
+ rtol=1e-14,
2071
+ nan_ok=False,
2072
+ )
2073
+
2074
+ def test_hurwitz_zeta(self):
2075
+ assert_mpmath_equal(
2076
+ sc.zeta,
2077
+ exception_to_nan(mpmath.zeta),
2078
+ [Arg(a=1, b=1e10, inclusive_a=False), Arg(a=0, inclusive_a=False)],
2079
+ )
2080
+
2081
+ def test_riemann_zeta(self):
2082
+ assert_mpmath_equal(
2083
+ sc.zeta,
2084
+ lambda x: mpmath.zeta(x) if x != 1 else mpmath.inf,
2085
+ [Arg(-100, 100)],
2086
+ nan_ok=False,
2087
+ rtol=5e-13,
2088
+ )
2089
+
2090
+ def test_zetac(self):
2091
+ assert_mpmath_equal(
2092
+ sc.zetac,
2093
+ lambda x: mpmath.zeta(x) - 1 if x != 1 else mpmath.inf,
2094
+ [Arg(-100, 100)],
2095
+ nan_ok=False,
2096
+ dps=45,
2097
+ rtol=5e-13,
2098
+ )
2099
+
2100
+ def test_boxcox(self):
2101
+
2102
+ def mp_boxcox(x, lmbda):
2103
+ x = mpmath.mp.mpf(x)
2104
+ lmbda = mpmath.mp.mpf(lmbda)
2105
+ if lmbda == 0:
2106
+ return mpmath.mp.log(x)
2107
+ else:
2108
+ return mpmath.mp.powm1(x, lmbda) / lmbda
2109
+
2110
+ assert_mpmath_equal(
2111
+ sc.boxcox,
2112
+ exception_to_nan(mp_boxcox),
2113
+ [Arg(a=0, inclusive_a=False), Arg()],
2114
+ n=200,
2115
+ dps=60,
2116
+ rtol=1e-13,
2117
+ )
2118
+
2119
+ def test_boxcox1p(self):
2120
+
2121
+ def mp_boxcox1p(x, lmbda):
2122
+ x = mpmath.mp.mpf(x)
2123
+ lmbda = mpmath.mp.mpf(lmbda)
2124
+ one = mpmath.mp.mpf(1)
2125
+ if lmbda == 0:
2126
+ return mpmath.mp.log(one + x)
2127
+ else:
2128
+ return mpmath.mp.powm1(one + x, lmbda) / lmbda
2129
+
2130
+ assert_mpmath_equal(
2131
+ sc.boxcox1p,
2132
+ exception_to_nan(mp_boxcox1p),
2133
+ [Arg(a=-1, inclusive_a=False), Arg()],
2134
+ n=200,
2135
+ dps=60,
2136
+ rtol=1e-13,
2137
+ )
2138
+
2139
+ def test_spherical_jn(self):
2140
+ def mp_spherical_jn(n, z):
2141
+ arg = mpmath.mpmathify(z)
2142
+ out = (mpmath.besselj(n + mpmath.mpf(1)/2, arg) /
2143
+ mpmath.sqrt(2*arg/mpmath.pi))
2144
+ if arg.imag == 0:
2145
+ return out.real
2146
+ else:
2147
+ return out
2148
+
2149
+ assert_mpmath_equal(
2150
+ lambda n, z: sc.spherical_jn(int(n), z),
2151
+ exception_to_nan(mp_spherical_jn),
2152
+ [IntArg(0, 200), Arg(-1e8, 1e8)],
2153
+ dps=300,
2154
+ )
2155
+
2156
+ def test_spherical_jn_complex(self):
2157
+ def mp_spherical_jn(n, z):
2158
+ arg = mpmath.mpmathify(z)
2159
+ out = (mpmath.besselj(n + mpmath.mpf(1)/2, arg) /
2160
+ mpmath.sqrt(2*arg/mpmath.pi))
2161
+ if arg.imag == 0:
2162
+ return out.real
2163
+ else:
2164
+ return out
2165
+
2166
+ assert_mpmath_equal(
2167
+ lambda n, z: sc.spherical_jn(int(n.real), z),
2168
+ exception_to_nan(mp_spherical_jn),
2169
+ [IntArg(0, 200), ComplexArg()]
2170
+ )
2171
+
2172
+ def test_spherical_yn(self):
2173
+ def mp_spherical_yn(n, z):
2174
+ arg = mpmath.mpmathify(z)
2175
+ out = (mpmath.bessely(n + mpmath.mpf(1)/2, arg) /
2176
+ mpmath.sqrt(2*arg/mpmath.pi))
2177
+ if arg.imag == 0:
2178
+ return out.real
2179
+ else:
2180
+ return out
2181
+
2182
+ assert_mpmath_equal(
2183
+ lambda n, z: sc.spherical_yn(int(n), z),
2184
+ exception_to_nan(mp_spherical_yn),
2185
+ [IntArg(0, 200), Arg(-1e10, 1e10)],
2186
+ dps=100,
2187
+ )
2188
+
2189
+ def test_spherical_yn_complex(self):
2190
+ def mp_spherical_yn(n, z):
2191
+ arg = mpmath.mpmathify(z)
2192
+ out = (mpmath.bessely(n + mpmath.mpf(1)/2, arg) /
2193
+ mpmath.sqrt(2*arg/mpmath.pi))
2194
+ if arg.imag == 0:
2195
+ return out.real
2196
+ else:
2197
+ return out
2198
+
2199
+ assert_mpmath_equal(
2200
+ lambda n, z: sc.spherical_yn(int(n.real), z),
2201
+ exception_to_nan(mp_spherical_yn),
2202
+ [IntArg(0, 200), ComplexArg()],
2203
+ )
2204
+
2205
+ def test_spherical_in(self):
2206
+ def mp_spherical_in(n, z):
2207
+ arg = mpmath.mpmathify(z)
2208
+ out = (mpmath.besseli(n + mpmath.mpf(1)/2, arg) /
2209
+ mpmath.sqrt(2*arg/mpmath.pi))
2210
+ if arg.imag == 0:
2211
+ return out.real
2212
+ else:
2213
+ return out
2214
+
2215
+ assert_mpmath_equal(
2216
+ lambda n, z: sc.spherical_in(int(n), z),
2217
+ exception_to_nan(mp_spherical_in),
2218
+ [IntArg(0, 200), Arg()],
2219
+ dps=200,
2220
+ atol=10**(-278),
2221
+ )
2222
+
2223
+ def test_spherical_in_complex(self):
2224
+ def mp_spherical_in(n, z):
2225
+ arg = mpmath.mpmathify(z)
2226
+ out = (mpmath.besseli(n + mpmath.mpf(1)/2, arg) /
2227
+ mpmath.sqrt(2*arg/mpmath.pi))
2228
+ if arg.imag == 0:
2229
+ return out.real
2230
+ else:
2231
+ return out
2232
+
2233
+ assert_mpmath_equal(
2234
+ lambda n, z: sc.spherical_in(int(n.real), z),
2235
+ exception_to_nan(mp_spherical_in),
2236
+ [IntArg(0, 200), ComplexArg()],
2237
+ )
2238
+
2239
+ def test_spherical_kn(self):
2240
+ def mp_spherical_kn(n, z):
2241
+ out = (mpmath.besselk(n + mpmath.mpf(1)/2, z) *
2242
+ mpmath.sqrt(mpmath.pi/(2*mpmath.mpmathify(z))))
2243
+ if mpmath.mpmathify(z).imag == 0:
2244
+ return out.real
2245
+ else:
2246
+ return out
2247
+
2248
+ assert_mpmath_equal(
2249
+ lambda n, z: sc.spherical_kn(int(n), z),
2250
+ exception_to_nan(mp_spherical_kn),
2251
+ [IntArg(0, 150), Arg()],
2252
+ dps=100,
2253
+ )
2254
+
2255
+ @pytest.mark.xfail(run=False,
2256
+ reason="Accuracy issues near z = -1 inherited from kv.")
2257
+ def test_spherical_kn_complex(self):
2258
+ def mp_spherical_kn(n, z):
2259
+ arg = mpmath.mpmathify(z)
2260
+ out = (mpmath.besselk(n + mpmath.mpf(1)/2, arg) /
2261
+ mpmath.sqrt(2*arg/mpmath.pi))
2262
+ if arg.imag == 0:
2263
+ return out.real
2264
+ else:
2265
+ return out
2266
+
2267
+ assert_mpmath_equal(
2268
+ lambda n, z: sc.spherical_kn(int(n.real), z),
2269
+ exception_to_nan(mp_spherical_kn),
2270
+ [IntArg(0, 200), ComplexArg()],
2271
+ dps=200,
2272
+ )
openflamingo/lib/python3.10/site-packages/scipy/special/tests/test_nan_inputs.py ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Test how the ufuncs in special handle nan inputs.
2
+
3
+ """
4
+ from typing import Callable
5
+
6
+ import numpy as np
7
+ from numpy.testing import assert_array_equal, assert_, suppress_warnings
8
+ import pytest
9
+ import scipy.special as sc
10
+
11
+
12
+ KNOWNFAILURES: dict[str, Callable] = {}
13
+
14
+ POSTPROCESSING: dict[str, Callable] = {}
15
+
16
+
17
+ def _get_ufuncs():
18
+ ufuncs = []
19
+ ufunc_names = []
20
+ for name in sorted(sc.__dict__):
21
+ obj = sc.__dict__[name]
22
+ if not isinstance(obj, np.ufunc):
23
+ continue
24
+ msg = KNOWNFAILURES.get(obj)
25
+ if msg is None:
26
+ ufuncs.append(obj)
27
+ ufunc_names.append(name)
28
+ else:
29
+ fail = pytest.mark.xfail(run=False, reason=msg)
30
+ ufuncs.append(pytest.param(obj, marks=fail))
31
+ ufunc_names.append(name)
32
+ return ufuncs, ufunc_names
33
+
34
+
35
+ UFUNCS, UFUNC_NAMES = _get_ufuncs()
36
+
37
+
38
+ @pytest.mark.parametrize("func", UFUNCS, ids=UFUNC_NAMES)
39
+ def test_nan_inputs(func):
40
+ args = (np.nan,)*func.nin
41
+ with suppress_warnings() as sup:
42
+ # Ignore warnings about unsafe casts from legacy wrappers
43
+ sup.filter(RuntimeWarning,
44
+ "floating point number truncated to an integer")
45
+ try:
46
+ with suppress_warnings() as sup:
47
+ sup.filter(DeprecationWarning)
48
+ res = func(*args)
49
+ except TypeError:
50
+ # One of the arguments doesn't take real inputs
51
+ return
52
+ if func in POSTPROCESSING:
53
+ res = POSTPROCESSING[func](*res)
54
+
55
+ msg = f"got {res} instead of nan"
56
+ assert_array_equal(np.isnan(res), True, err_msg=msg)
57
+
58
+
59
+ def test_legacy_cast():
60
+ with suppress_warnings() as sup:
61
+ sup.filter(RuntimeWarning,
62
+ "floating point number truncated to an integer")
63
+ res = sc.bdtrc(np.nan, 1, 0.5)
64
+ assert_(np.isnan(res))