FaustDerLegende commited on
Commit
5c1037b
·
verified ·
1 Parent(s): b455217

Upload folder using huggingface_hub (part 16)

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 +20 -0
  2. .venv/lib/python3.12/site-packages/scipy-1.18.1.dist-info/INSTALLER +1 -0
  3. .venv/lib/python3.12/site-packages/scipy-1.18.1.dist-info/LICENSE.txt +937 -0
  4. .venv/lib/python3.12/site-packages/scipy-1.18.1.dist-info/METADATA +1092 -0
  5. .venv/lib/python3.12/site-packages/scipy-1.18.1.dist-info/RECORD +0 -0
  6. .venv/lib/python3.12/site-packages/scipy-1.18.1.dist-info/WHEEL +6 -0
  7. .venv/lib/python3.12/site-packages/scipy-1.18.1.dist-info/sboms/auditwheel.cdx.json +1 -0
  8. .venv/lib/python3.12/site-packages/scipy.libs/libgfortran-040039e1-0352e75f.so.5.0.0 +3 -0
  9. .venv/lib/python3.12/site-packages/scipy.libs/libgfortran-83c28eba.so.5.0.0 +3 -0
  10. .venv/lib/python3.12/site-packages/scipy.libs/libquadmath-2284e583.so.0.0.0 +3 -0
  11. .venv/lib/python3.12/site-packages/scipy.libs/libquadmath-96973f99-934c22de.so.0.0.0 +3 -0
  12. .venv/lib/python3.12/site-packages/scipy.libs/libscipy_openblas-5f890258.so +3 -0
  13. .venv/lib/python3.12/site-packages/scipy/special/tests/test_ellip_harm.py +288 -0
  14. .venv/lib/python3.12/site-packages/scipy/special/tests/test_erfinv.py +89 -0
  15. .venv/lib/python3.12/site-packages/scipy/special/tests/test_exponential_integrals.py +123 -0
  16. .venv/lib/python3.12/site-packages/scipy/special/tests/test_extending.py +28 -0
  17. .venv/lib/python3.12/site-packages/scipy/special/tests/test_faddeeva.py +85 -0
  18. .venv/lib/python3.12/site-packages/scipy/special/tests/test_gamma.py +12 -0
  19. .venv/lib/python3.12/site-packages/scipy/special/tests/test_gammainc.py +152 -0
  20. .venv/lib/python3.12/site-packages/scipy/special/tests/test_gen_harmonic.py +99 -0
  21. .venv/lib/python3.12/site-packages/scipy/special/tests/test_hyp2f1.py +2566 -0
  22. .venv/lib/python3.12/site-packages/scipy/special/tests/test_hypergeometric.py +234 -0
  23. .venv/lib/python3.12/site-packages/scipy/special/tests/test_iv_ratio.py +249 -0
  24. .venv/lib/python3.12/site-packages/scipy/special/tests/test_kolmogorov.py +491 -0
  25. .venv/lib/python3.12/site-packages/scipy/special/tests/test_lambertw.py +109 -0
  26. .venv/lib/python3.12/site-packages/scipy/special/tests/test_legendre.py +1421 -0
  27. .venv/lib/python3.12/site-packages/scipy/special/tests/test_log1mexp.py +85 -0
  28. .venv/lib/python3.12/site-packages/scipy/special/tests/test_loggamma.py +70 -0
  29. .venv/lib/python3.12/site-packages/scipy/special/tests/test_logit.py +161 -0
  30. .venv/lib/python3.12/site-packages/scipy/special/tests/test_logsumexp.py +481 -0
  31. .venv/lib/python3.12/site-packages/scipy/special/tests/test_mpmath.py +2160 -0
  32. .venv/lib/python3.12/site-packages/scipy/special/tests/test_nan_inputs.py +72 -0
  33. .venv/lib/python3.12/site-packages/scipy/special/tests/test_ndtr.py +77 -0
  34. .venv/lib/python3.12/site-packages/scipy/special/tests/test_ndtri_exp.py +94 -0
  35. .venv/lib/python3.12/site-packages/scipy/special/tests/test_orthogonal.py +823 -0
  36. .venv/lib/python3.12/site-packages/scipy/special/tests/test_orthogonal_eval.py +383 -0
  37. .venv/lib/python3.12/site-packages/scipy/special/tests/test_owens_t.py +53 -0
  38. .venv/lib/python3.12/site-packages/scipy/special/tests/test_pcf.py +24 -0
  39. .venv/lib/python3.12/site-packages/scipy/special/tests/test_pdtr.py +48 -0
  40. .venv/lib/python3.12/site-packages/scipy/special/tests/test_powm1.py +65 -0
  41. .venv/lib/python3.12/site-packages/scipy/special/tests/test_precompute_expn_asy.py +24 -0
  42. .venv/lib/python3.12/site-packages/scipy/special/tests/test_precompute_gammainc.py +112 -0
  43. .venv/lib/python3.12/site-packages/scipy/special/tests/test_precompute_utils.py +36 -0
  44. .venv/lib/python3.12/site-packages/scipy/special/tests/test_round.py +18 -0
  45. .venv/lib/python3.12/site-packages/scipy/special/tests/test_sf_error.py +153 -0
  46. .venv/lib/python3.12/site-packages/scipy/special/tests/test_sici.py +36 -0
  47. .venv/lib/python3.12/site-packages/scipy/special/tests/test_specfun.py +48 -0
  48. .venv/lib/python3.12/site-packages/scipy/special/tests/test_spence.py +32 -0
  49. .venv/lib/python3.12/site-packages/scipy/special/tests/test_spfun_stats.py +61 -0
  50. .venv/lib/python3.12/site-packages/scipy/special/tests/test_sph_harm.py +48 -0
.gitattributes CHANGED
@@ -385,3 +385,23 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
385
  .venv/lib/python3.12/site-packages/scipy/special/_ufuncs.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
386
  .venv/lib/python3.12/site-packages/scipy/special/_ufuncs_cxx.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
387
  .venv/lib/python3.12/site-packages/scipy/special/cython_special.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
385
  .venv/lib/python3.12/site-packages/scipy/special/_ufuncs.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
386
  .venv/lib/python3.12/site-packages/scipy/special/_ufuncs_cxx.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
387
  .venv/lib/python3.12/site-packages/scipy/special/cython_special.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
388
+ .venv/lib/python3.12/site-packages/scipy/stats/_ansari_swilk_statistics.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
389
+ .venv/lib/python3.12/site-packages/scipy/stats/_biasedurn.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
390
+ .venv/lib/python3.12/site-packages/scipy/stats/_qmc_cy.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
391
+ .venv/lib/python3.12/site-packages/scipy/stats/_qmvnt_cy.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
392
+ .venv/lib/python3.12/site-packages/scipy/stats/_rcont/rcont.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
393
+ .venv/lib/python3.12/site-packages/scipy/stats/_sobol.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
394
+ .venv/lib/python3.12/site-packages/scipy/stats/_stats.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
395
+ .venv/lib/python3.12/site-packages/scipy/stats/_stats_pythran.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
396
+ .venv/lib/python3.12/site-packages/scipy/stats/_unuran/unuran_wrapper.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
397
+ .venv/lib/python3.12/site-packages/scipy.libs/libgfortran-040039e1-0352e75f.so.5.0.0 filter=lfs diff=lfs merge=lfs -text
398
+ .venv/lib/python3.12/site-packages/scipy.libs/libgfortran-83c28eba.so.5.0.0 filter=lfs diff=lfs merge=lfs -text
399
+ .venv/lib/python3.12/site-packages/scipy.libs/libquadmath-2284e583.so.0.0.0 filter=lfs diff=lfs merge=lfs -text
400
+ .venv/lib/python3.12/site-packages/scipy.libs/libquadmath-96973f99-934c22de.so.0.0.0 filter=lfs diff=lfs merge=lfs -text
401
+ .venv/lib/python3.12/site-packages/scipy.libs/libscipy_openblas-5f890258.so filter=lfs diff=lfs merge=lfs -text
402
+ .venv/lib/python3.12/site-packages/setuptools/_vendor/__pycache__/typing_extensions.cpython-312.pyc filter=lfs diff=lfs merge=lfs -text
403
+ .venv/lib/python3.12/site-packages/setuptools/_vendor/backports/tarfile/__pycache__/__init__.cpython-312.pyc filter=lfs diff=lfs merge=lfs -text
404
+ .venv/lib/python3.12/site-packages/setuptools/_vendor/inflect/__pycache__/__init__.cpython-312.pyc filter=lfs diff=lfs merge=lfs -text
405
+ .venv/lib/python3.12/site-packages/setuptools/_vendor/more_itertools/__pycache__/more.cpython-312.pyc filter=lfs diff=lfs merge=lfs -text
406
+ .venv/lib/python3.12/site-packages/setuptools/command/__pycache__/easy_install.cpython-312.pyc filter=lfs diff=lfs merge=lfs -text
407
+ .venv/lib/python3.12/site-packages/setuptools/config/_validate_pyproject/__pycache__/fastjsonschema_validations.cpython-312.pyc filter=lfs diff=lfs merge=lfs -text
.venv/lib/python3.12/site-packages/scipy-1.18.1.dist-info/INSTALLER ADDED
@@ -0,0 +1 @@
 
 
1
+ pip
.venv/lib/python3.12/site-packages/scipy-1.18.1.dist-info/LICENSE.txt ADDED
@@ -0,0 +1,937 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Copyright (c) 2001-2002 Enthought, Inc. 2003, SciPy Developers.
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions
6
+ are met:
7
+
8
+ 1. Redistributions of source code must retain the above copyright
9
+ notice, this list of conditions and the following disclaimer.
10
+
11
+ 2. Redistributions in binary form must reproduce the above
12
+ copyright notice, this list of conditions and the following
13
+ disclaimer in the documentation and/or other materials provided
14
+ with the distribution.
15
+
16
+ 3. Neither the name of the copyright holder nor the names of its
17
+ contributors may be used to endorse or promote products derived
18
+ from this software without specific prior written permission.
19
+
20
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
+
32
+ ----
33
+
34
+
35
+ ----
36
+
37
+ This binary distribution of SciPy can also bundle the following software
38
+ (depending on the build):
39
+
40
+
41
+ Name: OpenBLAS
42
+ Files: scipy.libs/libscipy_openblas*.so
43
+ Description: bundled as a dynamically linked library
44
+ Availability: https://github.com/OpenMathLib/OpenBLAS/
45
+ License: BSD-3-Clause
46
+ Copyright (c) 2011-2014, The OpenBLAS Project
47
+ All rights reserved.
48
+
49
+ Redistribution and use in source and binary forms, with or without
50
+ modification, are permitted provided that the following conditions are
51
+ met:
52
+
53
+ 1. Redistributions of source code must retain the above copyright
54
+ notice, this list of conditions and the following disclaimer.
55
+
56
+ 2. Redistributions in binary form must reproduce the above copyright
57
+ notice, this list of conditions and the following disclaimer in
58
+ the documentation and/or other materials provided with the
59
+ distribution.
60
+ 3. Neither the name of the OpenBLAS project nor the names of
61
+ its contributors may be used to endorse or promote products
62
+ derived from this software without specific prior written
63
+ permission.
64
+
65
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
66
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
67
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
68
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
69
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
70
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
71
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
72
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
73
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
74
+ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
75
+
76
+
77
+ Name: LAPACK
78
+ Files: scipy.libs/libscipy_openblas*.so
79
+ Description: bundled in OpenBLAS
80
+ Availability: https://github.com/OpenMathLib/OpenBLAS/
81
+ License: BSD-3-Clause-Open-MPI
82
+ Copyright (c) 1992-2013 The University of Tennessee and The University
83
+ of Tennessee Research Foundation. All rights
84
+ reserved.
85
+ Copyright (c) 2000-2013 The University of California Berkeley. All
86
+ rights reserved.
87
+ Copyright (c) 2006-2013 The University of Colorado Denver. All rights
88
+ reserved.
89
+
90
+ $COPYRIGHT$
91
+
92
+ Additional copyrights may follow
93
+
94
+ $HEADER$
95
+
96
+ Redistribution and use in source and binary forms, with or without
97
+ modification, are permitted provided that the following conditions are
98
+ met:
99
+
100
+ - Redistributions of source code must retain the above copyright
101
+ notice, this list of conditions and the following disclaimer.
102
+
103
+ - Redistributions in binary form must reproduce the above copyright
104
+ notice, this list of conditions and the following disclaimer listed
105
+ in this license in the documentation and/or other materials
106
+ provided with the distribution.
107
+
108
+ - Neither the name of the copyright holders nor the names of its
109
+ contributors may be used to endorse or promote products derived from
110
+ this software without specific prior written permission.
111
+
112
+ The copyright holders provide no reassurances that the source code
113
+ provided does not infringe any patent, copyright, or any other
114
+ intellectual property rights of third parties. The copyright holders
115
+ disclaim any liability to any recipient for claims brought against
116
+ recipient by any third party for infringement of that parties
117
+ intellectual property rights.
118
+
119
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
120
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
121
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
122
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
123
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
124
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
125
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
126
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
127
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
128
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
129
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
130
+
131
+
132
+ Name: GCC runtime library
133
+ Files: scipy.libs/libgfortran*.so
134
+ Description: dynamically linked to files compiled with gcc
135
+ Availability: https://gcc.gnu.org/git/?p=gcc.git;a=tree;f=libgfortran
136
+ License: GPL-3.0-or-later WITH GCC-exception-3.1
137
+ Copyright (C) 2002-2017 Free Software Foundation, Inc.
138
+
139
+ Libgfortran is free software; you can redistribute it and/or modify
140
+ it under the terms of the GNU General Public License as published by
141
+ the Free Software Foundation; either version 3, or (at your option)
142
+ any later version.
143
+
144
+ Libgfortran is distributed in the hope that it will be useful,
145
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
146
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
147
+ GNU General Public License for more details.
148
+
149
+ Under Section 7 of GPL version 3, you are granted additional
150
+ permissions described in the GCC Runtime Library Exception, version
151
+ 3.1, as published by the Free Software Foundation.
152
+
153
+ You should have received a copy of the GNU General Public License and
154
+ a copy of the GCC Runtime Library Exception along with this program;
155
+ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
156
+ <http://www.gnu.org/licenses/>.
157
+
158
+ ----
159
+
160
+ Full text of license texts referred to above follows (that they are
161
+ listed below does not necessarily imply the conditions apply to the
162
+ present binary release):
163
+
164
+ ----
165
+
166
+ GCC RUNTIME LIBRARY EXCEPTION
167
+
168
+ Version 3.1, 31 March 2009
169
+
170
+ Copyright (C) 2009 Free Software Foundation, Inc. <http://fsf.org/>
171
+
172
+ Everyone is permitted to copy and distribute verbatim copies of this
173
+ license document, but changing it is not allowed.
174
+
175
+ This GCC Runtime Library Exception ("Exception") is an additional
176
+ permission under section 7 of the GNU General Public License, version
177
+ 3 ("GPLv3"). It applies to a given file (the "Runtime Library") that
178
+ bears a notice placed by the copyright holder of the file stating that
179
+ the file is governed by GPLv3 along with this Exception.
180
+
181
+ When you use GCC to compile a program, GCC may combine portions of
182
+ certain GCC header files and runtime libraries with the compiled
183
+ program. The purpose of this Exception is to allow compilation of
184
+ non-GPL (including proprietary) programs to use, in this way, the
185
+ header files and runtime libraries covered by this Exception.
186
+
187
+ 0. Definitions.
188
+
189
+ A file is an "Independent Module" if it either requires the Runtime
190
+ Library for execution after a Compilation Process, or makes use of an
191
+ interface provided by the Runtime Library, but is not otherwise based
192
+ on the Runtime Library.
193
+
194
+ "GCC" means a version of the GNU Compiler Collection, with or without
195
+ modifications, governed by version 3 (or a specified later version) of
196
+ the GNU General Public License (GPL) with the option of using any
197
+ subsequent versions published by the FSF.
198
+
199
+ "GPL-compatible Software" is software whose conditions of propagation,
200
+ modification and use would permit combination with GCC in accord with
201
+ the license of GCC.
202
+
203
+ "Target Code" refers to output from any compiler for a real or virtual
204
+ target processor architecture, in executable form or suitable for
205
+ input to an assembler, loader, linker and/or execution
206
+ phase. Notwithstanding that, Target Code does not include data in any
207
+ format that is used as a compiler intermediate representation, or used
208
+ for producing a compiler intermediate representation.
209
+
210
+ The "Compilation Process" transforms code entirely represented in
211
+ non-intermediate languages designed for human-written code, and/or in
212
+ Java Virtual Machine byte code, into Target Code. Thus, for example,
213
+ use of source code generators and preprocessors need not be considered
214
+ part of the Compilation Process, since the Compilation Process can be
215
+ understood as starting with the output of the generators or
216
+ preprocessors.
217
+
218
+ A Compilation Process is "Eligible" if it is done using GCC, alone or
219
+ with other GPL-compatible software, or if it is done without using any
220
+ work based on GCC. For example, using non-GPL-compatible Software to
221
+ optimize any GCC intermediate representations would not qualify as an
222
+ Eligible Compilation Process.
223
+
224
+ 1. Grant of Additional Permission.
225
+
226
+ You have permission to propagate a work of Target Code formed by
227
+ combining the Runtime Library with Independent Modules, even if such
228
+ propagation would otherwise violate the terms of GPLv3, provided that
229
+ all Target Code was generated by Eligible Compilation Processes. You
230
+ may then convey such a combination under terms of your choice,
231
+ consistent with the licensing of the Independent Modules.
232
+
233
+ 2. No Weakening of GCC Copyleft.
234
+
235
+ The availability of this Exception does not imply any general
236
+ presumption that third-party software is unaffected by the copyleft
237
+ requirements of the license of GCC.
238
+
239
+ ----
240
+
241
+ GNU GENERAL PUBLIC LICENSE
242
+ Version 3, 29 June 2007
243
+
244
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
245
+ Everyone is permitted to copy and distribute verbatim copies
246
+ of this license document, but changing it is not allowed.
247
+
248
+ Preamble
249
+
250
+ The GNU General Public License is a free, copyleft license for
251
+ software and other kinds of works.
252
+
253
+ The licenses for most software and other practical works are designed
254
+ to take away your freedom to share and change the works. By contrast,
255
+ the GNU General Public License is intended to guarantee your freedom to
256
+ share and change all versions of a program--to make sure it remains free
257
+ software for all its users. We, the Free Software Foundation, use the
258
+ GNU General Public License for most of our software; it applies also to
259
+ any other work released this way by its authors. You can apply it to
260
+ your programs, too.
261
+
262
+ When we speak of free software, we are referring to freedom, not
263
+ price. Our General Public Licenses are designed to make sure that you
264
+ have the freedom to distribute copies of free software (and charge for
265
+ them if you wish), that you receive source code or can get it if you
266
+ want it, that you can change the software or use pieces of it in new
267
+ free programs, and that you know you can do these things.
268
+
269
+ To protect your rights, we need to prevent others from denying you
270
+ these rights or asking you to surrender the rights. Therefore, you have
271
+ certain responsibilities if you distribute copies of the software, or if
272
+ you modify it: responsibilities to respect the freedom of others.
273
+
274
+ For example, if you distribute copies of such a program, whether
275
+ gratis or for a fee, you must pass on to the recipients the same
276
+ freedoms that you received. You must make sure that they, too, receive
277
+ or can get the source code. And you must show them these terms so they
278
+ know their rights.
279
+
280
+ Developers that use the GNU GPL protect your rights with two steps:
281
+ (1) assert copyright on the software, and (2) offer you this License
282
+ giving you legal permission to copy, distribute and/or modify it.
283
+
284
+ For the developers' and authors' protection, the GPL clearly explains
285
+ that there is no warranty for this free software. For both users' and
286
+ authors' sake, the GPL requires that modified versions be marked as
287
+ changed, so that their problems will not be attributed erroneously to
288
+ authors of previous versions.
289
+
290
+ Some devices are designed to deny users access to install or run
291
+ modified versions of the software inside them, although the manufacturer
292
+ can do so. This is fundamentally incompatible with the aim of
293
+ protecting users' freedom to change the software. The systematic
294
+ pattern of such abuse occurs in the area of products for individuals to
295
+ use, which is precisely where it is most unacceptable. Therefore, we
296
+ have designed this version of the GPL to prohibit the practice for those
297
+ products. If such problems arise substantially in other domains, we
298
+ stand ready to extend this provision to those domains in future versions
299
+ of the GPL, as needed to protect the freedom of users.
300
+
301
+ Finally, every program is threatened constantly by software patents.
302
+ States should not allow patents to restrict development and use of
303
+ software on general-purpose computers, but in those that do, we wish to
304
+ avoid the special danger that patents applied to a free program could
305
+ make it effectively proprietary. To prevent this, the GPL assures that
306
+ patents cannot be used to render the program non-free.
307
+
308
+ The precise terms and conditions for copying, distribution and
309
+ modification follow.
310
+
311
+ TERMS AND CONDITIONS
312
+
313
+ 0. Definitions.
314
+
315
+ "This License" refers to version 3 of the GNU General Public License.
316
+
317
+ "Copyright" also means copyright-like laws that apply to other kinds of
318
+ works, such as semiconductor masks.
319
+
320
+ "The Program" refers to any copyrightable work licensed under this
321
+ License. Each licensee is addressed as "you". "Licensees" and
322
+ "recipients" may be individuals or organizations.
323
+
324
+ To "modify" a work means to copy from or adapt all or part of the work
325
+ in a fashion requiring copyright permission, other than the making of an
326
+ exact copy. The resulting work is called a "modified version" of the
327
+ earlier work or a work "based on" the earlier work.
328
+
329
+ A "covered work" means either the unmodified Program or a work based
330
+ on the Program.
331
+
332
+ To "propagate" a work means to do anything with it that, without
333
+ permission, would make you directly or secondarily liable for
334
+ infringement under applicable copyright law, except executing it on a
335
+ computer or modifying a private copy. Propagation includes copying,
336
+ distribution (with or without modification), making available to the
337
+ public, and in some countries other activities as well.
338
+
339
+ To "convey" a work means any kind of propagation that enables other
340
+ parties to make or receive copies. Mere interaction with a user through
341
+ a computer network, with no transfer of a copy, is not conveying.
342
+
343
+ An interactive user interface displays "Appropriate Legal Notices"
344
+ to the extent that it includes a convenient and prominently visible
345
+ feature that (1) displays an appropriate copyright notice, and (2)
346
+ tells the user that there is no warranty for the work (except to the
347
+ extent that warranties are provided), that licensees may convey the
348
+ work under this License, and how to view a copy of this License. If
349
+ the interface presents a list of user commands or options, such as a
350
+ menu, a prominent item in the list meets this criterion.
351
+
352
+ 1. Source Code.
353
+
354
+ The "source code" for a work means the preferred form of the work
355
+ for making modifications to it. "Object code" means any non-source
356
+ form of a work.
357
+
358
+ A "Standard Interface" means an interface that either is an official
359
+ standard defined by a recognized standards body, or, in the case of
360
+ interfaces specified for a particular programming language, one that
361
+ is widely used among developers working in that language.
362
+
363
+ The "System Libraries" of an executable work include anything, other
364
+ than the work as a whole, that (a) is included in the normal form of
365
+ packaging a Major Component, but which is not part of that Major
366
+ Component, and (b) serves only to enable use of the work with that
367
+ Major Component, or to implement a Standard Interface for which an
368
+ implementation is available to the public in source code form. A
369
+ "Major Component", in this context, means a major essential component
370
+ (kernel, window system, and so on) of the specific operating system
371
+ (if any) on which the executable work runs, or a compiler used to
372
+ produce the work, or an object code interpreter used to run it.
373
+
374
+ The "Corresponding Source" for a work in object code form means all
375
+ the source code needed to generate, install, and (for an executable
376
+ work) run the object code and to modify the work, including scripts to
377
+ control those activities. However, it does not include the work's
378
+ System Libraries, or general-purpose tools or generally available free
379
+ programs which are used unmodified in performing those activities but
380
+ which are not part of the work. For example, Corresponding Source
381
+ includes interface definition files associated with source files for
382
+ the work, and the source code for shared libraries and dynamically
383
+ linked subprograms that the work is specifically designed to require,
384
+ such as by intimate data communication or control flow between those
385
+ subprograms and other parts of the work.
386
+
387
+ The Corresponding Source need not include anything that users
388
+ can regenerate automatically from other parts of the Corresponding
389
+ Source.
390
+
391
+ The Corresponding Source for a work in source code form is that
392
+ same work.
393
+
394
+ 2. Basic Permissions.
395
+
396
+ All rights granted under this License are granted for the term of
397
+ copyright on the Program, and are irrevocable provided the stated
398
+ conditions are met. This License explicitly affirms your unlimited
399
+ permission to run the unmodified Program. The output from running a
400
+ covered work is covered by this License only if the output, given its
401
+ content, constitutes a covered work. This License acknowledges your
402
+ rights of fair use or other equivalent, as provided by copyright law.
403
+
404
+ You may make, run and propagate covered works that you do not
405
+ convey, without conditions so long as your license otherwise remains
406
+ in force. You may convey covered works to others for the sole purpose
407
+ of having them make modifications exclusively for you, or provide you
408
+ with facilities for running those works, provided that you comply with
409
+ the terms of this License in conveying all material for which you do
410
+ not control copyright. Those thus making or running the covered works
411
+ for you must do so exclusively on your behalf, under your direction
412
+ and control, on terms that prohibit them from making any copies of
413
+ your copyrighted material outside their relationship with you.
414
+
415
+ Conveying under any other circumstances is permitted solely under
416
+ the conditions stated below. Sublicensing is not allowed; section 10
417
+ makes it unnecessary.
418
+
419
+ 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
420
+
421
+ No covered work shall be deemed part of an effective technological
422
+ measure under any applicable law fulfilling obligations under article
423
+ 11 of the WIPO copyright treaty adopted on 20 December 1996, or
424
+ similar laws prohibiting or restricting circumvention of such
425
+ measures.
426
+
427
+ When you convey a covered work, you waive any legal power to forbid
428
+ circumvention of technological measures to the extent such circumvention
429
+ is effected by exercising rights under this License with respect to
430
+ the covered work, and you disclaim any intention to limit operation or
431
+ modification of the work as a means of enforcing, against the work's
432
+ users, your or third parties' legal rights to forbid circumvention of
433
+ technological measures.
434
+
435
+ 4. Conveying Verbatim Copies.
436
+
437
+ You may convey verbatim copies of the Program's source code as you
438
+ receive it, in any medium, provided that you conspicuously and
439
+ appropriately publish on each copy an appropriate copyright notice;
440
+ keep intact all notices stating that this License and any
441
+ non-permissive terms added in accord with section 7 apply to the code;
442
+ keep intact all notices of the absence of any warranty; and give all
443
+ recipients a copy of this License along with the Program.
444
+
445
+ You may charge any price or no price for each copy that you convey,
446
+ and you may offer support or warranty protection for a fee.
447
+
448
+ 5. Conveying Modified Source Versions.
449
+
450
+ You may convey a work based on the Program, or the modifications to
451
+ produce it from the Program, in the form of source code under the
452
+ terms of section 4, provided that you also meet all of these conditions:
453
+
454
+ a) The work must carry prominent notices stating that you modified
455
+ it, and giving a relevant date.
456
+
457
+ b) The work must carry prominent notices stating that it is
458
+ released under this License and any conditions added under section
459
+ 7. This requirement modifies the requirement in section 4 to
460
+ "keep intact all notices".
461
+
462
+ c) You must license the entire work, as a whole, under this
463
+ License to anyone who comes into possession of a copy. This
464
+ License will therefore apply, along with any applicable section 7
465
+ additional terms, to the whole of the work, and all its parts,
466
+ regardless of how they are packaged. This License gives no
467
+ permission to license the work in any other way, but it does not
468
+ invalidate such permission if you have separately received it.
469
+
470
+ d) If the work has interactive user interfaces, each must display
471
+ Appropriate Legal Notices; however, if the Program has interactive
472
+ interfaces that do not display Appropriate Legal Notices, your
473
+ work need not make them do so.
474
+
475
+ A compilation of a covered work with other separate and independent
476
+ works, which are not by their nature extensions of the covered work,
477
+ and which are not combined with it such as to form a larger program,
478
+ in or on a volume of a storage or distribution medium, is called an
479
+ "aggregate" if the compilation and its resulting copyright are not
480
+ used to limit the access or legal rights of the compilation's users
481
+ beyond what the individual works permit. Inclusion of a covered work
482
+ in an aggregate does not cause this License to apply to the other
483
+ parts of the aggregate.
484
+
485
+ 6. Conveying Non-Source Forms.
486
+
487
+ You may convey a covered work in object code form under the terms
488
+ of sections 4 and 5, provided that you also convey the
489
+ machine-readable Corresponding Source under the terms of this License,
490
+ in one of these ways:
491
+
492
+ a) Convey the object code in, or embodied in, a physical product
493
+ (including a physical distribution medium), accompanied by the
494
+ Corresponding Source fixed on a durable physical medium
495
+ customarily used for software interchange.
496
+
497
+ b) Convey the object code in, or embodied in, a physical product
498
+ (including a physical distribution medium), accompanied by a
499
+ written offer, valid for at least three years and valid for as
500
+ long as you offer spare parts or customer support for that product
501
+ model, to give anyone who possesses the object code either (1) a
502
+ copy of the Corresponding Source for all the software in the
503
+ product that is covered by this License, on a durable physical
504
+ medium customarily used for software interchange, for a price no
505
+ more than your reasonable cost of physically performing this
506
+ conveying of source, or (2) access to copy the
507
+ Corresponding Source from a network server at no charge.
508
+
509
+ c) Convey individual copies of the object code with a copy of the
510
+ written offer to provide the Corresponding Source. This
511
+ alternative is allowed only occasionally and noncommercially, and
512
+ only if you received the object code with such an offer, in accord
513
+ with subsection 6b.
514
+
515
+ d) Convey the object code by offering access from a designated
516
+ place (gratis or for a charge), and offer equivalent access to the
517
+ Corresponding Source in the same way through the same place at no
518
+ further charge. You need not require recipients to copy the
519
+ Corresponding Source along with the object code. If the place to
520
+ copy the object code is a network server, the Corresponding Source
521
+ may be on a different server (operated by you or a third party)
522
+ that supports equivalent copying facilities, provided you maintain
523
+ clear directions next to the object code saying where to find the
524
+ Corresponding Source. Regardless of what server hosts the
525
+ Corresponding Source, you remain obligated to ensure that it is
526
+ available for as long as needed to satisfy these requirements.
527
+
528
+ e) Convey the object code using peer-to-peer transmission, provided
529
+ you inform other peers where the object code and Corresponding
530
+ Source of the work are being offered to the general public at no
531
+ charge under subsection 6d.
532
+
533
+ A separable portion of the object code, whose source code is excluded
534
+ from the Corresponding Source as a System Library, need not be
535
+ included in conveying the object code work.
536
+
537
+ A "User Product" is either (1) a "consumer product", which means any
538
+ tangible personal property which is normally used for personal, family,
539
+ or household purposes, or (2) anything designed or sold for incorporation
540
+ into a dwelling. In determining whether a product is a consumer product,
541
+ doubtful cases shall be resolved in favor of coverage. For a particular
542
+ product received by a particular user, "normally used" refers to a
543
+ typical or common use of that class of product, regardless of the status
544
+ of the particular user or of the way in which the particular user
545
+ actually uses, or expects or is expected to use, the product. A product
546
+ is a consumer product regardless of whether the product has substantial
547
+ commercial, industrial or non-consumer uses, unless such uses represent
548
+ the only significant mode of use of the product.
549
+
550
+ "Installation Information" for a User Product means any methods,
551
+ procedures, authorization keys, or other information required to install
552
+ and execute modified versions of a covered work in that User Product from
553
+ a modified version of its Corresponding Source. The information must
554
+ suffice to ensure that the continued functioning of the modified object
555
+ code is in no case prevented or interfered with solely because
556
+ modification has been made.
557
+
558
+ If you convey an object code work under this section in, or with, or
559
+ specifically for use in, a User Product, and the conveying occurs as
560
+ part of a transaction in which the right of possession and use of the
561
+ User Product is transferred to the recipient in perpetuity or for a
562
+ fixed term (regardless of how the transaction is characterized), the
563
+ Corresponding Source conveyed under this section must be accompanied
564
+ by the Installation Information. But this requirement does not apply
565
+ if neither you nor any third party retains the ability to install
566
+ modified object code on the User Product (for example, the work has
567
+ been installed in ROM).
568
+
569
+ The requirement to provide Installation Information does not include a
570
+ requirement to continue to provide support service, warranty, or updates
571
+ for a work that has been modified or installed by the recipient, or for
572
+ the User Product in which it has been modified or installed. Access to a
573
+ network may be denied when the modification itself materially and
574
+ adversely affects the operation of the network or violates the rules and
575
+ protocols for communication across the network.
576
+
577
+ Corresponding Source conveyed, and Installation Information provided,
578
+ in accord with this section must be in a format that is publicly
579
+ documented (and with an implementation available to the public in
580
+ source code form), and must require no special password or key for
581
+ unpacking, reading or copying.
582
+
583
+ 7. Additional Terms.
584
+
585
+ "Additional permissions" are terms that supplement the terms of this
586
+ License by making exceptions from one or more of its conditions.
587
+ Additional permissions that are applicable to the entire Program shall
588
+ be treated as though they were included in this License, to the extent
589
+ that they are valid under applicable law. If additional permissions
590
+ apply only to part of the Program, that part may be used separately
591
+ under those permissions, but the entire Program remains governed by
592
+ this License without regard to the additional permissions.
593
+
594
+ When you convey a copy of a covered work, you may at your option
595
+ remove any additional permissions from that copy, or from any part of
596
+ it. (Additional permissions may be written to require their own
597
+ removal in certain cases when you modify the work.) You may place
598
+ additional permissions on material, added by you to a covered work,
599
+ for which you have or can give appropriate copyright permission.
600
+
601
+ Notwithstanding any other provision of this License, for material you
602
+ add to a covered work, you may (if authorized by the copyright holders of
603
+ that material) supplement the terms of this License with terms:
604
+
605
+ a) Disclaiming warranty or limiting liability differently from the
606
+ terms of sections 15 and 16 of this License; or
607
+
608
+ b) Requiring preservation of specified reasonable legal notices or
609
+ author attributions in that material or in the Appropriate Legal
610
+ Notices displayed by works containing it; or
611
+
612
+ c) Prohibiting misrepresentation of the origin of that material, or
613
+ requiring that modified versions of such material be marked in
614
+ reasonable ways as different from the original version; or
615
+
616
+ d) Limiting the use for publicity purposes of names of licensors or
617
+ authors of the material; or
618
+
619
+ e) Declining to grant rights under trademark law for use of some
620
+ trade names, trademarks, or service marks; or
621
+
622
+ f) Requiring indemnification of licensors and authors of that
623
+ material by anyone who conveys the material (or modified versions of
624
+ it) with contractual assumptions of liability to the recipient, for
625
+ any liability that these contractual assumptions directly impose on
626
+ those licensors and authors.
627
+
628
+ All other non-permissive additional terms are considered "further
629
+ restrictions" within the meaning of section 10. If the Program as you
630
+ received it, or any part of it, contains a notice stating that it is
631
+ governed by this License along with a term that is a further
632
+ restriction, you may remove that term. If a license document contains
633
+ a further restriction but permits relicensing or conveying under this
634
+ License, you may add to a covered work material governed by the terms
635
+ of that license document, provided that the further restriction does
636
+ not survive such relicensing or conveying.
637
+
638
+ If you add terms to a covered work in accord with this section, you
639
+ must place, in the relevant source files, a statement of the
640
+ additional terms that apply to those files, or a notice indicating
641
+ where to find the applicable terms.
642
+
643
+ Additional terms, permissive or non-permissive, may be stated in the
644
+ form of a separately written license, or stated as exceptions;
645
+ the above requirements apply either way.
646
+
647
+ 8. Termination.
648
+
649
+ You may not propagate or modify a covered work except as expressly
650
+ provided under this License. Any attempt otherwise to propagate or
651
+ modify it is void, and will automatically terminate your rights under
652
+ this License (including any patent licenses granted under the third
653
+ paragraph of section 11).
654
+
655
+ However, if you cease all violation of this License, then your
656
+ license from a particular copyright holder is reinstated (a)
657
+ provisionally, unless and until the copyright holder explicitly and
658
+ finally terminates your license, and (b) permanently, if the copyright
659
+ holder fails to notify you of the violation by some reasonable means
660
+ prior to 60 days after the cessation.
661
+
662
+ Moreover, your license from a particular copyright holder is
663
+ reinstated permanently if the copyright holder notifies you of the
664
+ violation by some reasonable means, this is the first time you have
665
+ received notice of violation of this License (for any work) from that
666
+ copyright holder, and you cure the violation prior to 30 days after
667
+ your receipt of the notice.
668
+
669
+ Termination of your rights under this section does not terminate the
670
+ licenses of parties who have received copies or rights from you under
671
+ this License. If your rights have been terminated and not permanently
672
+ reinstated, you do not qualify to receive new licenses for the same
673
+ material under section 10.
674
+
675
+ 9. Acceptance Not Required for Having Copies.
676
+
677
+ You are not required to accept this License in order to receive or
678
+ run a copy of the Program. Ancillary propagation of a covered work
679
+ occurring solely as a consequence of using peer-to-peer transmission
680
+ to receive a copy likewise does not require acceptance. However,
681
+ nothing other than this License grants you permission to propagate or
682
+ modify any covered work. These actions infringe copyright if you do
683
+ not accept this License. Therefore, by modifying or propagating a
684
+ covered work, you indicate your acceptance of this License to do so.
685
+
686
+ 10. Automatic Licensing of Downstream Recipients.
687
+
688
+ Each time you convey a covered work, the recipient automatically
689
+ receives a license from the original licensors, to run, modify and
690
+ propagate that work, subject to this License. You are not responsible
691
+ for enforcing compliance by third parties with this License.
692
+
693
+ An "entity transaction" is a transaction transferring control of an
694
+ organization, or substantially all assets of one, or subdividing an
695
+ organization, or merging organizations. If propagation of a covered
696
+ work results from an entity transaction, each party to that
697
+ transaction who receives a copy of the work also receives whatever
698
+ licenses to the work the party's predecessor in interest had or could
699
+ give under the previous paragraph, plus a right to possession of the
700
+ Corresponding Source of the work from the predecessor in interest, if
701
+ the predecessor has it or can get it with reasonable efforts.
702
+
703
+ You may not impose any further restrictions on the exercise of the
704
+ rights granted or affirmed under this License. For example, you may
705
+ not impose a license fee, royalty, or other charge for exercise of
706
+ rights granted under this License, and you may not initiate litigation
707
+ (including a cross-claim or counterclaim in a lawsuit) alleging that
708
+ any patent claim is infringed by making, using, selling, offering for
709
+ sale, or importing the Program or any portion of it.
710
+
711
+ 11. Patents.
712
+
713
+ A "contributor" is a copyright holder who authorizes use under this
714
+ License of the Program or a work on which the Program is based. The
715
+ work thus licensed is called the contributor's "contributor version".
716
+
717
+ A contributor's "essential patent claims" are all patent claims
718
+ owned or controlled by the contributor, whether already acquired or
719
+ hereafter acquired, that would be infringed by some manner, permitted
720
+ by this License, of making, using, or selling its contributor version,
721
+ but do not include claims that would be infringed only as a
722
+ consequence of further modification of the contributor version. For
723
+ purposes of this definition, "control" includes the right to grant
724
+ patent sublicenses in a manner consistent with the requirements of
725
+ this License.
726
+
727
+ Each contributor grants you a non-exclusive, worldwide, royalty-free
728
+ patent license under the contributor's essential patent claims, to
729
+ make, use, sell, offer for sale, import and otherwise run, modify and
730
+ propagate the contents of its contributor version.
731
+
732
+ In the following three paragraphs, a "patent license" is any express
733
+ agreement or commitment, however denominated, not to enforce a patent
734
+ (such as an express permission to practice a patent or covenant not to
735
+ sue for patent infringement). To "grant" such a patent license to a
736
+ party means to make such an agreement or commitment not to enforce a
737
+ patent against the party.
738
+
739
+ If you convey a covered work, knowingly relying on a patent license,
740
+ and the Corresponding Source of the work is not available for anyone
741
+ to copy, free of charge and under the terms of this License, through a
742
+ publicly available network server or other readily accessible means,
743
+ then you must either (1) cause the Corresponding Source to be so
744
+ available, or (2) arrange to deprive yourself of the benefit of the
745
+ patent license for this particular work, or (3) arrange, in a manner
746
+ consistent with the requirements of this License, to extend the patent
747
+ license to downstream recipients. "Knowingly relying" means you have
748
+ actual knowledge that, but for the patent license, your conveying the
749
+ covered work in a country, or your recipient's use of the covered work
750
+ in a country, would infringe one or more identifiable patents in that
751
+ country that you have reason to believe are valid.
752
+
753
+ If, pursuant to or in connection with a single transaction or
754
+ arrangement, you convey, or propagate by procuring conveyance of, a
755
+ covered work, and grant a patent license to some of the parties
756
+ receiving the covered work authorizing them to use, propagate, modify
757
+ or convey a specific copy of the covered work, then the patent license
758
+ you grant is automatically extended to all recipients of the covered
759
+ work and works based on it.
760
+
761
+ A patent license is "discriminatory" if it does not include within
762
+ the scope of its coverage, prohibits the exercise of, or is
763
+ conditioned on the non-exercise of one or more of the rights that are
764
+ specifically granted under this License. You may not convey a covered
765
+ work if you are a party to an arrangement with a third party that is
766
+ in the business of distributing software, under which you make payment
767
+ to the third party based on the extent of your activity of conveying
768
+ the work, and under which the third party grants, to any of the
769
+ parties who would receive the covered work from you, a discriminatory
770
+ patent license (a) in connection with copies of the covered work
771
+ conveyed by you (or copies made from those copies), or (b) primarily
772
+ for and in connection with specific products or compilations that
773
+ contain the covered work, unless you entered into that arrangement,
774
+ or that patent license was granted, prior to 28 March 2007.
775
+
776
+ Nothing in this License shall be construed as excluding or limiting
777
+ any implied license or other defenses to infringement that may
778
+ otherwise be available to you under applicable patent law.
779
+
780
+ 12. No Surrender of Others' Freedom.
781
+
782
+ If conditions are imposed on you (whether by court order, agreement or
783
+ otherwise) that contradict the conditions of this License, they do not
784
+ excuse you from the conditions of this License. If you cannot convey a
785
+ covered work so as to satisfy simultaneously your obligations under this
786
+ License and any other pertinent obligations, then as a consequence you may
787
+ not convey it at all. For example, if you agree to terms that obligate you
788
+ to collect a royalty for further conveying from those to whom you convey
789
+ the Program, the only way you could satisfy both those terms and this
790
+ License would be to refrain entirely from conveying the Program.
791
+
792
+ 13. Use with the GNU Affero General Public License.
793
+
794
+ Notwithstanding any other provision of this License, you have
795
+ permission to link or combine any covered work with a work licensed
796
+ under version 3 of the GNU Affero General Public License into a single
797
+ combined work, and to convey the resulting work. The terms of this
798
+ License will continue to apply to the part which is the covered work,
799
+ but the special requirements of the GNU Affero General Public License,
800
+ section 13, concerning interaction through a network will apply to the
801
+ combination as such.
802
+
803
+ 14. Revised Versions of this License.
804
+
805
+ The Free Software Foundation may publish revised and/or new versions of
806
+ the GNU General Public License from time to time. Such new versions will
807
+ be similar in spirit to the present version, but may differ in detail to
808
+ address new problems or concerns.
809
+
810
+ Each version is given a distinguishing version number. If the
811
+ Program specifies that a certain numbered version of the GNU General
812
+ Public License "or any later version" applies to it, you have the
813
+ option of following the terms and conditions either of that numbered
814
+ version or of any later version published by the Free Software
815
+ Foundation. If the Program does not specify a version number of the
816
+ GNU General Public License, you may choose any version ever published
817
+ by the Free Software Foundation.
818
+
819
+ If the Program specifies that a proxy can decide which future
820
+ versions of the GNU General Public License can be used, that proxy's
821
+ public statement of acceptance of a version permanently authorizes you
822
+ to choose that version for the Program.
823
+
824
+ Later license versions may give you additional or different
825
+ permissions. However, no additional obligations are imposed on any
826
+ author or copyright holder as a result of your choosing to follow a
827
+ later version.
828
+
829
+ 15. Disclaimer of Warranty.
830
+
831
+ THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
832
+ APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
833
+ HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
834
+ OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
835
+ THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
836
+ PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
837
+ IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
838
+ ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
839
+
840
+ 16. Limitation of Liability.
841
+
842
+ IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
843
+ WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
844
+ THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
845
+ GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
846
+ USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
847
+ DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
848
+ PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
849
+ EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
850
+ SUCH DAMAGES.
851
+
852
+ 17. Interpretation of Sections 15 and 16.
853
+
854
+ If the disclaimer of warranty and limitation of liability provided
855
+ above cannot be given local legal effect according to their terms,
856
+ reviewing courts shall apply local law that most closely approximates
857
+ an absolute waiver of all civil liability in connection with the
858
+ Program, unless a warranty or assumption of liability accompanies a
859
+ copy of the Program in return for a fee.
860
+
861
+ END OF TERMS AND CONDITIONS
862
+
863
+ How to Apply These Terms to Your New Programs
864
+
865
+ If you develop a new program, and you want it to be of the greatest
866
+ possible use to the public, the best way to achieve this is to make it
867
+ free software which everyone can redistribute and change under these terms.
868
+
869
+ To do so, attach the following notices to the program. It is safest
870
+ to attach them to the start of each source file to most effectively
871
+ state the exclusion of warranty; and each file should have at least
872
+ the "copyright" line and a pointer to where the full notice is found.
873
+
874
+ <one line to give the program's name and a brief idea of what it does.>
875
+ Copyright (C) <year> <name of author>
876
+
877
+ This program is free software: you can redistribute it and/or modify
878
+ it under the terms of the GNU General Public License as published by
879
+ the Free Software Foundation, either version 3 of the License, or
880
+ (at your option) any later version.
881
+
882
+ This program is distributed in the hope that it will be useful,
883
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
884
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
885
+ GNU General Public License for more details.
886
+
887
+ You should have received a copy of the GNU General Public License
888
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
889
+
890
+ Also add information on how to contact you by electronic and paper mail.
891
+
892
+ If the program does terminal interaction, make it output a short
893
+ notice like this when it starts in an interactive mode:
894
+
895
+ <program> Copyright (C) <year> <name of author>
896
+ This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
897
+ This is free software, and you are welcome to redistribute it
898
+ under certain conditions; type `show c' for details.
899
+
900
+ The hypothetical commands `show w' and `show c' should show the appropriate
901
+ parts of the General Public License. Of course, your program's commands
902
+ might be different; for a GUI interface, you would use an "about box".
903
+
904
+ You should also get your employer (if you work as a programmer) or school,
905
+ if any, to sign a "copyright disclaimer" for the program, if necessary.
906
+ For more information on this, and how to apply and follow the GNU GPL, see
907
+ <http://www.gnu.org/licenses/>.
908
+
909
+ The GNU General Public License does not permit incorporating your program
910
+ into proprietary programs. If your program is a subroutine library, you
911
+ may consider it more useful to permit linking proprietary applications with
912
+ the library. If this is what you want to do, use the GNU Lesser General
913
+ Public License instead of this License. But first, please read
914
+ <http://www.gnu.org/philosophy/why-not-lgpl.html>.
915
+
916
+
917
+ Name: libquadmath
918
+ Files: scipy.libs/libquadmath*.so
919
+ Description: dynamically linked to files compiled with gcc
920
+ Availability: https://gcc.gnu.org/git/?p=gcc.git;a=tree;f=libquadmath
921
+ License: LGPL-2.1-or-later
922
+
923
+ GCC Quad-Precision Math Library
924
+ Copyright (C) 2010-2019 Free Software Foundation, Inc.
925
+ Written by Francois-Xavier Coudert <fxcoudert@gcc.gnu.org>
926
+
927
+ This file is part of the libquadmath library.
928
+ Libquadmath is free software; you can redistribute it and/or
929
+ modify it under the terms of the GNU Library General Public
930
+ License as published by the Free Software Foundation; either
931
+ version 2.1 of the License, or (at your option) any later version.
932
+
933
+ Libquadmath is distributed in the hope that it will be useful,
934
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
935
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
936
+ Lesser General Public License for more details.
937
+ https://www.gnu.org/licenses/old-licenses/lgpl-2.1.html
.venv/lib/python3.12/site-packages/scipy-1.18.1.dist-info/METADATA ADDED
@@ -0,0 +1,1092 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Metadata-Version: 2.1
2
+ Name: scipy
3
+ Version: 1.18.1
4
+ Summary: Fundamental algorithms for scientific computing in Python
5
+ Maintainer-Email: SciPy Developers <scipy-dev@python.org>
6
+ License: Copyright (c) 2001-2002 Enthought, Inc. 2003, SciPy Developers.
7
+ All rights reserved.
8
+
9
+ Redistribution and use in source and binary forms, with or without
10
+ modification, are permitted provided that the following conditions
11
+ are met:
12
+
13
+ 1. Redistributions of source code must retain the above copyright
14
+ notice, this list of conditions and the following disclaimer.
15
+
16
+ 2. Redistributions in binary form must reproduce the above
17
+ copyright notice, this list of conditions and the following
18
+ disclaimer in the documentation and/or other materials provided
19
+ with the distribution.
20
+
21
+ 3. Neither the name of the copyright holder nor the names of its
22
+ contributors may be used to endorse or promote products derived
23
+ from this software without specific prior written permission.
24
+
25
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36
+
37
+ ----
38
+
39
+
40
+ ----
41
+
42
+ This binary distribution of SciPy can also bundle the following software
43
+ (depending on the build):
44
+
45
+
46
+ Name: OpenBLAS
47
+ Files: scipy.libs/libscipy_openblas*.so
48
+ Description: bundled as a dynamically linked library
49
+ Availability: https://github.com/OpenMathLib/OpenBLAS/
50
+ License: BSD-3-Clause
51
+ Copyright (c) 2011-2014, The OpenBLAS Project
52
+ All rights reserved.
53
+
54
+ Redistribution and use in source and binary forms, with or without
55
+ modification, are permitted provided that the following conditions are
56
+ met:
57
+
58
+ 1. Redistributions of source code must retain the above copyright
59
+ notice, this list of conditions and the following disclaimer.
60
+
61
+ 2. Redistributions in binary form must reproduce the above copyright
62
+ notice, this list of conditions and the following disclaimer in
63
+ the documentation and/or other materials provided with the
64
+ distribution.
65
+ 3. Neither the name of the OpenBLAS project nor the names of
66
+ its contributors may be used to endorse or promote products
67
+ derived from this software without specific prior written
68
+ permission.
69
+
70
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
71
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
72
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
73
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
74
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
75
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
76
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
77
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
78
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
79
+ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
80
+
81
+
82
+ Name: LAPACK
83
+ Files: scipy.libs/libscipy_openblas*.so
84
+ Description: bundled in OpenBLAS
85
+ Availability: https://github.com/OpenMathLib/OpenBLAS/
86
+ License: BSD-3-Clause-Open-MPI
87
+ Copyright (c) 1992-2013 The University of Tennessee and The University
88
+ of Tennessee Research Foundation. All rights
89
+ reserved.
90
+ Copyright (c) 2000-2013 The University of California Berkeley. All
91
+ rights reserved.
92
+ Copyright (c) 2006-2013 The University of Colorado Denver. All rights
93
+ reserved.
94
+
95
+ $COPYRIGHT$
96
+
97
+ Additional copyrights may follow
98
+
99
+ $HEADER$
100
+
101
+ Redistribution and use in source and binary forms, with or without
102
+ modification, are permitted provided that the following conditions are
103
+ met:
104
+
105
+ - Redistributions of source code must retain the above copyright
106
+ notice, this list of conditions and the following disclaimer.
107
+
108
+ - Redistributions in binary form must reproduce the above copyright
109
+ notice, this list of conditions and the following disclaimer listed
110
+ in this license in the documentation and/or other materials
111
+ provided with the distribution.
112
+
113
+ - Neither the name of the copyright holders nor the names of its
114
+ contributors may be used to endorse or promote products derived from
115
+ this software without specific prior written permission.
116
+
117
+ The copyright holders provide no reassurances that the source code
118
+ provided does not infringe any patent, copyright, or any other
119
+ intellectual property rights of third parties. The copyright holders
120
+ disclaim any liability to any recipient for claims brought against
121
+ recipient by any third party for infringement of that parties
122
+ intellectual property rights.
123
+
124
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
125
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
126
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
127
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
128
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
129
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
130
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
131
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
132
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
133
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
134
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
135
+
136
+
137
+ Name: GCC runtime library
138
+ Files: scipy.libs/libgfortran*.so
139
+ Description: dynamically linked to files compiled with gcc
140
+ Availability: https://gcc.gnu.org/git/?p=gcc.git;a=tree;f=libgfortran
141
+ License: GPL-3.0-or-later WITH GCC-exception-3.1
142
+ Copyright (C) 2002-2017 Free Software Foundation, Inc.
143
+
144
+ Libgfortran is free software; you can redistribute it and/or modify
145
+ it under the terms of the GNU General Public License as published by
146
+ the Free Software Foundation; either version 3, or (at your option)
147
+ any later version.
148
+
149
+ Libgfortran is distributed in the hope that it will be useful,
150
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
151
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
152
+ GNU General Public License for more details.
153
+
154
+ Under Section 7 of GPL version 3, you are granted additional
155
+ permissions described in the GCC Runtime Library Exception, version
156
+ 3.1, as published by the Free Software Foundation.
157
+
158
+ You should have received a copy of the GNU General Public License and
159
+ a copy of the GCC Runtime Library Exception along with this program;
160
+ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
161
+ <http://www.gnu.org/licenses/>.
162
+
163
+ ----
164
+
165
+ Full text of license texts referred to above follows (that they are
166
+ listed below does not necessarily imply the conditions apply to the
167
+ present binary release):
168
+
169
+ ----
170
+
171
+ GCC RUNTIME LIBRARY EXCEPTION
172
+
173
+ Version 3.1, 31 March 2009
174
+
175
+ Copyright (C) 2009 Free Software Foundation, Inc. <http://fsf.org/>
176
+
177
+ Everyone is permitted to copy and distribute verbatim copies of this
178
+ license document, but changing it is not allowed.
179
+
180
+ This GCC Runtime Library Exception ("Exception") is an additional
181
+ permission under section 7 of the GNU General Public License, version
182
+ 3 ("GPLv3"). It applies to a given file (the "Runtime Library") that
183
+ bears a notice placed by the copyright holder of the file stating that
184
+ the file is governed by GPLv3 along with this Exception.
185
+
186
+ When you use GCC to compile a program, GCC may combine portions of
187
+ certain GCC header files and runtime libraries with the compiled
188
+ program. The purpose of this Exception is to allow compilation of
189
+ non-GPL (including proprietary) programs to use, in this way, the
190
+ header files and runtime libraries covered by this Exception.
191
+
192
+ 0. Definitions.
193
+
194
+ A file is an "Independent Module" if it either requires the Runtime
195
+ Library for execution after a Compilation Process, or makes use of an
196
+ interface provided by the Runtime Library, but is not otherwise based
197
+ on the Runtime Library.
198
+
199
+ "GCC" means a version of the GNU Compiler Collection, with or without
200
+ modifications, governed by version 3 (or a specified later version) of
201
+ the GNU General Public License (GPL) with the option of using any
202
+ subsequent versions published by the FSF.
203
+
204
+ "GPL-compatible Software" is software whose conditions of propagation,
205
+ modification and use would permit combination with GCC in accord with
206
+ the license of GCC.
207
+
208
+ "Target Code" refers to output from any compiler for a real or virtual
209
+ target processor architecture, in executable form or suitable for
210
+ input to an assembler, loader, linker and/or execution
211
+ phase. Notwithstanding that, Target Code does not include data in any
212
+ format that is used as a compiler intermediate representation, or used
213
+ for producing a compiler intermediate representation.
214
+
215
+ The "Compilation Process" transforms code entirely represented in
216
+ non-intermediate languages designed for human-written code, and/or in
217
+ Java Virtual Machine byte code, into Target Code. Thus, for example,
218
+ use of source code generators and preprocessors need not be considered
219
+ part of the Compilation Process, since the Compilation Process can be
220
+ understood as starting with the output of the generators or
221
+ preprocessors.
222
+
223
+ A Compilation Process is "Eligible" if it is done using GCC, alone or
224
+ with other GPL-compatible software, or if it is done without using any
225
+ work based on GCC. For example, using non-GPL-compatible Software to
226
+ optimize any GCC intermediate representations would not qualify as an
227
+ Eligible Compilation Process.
228
+
229
+ 1. Grant of Additional Permission.
230
+
231
+ You have permission to propagate a work of Target Code formed by
232
+ combining the Runtime Library with Independent Modules, even if such
233
+ propagation would otherwise violate the terms of GPLv3, provided that
234
+ all Target Code was generated by Eligible Compilation Processes. You
235
+ may then convey such a combination under terms of your choice,
236
+ consistent with the licensing of the Independent Modules.
237
+
238
+ 2. No Weakening of GCC Copyleft.
239
+
240
+ The availability of this Exception does not imply any general
241
+ presumption that third-party software is unaffected by the copyleft
242
+ requirements of the license of GCC.
243
+
244
+ ----
245
+
246
+ GNU GENERAL PUBLIC LICENSE
247
+ Version 3, 29 June 2007
248
+
249
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
250
+ Everyone is permitted to copy and distribute verbatim copies
251
+ of this license document, but changing it is not allowed.
252
+
253
+ Preamble
254
+
255
+ The GNU General Public License is a free, copyleft license for
256
+ software and other kinds of works.
257
+
258
+ The licenses for most software and other practical works are designed
259
+ to take away your freedom to share and change the works. By contrast,
260
+ the GNU General Public License is intended to guarantee your freedom to
261
+ share and change all versions of a program--to make sure it remains free
262
+ software for all its users. We, the Free Software Foundation, use the
263
+ GNU General Public License for most of our software; it applies also to
264
+ any other work released this way by its authors. You can apply it to
265
+ your programs, too.
266
+
267
+ When we speak of free software, we are referring to freedom, not
268
+ price. Our General Public Licenses are designed to make sure that you
269
+ have the freedom to distribute copies of free software (and charge for
270
+ them if you wish), that you receive source code or can get it if you
271
+ want it, that you can change the software or use pieces of it in new
272
+ free programs, and that you know you can do these things.
273
+
274
+ To protect your rights, we need to prevent others from denying you
275
+ these rights or asking you to surrender the rights. Therefore, you have
276
+ certain responsibilities if you distribute copies of the software, or if
277
+ you modify it: responsibilities to respect the freedom of others.
278
+
279
+ For example, if you distribute copies of such a program, whether
280
+ gratis or for a fee, you must pass on to the recipients the same
281
+ freedoms that you received. You must make sure that they, too, receive
282
+ or can get the source code. And you must show them these terms so they
283
+ know their rights.
284
+
285
+ Developers that use the GNU GPL protect your rights with two steps:
286
+ (1) assert copyright on the software, and (2) offer you this License
287
+ giving you legal permission to copy, distribute and/or modify it.
288
+
289
+ For the developers' and authors' protection, the GPL clearly explains
290
+ that there is no warranty for this free software. For both users' and
291
+ authors' sake, the GPL requires that modified versions be marked as
292
+ changed, so that their problems will not be attributed erroneously to
293
+ authors of previous versions.
294
+
295
+ Some devices are designed to deny users access to install or run
296
+ modified versions of the software inside them, although the manufacturer
297
+ can do so. This is fundamentally incompatible with the aim of
298
+ protecting users' freedom to change the software. The systematic
299
+ pattern of such abuse occurs in the area of products for individuals to
300
+ use, which is precisely where it is most unacceptable. Therefore, we
301
+ have designed this version of the GPL to prohibit the practice for those
302
+ products. If such problems arise substantially in other domains, we
303
+ stand ready to extend this provision to those domains in future versions
304
+ of the GPL, as needed to protect the freedom of users.
305
+
306
+ Finally, every program is threatened constantly by software patents.
307
+ States should not allow patents to restrict development and use of
308
+ software on general-purpose computers, but in those that do, we wish to
309
+ avoid the special danger that patents applied to a free program could
310
+ make it effectively proprietary. To prevent this, the GPL assures that
311
+ patents cannot be used to render the program non-free.
312
+
313
+ The precise terms and conditions for copying, distribution and
314
+ modification follow.
315
+
316
+ TERMS AND CONDITIONS
317
+
318
+ 0. Definitions.
319
+
320
+ "This License" refers to version 3 of the GNU General Public License.
321
+
322
+ "Copyright" also means copyright-like laws that apply to other kinds of
323
+ works, such as semiconductor masks.
324
+
325
+ "The Program" refers to any copyrightable work licensed under this
326
+ License. Each licensee is addressed as "you". "Licensees" and
327
+ "recipients" may be individuals or organizations.
328
+
329
+ To "modify" a work means to copy from or adapt all or part of the work
330
+ in a fashion requiring copyright permission, other than the making of an
331
+ exact copy. The resulting work is called a "modified version" of the
332
+ earlier work or a work "based on" the earlier work.
333
+
334
+ A "covered work" means either the unmodified Program or a work based
335
+ on the Program.
336
+
337
+ To "propagate" a work means to do anything with it that, without
338
+ permission, would make you directly or secondarily liable for
339
+ infringement under applicable copyright law, except executing it on a
340
+ computer or modifying a private copy. Propagation includes copying,
341
+ distribution (with or without modification), making available to the
342
+ public, and in some countries other activities as well.
343
+
344
+ To "convey" a work means any kind of propagation that enables other
345
+ parties to make or receive copies. Mere interaction with a user through
346
+ a computer network, with no transfer of a copy, is not conveying.
347
+
348
+ An interactive user interface displays "Appropriate Legal Notices"
349
+ to the extent that it includes a convenient and prominently visible
350
+ feature that (1) displays an appropriate copyright notice, and (2)
351
+ tells the user that there is no warranty for the work (except to the
352
+ extent that warranties are provided), that licensees may convey the
353
+ work under this License, and how to view a copy of this License. If
354
+ the interface presents a list of user commands or options, such as a
355
+ menu, a prominent item in the list meets this criterion.
356
+
357
+ 1. Source Code.
358
+
359
+ The "source code" for a work means the preferred form of the work
360
+ for making modifications to it. "Object code" means any non-source
361
+ form of a work.
362
+
363
+ A "Standard Interface" means an interface that either is an official
364
+ standard defined by a recognized standards body, or, in the case of
365
+ interfaces specified for a particular programming language, one that
366
+ is widely used among developers working in that language.
367
+
368
+ The "System Libraries" of an executable work include anything, other
369
+ than the work as a whole, that (a) is included in the normal form of
370
+ packaging a Major Component, but which is not part of that Major
371
+ Component, and (b) serves only to enable use of the work with that
372
+ Major Component, or to implement a Standard Interface for which an
373
+ implementation is available to the public in source code form. A
374
+ "Major Component", in this context, means a major essential component
375
+ (kernel, window system, and so on) of the specific operating system
376
+ (if any) on which the executable work runs, or a compiler used to
377
+ produce the work, or an object code interpreter used to run it.
378
+
379
+ The "Corresponding Source" for a work in object code form means all
380
+ the source code needed to generate, install, and (for an executable
381
+ work) run the object code and to modify the work, including scripts to
382
+ control those activities. However, it does not include the work's
383
+ System Libraries, or general-purpose tools or generally available free
384
+ programs which are used unmodified in performing those activities but
385
+ which are not part of the work. For example, Corresponding Source
386
+ includes interface definition files associated with source files for
387
+ the work, and the source code for shared libraries and dynamically
388
+ linked subprograms that the work is specifically designed to require,
389
+ such as by intimate data communication or control flow between those
390
+ subprograms and other parts of the work.
391
+
392
+ The Corresponding Source need not include anything that users
393
+ can regenerate automatically from other parts of the Corresponding
394
+ Source.
395
+
396
+ The Corresponding Source for a work in source code form is that
397
+ same work.
398
+
399
+ 2. Basic Permissions.
400
+
401
+ All rights granted under this License are granted for the term of
402
+ copyright on the Program, and are irrevocable provided the stated
403
+ conditions are met. This License explicitly affirms your unlimited
404
+ permission to run the unmodified Program. The output from running a
405
+ covered work is covered by this License only if the output, given its
406
+ content, constitutes a covered work. This License acknowledges your
407
+ rights of fair use or other equivalent, as provided by copyright law.
408
+
409
+ You may make, run and propagate covered works that you do not
410
+ convey, without conditions so long as your license otherwise remains
411
+ in force. You may convey covered works to others for the sole purpose
412
+ of having them make modifications exclusively for you, or provide you
413
+ with facilities for running those works, provided that you comply with
414
+ the terms of this License in conveying all material for which you do
415
+ not control copyright. Those thus making or running the covered works
416
+ for you must do so exclusively on your behalf, under your direction
417
+ and control, on terms that prohibit them from making any copies of
418
+ your copyrighted material outside their relationship with you.
419
+
420
+ Conveying under any other circumstances is permitted solely under
421
+ the conditions stated below. Sublicensing is not allowed; section 10
422
+ makes it unnecessary.
423
+
424
+ 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
425
+
426
+ No covered work shall be deemed part of an effective technological
427
+ measure under any applicable law fulfilling obligations under article
428
+ 11 of the WIPO copyright treaty adopted on 20 December 1996, or
429
+ similar laws prohibiting or restricting circumvention of such
430
+ measures.
431
+
432
+ When you convey a covered work, you waive any legal power to forbid
433
+ circumvention of technological measures to the extent such circumvention
434
+ is effected by exercising rights under this License with respect to
435
+ the covered work, and you disclaim any intention to limit operation or
436
+ modification of the work as a means of enforcing, against the work's
437
+ users, your or third parties' legal rights to forbid circumvention of
438
+ technological measures.
439
+
440
+ 4. Conveying Verbatim Copies.
441
+
442
+ You may convey verbatim copies of the Program's source code as you
443
+ receive it, in any medium, provided that you conspicuously and
444
+ appropriately publish on each copy an appropriate copyright notice;
445
+ keep intact all notices stating that this License and any
446
+ non-permissive terms added in accord with section 7 apply to the code;
447
+ keep intact all notices of the absence of any warranty; and give all
448
+ recipients a copy of this License along with the Program.
449
+
450
+ You may charge any price or no price for each copy that you convey,
451
+ and you may offer support or warranty protection for a fee.
452
+
453
+ 5. Conveying Modified Source Versions.
454
+
455
+ You may convey a work based on the Program, or the modifications to
456
+ produce it from the Program, in the form of source code under the
457
+ terms of section 4, provided that you also meet all of these conditions:
458
+
459
+ a) The work must carry prominent notices stating that you modified
460
+ it, and giving a relevant date.
461
+
462
+ b) The work must carry prominent notices stating that it is
463
+ released under this License and any conditions added under section
464
+ 7. This requirement modifies the requirement in section 4 to
465
+ "keep intact all notices".
466
+
467
+ c) You must license the entire work, as a whole, under this
468
+ License to anyone who comes into possession of a copy. This
469
+ License will therefore apply, along with any applicable section 7
470
+ additional terms, to the whole of the work, and all its parts,
471
+ regardless of how they are packaged. This License gives no
472
+ permission to license the work in any other way, but it does not
473
+ invalidate such permission if you have separately received it.
474
+
475
+ d) If the work has interactive user interfaces, each must display
476
+ Appropriate Legal Notices; however, if the Program has interactive
477
+ interfaces that do not display Appropriate Legal Notices, your
478
+ work need not make them do so.
479
+
480
+ A compilation of a covered work with other separate and independent
481
+ works, which are not by their nature extensions of the covered work,
482
+ and which are not combined with it such as to form a larger program,
483
+ in or on a volume of a storage or distribution medium, is called an
484
+ "aggregate" if the compilation and its resulting copyright are not
485
+ used to limit the access or legal rights of the compilation's users
486
+ beyond what the individual works permit. Inclusion of a covered work
487
+ in an aggregate does not cause this License to apply to the other
488
+ parts of the aggregate.
489
+
490
+ 6. Conveying Non-Source Forms.
491
+
492
+ You may convey a covered work in object code form under the terms
493
+ of sections 4 and 5, provided that you also convey the
494
+ machine-readable Corresponding Source under the terms of this License,
495
+ in one of these ways:
496
+
497
+ a) Convey the object code in, or embodied in, a physical product
498
+ (including a physical distribution medium), accompanied by the
499
+ Corresponding Source fixed on a durable physical medium
500
+ customarily used for software interchange.
501
+
502
+ b) Convey the object code in, or embodied in, a physical product
503
+ (including a physical distribution medium), accompanied by a
504
+ written offer, valid for at least three years and valid for as
505
+ long as you offer spare parts or customer support for that product
506
+ model, to give anyone who possesses the object code either (1) a
507
+ copy of the Corresponding Source for all the software in the
508
+ product that is covered by this License, on a durable physical
509
+ medium customarily used for software interchange, for a price no
510
+ more than your reasonable cost of physically performing this
511
+ conveying of source, or (2) access to copy the
512
+ Corresponding Source from a network server at no charge.
513
+
514
+ c) Convey individual copies of the object code with a copy of the
515
+ written offer to provide the Corresponding Source. This
516
+ alternative is allowed only occasionally and noncommercially, and
517
+ only if you received the object code with such an offer, in accord
518
+ with subsection 6b.
519
+
520
+ d) Convey the object code by offering access from a designated
521
+ place (gratis or for a charge), and offer equivalent access to the
522
+ Corresponding Source in the same way through the same place at no
523
+ further charge. You need not require recipients to copy the
524
+ Corresponding Source along with the object code. If the place to
525
+ copy the object code is a network server, the Corresponding Source
526
+ may be on a different server (operated by you or a third party)
527
+ that supports equivalent copying facilities, provided you maintain
528
+ clear directions next to the object code saying where to find the
529
+ Corresponding Source. Regardless of what server hosts the
530
+ Corresponding Source, you remain obligated to ensure that it is
531
+ available for as long as needed to satisfy these requirements.
532
+
533
+ e) Convey the object code using peer-to-peer transmission, provided
534
+ you inform other peers where the object code and Corresponding
535
+ Source of the work are being offered to the general public at no
536
+ charge under subsection 6d.
537
+
538
+ A separable portion of the object code, whose source code is excluded
539
+ from the Corresponding Source as a System Library, need not be
540
+ included in conveying the object code work.
541
+
542
+ A "User Product" is either (1) a "consumer product", which means any
543
+ tangible personal property which is normally used for personal, family,
544
+ or household purposes, or (2) anything designed or sold for incorporation
545
+ into a dwelling. In determining whether a product is a consumer product,
546
+ doubtful cases shall be resolved in favor of coverage. For a particular
547
+ product received by a particular user, "normally used" refers to a
548
+ typical or common use of that class of product, regardless of the status
549
+ of the particular user or of the way in which the particular user
550
+ actually uses, or expects or is expected to use, the product. A product
551
+ is a consumer product regardless of whether the product has substantial
552
+ commercial, industrial or non-consumer uses, unless such uses represent
553
+ the only significant mode of use of the product.
554
+
555
+ "Installation Information" for a User Product means any methods,
556
+ procedures, authorization keys, or other information required to install
557
+ and execute modified versions of a covered work in that User Product from
558
+ a modified version of its Corresponding Source. The information must
559
+ suffice to ensure that the continued functioning of the modified object
560
+ code is in no case prevented or interfered with solely because
561
+ modification has been made.
562
+
563
+ If you convey an object code work under this section in, or with, or
564
+ specifically for use in, a User Product, and the conveying occurs as
565
+ part of a transaction in which the right of possession and use of the
566
+ User Product is transferred to the recipient in perpetuity or for a
567
+ fixed term (regardless of how the transaction is characterized), the
568
+ Corresponding Source conveyed under this section must be accompanied
569
+ by the Installation Information. But this requirement does not apply
570
+ if neither you nor any third party retains the ability to install
571
+ modified object code on the User Product (for example, the work has
572
+ been installed in ROM).
573
+
574
+ The requirement to provide Installation Information does not include a
575
+ requirement to continue to provide support service, warranty, or updates
576
+ for a work that has been modified or installed by the recipient, or for
577
+ the User Product in which it has been modified or installed. Access to a
578
+ network may be denied when the modification itself materially and
579
+ adversely affects the operation of the network or violates the rules and
580
+ protocols for communication across the network.
581
+
582
+ Corresponding Source conveyed, and Installation Information provided,
583
+ in accord with this section must be in a format that is publicly
584
+ documented (and with an implementation available to the public in
585
+ source code form), and must require no special password or key for
586
+ unpacking, reading or copying.
587
+
588
+ 7. Additional Terms.
589
+
590
+ "Additional permissions" are terms that supplement the terms of this
591
+ License by making exceptions from one or more of its conditions.
592
+ Additional permissions that are applicable to the entire Program shall
593
+ be treated as though they were included in this License, to the extent
594
+ that they are valid under applicable law. If additional permissions
595
+ apply only to part of the Program, that part may be used separately
596
+ under those permissions, but the entire Program remains governed by
597
+ this License without regard to the additional permissions.
598
+
599
+ When you convey a copy of a covered work, you may at your option
600
+ remove any additional permissions from that copy, or from any part of
601
+ it. (Additional permissions may be written to require their own
602
+ removal in certain cases when you modify the work.) You may place
603
+ additional permissions on material, added by you to a covered work,
604
+ for which you have or can give appropriate copyright permission.
605
+
606
+ Notwithstanding any other provision of this License, for material you
607
+ add to a covered work, you may (if authorized by the copyright holders of
608
+ that material) supplement the terms of this License with terms:
609
+
610
+ a) Disclaiming warranty or limiting liability differently from the
611
+ terms of sections 15 and 16 of this License; or
612
+
613
+ b) Requiring preservation of specified reasonable legal notices or
614
+ author attributions in that material or in the Appropriate Legal
615
+ Notices displayed by works containing it; or
616
+
617
+ c) Prohibiting misrepresentation of the origin of that material, or
618
+ requiring that modified versions of such material be marked in
619
+ reasonable ways as different from the original version; or
620
+
621
+ d) Limiting the use for publicity purposes of names of licensors or
622
+ authors of the material; or
623
+
624
+ e) Declining to grant rights under trademark law for use of some
625
+ trade names, trademarks, or service marks; or
626
+
627
+ f) Requiring indemnification of licensors and authors of that
628
+ material by anyone who conveys the material (or modified versions of
629
+ it) with contractual assumptions of liability to the recipient, for
630
+ any liability that these contractual assumptions directly impose on
631
+ those licensors and authors.
632
+
633
+ All other non-permissive additional terms are considered "further
634
+ restrictions" within the meaning of section 10. If the Program as you
635
+ received it, or any part of it, contains a notice stating that it is
636
+ governed by this License along with a term that is a further
637
+ restriction, you may remove that term. If a license document contains
638
+ a further restriction but permits relicensing or conveying under this
639
+ License, you may add to a covered work material governed by the terms
640
+ of that license document, provided that the further restriction does
641
+ not survive such relicensing or conveying.
642
+
643
+ If you add terms to a covered work in accord with this section, you
644
+ must place, in the relevant source files, a statement of the
645
+ additional terms that apply to those files, or a notice indicating
646
+ where to find the applicable terms.
647
+
648
+ Additional terms, permissive or non-permissive, may be stated in the
649
+ form of a separately written license, or stated as exceptions;
650
+ the above requirements apply either way.
651
+
652
+ 8. Termination.
653
+
654
+ You may not propagate or modify a covered work except as expressly
655
+ provided under this License. Any attempt otherwise to propagate or
656
+ modify it is void, and will automatically terminate your rights under
657
+ this License (including any patent licenses granted under the third
658
+ paragraph of section 11).
659
+
660
+ However, if you cease all violation of this License, then your
661
+ license from a particular copyright holder is reinstated (a)
662
+ provisionally, unless and until the copyright holder explicitly and
663
+ finally terminates your license, and (b) permanently, if the copyright
664
+ holder fails to notify you of the violation by some reasonable means
665
+ prior to 60 days after the cessation.
666
+
667
+ Moreover, your license from a particular copyright holder is
668
+ reinstated permanently if the copyright holder notifies you of the
669
+ violation by some reasonable means, this is the first time you have
670
+ received notice of violation of this License (for any work) from that
671
+ copyright holder, and you cure the violation prior to 30 days after
672
+ your receipt of the notice.
673
+
674
+ Termination of your rights under this section does not terminate the
675
+ licenses of parties who have received copies or rights from you under
676
+ this License. If your rights have been terminated and not permanently
677
+ reinstated, you do not qualify to receive new licenses for the same
678
+ material under section 10.
679
+
680
+ 9. Acceptance Not Required for Having Copies.
681
+
682
+ You are not required to accept this License in order to receive or
683
+ run a copy of the Program. Ancillary propagation of a covered work
684
+ occurring solely as a consequence of using peer-to-peer transmission
685
+ to receive a copy likewise does not require acceptance. However,
686
+ nothing other than this License grants you permission to propagate or
687
+ modify any covered work. These actions infringe copyright if you do
688
+ not accept this License. Therefore, by modifying or propagating a
689
+ covered work, you indicate your acceptance of this License to do so.
690
+
691
+ 10. Automatic Licensing of Downstream Recipients.
692
+
693
+ Each time you convey a covered work, the recipient automatically
694
+ receives a license from the original licensors, to run, modify and
695
+ propagate that work, subject to this License. You are not responsible
696
+ for enforcing compliance by third parties with this License.
697
+
698
+ An "entity transaction" is a transaction transferring control of an
699
+ organization, or substantially all assets of one, or subdividing an
700
+ organization, or merging organizations. If propagation of a covered
701
+ work results from an entity transaction, each party to that
702
+ transaction who receives a copy of the work also receives whatever
703
+ licenses to the work the party's predecessor in interest had or could
704
+ give under the previous paragraph, plus a right to possession of the
705
+ Corresponding Source of the work from the predecessor in interest, if
706
+ the predecessor has it or can get it with reasonable efforts.
707
+
708
+ You may not impose any further restrictions on the exercise of the
709
+ rights granted or affirmed under this License. For example, you may
710
+ not impose a license fee, royalty, or other charge for exercise of
711
+ rights granted under this License, and you may not initiate litigation
712
+ (including a cross-claim or counterclaim in a lawsuit) alleging that
713
+ any patent claim is infringed by making, using, selling, offering for
714
+ sale, or importing the Program or any portion of it.
715
+
716
+ 11. Patents.
717
+
718
+ A "contributor" is a copyright holder who authorizes use under this
719
+ License of the Program or a work on which the Program is based. The
720
+ work thus licensed is called the contributor's "contributor version".
721
+
722
+ A contributor's "essential patent claims" are all patent claims
723
+ owned or controlled by the contributor, whether already acquired or
724
+ hereafter acquired, that would be infringed by some manner, permitted
725
+ by this License, of making, using, or selling its contributor version,
726
+ but do not include claims that would be infringed only as a
727
+ consequence of further modification of the contributor version. For
728
+ purposes of this definition, "control" includes the right to grant
729
+ patent sublicenses in a manner consistent with the requirements of
730
+ this License.
731
+
732
+ Each contributor grants you a non-exclusive, worldwide, royalty-free
733
+ patent license under the contributor's essential patent claims, to
734
+ make, use, sell, offer for sale, import and otherwise run, modify and
735
+ propagate the contents of its contributor version.
736
+
737
+ In the following three paragraphs, a "patent license" is any express
738
+ agreement or commitment, however denominated, not to enforce a patent
739
+ (such as an express permission to practice a patent or covenant not to
740
+ sue for patent infringement). To "grant" such a patent license to a
741
+ party means to make such an agreement or commitment not to enforce a
742
+ patent against the party.
743
+
744
+ If you convey a covered work, knowingly relying on a patent license,
745
+ and the Corresponding Source of the work is not available for anyone
746
+ to copy, free of charge and under the terms of this License, through a
747
+ publicly available network server or other readily accessible means,
748
+ then you must either (1) cause the Corresponding Source to be so
749
+ available, or (2) arrange to deprive yourself of the benefit of the
750
+ patent license for this particular work, or (3) arrange, in a manner
751
+ consistent with the requirements of this License, to extend the patent
752
+ license to downstream recipients. "Knowingly relying" means you have
753
+ actual knowledge that, but for the patent license, your conveying the
754
+ covered work in a country, or your recipient's use of the covered work
755
+ in a country, would infringe one or more identifiable patents in that
756
+ country that you have reason to believe are valid.
757
+
758
+ If, pursuant to or in connection with a single transaction or
759
+ arrangement, you convey, or propagate by procuring conveyance of, a
760
+ covered work, and grant a patent license to some of the parties
761
+ receiving the covered work authorizing them to use, propagate, modify
762
+ or convey a specific copy of the covered work, then the patent license
763
+ you grant is automatically extended to all recipients of the covered
764
+ work and works based on it.
765
+
766
+ A patent license is "discriminatory" if it does not include within
767
+ the scope of its coverage, prohibits the exercise of, or is
768
+ conditioned on the non-exercise of one or more of the rights that are
769
+ specifically granted under this License. You may not convey a covered
770
+ work if you are a party to an arrangement with a third party that is
771
+ in the business of distributing software, under which you make payment
772
+ to the third party based on the extent of your activity of conveying
773
+ the work, and under which the third party grants, to any of the
774
+ parties who would receive the covered work from you, a discriminatory
775
+ patent license (a) in connection with copies of the covered work
776
+ conveyed by you (or copies made from those copies), or (b) primarily
777
+ for and in connection with specific products or compilations that
778
+ contain the covered work, unless you entered into that arrangement,
779
+ or that patent license was granted, prior to 28 March 2007.
780
+
781
+ Nothing in this License shall be construed as excluding or limiting
782
+ any implied license or other defenses to infringement that may
783
+ otherwise be available to you under applicable patent law.
784
+
785
+ 12. No Surrender of Others' Freedom.
786
+
787
+ If conditions are imposed on you (whether by court order, agreement or
788
+ otherwise) that contradict the conditions of this License, they do not
789
+ excuse you from the conditions of this License. If you cannot convey a
790
+ covered work so as to satisfy simultaneously your obligations under this
791
+ License and any other pertinent obligations, then as a consequence you may
792
+ not convey it at all. For example, if you agree to terms that obligate you
793
+ to collect a royalty for further conveying from those to whom you convey
794
+ the Program, the only way you could satisfy both those terms and this
795
+ License would be to refrain entirely from conveying the Program.
796
+
797
+ 13. Use with the GNU Affero General Public License.
798
+
799
+ Notwithstanding any other provision of this License, you have
800
+ permission to link or combine any covered work with a work licensed
801
+ under version 3 of the GNU Affero General Public License into a single
802
+ combined work, and to convey the resulting work. The terms of this
803
+ License will continue to apply to the part which is the covered work,
804
+ but the special requirements of the GNU Affero General Public License,
805
+ section 13, concerning interaction through a network will apply to the
806
+ combination as such.
807
+
808
+ 14. Revised Versions of this License.
809
+
810
+ The Free Software Foundation may publish revised and/or new versions of
811
+ the GNU General Public License from time to time. Such new versions will
812
+ be similar in spirit to the present version, but may differ in detail to
813
+ address new problems or concerns.
814
+
815
+ Each version is given a distinguishing version number. If the
816
+ Program specifies that a certain numbered version of the GNU General
817
+ Public License "or any later version" applies to it, you have the
818
+ option of following the terms and conditions either of that numbered
819
+ version or of any later version published by the Free Software
820
+ Foundation. If the Program does not specify a version number of the
821
+ GNU General Public License, you may choose any version ever published
822
+ by the Free Software Foundation.
823
+
824
+ If the Program specifies that a proxy can decide which future
825
+ versions of the GNU General Public License can be used, that proxy's
826
+ public statement of acceptance of a version permanently authorizes you
827
+ to choose that version for the Program.
828
+
829
+ Later license versions may give you additional or different
830
+ permissions. However, no additional obligations are imposed on any
831
+ author or copyright holder as a result of your choosing to follow a
832
+ later version.
833
+
834
+ 15. Disclaimer of Warranty.
835
+
836
+ THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
837
+ APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
838
+ HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
839
+ OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
840
+ THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
841
+ PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
842
+ IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
843
+ ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
844
+
845
+ 16. Limitation of Liability.
846
+
847
+ IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
848
+ WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
849
+ THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
850
+ GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
851
+ USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
852
+ DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
853
+ PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
854
+ EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
855
+ SUCH DAMAGES.
856
+
857
+ 17. Interpretation of Sections 15 and 16.
858
+
859
+ If the disclaimer of warranty and limitation of liability provided
860
+ above cannot be given local legal effect according to their terms,
861
+ reviewing courts shall apply local law that most closely approximates
862
+ an absolute waiver of all civil liability in connection with the
863
+ Program, unless a warranty or assumption of liability accompanies a
864
+ copy of the Program in return for a fee.
865
+
866
+ END OF TERMS AND CONDITIONS
867
+
868
+ How to Apply These Terms to Your New Programs
869
+
870
+ If you develop a new program, and you want it to be of the greatest
871
+ possible use to the public, the best way to achieve this is to make it
872
+ free software which everyone can redistribute and change under these terms.
873
+
874
+ To do so, attach the following notices to the program. It is safest
875
+ to attach them to the start of each source file to most effectively
876
+ state the exclusion of warranty; and each file should have at least
877
+ the "copyright" line and a pointer to where the full notice is found.
878
+
879
+ <one line to give the program's name and a brief idea of what it does.>
880
+ Copyright (C) <year> <name of author>
881
+
882
+ This program is free software: you can redistribute it and/or modify
883
+ it under the terms of the GNU General Public License as published by
884
+ the Free Software Foundation, either version 3 of the License, or
885
+ (at your option) any later version.
886
+
887
+ This program is distributed in the hope that it will be useful,
888
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
889
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
890
+ GNU General Public License for more details.
891
+
892
+ You should have received a copy of the GNU General Public License
893
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
894
+
895
+ Also add information on how to contact you by electronic and paper mail.
896
+
897
+ If the program does terminal interaction, make it output a short
898
+ notice like this when it starts in an interactive mode:
899
+
900
+ <program> Copyright (C) <year> <name of author>
901
+ This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
902
+ This is free software, and you are welcome to redistribute it
903
+ under certain conditions; type `show c' for details.
904
+
905
+ The hypothetical commands `show w' and `show c' should show the appropriate
906
+ parts of the General Public License. Of course, your program's commands
907
+ might be different; for a GUI interface, you would use an "about box".
908
+
909
+ You should also get your employer (if you work as a programmer) or school,
910
+ if any, to sign a "copyright disclaimer" for the program, if necessary.
911
+ For more information on this, and how to apply and follow the GNU GPL, see
912
+ <http://www.gnu.org/licenses/>.
913
+
914
+ The GNU General Public License does not permit incorporating your program
915
+ into proprietary programs. If your program is a subroutine library, you
916
+ may consider it more useful to permit linking proprietary applications with
917
+ the library. If this is what you want to do, use the GNU Lesser General
918
+ Public License instead of this License. But first, please read
919
+ <http://www.gnu.org/philosophy/why-not-lgpl.html>.
920
+
921
+
922
+ Name: libquadmath
923
+ Files: scipy.libs/libquadmath*.so
924
+ Description: dynamically linked to files compiled with gcc
925
+ Availability: https://gcc.gnu.org/git/?p=gcc.git;a=tree;f=libquadmath
926
+ License: LGPL-2.1-or-later
927
+
928
+ GCC Quad-Precision Math Library
929
+ Copyright (C) 2010-2019 Free Software Foundation, Inc.
930
+ Written by Francois-Xavier Coudert <fxcoudert@gcc.gnu.org>
931
+
932
+ This file is part of the libquadmath library.
933
+ Libquadmath is free software; you can redistribute it and/or
934
+ modify it under the terms of the GNU Library General Public
935
+ License as published by the Free Software Foundation; either
936
+ version 2.1 of the License, or (at your option) any later version.
937
+
938
+ Libquadmath is distributed in the hope that it will be useful,
939
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
940
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
941
+ Lesser General Public License for more details.
942
+ https://www.gnu.org/licenses/old-licenses/lgpl-2.1.html
943
+
944
+ Classifier: Development Status :: 5 - Production/Stable
945
+ Classifier: Intended Audience :: Science/Research
946
+ Classifier: Intended Audience :: Developers
947
+ Classifier: License :: OSI Approved :: BSD License
948
+ Classifier: Programming Language :: C
949
+ Classifier: Programming Language :: Python
950
+ Classifier: Programming Language :: Python :: 3
951
+ Classifier: Programming Language :: Python :: 3.12
952
+ Classifier: Programming Language :: Python :: 3.13
953
+ Classifier: Programming Language :: Python :: 3.14
954
+ Classifier: Programming Language :: Python :: 3.15
955
+ Classifier: Topic :: Software Development :: Libraries
956
+ Classifier: Topic :: Scientific/Engineering
957
+ Classifier: Operating System :: Microsoft :: Windows
958
+ Classifier: Operating System :: POSIX :: Linux
959
+ Classifier: Operating System :: POSIX
960
+ Classifier: Operating System :: Unix
961
+ Classifier: Operating System :: MacOS
962
+ Project-URL: homepage, https://scipy.org/
963
+ Project-URL: documentation, https://docs.scipy.org/doc/scipy/
964
+ Project-URL: source, https://github.com/scipy/scipy
965
+ Project-URL: download, https://github.com/scipy/scipy/releases
966
+ Project-URL: tracker, https://github.com/scipy/scipy/issues
967
+ Requires-Python: >=3.12
968
+ Requires-Dist: numpy<2.8,>=2.0.0
969
+ Provides-Extra: test
970
+ Requires-Dist: pytest>=8.0.0; extra == "test"
971
+ Requires-Dist: pytest-cov; extra == "test"
972
+ Requires-Dist: pytest-timeout; extra == "test"
973
+ Requires-Dist: pytest-xdist; extra == "test"
974
+ Requires-Dist: asv; extra == "test"
975
+ Requires-Dist: mpmath; extra == "test"
976
+ Requires-Dist: gmpy2; extra == "test"
977
+ Requires-Dist: threadpoolctl; extra == "test"
978
+ Requires-Dist: scikit-umfpack; extra == "test"
979
+ Requires-Dist: pooch; extra == "test"
980
+ Requires-Dist: hypothesis>=6.30; extra == "test"
981
+ Requires-Dist: array-api-strict>=2.3.1; extra == "test"
982
+ Requires-Dist: Cython; extra == "test"
983
+ Requires-Dist: meson; extra == "test"
984
+ Requires-Dist: ninja; sys_platform != "emscripten" and extra == "test"
985
+ Requires-Dist: scipy-doctest>=2.0.0; extra == "test"
986
+ Provides-Extra: doc
987
+ Requires-Dist: sphinx<8.2.0,>=5.0.0; extra == "doc"
988
+ Requires-Dist: intersphinx_registry; extra == "doc"
989
+ Requires-Dist: pydata-sphinx-theme>=0.15.2; extra == "doc"
990
+ Requires-Dist: sphinx-copybutton; extra == "doc"
991
+ Requires-Dist: sphinx-design>=0.4.0; extra == "doc"
992
+ Requires-Dist: matplotlib>=3.5; extra == "doc"
993
+ Requires-Dist: numpydoc; extra == "doc"
994
+ Requires-Dist: jupytext; extra == "doc"
995
+ Requires-Dist: myst-nb>=1.2.0; extra == "doc"
996
+ Requires-Dist: pooch; extra == "doc"
997
+ Requires-Dist: jupyterlite-sphinx>=0.19.1; extra == "doc"
998
+ Requires-Dist: jupyterlite-pyodide-kernel; extra == "doc"
999
+ Requires-Dist: linkify-it-py; extra == "doc"
1000
+ Requires-Dist: tabulate; extra == "doc"
1001
+ Provides-Extra: dev
1002
+ Requires-Dist: click<8.3.0; extra == "dev"
1003
+ Requires-Dist: spin; extra == "dev"
1004
+ Requires-Dist: mypy==1.19.1; extra == "dev"
1005
+ Requires-Dist: pyrefly==0.63.0; extra == "dev"
1006
+ Requires-Dist: typing_extensions; extra == "dev"
1007
+ Requires-Dist: types-psutil; extra == "dev"
1008
+ Requires-Dist: pycodestyle; extra == "dev"
1009
+ Requires-Dist: ruff>=0.12.0; extra == "dev"
1010
+ Requires-Dist: cython-lint>=0.12.2; extra == "dev"
1011
+ Description-Content-Type: text/x-rst
1012
+
1013
+ .. image:: https://raw.githubusercontent.com/scipy/scipy/main/doc/source/_static/logo.svg
1014
+ :target: https://scipy.org
1015
+ :width: 110
1016
+ :height: 110
1017
+ :align: left
1018
+
1019
+ .. image:: https://img.shields.io/badge/powered%20by-NumFOCUS-orange.svg?style=flat&colorA=E1523D&colorB=007D8A
1020
+ :target: https://numfocus.org
1021
+
1022
+ .. image:: https://img.shields.io/pypi/dm/scipy.svg?label=Pypi%20downloads
1023
+ :target: https://pypi.org/project/scipy/
1024
+
1025
+ .. image:: https://img.shields.io/conda/dn/conda-forge/scipy.svg?label=Conda%20downloads
1026
+ :target: https://anaconda.org/conda-forge/scipy
1027
+
1028
+ .. image:: https://img.shields.io/badge/stackoverflow-Ask%20questions-blue.svg
1029
+ :target: https://stackoverflow.com/questions/tagged/scipy
1030
+
1031
+ .. image:: https://img.shields.io/badge/DOI-10.1038%2Fs41592--019--0686--2-blue.svg
1032
+ :target: https://www.nature.com/articles/s41592-019-0686-2
1033
+
1034
+ .. image:: https://insights.linuxfoundation.org/api/badge/health-score?project=scipy
1035
+ :target: https://insights.linuxfoundation.org/project/scipy
1036
+
1037
+ SciPy (pronounced "Sigh Pie") is an open-source software for mathematics,
1038
+ science, and engineering. It includes modules for statistics, optimization,
1039
+ integration, linear algebra, Fourier transforms, signal and image processing,
1040
+ ODE solvers, and more.
1041
+
1042
+ - **Website:** https://scipy.org
1043
+ - **Documentation:** https://docs.scipy.org/doc/scipy/
1044
+ - **Development version of the documentation:** https://scipy.github.io/devdocs
1045
+ - **SciPy development forum:** https://discuss.scientific-python.org/c/contributor/scipy
1046
+ - **Stack Overflow:** https://stackoverflow.com/questions/tagged/scipy
1047
+ - **Source code:** https://github.com/scipy/scipy
1048
+ - **Contributing:** https://scipy.github.io/devdocs/dev/index.html
1049
+ - **Bug reports:** https://github.com/scipy/scipy/issues
1050
+ - **Code of Conduct:** https://docs.scipy.org/doc/scipy/dev/conduct/code_of_conduct.html
1051
+ - **Report a security vulnerability:** via Tidelift, as explained in
1052
+ `our docs on Security <https://scipy.github.io/devdocs/tutorial/security.html>`__
1053
+ - **Citing in your work:** https://www.scipy.org/citing-scipy/
1054
+
1055
+ SciPy is built to work with
1056
+ NumPy arrays, and provides many user-friendly and efficient numerical routines,
1057
+ such as routines for numerical integration and optimization. Together, they
1058
+ run on all popular operating systems, are quick to install, and are free of
1059
+ charge. NumPy and SciPy are easy to use, but powerful enough to be depended
1060
+ upon by some of the world's leading scientists and engineers. If you need to
1061
+ manipulate numbers on a computer and display or publish the results, give
1062
+ SciPy a try!
1063
+
1064
+ For the installation instructions, see `our install
1065
+ guide <https://scipy.org/install/>`__.
1066
+
1067
+
1068
+ Call for Contributions
1069
+ ----------------------
1070
+
1071
+ We appreciate and welcome contributions. Small improvements or fixes are always appreciated; issues labeled as "good
1072
+ first issue" may be a good starting point. Have a look at `our contributing
1073
+ guide <https://scipy.github.io/devdocs/dev/index.html>`__.
1074
+
1075
+ Writing code isn’t the only way to contribute to SciPy. You can also:
1076
+
1077
+ - review pull requests
1078
+ - triage issues
1079
+ - develop tutorials, presentations, and other educational materials
1080
+ - maintain and improve `our website <https://github.com/scipy/scipy.org>`__
1081
+ - develop graphic design for our brand assets and promotional materials
1082
+ - help with outreach and onboard new contributors
1083
+ - write grant proposals and help with other fundraising efforts
1084
+
1085
+ If you’re unsure where to start or how your skills fit in, reach out! You can
1086
+ ask on the `forum <https://discuss.scientific-python.org/c/contributor/scipy>`__
1087
+ or here, on GitHub, by leaving a comment on a relevant issue that is already
1088
+ open.
1089
+
1090
+ If you are new to contributing to open source, `this
1091
+ guide <https://opensource.guide/how-to-contribute/>`__ helps explain why, what,
1092
+ and how to get involved.
.venv/lib/python3.12/site-packages/scipy-1.18.1.dist-info/RECORD ADDED
The diff for this file is too large to render. See raw diff
 
.venv/lib/python3.12/site-packages/scipy-1.18.1.dist-info/WHEEL ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ Wheel-Version: 1.0
2
+ Generator: meson
3
+ Root-Is-Purelib: false
4
+ Tag: cp312-cp312-manylinux_2_27_x86_64
5
+ Tag: cp312-cp312-manylinux_2_28_x86_64
6
+
.venv/lib/python3.12/site-packages/scipy-1.18.1.dist-info/sboms/auditwheel.cdx.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"bomFormat": "CycloneDX", "specVersion": "1.4", "version": 1, "metadata": {"component": {"type": "library", "bom-ref": "pkg:pypi/scipy@1.18.1?file_name=scipy-1.18.1-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl", "name": "scipy", "version": "1.18.1", "purl": "pkg:pypi/scipy@1.18.1?file_name=scipy-1.18.1-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl"}, "tools": [{"name": "auditwheel", "version": "6.7.0"}]}, "components": [{"type": "library", "bom-ref": "pkg:pypi/scipy@1.18.1?file_name=scipy-1.18.1-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl", "name": "scipy", "version": "1.18.1", "purl": "pkg:pypi/scipy@1.18.1?file_name=scipy-1.18.1-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl"}, {"type": "library", "bom-ref": "pkg:rpm/almalinux/libquadmath@8.5.0-28.el8_10.alma.1#97b91febe2a1c7927c6482d6bd6567b83be3467f33c9d2764df1283f7ac9a5fa", "name": "libquadmath", "version": "8.5.0-28.el8_10.alma.1", "purl": "pkg:rpm/almalinux/libquadmath@8.5.0-28.el8_10.alma.1"}, {"type": "library", "bom-ref": "pkg:rpm/almalinux/libgfortran@8.5.0-28.el8_10.alma.1#3362720ce454cc402813e3cfe54f0eb4efaedcd690fa35129ddc4b3de40e0650", "name": "libgfortran", "version": "8.5.0-28.el8_10.alma.1", "purl": "pkg:rpm/almalinux/libgfortran@8.5.0-28.el8_10.alma.1"}], "dependencies": [{"ref": "pkg:pypi/scipy@1.18.1?file_name=scipy-1.18.1-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl", "dependsOn": ["pkg:rpm/almalinux/libquadmath@8.5.0-28.el8_10.alma.1#97b91febe2a1c7927c6482d6bd6567b83be3467f33c9d2764df1283f7ac9a5fa", "pkg:rpm/almalinux/libgfortran@8.5.0-28.el8_10.alma.1#3362720ce454cc402813e3cfe54f0eb4efaedcd690fa35129ddc4b3de40e0650"]}, {"ref": "pkg:rpm/almalinux/libquadmath@8.5.0-28.el8_10.alma.1#97b91febe2a1c7927c6482d6bd6567b83be3467f33c9d2764df1283f7ac9a5fa"}, {"ref": "pkg:rpm/almalinux/libgfortran@8.5.0-28.el8_10.alma.1#3362720ce454cc402813e3cfe54f0eb4efaedcd690fa35129ddc4b3de40e0650"}]}
.venv/lib/python3.12/site-packages/scipy.libs/libgfortran-040039e1-0352e75f.so.5.0.0 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c6090048eccc763522c12ef016f81da6b627cb3a044f55cf0479a839c41c0980
3
+ size 2833617
.venv/lib/python3.12/site-packages/scipy.libs/libgfortran-83c28eba.so.5.0.0 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:468e71e59e1d784821a76702e5ecd1e0dbcfc024499f74a552d1bea4b26f27ad
3
+ size 2751569
.venv/lib/python3.12/site-packages/scipy.libs/libquadmath-2284e583.so.0.0.0 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a9307bbaa353623fa014e8b682d50c4629f5e5c7d61daa9a8652f7d165cd421a
3
+ size 272193
.venv/lib/python3.12/site-packages/scipy.libs/libquadmath-96973f99-934c22de.so.0.0.0 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6ed5137f412781ad7863439fb543613f620b43c32b63292a0029246162f5bbc6
3
+ size 250985
.venv/lib/python3.12/site-packages/scipy.libs/libscipy_openblas-5f890258.so ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2a5b4c1a6311873c59132b2ceaaf3c26258a17350b7cd27ea8782a47e3322981
3
+ size 25094609
.venv/lib/python3.12/site-packages/scipy/special/tests/test_ellip_harm.py ADDED
@@ -0,0 +1,288 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #
2
+ # Tests for the Ellipsoidal Harmonic Function,
3
+ # Distributed under the same license as SciPy itself.
4
+ #
5
+ import warnings
6
+
7
+ import numpy as np
8
+ from numpy.testing import assert_equal, assert_allclose, assert_
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 warnings.catch_warnings():
56
+ warnings.filterwarnings(
57
+ "ignore", "The occurrence of roundoff error", IntegrationWarning)
58
+ warnings.filterwarnings(
59
+ "ignore", "The maximum number of subdivisions", IntegrationWarning)
60
+
61
+ for p in pts:
62
+ err_msg = repr(p)
63
+ exact = potential(*p)
64
+ result, last_term = summation(*p)
65
+ assert_allclose(exact, result, atol=0, rtol=1e-8, err_msg=err_msg)
66
+ assert_(abs(result - exact) < 10*abs(last_term), err_msg)
67
+
68
+
69
+ def test_ellip_norm():
70
+
71
+ def G01(h2, k2):
72
+ return 4*pi
73
+
74
+ def G11(h2, k2):
75
+ return 4*pi*h2*k2/3
76
+
77
+ def G12(h2, k2):
78
+ return 4*pi*h2*(k2 - h2)/3
79
+
80
+ def G13(h2, k2):
81
+ return 4*pi*k2*(k2 - h2)/3
82
+
83
+ def G22(h2, k2):
84
+ res = (2*(h2**4 + k2**4) - 4*h2*k2*(h2**2 + k2**2) + 6*h2**2*k2**2 +
85
+ sqrt(h2**2 + k2**2 - h2*k2)*(-2*(h2**3 + k2**3) + 3*h2*k2*(h2 + k2)))
86
+ return 16*pi/405*res
87
+
88
+ def G21(h2, k2):
89
+ res = (2*(h2**4 + k2**4) - 4*h2*k2*(h2**2 + k2**2) + 6*h2**2*k2**2
90
+ + sqrt(h2**2 + k2**2 - h2*k2)*(2*(h2**3 + k2**3) - 3*h2*k2*(h2 + k2)))
91
+ return 16*pi/405*res
92
+
93
+ def G23(h2, k2):
94
+ return 4*pi*h2**2*k2*(k2 - h2)/15
95
+
96
+ def G24(h2, k2):
97
+ return 4*pi*h2*k2**2*(k2 - h2)/15
98
+
99
+ def G25(h2, k2):
100
+ return 4*pi*h2*k2*(k2 - h2)**2/15
101
+
102
+ def G32(h2, k2):
103
+ res = (16*(h2**4 + k2**4) - 36*h2*k2*(h2**2 + k2**2) + 46*h2**2*k2**2
104
+ + sqrt(4*(h2**2 + k2**2) - 7*h2*k2)*(-8*(h2**3 + k2**3) +
105
+ 11*h2*k2*(h2 + k2)))
106
+ return 16*pi/13125*k2*h2*res
107
+
108
+ def G31(h2, k2):
109
+ res = (16*(h2**4 + k2**4) - 36*h2*k2*(h2**2 + k2**2) + 46*h2**2*k2**2
110
+ + sqrt(4*(h2**2 + k2**2) - 7*h2*k2)*(8*(h2**3 + k2**3) -
111
+ 11*h2*k2*(h2 + k2)))
112
+ return 16*pi/13125*h2*k2*res
113
+
114
+ def G34(h2, k2):
115
+ res = (6*h2**4 + 16*k2**4 - 12*h2**3*k2 - 28*h2*k2**3 + 34*h2**2*k2**2
116
+ + sqrt(h2**2 + 4*k2**2 - h2*k2)*(-6*h2**3 - 8*k2**3 + 9*h2**2*k2 +
117
+ 13*h2*k2**2))
118
+ return 16*pi/13125*h2*(k2 - h2)*res
119
+
120
+ def G33(h2, k2):
121
+ res = (6*h2**4 + 16*k2**4 - 12*h2**3*k2 - 28*h2*k2**3 + 34*h2**2*k2**2
122
+ + sqrt(h2**2 + 4*k2**2 - h2*k2)*(6*h2**3 + 8*k2**3 - 9*h2**2*k2 -
123
+ 13*h2*k2**2))
124
+ return 16*pi/13125*h2*(k2 - h2)*res
125
+
126
+ def G36(h2, k2):
127
+ res = (16*h2**4 + 6*k2**4 - 28*h2**3*k2 - 12*h2*k2**3 + 34*h2**2*k2**2
128
+ + sqrt(4*h2**2 + k2**2 - h2*k2)*(-8*h2**3 - 6*k2**3 + 13*h2**2*k2 +
129
+ 9*h2*k2**2))
130
+ return 16*pi/13125*k2*(k2 - h2)*res
131
+
132
+ def G35(h2, k2):
133
+ res = (16*h2**4 + 6*k2**4 - 28*h2**3*k2 - 12*h2*k2**3 + 34*h2**2*k2**2
134
+ + sqrt(4*h2**2 + k2**2 - h2*k2)*(8*h2**3 + 6*k2**3 - 13*h2**2*k2 -
135
+ 9*h2*k2**2))
136
+ return 16*pi/13125*k2*(k2 - h2)*res
137
+
138
+ def G37(h2, k2):
139
+ return 4*pi*h2**2*k2**2*(k2 - h2)**2/105
140
+
141
+ known_funcs = {(0, 1): G01, (1, 1): G11, (1, 2): G12, (1, 3): G13,
142
+ (2, 1): G21, (2, 2): G22, (2, 3): G23, (2, 4): G24,
143
+ (2, 5): G25, (3, 1): G31, (3, 2): G32, (3, 3): G33,
144
+ (3, 4): G34, (3, 5): G35, (3, 6): G36, (3, 7): G37}
145
+
146
+ def _ellip_norm(n, p, h2, k2):
147
+ func = known_funcs[n, p]
148
+ return func(h2, k2)
149
+ _ellip_norm = np.vectorize(_ellip_norm)
150
+
151
+ def ellip_normal_known(h2, k2, n, p):
152
+ return _ellip_norm(n, p, h2, k2)
153
+
154
+ # generate both large and small h2 < k2 pairs
155
+ np.random.seed(1234)
156
+ h2 = np.random.pareto(0.5, size=1)
157
+ k2 = h2 * (1 + np.random.pareto(0.5, size=h2.size))
158
+
159
+ points = []
160
+ for n in range(4):
161
+ for p in range(1, 2*n+2):
162
+ points.append((h2, k2, np.full(h2.size, n), np.full(h2.size, p)))
163
+ points = np.array(points)
164
+ with warnings.catch_warnings():
165
+ warnings.filterwarnings(
166
+ "ignore", "The occurrence of roundoff error", IntegrationWarning)
167
+ assert_func_equal(ellip_normal, ellip_normal_known, points, rtol=1e-12)
168
+
169
+
170
+ def test_ellip_harm_2():
171
+
172
+ def I1(h2, k2, s):
173
+ res = (ellip_harm_2(h2, k2, 1, 1, s)/(3 * ellip_harm(h2, k2, 1, 1, s))
174
+ + ellip_harm_2(h2, k2, 1, 2, s)/(3 * ellip_harm(h2, k2, 1, 2, s)) +
175
+ ellip_harm_2(h2, k2, 1, 3, s)/(3 * ellip_harm(h2, k2, 1, 3, s)))
176
+ return res
177
+
178
+ with warnings.catch_warnings():
179
+ warnings.filterwarnings(
180
+ "ignore", "The occurrence of roundoff error", IntegrationWarning)
181
+ assert_allclose(I1(5, 8, 10), 1/(10*sqrt((100-5)*(100-8))),
182
+ atol=1.5e-7, rtol=0)
183
+
184
+ # Values produced by code from arXiv:1204.0267
185
+ assert_allclose(ellip_harm_2(5, 8, 2, 1, 10), 0.00108056853382,
186
+ atol=1.5e-7, rtol=0)
187
+ assert_allclose(ellip_harm_2(5, 8, 2, 2, 10), 0.00105820513809,
188
+ atol=1.5e-7, rtol=0)
189
+ assert_allclose(ellip_harm_2(5, 8, 2, 3, 10), 0.00106058384743,
190
+ atol=1.5e-7, rtol=0)
191
+ assert_allclose(ellip_harm_2(5, 8, 2, 4, 10), 0.00106774492306,
192
+ atol=1.5e-7, rtol=0)
193
+ assert_allclose(ellip_harm_2(5, 8, 2, 5, 10), 0.00107976356454,
194
+ atol=1.5e-7, rtol=0)
195
+
196
+
197
+ def test_ellip_harm():
198
+
199
+ def E01(h2, k2, s):
200
+ return 1
201
+
202
+ def E11(h2, k2, s):
203
+ return s
204
+
205
+ def E12(h2, k2, s):
206
+ return sqrt(abs(s*s - h2))
207
+
208
+ def E13(h2, k2, s):
209
+ return sqrt(abs(s*s - k2))
210
+
211
+ def E21(h2, k2, s):
212
+ return s*s - 1/3*((h2 + k2) + sqrt(abs((h2 + k2)*(h2 + k2)-3*h2*k2)))
213
+
214
+ def E22(h2, k2, s):
215
+ return s*s - 1/3*((h2 + k2) - sqrt(abs((h2 + k2)*(h2 + k2)-3*h2*k2)))
216
+
217
+ def E23(h2, k2, s):
218
+ return s * sqrt(abs(s*s - h2))
219
+
220
+ def E24(h2, k2, s):
221
+ return s * sqrt(abs(s*s - k2))
222
+
223
+ def E25(h2, k2, s):
224
+ return sqrt(abs((s*s - h2)*(s*s - k2)))
225
+
226
+ def E31(h2, k2, s):
227
+ return s*s*s - (s/5)*(2*(h2 + k2) + sqrt(4*(h2 + k2)*(h2 + k2) -
228
+ 15*h2*k2))
229
+
230
+ def E32(h2, k2, s):
231
+ return s*s*s - (s/5)*(2*(h2 + k2) - sqrt(4*(h2 + k2)*(h2 + k2) -
232
+ 15*h2*k2))
233
+
234
+ def E33(h2, k2, s):
235
+ return sqrt(abs(s*s - h2))*(s*s - 1/5*((h2 + 2*k2) + sqrt(abs((h2 +
236
+ 2*k2)*(h2 + 2*k2) - 5*h2*k2))))
237
+
238
+ def E34(h2, k2, s):
239
+ return sqrt(abs(s*s - h2))*(s*s - 1/5*((h2 + 2*k2) - sqrt(abs((h2 +
240
+ 2*k2)*(h2 + 2*k2) - 5*h2*k2))))
241
+
242
+ def E35(h2, k2, s):
243
+ return sqrt(abs(s*s - k2))*(s*s - 1/5*((2*h2 + k2) + sqrt(abs((2*h2
244
+ + k2)*(2*h2 + k2) - 5*h2*k2))))
245
+
246
+ def E36(h2, k2, s):
247
+ return sqrt(abs(s*s - k2))*(s*s - 1/5*((2*h2 + k2) - sqrt(abs((2*h2
248
+ + k2)*(2*h2 + k2) - 5*h2*k2))))
249
+
250
+ def E37(h2, k2, s):
251
+ return s * sqrt(abs((s*s - h2)*(s*s - k2)))
252
+
253
+ assert_equal(ellip_harm(5, 8, 1, 2, 2.5, 1, 1),
254
+ ellip_harm(5, 8, 1, 2, 2.5))
255
+
256
+ known_funcs = {(0, 1): E01, (1, 1): E11, (1, 2): E12, (1, 3): E13,
257
+ (2, 1): E21, (2, 2): E22, (2, 3): E23, (2, 4): E24,
258
+ (2, 5): E25, (3, 1): E31, (3, 2): E32, (3, 3): E33,
259
+ (3, 4): E34, (3, 5): E35, (3, 6): E36, (3, 7): E37}
260
+
261
+ point_ref = []
262
+
263
+ def ellip_harm_known(h2, k2, n, p, s):
264
+ for i in range(h2.size):
265
+ func = known_funcs[(int(n[i]), int(p[i]))]
266
+ point_ref.append(func(h2[i], k2[i], s[i]))
267
+ return point_ref
268
+
269
+ rng = np.random.RandomState(1234)
270
+ h2 = rng.pareto(0.5, size=30)
271
+ k2 = h2*(1 + rng.pareto(0.5, size=h2.size))
272
+ s = rng.pareto(0.5, size=h2.size)
273
+ points = []
274
+ for i in range(h2.size):
275
+ for n in range(4):
276
+ for p in range(1, 2*n+2):
277
+ points.append((h2[i], k2[i], n, p, s[i]))
278
+ points = np.array(points)
279
+ assert_func_equal(ellip_harm, ellip_harm_known, points, rtol=1e-12)
280
+
281
+
282
+ def test_ellip_harm_invalid_p():
283
+ # Regression test. This should return nan.
284
+ n = 4
285
+ # Make p > 2*n + 1.
286
+ p = 2*n + 2
287
+ result = ellip_harm(0.5, 2.0, n, p, 0.2)
288
+ assert np.isnan(result)
.venv/lib/python3.12/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)
.venv/lib/python3.12/site-packages/scipy/special/tests/test_exponential_integrals.py ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ @pytest.mark.parametrize('x, expected', [(0, -np.inf), (np.inf, np.inf)])
115
+ def test_limits(self, x, expected):
116
+ y = sc.expi(x)
117
+ assert y == expected
118
+
119
+
120
+ class TestExpn:
121
+
122
+ def test_out_of_domain(self):
123
+ assert all(np.isnan([sc.expn(-1, 1.0), sc.expn(1, -1.0)]))
.venv/lib/python3.12/site-packages/scipy/special/tests/test_extending.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import platform
3
+ import sysconfig
4
+
5
+ import pytest
6
+
7
+ from scipy._lib._testutils import IS_EDITABLE,_test_cython_extension, cython
8
+ from scipy.special import beta, gamma
9
+
10
+
11
+ @pytest.mark.fail_slow(40)
12
+ # essential per https://github.com/scipy/scipy/pull/20487#discussion_r1567057247
13
+ @pytest.mark.skipif(IS_EDITABLE,
14
+ reason='Editable install cannot find .pxd headers.')
15
+ @pytest.mark.skipif((platform.system() == 'Windows' and
16
+ sysconfig.get_config_var('Py_GIL_DISABLED')),
17
+ reason='gh-22039')
18
+ @pytest.mark.skipif(platform.machine() in ["wasm32", "wasm64"],
19
+ reason="Can't start subprocess")
20
+ @pytest.mark.skipif(cython is None, reason="requires cython")
21
+ def test_cython(tmp_path):
22
+ srcdir = os.path.dirname(os.path.dirname(__file__))
23
+ extensions, extensions_cpp = _test_cython_extension(tmp_path, srcdir)
24
+ # actually test the cython c-extensions
25
+ assert extensions.cy_beta(0.5, 0.1) == beta(0.5, 0.1)
26
+ assert extensions.cy_gamma(0.5 + 1.0j) == gamma(0.5 + 1.0j)
27
+ assert extensions_cpp.cy_beta(0.5, 0.1) == beta(0.5, 0.1)
28
+ assert extensions_cpp.cy_gamma(0.5 + 1.0j) == gamma(0.5 + 1.0j)
.venv/lib/python3.12/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
+ )
.venv/lib/python3.12/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)
.venv/lib/python3.12/site-packages/scipy/special/tests/test_gammainc.py ADDED
@@ -0,0 +1,152 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ @pytest.mark.parametrize("x", [-np.inf, -1.0, -0.0, 0.0, np.inf, np.nan])
42
+ def test_a_nan(self, x):
43
+ assert np.isnan(sc.gammainc(np.nan, x))
44
+
45
+ @pytest.mark.parametrize("a", [-np.inf, -1.0, -0.0, 0.0, np.inf, np.nan])
46
+ def test_x_nan(self, a):
47
+ assert np.isnan(sc.gammainc(a, np.nan))
48
+
49
+ def test_infinite_limits(self):
50
+ # Test that large arguments converge to the hard-coded limits
51
+ # at infinity.
52
+ assert_allclose(
53
+ sc.gammainc(1000, 100),
54
+ sc.gammainc(np.inf, 100),
55
+ atol=1e-200, # Use `atol` since the function converges to 0.
56
+ rtol=0
57
+ )
58
+ assert sc.gammainc(100, 1000) == sc.gammainc(100, np.inf)
59
+
60
+ def test_x_zero(self):
61
+ a = np.arange(1, 10)
62
+ assert_array_equal(sc.gammainc(a, 0), 0)
63
+
64
+ def test_limit_check(self):
65
+ result = sc.gammainc(1e-10, 1)
66
+ limit = sc.gammainc(0, 1)
67
+ assert np.isclose(result, limit)
68
+
69
+ def gammainc_line(self, x):
70
+ # The line a = x where a simpler asymptotic expansion (analog
71
+ # of DLMF 8.12.15) is available.
72
+ c = np.array([-1/3, -1/540, 25/6048, 101/155520,
73
+ -3184811/3695155200, -2745493/8151736420])
74
+ res = 0
75
+ xfac = 1
76
+ for ck in c:
77
+ res -= ck*xfac
78
+ xfac /= x
79
+ res /= np.sqrt(2*np.pi*x)
80
+ res += 0.5
81
+ return res
82
+
83
+ def test_line(self):
84
+ x = np.logspace(np.log10(25), 300, 500)
85
+ a = x
86
+ dataset = np.vstack((a, x, self.gammainc_line(x))).T
87
+ FuncData(sc.gammainc, dataset, (0, 1), 2, rtol=1e-11).check()
88
+
89
+ def test_roundtrip(self):
90
+ a = np.logspace(-5, 10, 100)
91
+ x = np.logspace(-5, 10, 100)
92
+
93
+ y = sc.gammaincinv(a, sc.gammainc(a, x))
94
+ assert_allclose(x, y, rtol=1e-10)
95
+
96
+
97
+ class TestGammaincc:
98
+
99
+ @pytest.mark.parametrize('a, x', INVALID_POINTS)
100
+ def test_domain(self, a, x):
101
+ assert np.isnan(sc.gammaincc(a, x))
102
+
103
+ def test_a_eq_0_x_gt_0(self):
104
+ assert sc.gammaincc(0, 1) == 0
105
+
106
+ @pytest.mark.parametrize('a, x, desired', [
107
+ (np.inf, 1, 1),
108
+ (np.inf, 0, 1),
109
+ (np.inf, np.inf, np.nan),
110
+ (1, np.inf, 0)
111
+ ])
112
+ def test_infinite_arguments(self, a, x, desired):
113
+ result = sc.gammaincc(a, x)
114
+ if np.isnan(desired):
115
+ assert np.isnan(result)
116
+ else:
117
+ assert result == desired
118
+
119
+ @pytest.mark.parametrize("x", [-np.inf, -1.0, -0.0, 0.0, np.inf, np.nan])
120
+ def test_a_nan(self, x):
121
+ assert np.isnan(sc.gammaincc(np.nan, x))
122
+
123
+ @pytest.mark.parametrize("a", [-np.inf, -1.0, -0.0, 0.0, np.inf, np.nan])
124
+ def test_x_nan(self, a):
125
+ assert np.isnan(sc.gammaincc(a, np.nan))
126
+
127
+ def test_infinite_limits(self):
128
+ # Test that large arguments converge to the hard-coded limits
129
+ # at infinity.
130
+ assert sc.gammaincc(1000, 100) == sc.gammaincc(np.inf, 100)
131
+ assert_allclose(
132
+ sc.gammaincc(100, 1000),
133
+ sc.gammaincc(100, np.inf),
134
+ atol=1e-200, # Use `atol` since the function converges to 0.
135
+ rtol=0
136
+ )
137
+
138
+ def test_limit_check(self):
139
+ result = sc.gammaincc(1e-10,1)
140
+ limit = sc.gammaincc(0,1)
141
+ assert np.isclose(result, limit)
142
+
143
+ def test_x_zero(self):
144
+ a = np.arange(1, 10)
145
+ assert_array_equal(sc.gammaincc(a, 0), 1)
146
+
147
+ def test_roundtrip(self):
148
+ a = np.logspace(-5, 10, 100)
149
+ x = np.logspace(-5, 10, 100)
150
+
151
+ y = sc.gammainccinv(a, sc.gammaincc(a, x))
152
+ assert_allclose(x, y, rtol=1e-14)
.venv/lib/python3.12/site-packages/scipy/special/tests/test_gen_harmonic.py ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ from numpy.testing import assert_allclose, assert_equal
3
+ import pytest
4
+ from scipy.special._ufuncs import _gen_harmonic, _normalized_gen_harmonic
5
+
6
+
7
+ #
8
+ # In the following tests, reference values were computed with mpmath.
9
+ #
10
+
11
+ @pytest.mark.parametrize('typ', [np.int32, np.int64, np.float64])
12
+ @pytest.mark.parametrize(
13
+ 'n, a, ref',
14
+ [(8, 9.0, 1.0020083884212339),
15
+ (1000, 2.5, 1.3414661912046497),
16
+ (10, 1.5, 1.9953364933456017),
17
+ (10000, 1.25, 4.1951168257387765),
18
+ (10000,1.00001, 9.787182620770265),
19
+ (80, 1.000002, 4.965460167788836),
20
+ (75, 1 + 1e-12, 4.901355630543771),
21
+ (100, 1 + 1e-14, 5.187377517639515),
22
+ (100, 1 + 8e-16, 5.187377517639611),
23
+ (100, 1.0, 5.187377517639621),
24
+ (7, 1.0, 2.592857142857143),
25
+ (8000, 1.0, 9.564474984261423),
26
+ (5, 1 - 1e-12, 2.2833333333347143),
27
+ (25000, 1 - 1e-12, 10.703866768669737),
28
+ (1000, 0.995, 7.6058022857089975),
29
+ (1000, 0.75, 19.055178975831392),
30
+ (10000, 0.25, 1332.5700547197382),
31
+ (5, 1e-8, 4.999999952125083),
32
+ (15, 1e-16, 14.999999999999996),
33
+ (100, 0.0, 100.0),
34
+ (4, -1.0, 10.0),
35
+ (75, -1.5, 19811.38815892374)]
36
+ )
37
+ def test_gen_harmonic(typ, n, a, ref):
38
+ h = _gen_harmonic(typ(n), a)
39
+ assert_allclose(h, ref, rtol=5e-15)
40
+
41
+
42
+ @pytest.mark.parametrize('typ', [np.int32, np.int64, np.float64])
43
+ @pytest.mark.parametrize(
44
+ 'n, a, ref',
45
+ [(10, np.inf, 1.0),
46
+ (1, np.nan, 1.0),
47
+ (1, -np.inf, 1.0),
48
+ (3, np.nan, np.nan),
49
+ (-3, 1.0, np.nan)]
50
+ )
51
+ def test_gen_harmonic_exact_cases(typ, n, a, ref):
52
+ h = _gen_harmonic(typ(n), a)
53
+ assert_equal(h, ref)
54
+
55
+
56
+ def test_gen_harmonic_n_nan():
57
+ h = _gen_harmonic(np.nan, 0.75)
58
+ assert_equal(h, np.nan)
59
+
60
+
61
+ @pytest.mark.parametrize('typ', [np.int32, np.int64, np.float64])
62
+ @pytest.mark.parametrize(
63
+ 'j, k, n, a, ref',
64
+ [(400, 5000, 5000, 10.0, 4.2821759663214485e-25),
65
+ (400, 5000, 5000, 3.5, 1.11086549102426e-07),
66
+ (1, 2, 3, 1.5, 0.8755176866163012),
67
+ (300, 500, 500, 1 + 1e-14, 0.07559343891632035),
68
+ (1500, 2500, 3000, 1 - 1e-12, 0.05957291246371843),
69
+ (10, 12, 16, 0.5, 0.13601665344521513),
70
+ (16, 16, 20, 0.125, 0.04583107002260924),
71
+ (10, 12, 16, -0.5, 0.22359306724308234),
72
+ (1, 8000, 10000, -1.5, 0.5724512895513029)]
73
+ )
74
+ def test_normalized_gen_harmonic(typ, j, k, n, a, ref):
75
+ h = _normalized_gen_harmonic(typ(j), typ(k), typ(n), a)
76
+ assert_allclose(h, ref, 5e-15)
77
+
78
+
79
+ @pytest.mark.parametrize('typ', [np.int32, np.int64, np.float64])
80
+ @pytest.mark.parametrize(
81
+ 'j, k, n, a, ref',
82
+ [(1, 1, 1, 0.5, 1.0),
83
+ (1, 1, 1, np.nan, 1.0),
84
+ (1, 2, 5, np.nan, np.nan),
85
+ (1, 2, 1, 1.25, np.nan),
86
+ (1, 2, 3, np.inf, 1.0),
87
+ (2, 3, 4, np.inf, 0.0),
88
+ (1, 1, 10, -np.inf, 0.0),
89
+ (2, 3, 4, -np.inf, np.nan),
90
+ (3, 6, 8, 0.0, 0.5)]
91
+ )
92
+ def test_normalized_gen_harmonic_exact_cases(typ, j, k, n, a, ref):
93
+ h = _normalized_gen_harmonic(typ(j), typ(k), typ(n), a)
94
+ assert_equal(h, ref)
95
+
96
+
97
+ def test_normalized_gen_harmonic_input_nan():
98
+ h = _normalized_gen_harmonic(1.0, np.nan, 10.0, 1.05)
99
+ assert_equal(h, np.nan)
.venv/lib/python3.12/site-packages/scipy/special/tests/test_hyp2f1.py ADDED
@@ -0,0 +1,2566 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Tests for hyp2f1 for complex values.
2
+
3
+ Author: Albert Steppi, with credit to Adam Kullberg (FormerPhycisist) for
4
+ the implementation of mp_hyp2f1 below, which modifies mpmath's hyp2f1 to
5
+ return the same branch as scipy's on the standard branch cut.
6
+ """
7
+
8
+ import sys
9
+ import pytest
10
+ import numpy as np
11
+ from typing import NamedTuple
12
+ from numpy.testing import assert_allclose
13
+
14
+ from scipy.special import hyp2f1
15
+ from scipy.special._testutils import check_version, MissingModule
16
+
17
+
18
+ try:
19
+ import mpmath
20
+ except ImportError:
21
+ mpmath = MissingModule("mpmath")
22
+
23
+
24
+ def mp_hyp2f1(a, b, c, z):
25
+ """Return mpmath hyp2f1 calculated on same branch as scipy hyp2f1.
26
+
27
+ For most values of a,b,c mpmath returns the x - 0j branch of hyp2f1 on the
28
+ branch cut x=(1,inf) whereas scipy's hyp2f1 calculates the x + 0j branch.
29
+ Thus, to generate the right comparison values on the branch cut, we
30
+ evaluate mpmath.hyp2f1 at x + 1e-15*j.
31
+
32
+ The exception to this occurs when c-a=-m in which case both mpmath and
33
+ scipy calculate the x + 0j branch on the branch cut. When this happens
34
+ mpmath.hyp2f1 will be evaluated at the original z point.
35
+ """
36
+ on_branch_cut = z.real > 1.0 and abs(z.imag) < 1.0e-15
37
+ cond1 = abs(c - a - round(c - a)) < 1.0e-15 and round(c - a) <= 0
38
+ cond2 = abs(c - b - round(c - b)) < 1.0e-15 and round(c - b) <= 0
39
+ # Make sure imaginary part is *exactly* zero
40
+ if on_branch_cut:
41
+ z = z.real + 0.0j
42
+ if on_branch_cut and not (cond1 or cond2):
43
+ z_mpmath = z.real + 1.0e-15j
44
+ else:
45
+ z_mpmath = z
46
+ return complex(mpmath.hyp2f1(a, b, c, z_mpmath))
47
+
48
+
49
+ class Hyp2f1TestCase(NamedTuple):
50
+ a: float
51
+ b: float
52
+ c: float
53
+ z: complex
54
+ expected: complex
55
+ rtol: float
56
+
57
+
58
+ class TestHyp2f1:
59
+ """Tests for hyp2f1 for complex values.
60
+
61
+ Expected values for test cases were computed using mpmath. See
62
+ `scipy.special._precompute.hyp2f1_data`. The verbose style of specifying
63
+ test cases is used for readability and to make it easier to mark individual
64
+ cases as expected to fail. Expected failures are used to highlight cases
65
+ where improvements are needed. See
66
+ `scipy.special._precompute.hyp2f1_data.make_hyp2f1_test_cases` for a
67
+ function to generate the boilerplate for the test cases.
68
+
69
+ Assertions have been added to each test to ensure that the test cases match
70
+ the situations that are intended. A final test `test_test_hyp2f1` checks
71
+ that the expected values in the test cases actually match what is computed
72
+ by mpmath. This test is marked slow even though it isn't particularly slow
73
+ so that it won't run by default on continuous integration builds.
74
+ """
75
+ @pytest.mark.parametrize(
76
+ "hyp2f1_test_case",
77
+ [
78
+ pytest.param(
79
+ Hyp2f1TestCase(
80
+ a=0.5,
81
+ b=0.2,
82
+ c=-10,
83
+ z=0.2 + 0.2j,
84
+ expected=np.inf + 0j,
85
+ rtol=0
86
+ )
87
+ ),
88
+ pytest.param(
89
+ Hyp2f1TestCase(
90
+ a=0.5,
91
+ b=0.2,
92
+ c=-10,
93
+ z=0 + 0j,
94
+ expected=1 + 0j,
95
+ rtol=0
96
+ ),
97
+ ),
98
+ pytest.param(
99
+ Hyp2f1TestCase(
100
+ a=0.5,
101
+ b=0,
102
+ c=-10,
103
+ z=0.2 + 0.2j,
104
+ expected=1 + 0j,
105
+ rtol=0
106
+ ),
107
+ ),
108
+ pytest.param(
109
+ Hyp2f1TestCase(
110
+ a=0.5,
111
+ b=0,
112
+ c=0,
113
+ z=0.2 + 0.2j,
114
+ expected=1 + 0j,
115
+ rtol=0,
116
+ ),
117
+ ),
118
+ pytest.param(
119
+ Hyp2f1TestCase(
120
+ a=0.5,
121
+ b=0.2,
122
+ c=0,
123
+ z=0.2 + 0.2j,
124
+ expected=np.inf + 0j,
125
+ rtol=0,
126
+ ),
127
+ ),
128
+ pytest.param(
129
+ Hyp2f1TestCase(
130
+ a=0.5,
131
+ b=0.2,
132
+ c=0,
133
+ z=0 + 0j,
134
+ expected=np.nan + 0j,
135
+ rtol=0,
136
+ ),
137
+ ),
138
+ pytest.param(
139
+ Hyp2f1TestCase(
140
+ a=0.5,
141
+ b=-5,
142
+ c=-10,
143
+ z=0.2 + 0.2j,
144
+ expected=(1.0495404166666666+0.05708208333333334j),
145
+ rtol=1e-15,
146
+ ),
147
+ ),
148
+ pytest.param(
149
+ Hyp2f1TestCase(
150
+ a=0.5,
151
+ b=-10,
152
+ c=-10,
153
+ z=0.2 + 0.2j,
154
+ expected=(1.092966013125+0.13455014673750001j),
155
+ rtol=1e-15,
156
+ ),
157
+ ),
158
+ pytest.param(
159
+ Hyp2f1TestCase(
160
+ a=-10,
161
+ b=-20,
162
+ c=-10,
163
+ z=0.2 + 0.2j,
164
+ expected=(-0.07712512000000005+0.12752814080000005j),
165
+ rtol=1e-13,
166
+ ),
167
+ ),
168
+ pytest.param(
169
+ Hyp2f1TestCase(
170
+ a=-1,
171
+ b=3.2,
172
+ c=-1,
173
+ z=0.2 + 0.2j,
174
+ expected=(1.6400000000000001+0.6400000000000001j),
175
+ rtol=1e-13,
176
+ ),
177
+ ),
178
+ pytest.param(
179
+ Hyp2f1TestCase(
180
+ a=-2,
181
+ b=1.2,
182
+ c=-4,
183
+ z=1 + 0j,
184
+ expected=1.8200000000000001 + 0j,
185
+ rtol=1e-15,
186
+ ),
187
+ ),
188
+ ]
189
+ )
190
+ def test_c_non_positive_int(self, hyp2f1_test_case):
191
+ a, b, c, z, expected, rtol = hyp2f1_test_case
192
+ assert_allclose(hyp2f1(a, b, c, z), expected, rtol=rtol)
193
+
194
+ @pytest.mark.parametrize(
195
+ "hyp2f1_test_case",
196
+ [
197
+ pytest.param(
198
+ Hyp2f1TestCase(
199
+ a=0.5,
200
+ b=0.2,
201
+ c=1.5,
202
+ z=1 + 0j,
203
+ expected=1.1496439092239847 + 0j,
204
+ rtol=1e-15
205
+ ),
206
+ ),
207
+ pytest.param(
208
+ Hyp2f1TestCase(
209
+ a=12.3,
210
+ b=8.0,
211
+ c=20.31,
212
+ z=1 + 0j,
213
+ expected=69280986.75273195 + 0j,
214
+ rtol=1e-15
215
+ ),
216
+ ),
217
+ pytest.param(
218
+ Hyp2f1TestCase(
219
+ a=290.2,
220
+ b=321.5,
221
+ c=700.1,
222
+ z=1 + 0j,
223
+ expected=1.3396562400934e117 + 0j,
224
+ rtol=1e-12,
225
+ ),
226
+ ),
227
+ # Note that here even mpmath produces different results for
228
+ # results that should be equivalent.
229
+ pytest.param(
230
+ Hyp2f1TestCase(
231
+ a=9.2,
232
+ b=621.5,
233
+ c=700.1,
234
+ z=(1+0j),
235
+ expected=(952726652.4158565+0j),
236
+ rtol=5e-13,
237
+ ),
238
+ ),
239
+ pytest.param(
240
+ Hyp2f1TestCase(
241
+ a=621.5,
242
+ b=9.2,
243
+ c=700.1,
244
+ z=(1+0j),
245
+ expected=(952726652.4160284+0j),
246
+ rtol=5e-12,
247
+ ),
248
+ ),
249
+ pytest.param(
250
+ Hyp2f1TestCase(
251
+ a=-101.2,
252
+ b=-400.4,
253
+ c=-172.1,
254
+ z=(1+0j),
255
+ expected=(2.2253618341394838e+37+0j),
256
+ rtol=1e-13,
257
+ ),
258
+ ),
259
+ pytest.param(
260
+ Hyp2f1TestCase(
261
+ a=-400.4,
262
+ b=-101.2,
263
+ c=-172.1,
264
+ z=(1+0j),
265
+ expected=(2.2253618341394838e+37+0j),
266
+ rtol=5e-13,
267
+ ),
268
+ ),
269
+ pytest.param(
270
+ Hyp2f1TestCase(
271
+ a=172.5,
272
+ b=-201.3,
273
+ c=151.2,
274
+ z=(1+0j),
275
+ expected=(7.072266653650905e-135+0j),
276
+ rtol=5e-13,
277
+ ),
278
+ ),
279
+ pytest.param(
280
+ Hyp2f1TestCase(
281
+ a=-201.3,
282
+ b=172.5,
283
+ c=151.2,
284
+ z=(1+0j),
285
+ expected=(7.072266653650905e-135+0j),
286
+ rtol=5e-13,
287
+ ),
288
+ ),
289
+ pytest.param(
290
+ Hyp2f1TestCase(
291
+ a=-102.1,
292
+ b=-20.3,
293
+ c=1.3,
294
+ z=1 + 0j,
295
+ expected=2.7899070752746906e22 + 0j,
296
+ rtol=3e-14,
297
+ ),
298
+ ),
299
+ pytest.param(
300
+ Hyp2f1TestCase(
301
+ a=-202.6,
302
+ b=60.3,
303
+ c=1.5,
304
+ z=1 + 0j,
305
+ expected=-1.3113641413099326e-56 + 0j,
306
+ rtol=1e-12,
307
+ ),
308
+ ),
309
+ ],
310
+ )
311
+ def test_unital_argument(self, hyp2f1_test_case):
312
+ """Tests for case z = 1, c - a - b > 0.
313
+
314
+ Expected answers computed using mpmath.
315
+ """
316
+ a, b, c, z, expected, rtol = hyp2f1_test_case
317
+ assert z == 1 and c - a - b > 0 # Tests the test
318
+ assert_allclose(hyp2f1(a, b, c, z), expected, rtol=rtol)
319
+
320
+ @pytest.mark.parametrize(
321
+ "hyp2f1_test_case",
322
+ [
323
+ pytest.param(
324
+ Hyp2f1TestCase(
325
+ a=0.5,
326
+ b=0.2,
327
+ c=1.3,
328
+ z=-1 + 0j,
329
+ expected=0.9428846409614143 + 0j,
330
+ rtol=1e-15),
331
+ ),
332
+ pytest.param(
333
+ Hyp2f1TestCase(
334
+ a=12.3,
335
+ b=8.0,
336
+ c=5.300000000000001,
337
+ z=-1 + 0j,
338
+ expected=-4.845809986595704e-06 + 0j,
339
+ rtol=1e-15
340
+ ),
341
+ ),
342
+ pytest.param(
343
+ Hyp2f1TestCase(
344
+ a=221.5,
345
+ b=90.2,
346
+ c=132.3,
347
+ z=-1 + 0j,
348
+ expected=2.0490488728377282e-42 + 0j,
349
+ rtol=1e-7,
350
+ ),
351
+ ),
352
+ pytest.param(
353
+ Hyp2f1TestCase(
354
+ a=-102.1,
355
+ b=-20.3,
356
+ c=-80.8,
357
+ z=-1 + 0j,
358
+ expected=45143784.46783885 + 0j,
359
+ rtol=1e-7,
360
+ ),
361
+ marks=pytest.mark.xfail(
362
+ condition=sys.maxsize < 2**32,
363
+ reason="Fails on 32 bit.",
364
+ )
365
+ ),
366
+ ],
367
+ )
368
+ def test_special_case_z_near_minus_1(self, hyp2f1_test_case):
369
+ """Tests for case z ~ -1, c ~ 1 + a - b
370
+
371
+ Expected answers computed using mpmath.
372
+ """
373
+ a, b, c, z, expected, rtol = hyp2f1_test_case
374
+ assert abs(1 + a - b - c) < 1e-15 and abs(z + 1) < 1e-15
375
+ assert_allclose(hyp2f1(a, b, c, z), expected, rtol=rtol)
376
+
377
+ @pytest.mark.parametrize(
378
+ "hyp2f1_test_case",
379
+ [
380
+ pytest.param(
381
+ Hyp2f1TestCase(
382
+ a=-4,
383
+ b=2.02764642551431,
384
+ c=1.0561196186065624,
385
+ z=(0.9473684210526314-0.10526315789473695j),
386
+ expected=(0.0031961077109535375-0.0011313924606557173j),
387
+ rtol=1e-12,
388
+ ),
389
+ ),
390
+ pytest.param(
391
+ Hyp2f1TestCase(
392
+ a=-8,
393
+ b=-7.937789122896016,
394
+ c=-15.964218273004214,
395
+ z=(2-0.10526315789473695j),
396
+ expected=(0.005543763196412503-0.0025948879065698306j),
397
+ rtol=5e-13,
398
+ ),
399
+ ),
400
+ pytest.param(
401
+ Hyp2f1TestCase(
402
+ a=-8,
403
+ b=8.095813935368371,
404
+ c=4.0013768449590685,
405
+ z=(0.9473684210526314-0.10526315789473695j),
406
+ expected=(-0.0003054674127221263-9.261359291755414e-05j),
407
+ rtol=1e-10,
408
+ ),
409
+ ),
410
+ pytest.param(
411
+ Hyp2f1TestCase(
412
+ a=-4,
413
+ b=-3.956227226099288,
414
+ c=-3.9316537064827854,
415
+ z=(1.1578947368421053-0.3157894736842106j),
416
+ expected=(-0.0020809502580892937-0.0041877333232365095j),
417
+ rtol=5e-12,
418
+ ),
419
+ ),
420
+ pytest.param(
421
+ Hyp2f1TestCase(
422
+ a=2.02764642551431,
423
+ b=-4,
424
+ c=2.050308316530781,
425
+ z=(0.9473684210526314-0.10526315789473695j),
426
+ expected=(0.0011282435590058734+0.0002027062303465851j),
427
+ rtol=5e-13,
428
+ ),
429
+ ),
430
+ pytest.param(
431
+ Hyp2f1TestCase(
432
+ a=-7.937789122896016,
433
+ b=-8,
434
+ c=-15.964218273004214,
435
+ z=(1.3684210526315788+0.10526315789473673j),
436
+ expected=(-9.134907719238265e-05-0.00040219233987390723j),
437
+ rtol=5e-12,
438
+ ),
439
+ ),
440
+ pytest.param(
441
+ Hyp2f1TestCase(
442
+ a=4.080187217753502,
443
+ b=-4,
444
+ c=4.0013768449590685,
445
+ z=(0.9473684210526314-0.10526315789473695j),
446
+ expected=(-0.000519013062087489-0.0005855883076830948j),
447
+ rtol=5e-12,
448
+ ),
449
+ ),
450
+ pytest.param(
451
+ Hyp2f1TestCase(
452
+ a=-10000,
453
+ b=2.2,
454
+ c=93459345.3,
455
+ z=(2+2j),
456
+ expected=(0.9995292071559088-0.00047047067522659253j),
457
+ rtol=1e-12,
458
+ ),
459
+ ),
460
+ ]
461
+ )
462
+ def test_a_b_negative_int(self, hyp2f1_test_case):
463
+ a, b, c, z, expected, rtol = hyp2f1_test_case
464
+ assert a == int(a) and a < 0 or b == int(b) and b < 0 # Tests the test
465
+ assert_allclose(hyp2f1(a, b, c, z), expected, rtol=rtol)
466
+
467
+ @pytest.mark.parametrize(
468
+ "hyp2f1_test_case",
469
+ [
470
+ pytest.param(
471
+ Hyp2f1TestCase(
472
+ a=-0.5,
473
+ b=-0.9629749245209605,
474
+ c=-15.5,
475
+ z=(1.1578947368421053-1.1578947368421053j),
476
+ expected=(0.9778506962676361+0.044083801141231616j),
477
+ rtol=3e-12,
478
+ ),
479
+ ),
480
+ pytest.param(
481
+ Hyp2f1TestCase(
482
+ a=8.5,
483
+ b=-3.9316537064827854,
484
+ c=1.5,
485
+ z=(0.9473684210526314-0.10526315789473695j),
486
+ expected=(4.0793167523167675-10.11694246310966j),
487
+ rtol=6e-12,
488
+ ),
489
+ ),
490
+ pytest.param(
491
+ Hyp2f1TestCase(
492
+ a=8.5,
493
+ b=-0.9629749245209605,
494
+ c=2.5,
495
+ z=(1.1578947368421053-0.10526315789473695j),
496
+ expected=(-2.9692999501916915+0.6394599899845594j),
497
+ rtol=1e-11,
498
+ ),
499
+ ),
500
+ pytest.param(
501
+ Hyp2f1TestCase(
502
+ a=-0.5,
503
+ b=-0.9629749245209605,
504
+ c=-15.5,
505
+ z=(1.5789473684210522-1.1578947368421053j),
506
+ expected=(0.9493076367106102-0.04316852977183447j),
507
+ rtol=1e-11,
508
+ ),
509
+ ),
510
+ pytest.param(
511
+ Hyp2f1TestCase(
512
+ a=-0.9220024191881196,
513
+ b=-0.5,
514
+ c=-15.5,
515
+ z=(0.5263157894736841+0.10526315789473673j),
516
+ expected=(0.9844377175631795-0.003120587561483841j),
517
+ rtol=1e-10,
518
+ ),
519
+ ),
520
+ ],
521
+ )
522
+ def test_a_b_neg_int_after_euler_hypergeometric_transformation(
523
+ self, hyp2f1_test_case
524
+ ):
525
+ a, b, c, z, expected, rtol = hyp2f1_test_case
526
+ assert ( # Tests the test
527
+ (abs(c - a - int(c - a)) < 1e-15 and c - a < 0) or
528
+ (abs(c - b - int(c - b)) < 1e-15 and c - b < 0)
529
+ )
530
+ assert_allclose(hyp2f1(a, b, c, z), expected, rtol=rtol)
531
+
532
+ @pytest.mark.parametrize(
533
+ "hyp2f1_test_case",
534
+ [
535
+ pytest.param(
536
+ Hyp2f1TestCase(
537
+ a=-0.9220024191881196,
538
+ b=-0.9629749245209605,
539
+ c=-15.963511401609862,
540
+ z=(0.10526315789473673-0.3157894736842106j),
541
+ expected=(0.9941449585778349+0.01756335047931358j),
542
+ rtol=1e-14,
543
+ ),
544
+ ),
545
+ pytest.param(
546
+ Hyp2f1TestCase(
547
+ a=1.0272592605282642,
548
+ b=-0.9629749245209605,
549
+ c=-15.963511401609862,
550
+ z=(0.5263157894736841+0.5263157894736841j),
551
+ expected=(1.0388722293372104-0.09549450380041416j),
552
+ rtol=5e-11,
553
+ ),
554
+ ),
555
+ pytest.param(
556
+ Hyp2f1TestCase(
557
+ a=2.02764642551431,
558
+ b=1.0561196186065624,
559
+ c=-7.93846038215665,
560
+ z=(0.10526315789473673+0.7368421052631575j),
561
+ expected=(2.1948378809826434+24.934157235172222j),
562
+ rtol=5e-15,
563
+ ),
564
+ ),
565
+ pytest.param(
566
+ Hyp2f1TestCase(
567
+ a=2.02764642551431,
568
+ b=16.088264119063613,
569
+ c=8.031683612216888,
570
+ z=(0.3157894736842106-0.736842105263158j),
571
+ expected=(-0.4075277891264672-0.06819344579666956j),
572
+ rtol=2e-12,
573
+ ),
574
+ ),
575
+ pytest.param(
576
+ Hyp2f1TestCase(
577
+ a=4.080187217753502,
578
+ b=2.050308316530781,
579
+ c=8.031683612216888,
580
+ z=(0.7368421052631575-0.10526315789473695j),
581
+ expected=(2.833535530740603-0.6925373701408158j),
582
+ rtol=5e-15,
583
+ ),
584
+ ),
585
+ pytest.param(
586
+ Hyp2f1TestCase(
587
+ a=2.02764642551431,
588
+ b=2.050308316530781,
589
+ c=4.078873014294075,
590
+ z=(0.10526315789473673-0.3157894736842106j),
591
+ expected=(1.005347176329683-0.3580736009337313j),
592
+ rtol=5e-16,
593
+ ),
594
+ ),
595
+ pytest.param(
596
+ Hyp2f1TestCase(
597
+ a=-0.9220024191881196,
598
+ b=-0.9629749245209605,
599
+ c=-15.963511401609862,
600
+ z=(0.3157894736842106-0.5263157894736843j),
601
+ expected=(0.9824353641135369+0.029271018868990268j),
602
+ rtol=5e-13,
603
+ ),
604
+ ),
605
+ pytest.param(
606
+ Hyp2f1TestCase(
607
+ a=-0.9220024191881196,
608
+ b=-0.9629749245209605,
609
+ c=-159.63511401609862,
610
+ z=(0.3157894736842106-0.5263157894736843j),
611
+ expected=(0.9982436200365834+0.002927268199671111j),
612
+ rtol=1e-7,
613
+ ),
614
+ marks=pytest.mark.xfail(reason="Poor convergence.")
615
+ ),
616
+ pytest.param(
617
+ Hyp2f1TestCase(
618
+ a=2.02764642551431,
619
+ b=16.088264119063613,
620
+ c=8.031683612216888,
621
+ z=(0.5263157894736841-0.5263157894736843j),
622
+ expected=(-0.6906825165778091+0.8176575137504892j),
623
+ rtol=5e-13,
624
+ ),
625
+ ),
626
+ ]
627
+ )
628
+ def test_region1(self, hyp2f1_test_case):
629
+ """|z| < 0.9 and real(z) >= 0."""
630
+ a, b, c, z, expected, rtol = hyp2f1_test_case
631
+ assert abs(z) < 0.9 and z.real >= 0 # Tests the test
632
+ assert_allclose(hyp2f1(a, b, c, z), expected, rtol=rtol)
633
+
634
+ @pytest.mark.parametrize(
635
+ "hyp2f1_test_case",
636
+ [
637
+ pytest.param(
638
+ Hyp2f1TestCase(
639
+ a=2.02764642551431,
640
+ b=1.0561196186065624,
641
+ c=4.078873014294075,
642
+ z=(-0.3157894736842106+0.7368421052631575j),
643
+ expected=(0.7751915029081136+0.24068493258607315j),
644
+ rtol=5e-15,
645
+ ),
646
+ ),
647
+ pytest.param(
648
+ Hyp2f1TestCase(
649
+ a=16.087593263474208,
650
+ b=16.088264119063613,
651
+ c=2.0397202577726152,
652
+ z=(-0.9473684210526316-0.3157894736842106j),
653
+ expected=(6.564549348474962e-07+1.6761570598334562e-06j),
654
+ rtol=5e-09,
655
+ ),
656
+ ),
657
+ pytest.param(
658
+ Hyp2f1TestCase(
659
+ a=1.0272592605282642,
660
+ b=2.050308316530781,
661
+ c=16.056809865262608,
662
+ z=(-0.10526315789473695-0.10526315789473695j),
663
+ expected=(0.9862043298997204-0.013293151372712681j),
664
+ rtol=5e-15,
665
+ ),
666
+ ),
667
+ pytest.param(
668
+ Hyp2f1TestCase(
669
+ a=4.080187217753502,
670
+ b=8.077282662161238,
671
+ c=16.056809865262608,
672
+ z=(-0.3157894736842106-0.736842105263158j),
673
+ expected=(0.16163826638754716-0.41378530376373734j),
674
+ rtol=5e-15,
675
+ ),
676
+ ),
677
+ pytest.param(
678
+ Hyp2f1TestCase(
679
+ a=2.02764642551431,
680
+ b=2.050308316530781,
681
+ c=-0.906685989801748,
682
+ z=(-0.5263157894736843+0.3157894736842106j),
683
+ expected=(-6.256871535165936+0.13824973858225484j),
684
+ rtol=1e-15,
685
+ ),
686
+ ),
687
+ pytest.param(
688
+ Hyp2f1TestCase(
689
+ a=2.02764642551431,
690
+ b=8.077282662161238,
691
+ c=-3.9924618758357022,
692
+ z=(-0.9473684210526316-0.3157894736842106j),
693
+ expected=(75.54672526086316+50.56157041797548j),
694
+ rtol=5e-12,
695
+ ),
696
+ ),
697
+ pytest.param(
698
+ Hyp2f1TestCase(
699
+ a=16.087593263474208,
700
+ b=8.077282662161238,
701
+ c=-1.9631175993998025,
702
+ z=(-0.5263157894736843+0.5263157894736841j),
703
+ expected=(282.0602536306534-82.31597306936214j),
704
+ rtol=5e-13,
705
+ ),
706
+ ),
707
+ pytest.param(
708
+ Hyp2f1TestCase(
709
+ a=8.095813935368371,
710
+ b=-3.9316537064827854,
711
+ c=8.031683612216888,
712
+ z=(-0.5263157894736843-0.10526315789473695j),
713
+ expected=(5.179603735575851+1.4445374002099813j),
714
+ rtol=5e-14,
715
+ ),
716
+ ),
717
+ pytest.param(
718
+ Hyp2f1TestCase(
719
+ a=4.080187217753502,
720
+ b=-7.949900487447654,
721
+ c=1.0651378143226575,
722
+ z=(-0.3157894736842106-0.9473684210526316j),
723
+ expected=(2317.623517606141-269.51476321010324j),
724
+ rtol=5e-13,
725
+ ),
726
+ ),
727
+ pytest.param(
728
+ Hyp2f1TestCase(
729
+ a=16.087593263474208,
730
+ b=-1.92872979730171,
731
+ c=2.0397202577726152,
732
+ z=(-0.736842105263158-0.3157894736842106j),
733
+ expected=(29.179154096175836+22.126690357535043j),
734
+ rtol=5e-15,
735
+ ),
736
+ ),
737
+ pytest.param(
738
+ Hyp2f1TestCase(
739
+ a=8.095813935368371,
740
+ b=-3.9316537064827854,
741
+ c=-15.963511401609862,
742
+ z=(-0.736842105263158-0.10526315789473695j),
743
+ expected=(0.20820247892032057-0.04763956711248794j),
744
+ rtol=5e-14,
745
+ ),
746
+ ),
747
+ pytest.param(
748
+ Hyp2f1TestCase(
749
+ a=1.0272592605282642,
750
+ b=-15.964218273004214,
751
+ c=-1.9631175993998025,
752
+ z=(-0.3157894736842106-0.5263157894736843j),
753
+ expected=(-157471.63920142158+991294.0587828817j),
754
+ rtol=5e-14,
755
+ ),
756
+ ),
757
+ pytest.param(
758
+ Hyp2f1TestCase(
759
+ a=8.095813935368371,
760
+ b=-7.949900487447654,
761
+ c=-7.93846038215665,
762
+ z=(-0.10526315789473695-0.10526315789473695j),
763
+ expected=(0.30765349653210194-0.2979706363594157j),
764
+ rtol=1e-15,
765
+ ),
766
+ ),
767
+ pytest.param(
768
+ Hyp2f1TestCase(
769
+ a=-3.956227226099288,
770
+ b=1.0561196186065624,
771
+ c=8.031683612216888,
772
+ z=(-0.9473684210526316-0.10526315789473695j),
773
+ expected=(1.6787607400597109+0.10056620134616838j),
774
+ rtol=5e-14,
775
+ ),
776
+ ),
777
+ pytest.param(
778
+ Hyp2f1TestCase(
779
+ a=-7.937789122896016,
780
+ b=16.088264119063613,
781
+ c=4.078873014294075,
782
+ z=(-0.5263157894736843-0.736842105263158j),
783
+ expected=(7062.07842506049-12768.77955655703j),
784
+ rtol=5e-15,
785
+ ),
786
+ ),
787
+ pytest.param(
788
+ Hyp2f1TestCase(
789
+ a=-7.937789122896016,
790
+ b=16.088264119063613,
791
+ c=2.0397202577726152,
792
+ z=(-0.3157894736842106+0.7368421052631575j),
793
+ expected=(54749.216391029935-23078.144720887536j),
794
+ rtol=2e-15,
795
+ ),
796
+ ),
797
+ pytest.param(
798
+ Hyp2f1TestCase(
799
+ a=-3.956227226099288,
800
+ b=1.0561196186065624,
801
+ c=-0.906685989801748,
802
+ z=(-0.10526315789473695-0.10526315789473695j),
803
+ expected=(1.21521766411428-4.449385173946672j),
804
+ rtol=5e-15,
805
+ ),
806
+ ),
807
+ pytest.param(
808
+ Hyp2f1TestCase(
809
+ a=-15.980848054962111,
810
+ b=4.0013768449590685,
811
+ c=-1.9631175993998025,
812
+ z=(-0.736842105263158+0.5263157894736841j),
813
+ expected=(19234693144.196907+1617913967.7294445j),
814
+ rtol=5e-14,
815
+ ),
816
+ ),
817
+ pytest.param(
818
+ Hyp2f1TestCase(
819
+ a=-1.9214641416286231,
820
+ b=1.0561196186065624,
821
+ c=-15.963511401609862,
822
+ z=(-0.5263157894736843+0.3157894736842106j),
823
+ expected=(0.9345201094534371+0.03745712558992195j),
824
+ rtol=5e-15,
825
+ ),
826
+ ),
827
+ pytest.param(
828
+ Hyp2f1TestCase(
829
+ a=-7.937789122896016,
830
+ b=-0.9629749245209605,
831
+ c=2.0397202577726152,
832
+ z=(-0.10526315789473695+0.10526315789473673j),
833
+ expected=(0.605732446296829+0.398171533680972j),
834
+ rtol=5e-15,
835
+ ),
836
+ ),
837
+ pytest.param(
838
+ Hyp2f1TestCase(
839
+ a=-1.9214641416286231,
840
+ b=-15.964218273004214,
841
+ c=2.0397202577726152,
842
+ z=(-0.10526315789473695-0.5263157894736843j),
843
+ expected=(-9.753761888305416-4.590126012666959j),
844
+ rtol=5e-15,
845
+ ),
846
+ ),
847
+ pytest.param(
848
+ Hyp2f1TestCase(
849
+ a=-3.956227226099288,
850
+ b=-1.92872979730171,
851
+ c=2.0397202577726152,
852
+ z=(-0.10526315789473695+0.3157894736842106j),
853
+ expected=(0.45587226291120714+1.0694545265819797j),
854
+ rtol=5e-15,
855
+ ),
856
+ ),
857
+ pytest.param(
858
+ Hyp2f1TestCase(
859
+ a=-0.9220024191881196,
860
+ b=-7.949900487447654,
861
+ c=-0.906685989801748,
862
+ z=(-0.736842105263158+0.3157894736842106j),
863
+ expected=(12.334808243233418-76.26089051819054j),
864
+ rtol=5e-14,
865
+ ),
866
+ ),
867
+ pytest.param(
868
+ Hyp2f1TestCase(
869
+ a=-0.9220024191881196,
870
+ b=-7.949900487447654,
871
+ c=-15.963511401609862,
872
+ z=(-0.5263157894736843+0.10526315789473673j),
873
+ expected=(1.2396019687632678-0.047507973161146286j),
874
+ rtol=1e-14,
875
+ ),
876
+ ),
877
+ pytest.param(
878
+ Hyp2f1TestCase(
879
+ a=-15.980848054962111,
880
+ b=-0.9629749245209605,
881
+ c=-0.906685989801748,
882
+ z=(-0.3157894736842106-0.5263157894736843j),
883
+ expected=(97.7889554372208-18.999754543400016j),
884
+ rtol=5e-13,
885
+ ),
886
+ ),
887
+ ]
888
+ )
889
+ def test_region2(self, hyp2f1_test_case):
890
+ """|z| < 1 and real(z) < 0."""
891
+ a, b, c, z, expected, rtol = hyp2f1_test_case
892
+ assert abs(z) < 1 and z.real < 0 # Tests the test
893
+ assert_allclose(hyp2f1(a, b, c, z), expected, rtol=rtol)
894
+
895
+ @pytest.mark.parametrize(
896
+ "hyp2f1_test_case",
897
+ [
898
+ pytest.param(
899
+ Hyp2f1TestCase(
900
+ a=16.25,
901
+ b=-3.75,
902
+ c=-3.5,
903
+ z=(0.5263157894736841+0.7368421052631575j),
904
+ expected=(-1279.4894322256655-2302.914821389276j),
905
+ rtol=5e-14,
906
+ ),
907
+ ),
908
+ pytest.param(
909
+ Hyp2f1TestCase(
910
+ a=-15.75,
911
+ b=8.25,
912
+ c=-1.5,
913
+ z=(0.9473684210526314+0.3157894736842106j),
914
+ expected=(-8889.452798586273-11961.162305065242j),
915
+ rtol=5e-14,
916
+ ),
917
+ ),
918
+ pytest.param(
919
+ Hyp2f1TestCase(
920
+ a=2.25,
921
+ b=2.25,
922
+ c=-1.5,
923
+ z=(0.5263157894736841-0.736842105263158j),
924
+ expected=(-236.58971357952055-238.5228224781136j),
925
+ rtol=5e-15,
926
+ ),
927
+ ),
928
+ pytest.param(
929
+ Hyp2f1TestCase(
930
+ a=-0.75,
931
+ b=-7.75,
932
+ c=-15.5,
933
+ z=(0.5263157894736841+0.7368421052631575j),
934
+ expected=(0.8116076584352279-0.29360565398246036j),
935
+ rtol=5e-16,
936
+ ),
937
+ ),
938
+ pytest.param(
939
+ Hyp2f1TestCase(
940
+ a=1.25,
941
+ b=4.25,
942
+ c=-0.5,
943
+ z=(0.5263157894736841-0.736842105263158j),
944
+ expected=(-28.119407485189985+98.89858821348005j),
945
+ rtol=5e-15,
946
+ ),
947
+ ),
948
+ pytest.param(
949
+ Hyp2f1TestCase(
950
+ a=-0.75,
951
+ b=2.25,
952
+ c=1.5,
953
+ z=(0.5263157894736841+0.7368421052631575j),
954
+ expected=(0.5311049067450484-0.9434347326448517j),
955
+ rtol=5e-14,
956
+ ),
957
+ ),
958
+ pytest.param(
959
+ Hyp2f1TestCase(
960
+ a=8.25,
961
+ b=-15.75,
962
+ c=-7.5,
963
+ z=(0.9473684210526314+0.10526315789473673j),
964
+ expected=(1262084.378141873+1775569.6338380123j),
965
+ rtol=5e-14,
966
+ ),
967
+ ),
968
+ pytest.param(
969
+ Hyp2f1TestCase(
970
+ a=-15.75,
971
+ b=-7.75,
972
+ c=-15.5,
973
+ z=(0.5263157894736841-0.736842105263158j),
974
+ expected=(-0.009810480794804165+0.3648997569257999j),
975
+ rtol=1e-15,
976
+ ),
977
+ ),
978
+ pytest.param(
979
+ Hyp2f1TestCase(
980
+ a=8.25,
981
+ b=2.25,
982
+ c=-3.5,
983
+ z=(0.5263157894736841-0.736842105263158j),
984
+ expected=(585660.8815535795-33646.68398590896j),
985
+ rtol=5e-14,
986
+ ),
987
+ ),
988
+ pytest.param(
989
+ Hyp2f1TestCase(
990
+ a=4.080187217753502,
991
+ b=-3.9316537064827854,
992
+ c=-15.963511401609862,
993
+ z=(0.9473684210526314-0.10526315789473695j),
994
+ expected=(181899621848365.2-173207123998705.7j),
995
+ rtol=5e-14,
996
+ ),
997
+ ),
998
+ pytest.param(
999
+ Hyp2f1TestCase(
1000
+ a=-15.75,
1001
+ b=8.25,
1002
+ c=-0.5,
1003
+ z=(0.9473684210526314-0.10526315789473695j),
1004
+ expected=(0.04271686244952705-0.14087902824639406j),
1005
+ rtol=5e-14,
1006
+ ),
1007
+ ),
1008
+ pytest.param(
1009
+ Hyp2f1TestCase(
1010
+ a=-7.937789122896016,
1011
+ b=-1.92872979730171,
1012
+ c=-0.906685989801748,
1013
+ z=(0.9473684210526314-0.3157894736842106j),
1014
+ expected=(-449.5119088817207+320.1423128036188j),
1015
+ rtol=5e-14,
1016
+ ),
1017
+ ),
1018
+ pytest.param(
1019
+ Hyp2f1TestCase(
1020
+ a=-3.956227226099288,
1021
+ b=1.0561196186065624,
1022
+ c=8.031683612216888,
1023
+ z=(0.9473684210526314-0.10526315789473695j),
1024
+ expected=(0.6361479738012501+0.028575620091205088j),
1025
+ rtol=5e-15,
1026
+ ),
1027
+ ),
1028
+ pytest.param(
1029
+ Hyp2f1TestCase(
1030
+ a=4.25,
1031
+ b=16.25,
1032
+ c=16.5,
1033
+ z=(0.5263157894736841+0.7368421052631575j),
1034
+ expected=(-0.9038811840552261-1.5356250756164884j),
1035
+ rtol=1e-8,
1036
+ ),
1037
+ marks=pytest.mark.xfail(
1038
+ reason="Unhandled parameters."
1039
+ )
1040
+ ),
1041
+ pytest.param(
1042
+ Hyp2f1TestCase(
1043
+ a=8.25,
1044
+ b=-1.75,
1045
+ c=-1.5,
1046
+ z=(0.9473684210526314+0.3157894736842106j),
1047
+ expected=(653.0109150415394-4554.162605155542j),
1048
+ rtol=1e-15,
1049
+ ),
1050
+ ),
1051
+ pytest.param(
1052
+ Hyp2f1TestCase(
1053
+ a=-15.75,
1054
+ b=-3.75,
1055
+ c=4.5,
1056
+ z=(0.9473684210526314-0.10526315789473695j),
1057
+ expected=(118.7009859241035-34.18713648654642j),
1058
+ rtol=1e-15,
1059
+ ),
1060
+ ),
1061
+ pytest.param(
1062
+ Hyp2f1TestCase(
1063
+ a=4.25,
1064
+ b=-15.75,
1065
+ c=-3.5,
1066
+ z=(0.5263157894736841+0.7368421052631575j),
1067
+ expected=(-540204.4774526551+4970059.109251281j),
1068
+ rtol=1e-14,
1069
+ ),
1070
+ ),
1071
+ pytest.param(
1072
+ Hyp2f1TestCase(
1073
+ a=8.25,
1074
+ b=-15.75,
1075
+ c=-0.5,
1076
+ z=(0.5263157894736841-0.736842105263158j),
1077
+ expected=(2253490.972258385+3318620.683390017j),
1078
+ rtol=5e-13,
1079
+ ),
1080
+ ),
1081
+ pytest.param(
1082
+ Hyp2f1TestCase(
1083
+ a=16.25,
1084
+ b=-7.75,
1085
+ c=-7.5,
1086
+ z=(0.9473684210526314+0.3157894736842106j),
1087
+ expected=(-46159826.46716958-17880663.82218242j),
1088
+ rtol=5e-14,
1089
+ ),
1090
+ ),
1091
+ pytest.param(
1092
+ Hyp2f1TestCase(
1093
+ a=-0.9220024191881196,
1094
+ b=-7.949900487447654,
1095
+ c=-7.93846038215665,
1096
+ z=(0.9473684210526314-0.10526315789473695j),
1097
+ expected=(0.07116833581404514+0.11823358038036977j),
1098
+ rtol=5e-13,
1099
+ ),
1100
+ ),
1101
+ pytest.param(
1102
+ Hyp2f1TestCase(
1103
+ a=16.087593263474208,
1104
+ b=4.0013768449590685,
1105
+ c=-7.93846038215665,
1106
+ z=(0.7368421052631575+0.5263157894736841j),
1107
+ expected=(4.7724909620664006e+17-6.039064078946702e+16j),
1108
+ rtol=5e-13,
1109
+ ),
1110
+ ),
1111
+ pytest.param(
1112
+ Hyp2f1TestCase(
1113
+ a=1.25,
1114
+ b=-7.75,
1115
+ c=1.5,
1116
+ z=(0.9473684210526314-0.10526315789473695j),
1117
+ expected=(0.0188022179759303+0.002921737281641378j),
1118
+ rtol=5e-15,
1119
+ ),
1120
+ ),
1121
+ pytest.param(
1122
+ Hyp2f1TestCase(
1123
+ a=1.0272592605282642,
1124
+ b=1.0561196186065624,
1125
+ c=-7.93846038215665,
1126
+ z=(0.7368421052631575-0.5263157894736843j),
1127
+ expected=(-9203.462928334846+12390.110518017136j),
1128
+ rtol=5e-13,
1129
+ ),
1130
+ ),
1131
+ pytest.param(
1132
+ Hyp2f1TestCase(
1133
+ a=-3.75,
1134
+ b=-15.75,
1135
+ c=8.5,
1136
+ z=(0.7368421052631575+0.5263157894736841j),
1137
+ expected=(6.468457061368628+24.190040684917374j),
1138
+ rtol=6e-16,
1139
+ ),
1140
+ ),
1141
+ pytest.param(
1142
+ Hyp2f1TestCase(
1143
+ a=2.02764642551431,
1144
+ b=16.088264119063613,
1145
+ c=2.0397202577726152,
1146
+ z=(0.7368421052631575+0.5263157894736841j),
1147
+ expected=(2408.3451340186543-4275.257316636014j),
1148
+ rtol=5e-14,
1149
+ ),
1150
+ ),
1151
+ pytest.param(
1152
+ Hyp2f1TestCase(
1153
+ a=-3.75,
1154
+ b=-7.75,
1155
+ c=8.5,
1156
+ z=(0.7368421052631575-0.5263157894736843j),
1157
+ expected=(4.1379984626381345-5.183654781039423j),
1158
+ rtol=5e-15,
1159
+ ),
1160
+ ),
1161
+ pytest.param(
1162
+ Hyp2f1TestCase(
1163
+ a=8.25,
1164
+ b=-7.75,
1165
+ c=-0.5,
1166
+ z=(0.5263157894736841+0.7368421052631575j),
1167
+ expected=(-81177.775295738+56079.73286548954j),
1168
+ rtol=5e-14,
1169
+ ),
1170
+ ),
1171
+ pytest.param(
1172
+ Hyp2f1TestCase(
1173
+ a=4.080187217753502,
1174
+ b=2.050308316530781,
1175
+ c=-0.906685989801748,
1176
+ z=(0.9473684210526314+0.3157894736842106j),
1177
+ expected=(1192868.5068926765+3624210.8182139914j),
1178
+ rtol=5e-14,
1179
+ ),
1180
+ ),
1181
+ pytest.param(
1182
+ Hyp2f1TestCase(
1183
+ a=-7.937789122896016,
1184
+ b=-1.92872979730171,
1185
+ c=8.031683612216888,
1186
+ z=(0.5263157894736841+0.7368421052631575j),
1187
+ expected=(1.8286341846195202+1.9295255682312178j),
1188
+ rtol=5e-14,
1189
+ ),
1190
+ ),
1191
+ pytest.param(
1192
+ Hyp2f1TestCase(
1193
+ a=1.0272592605282642,
1194
+ b=1.0561196186065624,
1195
+ c=16.056809865262608,
1196
+ z=(0.7368421052631575-0.5263157894736843j),
1197
+ expected=(1.0514645669696452-0.0430834059440128j),
1198
+ rtol=5e-10,
1199
+ ),
1200
+ ),
1201
+ pytest.param(
1202
+ Hyp2f1TestCase(
1203
+ a=16.087593263474208,
1204
+ b=-15.964218273004214,
1205
+ c=2.0397202577726152,
1206
+ z=(0.5263157894736841+0.7368421052631575j),
1207
+ expected=(541983.236432269+288200.2043029435j),
1208
+ rtol=5e-13,
1209
+ ),
1210
+ ),
1211
+ pytest.param(
1212
+ Hyp2f1TestCase(
1213
+ a=2.25,
1214
+ b=8.25,
1215
+ c=1.5,
1216
+ z=(0.5263157894736841-0.736842105263158j),
1217
+ expected=(-10.931988086039945+1.9136272843579096j),
1218
+ rtol=1e-15,
1219
+ ),
1220
+ ),
1221
+ ]
1222
+ )
1223
+ def test_region3(self, hyp2f1_test_case):
1224
+ """0.9 <= |z| <= 1 and |1 - z| < 0.9."""
1225
+ a, b, c, z, expected, rtol = hyp2f1_test_case
1226
+ assert 0.9 <= abs(z) <= 1 and abs(1 - z) < 0.9 # Tests the test
1227
+ assert_allclose(hyp2f1(a, b, c, z), expected, rtol=rtol)
1228
+
1229
+ @pytest.mark.parametrize(
1230
+ "hyp2f1_test_case",
1231
+ [
1232
+ pytest.param(
1233
+ Hyp2f1TestCase(
1234
+ a=16.25,
1235
+ b=4.25,
1236
+ c=2.5,
1237
+ z=(0.4931034482758623-0.7965517241379311j),
1238
+ expected=(38.41207903409937-30.510151276075792j),
1239
+ rtol=5e-14,
1240
+ ),
1241
+ ),
1242
+ pytest.param(
1243
+ Hyp2f1TestCase(
1244
+ a=2.0,
1245
+ b=16.087593263474208,
1246
+ c=16.088264119063613,
1247
+ z=(0.5689655172413794-0.7965517241379311j),
1248
+ expected=(-0.6667857912761286-1.0206224321443573j),
1249
+ rtol=1e-15,
1250
+ ),
1251
+ ),
1252
+ pytest.param(
1253
+ Hyp2f1TestCase(
1254
+ a=8.0,
1255
+ b=1.0272592605282642,
1256
+ c=-7.949900487447654,
1257
+ z=(0.4931034482758623-0.7965517241379311j),
1258
+ expected=(1679024.1647997478-2748129.775857212j),
1259
+ rtol=5e-14,
1260
+ ),
1261
+ ),
1262
+ pytest.param(
1263
+ Hyp2f1TestCase(
1264
+ a=4.080187217753502,
1265
+ b=16.0,
1266
+ c=-7.949900487447654,
1267
+ z=(0.4931034482758623-0.7965517241379311j),
1268
+ expected=(424747226301.16986-1245539049327.2856j),
1269
+ rtol=1e-14,
1270
+ ),
1271
+ ),
1272
+ pytest.param(
1273
+ Hyp2f1TestCase(
1274
+ a=2.02764642551431,
1275
+ b=-15.964218273004214,
1276
+ c=4.0,
1277
+ z=(0.4931034482758623-0.7965517241379311j),
1278
+ expected=(-0.0057826199201757595+0.026359861999025885j),
1279
+ rtol=5e-06,
1280
+ ),
1281
+ ),
1282
+ pytest.param(
1283
+ Hyp2f1TestCase(
1284
+ a=2.02764642551431,
1285
+ b=-0.9629749245209605,
1286
+ c=2.0397202577726152,
1287
+ z=(0.5689655172413794-0.7965517241379311j),
1288
+ expected=(0.4671901063492606+0.7769632229834897j),
1289
+ rtol=5e-14,
1290
+ ),
1291
+ ),
1292
+ pytest.param(
1293
+ Hyp2f1TestCase(
1294
+ a=2.0,
1295
+ b=-3.956227226099288,
1296
+ c=-7.949900487447654,
1297
+ z=(0.4931034482758623+0.7965517241379312j),
1298
+ expected=(0.9422283708145973+1.3476905754773343j),
1299
+ rtol=5e-15,
1300
+ ),
1301
+ ),
1302
+ pytest.param(
1303
+ Hyp2f1TestCase(
1304
+ a=1.0,
1305
+ b=-15.980848054962111,
1306
+ c=-15.964218273004214,
1307
+ z=(0.4931034482758623-0.7965517241379311j),
1308
+ expected=(0.4168719497319604-0.9770953555235625j),
1309
+ rtol=5e-10,
1310
+ ),
1311
+ ),
1312
+ pytest.param(
1313
+ Hyp2f1TestCase(
1314
+ a=-0.5,
1315
+ b=16.088264119063613,
1316
+ c=2.5,
1317
+ z=(0.5689655172413794+0.7965517241379312j),
1318
+ expected=(1.279096377550619-2.173827694297929j),
1319
+ rtol=5e-12,
1320
+ ),
1321
+ ),
1322
+ pytest.param(
1323
+ Hyp2f1TestCase(
1324
+ a=-1.9214641416286231,
1325
+ b=4.0013768449590685,
1326
+ c=2.0397202577726152,
1327
+ z=(0.4931034482758623+0.7965517241379312j),
1328
+ expected=(-2.071520656161738-0.7846098268395909j),
1329
+ rtol=5e-14,
1330
+ ),
1331
+ ),
1332
+ pytest.param(
1333
+ Hyp2f1TestCase(
1334
+ a=-0.9220024191881196,
1335
+ b=8.0,
1336
+ c=-0.9629749245209605,
1337
+ z=(0.5689655172413794-0.7965517241379311j),
1338
+ expected=(-7.740015495862889+3.386766435696699j),
1339
+ rtol=5e-12,
1340
+ ),
1341
+ ),
1342
+ pytest.param(
1343
+ Hyp2f1TestCase(
1344
+ a=-1.9214641416286231,
1345
+ b=16.088264119063613,
1346
+ c=-7.93846038215665,
1347
+ z=(0.4931034482758623+0.7965517241379312j),
1348
+ expected=(-6318.553685853241-7133.416085202879j),
1349
+ rtol=5e-9,
1350
+ ),
1351
+ ),
1352
+ pytest.param(
1353
+ Hyp2f1TestCase(
1354
+ a=-15.980848054962111,
1355
+ b=-3.9316537064827854,
1356
+ c=16.056809865262608,
1357
+ z=(0.5689655172413794+0.7965517241379312j),
1358
+ expected=(-0.8854577905547399+8.135089099967278j),
1359
+ rtol=5e-14,
1360
+ ),
1361
+ ),
1362
+ pytest.param(
1363
+ Hyp2f1TestCase(
1364
+ a=-1.9214641416286231,
1365
+ b=-0.9629749245209605,
1366
+ c=4.078873014294075,
1367
+ z=(0.4931034482758623+0.7965517241379312j),
1368
+ expected=(1.224291301521487+0.36014711766402485j),
1369
+ rtol=1e-15,
1370
+ ),
1371
+ ),
1372
+ pytest.param(
1373
+ Hyp2f1TestCase(
1374
+ a=-15.75,
1375
+ b=-0.75,
1376
+ c=-1.5,
1377
+ z=(0.4931034482758623+0.7965517241379312j),
1378
+ expected=(-1.5765685855028473-3.9399766961046323j),
1379
+ rtol=1e-3,
1380
+ ),
1381
+ marks=pytest.mark.xfail(
1382
+ reason="Unhandled parameters."
1383
+ )
1384
+ ),
1385
+ pytest.param(
1386
+ Hyp2f1TestCase(
1387
+ a=-15.980848054962111,
1388
+ b=-1.92872979730171,
1389
+ c=-7.93846038215665,
1390
+ z=(0.5689655172413794-0.7965517241379311j),
1391
+ expected=(56.794588688231194+4.556286783533971j),
1392
+ rtol=5e-14,
1393
+ ),
1394
+ ),
1395
+ pytest.param(
1396
+ Hyp2f1TestCase(
1397
+ a=4.5,
1398
+ b=4.5,
1399
+ c=2.050308316530781,
1400
+ z=(0.5689655172413794+0.7965517241379312j),
1401
+ expected=(-4.251456563455306+6.737837111569671j),
1402
+ rtol=5e-14,
1403
+ ),
1404
+ ),
1405
+ pytest.param(
1406
+ Hyp2f1TestCase(
1407
+ a=4.5,
1408
+ b=8.5,
1409
+ c=-1.92872979730171,
1410
+ z=(0.4931034482758623-0.7965517241379311j),
1411
+ expected=(2177143.9156599627-3313617.2748088865j),
1412
+ rtol=5e-14,
1413
+ ),
1414
+ ),
1415
+ pytest.param(
1416
+ Hyp2f1TestCase(
1417
+ a=2.5,
1418
+ b=-1.5,
1419
+ c=4.0013768449590685,
1420
+ z=(0.4931034482758623-0.7965517241379311j),
1421
+ expected=(0.45563554481603946+0.6212000158060831j),
1422
+ rtol=5e-14,
1423
+ ),
1424
+ ),
1425
+ pytest.param(
1426
+ Hyp2f1TestCase(
1427
+ a=8.5,
1428
+ b=-7.5,
1429
+ c=-15.964218273004214,
1430
+ z=(0.4931034482758623+0.7965517241379312j),
1431
+ expected=(61.03201617828073-37.185626416756214j),
1432
+ rtol=5e-14,
1433
+ ),
1434
+ ),
1435
+ pytest.param(
1436
+ Hyp2f1TestCase(
1437
+ a=-15.5,
1438
+ b=16.5,
1439
+ c=4.0013768449590685,
1440
+ z=(0.4931034482758623+0.7965517241379312j),
1441
+ expected=(-33143.425963520735+20790.608514722644j),
1442
+ rtol=1e-14,
1443
+ ),
1444
+ ),
1445
+ pytest.param(
1446
+ Hyp2f1TestCase(
1447
+ a=-0.5,
1448
+ b=4.5,
1449
+ c=-0.9629749245209605,
1450
+ z=(0.5689655172413794+0.7965517241379312j),
1451
+ expected=(30.778600270824423-26.65160354466787j),
1452
+ rtol=5e-13,
1453
+ ),
1454
+ ),
1455
+ pytest.param(
1456
+ Hyp2f1TestCase(
1457
+ a=-0.5,
1458
+ b=-3.5,
1459
+ c=16.088264119063613,
1460
+ z=(0.5689655172413794-0.7965517241379311j),
1461
+ expected=(1.0629792615560487-0.08308454486044772j),
1462
+ rtol=1e-15,
1463
+ ),
1464
+ ),
1465
+ pytest.param(
1466
+ Hyp2f1TestCase(
1467
+ a=-3.5,
1468
+ b=-7.5,
1469
+ c=-0.9629749245209605,
1470
+ z=(0.4931034482758623-0.7965517241379311j),
1471
+ expected=(17431.571802591767+3553.7129767034507j),
1472
+ rtol=5e-14,
1473
+ ),
1474
+ ),
1475
+ pytest.param(
1476
+ Hyp2f1TestCase(
1477
+ a=2.25,
1478
+ b=8.25,
1479
+ c=16.5,
1480
+ z=(0.11379310344827598+0.9482758620689657j),
1481
+ expected=(0.4468600750211926+0.7313214934036885j),
1482
+ rtol=1e-3,
1483
+ ),
1484
+ marks=pytest.mark.xfail(
1485
+ reason="Unhandled parameters."
1486
+ )
1487
+ ),
1488
+ pytest.param(
1489
+ Hyp2f1TestCase(
1490
+ a=8.25,
1491
+ b=16.25,
1492
+ c=4.5,
1493
+ z=(0.3413793103448277+0.8724137931034486j),
1494
+ expected=(-3.905704438293991+3.693347860329299j),
1495
+ rtol=5e-14,
1496
+ ),
1497
+ ),
1498
+ pytest.param(
1499
+ Hyp2f1TestCase(
1500
+ a=4.25,
1501
+ b=4.25,
1502
+ c=-0.5,
1503
+ z=(0.11379310344827598-0.9482758620689655j),
1504
+ expected=(-40.31777941834244-89.89852492432011j),
1505
+ rtol=5e-15,
1506
+ ),
1507
+ ),
1508
+ pytest.param(
1509
+ Hyp2f1TestCase(
1510
+ a=1.0272592605282642,
1511
+ b=8.0,
1512
+ c=-15.964218273004214,
1513
+ z=(0.11379310344827598-0.9482758620689655j),
1514
+ expected=(52584.347773055284-109197.86244309516j),
1515
+ rtol=5e-14,
1516
+ ),
1517
+ ),
1518
+ pytest.param(
1519
+ Hyp2f1TestCase(
1520
+ a=8.095813935368371,
1521
+ b=-15.964218273004214,
1522
+ c=16.056809865262608,
1523
+ z=(0.03793103448275881+0.9482758620689657j),
1524
+ expected=(-1.187733570412592-1.5147865053584582j),
1525
+ rtol=5e-10,
1526
+ ),
1527
+ ),
1528
+ pytest.param(
1529
+ Hyp2f1TestCase(
1530
+ a=4.080187217753502,
1531
+ b=-3.9316537064827854,
1532
+ c=1.0651378143226575,
1533
+ z=(0.26551724137931054+0.9482758620689657j),
1534
+ expected=(13.077494677898947+35.071599628224966j),
1535
+ rtol=5e-13,
1536
+ ),
1537
+ ),
1538
+ pytest.param(
1539
+ Hyp2f1TestCase(
1540
+ a=4.080187217753502,
1541
+ b=-3.5,
1542
+ c=-3.5,
1543
+ z=(0.26551724137931054+0.8724137931034486j),
1544
+ expected=(-0.5359656237994614-0.2344483936591811j),
1545
+ rtol=5e-15,
1546
+ ),
1547
+ ),
1548
+ pytest.param(
1549
+ Hyp2f1TestCase(
1550
+ a=4.25,
1551
+ b=-3.75,
1552
+ c=-1.5,
1553
+ z=(0.26551724137931054+0.9482758620689657j),
1554
+ expected=(1204.8114871663133+64.41022826840198j),
1555
+ rtol=5e-13,
1556
+ ),
1557
+ ),
1558
+ pytest.param(
1559
+ Hyp2f1TestCase(
1560
+ a=-1.9214641416286231,
1561
+ b=16.0,
1562
+ c=4.0013768449590685,
1563
+ z=(0.03793103448275881-0.9482758620689655j),
1564
+ expected=(-9.85268872413994+7.011107558429154j),
1565
+ rtol=5e-15,
1566
+ ),
1567
+ ),
1568
+ pytest.param(
1569
+ Hyp2f1TestCase(
1570
+ a=-7.937789122896016,
1571
+ b=16.0,
1572
+ c=4.0013768449590685,
1573
+ z=(0.3413793103448277-0.8724137931034484j),
1574
+ expected=(528.5522951158454-1412.21630264791j),
1575
+ rtol=5e-14,
1576
+ ),
1577
+ ),
1578
+ pytest.param(
1579
+ Hyp2f1TestCase(
1580
+ a=-15.5,
1581
+ b=1.0561196186065624,
1582
+ c=-7.5,
1583
+ z=(0.4172413793103451+0.8724137931034486j),
1584
+ expected=(133306.45260685298+256510.7045225382j),
1585
+ rtol=5e-15,
1586
+ ),
1587
+ ),
1588
+ pytest.param(
1589
+ Hyp2f1TestCase(
1590
+ a=-7.937789122896016,
1591
+ b=8.077282662161238,
1592
+ c=-15.963511401609862,
1593
+ z=(0.3413793103448277-0.8724137931034484j),
1594
+ expected=(-0.998555715276967+2.774198742229889j),
1595
+ rtol=5e-11,
1596
+ ),
1597
+ ),
1598
+ pytest.param(
1599
+ Hyp2f1TestCase(
1600
+ a=-7.75,
1601
+ b=-0.75,
1602
+ c=1.5,
1603
+ z=(0.11379310344827598-0.9482758620689655j),
1604
+ expected=(2.072445019723025-2.9793504811373515j),
1605
+ rtol=5e-14,
1606
+ ),
1607
+ ),
1608
+ pytest.param(
1609
+ Hyp2f1TestCase(
1610
+ a=-15.5,
1611
+ b=-1.92872979730171,
1612
+ c=1.5,
1613
+ z=(0.11379310344827598-0.9482758620689655j),
1614
+ expected=(-41.87581944176649-32.52980303527139j),
1615
+ rtol=5e-13,
1616
+ ),
1617
+ ),
1618
+ pytest.param(
1619
+ Hyp2f1TestCase(
1620
+ a=-3.75,
1621
+ b=-15.75,
1622
+ c=-0.5,
1623
+ z=(0.11379310344827598-0.9482758620689655j),
1624
+ expected=(-3729.6214864209774-30627.510509112635j),
1625
+ rtol=5e-15,
1626
+ ),
1627
+ ),
1628
+ pytest.param(
1629
+ Hyp2f1TestCase(
1630
+ a=-3.956227226099288,
1631
+ b=-15.964218273004214,
1632
+ c=-0.906685989801748,
1633
+ z=(0.03793103448275881+0.9482758620689657j),
1634
+ expected=(-131615.07820609974+145596.13384245415j),
1635
+ rtol=5e-15,
1636
+ ),
1637
+ ),
1638
+ pytest.param(
1639
+ Hyp2f1TestCase(
1640
+ a=1.5,
1641
+ b=16.5,
1642
+ c=16.088264119063613,
1643
+ z=(0.26551724137931054+0.8724137931034486j),
1644
+ expected=(0.18981844071070744+0.7855036242583742j),
1645
+ rtol=1e-15,
1646
+ ),
1647
+ ),
1648
+ pytest.param(
1649
+ Hyp2f1TestCase(
1650
+ a=16.5,
1651
+ b=8.5,
1652
+ c=-3.9316537064827854,
1653
+ z=(0.11379310344827598-0.9482758620689655j),
1654
+ expected=(110224529.2376068+128287212.04290268j),
1655
+ rtol=5e-13,
1656
+ ),
1657
+ ),
1658
+ pytest.param(
1659
+ Hyp2f1TestCase(
1660
+ a=2.5,
1661
+ b=-7.5,
1662
+ c=4.0013768449590685,
1663
+ z=(0.3413793103448277-0.8724137931034484j),
1664
+ expected=(0.2722302180888523-0.21790187837266162j),
1665
+ rtol=1.2e-12,
1666
+ ),
1667
+ ),
1668
+ pytest.param(
1669
+ Hyp2f1TestCase(
1670
+ a=8.5,
1671
+ b=-7.5,
1672
+ c=-15.964218273004214,
1673
+ z=(0.11379310344827598-0.9482758620689655j),
1674
+ expected=(-2.8252338010989035+2.430661949756161j),
1675
+ rtol=5e-14,
1676
+ ),
1677
+ ),
1678
+ pytest.param(
1679
+ Hyp2f1TestCase(
1680
+ a=-3.5,
1681
+ b=16.5,
1682
+ c=4.0013768449590685,
1683
+ z=(0.03793103448275881+0.9482758620689657j),
1684
+ expected=(-20.604894257647945+74.5109432558078j),
1685
+ rtol=5e-15,
1686
+ ),
1687
+ ),
1688
+ pytest.param(
1689
+ Hyp2f1TestCase(
1690
+ a=-7.5,
1691
+ b=8.5,
1692
+ c=-0.9629749245209605,
1693
+ z=(0.3413793103448277+0.8724137931034486j),
1694
+ expected=(-2764422.521269463-3965966.9965808876j),
1695
+ rtol=5e-14,
1696
+ ),
1697
+ ),
1698
+ pytest.param(
1699
+ Hyp2f1TestCase(
1700
+ a=-1.5,
1701
+ b=-0.5,
1702
+ c=1.0561196186065624,
1703
+ z=(0.26551724137931054+0.9482758620689657j),
1704
+ expected=(1.2262338560994905+0.6545051266925549j),
1705
+ rtol=1e-15,
1706
+ ),
1707
+ ),
1708
+ pytest.param(
1709
+ Hyp2f1TestCase(
1710
+ a=-0.5,
1711
+ b=-15.5,
1712
+ c=-7.949900487447654,
1713
+ z=(0.4172413793103451-0.8724137931034484j),
1714
+ expected=(-2258.1590330318213+8860.193389158803j),
1715
+ rtol=1.4e-10,
1716
+ ),
1717
+ ),
1718
+ ]
1719
+ )
1720
+ def test_region4(self, hyp2f1_test_case):
1721
+ """0.9 <= |z| <= 1 and |1 - z| >= 1.
1722
+
1723
+ This region is unhandled by of the standard transformations and
1724
+ needs special care.
1725
+ """
1726
+ a, b, c, z, expected, rtol = hyp2f1_test_case
1727
+ assert 0.9 <= abs(z) <= 1 and abs(1 - z) >= 0.9 # Tests the test
1728
+ assert_allclose(hyp2f1(a, b, c, z), expected, rtol=rtol)
1729
+
1730
+ @pytest.mark.parametrize(
1731
+ "hyp2f1_test_case",
1732
+ [
1733
+ pytest.param(
1734
+ Hyp2f1TestCase(
1735
+ a=4.5,
1736
+ b=16.088264119063613,
1737
+ c=8.5,
1738
+ z=(0.6448275862068968+0.8724137931034486j),
1739
+ expected=(0.018601324701770394-0.07618420586062377j),
1740
+ rtol=5e-08,
1741
+ ),
1742
+ ),
1743
+ pytest.param(
1744
+ Hyp2f1TestCase(
1745
+ a=8.25,
1746
+ b=4.25,
1747
+ c=4.5,
1748
+ z=(0.6448275862068968-0.8724137931034484j),
1749
+ expected=(-1.391549471425551-0.118036604903893j),
1750
+ rtol=5e-15,
1751
+ ),
1752
+ ),
1753
+ pytest.param(
1754
+ Hyp2f1TestCase(
1755
+ a=2.02764642551431,
1756
+ b=2.050308316530781,
1757
+ c=-1.9631175993998025,
1758
+ z=(0.6448275862068968+0.8724137931034486j),
1759
+ expected=(-2309.178768155151-1932.7247727595172j),
1760
+ rtol=5e-15,
1761
+ ),
1762
+ ),
1763
+ pytest.param(
1764
+ Hyp2f1TestCase(
1765
+ a=16.087593263474208,
1766
+ b=1.0,
1767
+ c=-15.964218273004214,
1768
+ z=(0.6448275862068968+0.8724137931034486j),
1769
+ expected=(85592537010.05054-8061416766688.324j),
1770
+ rtol=2e-14,
1771
+ ),
1772
+ ),
1773
+ pytest.param(
1774
+ Hyp2f1TestCase(
1775
+ a=8.095813935368371,
1776
+ b=-0.5,
1777
+ c=1.5,
1778
+ z=(0.6448275862068968+0.8724137931034486j),
1779
+ expected=(1.2334498208515172-2.1639498536219732j),
1780
+ rtol=5e-11,
1781
+ ),
1782
+ ),
1783
+ pytest.param(
1784
+ Hyp2f1TestCase(
1785
+ a=16.087593263474208,
1786
+ b=-15.964218273004214,
1787
+ c=4.0,
1788
+ z=(0.6448275862068968+0.8724137931034486j),
1789
+ expected=(102266.35398605966-44976.97828737755j),
1790
+ rtol=1e-3,
1791
+ ),
1792
+ marks=pytest.mark.xfail(
1793
+ reason="Unhandled parameters."
1794
+ )
1795
+ ),
1796
+ pytest.param(
1797
+ Hyp2f1TestCase(
1798
+ a=4.0,
1799
+ b=-3.956227226099288,
1800
+ c=-15.964218273004214,
1801
+ z=(0.6448275862068968-0.8724137931034484j),
1802
+ expected=(-2.9590030930007236-4.190770764773225j),
1803
+ rtol=5e-13,
1804
+ ),
1805
+ ),
1806
+ pytest.param(
1807
+ Hyp2f1TestCase(
1808
+ a=4.080187217753502,
1809
+ b=-15.5,
1810
+ c=-7.5,
1811
+ z=(0.5689655172413794-0.8724137931034484j),
1812
+ expected=(-112554838.92074208+174941462.9202412j),
1813
+ rtol=5e-05,
1814
+ ),
1815
+ ),
1816
+ pytest.param(
1817
+ Hyp2f1TestCase(
1818
+ a=-15.980848054962111,
1819
+ b=2.050308316530781,
1820
+ c=1.0,
1821
+ z=(0.6448275862068968-0.8724137931034484j),
1822
+ expected=(3.7519882374080145+7.360753798667486j),
1823
+ rtol=5e-13,
1824
+ ),
1825
+ ),
1826
+ pytest.param(
1827
+ Hyp2f1TestCase(
1828
+ a=-7.937789122896016,
1829
+ b=2.050308316530781,
1830
+ c=4.0,
1831
+ z=(0.6448275862068968-0.8724137931034484j),
1832
+ expected=(0.000181132943964693+0.07742903103815582j),
1833
+ rtol=5e-14,
1834
+ ),
1835
+ ),
1836
+ pytest.param(
1837
+ Hyp2f1TestCase(
1838
+ a=-7.937789122896016,
1839
+ b=4.0013768449590685,
1840
+ c=-1.9631175993998025,
1841
+ z=(0.5689655172413794+0.8724137931034486j),
1842
+ expected=(386338.760913596-386166.51762171905j),
1843
+ rtol=5e-15,
1844
+ ),
1845
+ ),
1846
+ pytest.param(
1847
+ Hyp2f1TestCase(
1848
+ a=-15.980848054962111,
1849
+ b=8.0,
1850
+ c=-1.92872979730171,
1851
+ z=(0.6448275862068968+0.8724137931034486j),
1852
+ expected=(1348667126.3444858-2375132427.158893j),
1853
+ rtol=5e-14,
1854
+ ),
1855
+ ),
1856
+ pytest.param(
1857
+ Hyp2f1TestCase(
1858
+ a=-3.5,
1859
+ b=-0.9629749245209605,
1860
+ c=4.5,
1861
+ z=(0.5689655172413794+0.8724137931034486j),
1862
+ expected=(1.428353429538678+0.6472718120804372j),
1863
+ rtol=5e-15,
1864
+ ),
1865
+ ),
1866
+ pytest.param(
1867
+ Hyp2f1TestCase(
1868
+ a=-7.937789122896016,
1869
+ b=-0.9629749245209605,
1870
+ c=2.0397202577726152,
1871
+ z=(0.5689655172413794-0.8724137931034484j),
1872
+ expected=(3.1439267526119643-3.145305240375117j),
1873
+ rtol=5e-14,
1874
+ ),
1875
+ ),
1876
+ pytest.param(
1877
+ Hyp2f1TestCase(
1878
+ a=-1.9214641416286231,
1879
+ b=-15.964218273004214,
1880
+ c=-7.93846038215665,
1881
+ z=(0.6448275862068968-0.8724137931034484j),
1882
+ expected=(75.27467675681773+144.0946946292215j),
1883
+ rtol=1e-07,
1884
+ ),
1885
+ ),
1886
+ pytest.param(
1887
+ Hyp2f1TestCase(
1888
+ a=-3.75,
1889
+ b=-7.75,
1890
+ c=-7.5,
1891
+ z=(0.5689655172413794+0.8724137931034486j),
1892
+ expected=(-0.3699450626264222+0.8732812475910993j),
1893
+ rtol=5e-15,
1894
+ ),
1895
+ ),
1896
+ pytest.param(
1897
+ Hyp2f1TestCase(
1898
+ a=1.5,
1899
+ b=16.5,
1900
+ c=1.0561196186065624,
1901
+ z=(0.5689655172413794-0.8724137931034484j),
1902
+ expected=(5.5361025821300665-2.4709693474656285j),
1903
+ rtol=5e-09,
1904
+ ),
1905
+ ),
1906
+ pytest.param(
1907
+ Hyp2f1TestCase(
1908
+ a=1.5,
1909
+ b=8.5,
1910
+ c=-3.9316537064827854,
1911
+ z=(0.6448275862068968-0.8724137931034484j),
1912
+ expected=(-782805.6699207705-537192.581278909j),
1913
+ rtol=5e-14,
1914
+ ),
1915
+ ),
1916
+ pytest.param(
1917
+ Hyp2f1TestCase(
1918
+ a=2.5,
1919
+ b=-15.5,
1920
+ c=1.0561196186065624,
1921
+ z=(0.6448275862068968+0.8724137931034486j),
1922
+ expected=(12.345113400639693-14.993248992902007j),
1923
+ rtol=0.0005,
1924
+ ),
1925
+ ),
1926
+ pytest.param(
1927
+ Hyp2f1TestCase(
1928
+ a=1.5,
1929
+ b=-0.5,
1930
+ c=-15.964218273004214,
1931
+ z=(0.6448275862068968+0.8724137931034486j),
1932
+ expected=(23.698109392667842+97.15002033534108j),
1933
+ rtol=5e-14,
1934
+ ),
1935
+ ),
1936
+ pytest.param(
1937
+ Hyp2f1TestCase(
1938
+ a=-7.5,
1939
+ b=16.5,
1940
+ c=4.0013768449590685,
1941
+ z=(0.6448275862068968-0.8724137931034484j),
1942
+ expected=(1115.2978631811834+915.9212658718577j),
1943
+ rtol=5e-15,
1944
+ ),
1945
+ ),
1946
+ pytest.param(
1947
+ Hyp2f1TestCase(
1948
+ a=-15.5,
1949
+ b=16.5,
1950
+ c=-0.9629749245209605,
1951
+ z=(0.6448275862068968+0.8724137931034486j),
1952
+ expected=(642077722221.6489+535274495398.21027j),
1953
+ rtol=5e-15,
1954
+ ),
1955
+ ),
1956
+ pytest.param(
1957
+ Hyp2f1TestCase(
1958
+ a=-7.5,
1959
+ b=-3.5,
1960
+ c=4.0013768449590685,
1961
+ z=(0.5689655172413794+0.8724137931034486j),
1962
+ expected=(-5.689219222945697+16.877463062787143j),
1963
+ rtol=5e-15,
1964
+ ),
1965
+ ),
1966
+ pytest.param(
1967
+ Hyp2f1TestCase(
1968
+ a=-15.5,
1969
+ b=-1.5,
1970
+ c=-0.9629749245209605,
1971
+ z=(0.5689655172413794-0.8724137931034484j),
1972
+ expected=(-44.32070290703576+1026.9127058617403j),
1973
+ rtol=5e-14,
1974
+ ),
1975
+ ),
1976
+ pytest.param(
1977
+ Hyp2f1TestCase(
1978
+ a=16.25,
1979
+ b=2.25,
1980
+ c=4.5,
1981
+ z=(0.11379310344827598-1.024137931034483j),
1982
+ expected=(-0.021965227124574663+0.009908300237809064j),
1983
+ rtol=1e-3,
1984
+ ),
1985
+ marks=pytest.mark.xfail(
1986
+ reason="Unhandled parameters."
1987
+ )
1988
+ ),
1989
+ pytest.param(
1990
+ Hyp2f1TestCase(
1991
+ a=2.02764642551431,
1992
+ b=1.5,
1993
+ c=16.5,
1994
+ z=(0.26551724137931054+1.024137931034483j),
1995
+ expected=(1.0046072901244183+0.19945500134119992j),
1996
+ rtol=5e-14,
1997
+ ),
1998
+ ),
1999
+ pytest.param(
2000
+ Hyp2f1TestCase(
2001
+ a=16.087593263474208,
2002
+ b=1.0,
2003
+ c=-3.9316537064827854,
2004
+ z=(0.3413793103448277+0.9482758620689657j),
2005
+ expected=(21022.30133421465+49175.98317370489j),
2006
+ rtol=5e-13,
2007
+ ),
2008
+ ),
2009
+ pytest.param(
2010
+ Hyp2f1TestCase(
2011
+ a=4.080187217753502,
2012
+ b=16.088264119063613,
2013
+ c=-1.9631175993998025,
2014
+ z=(0.4172413793103451-0.9482758620689655j),
2015
+ expected=(-7024239.358547302+2481375.02681063j),
2016
+ rtol=5e-14,
2017
+ ),
2018
+ ),
2019
+ pytest.param(
2020
+ Hyp2f1TestCase(
2021
+ a=16.25,
2022
+ b=-15.75,
2023
+ c=1.5,
2024
+ z=(0.18965517241379315+1.024137931034483j),
2025
+ expected=(92371704.94848-403546832.548352j),
2026
+ rtol=5e-06,
2027
+ ),
2028
+ ),
2029
+ pytest.param(
2030
+ Hyp2f1TestCase(
2031
+ a=8.5,
2032
+ b=-7.949900487447654,
2033
+ c=8.5,
2034
+ z=(0.26551724137931054-1.024137931034483j),
2035
+ expected=(1.9335109845308265+5.986542524829654j),
2036
+ rtol=5e-10,
2037
+ ),
2038
+ ),
2039
+ pytest.param(
2040
+ Hyp2f1TestCase(
2041
+ a=8.095813935368371,
2042
+ b=-1.92872979730171,
2043
+ c=-7.93846038215665,
2044
+ z=(0.4931034482758623+0.8724137931034486j),
2045
+ expected=(-122.52639696039328-59.72428067512221j),
2046
+ rtol=5e-14,
2047
+ ),
2048
+ ),
2049
+ pytest.param(
2050
+ Hyp2f1TestCase(
2051
+ a=16.25,
2052
+ b=-1.75,
2053
+ c=-1.5,
2054
+ z=(0.4931034482758623+0.9482758620689657j),
2055
+ expected=(-90.40642053579428+50.50649180047921j),
2056
+ rtol=5e-08,
2057
+ ),
2058
+ ),
2059
+ pytest.param(
2060
+ Hyp2f1TestCase(
2061
+ a=-3.5,
2062
+ b=8.077282662161238,
2063
+ c=16.5,
2064
+ z=(0.4931034482758623+0.9482758620689657j),
2065
+ expected=(-0.2155745818150323-0.564628986876639j),
2066
+ rtol=5e-15,
2067
+ ),
2068
+ ),
2069
+ pytest.param(
2070
+ Hyp2f1TestCase(
2071
+ a=-0.9220024191881196,
2072
+ b=1.0561196186065624,
2073
+ c=8.031683612216888,
2074
+ z=(0.4172413793103451-0.9482758620689655j),
2075
+ expected=(0.9503140488280465+0.11574960074292677j),
2076
+ rtol=5e-15,
2077
+ ),
2078
+ ),
2079
+ pytest.param(
2080
+ Hyp2f1TestCase(
2081
+ a=-0.75,
2082
+ b=2.25,
2083
+ c=-15.5,
2084
+ z=(0.4172413793103451+0.9482758620689657j),
2085
+ expected=(0.9285862488442175+0.8203699266719692j),
2086
+ rtol=5e-13,
2087
+ ),
2088
+ ),
2089
+ pytest.param(
2090
+ Hyp2f1TestCase(
2091
+ a=-7.75,
2092
+ b=4.25,
2093
+ c=-15.5,
2094
+ z=(0.3413793103448277-0.9482758620689655j),
2095
+ expected=(-1.0509834850116921-1.1145522325486075j),
2096
+ rtol=1.1e-14,
2097
+ ),
2098
+ ),
2099
+ pytest.param(
2100
+ Hyp2f1TestCase(
2101
+ a=-7.937789122896016,
2102
+ b=-0.9629749245209605,
2103
+ c=2.0397202577726152,
2104
+ z=(0.4931034482758623-0.9482758620689655j),
2105
+ expected=(2.88119116536769-3.4249933450696806j),
2106
+ rtol=5e-15,
2107
+ ),
2108
+ ),
2109
+ pytest.param(
2110
+ Hyp2f1TestCase(
2111
+ a=-15.5,
2112
+ b=-15.964218273004214,
2113
+ c=16.5,
2114
+ z=(0.18965517241379315+1.024137931034483j),
2115
+ expected=(199.65868451496038+347.79384207302877j),
2116
+ rtol=5e-12,
2117
+ ),
2118
+ ),
2119
+ pytest.param(
2120
+ Hyp2f1TestCase(
2121
+ a=-15.75,
2122
+ b=-15.75,
2123
+ c=-3.5,
2124
+ z=(0.4931034482758623-0.8724137931034484j),
2125
+ expected=(-208138312553.07013+58631611809.026955j),
2126
+ rtol=5e-14,
2127
+ ),
2128
+ ),
2129
+ pytest.param(
2130
+ Hyp2f1TestCase(
2131
+ a=-7.937789122896016,
2132
+ b=-15.5,
2133
+ c=-7.5,
2134
+ z=(0.3413793103448277+0.9482758620689657j),
2135
+ expected=(-23032.90519856288-18256.94050457296j),
2136
+ rtol=5e-15,
2137
+ ),
2138
+ ),
2139
+ pytest.param(
2140
+ Hyp2f1TestCase(
2141
+ a=4.5,
2142
+ b=1.5,
2143
+ c=1.0561196186065624,
2144
+ z=(0.4931034482758623-0.8724137931034484j),
2145
+ expected=(1.507342459587056+1.2332023580148403j),
2146
+ rtol=1e-15,
2147
+ ),
2148
+ ),
2149
+ pytest.param(
2150
+ Hyp2f1TestCase(
2151
+ a=2.5,
2152
+ b=4.5,
2153
+ c=-3.9316537064827854,
2154
+ z=(0.4172413793103451+0.9482758620689657j),
2155
+ expected=(7044.766127108853-40210.365567285575j),
2156
+ rtol=5e-14,
2157
+ ),
2158
+ ),
2159
+ pytest.param(
2160
+ Hyp2f1TestCase(
2161
+ a=1.5,
2162
+ b=-1.5,
2163
+ c=1.0561196186065624,
2164
+ z=(0.03793103448275881+1.024137931034483j),
2165
+ expected=(0.2725347741628333-2.247314875514784j),
2166
+ rtol=1e-15,
2167
+ ),
2168
+ ),
2169
+ pytest.param(
2170
+ Hyp2f1TestCase(
2171
+ a=4.5,
2172
+ b=-1.5,
2173
+ c=-7.949900487447654,
2174
+ z=(0.26551724137931054+1.024137931034483j),
2175
+ expected=(-11.250200011017546+12.597393659160472j),
2176
+ rtol=5e-14,
2177
+ ),
2178
+ ),
2179
+ pytest.param(
2180
+ Hyp2f1TestCase(
2181
+ a=-7.5,
2182
+ b=8.5,
2183
+ c=16.088264119063613,
2184
+ z=(0.26551724137931054+1.024137931034483j),
2185
+ expected=(-0.18515160890991517+0.7959014164484782j),
2186
+ rtol=2e-15,
2187
+ ),
2188
+ ),
2189
+ pytest.param(
2190
+ Hyp2f1TestCase(
2191
+ a=-7.5,
2192
+ b=16.5,
2193
+ c=-3.9316537064827854,
2194
+ z=(0.3413793103448277-1.024137931034483j),
2195
+ expected=(998246378.8556538+1112032928.103645j),
2196
+ rtol=5e-14,
2197
+ ),
2198
+ ),
2199
+ pytest.param(
2200
+ Hyp2f1TestCase(
2201
+ a=-1.5,
2202
+ b=-3.5,
2203
+ c=2.050308316530781,
2204
+ z=(0.03793103448275881+1.024137931034483j),
2205
+ expected=(0.5527670397711952+2.697662715303637j),
2206
+ rtol=1.2e-15, # rtol bumped from 1e-15 in gh18414
2207
+ ),
2208
+ ),
2209
+ pytest.param(
2210
+ Hyp2f1TestCase(
2211
+ a=-15.5,
2212
+ b=-1.5,
2213
+ c=-0.9629749245209605,
2214
+ z=(0.4931034482758623-0.8724137931034484j),
2215
+ expected=(55.396931662136886+968.467463806326j),
2216
+ rtol=5e-14,
2217
+ ),
2218
+ ),
2219
+ ]
2220
+ )
2221
+ def test_region5(self, hyp2f1_test_case):
2222
+ """1 < |z| < 1.1 and |1 - z| >= 0.9 and real(z) >= 0"""
2223
+ a, b, c, z, expected, rtol = hyp2f1_test_case
2224
+ assert 1 < abs(z) < 1.1 and abs(1 - z) >= 0.9 and z.real >= 0
2225
+ assert_allclose(hyp2f1(a, b, c, z), expected, rtol=rtol)
2226
+
2227
+ @pytest.mark.parametrize(
2228
+ "hyp2f1_test_case",
2229
+ [
2230
+ pytest.param(
2231
+ Hyp2f1TestCase(
2232
+ a=8.095813935368371,
2233
+ b=4.0013768449590685,
2234
+ c=4.078873014294075,
2235
+ z=(-0.9473684210526316+0.5263157894736841j),
2236
+ expected=(-0.0018093573941378783+0.003481887377423739j),
2237
+ rtol=5e-15,
2238
+ ),
2239
+ ),
2240
+ pytest.param(
2241
+ Hyp2f1TestCase(
2242
+ a=16.087593263474208,
2243
+ b=2.050308316530781,
2244
+ c=1.0651378143226575,
2245
+ z=(-0.736842105263158-0.736842105263158j),
2246
+ expected=(-0.00023401243818780545-1.7983496305603562e-05j),
2247
+ rtol=1e-15,
2248
+ ),
2249
+ ),
2250
+ pytest.param(
2251
+ Hyp2f1TestCase(
2252
+ a=1.0272592605282642,
2253
+ b=8.077282662161238,
2254
+ c=4.078873014294075,
2255
+ z=(-0.5263157894736843-0.9473684210526316j),
2256
+ expected=(0.22359773002226846-0.24092487123993353j),
2257
+ rtol=1e-15,
2258
+ ),
2259
+ ),
2260
+ pytest.param(
2261
+ Hyp2f1TestCase(
2262
+ a=1.0272592605282642,
2263
+ b=2.050308316530781,
2264
+ c=-15.963511401609862,
2265
+ z=(-0.9473684210526316-0.5263157894736843j),
2266
+ expected=(1.191573745740011+0.14347394589721466j),
2267
+ rtol=5e-14,
2268
+ ),
2269
+ ),
2270
+ pytest.param(
2271
+ Hyp2f1TestCase(
2272
+ a=4.080187217753502,
2273
+ b=4.0013768449590685,
2274
+ c=-15.963511401609862,
2275
+ z=(-0.9473684210526316-0.5263157894736843j),
2276
+ expected=(31.822620756901784-66.09094396747611j),
2277
+ rtol=5e-14,
2278
+ ),
2279
+ ),
2280
+ pytest.param(
2281
+ Hyp2f1TestCase(
2282
+ a=4.080187217753502,
2283
+ b=8.077282662161238,
2284
+ c=-7.93846038215665,
2285
+ z=(-0.9473684210526316+0.5263157894736841j),
2286
+ expected=(207.16750179245952+34.80478274924269j),
2287
+ rtol=5e-12,
2288
+ ),
2289
+ ),
2290
+ pytest.param(
2291
+ Hyp2f1TestCase(
2292
+ a=8.095813935368371,
2293
+ b=-7.949900487447654,
2294
+ c=8.031683612216888,
2295
+ z=(-0.736842105263158+0.7368421052631575j),
2296
+ expected=(-159.62429364277145+9.154224290644898j),
2297
+ rtol=5e-14,
2298
+ ),
2299
+ ),
2300
+ pytest.param(
2301
+ Hyp2f1TestCase(
2302
+ a=1.0272592605282642,
2303
+ b=-1.92872979730171,
2304
+ c=16.056809865262608,
2305
+ z=(-0.9473684210526316+0.5263157894736841j),
2306
+ expected=(1.121122351247184-0.07170260470126685j),
2307
+ rtol=5e-15,
2308
+ ),
2309
+ ),
2310
+ pytest.param(
2311
+ Hyp2f1TestCase(
2312
+ a=16.087593263474208,
2313
+ b=-0.9629749245209605,
2314
+ c=16.056809865262608,
2315
+ z=(-0.9473684210526316+0.5263157894736841j),
2316
+ expected=(1.9040596681316053-0.4951799449960107j),
2317
+ rtol=5e-14,
2318
+ ),
2319
+ ),
2320
+ pytest.param(
2321
+ Hyp2f1TestCase(
2322
+ a=1.0272592605282642,
2323
+ b=-1.92872979730171,
2324
+ c=-0.906685989801748,
2325
+ z=(-0.9473684210526316-0.5263157894736843j),
2326
+ expected=(-14.496623497780739-21.897524523299875j),
2327
+ rtol=5e-14,
2328
+ ),
2329
+ ),
2330
+ pytest.param(
2331
+ Hyp2f1TestCase(
2332
+ a=4.080187217753502,
2333
+ b=-3.9316537064827854,
2334
+ c=-3.9924618758357022,
2335
+ z=(-0.5263157894736843-0.9473684210526316j),
2336
+ expected=(36.33473466026878+253.88728442029577j),
2337
+ rtol=5e-14,
2338
+ ),
2339
+ ),
2340
+ pytest.param(
2341
+ Hyp2f1TestCase(
2342
+ a=1.0272592605282642,
2343
+ b=-15.964218273004214,
2344
+ c=-0.906685989801748,
2345
+ z=(-0.9473684210526316+0.5263157894736841j),
2346
+ expected=(1505052.5653144997-50820766.81043443j),
2347
+ rtol=1e-14,
2348
+ ),
2349
+ ),
2350
+ pytest.param(
2351
+ Hyp2f1TestCase(
2352
+ a=-3.956227226099288,
2353
+ b=4.0013768449590685,
2354
+ c=1.0651378143226575,
2355
+ z=(-0.5263157894736843+0.9473684210526314j),
2356
+ expected=(-127.79407519260877-28.69899444941112j),
2357
+ rtol=5e-15,
2358
+ ),
2359
+ ),
2360
+ pytest.param(
2361
+ Hyp2f1TestCase(
2362
+ a=-1.9214641416286231,
2363
+ b=8.077282662161238,
2364
+ c=16.056809865262608,
2365
+ z=(-0.9473684210526316-0.5263157894736843j),
2366
+ expected=(2.0623331933754976+0.741234463565458j),
2367
+ rtol=5e-15,
2368
+ ),
2369
+ ),
2370
+ pytest.param(
2371
+ Hyp2f1TestCase(
2372
+ a=-3.956227226099288,
2373
+ b=8.077282662161238,
2374
+ c=2.0397202577726152,
2375
+ z=(-0.9473684210526316+0.5263157894736841j),
2376
+ expected=(30.729193458862525-292.5700835046965j),
2377
+ rtol=1e-15,
2378
+ ),
2379
+ ),
2380
+ pytest.param(
2381
+ Hyp2f1TestCase(
2382
+ a=-1.9214641416286231,
2383
+ b=1.0561196186065624,
2384
+ c=-1.9631175993998025,
2385
+ z=(-0.5263157894736843-0.9473684210526316j),
2386
+ expected=(1.1285917906203495-0.735264575450189j),
2387
+ rtol=5e-15,
2388
+ ),
2389
+ ),
2390
+ pytest.param(
2391
+ Hyp2f1TestCase(
2392
+ a=-0.9220024191881196,
2393
+ b=1.0561196186065624,
2394
+ c=-3.9924618758357022,
2395
+ z=(-0.736842105263158+0.7368421052631575j),
2396
+ expected=(0.6356474446678052-0.02429663008952248j),
2397
+ rtol=5e-14,
2398
+ ),
2399
+ ),
2400
+ pytest.param(
2401
+ Hyp2f1TestCase(
2402
+ a=-1.9214641416286231,
2403
+ b=16.088264119063613,
2404
+ c=-7.93846038215665,
2405
+ z=(-0.736842105263158+0.7368421052631575j),
2406
+ expected=(0.4718880510273174+0.655083067736377j),
2407
+ rtol=1e-11,
2408
+ ),
2409
+ ),
2410
+ pytest.param(
2411
+ Hyp2f1TestCase(
2412
+ a=-7.937789122896016,
2413
+ b=-3.9316537064827854,
2414
+ c=16.056809865262608,
2415
+ z=(-0.9473684210526316+0.5263157894736841j),
2416
+ expected=(-0.14681550942352714+0.16092206364265146j),
2417
+ rtol=5e-11,
2418
+ ),
2419
+ ),
2420
+ pytest.param(
2421
+ Hyp2f1TestCase(
2422
+ a=-0.9220024191881196,
2423
+ b=-15.964218273004214,
2424
+ c=1.0651378143226575,
2425
+ z=(-0.5263157894736843+0.9473684210526314j),
2426
+ expected=(-6.436835190526225+22.883156700606182j),
2427
+ rtol=5e-14,
2428
+ ),
2429
+ ),
2430
+ pytest.param(
2431
+ Hyp2f1TestCase(
2432
+ a=-0.9220024191881196,
2433
+ b=-7.949900487447654,
2434
+ c=4.078873014294075,
2435
+ z=(-0.9473684210526316-0.5263157894736843j),
2436
+ expected=(-0.7505682955068583-1.1026583264249945j),
2437
+ rtol=5e-14,
2438
+ ),
2439
+ ),
2440
+ pytest.param(
2441
+ Hyp2f1TestCase(
2442
+ a=-3.956227226099288,
2443
+ b=-3.9316537064827854,
2444
+ c=-7.93846038215665,
2445
+ z=(-0.9473684210526316-0.5263157894736843j),
2446
+ expected=(3.6247814989198166+2.596041360148318j),
2447
+ rtol=5e-15,
2448
+ ),
2449
+ ),
2450
+ pytest.param(
2451
+ Hyp2f1TestCase(
2452
+ a=-3.956227226099288,
2453
+ b=-15.964218273004214,
2454
+ c=-1.9631175993998025,
2455
+ z=(-0.5263157894736843-0.9473684210526316j),
2456
+ expected=(-59537.65287927933-669074.4342539902j),
2457
+ rtol=5e-15,
2458
+ ),
2459
+ ),
2460
+ pytest.param(
2461
+ Hyp2f1TestCase(
2462
+ a=-3.956227226099288,
2463
+ b=-15.964218273004214,
2464
+ c=-1.9631175993998025,
2465
+ z=(-0.9473684210526316-0.5263157894736843j),
2466
+ expected=(-433084.9970266166+431088.393918521j),
2467
+ rtol=5e-14,
2468
+ ),
2469
+ ),
2470
+ pytest.param(
2471
+ Hyp2f1TestCase(
2472
+ a=1,
2473
+ b=1,
2474
+ c=4,
2475
+ z=(3 + 4j),
2476
+ expected=(0.49234384000963544+0.6051340616612397j),
2477
+ rtol=5e-14,
2478
+ ),
2479
+ ),
2480
+ ]
2481
+ )
2482
+ def test_region6(self, hyp2f1_test_case):
2483
+ """|z| > 1 but not in region 5."""
2484
+ a, b, c, z, expected, rtol = hyp2f1_test_case
2485
+ assert (
2486
+ abs(z) > 1 and
2487
+ not (1 < abs(z) < 1.1 and abs(1 - z) >= 0.9 and z.real >= 0)
2488
+ )
2489
+ assert_allclose(hyp2f1(a, b, c, z), expected, rtol=rtol)
2490
+
2491
+
2492
+ @pytest.mark.parametrize(
2493
+ "hyp2f1_test_case",
2494
+ [
2495
+ # Broke when fixing gamma pole behavior in gh-21827
2496
+ pytest.param(
2497
+ Hyp2f1TestCase(
2498
+ a=1.3,
2499
+ b=-0.2,
2500
+ c=0.3,
2501
+ z=-2.1,
2502
+ expected=1.8202169687521206,
2503
+ rtol=5e-15,
2504
+ ),
2505
+ ),
2506
+ ]
2507
+ )
2508
+ def test_miscellaneous(self, hyp2f1_test_case ):
2509
+ a, b, c, z, expected, rtol = hyp2f1_test_case
2510
+ assert_allclose(hyp2f1(a, b, c, z), expected, rtol=rtol)
2511
+
2512
+ @pytest.mark.slow
2513
+ @check_version(mpmath, "1.0.0")
2514
+ def test_test_hyp2f1(self):
2515
+ """Test that expected values match what is computed by mpmath.
2516
+
2517
+ This gathers the parameters for the test cases out of the pytest marks.
2518
+ The parameters are a, b, c, z, expected, rtol, where expected should
2519
+ be the value of hyp2f1(a, b, c, z) computed with mpmath. The test
2520
+ recomputes hyp2f1(a, b, c, z) using mpmath and verifies that expected
2521
+ actually is the correct value. This allows the data for the tests to
2522
+ live within the test code instead of an external datafile, while
2523
+ avoiding having to compute the results with mpmath during the test,
2524
+ except for when slow tests are being run.
2525
+ """
2526
+ test_methods = [
2527
+ test_method for test_method in dir(self)
2528
+ if test_method.startswith('test') and
2529
+ # Filter properties and attributes (futureproofing).
2530
+ callable(getattr(self, test_method)) and
2531
+ # Filter out this test
2532
+ test_method != 'test_test_hyp2f1'
2533
+ ]
2534
+ for test_method in test_methods:
2535
+ params = self._get_test_parameters(getattr(self, test_method))
2536
+ for a, b, c, z, expected, _ in params:
2537
+ assert_allclose(mp_hyp2f1(a, b, c, z), expected, rtol=2.25e-16)
2538
+
2539
+ def _get_test_parameters(self, test_method):
2540
+ """Get pytest.mark parameters for a test in this class."""
2541
+ return [
2542
+ case.values[0] for mark in test_method.pytestmark
2543
+ if mark.name == 'parametrize'
2544
+ for case in mark.args[1]
2545
+ ]
2546
+
2547
+ class TestHyp2f1ExtremeInputs:
2548
+
2549
+ @pytest.mark.parametrize("a", [1.0, 2.0, 3.0, -np.inf, np.inf])
2550
+ @pytest.mark.parametrize("b", [3.0, 4.0, 5.0, -np.inf, np.inf])
2551
+ @pytest.mark.parametrize("c", [3.0, 5.0, 6.0, 7.0])
2552
+ @pytest.mark.parametrize("z", [4.0 + 1.0j])
2553
+ def test_inf_a_b(self, a, b, c, z):
2554
+ if np.any(np.isinf(np.asarray([a, b]))):
2555
+ assert(np.isnan(hyp2f1(a, b, c, z)))
2556
+
2557
+ def test_large_a_b(self):
2558
+ assert(np.isnan(hyp2f1(10**7, 1.0, 3.0, 4.0 + 1.0j)))
2559
+ assert(np.isnan(hyp2f1(-10**7, 1.0, 3.0, 4.0 + 1.0j)))
2560
+
2561
+ assert(np.isnan(hyp2f1(1.0, 10**7, 3.0, 4.0 + 1.0j)))
2562
+ assert(np.isnan(hyp2f1(1.0, -10**7, 3.0, 4.0 + 1.0j)))
2563
+
2564
+ # Already correct in main but testing for surety
2565
+ assert(np.isnan(hyp2f1(np.inf, 1.0, 3.0, 4.0)))
2566
+ assert(np.isnan(hyp2f1(1.0, np.inf, 3.0, 4.0)))
.venv/lib/python3.12/site-packages/scipy/special/tests/test_hypergeometric.py ADDED
@@ -0,0 +1,234 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ @pytest.mark.parametrize(
27
+ 'a,b,x,expected',
28
+ [(0.21581740448533887, 1.0, 1e-05, 3.6030558839391325),
29
+ (0.21581740448533887, 1.0, 0.00021544346900318823, 2.8783254988948976),
30
+ (0.21581740448533887, 1.0, 0.004641588833612777, 2.154928216691109),
31
+ (0.21581740448533887, 1.0, 0.1, 1.446546638718792),
32
+ (0.0030949064301273865, 1.0, 1e-05, 1.0356696454116199),
33
+ (0.0030949064301273865, 1.0, 0.00021544346900318823, 1.0261510362481985),
34
+ (0.0030949064301273865, 1.0, 0.004641588833612777, 1.0166326903402296),
35
+ (0.0030949064301273865, 1.0, 0.1, 1.0071174207698674),
36
+ (0.1509924314279033, 1.0, 1e-05, 2.806173846998948),
37
+ (0.1509924314279033, 1.0, 0.00021544346900318823, 2.3092158526816124),
38
+ (0.1509924314279033, 1.0, 0.004641588833612777, 1.812905980588048),
39
+ (0.1509924314279033, 1.0, 0.1, 1.3239738117634872),
40
+ (-0.010678995342969011, 1.0, 1e-05, 0.8775194903781114),
41
+ (-0.010678995342969011, 1.0, 0.00021544346900318823, 0.9101008998540128),
42
+ (-0.010678995342969011, 1.0, 0.004641588833612777, 0.9426854294058609),
43
+ (-0.010678995342969011, 1.0, 0.1, 0.9753065150174902),
44
+ (-0.06556622211831487, 1.0, 1e-05, 0.26435429752668904),
45
+ (-0.06556622211831487, 1.0, 0.00021544346900318823, 0.4574756033875781),
46
+ (-0.06556622211831487, 1.0, 0.004641588833612777, 0.6507121093358457),
47
+ (-0.06556622211831487, 1.0, 0.1, 0.8453129788602187),
48
+ (-0.21628242470175185, 1.0, 1e-05, -1.2318314201114489),
49
+ (-0.21628242470175185, 1.0, 0.00021544346900318823, -0.6704694233529538),
50
+ (-0.21628242470175185, 1.0, 0.004641588833612777, -0.10795098653682857),
51
+ (-0.21628242470175185, 1.0, 0.1, 0.4687227684115524)]
52
+ )
53
+ def test_gh_15650_mp(self, a, b, x, expected):
54
+ # See https://github.com/scipy/scipy/issues/15650
55
+ # b == 1, |a| < 0.25, 0 < x < 1
56
+ #
57
+ # This purpose of this test is to check the accuracy of results
58
+ # in the region that was impacted by gh-15650.
59
+ #
60
+ # Reference values computed with mpmath using the script:
61
+ #
62
+ # import itertools as it
63
+ # import numpy as np
64
+ #
65
+ # from mpmath import mp
66
+ #
67
+ # rng = np.random.default_rng(1234)
68
+ #
69
+ # cases = []
70
+ # for a, x in it.product(
71
+ # np.random.uniform(-0.25, 0.25, size=6),
72
+ # np.logspace(-5, -1, 4),
73
+ # ):
74
+ # with mp.workdps(100):
75
+ # cases.append((float(a), 1.0, float(x), float(mp.hyperu(a, 1.0, x))))
76
+ assert_allclose(sc.hyperu(a, b, x), expected, rtol=1e-13)
77
+
78
+ def test_gh_15650_sanity(self):
79
+ # The purpose of this test is to sanity check hyperu in the region that
80
+ # was impacted by gh-15650 by making sure there are no excessively large
81
+ # results, as were reported there.
82
+ a = np.linspace(-0.5, 0.5, 500)
83
+ x = np.linspace(1e-6, 1e-1, 500)
84
+ a, x = np.meshgrid(a, x)
85
+ results = sc.hyperu(a, 1.0, x)
86
+ assert np.all(np.abs(results) < 1e3)
87
+
88
+
89
+ class TestHyp1f1:
90
+
91
+ @pytest.mark.parametrize('a, b, x', [
92
+ (np.nan, 1, 1),
93
+ (1, np.nan, 1),
94
+ (1, 1, np.nan)
95
+ ])
96
+ def test_nan_inputs(self, a, b, x):
97
+ assert np.isnan(sc.hyp1f1(a, b, x))
98
+
99
+ def test_poles(self):
100
+ assert_equal(sc.hyp1f1(1, [0, -1, -2, -3, -4], 0.5), np.inf)
101
+
102
+ @pytest.mark.parametrize('a, b, x, result', [
103
+ (-1, 1, 0.5, 0.5),
104
+ (1, 1, 0.5, 1.6487212707001281468),
105
+ (2, 1, 0.5, 2.4730819060501922203),
106
+ (1, 2, 0.5, 1.2974425414002562937),
107
+ (-10, 1, 0.5, -0.38937441413785204475)
108
+ ])
109
+ def test_special_cases(self, a, b, x, result):
110
+ # Hit all the special case branches at the beginning of the
111
+ # function. Desired answers computed using Mpmath.
112
+ assert_allclose(sc.hyp1f1(a, b, x), result, atol=0, rtol=1e-15)
113
+
114
+ @pytest.mark.parametrize('a, b, x, result', [
115
+ (1, 1, 0.44, 1.5527072185113360455),
116
+ (-1, 1, 0.44, 0.55999999999999999778),
117
+ (100, 100, 0.89, 2.4351296512898745592),
118
+ (-100, 100, 0.89, 0.40739062490768104667),
119
+ (1.5, 100, 59.99, 3.8073513625965598107),
120
+ (-1.5, 100, 59.99, 0.25099240047125826943)
121
+ ])
122
+ def test_geometric_convergence(self, a, b, x, result):
123
+ # Test the region where we are relying on the ratio of
124
+ #
125
+ # (|a| + 1) * |x| / |b|
126
+ #
127
+ # being small. Desired answers computed using Mpmath
128
+ assert_allclose(sc.hyp1f1(a, b, x), result, atol=0, rtol=1e-15)
129
+
130
+ @pytest.mark.parametrize('a, b, x, result', [
131
+ (-1, 1, 1.5, -0.5),
132
+ (-10, 1, 1.5, 0.41801777430943080357),
133
+ (-25, 1, 1.5, 0.25114491646037839809),
134
+ (-50, 1, 1.5, -0.25683643975194756115),
135
+ (-80, 1, 1.5, -0.24554329325751503601),
136
+ (-150, 1, 1.5, -0.173364795515420454496),
137
+ ])
138
+ def test_a_negative_integer(self, a, b, x, result):
139
+ # Desired answers computed using Mpmath.
140
+ assert_allclose(sc.hyp1f1(a, b, x), result, atol=0, rtol=2e-14)
141
+
142
+ @pytest.mark.parametrize('a, b, x, expected', [
143
+ (0.01, 150, -4, 0.99973683897677527773), # gh-3492
144
+ (1, 5, 0.01, 1.0020033381011970966), # gh-3593
145
+ (50, 100, 0.01, 1.0050126452421463411), # gh-3593
146
+ (1, 0.3, -1e3, -7.011932249442947651455e-04), # gh-14149
147
+ (1, 0.3, -1e4, -7.001190321418937164734e-05), # gh-14149
148
+ (9, 8.5, -350, -5.224090831922378361082e-20), # gh-17120
149
+ (9, 8.5, -355, -4.595407159813368193322e-20), # gh-17120
150
+ (75, -123.5, 15, 3.425753920814889017493e+06),
151
+ ])
152
+ def test_assorted_cases(self, a, b, x, expected):
153
+ # Expected values were computed with mpmath.hyp1f1(a, b, x).
154
+ assert_allclose(sc.hyp1f1(a, b, x), expected, atol=0, rtol=1e-14)
155
+
156
+ def test_a_neg_int_and_b_equal_x(self):
157
+ # This is a case where the Boost wrapper will call hypergeometric_pFq
158
+ # instead of hypergeometric_1F1. When we use a version of Boost in
159
+ # which https://github.com/boostorg/math/issues/833 is fixed, this
160
+ # test case can probably be moved into test_assorted_cases.
161
+ # The expected value was computed with mpmath.hyp1f1(a, b, x).
162
+ a = -10.0
163
+ b = 2.5
164
+ x = 2.5
165
+ expected = 0.0365323664364104338721
166
+ computed = sc.hyp1f1(a, b, x)
167
+ assert_allclose(computed, expected, atol=0, rtol=1e-13)
168
+
169
+ @pytest.mark.parametrize('a, b, x, desired', [
170
+ (-1, -2, 2, 2),
171
+ (-1, -4, 10, 3.5),
172
+ (-2, -2, 1, 2.5)
173
+ ])
174
+ def test_gh_11099(self, a, b, x, desired):
175
+ # All desired results computed using Mpmath
176
+ assert sc.hyp1f1(a, b, x) == desired
177
+
178
+ @pytest.mark.parametrize('a', [-3, -2])
179
+ def test_x_zero_a_and_b_neg_ints_and_a_ge_b(self, a):
180
+ assert sc.hyp1f1(a, -3, 0) == 1
181
+
182
+ # In the following tests with complex z, the reference values
183
+ # were computed with mpmath.hyp1f1(a, b, z), and verified with
184
+ # Wolfram Alpha Hypergeometric1F1(a, b, z), except for the
185
+ # case a=0.1, b=1, z=7-24j, where Wolfram Alpha reported
186
+ # "Standard computation time exceeded". That reference value
187
+ # was confirmed in an online Matlab session, with the commands
188
+ #
189
+ # > format long
190
+ # > hypergeom(0.1, 1, 7-24i)
191
+ # ans =
192
+ # -3.712349651834209 + 4.554636556672912i
193
+ #
194
+ @pytest.mark.parametrize(
195
+ 'a, b, z, ref',
196
+ [(-0.25, 0.5, 1+2j, 1.1814553180903435-1.2792130661292984j),
197
+ (0.25, 0.5, 1+2j, 0.24636797405707597+1.293434354945675j),
198
+ (25, 1.5, -2j, -516.1771262822523+407.04142751922024j),
199
+ (12, -1.5, -10+20j, -5098507.422706547-1341962.8043508842j),
200
+ pytest.param(
201
+ 10, 250, 10-15j, 1.1985998416598884-0.8613474402403436j,
202
+ marks=pytest.mark.xfail,
203
+ ),
204
+ pytest.param(
205
+ 0.1, 1, 7-24j, -3.712349651834209+4.554636556672913j,
206
+ marks=pytest.mark.xfail,
207
+ )
208
+ ],
209
+ )
210
+ def test_complex_z(self, a, b, z, ref):
211
+ h = sc.hyp1f1(a, b, z)
212
+ assert_allclose(h, ref, rtol=4e-15)
213
+
214
+ # The "legacy edge cases" mentioned in the comments in the following
215
+ # tests refers to the behavior of hyp1f1(a, b, x) when b is a nonpositive
216
+ # integer. In some subcases, the behavior of SciPy does not match that
217
+ # of Boost (1.81+), mpmath and Mathematica (via Wolfram Alpha online).
218
+ # If the handling of these edges cases is changed to agree with those
219
+ # libraries, these test will have to be updated.
220
+
221
+ @pytest.mark.parametrize('b', [0, -1, -5])
222
+ def test_legacy_case1(self, b):
223
+ # Test results of hyp1f1(0, n, x) for n <= 0.
224
+ # This is a legacy edge case.
225
+ # Boost (versions greater than 1.80), Mathematica (via Wolfram Alpha
226
+ # online) and mpmath all return 1 in this case, but SciPy's hyp1f1
227
+ # returns inf.
228
+ assert_equal(sc.hyp1f1(0, b, [-1.5, 0, 1.5]), [np.inf, np.inf, np.inf])
229
+
230
+ def test_legacy_case2(self):
231
+ # This is a legacy edge case.
232
+ # In software such as boost (1.81+), mpmath and Mathematica,
233
+ # the value is 1.
234
+ assert sc.hyp1f1(-4, -3, 0) == np.inf
.venv/lib/python3.12/site-packages/scipy/special/tests/test_iv_ratio.py ADDED
@@ -0,0 +1,249 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # This file contains unit tests for iv_ratio() and related functions.
2
+
3
+ import pytest
4
+ import numpy as np
5
+ from numpy.testing import assert_equal, assert_allclose
6
+ from scipy.special._ufuncs import ( # type: ignore[attr-defined]
7
+ _iv_ratio as iv_ratio,
8
+ _iv_ratio_c as iv_ratio_c,
9
+ )
10
+
11
+
12
+ class TestIvRatio:
13
+
14
+ @pytest.mark.parametrize('v,x,r', [
15
+ (0.5, 0.16666666666666666, 0.16514041292462933),
16
+ (0.5, 0.3333333333333333, 0.32151273753163434),
17
+ (0.5, 0.5, 0.46211715726000974),
18
+ (0.5, 0.6666666666666666, 0.5827829453479101),
19
+ (0.5, 0.8333333333333335, 0.6822617902381698),
20
+ (1, 0.3380952380952381, 0.1666773049170313),
21
+ (1, 0.7083333333333333, 0.33366443586989925),
22
+ (1, 1.1666666666666667, 0.5023355231537423),
23
+ (1, 1.8666666666666665, 0.674616572252164),
24
+ (1, 3.560606060606061, 0.844207659503163),
25
+ (2.34, 0.7975238095238094, 0.16704903081553285),
26
+ (2.34, 1.7133333333333334, 0.3360215931268845),
27
+ (2.34, 2.953333333333333, 0.50681909317803),
28
+ (2.34, 5.0826666666666656, 0.6755252698800679),
29
+ (2.34, 10.869696969696973, 0.8379351104498762),
30
+ (56.789, 19.46575238095238, 0.1667020505391409),
31
+ (56.789, 42.55008333333333, 0.33353809996933026),
32
+ (56.789, 75.552, 0.5003932381177826),
33
+ (56.789, 135.76026666666667, 0.6670528221946127),
34
+ (56.789, 307.8642424242425, 0.8334999441460798),
35
+ ])
36
+ def test_against_reference_values(self, v, x, r):
37
+ """The reference values are computed using mpmath as follows.
38
+
39
+ from mpmath import mp
40
+ mp.dps = 100
41
+
42
+ def iv_ratio_mp(v, x):
43
+ return mp.besseli(v, x) / mp.besseli(v - 1, x)
44
+
45
+ def _sample(n, *, v):
46
+ '''Return n positive real numbers x such that iv_ratio(v, x) are
47
+ roughly evenly spaced over (0, 1). The formula is taken from [1].
48
+
49
+ [1] Banerjee A., Dhillon, I. S., Ghosh, J., Sra, S. (2005).
50
+ "Clustering on the Unit Hypersphere using von Mises-Fisher
51
+ Distributions." Journal of Machine Learning Research,
52
+ 6(46):1345-1382.
53
+ '''
54
+ r = np.arange(1, n+1) / (n+1)
55
+ return r * (2*v-r*r) / (1-r*r)
56
+
57
+ for v in (0.5, 1, 2.34, 56.789):
58
+ xs = _sample(5, v=v)
59
+ for x in xs:
60
+ print(f"({v}, {x}, {float(iv_ratio_mp(v,x))}),")
61
+ """
62
+ assert_allclose(iv_ratio(v, x), r, rtol=4e-16, atol=0)
63
+
64
+ @pytest.mark.parametrize('v,x,r', [
65
+ (1, np.inf, 1),
66
+ (np.inf, 1, 0),
67
+ ])
68
+ def test_inf(self, v, x, r):
69
+ """If exactly one of v or x is inf and the other is within domain,
70
+ should return 0 or 1 accordingly."""
71
+ assert_equal(iv_ratio(v, x), r)
72
+
73
+ @pytest.mark.parametrize('v', [0.49, -np.inf, np.nan, np.inf])
74
+ @pytest.mark.parametrize('x', [-np.finfo(float).smallest_normal,
75
+ -np.finfo(float).smallest_subnormal,
76
+ -np.inf, np.nan, np.inf])
77
+ def test_nan(self, v, x):
78
+ """If at least one argument is out of domain, or if v = x = inf,
79
+ the function should return nan."""
80
+ assert_equal(iv_ratio(v, x), np.nan)
81
+
82
+ @pytest.mark.parametrize('v', [0.5, 1, np.finfo(float).max, np.inf])
83
+ def test_zero_x(self, v):
84
+ """If x is +/-0.0, return x to ensure iv_ratio is an odd function."""
85
+ assert_equal(iv_ratio(v, 0.0), 0.0)
86
+ assert_equal(iv_ratio(v, -0.0), -0.0)
87
+
88
+ @pytest.mark.parametrize('v,x', [
89
+ (1, np.finfo(float).smallest_normal),
90
+ (1, np.finfo(float).smallest_subnormal),
91
+ (1, np.finfo(float).smallest_subnormal*2),
92
+ (1e20, 123),
93
+ (np.finfo(float).max, 1),
94
+ (np.finfo(float).max, np.sqrt(np.finfo(float).max)),
95
+ ])
96
+ def test_tiny_x(self, v, x):
97
+ """If x is much less than v, the bounds
98
+
99
+ x x
100
+ --------------------------- <= R <= -----------------------
101
+ v-0.5+sqrt(x**2+(v+0.5)**2) v-1+sqrt(x**2+(v+1)**2)
102
+
103
+ collapses to R ~= x/2v. Test against this asymptotic expression.
104
+ """
105
+ assert_equal(iv_ratio(v, x), (0.5*x)/v)
106
+
107
+ @pytest.mark.parametrize('v,x', [
108
+ (1, 1e16),
109
+ (1e20, 1e40),
110
+ (np.sqrt(np.finfo(float).max), np.finfo(float).max),
111
+ ])
112
+ def test_huge_x(self, v, x):
113
+ """If x is much greater than v, the bounds
114
+
115
+ x x
116
+ --------------------------- <= R <= ---------------------------
117
+ v-0.5+sqrt(x**2+(v+0.5)**2) v-0.5+sqrt(x**2+(v-0.5)**2)
118
+
119
+ collapses to R ~= 1. Test against this asymptotic expression.
120
+ """
121
+ assert_equal(iv_ratio(v, x), 1.0)
122
+
123
+ @pytest.mark.parametrize('v,x', [
124
+ (np.finfo(float).max, np.finfo(float).max),
125
+ (np.finfo(float).max / 3, np.finfo(float).max),
126
+ (np.finfo(float).max, np.finfo(float).max / 3),
127
+ ])
128
+ def test_huge_v_x(self, v, x):
129
+ """If both x and v are very large, the bounds
130
+
131
+ x x
132
+ --------------------------- <= R <= -----------------------
133
+ v-0.5+sqrt(x**2+(v+0.5)**2) v-1+sqrt(x**2+(v+1)**2)
134
+
135
+ collapses to R ~= x/(v+sqrt(x**2+v**2). Test against this asymptotic
136
+ expression, and in particular that no numerical overflow occurs during
137
+ intermediate calculations.
138
+ """
139
+ t = x / v
140
+ expected = t / (1 + np.hypot(1, t))
141
+ assert_allclose(iv_ratio(v, x), expected, rtol=4e-16, atol=0)
142
+
143
+
144
+ class TestIvRatioC:
145
+
146
+ @pytest.mark.parametrize('v,x,r', [
147
+ (0.5, 0.16666666666666666, 0.8348595870753707),
148
+ (0.5, 0.3333333333333333, 0.6784872624683657),
149
+ (0.5, 0.5, 0.5378828427399902),
150
+ (0.5, 0.6666666666666666, 0.4172170546520899),
151
+ (0.5, 0.8333333333333335, 0.3177382097618302),
152
+ (1, 0.3380952380952381, 0.8333226950829686),
153
+ (1, 0.7083333333333333, 0.6663355641301008),
154
+ (1, 1.1666666666666667, 0.4976644768462577),
155
+ (1, 1.8666666666666665, 0.325383427747836),
156
+ (1, 3.560606060606061, 0.155792340496837),
157
+ (2.34, 0.7975238095238094, 0.8329509691844672),
158
+ (2.34, 1.7133333333333334, 0.6639784068731155),
159
+ (2.34, 2.953333333333333, 0.49318090682197),
160
+ (2.34, 5.0826666666666656, 0.3244747301199321),
161
+ (2.34, 10.869696969696973, 0.16206488955012377),
162
+ (56.789, 19.46575238095238, 0.8332979494608591),
163
+ (56.789, 42.55008333333333, 0.6664619000306697),
164
+ (56.789, 75.552, 0.4996067618822174),
165
+ (56.789, 135.76026666666667, 0.3329471778053873),
166
+ (56.789, 307.8642424242425, 0.16650005585392025),
167
+ ])
168
+ def test_against_reference_values(self, v, x, r):
169
+ """The reference values are one minus those of TestIvRatio."""
170
+ assert_allclose(iv_ratio_c(v, x), r, rtol=1e-15, atol=0)
171
+
172
+ @pytest.mark.parametrize('v,x,r', [
173
+ (1, np.inf, 0),
174
+ (np.inf, 1, 1),
175
+ ])
176
+ def test_inf(self, v, x, r):
177
+ """If exactly one of v or x is inf and the other is within domain,
178
+ should return 0 or 1 accordingly."""
179
+ assert_equal(iv_ratio_c(v, x), r)
180
+
181
+ @pytest.mark.parametrize('v', [0.49, -np.inf, np.nan, np.inf])
182
+ @pytest.mark.parametrize('x', [-np.finfo(float).smallest_normal,
183
+ -np.finfo(float).smallest_subnormal,
184
+ -np.inf, np.nan, np.inf])
185
+ def test_nan(self, v, x):
186
+ """If at least one argument is out of domain, or if v = x = inf,
187
+ the function should return nan."""
188
+ assert_equal(iv_ratio_c(v, x), np.nan)
189
+
190
+ @pytest.mark.parametrize('v', [0.5, 1, np.finfo(float).max, np.inf])
191
+ def test_zero_x(self, v):
192
+ """If x is +/-0.0, return 1."""
193
+ assert_equal(iv_ratio_c(v, 0.0), 1.0)
194
+ assert_equal(iv_ratio_c(v, -0.0), 1.0)
195
+
196
+ @pytest.mark.parametrize('v,x', [
197
+ (1, np.finfo(float).smallest_normal),
198
+ (1, np.finfo(float).smallest_subnormal),
199
+ (1, np.finfo(float).smallest_subnormal*2),
200
+ (1e20, 123),
201
+ (np.finfo(float).max, 1),
202
+ (np.finfo(float).max, np.sqrt(np.finfo(float).max)),
203
+ ])
204
+ def test_tiny_x(self, v, x):
205
+ """If x is much less than v, the bounds
206
+
207
+ x x
208
+ --------------------------- <= R <= -----------------------
209
+ v-0.5+sqrt(x**2+(v+0.5)**2) v-1+sqrt(x**2+(v+1)**2)
210
+
211
+ collapses to 1-R ~= 1-x/2v. Test against this asymptotic expression.
212
+ """
213
+ assert_equal(iv_ratio_c(v, x), 1.0-(0.5*x)/v)
214
+
215
+ @pytest.mark.parametrize('v,x', [
216
+ (1, 1e16),
217
+ (1e20, 1e40),
218
+ (np.sqrt(np.finfo(float).max), np.finfo(float).max),
219
+ ])
220
+ def test_huge_x(self, v, x):
221
+ """If x is much greater than v, the bounds
222
+
223
+ x x
224
+ --------------------------- <= R <= ---------------------------
225
+ v-0.5+sqrt(x**2+(v+0.5)**2) v-0.5+sqrt(x**2+(v-0.5)**2)
226
+
227
+ collapses to 1-R ~= (v-0.5)/x. Test against this asymptotic expression.
228
+ """
229
+ assert_allclose(iv_ratio_c(v, x), (v-0.5)/x, rtol=1e-15, atol=0)
230
+
231
+ @pytest.mark.parametrize('v,x', [
232
+ (np.finfo(float).max, np.finfo(float).max),
233
+ (np.finfo(float).max / 3, np.finfo(float).max),
234
+ (np.finfo(float).max, np.finfo(float).max / 3),
235
+ ])
236
+ def test_huge_v_x(self, v, x):
237
+ """If both x and v are very large, the bounds
238
+
239
+ x x
240
+ --------------------------- <= R <= -----------------------
241
+ v-0.5+sqrt(x**2+(v+0.5)**2) v-1+sqrt(x**2+(v+1)**2)
242
+
243
+ collapses to 1 - R ~= 1 - x/(v+sqrt(x**2+v**2). Test against this
244
+ asymptotic expression, and in particular that no numerical overflow
245
+ occurs during intermediate calculations.
246
+ """
247
+ t = x / v
248
+ expected = 1 - t / (1 + np.hypot(1, t))
249
+ assert_allclose(iv_ratio_c(v, x), expected, rtol=4e-16, atol=0)
.venv/lib/python3.12/site-packages/scipy/special/tests/test_kolmogorov.py ADDED
@@ -0,0 +1,491 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import itertools
2
+
3
+ import numpy as np
4
+ from numpy.testing import assert_
5
+ from scipy.special._testutils import FuncData
6
+
7
+ from scipy.special import kolmogorov, kolmogi, smirnov, smirnovi
8
+ from scipy.special._ufuncs import (_kolmogc, _kolmogci, _kolmogp,
9
+ _smirnovc, _smirnovci, _smirnovp)
10
+
11
+ _rtol = 1e-10
12
+
13
+ class TestSmirnov:
14
+ def test_nan(self):
15
+ assert_(np.isnan(smirnov(1, np.nan)))
16
+
17
+ def test_basic(self):
18
+ dataset = [(1, 0.1, 0.9),
19
+ (1, 0.875, 0.125),
20
+ (2, 0.875, 0.125 * 0.125),
21
+ (3, 0.875, 0.125 * 0.125 * 0.125)]
22
+
23
+ dataset = np.asarray(dataset)
24
+ FuncData(
25
+ smirnov, dataset, (0, 1), 2, rtol=_rtol
26
+ ).check(dtypes=[int, float, float])
27
+ dataset[:, -1] = 1 - dataset[:, -1]
28
+ FuncData(
29
+ _smirnovc, dataset, (0, 1), 2, rtol=_rtol
30
+ ).check(dtypes=[int, float, float])
31
+
32
+ def test_x_equals_0(self):
33
+ dataset = [(n, 0, 1) for n in itertools.chain(range(2, 20), range(1010, 1020))]
34
+ dataset = np.asarray(dataset)
35
+ FuncData(
36
+ smirnov, dataset, (0, 1), 2, rtol=_rtol
37
+ ).check(dtypes=[int, float, float])
38
+ dataset[:, -1] = 1 - dataset[:, -1]
39
+ FuncData(
40
+ _smirnovc, dataset, (0, 1), 2, rtol=_rtol
41
+ ).check(dtypes=[int, float, float])
42
+
43
+ def test_x_equals_1(self):
44
+ dataset = [(n, 1, 0) for n in itertools.chain(range(2, 20), range(1010, 1020))]
45
+ dataset = np.asarray(dataset)
46
+ FuncData(
47
+ smirnov, dataset, (0, 1), 2, rtol=_rtol
48
+ ).check(dtypes=[int, float, float])
49
+ dataset[:, -1] = 1 - dataset[:, -1]
50
+ FuncData(
51
+ _smirnovc, dataset, (0, 1), 2, rtol=_rtol
52
+ ).check(dtypes=[int, float, float])
53
+
54
+ def test_x_equals_0point5(self):
55
+ dataset = [(1, 0.5, 0.5),
56
+ (2, 0.5, 0.25),
57
+ (3, 0.5, 0.166666666667),
58
+ (4, 0.5, 0.09375),
59
+ (5, 0.5, 0.056),
60
+ (6, 0.5, 0.0327932098765),
61
+ (7, 0.5, 0.0191958707681),
62
+ (8, 0.5, 0.0112953186035),
63
+ (9, 0.5, 0.00661933257355),
64
+ (10, 0.5, 0.003888705)]
65
+
66
+ dataset = np.asarray(dataset)
67
+ FuncData(
68
+ smirnov, dataset, (0, 1), 2, rtol=_rtol
69
+ ).check(dtypes=[int, float, float])
70
+ dataset[:, -1] = 1 - dataset[:, -1]
71
+ FuncData(
72
+ _smirnovc, dataset, (0, 1), 2, rtol=_rtol
73
+ ).check(dtypes=[int, float, float])
74
+
75
+ def test_n_equals_1(self):
76
+ x = np.linspace(0, 1, 101, endpoint=True)
77
+ dataset = np.column_stack([[1]*len(x), x, 1-x])
78
+ FuncData(
79
+ smirnov, dataset, (0, 1), 2, rtol=_rtol
80
+ ).check(dtypes=[int, float, float])
81
+ dataset[:, -1] = 1 - dataset[:, -1]
82
+ FuncData(
83
+ _smirnovc, dataset, (0, 1), 2, rtol=_rtol
84
+ ).check(dtypes=[int, float, float])
85
+
86
+ def test_n_equals_2(self):
87
+ x = np.linspace(0.5, 1, 101, endpoint=True)
88
+ p = np.power(1-x, 2)
89
+ n = np.array([2] * len(x))
90
+ dataset = np.column_stack([n, x, p])
91
+ FuncData(
92
+ smirnov, dataset, (0, 1), 2, rtol=_rtol
93
+ ).check(dtypes=[int, float, float])
94
+ dataset[:, -1] = 1 - dataset[:, -1]
95
+ FuncData(
96
+ _smirnovc, dataset, (0, 1), 2, rtol=_rtol
97
+ ).check(dtypes=[int, float, float])
98
+
99
+ def test_n_equals_3(self):
100
+ x = np.linspace(0.7, 1, 31, endpoint=True)
101
+ p = np.power(1-x, 3)
102
+ n = np.array([3] * len(x))
103
+ dataset = np.column_stack([n, x, p])
104
+ FuncData(
105
+ smirnov, dataset, (0, 1), 2, rtol=_rtol
106
+ ).check(dtypes=[int, float, float])
107
+ dataset[:, -1] = 1 - dataset[:, -1]
108
+ FuncData(
109
+ _smirnovc, dataset, (0, 1), 2, rtol=_rtol
110
+ ).check(dtypes=[int, float, float])
111
+
112
+ def test_n_large(self):
113
+ # test for large values of n
114
+ # Probabilities should go down as n goes up
115
+ x = 0.4
116
+ pvals = np.array([smirnov(n, x) for n in range(400, 1100, 20)])
117
+ dfs = np.diff(pvals)
118
+ assert_(np.all(dfs <= 0), msg=f'Not all diffs negative {dfs}')
119
+
120
+
121
+ class TestSmirnovi:
122
+ def test_nan(self):
123
+ assert_(np.isnan(smirnovi(1, np.nan)))
124
+
125
+ def test_basic(self):
126
+ dataset = [(1, 0.4, 0.6),
127
+ (1, 0.6, 0.4),
128
+ (1, 0.99, 0.01),
129
+ (1, 0.01, 0.99),
130
+ (2, 0.125 * 0.125, 0.875),
131
+ (3, 0.125 * 0.125 * 0.125, 0.875),
132
+ (10, 1.0 / 16 ** 10, 1 - 1.0 / 16)]
133
+
134
+ dataset = np.asarray(dataset)
135
+ FuncData(
136
+ smirnovi, dataset, (0, 1), 2, rtol=_rtol
137
+ ).check(dtypes=[int, float, float])
138
+ dataset[:, 1] = 1 - dataset[:, 1]
139
+ FuncData(
140
+ _smirnovci, dataset, (0, 1), 2, rtol=_rtol
141
+ ).check(dtypes=[int, float, float])
142
+
143
+ def test_x_equals_0(self):
144
+ dataset = [(n, 0, 1) for n in itertools.chain(range(2, 20), range(1010, 1020))]
145
+ dataset = np.asarray(dataset)
146
+ FuncData(
147
+ smirnovi, dataset, (0, 1), 2, rtol=_rtol
148
+ ).check(dtypes=[int, float, float])
149
+ dataset[:, 1] = 1 - dataset[:, 1]
150
+ FuncData(
151
+ _smirnovci, dataset, (0, 1), 2, rtol=_rtol
152
+ ).check(dtypes=[int, float, float])
153
+
154
+ def test_x_equals_1(self):
155
+ dataset = [(n, 1, 0) for n in itertools.chain(range(2, 20), range(1010, 1020))]
156
+ dataset = np.asarray(dataset)
157
+ FuncData(
158
+ smirnovi, dataset, (0, 1), 2, rtol=_rtol
159
+ ).check(dtypes=[int, float, float])
160
+ dataset[:, 1] = 1 - dataset[:, 1]
161
+ FuncData(
162
+ _smirnovci, dataset, (0, 1), 2, rtol=_rtol
163
+ ).check(dtypes=[int, float, float])
164
+
165
+ def test_n_equals_1(self):
166
+ pp = np.linspace(0, 1, 101, endpoint=True)
167
+ # dataset = np.array([(1, p, 1-p) for p in pp])
168
+ dataset = np.column_stack([[1]*len(pp), pp, 1-pp])
169
+ FuncData(
170
+ smirnovi, dataset, (0, 1), 2, rtol=_rtol
171
+ ).check(dtypes=[int, float, float])
172
+ dataset[:, 1] = 1 - dataset[:, 1]
173
+ FuncData(
174
+ _smirnovci, dataset, (0, 1), 2, rtol=_rtol
175
+ ).check(dtypes=[int, float, float])
176
+
177
+ def test_n_equals_2(self):
178
+ x = np.linspace(0.5, 1, 101, endpoint=True)
179
+ p = np.power(1-x, 2)
180
+ n = np.array([2] * len(x))
181
+ dataset = np.column_stack([n, p, x])
182
+ FuncData(
183
+ smirnovi, dataset, (0, 1), 2, rtol=_rtol
184
+ ).check(dtypes=[int, float, float])
185
+ dataset[:, 1] = 1 - dataset[:, 1]
186
+ FuncData(
187
+ _smirnovci, dataset, (0, 1), 2, rtol=_rtol
188
+ ).check(dtypes=[int, float, float])
189
+
190
+ def test_n_equals_3(self):
191
+ x = np.linspace(0.7, 1, 31, endpoint=True)
192
+ p = np.power(1-x, 3)
193
+ n = np.array([3] * len(x))
194
+ dataset = np.column_stack([n, p, x])
195
+ FuncData(
196
+ smirnovi, dataset, (0, 1), 2, rtol=_rtol
197
+ ).check(dtypes=[int, float, float])
198
+ dataset[:, 1] = 1 - dataset[:, 1]
199
+ FuncData(
200
+ _smirnovci, dataset, (0, 1), 2, rtol=_rtol
201
+ ).check(dtypes=[int, float, float])
202
+
203
+ def test_round_trip(self):
204
+ def _sm_smi(n, p):
205
+ return smirnov(n, smirnovi(n, p))
206
+
207
+ def _smc_smci(n, p):
208
+ return _smirnovc(n, _smirnovci(n, p))
209
+
210
+ dataset = [(1, 0.4, 0.4),
211
+ (1, 0.6, 0.6),
212
+ (2, 0.875, 0.875),
213
+ (3, 0.875, 0.875),
214
+ (3, 0.125, 0.125),
215
+ (10, 0.999, 0.999),
216
+ (10, 0.0001, 0.0001)]
217
+
218
+ dataset = np.asarray(dataset)
219
+ FuncData(
220
+ _sm_smi, dataset, (0, 1), 2, rtol=_rtol
221
+ ).check(dtypes=[int, float, float])
222
+ FuncData(
223
+ _smc_smci, dataset, (0, 1), 2, rtol=_rtol
224
+ ).check(dtypes=[int, float, float])
225
+
226
+ def test_x_equals_0point5(self):
227
+ dataset = [(1, 0.5, 0.5),
228
+ (2, 0.5, 0.366025403784),
229
+ (2, 0.25, 0.5),
230
+ (3, 0.5, 0.297156508177),
231
+ (4, 0.5, 0.255520481121),
232
+ (5, 0.5, 0.234559536069),
233
+ (6, 0.5, 0.21715965898),
234
+ (7, 0.5, 0.202722580034),
235
+ (8, 0.5, 0.190621765256),
236
+ (9, 0.5, 0.180363501362),
237
+ (10, 0.5, 0.17157867006)]
238
+
239
+ dataset = np.asarray(dataset)
240
+ FuncData(
241
+ smirnovi, dataset, (0, 1), 2, rtol=_rtol
242
+ ).check(dtypes=[int, float, float])
243
+ dataset[:, 1] = 1 - dataset[:, 1]
244
+ FuncData(
245
+ _smirnovci, dataset, (0, 1), 2, rtol=_rtol
246
+ ).check(dtypes=[int, float, float])
247
+
248
+
249
+ class TestSmirnovp:
250
+ def test_nan(self):
251
+ assert_(np.isnan(_smirnovp(1, np.nan)))
252
+
253
+ def test_basic(self):
254
+ # Check derivative at endpoints
255
+ n1_10 = np.arange(1, 10)
256
+ dataset0 = np.column_stack([n1_10,
257
+ np.full_like(n1_10, 0),
258
+ np.full_like(n1_10, -1)])
259
+ FuncData(
260
+ _smirnovp, dataset0, (0, 1), 2, rtol=_rtol
261
+ ).check(dtypes=[int, float, float])
262
+
263
+ n2_10 = np.arange(2, 10)
264
+ dataset1 = np.column_stack([n2_10,
265
+ np.full_like(n2_10, 1.0),
266
+ np.full_like(n2_10, 0)])
267
+ FuncData(
268
+ _smirnovp, dataset1, (0, 1), 2, rtol=_rtol
269
+ ).check(dtypes=[int, float, float])
270
+
271
+ def test_oneminusoneovern(self):
272
+ # Check derivative at x=1-1/n
273
+ n = np.arange(1, 20)
274
+ x = 1.0/n
275
+ xm1 = 1-1.0/n
276
+ pp1 = -n * x**(n-1)
277
+ pp1 -= (1-np.sign(n-2)**2) * 0.5 # n=2, x=0.5, 1-1/n = 0.5, need to adjust
278
+ dataset1 = np.column_stack([n, xm1, pp1])
279
+ FuncData(
280
+ _smirnovp, dataset1, (0, 1), 2, rtol=_rtol
281
+ ).check(dtypes=[int, float, float])
282
+
283
+ def test_oneovertwon(self):
284
+ # Check derivative at x=1/2n (Discontinuous at x=1/n, so check at x=1/2n)
285
+ n = np.arange(1, 20)
286
+ x = 1.0/2/n
287
+ pp = -(n*x+1) * (1+x)**(n-2)
288
+ dataset0 = np.column_stack([n, x, pp])
289
+ FuncData(
290
+ _smirnovp, dataset0, (0, 1), 2, rtol=_rtol
291
+ ).check(dtypes=[int, float, float])
292
+
293
+ def test_oneovern(self):
294
+ # Check derivative at x=1/n
295
+ # (Discontinuous at x=1/n, hard to tell if x==1/n, only use n=power of 2)
296
+ n = 2**np.arange(1, 10)
297
+ x = 1.0/n
298
+ pp = -(n*x+1) * (1+x)**(n-2) + 0.5
299
+ dataset0 = np.column_stack([n, x, pp])
300
+ FuncData(
301
+ _smirnovp, dataset0, (0, 1), 2, rtol=_rtol
302
+ ).check(dtypes=[int, float, float])
303
+
304
+ def test_oneovernclose(self):
305
+ # Check derivative at x=1/n
306
+ # (Discontinuous at x=1/n, test on either side: x=1/n +/- 2epsilon)
307
+ n = np.arange(3, 20)
308
+
309
+ x = 1.0/n - 2*np.finfo(float).eps
310
+ pp = -(n*x+1) * (1+x)**(n-2)
311
+ dataset0 = np.column_stack([n, x, pp])
312
+ FuncData(
313
+ _smirnovp, dataset0, (0, 1), 2, rtol=_rtol
314
+ ).check(dtypes=[int, float, float])
315
+
316
+ x = 1.0/n + 2*np.finfo(float).eps
317
+ pp = -(n*x+1) * (1+x)**(n-2) + 1
318
+ dataset1 = np.column_stack([n, x, pp])
319
+ FuncData(
320
+ _smirnovp, dataset1, (0, 1), 2, rtol=_rtol
321
+ ).check(dtypes=[int, float, float])
322
+
323
+
324
+ class TestKolmogorov:
325
+ def test_nan(self):
326
+ assert_(np.isnan(kolmogorov(np.nan)))
327
+
328
+ def test_basic(self):
329
+ dataset = [(0, 1.0),
330
+ (0.5, 0.96394524366487511),
331
+ (0.8275735551899077, 0.5000000000000000),
332
+ (1, 0.26999967167735456),
333
+ (2, 0.00067092525577969533)]
334
+
335
+ dataset = np.asarray(dataset)
336
+ FuncData(kolmogorov, dataset, (0,), 1, rtol=_rtol).check()
337
+
338
+ def test_linspace(self):
339
+ x = np.linspace(0, 2.0, 21)
340
+ dataset = [1.0000000000000000, 1.0000000000000000, 0.9999999999994950,
341
+ 0.9999906941986655, 0.9971923267772983, 0.9639452436648751,
342
+ 0.8642827790506042, 0.7112351950296890, 0.5441424115741981,
343
+ 0.3927307079406543, 0.2699996716773546, 0.1777181926064012,
344
+ 0.1122496666707249, 0.0680922218447664, 0.0396818795381144,
345
+ 0.0222179626165251, 0.0119520432391966, 0.0061774306344441,
346
+ 0.0030676213475797, 0.0014636048371873, 0.0006709252557797]
347
+
348
+ dataset_c = [0.0000000000000000, 6.609305242245699e-53, 5.050407338670114e-13,
349
+ 9.305801334566668e-06, 0.0028076732227017, 0.0360547563351249,
350
+ 0.1357172209493958, 0.2887648049703110, 0.4558575884258019,
351
+ 0.6072692920593457, 0.7300003283226455, 0.8222818073935988,
352
+ 0.8877503333292751, 0.9319077781552336, 0.9603181204618857,
353
+ 0.9777820373834749, 0.9880479567608034, 0.9938225693655559,
354
+ 0.9969323786524203, 0.9985363951628127, 0.9993290747442203]
355
+
356
+ dataset = np.column_stack([x, dataset])
357
+ FuncData(kolmogorov, dataset, (0,), 1, rtol=_rtol).check()
358
+ dataset_c = np.column_stack([x, dataset_c])
359
+ FuncData(_kolmogc, dataset_c, (0,), 1, rtol=_rtol).check()
360
+
361
+ def test_linspacei(self):
362
+ p = np.linspace(0, 1.0, 21, endpoint=True)
363
+ dataset = [np.inf, 1.3580986393225507, 1.2238478702170823,
364
+ 1.1379465424937751, 1.0727491749396481, 1.0191847202536859,
365
+ 0.9730633753323726, 0.9320695842357622, 0.8947644549851197,
366
+ 0.8601710725555463, 0.8275735551899077, 0.7964065373291559,
367
+ 0.7661855555617682, 0.7364542888171910, 0.7067326523068980,
368
+ 0.6764476915028201, 0.6448126061663567, 0.6105590999244391,
369
+ 0.5711732651063401, 0.5196103791686224, 0.0000000000000000]
370
+
371
+ dataset_c = [0.0000000000000000, 0.5196103791686225, 0.5711732651063401,
372
+ 0.6105590999244391, 0.6448126061663567, 0.6764476915028201,
373
+ 0.7067326523068980, 0.7364542888171910, 0.7661855555617682,
374
+ 0.7964065373291559, 0.8275735551899077, 0.8601710725555463,
375
+ 0.8947644549851196, 0.9320695842357622, 0.9730633753323727,
376
+ 1.0191847202536859, 1.0727491749396481, 1.1379465424937754,
377
+ 1.2238478702170825, 1.3580986393225509, np.inf]
378
+
379
+ dataset = np.column_stack([p[1:], dataset[1:]])
380
+ FuncData(kolmogi, dataset, (0,), 1, rtol=_rtol).check()
381
+ dataset_c = np.column_stack([p[:-1], dataset_c[:-1]])
382
+ FuncData(_kolmogci, dataset_c, (0,), 1, rtol=_rtol).check()
383
+
384
+ def test_smallx(self):
385
+ epsilon = 0.1 ** np.arange(1, 14)
386
+ x = np.array([0.571173265106, 0.441027698518, 0.374219690278, 0.331392659217,
387
+ 0.300820537459, 0.277539353999, 0.259023494805, 0.243829561254,
388
+ 0.231063086389, 0.220135543236, 0.210641372041, 0.202290283658,
389
+ 0.19487060742])
390
+
391
+ dataset = np.column_stack([x, 1-epsilon])
392
+ FuncData(kolmogorov, dataset, (0,), 1, rtol=_rtol).check()
393
+
394
+ def test_round_trip(self):
395
+ def _ki_k(_x):
396
+ return kolmogi(kolmogorov(_x))
397
+
398
+ def _kci_kc(_x):
399
+ return _kolmogci(_kolmogc(_x))
400
+
401
+ x = np.linspace(0.0, 2.0, 21, endpoint=True)
402
+ # Exclude 0.1, 0.2. 0.2 almost makes succeeds, but 0.1 has no chance.
403
+ x02 = x[(x == 0) | (x > 0.21)]
404
+ dataset02 = np.column_stack([x02, x02])
405
+ FuncData(_ki_k, dataset02, (0,), 1, rtol=_rtol).check()
406
+
407
+ dataset = np.column_stack([x, x])
408
+ FuncData(_kci_kc, dataset, (0,), 1, rtol=_rtol).check()
409
+
410
+
411
+ class TestKolmogi:
412
+ def test_nan(self):
413
+ assert_(np.isnan(kolmogi(np.nan)))
414
+
415
+ def test_basic(self):
416
+ dataset = [(1.0, 0),
417
+ (0.96394524366487511, 0.5),
418
+ (0.9, 0.571173265106),
419
+ (0.5000000000000000, 0.8275735551899077),
420
+ (0.26999967167735456, 1),
421
+ (0.00067092525577969533, 2)]
422
+
423
+ dataset = np.asarray(dataset)
424
+ FuncData(kolmogi, dataset, (0,), 1, rtol=_rtol).check()
425
+
426
+ def test_smallpcdf(self):
427
+ epsilon = 0.5 ** np.arange(1, 55, 3)
428
+ # kolmogi(1-p) == _kolmogci(p) if 1-(1-p) == p, but not necessarily otherwise
429
+ # Use epsilon s.t. 1-(1-epsilon)) == epsilon,
430
+ # so can use same x-array for both results
431
+
432
+ x = np.array([0.8275735551899077, 0.5345255069097583, 0.4320114038786941,
433
+ 0.3736868442620478, 0.3345161714909591, 0.3057833329315859,
434
+ 0.2835052890528936, 0.2655578150208676, 0.2506869966107999,
435
+ 0.2380971058736669, 0.2272549289962079, 0.2177876361600040,
436
+ 0.2094254686862041, 0.2019676748836232, 0.1952612948137504,
437
+ 0.1891874239646641, 0.1836520225050326, 0.1785795904846466])
438
+
439
+ dataset = np.column_stack([1-epsilon, x])
440
+ FuncData(kolmogi, dataset, (0,), 1, rtol=_rtol).check()
441
+
442
+ dataset = np.column_stack([epsilon, x])
443
+ FuncData(_kolmogci, dataset, (0,), 1, rtol=_rtol).check()
444
+
445
+ def test_smallpsf(self):
446
+ epsilon = 0.5 ** np.arange(1, 55, 3)
447
+ # kolmogi(p) == _kolmogci(1-p) if 1-(1-p) == p, but not necessarily otherwise
448
+ # Use epsilon s.t. 1-(1-epsilon)) == epsilon,
449
+ # so can use same x-array for both results
450
+
451
+ x = np.array([0.8275735551899077, 1.3163786275161036, 1.6651092133663343,
452
+ 1.9525136345289607, 2.2027324540033235, 2.4272929437460848,
453
+ 2.6327688477341593, 2.8233300509220260, 3.0018183401530627,
454
+ 3.1702735084088891, 3.3302184446307912, 3.4828258153113318,
455
+ 3.6290214150152051, 3.7695513262825959, 3.9050272690877326,
456
+ 4.0359582187082550, 4.1627730557884890, 4.2858371743264527])
457
+
458
+ dataset = np.column_stack([epsilon, x])
459
+ FuncData(kolmogi, dataset, (0,), 1, rtol=_rtol).check()
460
+
461
+ dataset = np.column_stack([1-epsilon, x])
462
+ FuncData(_kolmogci, dataset, (0,), 1, rtol=_rtol).check()
463
+
464
+ def test_round_trip(self):
465
+ def _k_ki(_p):
466
+ return kolmogorov(kolmogi(_p))
467
+
468
+ p = np.linspace(0.1, 1.0, 10, endpoint=True)
469
+ dataset = np.column_stack([p, p])
470
+ FuncData(_k_ki, dataset, (0,), 1, rtol=_rtol).check()
471
+
472
+
473
+ class TestKolmogp:
474
+ def test_nan(self):
475
+ assert_(np.isnan(_kolmogp(np.nan)))
476
+
477
+ def test_basic(self):
478
+ dataset = [(0.000000, -0.0),
479
+ (0.200000, -1.532420541338916e-10),
480
+ (0.400000, -0.1012254419260496),
481
+ (0.600000, -1.324123244249925),
482
+ (0.800000, -1.627024345636592),
483
+ (1.000000, -1.071948558356941),
484
+ (1.200000, -0.538512430720529),
485
+ (1.400000, -0.2222133182429472),
486
+ (1.600000, -0.07649302775520538),
487
+ (1.800000, -0.02208687346347873),
488
+ (2.000000, -0.005367402045629683)]
489
+
490
+ dataset = np.asarray(dataset)
491
+ FuncData(_kolmogp, dataset, (0,), 1, rtol=_rtol).check()
.venv/lib/python3.12/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_allclose
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_allclose(lambertw(r_[0., e, 1.]), r_[0., 1., 0.567143290409783873],
89
+ atol=1.5e-7, rtol=0)
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
.venv/lib/python3.12/site-packages/scipy/special/tests/test_legendre.py ADDED
@@ -0,0 +1,1421 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import math
2
+ import warnings
3
+
4
+ import numpy as np
5
+
6
+ import pytest
7
+ from numpy.testing import assert_equal, assert_allclose
8
+
9
+ from scipy import special
10
+ from scipy.special import (legendre_p, legendre_p_all, assoc_legendre_p,
11
+ assoc_legendre_p_all, sph_legendre_p, sph_legendre_p_all)
12
+
13
+
14
+ # Base polynomials come from Abrahmowitz and Stegan
15
+ class TestLegendre:
16
+ def test_legendre(self):
17
+ leg0 = special.legendre(0)
18
+ leg1 = special.legendre(1)
19
+ leg2 = special.legendre(2)
20
+ leg3 = special.legendre(3)
21
+ leg4 = special.legendre(4)
22
+ leg5 = special.legendre(5)
23
+ assert_equal(leg0.c, [1])
24
+ assert_equal(leg1.c, [1,0])
25
+ assert_allclose(leg2.c, np.array([3, 0, -1])/2.0,
26
+ atol=1.5e-13, rtol=0)
27
+ assert_allclose(leg3.c, np.array([5, 0, -3, 0])/2.0,
28
+ atol=1.5e-7, rtol=0)
29
+ assert_allclose(leg4.c, np.array([35, 0, -30, 0, 3])/8.0,
30
+ atol=1.5e-7, rtol=0)
31
+ assert_allclose(leg5.c, np.array([63, 0, -70, 0, 15, 0])/8.0,
32
+ atol=1.5e-7, rtol=0)
33
+
34
+ class TestLegendreP:
35
+ @pytest.mark.parametrize("shape", [(10,), (4, 9), (3, 5, 7)])
36
+ def test_ode(self, shape):
37
+ rng = np.random.default_rng(1234)
38
+
39
+ n = rng.integers(0, 100, shape)
40
+ x = rng.uniform(-1, 1, shape)
41
+
42
+ p, p_jac, p_hess = legendre_p(n, x, diff_n=2)
43
+
44
+ assert p.shape == shape
45
+ assert p_jac.shape == p.shape
46
+ assert p_hess.shape == p_jac.shape
47
+
48
+ err = (1 - x * x) * p_hess - 2 * x * p_jac + n * (n + 1) * p
49
+ np.testing.assert_allclose(err, 0, atol=1e-10)
50
+
51
+ @pytest.mark.parametrize("n_max", [1, 2, 4, 8, 16, 32])
52
+ @pytest.mark.parametrize("x_shape", [(10,), (4, 9), (3, 5, 7)])
53
+ def test_all_ode(self, n_max, x_shape):
54
+ rng = np.random.default_rng(1234)
55
+
56
+ x = rng.uniform(-1, 1, x_shape)
57
+ p, p_jac, p_hess = legendre_p_all(n_max, x, diff_n=2)
58
+
59
+ n = np.arange(n_max + 1)
60
+ n = np.expand_dims(n, axis = tuple(range(1, x.ndim + 1)))
61
+
62
+ assert p.shape == (len(n),) + x.shape
63
+ assert p_jac.shape == p.shape
64
+ assert p_hess.shape == p_jac.shape
65
+
66
+ err = (1 - x * x) * p_hess - 2 * x * p_jac + n * (n + 1) * p
67
+ np.testing.assert_allclose(err, 0, atol=1e-10)
68
+
69
+
70
+ class TestAssocLegendreP:
71
+ def test_assoc_legendre_gh23101(self):
72
+ z = np.array([-1, -.5, 0, .5, 1])
73
+ expected = assoc_legendre_p_1_0(z)
74
+ result = assoc_legendre_p(1, 0, z)
75
+ assert_allclose(np.squeeze(result), expected)
76
+
77
+ expected = assoc_legendre_p_3_0(z)
78
+ result = assoc_legendre_p(3, 0, z)
79
+ assert_allclose(np.squeeze(result), expected)
80
+
81
+ @pytest.mark.parametrize("shape", [(10,), (4, 9), (3, 5, 7, 10)])
82
+ @pytest.mark.parametrize("m_max", [5, 4])
83
+ @pytest.mark.parametrize("n_max", [7, 10])
84
+ def test_lpmn(self, shape, n_max, m_max):
85
+ rng = np.random.default_rng(1234)
86
+
87
+ x = rng.uniform(-0.99, 0.99, shape)
88
+ p_all, p_all_jac, p_all_hess = \
89
+ assoc_legendre_p_all(n_max, m_max, x, diff_n=2)
90
+
91
+ n = np.arange(n_max + 1)
92
+ n = np.expand_dims(n, axis = tuple(range(1, x.ndim + 2)))
93
+
94
+ m = np.concatenate([np.arange(m_max + 1), np.arange(-m_max, 0)])
95
+ m = np.expand_dims(m, axis = (0,) + tuple(range(2, x.ndim + 2)))
96
+
97
+ x = np.expand_dims(x, axis = (0, 1))
98
+ p, p_jac, p_hess = assoc_legendre_p(n, m, x, diff_n=2)
99
+
100
+ np.testing.assert_allclose(p, p_all)
101
+ np.testing.assert_allclose(p_jac, p_all_jac)
102
+ np.testing.assert_allclose(p_hess, p_all_hess)
103
+
104
+ @pytest.mark.parametrize("shape", [(10,), (4, 9), (3, 5, 7, 10)])
105
+ @pytest.mark.parametrize("norm", [True, False])
106
+ def test_ode(self, shape, norm):
107
+ rng = np.random.default_rng(1234)
108
+
109
+ n = rng.integers(0, 10, shape)
110
+ m = rng.integers(-10, 10, shape)
111
+ x = rng.uniform(-1, 1, shape)
112
+
113
+ p, p_jac, p_hess = assoc_legendre_p(n, m, x, norm=norm, diff_n=2)
114
+
115
+ assert p.shape == shape
116
+ assert p_jac.shape == p.shape
117
+ assert p_hess.shape == p_jac.shape
118
+
119
+ np.testing.assert_allclose((1 - x * x) * p_hess,
120
+ 2 * x * p_jac - (n * (n + 1) - m * m / (1 - x * x)) * p,
121
+ rtol=1e-05, atol=1e-08)
122
+
123
+ @pytest.mark.parametrize("shape", [(10,), (4, 9), (3, 5, 7)])
124
+ def test_all(self, shape):
125
+ rng = np.random.default_rng(1234)
126
+
127
+ n_max = 20
128
+ m_max = 20
129
+
130
+ x = rng.uniform(-0.99, 0.99, shape)
131
+
132
+ p, p_jac, p_hess = assoc_legendre_p_all(n_max, m_max, x, diff_n=2)
133
+
134
+ m = np.concatenate([np.arange(m_max + 1), np.arange(-m_max, 0)])
135
+ n = np.arange(n_max + 1)
136
+
137
+ n = np.expand_dims(n, axis = tuple(range(1, x.ndim + 2)))
138
+ m = np.expand_dims(m, axis = (0,) + tuple(range(2, x.ndim + 2)))
139
+ np.testing.assert_allclose((1 - x * x) * p_hess,
140
+ 2 * x * p_jac - (n * (n + 1) - m * m / (1 - x * x)) * p,
141
+ rtol=1e-05, atol=1e-08)
142
+
143
+ @pytest.mark.parametrize("shape", [(10,), (4, 9), (3, 5, 7)])
144
+ @pytest.mark.parametrize("norm", [True, False])
145
+ def test_specific(self, shape, norm):
146
+ rng = np.random.default_rng(1234)
147
+
148
+ x = rng.uniform(-0.99, 0.99, shape)
149
+
150
+ p, p_jac = assoc_legendre_p_all(4, 4, x, norm=norm, diff_n=1)
151
+
152
+ np.testing.assert_allclose(p[0, 0],
153
+ assoc_legendre_p_0_0(x, norm=norm))
154
+ np.testing.assert_allclose(p[0, 1], 0)
155
+ np.testing.assert_allclose(p[0, 2], 0)
156
+ np.testing.assert_allclose(p[0, 3], 0)
157
+ np.testing.assert_allclose(p[0, 4], 0)
158
+ np.testing.assert_allclose(p[0, -3], 0)
159
+ np.testing.assert_allclose(p[0, -2], 0)
160
+ np.testing.assert_allclose(p[0, -1], 0)
161
+
162
+ np.testing.assert_allclose(p[1, 0],
163
+ assoc_legendre_p_1_0(x, norm=norm))
164
+ np.testing.assert_allclose(p[1, 1],
165
+ assoc_legendre_p_1_1(x, norm=norm))
166
+ np.testing.assert_allclose(p[1, 2], 0)
167
+ np.testing.assert_allclose(p[1, 3], 0)
168
+ np.testing.assert_allclose(p[1, 4], 0)
169
+ np.testing.assert_allclose(p[1, -4], 0)
170
+ np.testing.assert_allclose(p[1, -3], 0)
171
+ np.testing.assert_allclose(p[1, -2], 0)
172
+ np.testing.assert_allclose(p[1, -1],
173
+ assoc_legendre_p_1_m1(x, norm=norm))
174
+
175
+ np.testing.assert_allclose(p[2, 0],
176
+ assoc_legendre_p_2_0(x, norm=norm))
177
+ np.testing.assert_allclose(p[2, 1],
178
+ assoc_legendre_p_2_1(x, norm=norm))
179
+ np.testing.assert_allclose(p[2, 2],
180
+ assoc_legendre_p_2_2(x, norm=norm))
181
+ np.testing.assert_allclose(p[2, 3], 0)
182
+ np.testing.assert_allclose(p[2, 4], 0)
183
+ np.testing.assert_allclose(p[2, -4], 0)
184
+ np.testing.assert_allclose(p[2, -3], 0)
185
+ np.testing.assert_allclose(p[2, -2],
186
+ assoc_legendre_p_2_m2(x, norm=norm))
187
+ np.testing.assert_allclose(p[2, -1],
188
+ assoc_legendre_p_2_m1(x, norm=norm))
189
+
190
+ np.testing.assert_allclose(p[3, 0],
191
+ assoc_legendre_p_3_0(x, norm=norm))
192
+ np.testing.assert_allclose(p[3, 1],
193
+ assoc_legendre_p_3_1(x, norm=norm))
194
+ np.testing.assert_allclose(p[3, 2],
195
+ assoc_legendre_p_3_2(x, norm=norm))
196
+ np.testing.assert_allclose(p[3, 3],
197
+ assoc_legendre_p_3_3(x, norm=norm))
198
+ np.testing.assert_allclose(p[3, 4], 0)
199
+ np.testing.assert_allclose(p[3, -4], 0)
200
+ np.testing.assert_allclose(p[3, -3],
201
+ assoc_legendre_p_3_m3(x, norm=norm))
202
+ np.testing.assert_allclose(p[3, -2],
203
+ assoc_legendre_p_3_m2(x, norm=norm))
204
+ np.testing.assert_allclose(p[3, -1],
205
+ assoc_legendre_p_3_m1(x, norm=norm))
206
+
207
+ np.testing.assert_allclose(p[4, 0],
208
+ assoc_legendre_p_4_0(x, norm=norm))
209
+ np.testing.assert_allclose(p[4, 1],
210
+ assoc_legendre_p_4_1(x, norm=norm))
211
+ np.testing.assert_allclose(p[4, 2],
212
+ assoc_legendre_p_4_2(x, norm=norm))
213
+ np.testing.assert_allclose(p[4, 3],
214
+ assoc_legendre_p_4_3(x, norm=norm))
215
+ np.testing.assert_allclose(p[4, 4],
216
+ assoc_legendre_p_4_4(x, norm=norm))
217
+ np.testing.assert_allclose(p[4, -4],
218
+ assoc_legendre_p_4_m4(x, norm=norm))
219
+ np.testing.assert_allclose(p[4, -3],
220
+ assoc_legendre_p_4_m3(x, norm=norm))
221
+ np.testing.assert_allclose(p[4, -2],
222
+ assoc_legendre_p_4_m2(x, norm=norm))
223
+ np.testing.assert_allclose(p[4, -1],
224
+ assoc_legendre_p_4_m1(x, norm=norm))
225
+
226
+ np.testing.assert_allclose(p_jac[0, 0],
227
+ assoc_legendre_p_0_0_jac(x, norm=norm))
228
+ np.testing.assert_allclose(p_jac[0, 1], 0)
229
+ np.testing.assert_allclose(p_jac[0, 2], 0)
230
+ np.testing.assert_allclose(p_jac[0, 3], 0)
231
+ np.testing.assert_allclose(p_jac[0, 4], 0)
232
+ np.testing.assert_allclose(p_jac[0, -4], 0)
233
+ np.testing.assert_allclose(p_jac[0, -3], 0)
234
+ np.testing.assert_allclose(p_jac[0, -2], 0)
235
+ np.testing.assert_allclose(p_jac[0, -1], 0)
236
+
237
+ np.testing.assert_allclose(p_jac[1, 0],
238
+ assoc_legendre_p_1_0_jac(x, norm=norm))
239
+ np.testing.assert_allclose(p_jac[1, 1],
240
+ assoc_legendre_p_1_1_jac(x, norm=norm))
241
+ np.testing.assert_allclose(p_jac[1, 2], 0)
242
+ np.testing.assert_allclose(p_jac[1, 3], 0)
243
+ np.testing.assert_allclose(p_jac[1, 4], 0)
244
+ np.testing.assert_allclose(p_jac[1, -4], 0)
245
+ np.testing.assert_allclose(p_jac[1, -3], 0)
246
+ np.testing.assert_allclose(p_jac[1, -2], 0)
247
+ np.testing.assert_allclose(p_jac[1, -1],
248
+ assoc_legendre_p_1_m1_jac(x, norm=norm))
249
+
250
+ np.testing.assert_allclose(p_jac[2, 0],
251
+ assoc_legendre_p_2_0_jac(x, norm=norm))
252
+ np.testing.assert_allclose(p_jac[2, 1],
253
+ assoc_legendre_p_2_1_jac(x, norm=norm))
254
+ np.testing.assert_allclose(p_jac[2, 2],
255
+ assoc_legendre_p_2_2_jac(x, norm=norm))
256
+ np.testing.assert_allclose(p_jac[2, 3], 0)
257
+ np.testing.assert_allclose(p_jac[2, 4], 0)
258
+ np.testing.assert_allclose(p_jac[2, -4], 0)
259
+ np.testing.assert_allclose(p_jac[2, -3], 0)
260
+ np.testing.assert_allclose(p_jac[2, -2],
261
+ assoc_legendre_p_2_m2_jac(x, norm=norm))
262
+ np.testing.assert_allclose(p_jac[2, -1],
263
+ assoc_legendre_p_2_m1_jac(x, norm=norm))
264
+
265
+ np.testing.assert_allclose(p_jac[3, 0],
266
+ assoc_legendre_p_3_0_jac(x, norm=norm))
267
+ np.testing.assert_allclose(p_jac[3, 1],
268
+ assoc_legendre_p_3_1_jac(x, norm=norm))
269
+ np.testing.assert_allclose(p_jac[3, 2],
270
+ assoc_legendre_p_3_2_jac(x, norm=norm))
271
+ np.testing.assert_allclose(p_jac[3, 3],
272
+ assoc_legendre_p_3_3_jac(x, norm=norm))
273
+ np.testing.assert_allclose(p_jac[3, 4], 0)
274
+ np.testing.assert_allclose(p_jac[3, -4], 0)
275
+ np.testing.assert_allclose(p_jac[3, -3],
276
+ assoc_legendre_p_3_m3_jac(x, norm=norm))
277
+ np.testing.assert_allclose(p_jac[3, -2],
278
+ assoc_legendre_p_3_m2_jac(x, norm=norm))
279
+ np.testing.assert_allclose(p_jac[3, -1],
280
+ assoc_legendre_p_3_m1_jac(x, norm=norm))
281
+
282
+ np.testing.assert_allclose(p_jac[4, 0],
283
+ assoc_legendre_p_4_0_jac(x, norm=norm))
284
+ np.testing.assert_allclose(p_jac[4, 1],
285
+ assoc_legendre_p_4_1_jac(x, norm=norm))
286
+ np.testing.assert_allclose(p_jac[4, 2],
287
+ assoc_legendre_p_4_2_jac(x, norm=norm))
288
+ np.testing.assert_allclose(p_jac[4, 3],
289
+ assoc_legendre_p_4_3_jac(x, norm=norm))
290
+ np.testing.assert_allclose(p_jac[4, 4],
291
+ assoc_legendre_p_4_4_jac(x, norm=norm))
292
+ np.testing.assert_allclose(p_jac[4, -4],
293
+ assoc_legendre_p_4_m4_jac(x, norm=norm))
294
+ np.testing.assert_allclose(p_jac[4, -3],
295
+ assoc_legendre_p_4_m3_jac(x, norm=norm))
296
+ np.testing.assert_allclose(p_jac[4, -2],
297
+ assoc_legendre_p_4_m2_jac(x, norm=norm))
298
+ np.testing.assert_allclose(p_jac[4, -1],
299
+ assoc_legendre_p_4_m1_jac(x, norm=norm))
300
+
301
+ @pytest.mark.parametrize("m_max", [7])
302
+ @pytest.mark.parametrize("n_max", [10])
303
+ @pytest.mark.parametrize("x", [1, -1])
304
+ def test_all_limits(self, m_max, n_max, x):
305
+ p, p_jac = assoc_legendre_p_all(n_max, m_max, x, diff_n=1)
306
+
307
+ n = np.arange(n_max + 1)
308
+
309
+ np.testing.assert_allclose(p_jac[:, 0],
310
+ pow(x, n + 1) * n * (n + 1) / 2)
311
+ np.testing.assert_allclose(p_jac[:, 1],
312
+ np.where(n >= 1, pow(x, n) * np.inf, 0))
313
+ np.testing.assert_allclose(p_jac[:, 2],
314
+ np.where(n >= 2, -pow(x, n + 1) * (n + 2) * (n + 1) * n * (n - 1) / 4, 0))
315
+ np.testing.assert_allclose(p_jac[:, -2],
316
+ np.where(n >= 2, -pow(x, n + 1) / 4, 0))
317
+ np.testing.assert_allclose(p_jac[:, -1],
318
+ np.where(n >= 1, -pow(x, n) * np.inf, 0))
319
+
320
+ for m in range(3, m_max + 1):
321
+ np.testing.assert_allclose(p_jac[:, m], 0)
322
+ np.testing.assert_allclose(p_jac[:, -m], 0)
323
+
324
+ @pytest.mark.parametrize("n", np.arange(0, 20))
325
+ def test_assoc_legendre_p_norm_m0(self, n):
326
+ # gh 24099
327
+ m = 0
328
+ z = np.linspace(-1, 1, 101)
329
+ p = assoc_legendre_p(n, m, z, norm=False)
330
+ p_norm = assoc_legendre_p(n, m, z, norm=True)
331
+ factor = np.sqrt((2 * n + 1) / 2)
332
+ np.testing.assert_allclose(p_norm, factor * p)
333
+
334
+ @pytest.mark.parametrize("n", np.arange(0, 20))
335
+ def test_assoc_legendre_p_all_norm_m0(self, n):
336
+ # gh 24099
337
+ m = 0
338
+ z = np.linspace(-1, 1, 101)
339
+ p_all = assoc_legendre_p_all(n, m, z, norm=False)[0, : n + 1, 0, :]
340
+ p_norm_all = assoc_legendre_p_all(n, m, z, norm=True)[0, : n + 1, 0, :]
341
+ factor = np.sqrt((2 * np.arange(n + 1) + 1) / 2)
342
+ factor = factor[:, np.newaxis]
343
+ np.testing.assert_allclose(p_norm_all, factor * p_all)
344
+
345
+
346
+ class TestMultiAssocLegendreP:
347
+ @pytest.mark.parametrize("shape", [(1000,), (4, 9), (3, 5, 7)])
348
+ @pytest.mark.parametrize("branch_cut", [2, 3])
349
+ @pytest.mark.parametrize("z_min, z_max", [(-10 - 10j, 10 + 10j),
350
+ (-1, 1), (-10j, 10j)])
351
+ @pytest.mark.parametrize("norm", [True, False])
352
+ def test_specific(self, shape, branch_cut, z_min, z_max, norm):
353
+ rng = np.random.default_rng(1234)
354
+
355
+ z = rng.uniform(z_min.real, z_max.real, shape) + \
356
+ 1j * rng.uniform(z_min.imag, z_max.imag, shape)
357
+
358
+ p, p_jac = assoc_legendre_p_all(4, 4,
359
+ z, branch_cut=branch_cut, norm=norm, diff_n=1)
360
+
361
+ np.testing.assert_allclose(p[0, 0],
362
+ assoc_legendre_p_0_0(z, branch_cut=branch_cut, norm=norm))
363
+ np.testing.assert_allclose(p[0, 1], 0)
364
+ np.testing.assert_allclose(p[0, 2], 0)
365
+ np.testing.assert_allclose(p[0, 3], 0)
366
+ np.testing.assert_allclose(p[0, 4], 0)
367
+ np.testing.assert_allclose(p[0, -4], 0)
368
+ np.testing.assert_allclose(p[0, -3], 0)
369
+ np.testing.assert_allclose(p[0, -2], 0)
370
+ np.testing.assert_allclose(p[0, -1], 0)
371
+
372
+ np.testing.assert_allclose(p[1, 0],
373
+ assoc_legendre_p_1_0(z, branch_cut=branch_cut, norm=norm))
374
+ np.testing.assert_allclose(p[1, 1],
375
+ assoc_legendre_p_1_1(z, branch_cut=branch_cut, norm=norm))
376
+ np.testing.assert_allclose(p[1, 2], 0)
377
+ np.testing.assert_allclose(p[1, 3], 0)
378
+ np.testing.assert_allclose(p[1, 4], 0)
379
+ np.testing.assert_allclose(p[1, -4], 0)
380
+ np.testing.assert_allclose(p[1, -3], 0)
381
+ np.testing.assert_allclose(p[1, -2], 0)
382
+ np.testing.assert_allclose(p[1, -1],
383
+ assoc_legendre_p_1_m1(z, branch_cut=branch_cut, norm=norm))
384
+
385
+ np.testing.assert_allclose(p[2, 0],
386
+ assoc_legendre_p_2_0(z, branch_cut=branch_cut, norm=norm))
387
+ np.testing.assert_allclose(p[2, 1],
388
+ assoc_legendre_p_2_1(z, branch_cut=branch_cut, norm=norm))
389
+ np.testing.assert_allclose(p[2, 2],
390
+ assoc_legendre_p_2_2(z, branch_cut=branch_cut, norm=norm))
391
+ np.testing.assert_allclose(p[2, 3], 0)
392
+ np.testing.assert_allclose(p[2, 4], 0)
393
+ np.testing.assert_allclose(p[2, -4], 0)
394
+ np.testing.assert_allclose(p[2, -3], 0)
395
+ np.testing.assert_allclose(p[2, -2],
396
+ assoc_legendre_p_2_m2(z, branch_cut=branch_cut, norm=norm))
397
+ np.testing.assert_allclose(p[2, -1],
398
+ assoc_legendre_p_2_m1(z, branch_cut=branch_cut, norm=norm))
399
+
400
+ np.testing.assert_allclose(p[3, 0],
401
+ assoc_legendre_p_3_0(z, branch_cut=branch_cut, norm=norm))
402
+ np.testing.assert_allclose(p[3, 1],
403
+ assoc_legendre_p_3_1(z, branch_cut=branch_cut, norm=norm))
404
+ np.testing.assert_allclose(p[3, 2],
405
+ assoc_legendre_p_3_2(z, branch_cut=branch_cut, norm=norm))
406
+ np.testing.assert_allclose(p[3, 3],
407
+ assoc_legendre_p_3_3(z, branch_cut=branch_cut, norm=norm))
408
+ np.testing.assert_allclose(p[3, 4], 0)
409
+ np.testing.assert_allclose(p[3, -4], 0)
410
+ np.testing.assert_allclose(p[3, -3],
411
+ assoc_legendre_p_3_m3(z, branch_cut=branch_cut, norm=norm))
412
+ np.testing.assert_allclose(p[3, -2],
413
+ assoc_legendre_p_3_m2(z, branch_cut=branch_cut, norm=norm))
414
+ np.testing.assert_allclose(p[3, -1],
415
+ assoc_legendre_p_3_m1(z, branch_cut=branch_cut, norm=norm))
416
+
417
+ np.testing.assert_allclose(p[4, 0],
418
+ assoc_legendre_p_4_0(z, branch_cut=branch_cut, norm=norm))
419
+ np.testing.assert_allclose(p[4, 1],
420
+ assoc_legendre_p_4_1(z, branch_cut=branch_cut, norm=norm))
421
+ np.testing.assert_allclose(p[4, 2],
422
+ assoc_legendre_p_4_2(z, branch_cut=branch_cut, norm=norm))
423
+ np.testing.assert_allclose(p[4, 3],
424
+ assoc_legendre_p_4_3(z, branch_cut=branch_cut, norm=norm))
425
+ np.testing.assert_allclose(p[4, 4],
426
+ assoc_legendre_p_4_4(z, branch_cut=branch_cut, norm=norm))
427
+ np.testing.assert_allclose(p[4, -4],
428
+ assoc_legendre_p_4_m4(z, branch_cut=branch_cut, norm=norm))
429
+ np.testing.assert_allclose(p[4, -3],
430
+ assoc_legendre_p_4_m3(z, branch_cut=branch_cut, norm=norm))
431
+ np.testing.assert_allclose(p[4, -2],
432
+ assoc_legendre_p_4_m2(z, branch_cut=branch_cut, norm=norm))
433
+ np.testing.assert_allclose(p[4, -1],
434
+ assoc_legendre_p_4_m1(z, branch_cut=branch_cut, norm=norm))
435
+
436
+ np.testing.assert_allclose(p_jac[0, 0],
437
+ assoc_legendre_p_0_0_jac(z, branch_cut=branch_cut, norm=norm))
438
+ np.testing.assert_allclose(p_jac[0, 1], 0)
439
+ np.testing.assert_allclose(p_jac[0, 2], 0)
440
+ np.testing.assert_allclose(p_jac[0, 3], 0)
441
+ np.testing.assert_allclose(p_jac[0, 4], 0)
442
+ np.testing.assert_allclose(p_jac[0, -4], 0)
443
+ np.testing.assert_allclose(p_jac[0, -3], 0)
444
+ np.testing.assert_allclose(p_jac[0, -2], 0)
445
+ np.testing.assert_allclose(p_jac[0, -1], 0)
446
+
447
+ np.testing.assert_allclose(p_jac[1, 0],
448
+ assoc_legendre_p_1_0_jac(z, branch_cut=branch_cut, norm=norm))
449
+ np.testing.assert_allclose(p_jac[1, 1],
450
+ assoc_legendre_p_1_1_jac(z, branch_cut=branch_cut, norm=norm))
451
+ np.testing.assert_allclose(p_jac[1, 2], 0)
452
+ np.testing.assert_allclose(p_jac[1, 3], 0)
453
+ np.testing.assert_allclose(p_jac[1, 4], 0)
454
+ np.testing.assert_allclose(p_jac[1, -4], 0)
455
+ np.testing.assert_allclose(p_jac[1, -3], 0)
456
+ np.testing.assert_allclose(p_jac[1, -2], 0)
457
+ np.testing.assert_allclose(p_jac[1, -1],
458
+ assoc_legendre_p_1_m1_jac(z, branch_cut=branch_cut, norm=norm))
459
+
460
+ np.testing.assert_allclose(p_jac[2, 0],
461
+ assoc_legendre_p_2_0_jac(z, branch_cut=branch_cut, norm=norm))
462
+ np.testing.assert_allclose(p_jac[2, 1],
463
+ assoc_legendre_p_2_1_jac(z, branch_cut=branch_cut, norm=norm))
464
+ np.testing.assert_allclose(p_jac[2, 2],
465
+ assoc_legendre_p_2_2_jac(z, branch_cut=branch_cut, norm=norm))
466
+ np.testing.assert_allclose(p_jac[2, 3], 0)
467
+ np.testing.assert_allclose(p_jac[2, 4], 0)
468
+ np.testing.assert_allclose(p_jac[2, -4], 0)
469
+ np.testing.assert_allclose(p_jac[2, -3], 0)
470
+ np.testing.assert_allclose(p_jac[2, -2],
471
+ assoc_legendre_p_2_m2_jac(z, branch_cut=branch_cut, norm=norm))
472
+ np.testing.assert_allclose(p_jac[2, -1],
473
+ assoc_legendre_p_2_m1_jac(z, branch_cut=branch_cut, norm=norm))
474
+
475
+ np.testing.assert_allclose(p_jac[3, 0],
476
+ assoc_legendre_p_3_0_jac(z, branch_cut=branch_cut, norm=norm))
477
+ np.testing.assert_allclose(p_jac[3, 1],
478
+ assoc_legendre_p_3_1_jac(z, branch_cut=branch_cut, norm=norm))
479
+ np.testing.assert_allclose(p_jac[3, 2],
480
+ assoc_legendre_p_3_2_jac(z, branch_cut=branch_cut, norm=norm))
481
+ np.testing.assert_allclose(p_jac[3, 3],
482
+ assoc_legendre_p_3_3_jac(z, branch_cut=branch_cut, norm=norm))
483
+ np.testing.assert_allclose(p_jac[3, 4], 0)
484
+ np.testing.assert_allclose(p_jac[3, -4], 0)
485
+ np.testing.assert_allclose(p_jac[3, -3],
486
+ assoc_legendre_p_3_m3_jac(z, branch_cut=branch_cut, norm=norm))
487
+ np.testing.assert_allclose(p_jac[3, -2],
488
+ assoc_legendre_p_3_m2_jac(z, branch_cut=branch_cut, norm=norm))
489
+ np.testing.assert_allclose(p_jac[3, -1],
490
+ assoc_legendre_p_3_m1_jac(z, branch_cut=branch_cut, norm=norm))
491
+
492
+ np.testing.assert_allclose(p_jac[4, 0],
493
+ assoc_legendre_p_4_0_jac(z, branch_cut=branch_cut, norm=norm))
494
+ np.testing.assert_allclose(p_jac[4, 1],
495
+ assoc_legendre_p_4_1_jac(z, branch_cut=branch_cut, norm=norm))
496
+ np.testing.assert_allclose(p_jac[4, 2],
497
+ assoc_legendre_p_4_2_jac(z, branch_cut=branch_cut, norm=norm))
498
+ np.testing.assert_allclose(p_jac[4, 3],
499
+ assoc_legendre_p_4_3_jac(z, branch_cut=branch_cut, norm=norm))
500
+ np.testing.assert_allclose(p_jac[4, 4],
501
+ assoc_legendre_p_4_4_jac(z, branch_cut=branch_cut, norm=norm))
502
+ np.testing.assert_allclose(p_jac[4, -4],
503
+ assoc_legendre_p_4_m4_jac(z, branch_cut=branch_cut, norm=norm))
504
+ np.testing.assert_allclose(p_jac[4, -3],
505
+ assoc_legendre_p_4_m3_jac(z, branch_cut=branch_cut, norm=norm))
506
+ np.testing.assert_allclose(p_jac[4, -2],
507
+ assoc_legendre_p_4_m2_jac(z, branch_cut=branch_cut, norm=norm))
508
+ np.testing.assert_allclose(p_jac[4, -1],
509
+ assoc_legendre_p_4_m1_jac(z, branch_cut=branch_cut, norm=norm))
510
+
511
+ class TestSphLegendreP:
512
+ @pytest.mark.parametrize("shape", [(10,), (4, 9), (3, 5, 7)])
513
+ def test_specific(self, shape):
514
+ rng = np.random.default_rng(1234)
515
+
516
+ theta = rng.uniform(-np.pi, np.pi, shape)
517
+
518
+ p, p_jac = sph_legendre_p_all(4, 4, theta, diff_n=1)
519
+
520
+ np.testing.assert_allclose(p[0, 0],
521
+ sph_legendre_p_0_0(theta))
522
+ np.testing.assert_allclose(p[0, 1], 0)
523
+ np.testing.assert_allclose(p[0, 2], 0)
524
+ np.testing.assert_allclose(p[0, 3], 0)
525
+ np.testing.assert_allclose(p[0, 4], 0)
526
+ np.testing.assert_allclose(p[0, -3], 0)
527
+ np.testing.assert_allclose(p[0, -2], 0)
528
+ np.testing.assert_allclose(p[0, -1], 0)
529
+
530
+ np.testing.assert_allclose(p[1, 0],
531
+ sph_legendre_p_1_0(theta))
532
+ np.testing.assert_allclose(p[1, 1],
533
+ sph_legendre_p_1_1(theta))
534
+ np.testing.assert_allclose(p[1, 2], 0)
535
+ np.testing.assert_allclose(p[1, 3], 0)
536
+ np.testing.assert_allclose(p[1, 4], 0)
537
+ np.testing.assert_allclose(p[1, -4], 0)
538
+ np.testing.assert_allclose(p[1, -3], 0)
539
+ np.testing.assert_allclose(p[1, -2], 0)
540
+ np.testing.assert_allclose(p[1, -1],
541
+ sph_legendre_p_1_m1(theta))
542
+
543
+ np.testing.assert_allclose(p[2, 0],
544
+ sph_legendre_p_2_0(theta))
545
+ np.testing.assert_allclose(p[2, 1],
546
+ sph_legendre_p_2_1(theta))
547
+ np.testing.assert_allclose(p[2, 2],
548
+ sph_legendre_p_2_2(theta))
549
+ np.testing.assert_allclose(p[2, 3], 0)
550
+ np.testing.assert_allclose(p[2, 4], 0)
551
+ np.testing.assert_allclose(p[2, -4], 0)
552
+ np.testing.assert_allclose(p[2, -3], 0)
553
+ np.testing.assert_allclose(p[2, -2],
554
+ sph_legendre_p_2_m2(theta))
555
+ np.testing.assert_allclose(p[2, -1],
556
+ sph_legendre_p_2_m1(theta))
557
+
558
+ np.testing.assert_allclose(p[3, 0],
559
+ sph_legendre_p_3_0(theta))
560
+ np.testing.assert_allclose(p[3, 1],
561
+ sph_legendre_p_3_1(theta))
562
+ np.testing.assert_allclose(p[3, 2],
563
+ sph_legendre_p_3_2(theta))
564
+ np.testing.assert_allclose(p[3, 3],
565
+ sph_legendre_p_3_3(theta))
566
+ np.testing.assert_allclose(p[3, 4], 0)
567
+ np.testing.assert_allclose(p[3, -4], 0)
568
+ np.testing.assert_allclose(p[3, -3],
569
+ sph_legendre_p_3_m3(theta))
570
+ np.testing.assert_allclose(p[3, -2],
571
+ sph_legendre_p_3_m2(theta))
572
+ np.testing.assert_allclose(p[3, -1],
573
+ sph_legendre_p_3_m1(theta))
574
+
575
+ np.testing.assert_allclose(p[4, 0],
576
+ sph_legendre_p_4_0(theta))
577
+ np.testing.assert_allclose(p[4, 1],
578
+ sph_legendre_p_4_1(theta))
579
+ np.testing.assert_allclose(p[4, 2],
580
+ sph_legendre_p_4_2(theta))
581
+ np.testing.assert_allclose(p[4, 3],
582
+ sph_legendre_p_4_3(theta))
583
+ np.testing.assert_allclose(p[4, 4],
584
+ sph_legendre_p_4_4(theta))
585
+ np.testing.assert_allclose(p[4, -4],
586
+ sph_legendre_p_4_m4(theta))
587
+ np.testing.assert_allclose(p[4, -3],
588
+ sph_legendre_p_4_m3(theta))
589
+ np.testing.assert_allclose(p[4, -2],
590
+ sph_legendre_p_4_m2(theta))
591
+ np.testing.assert_allclose(p[4, -1],
592
+ sph_legendre_p_4_m1(theta))
593
+
594
+ np.testing.assert_allclose(p_jac[0, 0],
595
+ sph_legendre_p_0_0_jac(theta))
596
+ np.testing.assert_allclose(p_jac[0, 1], 0)
597
+ np.testing.assert_allclose(p_jac[0, 2], 0)
598
+ np.testing.assert_allclose(p_jac[0, 3], 0)
599
+ np.testing.assert_allclose(p_jac[0, 4], 0)
600
+ np.testing.assert_allclose(p_jac[0, -3], 0)
601
+ np.testing.assert_allclose(p_jac[0, -2], 0)
602
+ np.testing.assert_allclose(p_jac[0, -1], 0)
603
+
604
+ np.testing.assert_allclose(p_jac[1, 0],
605
+ sph_legendre_p_1_0_jac(theta))
606
+ np.testing.assert_allclose(p_jac[1, 1],
607
+ sph_legendre_p_1_1_jac(theta))
608
+ np.testing.assert_allclose(p_jac[1, 2], 0)
609
+ np.testing.assert_allclose(p_jac[1, 3], 0)
610
+ np.testing.assert_allclose(p_jac[1, 4], 0)
611
+ np.testing.assert_allclose(p_jac[1, -4], 0)
612
+ np.testing.assert_allclose(p_jac[1, -3], 0)
613
+ np.testing.assert_allclose(p_jac[1, -2], 0)
614
+ np.testing.assert_allclose(p_jac[1, -1],
615
+ sph_legendre_p_1_m1_jac(theta))
616
+
617
+ np.testing.assert_allclose(p_jac[2, 0],
618
+ sph_legendre_p_2_0_jac(theta))
619
+ np.testing.assert_allclose(p_jac[2, 1],
620
+ sph_legendre_p_2_1_jac(theta))
621
+ np.testing.assert_allclose(p_jac[2, 2],
622
+ sph_legendre_p_2_2_jac(theta))
623
+ np.testing.assert_allclose(p_jac[2, 3], 0)
624
+ np.testing.assert_allclose(p_jac[2, 4], 0)
625
+ np.testing.assert_allclose(p_jac[2, -4], 0)
626
+ np.testing.assert_allclose(p_jac[2, -3], 0)
627
+ np.testing.assert_allclose(p_jac[2, -2],
628
+ sph_legendre_p_2_m2_jac(theta))
629
+ np.testing.assert_allclose(p_jac[2, -1],
630
+ sph_legendre_p_2_m1_jac(theta))
631
+
632
+ np.testing.assert_allclose(p_jac[3, 0],
633
+ sph_legendre_p_3_0_jac(theta))
634
+ np.testing.assert_allclose(p_jac[3, 1],
635
+ sph_legendre_p_3_1_jac(theta))
636
+ np.testing.assert_allclose(p_jac[3, 2],
637
+ sph_legendre_p_3_2_jac(theta))
638
+ np.testing.assert_allclose(p_jac[3, 3],
639
+ sph_legendre_p_3_3_jac(theta))
640
+ np.testing.assert_allclose(p_jac[3, 4], 0)
641
+ np.testing.assert_allclose(p_jac[3, -4], 0)
642
+ np.testing.assert_allclose(p_jac[3, -3],
643
+ sph_legendre_p_3_m3_jac(theta))
644
+ np.testing.assert_allclose(p_jac[3, -2],
645
+ sph_legendre_p_3_m2_jac(theta))
646
+ np.testing.assert_allclose(p_jac[3, -1],
647
+ sph_legendre_p_3_m1_jac(theta))
648
+
649
+ np.testing.assert_allclose(p_jac[4, 0],
650
+ sph_legendre_p_4_0_jac(theta))
651
+ np.testing.assert_allclose(p_jac[4, 1],
652
+ sph_legendre_p_4_1_jac(theta))
653
+ np.testing.assert_allclose(p_jac[4, 2],
654
+ sph_legendre_p_4_2_jac(theta))
655
+ np.testing.assert_allclose(p_jac[4, 3],
656
+ sph_legendre_p_4_3_jac(theta))
657
+ np.testing.assert_allclose(p_jac[4, 4],
658
+ sph_legendre_p_4_4_jac(theta))
659
+ np.testing.assert_allclose(p_jac[4, -4],
660
+ sph_legendre_p_4_m4_jac(theta))
661
+ np.testing.assert_allclose(p_jac[4, -3],
662
+ sph_legendre_p_4_m3_jac(theta))
663
+ np.testing.assert_allclose(p_jac[4, -2],
664
+ sph_legendre_p_4_m2_jac(theta))
665
+ np.testing.assert_allclose(p_jac[4, -1],
666
+ sph_legendre_p_4_m1_jac(theta))
667
+
668
+ @pytest.mark.parametrize("shape", [(10,), (4, 9), (3, 5, 7, 10)])
669
+ def test_ode(self, shape):
670
+ rng = np.random.default_rng(1234)
671
+
672
+ n = rng.integers(0, 10, shape)
673
+ m = rng.integers(-10, 10, shape)
674
+ theta = rng.uniform(-np.pi, np.pi, shape)
675
+
676
+ p, p_jac, p_hess = sph_legendre_p(n, m, theta, diff_n=2)
677
+
678
+ assert p.shape == shape
679
+ assert p_jac.shape == p.shape
680
+ assert p_hess.shape == p_jac.shape
681
+
682
+ np.testing.assert_allclose(np.sin(theta) * p_hess, -np.cos(theta) * p_jac
683
+ - (n * (n + 1) * np.sin(theta) - m * m / np.sin(theta)) * p,
684
+ rtol=1e-05, atol=1e-08)
685
+
686
+ class TestLegendreFunctions:
687
+ """
688
+ @pytest.mark.parametrize("m_max", [3])
689
+ @pytest.mark.parametrize("n_max", [5])
690
+ @pytest.mark.parametrize("z", [-1])
691
+ def test_clpmn_all_limits(self, m_max, n_max, z):
692
+ rng = np.random.default_rng(1234)
693
+
694
+ type = 2
695
+
696
+ p, p_jac = special.clpmn_all(m_max, n_max, type, z, diff_n=1)
697
+
698
+ n = np.arange(n_max + 1)
699
+
700
+ np.testing.assert_allclose(p_jac[0], pow(z, n + 1) * n * (n + 1) / 2)
701
+ np.testing.assert_allclose(p_jac[1], np.where(n >= 1, pow(z, n) * np.inf, 0))
702
+ np.testing.assert_allclose(p_jac[2], np.where(n >= 2,
703
+ -pow(z, n + 1) * (n + 2) * (n + 1) * n * (n - 1) / 4, 0))
704
+ np.testing.assert_allclose(p_jac[-2], np.where(n >= 2, -pow(z, n + 1) / 4, 0))
705
+ np.testing.assert_allclose(p_jac[-1], np.where(n >= 1, -pow(z, n) * np.inf, 0))
706
+
707
+ for m in range(3, m_max + 1):
708
+ np.testing.assert_allclose(p_jac[m], 0)
709
+ np.testing.assert_allclose(p_jac[-m], 0)
710
+ """
711
+
712
+ def test_lpmv(self):
713
+ lp = special.lpmv(0, 2, .5)
714
+ assert_allclose(lp, -0.125, atol=1.5e-7, rtol=0)
715
+ lp = special.lpmv(0, 40, .001)
716
+ assert_allclose(lp, 0.1252678976534484, atol=1.5e-7, rtol=0)
717
+
718
+ # XXX: this is outside the domain of the current implementation,
719
+ # so ensure it returns a NaN rather than a wrong answer.
720
+ with np.errstate(all='ignore'):
721
+ lp = special.lpmv(-1,-1,.001)
722
+ assert lp != 0 or np.isnan(lp)
723
+
724
+ def test_lqmn(self):
725
+ lqmnf = special.lqmn(0, 2, .5)
726
+ lqf = special.lqn(2, .5)
727
+ assert_allclose(lqmnf[0][0], lqf[0], atol=1.5e-4, rtol=0)
728
+ assert_allclose(lqmnf[1][0], lqf[1], atol=1.5e-4, rtol=0)
729
+
730
+ def test_lqmn_gt1(self):
731
+ """algorithm for real arguments changes at 1.0001
732
+ test against analytical result for m=2, n=1
733
+ """
734
+ x0 = 1.0001
735
+ delta = 0.00002
736
+ for x in (x0-delta, x0+delta):
737
+ lq = special.lqmn(2, 1, x)[0][-1, -1]
738
+ expected = 2/(x*x-1)
739
+ assert_allclose(lq, expected, atol=1.5e-7, rtol=0)
740
+
741
+ def test_lqmn_shape(self):
742
+ a, b = special.lqmn(4, 4, 1.1)
743
+ assert_equal(a.shape, (5, 5))
744
+ assert_equal(b.shape, (5, 5))
745
+
746
+ a, b = special.lqmn(4, 0, 1.1)
747
+ assert_equal(a.shape, (5, 1))
748
+ assert_equal(b.shape, (5, 1))
749
+
750
+ def test_lqn(self):
751
+ lqf = special.lqn(2, .5)
752
+ assert_allclose(lqf, (np.array([0.5493, -0.7253, -0.8187]),
753
+ np.array([1.3333, 1.216, -0.8427])),
754
+ atol=1.5e-4, rtol=0)
755
+
756
+ @pytest.mark.parametrize("function", [special.lqn])
757
+ @pytest.mark.parametrize("n", [1, 2, 4, 8, 16, 32])
758
+ @pytest.mark.parametrize("z_complex", [False, True])
759
+ @pytest.mark.parametrize("z_inexact", [False, True])
760
+ @pytest.mark.parametrize(
761
+ "input_shape",
762
+ [
763
+ (), (1, ), (2, ), (2, 1), (1, 2), (2, 2), (2, 2, 1), (2, 2, 2)
764
+ ]
765
+ )
766
+ def test_array_inputs_lxn(self, function, n, z_complex, z_inexact, input_shape):
767
+ """Tests for correct output shapes."""
768
+ rng = np.random.default_rng(1234)
769
+ if z_inexact:
770
+ z = rng.integers(-3, 3, size=input_shape)
771
+ else:
772
+ z = rng.uniform(-1, 1, size=input_shape)
773
+
774
+ if z_complex:
775
+ z = 1j * z + 0.5j * z
776
+
777
+ with warnings.catch_warnings():
778
+ warnings.simplefilter("ignore", category=DeprecationWarning)
779
+ P_z, P_d_z = function(n, z)
780
+ assert P_z.shape == (n + 1, ) + input_shape
781
+ assert P_d_z.shape == (n + 1, ) + input_shape
782
+
783
+ @pytest.mark.parametrize("function", [special.lqmn])
784
+ @pytest.mark.parametrize(
785
+ "m,n",
786
+ [(0, 1), (1, 2), (1, 4), (3, 8), (11, 16), (19, 32)]
787
+ )
788
+ @pytest.mark.parametrize("z_inexact", [False, True])
789
+ @pytest.mark.parametrize(
790
+ "input_shape", [
791
+ (), (1, ), (2, ), (2, 1), (1, 2), (2, 2), (2, 2, 1)
792
+ ]
793
+ )
794
+ def test_array_inputs_lxmn(self, function, m, n, z_inexact, input_shape):
795
+ """Tests for correct output shapes and dtypes."""
796
+ rng = np.random.default_rng(1234)
797
+ if z_inexact:
798
+ z = rng.integers(-3, 3, size=input_shape)
799
+ else:
800
+ z = rng.uniform(-1, 1, size=input_shape)
801
+
802
+ P_z, P_d_z = function(m, n, z)
803
+ assert P_z.shape == (m + 1, n + 1) + input_shape
804
+ assert P_d_z.shape == (m + 1, n + 1) + input_shape
805
+
806
+ @pytest.mark.parametrize("function", [special.lqmn])
807
+ @pytest.mark.parametrize(
808
+ "m,n",
809
+ [(0, 1), (1, 2), (1, 4), (3, 8), (11, 16), (19, 32)]
810
+ )
811
+ @pytest.mark.parametrize(
812
+ "input_shape", [
813
+ (), (1, ), (2, ), (2, 1), (1, 2), (2, 2), (2, 2, 1)
814
+ ]
815
+ )
816
+ def test_array_inputs_clxmn(self, function, m, n, input_shape):
817
+ """Tests for correct output shapes and dtypes."""
818
+ rng = np.random.default_rng(1234)
819
+ z = rng.uniform(-1, 1, size=input_shape)
820
+ z = 1j * z + 0.5j * z
821
+
822
+ with warnings.catch_warnings():
823
+ warnings.simplefilter("ignore", category=DeprecationWarning)
824
+ P_z, P_d_z = function(m, n, z)
825
+
826
+ assert P_z.shape == (m + 1, n + 1) + input_shape
827
+ assert P_d_z.shape == (m + 1, n + 1) + input_shape
828
+
829
+ def assoc_legendre_factor(n, m, norm):
830
+ if norm:
831
+ return (math.sqrt((2 * n + 1) *
832
+ math.factorial(n - m) / (2 * math.factorial(n + m))))
833
+
834
+ return 1
835
+
836
+ def assoc_legendre_p_0_0(z, *, branch_cut=2, norm=False):
837
+ fac = assoc_legendre_factor(0, 0, norm)
838
+
839
+ return np.full_like(z, fac)
840
+
841
+ def assoc_legendre_p_1_0(z, *, branch_cut=2, norm=False):
842
+ fac = assoc_legendre_factor(1, 0, norm)
843
+
844
+ return fac * z
845
+
846
+ def assoc_legendre_p_1_1(z, *, branch_cut=2, norm=False):
847
+ branch_sign = np.where(branch_cut == 3, np.where(np.signbit(np.real(z)), 1, -1), -1)
848
+ branch_cut_sign = np.where(branch_cut == 3, -1, 1)
849
+ fac = assoc_legendre_factor(1, 1, norm)
850
+
851
+ w = np.sqrt(np.where(branch_cut == 3, z * z - 1, 1 - z * z))
852
+
853
+ return branch_cut_sign * branch_sign * fac * w
854
+
855
+ def assoc_legendre_p_1_m1(z, *, branch_cut=2, norm=False):
856
+ branch_cut_sign = np.where(branch_cut == 3, -1, 1)
857
+ fac = assoc_legendre_factor(1, -1, norm)
858
+
859
+ return (-branch_cut_sign * fac *
860
+ assoc_legendre_p_1_1(z, branch_cut=branch_cut) / 2)
861
+
862
+ def assoc_legendre_p_2_0(z, *, branch_cut=2, norm=False):
863
+ fac = assoc_legendre_factor(2, 0, norm)
864
+
865
+ return fac * (3 * z * z - 1) / 2
866
+
867
+ def assoc_legendre_p_2_1(z, *, branch_cut=2, norm=False):
868
+ fac = assoc_legendre_factor(2, 1, norm)
869
+
870
+ return (3 * fac * z *
871
+ assoc_legendre_p_1_1(z, branch_cut=branch_cut))
872
+
873
+ def assoc_legendre_p_2_2(z, *, branch_cut=2, norm=False):
874
+ branch_cut_sign = np.where(branch_cut == 3, -1, 1)
875
+ fac = assoc_legendre_factor(2, 2, norm)
876
+
877
+ return 3 * branch_cut_sign * fac * (1 - z * z)
878
+
879
+ def assoc_legendre_p_2_m2(z, *, branch_cut=2, norm=False):
880
+ branch_cut_sign = np.where(branch_cut == 3, -1, 1)
881
+ fac = assoc_legendre_factor(2, -2, norm)
882
+
883
+ return branch_cut_sign * fac * (1 - z * z) / 8
884
+
885
+ def assoc_legendre_p_2_m1(z, *, branch_cut=2, norm=False):
886
+ branch_cut_sign = np.where(branch_cut == 3, -1, 1)
887
+ fac = assoc_legendre_factor(2, -1, norm)
888
+
889
+ return (-branch_cut_sign * fac * z *
890
+ assoc_legendre_p_1_1(z, branch_cut=branch_cut) / 2)
891
+
892
+ def assoc_legendre_p_3_0(z, *, branch_cut=2, norm=False):
893
+ fac = assoc_legendre_factor(3, 0, norm)
894
+
895
+ return fac * (5 * z * z - 3) * z / 2
896
+
897
+ def assoc_legendre_p_3_1(z, *, branch_cut=2, norm=False):
898
+ fac = assoc_legendre_factor(3, 1, norm)
899
+
900
+ return (3 * fac * (5 * z * z - 1) *
901
+ assoc_legendre_p_1_1(z, branch_cut=branch_cut) / 2)
902
+
903
+ def assoc_legendre_p_3_2(z, *, branch_cut=2, norm=False):
904
+ branch_cut_sign = np.where(branch_cut == 3, -1, 1)
905
+ fac = assoc_legendre_factor(3, 2, norm)
906
+
907
+ return 15 * branch_cut_sign * fac * (1 - z * z) * z
908
+
909
+ def assoc_legendre_p_3_3(z, *, branch_cut=2, norm=False):
910
+ branch_cut_sign = np.where(branch_cut == 3, -1, 1)
911
+ fac = assoc_legendre_factor(3, 3, norm)
912
+
913
+ return (15 * branch_cut_sign * fac * (1 - z * z) *
914
+ assoc_legendre_p_1_1(z, branch_cut=branch_cut))
915
+
916
+ def assoc_legendre_p_3_m3(z, *, branch_cut=2, norm=False):
917
+ fac = assoc_legendre_factor(3, -3, norm)
918
+
919
+ return (fac * (z * z - 1) *
920
+ assoc_legendre_p_1_1(z, branch_cut=branch_cut) / 48)
921
+
922
+ def assoc_legendre_p_3_m2(z, *, branch_cut=2, norm=False):
923
+ branch_cut_sign = np.where(branch_cut == 3, -1, 1)
924
+ fac = assoc_legendre_factor(3, -2, norm)
925
+
926
+ return branch_cut_sign * fac * (1 - z * z) * z / 8
927
+
928
+ def assoc_legendre_p_3_m1(z, *, branch_cut=2, norm=False):
929
+ branch_cut_sign = np.where(branch_cut == 3, -1, 1)
930
+ fac = assoc_legendre_factor(3, -1, norm)
931
+
932
+ return (branch_cut_sign * fac * (1 - 5 * z * z) *
933
+ assoc_legendre_p_1_1(z, branch_cut=branch_cut) / 8)
934
+
935
+ def assoc_legendre_p_4_0(z, *, branch_cut=2, norm=False):
936
+ fac = assoc_legendre_factor(4, 0, norm)
937
+
938
+ return fac * ((35 * z * z - 30) * z * z + 3) / 8
939
+
940
+ def assoc_legendre_p_4_1(z, *, branch_cut=2, norm=False):
941
+ fac = assoc_legendre_factor(4, 1, norm)
942
+
943
+ return (5 * fac * (7 * z * z - 3) * z *
944
+ assoc_legendre_p_1_1(z, branch_cut=branch_cut) / 2)
945
+
946
+ def assoc_legendre_p_4_2(z, *, branch_cut=2, norm=False):
947
+ branch_cut_sign = np.where(branch_cut == 3, -1, 1)
948
+ fac = assoc_legendre_factor(4, 2, norm)
949
+
950
+ return 15 * branch_cut_sign * fac * ((8 - 7 * z * z) * z * z - 1) / 2
951
+
952
+ def assoc_legendre_p_4_3(z, *, branch_cut=2, norm=False):
953
+ branch_cut_sign = np.where(branch_cut == 3, -1, 1)
954
+ fac = assoc_legendre_factor(4, 3, norm)
955
+
956
+ return (105 * branch_cut_sign * fac * (1 - z * z) * z *
957
+ assoc_legendre_p_1_1(z, branch_cut=branch_cut))
958
+
959
+ def assoc_legendre_p_4_4(z, *, branch_cut=2, norm=False):
960
+ fac = assoc_legendre_factor(4, 4, norm)
961
+
962
+ return 105 * fac * np.square(z * z - 1)
963
+
964
+ def assoc_legendre_p_4_m4(z, *, branch_cut=2, norm=False):
965
+ fac = assoc_legendre_factor(4, -4, norm)
966
+
967
+ return fac * np.square(z * z - 1) / 384
968
+
969
+ def assoc_legendre_p_4_m3(z, *, branch_cut=2, norm=False):
970
+ fac = assoc_legendre_factor(4, -3, norm)
971
+
972
+ return (fac * (z * z - 1) * z *
973
+ assoc_legendre_p_1_1(z, branch_cut=branch_cut) / 48)
974
+
975
+ def assoc_legendre_p_4_m2(z, *, branch_cut=2, norm=False):
976
+ branch_cut_sign = np.where(branch_cut == 3, -1, 1)
977
+ fac = assoc_legendre_factor(4, -2, norm)
978
+
979
+ return branch_cut_sign * fac * ((8 - 7 * z * z) * z * z - 1) / 48
980
+
981
+ def assoc_legendre_p_4_m1(z, *, branch_cut=2, norm=False):
982
+ branch_cut_sign = np.where(branch_cut == 3, -1, 1)
983
+ fac = assoc_legendre_factor(4, -1, norm)
984
+
985
+ return (branch_cut_sign * fac * (3 - 7 * z * z) * z *
986
+ assoc_legendre_p_1_1(z, branch_cut=branch_cut) / 8)
987
+
988
+ def assoc_legendre_p_1_1_jac_div_z(z, branch_cut=2):
989
+ branch_sign = np.where(branch_cut == 3, np.where(np.signbit(np.real(z)), 1, -1), -1)
990
+
991
+ out11_div_z = (-branch_sign /
992
+ np.sqrt(np.where(branch_cut == 3, z * z - 1, 1 - z * z)))
993
+
994
+ return out11_div_z
995
+
996
+ def assoc_legendre_p_0_0_jac(z, *, branch_cut=2, norm=False):
997
+ return np.zeros_like(z)
998
+
999
+ def assoc_legendre_p_1_0_jac(z, *, branch_cut=2, norm=False):
1000
+ fac = assoc_legendre_factor(1, 0, norm)
1001
+
1002
+ return np.full_like(z, fac)
1003
+
1004
+ def assoc_legendre_p_1_1_jac(z, *, branch_cut=2, norm=False):
1005
+ fac = assoc_legendre_factor(1, 1, norm)
1006
+
1007
+ return (fac * z *
1008
+ assoc_legendre_p_1_1_jac_div_z(z, branch_cut=branch_cut))
1009
+
1010
+ def assoc_legendre_p_1_m1_jac(z, *, branch_cut=2, norm=False):
1011
+ branch_cut_sign = np.where(branch_cut == 3, -1, 1)
1012
+ fac = assoc_legendre_factor(1, -1, norm)
1013
+
1014
+ return (-branch_cut_sign * fac * z *
1015
+ assoc_legendre_p_1_1_jac_div_z(z, branch_cut=branch_cut) / 2)
1016
+
1017
+ def assoc_legendre_p_2_0_jac(z, *, branch_cut=2, norm=False):
1018
+ fac = assoc_legendre_factor(2, 0, norm)
1019
+
1020
+ return 3 * fac * z
1021
+
1022
+ def assoc_legendre_p_2_1_jac(z, *, branch_cut=2, norm=False):
1023
+ fac = assoc_legendre_factor(2, 1, norm)
1024
+
1025
+ return (3 * fac * (2 * z * z - 1) *
1026
+ assoc_legendre_p_1_1_jac_div_z(z, branch_cut=branch_cut))
1027
+
1028
+ def assoc_legendre_p_2_2_jac(z, *, branch_cut=2, norm=False):
1029
+ branch_cut_sign = np.where(branch_cut == 3, -1, 1)
1030
+ fac = assoc_legendre_factor(2, 2, norm)
1031
+
1032
+ return -6 * branch_cut_sign * fac * z
1033
+
1034
+ def assoc_legendre_p_2_m1_jac(z, *, branch_cut=2, norm=False):
1035
+ branch_cut_sign = np.where(branch_cut == 3, -1, 1)
1036
+ fac = assoc_legendre_factor(2, -1, norm)
1037
+
1038
+ return (branch_cut_sign * fac * (1 - 2 * z * z) *
1039
+ assoc_legendre_p_1_1_jac_div_z(z, branch_cut=branch_cut) / 2)
1040
+
1041
+ def assoc_legendre_p_2_m2_jac(z, *, branch_cut=2, norm=False):
1042
+ branch_cut_sign = np.where(branch_cut == 3, -1, 1)
1043
+ fac = assoc_legendre_factor(2, -2, norm)
1044
+
1045
+ return -branch_cut_sign * fac * z / 4
1046
+
1047
+ def assoc_legendre_p_3_0_jac(z, *, branch_cut=2, norm=False):
1048
+ fac = assoc_legendre_factor(3, 0, norm)
1049
+
1050
+ return 3 * fac * (5 * z * z - 1) / 2
1051
+
1052
+ def assoc_legendre_p_3_1_jac(z, *, branch_cut=2, norm=False):
1053
+ fac = assoc_legendre_factor(3, 1, norm)
1054
+
1055
+ return (3 * fac * (15 * z * z - 11) * z *
1056
+ assoc_legendre_p_1_1_jac_div_z(z, branch_cut=branch_cut) / 2)
1057
+
1058
+ def assoc_legendre_p_3_2_jac(z, *, branch_cut=2, norm=False):
1059
+ branch_cut_sign = np.where(branch_cut == 3, -1, 1)
1060
+ fac = assoc_legendre_factor(3, 2, norm)
1061
+
1062
+ return 15 * branch_cut_sign * fac * (1 - 3 * z * z)
1063
+
1064
+ def assoc_legendre_p_3_3_jac(z, *, branch_cut=2, norm=False):
1065
+ branch_cut_sign = np.where(branch_cut == 3, -1, 1)
1066
+ fac = assoc_legendre_factor(3, 3, norm)
1067
+
1068
+ return (45 * branch_cut_sign * fac * (1 - z * z) * z *
1069
+ assoc_legendre_p_1_1_jac_div_z(z, branch_cut=branch_cut))
1070
+
1071
+ def assoc_legendre_p_3_m3_jac(z, *, branch_cut=2, norm=False):
1072
+ fac = assoc_legendre_factor(3, -3, norm)
1073
+
1074
+ return (fac * (z * z - 1) * z *
1075
+ assoc_legendre_p_1_1_jac_div_z(z, branch_cut=branch_cut) / 16)
1076
+
1077
+ def assoc_legendre_p_3_m2_jac(z, *, branch_cut=2, norm=False):
1078
+ branch_cut_sign = np.where(branch_cut == 3, -1, 1)
1079
+ fac = assoc_legendre_factor(3, -2, norm)
1080
+
1081
+ return branch_cut_sign * fac * (1 - 3 * z * z) / 8
1082
+
1083
+ def assoc_legendre_p_3_m1_jac(z, *, branch_cut=2, norm=False):
1084
+ branch_cut_sign = np.where(branch_cut == 3, -1, 1)
1085
+ fac = assoc_legendre_factor(3, -1, norm)
1086
+
1087
+ return (branch_cut_sign * fac * (11 - 15 * z * z) * z *
1088
+ assoc_legendre_p_1_1_jac_div_z(z, branch_cut=branch_cut) / 8)
1089
+
1090
+ def assoc_legendre_p_4_0_jac(z, *, branch_cut=2, norm=False):
1091
+ fac = assoc_legendre_factor(4, 0, norm)
1092
+
1093
+ return 5 * fac * (7 * z * z - 3) * z / 2
1094
+
1095
+ def assoc_legendre_p_4_1_jac(z, *, branch_cut=2, norm=False):
1096
+ fac = assoc_legendre_factor(4, 1, norm)
1097
+
1098
+ return (5 * fac * ((28 * z * z - 27) * z * z + 3) *
1099
+ assoc_legendre_p_1_1_jac_div_z(z, branch_cut=branch_cut) / 2)
1100
+
1101
+ def assoc_legendre_p_4_2_jac(z, *, branch_cut=2, norm=False):
1102
+ branch_cut_sign = np.where(branch_cut == 3, -1, 1)
1103
+ fac = assoc_legendre_factor(4, 2, norm)
1104
+
1105
+ return 30 * branch_cut_sign * fac * (4 - 7 * z * z) * z
1106
+
1107
+ def assoc_legendre_p_4_3_jac(z, *, branch_cut=2, norm=False):
1108
+ branch_cut_sign = np.where(branch_cut == 3, -1, 1)
1109
+ fac = assoc_legendre_factor(4, 3, norm)
1110
+
1111
+ return (105 * branch_cut_sign * fac * ((5 - 4 * z * z) * z * z - 1) *
1112
+ assoc_legendre_p_1_1_jac_div_z(z, branch_cut=branch_cut))
1113
+
1114
+ def assoc_legendre_p_4_4_jac(z, *, branch_cut=2, norm=False):
1115
+ fac = assoc_legendre_factor(4, 4, norm)
1116
+
1117
+ return 420 * fac * (z * z - 1) * z
1118
+
1119
+ def assoc_legendre_p_4_m4_jac(z, *, branch_cut=2, norm=False):
1120
+ fac = assoc_legendre_factor(4, -4, norm)
1121
+
1122
+ return fac * (z * z - 1) * z / 96
1123
+
1124
+ def assoc_legendre_p_4_m3_jac(z, *, branch_cut=2, norm=False):
1125
+ fac = assoc_legendre_factor(4, -3, norm)
1126
+
1127
+ return (fac * ((4 * z * z - 5) * z * z + 1) *
1128
+ assoc_legendre_p_1_1_jac_div_z(z, branch_cut=branch_cut) / 48)
1129
+
1130
+ def assoc_legendre_p_4_m2_jac(z, *, branch_cut=2, norm=False):
1131
+ branch_cut_sign = np.where(branch_cut == 3, -1, 1)
1132
+ fac = assoc_legendre_factor(4, -2, norm)
1133
+
1134
+ return branch_cut_sign * fac * (4 - 7 * z * z) * z / 12
1135
+
1136
+ def assoc_legendre_p_4_m1_jac(z, *, branch_cut=2, norm=False):
1137
+ branch_cut_sign = np.where(branch_cut == 3, -1, 1)
1138
+ fac = assoc_legendre_factor(4, -1, norm)
1139
+
1140
+ return (branch_cut_sign * fac * ((27 - 28 * z * z) * z * z - 3) *
1141
+ assoc_legendre_p_1_1_jac_div_z(z, branch_cut=branch_cut) / 8)
1142
+
1143
+ def sph_legendre_factor(n, m):
1144
+ return assoc_legendre_factor(n, m, norm=True) / np.sqrt(2 * np.pi)
1145
+
1146
+ def sph_legendre_p_0_0(theta):
1147
+ fac = sph_legendre_factor(0, 0)
1148
+
1149
+ return np.full_like(theta, fac)
1150
+
1151
+ def sph_legendre_p_1_0(theta):
1152
+ fac = sph_legendre_factor(1, 0)
1153
+
1154
+ return fac * np.cos(theta)
1155
+
1156
+ def sph_legendre_p_1_1(theta):
1157
+ fac = sph_legendre_factor(1, 1)
1158
+
1159
+ return -fac * np.abs(np.sin(theta))
1160
+
1161
+ def sph_legendre_p_1_m1(theta):
1162
+ fac = sph_legendre_factor(1, -1)
1163
+
1164
+ return fac * np.abs(np.sin(theta)) / 2
1165
+
1166
+ def sph_legendre_p_2_0(theta):
1167
+ fac = sph_legendre_factor(2, 0)
1168
+
1169
+ return fac * (3 * np.square(np.cos(theta)) - 1) / 2
1170
+
1171
+ def sph_legendre_p_2_1(theta):
1172
+ fac = sph_legendre_factor(2, 1)
1173
+
1174
+ return -3 * fac * np.abs(np.sin(theta)) * np.cos(theta)
1175
+
1176
+ def sph_legendre_p_2_2(theta):
1177
+ fac = sph_legendre_factor(2, 2)
1178
+
1179
+ return 3 * fac * (1 - np.square(np.cos(theta)))
1180
+
1181
+ def sph_legendre_p_2_m2(theta):
1182
+ fac = sph_legendre_factor(2, -2)
1183
+
1184
+ return fac * (1 - np.square(np.cos(theta))) / 8
1185
+
1186
+ def sph_legendre_p_2_m1(theta):
1187
+ fac = sph_legendre_factor(2, -1)
1188
+
1189
+ return fac * np.cos(theta) * np.abs(np.sin(theta)) / 2
1190
+
1191
+ def sph_legendre_p_3_0(theta):
1192
+ fac = sph_legendre_factor(3, 0)
1193
+
1194
+ return (fac * (5 * np.square(np.cos(theta)) - 3) *
1195
+ np.cos(theta) / 2)
1196
+
1197
+ def sph_legendre_p_3_1(theta):
1198
+ fac = sph_legendre_factor(3, 1)
1199
+
1200
+ return (-3 * fac * (5 * np.square(np.cos(theta)) - 1) *
1201
+ np.abs(np.sin(theta)) / 2)
1202
+
1203
+ def sph_legendre_p_3_2(theta):
1204
+ fac = sph_legendre_factor(3, 2)
1205
+
1206
+ return (-15 * fac * (np.square(np.cos(theta)) - 1) *
1207
+ np.cos(theta))
1208
+
1209
+ def sph_legendre_p_3_3(theta):
1210
+ fac = sph_legendre_factor(3, 3)
1211
+
1212
+ return -15 * fac * np.power(np.abs(np.sin(theta)), 3)
1213
+
1214
+ def sph_legendre_p_3_m3(theta):
1215
+ fac = sph_legendre_factor(3, -3)
1216
+
1217
+ return fac * np.power(np.abs(np.sin(theta)), 3) / 48
1218
+
1219
+ def sph_legendre_p_3_m2(theta):
1220
+ fac = sph_legendre_factor(3, -2)
1221
+
1222
+ return (-fac * (np.square(np.cos(theta)) - 1) *
1223
+ np.cos(theta) / 8)
1224
+
1225
+ def sph_legendre_p_3_m1(theta):
1226
+ fac = sph_legendre_factor(3, -1)
1227
+
1228
+ return (fac * (5 * np.square(np.cos(theta)) - 1) *
1229
+ np.abs(np.sin(theta)) / 8)
1230
+
1231
+ def sph_legendre_p_4_0(theta):
1232
+ fac = sph_legendre_factor(4, 0)
1233
+
1234
+ return (fac * (35 * np.square(np.square(np.cos(theta))) -
1235
+ 30 * np.square(np.cos(theta)) + 3) / 8)
1236
+
1237
+ def sph_legendre_p_4_1(theta):
1238
+ fac = sph_legendre_factor(4, 1)
1239
+
1240
+ return (-5 * fac * (7 * np.square(np.cos(theta)) - 3) *
1241
+ np.cos(theta) * np.abs(np.sin(theta)) / 2)
1242
+
1243
+ def sph_legendre_p_4_2(theta):
1244
+ fac = sph_legendre_factor(4, 2)
1245
+
1246
+ return (-15 * fac * (7 * np.square(np.cos(theta)) - 1) *
1247
+ (np.square(np.cos(theta)) - 1) / 2)
1248
+
1249
+ def sph_legendre_p_4_3(theta):
1250
+ fac = sph_legendre_factor(4, 3)
1251
+
1252
+ return -105 * fac * np.power(np.abs(np.sin(theta)), 3) * np.cos(theta)
1253
+
1254
+ def sph_legendre_p_4_4(theta):
1255
+ fac = sph_legendre_factor(4, 4)
1256
+
1257
+ return 105 * fac * np.square(np.square(np.cos(theta)) - 1)
1258
+
1259
+ def sph_legendre_p_4_m4(theta):
1260
+ fac = sph_legendre_factor(4, -4)
1261
+
1262
+ return fac * np.square(np.square(np.cos(theta)) - 1) / 384
1263
+
1264
+ def sph_legendre_p_4_m3(theta):
1265
+ fac = sph_legendre_factor(4, -3)
1266
+
1267
+ return (fac * np.power(np.abs(np.sin(theta)), 3) *
1268
+ np.cos(theta) / 48)
1269
+
1270
+ def sph_legendre_p_4_m2(theta):
1271
+ fac = sph_legendre_factor(4, -2)
1272
+
1273
+ return (-fac * (7 * np.square(np.cos(theta)) - 1) *
1274
+ (np.square(np.cos(theta)) - 1) / 48)
1275
+
1276
+ def sph_legendre_p_4_m1(theta):
1277
+ fac = sph_legendre_factor(4, -1)
1278
+
1279
+ return (fac * (7 * np.square(np.cos(theta)) - 3) *
1280
+ np.cos(theta) * np.abs(np.sin(theta)) / 8)
1281
+
1282
+ def sph_legendre_p_0_0_jac(theta):
1283
+ return np.zeros_like(theta)
1284
+
1285
+ def sph_legendre_p_1_0_jac(theta):
1286
+ fac = sph_legendre_factor(1, 0)
1287
+
1288
+ return -fac * np.sin(theta)
1289
+
1290
+ def sph_legendre_p_1_1_jac(theta):
1291
+ fac = sph_legendre_factor(1, 1)
1292
+
1293
+ return -fac * np.cos(theta) * (2 * np.heaviside(np.sin(theta), 1) - 1)
1294
+
1295
+ def sph_legendre_p_1_m1_jac(theta):
1296
+ fac = sph_legendre_factor(1, -1)
1297
+
1298
+ return fac * np.cos(theta) * (2 * np.heaviside(np.sin(theta), 1) - 1) / 2
1299
+
1300
+ def sph_legendre_p_2_0_jac(theta):
1301
+ fac = sph_legendre_factor(2, 0)
1302
+
1303
+ return -3 * fac * np.cos(theta) * np.sin(theta)
1304
+
1305
+ def sph_legendre_p_2_1_jac(theta):
1306
+ fac = sph_legendre_factor(2, 1)
1307
+
1308
+ return (3 * fac * (-np.square(np.cos(theta)) *
1309
+ (2 * np.heaviside(np.sin(theta), 1) - 1) +
1310
+ np.abs(np.sin(theta)) * np.sin(theta)))
1311
+
1312
+ def sph_legendre_p_2_2_jac(theta):
1313
+ fac = sph_legendre_factor(2, 2)
1314
+
1315
+ return 6 * fac * np.sin(theta) * np.cos(theta)
1316
+
1317
+ def sph_legendre_p_2_m2_jac(theta):
1318
+ fac = sph_legendre_factor(2, -2)
1319
+
1320
+ return fac * np.sin(theta) * np.cos(theta) / 4
1321
+
1322
+ def sph_legendre_p_2_m1_jac(theta):
1323
+ fac = sph_legendre_factor(2, -1)
1324
+
1325
+ return (-fac * (-np.square(np.cos(theta)) *
1326
+ (2 * np.heaviside(np.sin(theta), 1) - 1) +
1327
+ np.abs(np.sin(theta)) * np.sin(theta)) / 2)
1328
+
1329
+ def sph_legendre_p_3_0_jac(theta):
1330
+ fac = sph_legendre_factor(3, 0)
1331
+
1332
+ return 3 * fac * (1 - 5 * np.square(np.cos(theta))) * np.sin(theta) / 2
1333
+
1334
+ def sph_legendre_p_3_1_jac(theta):
1335
+ fac = sph_legendre_factor(3, 1)
1336
+
1337
+ return (3 * fac * (11 - 15 * np.square(np.cos(theta))) * np.cos(theta) *
1338
+ (2 * np.heaviside(np.sin(theta), 1) - 1) / 2)
1339
+
1340
+ def sph_legendre_p_3_2_jac(theta):
1341
+ fac = sph_legendre_factor(3, 2)
1342
+
1343
+ return 15 * fac * (3 * np.square(np.cos(theta)) - 1) * np.sin(theta)
1344
+
1345
+ def sph_legendre_p_3_3_jac(theta):
1346
+ fac = sph_legendre_factor(3, 3)
1347
+
1348
+ return -45 * fac * np.abs(np.sin(theta)) * np.sin(theta) * np.cos(theta)
1349
+
1350
+ def sph_legendre_p_3_m3_jac(theta):
1351
+ fac = sph_legendre_factor(3, -3)
1352
+
1353
+ return fac * np.abs(np.sin(theta)) * np.sin(theta) * np.cos(theta) / 16
1354
+
1355
+ def sph_legendre_p_3_m2_jac(theta):
1356
+ fac = sph_legendre_factor(3, -2)
1357
+
1358
+ return fac * (3 * np.square(np.cos(theta)) - 1) * np.sin(theta) / 8
1359
+
1360
+ def sph_legendre_p_3_m1_jac(theta):
1361
+ fac = sph_legendre_factor(3, -1)
1362
+
1363
+ return (-fac * (11 - 15 * np.square(np.cos(theta))) *
1364
+ np.cos(theta) *
1365
+ (2 * np.heaviside(np.sin(theta), 1) - 1) / 8)
1366
+
1367
+ def sph_legendre_p_4_0_jac(theta):
1368
+ fac = sph_legendre_factor(4, 0)
1369
+
1370
+ return (-5 * fac * (7 * np.square(np.cos(theta)) - 3) *
1371
+ np.sin(theta) * np.cos(theta) / 2)
1372
+
1373
+ def sph_legendre_p_4_1_jac(theta):
1374
+ fac = sph_legendre_factor(4, 1)
1375
+
1376
+ return (5 * fac * (-3 + 27 * np.square(np.cos(theta)) -
1377
+ 28 * np.square(np.square(np.cos(theta)))) *
1378
+ (2 * np.heaviside(np.sin(theta), 1) - 1) / 2)
1379
+
1380
+ def sph_legendre_p_4_2_jac(theta):
1381
+ fac = sph_legendre_factor(4, 2)
1382
+
1383
+ return (30 * fac * (7 * np.square(np.cos(theta)) - 4) *
1384
+ np.sin(theta) * np.cos(theta))
1385
+
1386
+ def sph_legendre_p_4_3_jac(theta):
1387
+ fac = sph_legendre_factor(4, 3)
1388
+
1389
+ return (-105 * fac * (4 * np.square(np.cos(theta)) - 1) *
1390
+ np.abs(np.sin(theta)) * np.sin(theta))
1391
+
1392
+ def sph_legendre_p_4_4_jac(theta):
1393
+ fac = sph_legendre_factor(4, 4)
1394
+
1395
+ return (-420 * fac * (np.square(np.cos(theta)) - 1) *
1396
+ np.sin(theta) * np.cos(theta))
1397
+
1398
+ def sph_legendre_p_4_m4_jac(theta):
1399
+ fac = sph_legendre_factor(4, -4)
1400
+
1401
+ return (-fac * (np.square(np.cos(theta)) - 1) *
1402
+ np.sin(theta) * np.cos(theta) / 96)
1403
+
1404
+ def sph_legendre_p_4_m3_jac(theta):
1405
+ fac = sph_legendre_factor(4, -3)
1406
+
1407
+ return (fac * (4 * np.square(np.cos(theta)) - 1) *
1408
+ np.abs(np.sin(theta)) * np.sin(theta) / 48)
1409
+
1410
+ def sph_legendre_p_4_m2_jac(theta):
1411
+ fac = sph_legendre_factor(4, -2)
1412
+
1413
+ return (fac * (7 * np.square(np.cos(theta)) - 4) * np.sin(theta) *
1414
+ np.cos(theta) / 12)
1415
+
1416
+ def sph_legendre_p_4_m1_jac(theta):
1417
+ fac = sph_legendre_factor(4, -1)
1418
+
1419
+ return (-fac * (-3 + 27 * np.square(np.cos(theta)) -
1420
+ 28 * np.square(np.square(np.cos(theta)))) *
1421
+ (2 * np.heaviside(np.sin(theta), 1) - 1) / 8)
.venv/lib/python3.12/site-packages/scipy/special/tests/test_log1mexp.py ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import pytest
3
+
4
+ from numpy.testing import assert_allclose, assert_equal
5
+
6
+ from scipy.special._ufuncs import _log1mexp
7
+
8
+ # # Test cases generated with the script
9
+ #
10
+ # import numpy as np
11
+
12
+ # from mpmath import mp
13
+
14
+
15
+ # def mp_log1mexp(x):
16
+ # with mp.workdps(324):
17
+ # return float(mp.log(mp.one - mp.exp(x)))
18
+
19
+ # X = np.concat([-np.logspace(-1, -300, 20), np.linspace(-745, -1, 20)])
20
+
21
+ # cases = [(float(x), mp_log1mexp(x)) for x in X]
22
+
23
+ @pytest.mark.parametrize(
24
+ "x,expected",
25
+ [
26
+ (-0.1, -2.3521684610440907),
27
+ (-1.8329807108324374e-17, -38.538003135374026),
28
+ (-3.359818286283788e-33, -74.773421177754),
29
+ (-6.1584821106602796e-49, -111.00883922013399),
30
+ (-1.1288378916846929e-64, -147.24425726251397),
31
+ (-2.0691380811148324e-80, -183.47967530489393),
32
+ (-3.792690190732269e-96, -219.71509334727392),
33
+ (-6.951927961775534e-112, -255.95051138965394),
34
+ (-1.2742749857031425e-127, -292.1859294320339),
35
+ (-2.3357214690901785e-143, -328.42134747441384),
36
+ (-4.281332398719571e-159, -364.6567655167938),
37
+ (-7.847599703514559e-175, -400.8921835591739),
38
+ (-1.4384498882876776e-190, -437.1276016015538),
39
+ (-2.6366508987304307e-206, -473.3630196439338),
40
+ (-4.832930238571653e-222, -509.59843768631384),
41
+ (-8.858667904100796e-238, -545.8338557286938),
42
+ (-1.623776739188744e-253, -582.0692737710738),
43
+ (-2.9763514416312156e-269, -618.3046918134538),
44
+ (-5.455594781168782e-285, -654.5401098558336),
45
+ (-1e-300, -690.7755278982137),
46
+ (-745.0, -5e-324),
47
+ (-705.8421052631579, -2.8619931451743316e-307),
48
+ (-666.6842105263158, -2.9021923726875757e-290),
49
+ (-627.5263157894738, -2.9429562339405562e-273),
50
+ (-588.3684210526316, -2.9842926597143714e-256),
51
+ (-549.2105263157895, -3.0262096921839423e-239),
52
+ (-510.0526315789474, -3.0687154864846747e-222),
53
+ (-470.89473684210526, -3.1118183122979086e-205),
54
+ (-431.7368421052632, -3.155526555459449e-188),
55
+ (-392.5789473684211, -3.1998487195921207e-171),
56
+ (-353.42105263157896, -3.2447934277596653e-154),
57
+ (-314.2631578947369, -3.2903694241438367e-137),
58
+ (-275.1052631578948, -3.3365855757467166e-120),
59
+ (-235.94736842105266, -3.3834508741152875e-103),
60
+ (-196.78947368421052, -3.4309744370903894e-86),
61
+ (-157.63157894736844, -3.4791655105810003e-69),
62
+ (-118.47368421052636, -3.528033470363468e-52),
63
+ (-79.31578947368428, -3.577587823905024e-35),
64
+ (-40.157894736842195, -3.627838212213697e-18),
65
+ (-1.0, -0.4586751453870819),
66
+ ]
67
+ )
68
+ def test_log1mexp(x, expected):
69
+ observed = _log1mexp(x)
70
+ assert_allclose(observed, expected, rtol=1e-15, atol=1e-300)
71
+
72
+
73
+ @pytest.mark.parametrize("x", [1.1, 1e10, np.inf])
74
+ def test_log1mexp_out_of_domain(x):
75
+ observed = _log1mexp(x)
76
+ assert np.isnan(observed)
77
+
78
+
79
+ @pytest.mark.parametrize(
80
+ "x,expected",
81
+ [(-np.inf, -0.0), (0.0, -np.inf), (-0.0, -np.inf), (np.nan, np.nan)]
82
+ )
83
+ def test_log1mexp_extreme(x, expected):
84
+ observed = _log1mexp(x)
85
+ assert_equal(expected, observed)
.venv/lib/python3.12/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)
.venv/lib/python3.12/site-packages/scipy/special/tests/test_logit.py ADDED
@@ -0,0 +1,161 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ from numpy.testing import assert_equal, assert_allclose
3
+ from scipy.special import logit, expit, log_expit
4
+
5
+
6
+ class TestLogit:
7
+
8
+ def check_logit_out(self, a, expected):
9
+ actual = logit(a)
10
+ assert_equal(actual.dtype, a.dtype)
11
+ rtol = 16*np.finfo(a.dtype).eps
12
+ assert_allclose(actual, expected, rtol=rtol)
13
+
14
+ def test_float32(self):
15
+ a = np.concatenate((np.linspace(0, 1, 10, dtype=np.float32),
16
+ [np.float32(0.0001), np.float32(0.49999),
17
+ np.float32(0.50001)]))
18
+ # Expected values computed with mpmath from float32 inputs, e.g.
19
+ # from mpmath import mp
20
+ # mp.dps = 200
21
+ # a = np.float32(1/9)
22
+ # print(np.float32(mp.log(a) - mp.log1p(-a)))
23
+ # prints `-2.0794415`.
24
+ expected = np.array([-np.inf, -2.0794415, -1.2527629, -6.9314712e-01,
25
+ -2.2314353e-01, 2.2314365e-01, 6.9314724e-01,
26
+ 1.2527630, 2.0794415, np.inf,
27
+ -9.2102404, -4.0054321e-05, 4.0054321e-05],
28
+ dtype=np.float32)
29
+ self.check_logit_out(a, expected)
30
+
31
+ def test_float64(self):
32
+ a = np.concatenate((np.linspace(0, 1, 10, dtype=np.float64),
33
+ [1e-8, 0.4999999999999, 0.50000000001]))
34
+ # Expected values computed with mpmath.
35
+ expected = np.array([-np.inf,
36
+ -2.079441541679836,
37
+ -1.252762968495368,
38
+ -0.6931471805599454,
39
+ -0.22314355131420985,
40
+ 0.22314355131420985,
41
+ 0.6931471805599452,
42
+ 1.2527629684953674,
43
+ 2.0794415416798353,
44
+ np.inf,
45
+ -18.420680733952366,
46
+ -3.999023334699814e-13,
47
+ 4.000000330961484e-11])
48
+ self.check_logit_out(a, expected)
49
+
50
+ def test_nan(self):
51
+ expected = np.array([np.nan]*4)
52
+ with np.errstate(invalid='ignore'):
53
+ actual = logit(np.array([-3., -2., 2., 3.]))
54
+
55
+ assert_equal(expected, actual)
56
+
57
+
58
+ class TestExpit:
59
+ def check_expit_out(self, dtype, expected):
60
+ a = np.linspace(-4, 4, 10)
61
+ a = np.array(a, dtype=dtype)
62
+ actual = expit(a)
63
+ assert_allclose(actual, expected, atol=1.5e-7, rtol=0)
64
+ assert_equal(actual.dtype, np.dtype(dtype))
65
+
66
+ def test_float32(self):
67
+ expected = np.array([0.01798621, 0.04265125,
68
+ 0.09777259, 0.20860852,
69
+ 0.39068246, 0.60931754,
70
+ 0.79139149, 0.9022274,
71
+ 0.95734876, 0.98201376], dtype=np.float32)
72
+ self.check_expit_out('f4', expected)
73
+
74
+ def test_float64(self):
75
+ expected = np.array([0.01798621, 0.04265125,
76
+ 0.0977726, 0.20860853,
77
+ 0.39068246, 0.60931754,
78
+ 0.79139147, 0.9022274,
79
+ 0.95734875, 0.98201379])
80
+ self.check_expit_out('f8', expected)
81
+
82
+ def test_large(self):
83
+ for dtype in (np.float32, np.float64, np.longdouble):
84
+ for n in (88, 89, 709, 710, 11356, 11357):
85
+ n = np.array(n, dtype=dtype)
86
+ assert_allclose(expit(n), 1.0, atol=1e-20)
87
+ assert_allclose(expit(-n), 0.0, atol=1e-20)
88
+ assert_equal(expit(n).dtype, dtype)
89
+ assert_equal(expit(-n).dtype, dtype)
90
+
91
+
92
+ class TestLogExpit:
93
+
94
+ def test_large_negative(self):
95
+ x = np.array([-10000.0, -750.0, -500.0, -35.0])
96
+ y = log_expit(x)
97
+ assert_equal(y, x)
98
+
99
+ def test_large_positive(self):
100
+ x = np.array([750.0, 1000.0, 10000.0])
101
+ y = log_expit(x)
102
+ # y will contain -0.0, and -0.0 is used in the expected value,
103
+ # but assert_equal does not check the sign of zeros, and I don't
104
+ # think the sign is an essential part of the test (i.e. it would
105
+ # probably be OK if log_expit(1000) returned 0.0 instead of -0.0).
106
+ assert_equal(y, np.array([-0.0, -0.0, -0.0]))
107
+
108
+ def test_basic_float64(self):
109
+ x = np.array([-32, -20, -10, -3, -1, -0.1, -1e-9,
110
+ 0, 1e-9, 0.1, 1, 10, 100, 500, 710, 725, 735])
111
+ y = log_expit(x)
112
+ #
113
+ # Expected values were computed with mpmath:
114
+ #
115
+ # import mpmath
116
+ #
117
+ # mpmath.mp.dps = 100
118
+ #
119
+ # def mp_log_expit(x):
120
+ # return -mpmath.log1p(mpmath.exp(-x))
121
+ #
122
+ # expected = [float(mp_log_expit(t)) for t in x]
123
+ #
124
+ expected = [-32.000000000000014, -20.000000002061153,
125
+ -10.000045398899218, -3.048587351573742,
126
+ -1.3132616875182228, -0.7443966600735709,
127
+ -0.6931471810599453, -0.6931471805599453,
128
+ -0.6931471800599454, -0.6443966600735709,
129
+ -0.3132616875182228, -4.539889921686465e-05,
130
+ -3.720075976020836e-44, -7.124576406741286e-218,
131
+ -4.47628622567513e-309, -1.36930634e-315,
132
+ -6.217e-320]
133
+
134
+ # When tested locally, only one value in y was not exactly equal to
135
+ # expected. That was for x=1, and the y value differed from the
136
+ # expected by 1 ULP. For this test, however, I'll use rtol=1e-15.
137
+ assert_allclose(y, expected, rtol=1e-15)
138
+
139
+ def test_basic_float32(self):
140
+ x = np.array([-32, -20, -10, -3, -1, -0.1, -1e-9,
141
+ 0, 1e-9, 0.1, 1, 10, 100], dtype=np.float32)
142
+ y = log_expit(x)
143
+ #
144
+ # Expected values were computed with mpmath:
145
+ #
146
+ # import mpmath
147
+ #
148
+ # mpmath.mp.dps = 100
149
+ #
150
+ # def mp_log_expit(x):
151
+ # return -mpmath.log1p(mpmath.exp(-x))
152
+ #
153
+ # expected = [np.float32(mp_log_expit(t)) for t in x]
154
+ #
155
+ expected = np.array([-32.0, -20.0, -10.000046, -3.0485873,
156
+ -1.3132616, -0.7443967, -0.6931472,
157
+ -0.6931472, -0.6931472, -0.64439666,
158
+ -0.3132617, -4.5398898e-05, -3.8e-44],
159
+ dtype=np.float32)
160
+
161
+ assert_allclose(y, expected, rtol=5e-7)
.venv/lib/python3.12/site-packages/scipy/special/tests/test_logsumexp.py ADDED
@@ -0,0 +1,481 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import itertools as it
2
+ import math
3
+ import pytest
4
+
5
+ import numpy as np
6
+
7
+ from scipy._lib._array_api import (is_array_api_strict, make_xp_test_case,
8
+ xp_default_dtype, xp_device)
9
+ from scipy._lib._array_api_no_0d import (xp_assert_equal, xp_assert_close,
10
+ xp_assert_less)
11
+
12
+ from scipy.special import log_softmax, logsumexp, softmax
13
+ from scipy.special._logsumexp import _wrap_radians
14
+
15
+
16
+ dtypes = ['float32', 'float64', 'int32', 'int64', 'complex64', 'complex128']
17
+ integral_dtypes = ['int32', 'int64']
18
+
19
+
20
+ @pytest.mark.uses_xp_capabilities(False, reason="private")
21
+ def test_wrap_radians(xp):
22
+ x = xp.asarray([-math.pi-1, -math.pi, -1, -1e-300,
23
+ 0, 1e-300, 1, math.pi, math.pi+1])
24
+ ref = xp.asarray([math.pi-1, math.pi, -1, -1e-300,
25
+ 0, 1e-300, 1, math.pi, -math.pi+1])
26
+ res = _wrap_radians(x, xp=xp)
27
+ xp_assert_close(res, ref, atol=0)
28
+
29
+
30
+ # numpy warning filters don't work for dask (dask/dask#3245)
31
+ # (also we should not expect the numpy warning filter to work for any Array API
32
+ # library)
33
+ @pytest.mark.filterwarnings("ignore:invalid value encountered:RuntimeWarning")
34
+ @pytest.mark.filterwarnings("ignore:divide by zero encountered:RuntimeWarning")
35
+ @pytest.mark.filterwarnings("ignore:overflow encountered:RuntimeWarning")
36
+ @make_xp_test_case(logsumexp)
37
+ class TestLogSumExp:
38
+ def test_logsumexp(self, xp):
39
+ # Test with zero-size array
40
+ a = xp.asarray([])
41
+ desired = xp.asarray(-xp.inf)
42
+ xp_assert_equal(logsumexp(a), desired)
43
+
44
+ # Test whether logsumexp() function correctly handles large inputs.
45
+ a = xp.arange(200., dtype=xp.float64)
46
+ desired = xp.log(xp.sum(xp.exp(a)))
47
+ xp_assert_close(logsumexp(a), desired)
48
+
49
+ # Now test with large numbers
50
+ b = xp.asarray([1000., 1000.])
51
+ desired = xp.asarray(1000.0 + math.log(2.0))
52
+ xp_assert_close(logsumexp(b), desired)
53
+
54
+ n = 1000
55
+ b = xp.full((n,), 10000)
56
+ desired = xp.asarray(10000.0 + math.log(n))
57
+ xp_assert_close(logsumexp(b), desired)
58
+
59
+ x = xp.asarray([1e-40] * 1000000)
60
+ logx = xp.log(x)
61
+ X = xp.stack([x, x])
62
+ logX = xp.stack([logx, logx])
63
+ xp_assert_close(xp.exp(logsumexp(logX)), xp.sum(X))
64
+ xp_assert_close(xp.exp(logsumexp(logX, axis=0)), xp.sum(X, axis=0))
65
+ xp_assert_close(xp.exp(logsumexp(logX, axis=1)), xp.sum(X, axis=1))
66
+
67
+ # Handling special values properly
68
+ inf = xp.asarray([xp.inf])
69
+ nan = xp.asarray([xp.nan])
70
+ xp_assert_equal(logsumexp(inf), inf[0])
71
+ xp_assert_equal(logsumexp(-inf), -inf[0])
72
+ xp_assert_equal(logsumexp(nan), nan[0])
73
+ xp_assert_equal(logsumexp(xp.asarray([-xp.inf, -xp.inf])), -inf[0])
74
+
75
+ # Handling an array with different magnitudes on the axes
76
+ a = xp.asarray([[1e10, 1e-10],
77
+ [-1e10, -np.inf]])
78
+ ref = xp.asarray([1e10, -1e10])
79
+ xp_assert_close(logsumexp(a, axis=-1), ref)
80
+
81
+ # Test keeping dimensions
82
+ ref = xp.expand_dims(ref, axis=-1)
83
+ xp_assert_close(logsumexp(a, axis=-1, keepdims=True), ref)
84
+
85
+ # Test multiple axes
86
+ xp_assert_close(logsumexp(a, axis=(-1, -2)), xp.asarray(1e10))
87
+
88
+ def test_logsumexp_b(self, xp):
89
+ a = xp.arange(200., dtype=xp.float64)
90
+ b = xp.arange(200., 0., -1.)
91
+ desired = xp.log(xp.sum(b*xp.exp(a)))
92
+ xp_assert_close(logsumexp(a, b=b), desired)
93
+
94
+ a = xp.asarray([1000, 1000])
95
+ b = xp.asarray([1.2, 1.2])
96
+ desired = xp.asarray(1000 + math.log(2 * 1.2))
97
+ xp_assert_close(logsumexp(a, b=b), desired)
98
+
99
+ x = xp.asarray([1e-40] * 100000)
100
+ b = xp.linspace(1, 1000, 100000)
101
+ logx = xp.log(x)
102
+ X = xp.stack((x, x))
103
+ logX = xp.stack((logx, logx))
104
+ B = xp.stack((b, b))
105
+ xp_assert_close(xp.exp(logsumexp(logX, b=B)), xp.sum(B * X))
106
+ xp_assert_close(xp.exp(logsumexp(logX, b=B, axis=0)), xp.sum(B * X, axis=0))
107
+ xp_assert_close(xp.exp(logsumexp(logX, b=B, axis=1)), xp.sum(B * X, axis=1))
108
+
109
+ def test_logsumexp_sign(self, xp):
110
+ a = xp.asarray([1, 1, 1])
111
+ b = xp.asarray([1, -1, -1])
112
+
113
+ r, s = logsumexp(a, b=b, return_sign=True)
114
+ xp_assert_close(r, xp.asarray(1.))
115
+ xp_assert_equal(s, xp.asarray(-1.))
116
+
117
+ def test_logsumexp_sign_zero(self, xp):
118
+ a = xp.asarray([1, 1])
119
+ b = xp.asarray([1, -1])
120
+
121
+ r, s = logsumexp(a, b=b, return_sign=True)
122
+ assert not xp.isfinite(r)
123
+ assert not xp.isnan(r)
124
+ assert r < 0
125
+ assert s == 0
126
+
127
+ def test_logsumexp_sign_shape(self, xp):
128
+ a = xp.ones((1, 2, 3, 4))
129
+ b = xp.ones_like(a)
130
+
131
+ r, s = logsumexp(a, axis=2, b=b, return_sign=True)
132
+ assert r.shape == s.shape == (1, 2, 4)
133
+
134
+ r, s = logsumexp(a, axis=(1, 3), b=b, return_sign=True)
135
+ assert r.shape == s.shape == (1,3)
136
+
137
+ def test_logsumexp_complex_sign(self, xp):
138
+ a = xp.asarray([1 + 1j, 2 - 1j, -2 + 3j])
139
+
140
+ r, s = logsumexp(a, return_sign=True)
141
+
142
+ expected_sumexp = xp.sum(xp.exp(a))
143
+ # This is the numpy>=2.0 convention for np.sign
144
+ expected_sign = expected_sumexp / xp.abs(expected_sumexp)
145
+
146
+ xp_assert_close(s, expected_sign)
147
+ xp_assert_close(s * xp.exp(r), expected_sumexp)
148
+
149
+ def test_logsumexp_shape(self, xp):
150
+ a = xp.ones((1, 2, 3, 4))
151
+ b = xp.ones_like(a)
152
+
153
+ r = logsumexp(a, axis=2, b=b)
154
+ assert r.shape == (1, 2, 4)
155
+
156
+ r = logsumexp(a, axis=(1, 3), b=b)
157
+ assert r.shape == (1, 3)
158
+
159
+ def test_logsumexp_b_zero(self, xp):
160
+ a = xp.asarray([1, 10000])
161
+ b = xp.asarray([1, 0])
162
+
163
+ xp_assert_close(logsumexp(a, b=b), xp.asarray(1.))
164
+
165
+ def test_logsumexp_b_shape(self, xp):
166
+ a = xp.zeros((4, 1, 2, 1))
167
+ b = xp.ones((3, 1, 5))
168
+
169
+ logsumexp(a, b=b)
170
+
171
+ @pytest.mark.parametrize('arg', (1, [1, 2, 3]))
172
+ def test_xp_invalid_input(self, arg):
173
+ assert logsumexp(arg) == logsumexp(np.asarray(np.atleast_1d(arg)))
174
+
175
+ def test_array_like(self):
176
+ a = [1000, 1000]
177
+ desired = np.asarray(1000.0 + math.log(2.0))
178
+ xp_assert_close(logsumexp(a), desired)
179
+
180
+ @pytest.mark.parametrize('dtype', dtypes)
181
+ def test_dtypes_a(self, dtype, xp):
182
+ dtype = getattr(xp, dtype)
183
+ a = xp.asarray([1000., 1000.], dtype=dtype)
184
+ desired_dtype = (xp.asarray(1.).dtype if xp.isdtype(dtype, 'integral')
185
+ else dtype) # true for all libraries tested
186
+ desired = xp.asarray(1000.0 + math.log(2.0), dtype=desired_dtype)
187
+ xp_assert_close(logsumexp(a), desired)
188
+
189
+ @pytest.mark.parametrize('dtype_a', dtypes)
190
+ @pytest.mark.parametrize('dtype_b', dtypes)
191
+ def test_dtypes_ab(self, dtype_a, dtype_b, xp):
192
+ xp_dtype_a = getattr(xp, dtype_a)
193
+ xp_dtype_b = getattr(xp, dtype_b)
194
+ a = xp.asarray([2, 1], dtype=xp_dtype_a)
195
+ b = xp.asarray([1, -1], dtype=xp_dtype_b)
196
+ if is_array_api_strict(xp):
197
+ # special-case for `TypeError: array_api_strict.float32 and
198
+ # and array_api_strict.int64 cannot be type promoted together`
199
+ xp_float_dtypes = [dtype for dtype in [xp_dtype_a, xp_dtype_b]
200
+ if not xp.isdtype(dtype, 'integral')]
201
+ if len(xp_float_dtypes) < 2: # at least one is integral
202
+ xp_float_dtypes.append(xp.asarray(1.).dtype)
203
+ desired_dtype = xp.result_type(*xp_float_dtypes)
204
+ else:
205
+ desired_dtype = xp.result_type(xp_dtype_a, xp_dtype_b)
206
+ if xp.isdtype(desired_dtype, 'integral'):
207
+ desired_dtype = xp_default_dtype(xp)
208
+ desired = xp.asarray(math.log(math.exp(2) - math.exp(1)), dtype=desired_dtype)
209
+ xp_assert_close(logsumexp(a, b=b), desired)
210
+
211
+ def test_gh18295(self, xp):
212
+ # gh-18295 noted loss of precision when real part of one element is much
213
+ # larger than the rest. Check that this is resolved.
214
+ a = xp.asarray([0.0, -40.0])
215
+ res = logsumexp(a)
216
+ ref = xp.logaddexp(a[0], a[1])
217
+ xp_assert_close(res, ref)
218
+
219
+ @pytest.mark.parametrize('dtype', ['complex64', 'complex128'])
220
+ def test_gh21610(self, xp, dtype):
221
+ # gh-21610 noted that `logsumexp` could return imaginary components
222
+ # outside the range (-pi, pi]. Check that this is resolved.
223
+ # While working on this, I noticed that all other tests passed even
224
+ # when the imaginary component of the result was zero. This suggested
225
+ # the need of a stronger test with imaginary dtype.
226
+ rng = np.random.default_rng(324984329582349862)
227
+ dtype = getattr(xp, dtype)
228
+ shape = (10, 100)
229
+ x = rng.uniform(1, 40, shape) + 1.j * rng.uniform(1, 40, shape)
230
+ x = xp.asarray(x, dtype=dtype)
231
+
232
+ res = logsumexp(x, axis=1)
233
+ ref = xp.log(xp.sum(xp.exp(x), axis=1))
234
+ max = xp.full_like(xp.imag(res), xp.pi)
235
+ xp_assert_less(xp.abs(xp.imag(res)), max)
236
+ xp_assert_close(res, ref)
237
+
238
+ out, sgn = logsumexp(x, return_sign=True, axis=1)
239
+ ref = xp.sum(xp.exp(x), axis=1)
240
+ xp_assert_less(xp.abs(xp.imag(sgn)), max)
241
+ xp_assert_close(out, xp.real(xp.log(ref)))
242
+ xp_assert_close(sgn, ref/xp.abs(ref))
243
+
244
+ def test_gh21709_small_imaginary(self, xp):
245
+ # Test that `logsumexp` does not lose relative precision of
246
+ # small imaginary components
247
+ x = xp.asarray([0, 0.+2.2204460492503132e-17j])
248
+ res = logsumexp(x)
249
+ # from mpmath import mp
250
+ # mp.dps = 100
251
+ # x, y = mp.mpc(0), mp.mpc('0', '2.2204460492503132e-17')
252
+ # ref = complex(mp.log(mp.exp(x) + mp.exp(y)))
253
+ ref = xp.asarray(0.6931471805599453+1.1102230246251566e-17j)
254
+ xp_assert_close(xp.real(res), xp.real(ref))
255
+ xp_assert_close(xp.imag(res), xp.imag(ref), atol=0, rtol=1e-15)
256
+
257
+
258
+ @pytest.mark.parametrize('x,y', list(it.product(
259
+ [
260
+ -np.inf,
261
+ np.inf,
262
+ complex(-np.inf, 0.),
263
+ complex(-np.inf, -0.),
264
+ complex(-np.inf, np.inf),
265
+ complex(-np.inf, -np.inf),
266
+ complex(np.inf, 0.),
267
+ complex(np.inf, -0.),
268
+ complex(np.inf, np.inf),
269
+ complex(np.inf, -np.inf),
270
+ # Phase in each quadrant.
271
+ complex(-np.inf, 0.7533),
272
+ complex(-np.inf, 2.3562),
273
+ complex(-np.inf, 3.9270),
274
+ complex(-np.inf, 5.4978),
275
+ complex(np.inf, 0.7533),
276
+ complex(np.inf, 2.3562),
277
+ complex(np.inf, 3.9270),
278
+ complex(np.inf, 5.4978),
279
+ ], repeat=2)
280
+ ))
281
+ def test_gh22601_infinite_elements(self, x, y, xp):
282
+ # Test that `logsumexp` does reasonable things in the presence of
283
+ # real and complex infinities.
284
+ res = logsumexp(xp.asarray([x, y]))
285
+ ref = xp.log(xp.sum(xp.exp(xp.asarray([x, y]))))
286
+ xp_assert_equal(res, ref)
287
+
288
+ def test_no_writeback(self, xp):
289
+ """Test that logsumexp doesn't accidentally write back to its parameters."""
290
+ a = xp.asarray([5., 4.])
291
+ b = xp.asarray([3., 2.])
292
+ logsumexp(a)
293
+ logsumexp(a, b=b)
294
+ xp_assert_equal(a, xp.asarray([5., 4.]))
295
+ xp_assert_equal(b, xp.asarray([3., 2.]))
296
+
297
+ @pytest.mark.parametrize("x_raw", [1.0, 1.0j, []])
298
+ def test_device(self, x_raw, xp, devices):
299
+ """Test input device propagation to output."""
300
+ for d in devices:
301
+ x = xp.asarray(x_raw, device=d)
302
+ assert xp_device(logsumexp(x)) == xp_device(x)
303
+ assert xp_device(logsumexp(x, b=x)) == xp_device(x)
304
+
305
+ def test_gh22903(self, xp):
306
+ # gh-22903 reported that `logsumexp` produced NaN where the weight associated
307
+ # with the max magnitude element was negative and `return_sign=False`, even if
308
+ # the net result should be the log of a positive number.
309
+
310
+ # result is log of positive number
311
+ a = xp.asarray([3.06409428, 0.37251854, 3.87471931])
312
+ b = xp.asarray([1.88190708, 2.84174795, -0.85016884])
313
+ xp_assert_close(logsumexp(a, b=b), logsumexp(a, b=b, return_sign=True)[0])
314
+
315
+ # result is log of negative number
316
+ b = xp.asarray([1.88190708, 2.84174795, -3.85016884])
317
+ xp_assert_close(logsumexp(a, b=b), xp.asarray(xp.nan))
318
+
319
+ @pytest.mark.parametrize("a, b, sign_ref",
320
+ [([np.inf], None, 1.),
321
+ ([np.inf], [-1.], -1.)])
322
+ def test_gh23548(self, xp, a, b, sign_ref):
323
+ # gh-23548 reported that `logsumexp` with `return_sign=True` returned a sign
324
+ # of NaN with infinite reals
325
+ a, b = xp.asarray(a), xp.asarray(b) if b is not None else None
326
+ val, sign = logsumexp(a, b=b, return_sign=True)
327
+ assert xp.isinf(val)
328
+ xp_assert_equal(sign, xp.asarray(sign_ref))
329
+
330
+
331
+ @make_xp_test_case(softmax)
332
+ class TestSoftmax:
333
+ def test_softmax_fixtures(self, xp):
334
+ xp_assert_close(softmax(xp.asarray([1000., 0., 0., 0.])),
335
+ xp.asarray([1., 0., 0., 0.]), rtol=1e-13)
336
+ xp_assert_close(softmax(xp.asarray([1., 1.])),
337
+ xp.asarray([.5, .5]), rtol=1e-13)
338
+ xp_assert_close(softmax(xp.asarray([0., 1.])),
339
+ xp.asarray([1., np.e])/(1 + np.e),
340
+ rtol=1e-13)
341
+
342
+ # Expected value computed using mpmath (with mpmath.mp.dps = 200) and then
343
+ # converted to float.
344
+ x = xp.arange(4, dtype=xp.float64)
345
+ expected = xp.asarray([0.03205860328008499,
346
+ 0.08714431874203256,
347
+ 0.23688281808991013,
348
+ 0.6439142598879722], dtype=xp.float64)
349
+
350
+ xp_assert_close(softmax(x), expected, rtol=1e-13)
351
+
352
+ # Translation property. If all the values are changed by the same amount,
353
+ # the softmax result does not change.
354
+ xp_assert_close(softmax(x + 100), expected, rtol=1e-13)
355
+
356
+ # When axis=None, softmax operates on the entire array, and preserves
357
+ # the shape.
358
+ xp_assert_close(softmax(xp.reshape(x, (2, 2))),
359
+ xp.reshape(expected, (2, 2)), rtol=1e-13)
360
+
361
+ def test_softmax_multi_axes(self, xp):
362
+ xp_assert_close(softmax(xp.asarray([[1000., 0.], [1000., 0.]]), axis=0),
363
+ xp.asarray([[.5, .5], [.5, .5]]), rtol=1e-13)
364
+ xp_assert_close(softmax(xp.asarray([[1000., 0.], [1000., 0.]]), axis=1),
365
+ xp.asarray([[1., 0.], [1., 0.]]), rtol=1e-13)
366
+
367
+ # Expected value computed using mpmath (with mpmath.mp.dps = 200) and then
368
+ # converted to float.
369
+ x = xp.asarray([[-25., 0., 25., 50.],
370
+ [ 1., 325., 749., 750.]])
371
+ expected = xp.asarray([[2.678636961770877e-33,
372
+ 1.9287498479371314e-22,
373
+ 1.3887943864771144e-11,
374
+ 0.999999999986112],
375
+ [0.0,
376
+ 1.9444526359919372e-185,
377
+ 0.2689414213699951,
378
+ 0.7310585786300048]])
379
+ xp_assert_close(softmax(x, axis=1), expected, rtol=1e-13)
380
+ xp_assert_close(softmax(x.T, axis=0), expected.T, rtol=1e-13)
381
+
382
+ # 3-d input, with a tuple for the axis.
383
+ x3d = xp.reshape(x, (2, 2, 2))
384
+ xp_assert_close(softmax(x3d, axis=(1, 2)),
385
+ xp.reshape(expected, (2, 2, 2)), rtol=1e-13)
386
+
387
+ @pytest.mark.xfail_xp_backends("array_api_strict", reason="int->float promotion")
388
+ def test_softmax_int_array(self, xp):
389
+ xp_assert_close(softmax(xp.asarray([1000, 0, 0, 0])),
390
+ xp.asarray([1., 0., 0., 0.]), rtol=1e-13)
391
+
392
+ def test_softmax_scalar(self):
393
+ xp_assert_close(softmax(1000), np.asarray(1.), rtol=1e-13)
394
+
395
+ def test_softmax_array_like(self):
396
+ xp_assert_close(softmax([1000, 0, 0, 0]),
397
+ np.asarray([1., 0., 0., 0.]), rtol=1e-13)
398
+
399
+
400
+ @make_xp_test_case(log_softmax)
401
+ class TestLogSoftmax:
402
+ def test_log_softmax_basic(self, xp):
403
+ xp_assert_close(log_softmax(xp.asarray([1000., 1.])),
404
+ xp.asarray([0., -999.]), rtol=1e-13)
405
+
406
+ @pytest.mark.xfail_xp_backends("array_api_strict", reason="int->float promotion")
407
+ def test_log_softmax_int_array(self, xp):
408
+ xp_assert_close(log_softmax(xp.asarray([1000, 1])),
409
+ xp.asarray([0., -999.]), rtol=1e-13)
410
+
411
+ def test_log_softmax_scalar(self):
412
+ xp_assert_close(log_softmax(1.0), 0.0, rtol=1e-13)
413
+
414
+ def test_log_softmax_array_like(self):
415
+ xp_assert_close(log_softmax([1000, 1]),
416
+ np.asarray([0., -999.]), rtol=1e-13)
417
+
418
+ @staticmethod
419
+ def data_1d(xp):
420
+ x = xp.arange(4, dtype=xp.float64)
421
+ # Expected value computed using mpmath (with mpmath.mp.dps = 200)
422
+ expect = [-3.4401896985611953,
423
+ -2.4401896985611953,
424
+ -1.4401896985611953,
425
+ -0.44018969856119533]
426
+ return x, xp.asarray(expect, dtype=xp.float64)
427
+
428
+ @staticmethod
429
+ def data_2d(xp):
430
+ x = xp.reshape(xp.arange(8, dtype=xp.float64), (2, 4))
431
+
432
+ # Expected value computed using mpmath (with mpmath.mp.dps = 200)
433
+ expect = [[-3.4401896985611953,
434
+ -2.4401896985611953,
435
+ -1.4401896985611953,
436
+ -0.44018969856119533],
437
+ [-3.4401896985611953,
438
+ -2.4401896985611953,
439
+ -1.4401896985611953,
440
+ -0.44018969856119533]]
441
+ return x, xp.asarray(expect, dtype=xp.float64)
442
+
443
+ @pytest.mark.parametrize("offset", [0, 100])
444
+ def test_log_softmax_translation(self, offset, xp):
445
+ # Translation property. If all the values are changed by the same amount,
446
+ # the softmax result does not change.
447
+ x, expect = self.data_1d(xp)
448
+ x += offset
449
+ xp_assert_close(log_softmax(x), expect, rtol=1e-13)
450
+
451
+ def test_log_softmax_noneaxis(self, xp):
452
+ # When axis=None, softmax operates on the entire array, and preserves
453
+ # the shape.
454
+ x, expect = self.data_1d(xp)
455
+ x = xp.reshape(x, (2, 2))
456
+ expect = xp.reshape(expect, (2, 2))
457
+ xp_assert_close(log_softmax(x), expect, rtol=1e-13)
458
+
459
+ @pytest.mark.parametrize('axis_2d, expected_2d', [
460
+ (0, np.log(0.5) * np.ones((2, 2))),
461
+ (1, [[0., -999.], [0., -999.]]),
462
+ ])
463
+ def test_axes(self, axis_2d, expected_2d, xp):
464
+ x = xp.asarray([[1000., 1.], [1000., 1.]])
465
+ xp_assert_close(log_softmax(x, axis=axis_2d),
466
+ xp.asarray(expected_2d, dtype=x.dtype), rtol=1e-13)
467
+
468
+ def test_log_softmax_2d_axis1(self, xp):
469
+ x, expect = self.data_2d(xp)
470
+ xp_assert_close(log_softmax(x, axis=1), expect, rtol=1e-13)
471
+
472
+ def test_log_softmax_2d_axis0(self, xp):
473
+ x, expect = self.data_2d(xp)
474
+ xp_assert_close(log_softmax(x.T, axis=0), expect.T, rtol=1e-13)
475
+
476
+ def test_log_softmax_3d(self, xp):
477
+ # 3D input, with a tuple for the axis.
478
+ x, expect = self.data_2d(xp)
479
+ x = xp.reshape(x, (2, 2, 2))
480
+ expect = xp.reshape(expect, (2, 2, 2))
481
+ xp_assert_close(log_softmax(x, axis=(1, 2)), expect, rtol=1e-13)
.venv/lib/python3.12/site-packages/scipy/special/tests/test_mpmath.py ADDED
@@ -0,0 +1,2160 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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._external.packaging_version import version
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
+ pytestmark = pytest.mark.thread_unsafe(
31
+ reason=("mpmath gmpy2 backend is not thread-safe, "
32
+ "see https://github.com/mpmath/mpmath/issues/974"))
33
+
34
+ # ------------------------------------------------------------------------------
35
+ # expi
36
+ # ------------------------------------------------------------------------------
37
+
38
+ @check_version(mpmath, '0.10')
39
+ def test_expi_complex():
40
+ dataset = []
41
+ for r in np.logspace(-99, 2, 10):
42
+ for p in np.linspace(0, 2*np.pi, 30):
43
+ z = r*np.exp(1j*p)
44
+ dataset.append((z, complex(mpmath.ei(z))))
45
+ dataset = np.array(dataset, dtype=np.cdouble)
46
+
47
+ FuncData(sc.expi, dataset, 0, 1).check()
48
+
49
+
50
+ # ------------------------------------------------------------------------------
51
+ # expn
52
+ # ------------------------------------------------------------------------------
53
+
54
+ @check_version(mpmath, '0.19')
55
+ def test_expn_large_n():
56
+ # Test the transition to the asymptotic regime of n.
57
+ dataset = []
58
+ for n in [50, 51]:
59
+ for x in np.logspace(0, 4, 200):
60
+ with mpmath.workdps(100):
61
+ dataset.append((n, x, float(mpmath.expint(n, x))))
62
+ dataset = np.asarray(dataset)
63
+
64
+ FuncData(sc.expn, dataset, (0, 1), 2, rtol=1e-13).check()
65
+
66
+ # ------------------------------------------------------------------------------
67
+ # hyp0f1
68
+ # ------------------------------------------------------------------------------
69
+
70
+
71
+ @check_version(mpmath, '0.19')
72
+ def test_hyp0f1_gh5764():
73
+ # Do a small and somewhat systematic test that runs quickly
74
+ dataset = []
75
+ axis = [-99.5, -9.5, -0.5, 0.5, 9.5, 99.5]
76
+ for v in axis:
77
+ for x in axis:
78
+ for y in axis:
79
+ z = x + 1j*y
80
+ # mpmath computes the answer correctly at dps ~ 17 but
81
+ # fails for 20 < dps < 120 (uses a different method);
82
+ # set the dps high enough that this isn't an issue
83
+ with mpmath.workdps(120):
84
+ res = complex(mpmath.hyp0f1(v, z))
85
+ dataset.append((v, z, res))
86
+ dataset = np.array(dataset)
87
+
88
+ FuncData(lambda v, z: sc.hyp0f1(v.real, z), dataset, (0, 1), 2,
89
+ rtol=1e-13).check()
90
+
91
+
92
+ @check_version(mpmath, '0.19')
93
+ def test_hyp0f1_gh_1609():
94
+ # this is a regression test for gh-1609
95
+ vv = np.linspace(150, 180, 21)
96
+ af = sc.hyp0f1(vv, 0.5)
97
+ mf = np.array([mpmath.hyp0f1(v, 0.5) for v in vv])
98
+ assert_allclose(af, mf.astype(float), rtol=1e-12)
99
+
100
+
101
+ # ------------------------------------------------------------------------------
102
+ # hyperu
103
+ # ------------------------------------------------------------------------------
104
+
105
+ @check_version(mpmath, '1.1.0')
106
+ def test_hyperu_around_0():
107
+ dataset = []
108
+ # DLMF 13.2.14-15 test points.
109
+ for n in np.arange(-5, 5):
110
+ for b in np.linspace(-5, 5, 20):
111
+ a = -n
112
+ dataset.append((a, b, 0, float(mpmath.hyperu(a, b, 0))))
113
+ a = -n + b - 1
114
+ dataset.append((a, b, 0, float(mpmath.hyperu(a, b, 0))))
115
+ # DLMF 13.2.16-22 test points.
116
+ for a in [-10.5, -1.5, -0.5, 0, 0.5, 1, 10]:
117
+ for b in [-1.0, -0.5, 0, 0.5, 1, 1.5, 2, 2.5]:
118
+ dataset.append((a, b, 0, float(mpmath.hyperu(a, b, 0))))
119
+ dataset = np.array(dataset)
120
+
121
+ FuncData(sc.hyperu, dataset, (0, 1, 2), 3, rtol=1e-15, atol=5e-13).check()
122
+
123
+
124
+ # ------------------------------------------------------------------------------
125
+ # hyp2f1
126
+ # ------------------------------------------------------------------------------
127
+
128
+ @check_version(mpmath, '1.0.0')
129
+ def test_hyp2f1_strange_points():
130
+ pts = [
131
+ (2, -1, -1, 0.7), # expected: 2.4
132
+ (2, -2, -2, 0.7), # expected: 3.87
133
+ ]
134
+ pts += list(itertools.product([2, 1, -0.7, -1000], repeat=4))
135
+ pts = [
136
+ (a, b, c, x) for a, b, c, x in pts
137
+ if b == c and round(b) == b and b < 0 and b != -1000
138
+ ]
139
+ kw = dict(eliminate=True)
140
+ dataset = [p + (float(mpmath.hyp2f1(*p, **kw)),) for p in pts]
141
+ dataset = np.array(dataset, dtype=np.float64)
142
+
143
+ FuncData(sc.hyp2f1, dataset, (0,1,2,3), 4, rtol=1e-10).check()
144
+
145
+
146
+ @check_version(mpmath, '0.13')
147
+ def test_hyp2f1_real_some_points():
148
+ pts = [
149
+ (1, 2, 3, 0),
150
+ (1./3, 2./3, 5./6, 27./32),
151
+ (1./4, 1./2, 3./4, 80./81),
152
+ (2,-2, -3, 3),
153
+ (2, -3, -2, 3),
154
+ (2, -1.5, -1.5, 3),
155
+ (1, 2, 3, 0),
156
+ (0.7235, -1, -5, 0.3),
157
+ (0.25, 1./3, 2, 0.999),
158
+ (0.25, 1./3, 2, -1),
159
+ (2, 3, 5, 0.99),
160
+ (3./2, -0.5, 3, 0.99),
161
+ (2, 2.5, -3.25, 0.999),
162
+ (-8, 18.016500331508873, 10.805295997850628, 0.90875647507000001),
163
+ (-10, 900, -10.5, 0.99),
164
+ (-10, 900, 10.5, 0.99),
165
+ (-1, 2, 1, 1.0),
166
+ (-1, 2, 1, -1.0),
167
+ (-3, 13, 5, 1.0),
168
+ (-3, 13, 5, -1.0),
169
+ (0.5, 1 - 270.5, 1.5, 0.999**2), # from issue 1561
170
+ ]
171
+ dataset = [p + (float(mpmath.hyp2f1(*p)),) for p in pts]
172
+ dataset = np.array(dataset, dtype=np.float64)
173
+
174
+ with np.errstate(invalid='ignore'):
175
+ FuncData(sc.hyp2f1, dataset, (0,1,2,3), 4, rtol=1e-10).check()
176
+
177
+
178
+ @check_version(mpmath, '0.14')
179
+ def test_hyp2f1_some_points_2():
180
+ # Taken from mpmath unit tests -- this point failed for mpmath 0.13 but
181
+ # was fixed in their SVN since then
182
+ pts = [
183
+ (112, (51,10), (-9,10), -0.99999),
184
+ (10,-900,10.5,0.99),
185
+ (10,-900,-10.5,0.99),
186
+ ]
187
+
188
+ def fev(x):
189
+ if isinstance(x, tuple):
190
+ return float(x[0]) / x[1]
191
+ else:
192
+ return x
193
+
194
+ dataset = [tuple(map(fev, p)) + (float(mpmath.hyp2f1(*p)),) for p in pts]
195
+ dataset = np.array(dataset, dtype=np.float64)
196
+
197
+ FuncData(sc.hyp2f1, dataset, (0,1,2,3), 4, rtol=1e-10).check()
198
+
199
+
200
+ @check_version(mpmath, '0.13')
201
+ def test_hyp2f1_real_some():
202
+ dataset = []
203
+ for a in [-10, -5, -1.8, 1.8, 5, 10]:
204
+ for b in [-2.5, -1, 1, 7.4]:
205
+ for c in [-9, -1.8, 5, 20.4]:
206
+ for z in [-10, -1.01, -0.99, 0, 0.6, 0.95, 1.5, 10]:
207
+ try:
208
+ v = float(mpmath.hyp2f1(a, b, c, z))
209
+ except Exception:
210
+ continue
211
+ dataset.append((a, b, c, z, v))
212
+ dataset = np.array(dataset, dtype=np.float64)
213
+
214
+ with np.errstate(invalid='ignore'):
215
+ FuncData(sc.hyp2f1, dataset, (0,1,2,3), 4, rtol=1e-9,
216
+ ignore_inf_sign=True).check()
217
+
218
+
219
+ @check_version(mpmath, '0.12')
220
+ @pytest.mark.slow
221
+ def test_hyp2f1_real_random():
222
+ npoints = 500
223
+ dataset = np.zeros((npoints, 5), np.float64)
224
+
225
+ np.random.seed(1234)
226
+ dataset[:, 0] = np.random.pareto(1.5, npoints)
227
+ dataset[:, 1] = np.random.pareto(1.5, npoints)
228
+ dataset[:, 2] = np.random.pareto(1.5, npoints)
229
+ dataset[:, 3] = 2*np.random.rand(npoints) - 1
230
+
231
+ dataset[:, 0] *= (-1)**np.random.randint(2, npoints)
232
+ dataset[:, 1] *= (-1)**np.random.randint(2, npoints)
233
+ dataset[:, 2] *= (-1)**np.random.randint(2, npoints)
234
+
235
+ for ds in dataset:
236
+ if mpmath.__version__ < '0.14':
237
+ # mpmath < 0.14 fails for c too much smaller than a, b
238
+ if abs(ds[:2]).max() > abs(ds[2]):
239
+ ds[2] = abs(ds[:2]).max()
240
+ ds[4] = float(mpmath.hyp2f1(*tuple(ds[:4])))
241
+
242
+ FuncData(sc.hyp2f1, dataset, (0, 1, 2, 3), 4, rtol=1e-9).check()
243
+
244
+
245
+ # ------------------------------------------------------------------------------
246
+ # erf (complex)
247
+ # ------------------------------------------------------------------------------
248
+
249
+ @pytest.mark.slow()
250
+ @check_version(mpmath, '0.14')
251
+ def test_erf_complex():
252
+ # need to increase mpmath precision for this test
253
+ old_dps, old_prec = mpmath.mp.dps, mpmath.mp.prec
254
+ try:
255
+ mpmath.mp.dps = 70
256
+ x1, y1 = np.meshgrid(np.linspace(-10, 1, 31), np.linspace(-10, 1, 11))
257
+ x2, y2 = np.meshgrid(np.logspace(-80, .8, 31), np.logspace(-80, .8, 11))
258
+ points = np.r_[x1.ravel(),x2.ravel()] + 1j*np.r_[y1.ravel(), y2.ravel()]
259
+
260
+ assert_func_equal(sc.erf, lambda x: complex(mpmath.erf(x)), points,
261
+ vectorized=False, rtol=1e-13)
262
+ assert_func_equal(sc.erfc, lambda x: complex(mpmath.erfc(x)), points,
263
+ vectorized=False, rtol=1e-13)
264
+ finally:
265
+ mpmath.mp.dps, mpmath.mp.prec = old_dps, old_prec
266
+
267
+
268
+ # ------------------------------------------------------------------------------
269
+ # lpmv
270
+ # ------------------------------------------------------------------------------
271
+
272
+ @check_version(mpmath, '0.15')
273
+ def test_lpmv():
274
+ pts = []
275
+ for x in [-0.99, -0.557, 1e-6, 0.132, 1]:
276
+ pts.extend([
277
+ (1, 1, x),
278
+ (1, -1, x),
279
+ (-1, 1, x),
280
+ (-1, -2, x),
281
+ (1, 1.7, x),
282
+ (1, -1.7, x),
283
+ (-1, 1.7, x),
284
+ (-1, -2.7, x),
285
+ (1, 10, x),
286
+ (1, 11, x),
287
+ (3, 8, x),
288
+ (5, 11, x),
289
+ (-3, 8, x),
290
+ (-5, 11, x),
291
+ (3, -8, x),
292
+ (5, -11, x),
293
+ (-3, -8, x),
294
+ (-5, -11, x),
295
+ (3, 8.3, x),
296
+ (5, 11.3, x),
297
+ (-3, 8.3, x),
298
+ (-5, 11.3, x),
299
+ (3, -8.3, x),
300
+ (5, -11.3, x),
301
+ (-3, -8.3, x),
302
+ (-5, -11.3, x),
303
+ ])
304
+
305
+ def mplegenp(nu, mu, x):
306
+ if mu == int(mu) and x == 1:
307
+ # mpmath 0.17 gets this wrong
308
+ if mu == 0:
309
+ return 1
310
+ else:
311
+ return 0
312
+ return mpmath.legenp(nu, mu, x)
313
+
314
+ dataset = [p + (mplegenp(p[1], p[0], p[2]),) for p in pts]
315
+ dataset = np.array(dataset, dtype=np.float64)
316
+
317
+ def evf(mu, nu, x):
318
+ return sc.lpmv(mu.astype(int), nu, x)
319
+
320
+ with np.errstate(invalid='ignore'):
321
+ FuncData(evf, dataset, (0,1,2), 3, rtol=1e-10, atol=1e-14).check()
322
+
323
+
324
+ # ------------------------------------------------------------------------------
325
+ # beta
326
+ # ------------------------------------------------------------------------------
327
+
328
+ @pytest.mark.slow
329
+ @check_version(mpmath, '0.15')
330
+ def test_beta():
331
+ np.random.seed(1234)
332
+
333
+ b = np.r_[np.logspace(-200, 200, 4),
334
+ np.logspace(-10, 10, 4),
335
+ np.logspace(-1, 1, 4),
336
+ np.arange(-10, 11, 1),
337
+ np.arange(-10, 11, 1) + 0.5,
338
+ -1, -2.3, -3, -100.3, -10003.4]
339
+ a = b
340
+
341
+ ab = np.array(np.broadcast_arrays(a[:,None], b[None,:])).reshape(2, -1).T
342
+
343
+ old_dps, old_prec = mpmath.mp.dps, mpmath.mp.prec
344
+ try:
345
+ mpmath.mp.dps = 400
346
+
347
+ assert_func_equal(sc.beta,
348
+ lambda a, b: float(mpmath.beta(a, b)),
349
+ ab,
350
+ vectorized=False,
351
+ rtol=1e-10,
352
+ ignore_inf_sign=True)
353
+
354
+ assert_func_equal(
355
+ sc.betaln,
356
+ lambda a, b: float(mpmath.log(abs(mpmath.beta(a, b)))),
357
+ ab,
358
+ vectorized=False,
359
+ rtol=1e-10)
360
+ finally:
361
+ mpmath.mp.dps, mpmath.mp.prec = old_dps, old_prec
362
+
363
+
364
+ # ------------------------------------------------------------------------------
365
+ # loggamma
366
+ # ------------------------------------------------------------------------------
367
+
368
+ LOGGAMMA_TAYLOR_RADIUS = 0.2
369
+
370
+
371
+ @check_version(mpmath, '0.19')
372
+ def test_loggamma_taylor_transition():
373
+ # Make sure there isn't a big jump in accuracy when we move from
374
+ # using the Taylor series to using the recurrence relation.
375
+
376
+ r = LOGGAMMA_TAYLOR_RADIUS + np.array([-0.1, -0.01, 0, 0.01, 0.1])
377
+ theta = np.linspace(0, 2*np.pi, 20)
378
+ r, theta = np.meshgrid(r, theta)
379
+ dz = r*np.exp(1j*theta)
380
+ z = np.r_[1 + dz, 2 + dz].flatten()
381
+
382
+ dataset = [(z0, complex(mpmath.loggamma(z0))) for z0 in z]
383
+ dataset = np.array(dataset)
384
+
385
+ FuncData(sc.loggamma, dataset, 0, 1, rtol=5e-14).check()
386
+
387
+
388
+ @check_version(mpmath, '0.19')
389
+ def test_loggamma_taylor():
390
+ # Test around the zeros at z = 1, 2.
391
+
392
+ r = np.logspace(-16, np.log10(LOGGAMMA_TAYLOR_RADIUS), 10)
393
+ theta = np.linspace(0, 2*np.pi, 20)
394
+ r, theta = np.meshgrid(r, theta)
395
+ dz = r*np.exp(1j*theta)
396
+ z = np.r_[1 + dz, 2 + dz].flatten()
397
+
398
+ dataset = [(z0, complex(mpmath.loggamma(z0))) for z0 in z]
399
+ dataset = np.array(dataset)
400
+
401
+ FuncData(sc.loggamma, dataset, 0, 1, rtol=5e-14).check()
402
+
403
+
404
+ # ------------------------------------------------------------------------------
405
+ # rgamma
406
+ # ------------------------------------------------------------------------------
407
+
408
+ @check_version(mpmath, '0.19')
409
+ @pytest.mark.slow
410
+ def test_rgamma_zeros():
411
+ # Test around the zeros at z = 0, -1, -2, ..., -169. (After -169 we
412
+ # get values that are out of floating point range even when we're
413
+ # within 0.1 of the zero.)
414
+
415
+ # Can't use too many points here or the test takes forever.
416
+ dx = np.r_[-np.logspace(-1, -13, 3), 0, np.logspace(-13, -1, 3)]
417
+ dy = dx.copy()
418
+ dx, dy = np.meshgrid(dx, dy)
419
+ dz = dx + 1j*dy
420
+ zeros = np.arange(0, -170, -1).reshape(1, 1, -1)
421
+ z = (zeros + np.dstack((dz,)*zeros.size)).flatten()
422
+ with mpmath.workdps(100):
423
+ dataset = [(z0, complex(mpmath.rgamma(z0))) for z0 in z]
424
+
425
+ dataset = np.array(dataset)
426
+ FuncData(sc.rgamma, dataset, 0, 1, rtol=1e-12).check()
427
+
428
+
429
+ # ------------------------------------------------------------------------------
430
+ # digamma
431
+ # ------------------------------------------------------------------------------
432
+
433
+ @check_version(mpmath, '0.19')
434
+ @pytest.mark.slow
435
+ def test_digamma_roots():
436
+ # Test the special-cased roots for digamma.
437
+ root = mpmath.findroot(mpmath.digamma, 1.5)
438
+ roots = [float(root)]
439
+ root = mpmath.findroot(mpmath.digamma, -0.5)
440
+ roots.append(float(root))
441
+ roots = np.array(roots)
442
+
443
+ # If we test beyond a radius of 0.24 mpmath will take forever.
444
+ dx = np.r_[-0.24, -np.logspace(-1, -15, 10), 0, np.logspace(-15, -1, 10), 0.24]
445
+ dy = dx.copy()
446
+ dx, dy = np.meshgrid(dx, dy)
447
+ dz = dx + 1j*dy
448
+ z = (roots + np.dstack((dz,)*roots.size)).flatten()
449
+ with mpmath.workdps(30):
450
+ dataset = [(z0, complex(mpmath.digamma(z0))) for z0 in z]
451
+
452
+ dataset = np.array(dataset)
453
+ FuncData(sc.digamma, dataset, 0, 1, rtol=1e-14).check()
454
+
455
+
456
+ @check_version(mpmath, '0.19')
457
+ def test_digamma_negreal():
458
+ # Test digamma around the negative real axis. Don't do this in
459
+ # TestSystematic because the points need some jiggering so that
460
+ # mpmath doesn't take forever.
461
+
462
+ digamma = exception_to_nan(mpmath.digamma)
463
+
464
+ x = -np.logspace(300, -30, 100)
465
+ y = np.r_[-np.logspace(0, -3, 5), 0, np.logspace(-3, 0, 5)]
466
+ x, y = np.meshgrid(x, y)
467
+ z = (x + 1j*y).flatten()
468
+
469
+ with mpmath.workdps(40):
470
+ dataset = [(z0, complex(digamma(z0))) for z0 in z]
471
+ dataset = np.asarray(dataset)
472
+
473
+ FuncData(sc.digamma, dataset, 0, 1, rtol=1e-13).check()
474
+
475
+
476
+ @check_version(mpmath, '0.19')
477
+ def test_digamma_boundary():
478
+ # Check that there isn't a jump in accuracy when we switch from
479
+ # using the asymptotic series to the reflection formula.
480
+
481
+ x = -np.logspace(300, -30, 100)
482
+ y = np.array([-6.1, -5.9, 5.9, 6.1])
483
+ x, y = np.meshgrid(x, y)
484
+ z = (x + 1j*y).flatten()
485
+
486
+ with mpmath.workdps(30):
487
+ dataset = [(z0, complex(mpmath.digamma(z0))) for z0 in z]
488
+ dataset = np.asarray(dataset)
489
+
490
+ FuncData(sc.digamma, dataset, 0, 1, rtol=1e-13).check()
491
+
492
+
493
+ # ------------------------------------------------------------------------------
494
+ # gammainc
495
+ # ------------------------------------------------------------------------------
496
+
497
+ @check_version(mpmath, '0.19')
498
+ @pytest.mark.slow
499
+ def test_gammainc_boundary():
500
+ # Test the transition to the asymptotic series.
501
+ small = 20
502
+ a = np.linspace(0.5*small, 2*small, 50)
503
+ x = a.copy()
504
+ a, x = np.meshgrid(a, x)
505
+ a, x = a.flatten(), x.flatten()
506
+ with mpmath.workdps(100):
507
+ dataset = [(a0, x0, float(mpmath.gammainc(a0, b=x0, regularized=True)))
508
+ for a0, x0 in zip(a, x)]
509
+ dataset = np.array(dataset)
510
+
511
+ FuncData(sc.gammainc, dataset, (0, 1), 2, rtol=1e-12).check()
512
+
513
+
514
+ # ------------------------------------------------------------------------------
515
+ # spence
516
+ # ------------------------------------------------------------------------------
517
+
518
+ @check_version(mpmath, '0.19')
519
+ @pytest.mark.slow
520
+ def test_spence_circle():
521
+ # The trickiest region for spence is around the circle |z - 1| = 1,
522
+ # so test that region carefully.
523
+
524
+ def spence(z):
525
+ return complex(mpmath.polylog(2, 1 - z))
526
+
527
+ r = np.linspace(0.5, 1.5)
528
+ theta = np.linspace(0, 2*pi)
529
+ z = (1 + np.outer(r, np.exp(1j*theta))).flatten()
530
+ dataset = np.asarray([(z0, spence(z0)) for z0 in z])
531
+
532
+ FuncData(sc.spence, dataset, 0, 1, rtol=1e-14).check()
533
+
534
+
535
+ # ------------------------------------------------------------------------------
536
+ # sinpi and cospi
537
+ # ------------------------------------------------------------------------------
538
+
539
+ @check_version(mpmath, '0.19')
540
+ def test_sinpi_zeros():
541
+ eps = np.finfo(float).eps
542
+ dx = np.r_[-np.logspace(0, -13, 3), 0, np.logspace(-13, 0, 3)]
543
+ dy = dx.copy()
544
+ dx, dy = np.meshgrid(dx, dy)
545
+ dz = dx + 1j*dy
546
+ zeros = np.arange(-100, 100, 1).reshape(1, 1, -1)
547
+ z = (zeros + np.dstack((dz,)*zeros.size)).flatten()
548
+ dataset = np.asarray([(z0, complex(mpmath.sinpi(z0)))
549
+ for z0 in z])
550
+ FuncData(_sinpi, dataset, 0, 1, rtol=2*eps).check()
551
+
552
+
553
+ @check_version(mpmath, '0.19')
554
+ def test_cospi_zeros():
555
+ eps = np.finfo(float).eps
556
+ dx = np.r_[-np.logspace(0, -13, 3), 0, np.logspace(-13, 0, 3)]
557
+ dy = dx.copy()
558
+ dx, dy = np.meshgrid(dx, dy)
559
+ dz = dx + 1j*dy
560
+ zeros = (np.arange(-100, 100, 1) + 0.5).reshape(1, 1, -1)
561
+ z = (zeros + np.dstack((dz,)*zeros.size)).flatten()
562
+ dataset = np.asarray([(z0, complex(mpmath.cospi(z0)))
563
+ for z0 in z])
564
+
565
+ FuncData(_cospi, dataset, 0, 1, rtol=2*eps).check()
566
+
567
+
568
+ # ------------------------------------------------------------------------------
569
+ # ellipj
570
+ # ------------------------------------------------------------------------------
571
+
572
+ @check_version(mpmath, '0.19')
573
+ def test_dn_quarter_period():
574
+ def dn(u, m):
575
+ return sc.ellipj(u, m)[2]
576
+
577
+ def mpmath_dn(u, m):
578
+ return float(mpmath.ellipfun("dn", u=u, m=m))
579
+
580
+ m = np.linspace(0, 1, 20)
581
+ du = np.r_[-np.logspace(-1, -15, 10), 0, np.logspace(-15, -1, 10)]
582
+ dataset = []
583
+ for m0 in m:
584
+ u0 = float(mpmath.ellipk(m0))
585
+ for du0 in du:
586
+ p = u0 + du0
587
+ dataset.append((p, m0, mpmath_dn(p, m0)))
588
+ dataset = np.asarray(dataset)
589
+
590
+ FuncData(dn, dataset, (0, 1), 2, rtol=1e-10).check()
591
+
592
+
593
+ # ------------------------------------------------------------------------------
594
+ # Wright Omega
595
+ # ------------------------------------------------------------------------------
596
+
597
+ def _mpmath_wrightomega(z, dps):
598
+ with mpmath.workdps(dps):
599
+ z = mpmath.mpc(z)
600
+ unwind = mpmath.ceil((z.imag - mpmath.pi)/(2*mpmath.pi))
601
+ res = mpmath.lambertw(mpmath.exp(z), unwind)
602
+ return res
603
+
604
+
605
+ @pytest.mark.slow
606
+ @check_version(mpmath, '0.19')
607
+ def test_wrightomega_branch():
608
+ x = -np.logspace(10, 0, 25)
609
+ picut_above = [np.nextafter(np.pi, np.inf)]
610
+ picut_below = [np.nextafter(np.pi, -np.inf)]
611
+ npicut_above = [np.nextafter(-np.pi, np.inf)]
612
+ npicut_below = [np.nextafter(-np.pi, -np.inf)]
613
+ for i in range(50):
614
+ picut_above.append(np.nextafter(picut_above[-1], np.inf))
615
+ picut_below.append(np.nextafter(picut_below[-1], -np.inf))
616
+ npicut_above.append(np.nextafter(npicut_above[-1], np.inf))
617
+ npicut_below.append(np.nextafter(npicut_below[-1], -np.inf))
618
+ y = np.hstack((picut_above, picut_below, npicut_above, npicut_below))
619
+ x, y = np.meshgrid(x, y)
620
+ z = (x + 1j*y).flatten()
621
+
622
+ dataset = np.asarray([(z0, complex(_mpmath_wrightomega(z0, 25)))
623
+ for z0 in z])
624
+
625
+ FuncData(sc.wrightomega, dataset, 0, 1, rtol=1e-8).check()
626
+
627
+
628
+ @pytest.mark.slow
629
+ @check_version(mpmath, '0.19')
630
+ def test_wrightomega_region1():
631
+ # This region gets less coverage in the TestSystematic test
632
+ x = np.linspace(-2, 1)
633
+ y = np.linspace(1, 2*np.pi)
634
+ x, y = np.meshgrid(x, y)
635
+ z = (x + 1j*y).flatten()
636
+
637
+ dataset = np.asarray([(z0, complex(_mpmath_wrightomega(z0, 25)))
638
+ for z0 in z])
639
+
640
+ FuncData(sc.wrightomega, dataset, 0, 1, rtol=1e-15).check()
641
+
642
+
643
+ @pytest.mark.slow
644
+ @check_version(mpmath, '0.19')
645
+ def test_wrightomega_region2():
646
+ # This region gets less coverage in the TestSystematic test
647
+ x = np.linspace(-2, 1)
648
+ y = np.linspace(-2*np.pi, -1)
649
+ x, y = np.meshgrid(x, y)
650
+ z = (x + 1j*y).flatten()
651
+
652
+ dataset = np.asarray([(z0, complex(_mpmath_wrightomega(z0, 25)))
653
+ for z0 in z])
654
+
655
+ FuncData(sc.wrightomega, dataset, 0, 1, rtol=1e-15).check()
656
+
657
+
658
+ # ------------------------------------------------------------------------------
659
+ # lambertw
660
+ # ------------------------------------------------------------------------------
661
+
662
+ @pytest.mark.slow
663
+ @check_version(mpmath, '0.19')
664
+ def test_lambertw_smallz():
665
+ x, y = np.linspace(-1, 1, 25), np.linspace(-1, 1, 25)
666
+ x, y = np.meshgrid(x, y)
667
+ z = (x + 1j*y).flatten()
668
+
669
+ dataset = np.asarray([(z0, complex(mpmath.lambertw(z0)))
670
+ for z0 in z])
671
+
672
+ FuncData(sc.lambertw, dataset, 0, 1, rtol=1e-13).check()
673
+
674
+
675
+ # ------------------------------------------------------------------------------
676
+ # Systematic tests
677
+ # ------------------------------------------------------------------------------
678
+
679
+ HYPERKW = dict(maxprec=200, maxterms=200)
680
+
681
+
682
+ @pytest.mark.slow
683
+ @check_version(mpmath, '0.17')
684
+ class TestSystematic:
685
+
686
+ def test_airyai(self):
687
+ # oscillating function, limit range
688
+ assert_mpmath_equal(lambda z: sc.airy(z)[0],
689
+ mpmath.airyai,
690
+ [Arg(-1e8, 1e8)],
691
+ rtol=1e-5)
692
+ assert_mpmath_equal(lambda z: sc.airy(z)[0],
693
+ mpmath.airyai,
694
+ [Arg(-1e3, 1e3)])
695
+
696
+ def test_airyai_complex(self):
697
+ assert_mpmath_equal(lambda z: sc.airy(z)[0],
698
+ mpmath.airyai,
699
+ [ComplexArg()])
700
+
701
+ def test_airyai_prime(self):
702
+ # oscillating function, limit range
703
+ assert_mpmath_equal(lambda z: sc.airy(z)[1], lambda z:
704
+ mpmath.airyai(z, derivative=1),
705
+ [Arg(-1e8, 1e8)],
706
+ rtol=1e-5)
707
+ assert_mpmath_equal(lambda z: sc.airy(z)[1], lambda z:
708
+ mpmath.airyai(z, derivative=1),
709
+ [Arg(-1e3, 1e3)])
710
+
711
+ def test_airyai_prime_complex(self):
712
+ assert_mpmath_equal(lambda z: sc.airy(z)[1], lambda z:
713
+ mpmath.airyai(z, derivative=1),
714
+ [ComplexArg()])
715
+
716
+ def test_airybi(self):
717
+ # oscillating function, limit range
718
+ assert_mpmath_equal(lambda z: sc.airy(z)[2], lambda z:
719
+ mpmath.airybi(z),
720
+ [Arg(-1e8, 1e8)],
721
+ rtol=1e-5)
722
+ assert_mpmath_equal(lambda z: sc.airy(z)[2], lambda z:
723
+ mpmath.airybi(z),
724
+ [Arg(-1e3, 1e3)])
725
+
726
+ def test_airybi_complex(self):
727
+ assert_mpmath_equal(lambda z: sc.airy(z)[2], lambda z:
728
+ mpmath.airybi(z),
729
+ [ComplexArg()])
730
+
731
+ def test_airybi_prime(self):
732
+ # oscillating function, limit range
733
+ assert_mpmath_equal(lambda z: sc.airy(z)[3], lambda z:
734
+ mpmath.airybi(z, derivative=1),
735
+ [Arg(-1e8, 1e8)],
736
+ rtol=1e-5)
737
+ assert_mpmath_equal(lambda z: sc.airy(z)[3], lambda z:
738
+ mpmath.airybi(z, derivative=1),
739
+ [Arg(-1e3, 1e3)])
740
+
741
+ def test_airybi_prime_complex(self):
742
+ assert_mpmath_equal(lambda z: sc.airy(z)[3], lambda z:
743
+ mpmath.airybi(z, derivative=1),
744
+ [ComplexArg()])
745
+
746
+ def test_bei(self):
747
+ assert_mpmath_equal(sc.bei,
748
+ exception_to_nan(lambda z: mpmath.bei(0, z, **HYPERKW)),
749
+ [Arg(-1e3, 1e3)])
750
+
751
+ def test_ber(self):
752
+ assert_mpmath_equal(sc.ber,
753
+ exception_to_nan(lambda z: mpmath.ber(0, z, **HYPERKW)),
754
+ [Arg(-1e3, 1e3)])
755
+
756
+ def test_bernoulli(self):
757
+ assert_mpmath_equal(lambda n: sc.bernoulli(int(n))[int(n)],
758
+ lambda n: float(mpmath.bernoulli(int(n))),
759
+ [IntArg(0, 13000)],
760
+ rtol=1e-9, n=13000)
761
+
762
+ def test_besseli(self):
763
+ assert_mpmath_equal(
764
+ sc.iv,
765
+ exception_to_nan(lambda v, z: mpmath.besseli(v, z, **HYPERKW)),
766
+ [Arg(-1e100, 1e100), Arg()],
767
+ atol=1e-270,
768
+ )
769
+
770
+ def test_besseli_complex(self):
771
+ assert_mpmath_equal(
772
+ lambda v, z: sc.iv(v.real, z),
773
+ exception_to_nan(lambda v, z: mpmath.besseli(v, z, **HYPERKW)),
774
+ [Arg(-1e100, 1e100), ComplexArg()],
775
+ )
776
+
777
+ def test_besselj(self):
778
+ assert_mpmath_equal(
779
+ sc.jv,
780
+ exception_to_nan(lambda v, z: mpmath.besselj(v, z, **HYPERKW)),
781
+ [Arg(-1e100, 1e100), Arg(-1e3, 1e3)],
782
+ ignore_inf_sign=True,
783
+ )
784
+
785
+ # loss of precision at large arguments due to oscillation
786
+ assert_mpmath_equal(
787
+ sc.jv,
788
+ exception_to_nan(lambda v, z: mpmath.besselj(v, z, **HYPERKW)),
789
+ [Arg(-1e100, 1e100), Arg(-1e8, 1e8)],
790
+ ignore_inf_sign=True,
791
+ rtol=1e-5,
792
+ )
793
+
794
+ def test_besselj_complex(self):
795
+ assert_mpmath_equal(
796
+ lambda v, z: sc.jv(v.real, z),
797
+ exception_to_nan(lambda v, z: mpmath.besselj(v, z, **HYPERKW)),
798
+ [Arg(), ComplexArg()]
799
+ )
800
+
801
+ def test_besselk(self):
802
+ assert_mpmath_equal(
803
+ sc.kv,
804
+ mpmath.besselk,
805
+ [Arg(-200, 200), Arg(0, np.inf)],
806
+ nan_ok=False,
807
+ rtol=1e-12,
808
+ )
809
+
810
+ def test_besselk_int(self):
811
+ assert_mpmath_equal(
812
+ sc.kn,
813
+ mpmath.besselk,
814
+ [IntArg(-200, 200), Arg(0, np.inf)],
815
+ nan_ok=False,
816
+ rtol=1e-12,
817
+ )
818
+
819
+ def test_besselk_complex(self):
820
+ assert_mpmath_equal(
821
+ lambda v, z: sc.kv(v.real, z),
822
+ exception_to_nan(lambda v, z: mpmath.besselk(v, z, **HYPERKW)),
823
+ [Arg(-1e100, 1e100), ComplexArg()],
824
+ )
825
+
826
+ def test_bessely(self):
827
+ def mpbessely(v, x):
828
+ r = float(mpmath.bessely(v, x, **HYPERKW))
829
+ if abs(r) > 1e305:
830
+ # overflowing to inf a bit earlier is OK
831
+ r = np.inf * np.sign(r)
832
+ if abs(r) == 0 and x == 0:
833
+ # invalid result from mpmath, point x=0 is a divergence
834
+ return np.nan
835
+ return r
836
+ assert_mpmath_equal(
837
+ sc.yv,
838
+ exception_to_nan(mpbessely),
839
+ [Arg(-1e100, 1e100), Arg(-1e8, 1e8)],
840
+ n=5000,
841
+ )
842
+
843
+ def test_bessely_complex(self):
844
+ def mpbessely(v, x):
845
+ r = complex(mpmath.bessely(v, x, **HYPERKW))
846
+ if abs(r) > 1e305:
847
+ # overflowing to inf a bit earlier is OK
848
+ with np.errstate(invalid='ignore'):
849
+ r = np.inf * np.sign(r)
850
+ return r
851
+ assert_mpmath_equal(
852
+ lambda v, z: sc.yv(v.real, z),
853
+ exception_to_nan(mpbessely),
854
+ [Arg(), ComplexArg()],
855
+ n=15000,
856
+ )
857
+
858
+ def test_bessely_int(self):
859
+ def mpbessely(v, x):
860
+ r = float(mpmath.bessely(v, x))
861
+ if abs(r) == 0 and x == 0:
862
+ # invalid result from mpmath, point x=0 is a divergence
863
+ return np.nan
864
+ return r
865
+ assert_mpmath_equal(
866
+ lambda v, z: sc.yn(int(v), z),
867
+ exception_to_nan(mpbessely),
868
+ [IntArg(-1000, 1000), Arg(-1e8, 1e8)],
869
+ )
870
+
871
+ def test_beta(self):
872
+ bad_points = []
873
+
874
+ def beta(a, b, nonzero=False):
875
+ if a < -1e12 or b < -1e12:
876
+ # Function is defined here only at integers, but due
877
+ # to loss of precision this is numerically
878
+ # ill-defined. Don't compare values here.
879
+ return np.nan
880
+ if (a < 0 or b < 0) and (abs(float(a + b)) % 1) == 0:
881
+ # close to a zero of the function: mpmath and scipy
882
+ # will not round here the same, so the test needs to be
883
+ # run with an absolute tolerance
884
+ if nonzero:
885
+ bad_points.append((float(a), float(b)))
886
+ return np.nan
887
+ return mpmath.beta(a, b)
888
+
889
+ assert_mpmath_equal(
890
+ sc.beta,
891
+ lambda a, b: beta(a, b, nonzero=True),
892
+ [Arg(), Arg()],
893
+ dps=400,
894
+ ignore_inf_sign=True,
895
+ )
896
+
897
+ assert_mpmath_equal(
898
+ sc.beta,
899
+ beta,
900
+ np.array(bad_points),
901
+ dps=400,
902
+ ignore_inf_sign=True,
903
+ atol=1e-11,
904
+ )
905
+
906
+ def test_betainc(self):
907
+ assert_mpmath_equal(
908
+ sc.betainc,
909
+ time_limited()(
910
+ exception_to_nan(
911
+ lambda a, b, x: mpmath.betainc(a, b, 0, x, regularized=True)
912
+ )
913
+ ),
914
+ [Arg(), Arg(), Arg()],
915
+ )
916
+
917
+ def test_betaincc(self):
918
+ assert_mpmath_equal(
919
+ sc.betaincc,
920
+ time_limited()(
921
+ exception_to_nan(
922
+ lambda a, b, x: mpmath.betainc(a, b, x, 1, regularized=True)
923
+ )
924
+ ),
925
+ [Arg(), Arg(), Arg()],
926
+ dps=400,
927
+ )
928
+
929
+ def test_binom(self):
930
+ bad_points = []
931
+
932
+ def binomial(n, k, nonzero=False):
933
+ if abs(k) > 1e8*(abs(n) + 1):
934
+ # The binomial is rapidly oscillating in this region,
935
+ # and the function is numerically ill-defined. Don't
936
+ # compare values here.
937
+ return np.nan
938
+ if n < k and abs(float(n-k) - np.round(float(n-k))) < 1e-15:
939
+ # close to a zero of the function: mpmath and scipy
940
+ # will not round here the same, so the test needs to be
941
+ # run with an absolute tolerance
942
+ if nonzero:
943
+ bad_points.append((float(n), float(k)))
944
+ return np.nan
945
+ return mpmath.binomial(n, k)
946
+
947
+ assert_mpmath_equal(
948
+ sc.binom,
949
+ lambda n, k: binomial(n, k, nonzero=True),
950
+ [Arg(), Arg()],
951
+ dps=400,
952
+ )
953
+
954
+ assert_mpmath_equal(
955
+ sc.binom,
956
+ binomial,
957
+ np.array(bad_points),
958
+ dps=400,
959
+ atol=1e-14,
960
+ )
961
+
962
+ def test_chebyt_int(self):
963
+ assert_mpmath_equal(
964
+ lambda n, x: sc.eval_chebyt(int(n), x),
965
+ exception_to_nan(lambda n, x: mpmath.chebyt(n, x, **HYPERKW)),
966
+ [IntArg(), Arg()],
967
+ dps=50,
968
+ )
969
+
970
+ @pytest.mark.xfail(run=False, reason="some cases in hyp2f1 not fully accurate")
971
+ def test_chebyt(self):
972
+ assert_mpmath_equal(
973
+ sc.eval_chebyt,
974
+ lambda n, x: time_limited()(
975
+ exception_to_nan(mpmath.chebyt)
976
+ )(n, x, **HYPERKW),
977
+ [Arg(-101, 101), Arg()],
978
+ n=10000,
979
+ )
980
+
981
+ def test_chebyu_int(self):
982
+ assert_mpmath_equal(
983
+ lambda n, x: sc.eval_chebyu(int(n), x),
984
+ exception_to_nan(lambda n, x: mpmath.chebyu(n, x, **HYPERKW)),
985
+ [IntArg(), Arg()],
986
+ dps=50,
987
+ )
988
+
989
+ @pytest.mark.xfail(run=False, reason="some cases in hyp2f1 not fully accurate")
990
+ def test_chebyu(self):
991
+ assert_mpmath_equal(
992
+ sc.eval_chebyu,
993
+ lambda n, x: time_limited()(
994
+ exception_to_nan(mpmath.chebyu)
995
+ )(n, x, **HYPERKW),
996
+ [Arg(-101, 101), Arg()],
997
+ )
998
+
999
+ def test_chi(self):
1000
+ def chi(x):
1001
+ return sc.shichi(x)[1]
1002
+ assert_mpmath_equal(chi, mpmath.chi, [Arg()])
1003
+ # check asymptotic series cross-over
1004
+ assert_mpmath_equal(chi, mpmath.chi, [FixedArg([88 - 1e-9, 88, 88 + 1e-9])])
1005
+
1006
+ def test_chi_complex(self):
1007
+ def chi(z):
1008
+ return sc.shichi(z)[1]
1009
+ # chi oscillates as Im[z] -> +- inf, so limit range
1010
+ assert_mpmath_equal(
1011
+ chi,
1012
+ mpmath.chi,
1013
+ [ComplexArg(complex(-np.inf, -1e8), complex(np.inf, 1e8))],
1014
+ rtol=1e-12,
1015
+ )
1016
+
1017
+ def test_ci(self):
1018
+ def ci(x):
1019
+ return sc.sici(x)[1]
1020
+ # oscillating function: limit range
1021
+ assert_mpmath_equal(ci, mpmath.ci, [Arg(-1e8, 1e8)])
1022
+
1023
+ def test_ci_complex(self):
1024
+ def ci(z):
1025
+ return sc.sici(z)[1]
1026
+ # ci oscillates as Re[z] -> +- inf, so limit range
1027
+ assert_mpmath_equal(
1028
+ ci,
1029
+ mpmath.ci,
1030
+ [ComplexArg(complex(-1e8, -np.inf), complex(1e8, np.inf))],
1031
+ rtol=1e-8,
1032
+ )
1033
+
1034
+ def test_cospi(self):
1035
+ eps = np.finfo(float).eps
1036
+ assert_mpmath_equal(_cospi, mpmath.cospi, [Arg()], nan_ok=False, rtol=2*eps)
1037
+
1038
+ def test_cospi_complex(self):
1039
+ assert_mpmath_equal(
1040
+ _cospi,
1041
+ mpmath.cospi,
1042
+ [ComplexArg()],
1043
+ nan_ok=False,
1044
+ rtol=1e-13,
1045
+ )
1046
+
1047
+ def test_digamma(self):
1048
+ assert_mpmath_equal(
1049
+ sc.digamma,
1050
+ exception_to_nan(mpmath.digamma),
1051
+ [Arg()],
1052
+ rtol=1e-12,
1053
+ dps=50,
1054
+ )
1055
+
1056
+ def test_digamma_complex(self):
1057
+ # Test on a cut plane because mpmath will hang. See
1058
+ # test_digamma_negreal for tests on the negative real axis.
1059
+ def param_filter(z):
1060
+ return np.where((z.real < 0) & (np.abs(z.imag) < 1.12), False, True)
1061
+
1062
+ assert_mpmath_equal(
1063
+ sc.digamma,
1064
+ exception_to_nan(mpmath.digamma),
1065
+ [ComplexArg()],
1066
+ rtol=1e-13,
1067
+ dps=40,
1068
+ param_filter=param_filter
1069
+ )
1070
+
1071
+ def test_e1(self):
1072
+ assert_mpmath_equal(
1073
+ sc.exp1,
1074
+ mpmath.e1,
1075
+ [Arg()],
1076
+ rtol=1e-14,
1077
+ )
1078
+
1079
+ def test_e1_complex(self):
1080
+ # E_1 oscillates as Im[z] -> +- inf, so limit range
1081
+ assert_mpmath_equal(
1082
+ sc.exp1,
1083
+ mpmath.e1,
1084
+ [ComplexArg(complex(-np.inf, -1e8), complex(np.inf, 1e8))],
1085
+ rtol=1e-11,
1086
+ )
1087
+
1088
+ # Check cross-over region
1089
+ assert_mpmath_equal(
1090
+ sc.exp1,
1091
+ mpmath.e1,
1092
+ (np.linspace(-50, 50, 171)[:, None]
1093
+ + np.r_[0, np.logspace(-3, 2, 61), -np.logspace(-3, 2, 11)]*1j).ravel(),
1094
+ rtol=1e-11,
1095
+ )
1096
+ assert_mpmath_equal(
1097
+ sc.exp1,
1098
+ mpmath.e1,
1099
+ (np.linspace(-50, -35, 10000) + 0j),
1100
+ rtol=1e-11,
1101
+ )
1102
+
1103
+ def test_exprel(self):
1104
+ assert_mpmath_equal(
1105
+ sc.exprel,
1106
+ lambda x: mpmath.expm1(x)/x if x != 0 else mpmath.mpf('1.0'),
1107
+ [Arg(a=-np.log(np.finfo(np.float64).max),
1108
+ b=np.log(np.finfo(np.float64).max))],
1109
+ )
1110
+ assert_mpmath_equal(
1111
+ sc.exprel,
1112
+ lambda x: mpmath.expm1(x)/x if x != 0 else mpmath.mpf('1.0'),
1113
+ np.array([1e-12, 1e-24, 0, 1e12, 1e24, np.inf]),
1114
+ rtol=1e-11,
1115
+ )
1116
+ assert_(np.isinf(sc.exprel(np.inf)))
1117
+ assert_(sc.exprel(-np.inf) == 0)
1118
+
1119
+ def test_expm1_complex(self):
1120
+ # Oscillates as a function of Im[z], so limit range to avoid loss of precision
1121
+ assert_mpmath_equal(
1122
+ sc.expm1,
1123
+ mpmath.expm1,
1124
+ [ComplexArg(complex(-np.inf, -1e7), complex(np.inf, 1e7))],
1125
+ )
1126
+
1127
+ def test_log1p_complex(self):
1128
+ assert_mpmath_equal(
1129
+ sc.log1p,
1130
+ lambda x: mpmath.log(x+1),
1131
+ [ComplexArg()],
1132
+ dps=60,
1133
+ )
1134
+
1135
+ def test_log1pmx(self):
1136
+ assert_mpmath_equal(
1137
+ _log1pmx,
1138
+ lambda x: mpmath.log(x + 1) - x,
1139
+ [Arg()],
1140
+ dps=60,
1141
+ rtol=1e-14,
1142
+ )
1143
+
1144
+ def test_ei(self):
1145
+ assert_mpmath_equal(sc.expi, mpmath.ei, [Arg()], rtol=1e-11)
1146
+
1147
+ def test_ei_complex(self):
1148
+ # Ei oscillates as Im[z] -> +- inf, so limit range
1149
+ assert_mpmath_equal(
1150
+ sc.expi,
1151
+ mpmath.ei,
1152
+ [ComplexArg(complex(-np.inf, -1e8), complex(np.inf, 1e8))],
1153
+ rtol=1e-9,
1154
+ )
1155
+
1156
+ def test_ellipe(self):
1157
+ assert_mpmath_equal(sc.ellipe, mpmath.ellipe, [Arg(b=1.0)])
1158
+
1159
+ def test_ellipeinc(self):
1160
+ assert_mpmath_equal(sc.ellipeinc, mpmath.ellipe, [Arg(-1e3, 1e3), Arg(b=1.0)])
1161
+
1162
+ def test_ellipeinc_largephi(self):
1163
+ assert_mpmath_equal(sc.ellipeinc, mpmath.ellipe, [Arg(), Arg()])
1164
+
1165
+ def test_ellipf(self):
1166
+ assert_mpmath_equal(sc.ellipkinc, mpmath.ellipf, [Arg(-1e3, 1e3), Arg()])
1167
+
1168
+ def test_ellipf_largephi(self):
1169
+ assert_mpmath_equal(sc.ellipkinc, mpmath.ellipf, [Arg(), Arg()])
1170
+
1171
+ def test_ellipk(self):
1172
+ assert_mpmath_equal(sc.ellipk, mpmath.ellipk, [Arg(b=1.0)])
1173
+ assert_mpmath_equal(
1174
+ sc.ellipkm1,
1175
+ lambda m: mpmath.ellipk(1 - m),
1176
+ [Arg(a=0.0)],
1177
+ dps=400,
1178
+ )
1179
+
1180
+ def test_ellipkinc(self):
1181
+ def ellipkinc(phi, m):
1182
+ return mpmath.ellippi(0, phi, m)
1183
+ assert_mpmath_equal(
1184
+ sc.ellipkinc,
1185
+ ellipkinc,
1186
+ [Arg(-1e3, 1e3), Arg(b=1.0)],
1187
+ ignore_inf_sign=True,
1188
+ )
1189
+
1190
+ def test_ellipkinc_largephi(self):
1191
+ def ellipkinc(phi, m):
1192
+ return mpmath.ellippi(0, phi, m)
1193
+ assert_mpmath_equal(
1194
+ sc.ellipkinc,
1195
+ ellipkinc,
1196
+ [Arg(), Arg(b=1.0)],
1197
+ ignore_inf_sign=True,
1198
+ )
1199
+
1200
+ def test_ellipfun_sn(self):
1201
+ def sn(u, m):
1202
+ # mpmath doesn't get the zero at u = 0--fix that
1203
+ if u == 0:
1204
+ return 0
1205
+ else:
1206
+ return mpmath.ellipfun("sn", u=u, m=m)
1207
+
1208
+ # Oscillating function --- limit range of first argument; the
1209
+ # loss of precision there is an expected numerical feature
1210
+ # rather than an actual bug
1211
+ assert_mpmath_equal(
1212
+ lambda u, m: sc.ellipj(u, m)[0],
1213
+ sn,
1214
+ [Arg(-1e6, 1e6), Arg(a=0, b=1)],
1215
+ rtol=1e-8,
1216
+ )
1217
+
1218
+ def test_ellipfun_cn(self):
1219
+ # see comment in ellipfun_sn
1220
+ assert_mpmath_equal(
1221
+ lambda u, m: sc.ellipj(u, m)[1],
1222
+ lambda u, m: mpmath.ellipfun("cn", u=u, m=m),
1223
+ [Arg(-1e6, 1e6), Arg(a=0, b=1)],
1224
+ rtol=1e-8,
1225
+ )
1226
+
1227
+ def test_ellipfun_dn(self):
1228
+ # see comment in ellipfun_sn
1229
+ assert_mpmath_equal(
1230
+ lambda u, m: sc.ellipj(u, m)[2],
1231
+ lambda u, m: mpmath.ellipfun("dn", u=u, m=m),
1232
+ [Arg(-1e6, 1e6), Arg(a=0, b=1)],
1233
+ rtol=1e-8,
1234
+ )
1235
+
1236
+ def test_erf(self):
1237
+ assert_mpmath_equal(sc.erf, lambda z: mpmath.erf(z), [Arg()])
1238
+
1239
+ def test_erf_complex(self):
1240
+ assert_mpmath_equal(sc.erf, lambda z: mpmath.erf(z), [ComplexArg()], n=200)
1241
+
1242
+ def test_erfc(self):
1243
+ assert_mpmath_equal(
1244
+ sc.erfc,
1245
+ exception_to_nan(lambda z: mpmath.erfc(z)),
1246
+ [Arg()],
1247
+ rtol=1e-13,
1248
+ )
1249
+
1250
+ def test_erfc_complex(self):
1251
+ assert_mpmath_equal(
1252
+ sc.erfc,
1253
+ exception_to_nan(lambda z: mpmath.erfc(z)),
1254
+ [ComplexArg()],
1255
+ n=200,
1256
+ )
1257
+
1258
+ def test_erfi(self):
1259
+ assert_mpmath_equal(sc.erfi, mpmath.erfi, [Arg()], n=200)
1260
+
1261
+ def test_erfi_complex(self):
1262
+ assert_mpmath_equal(sc.erfi, mpmath.erfi, [ComplexArg()], n=200)
1263
+
1264
+ def test_ndtr(self):
1265
+ assert_mpmath_equal(
1266
+ sc.ndtr,
1267
+ exception_to_nan(lambda z: mpmath.ncdf(z)),
1268
+ [Arg()],
1269
+ n=200,
1270
+ )
1271
+
1272
+ def test_ndtr_complex(self):
1273
+ assert_mpmath_equal(
1274
+ sc.ndtr,
1275
+ lambda z: mpmath.erfc(-z/np.sqrt(2.))/2.,
1276
+ [ComplexArg(a=complex(-10000, -10000), b=complex(10000, 10000))],
1277
+ n=400,
1278
+ )
1279
+
1280
+ def test_log_ndtr(self):
1281
+ assert_mpmath_equal(
1282
+ sc.log_ndtr,
1283
+ exception_to_nan(lambda z: mpmath.log(mpmath.ncdf(z))),
1284
+ [Arg()], n=600, dps=300, rtol=1e-13,
1285
+ )
1286
+
1287
+ def test_log_ndtr_complex(self):
1288
+ assert_mpmath_equal(
1289
+ sc.log_ndtr,
1290
+ exception_to_nan(lambda z: mpmath.log(mpmath.erfc(-z/np.sqrt(2.))/2.)),
1291
+ [ComplexArg(a=complex(-10000, -100), b=complex(10000, 100))],
1292
+ n=200, dps=300,
1293
+ )
1294
+
1295
+ def test_eulernum(self):
1296
+ assert_mpmath_equal(
1297
+ lambda n: sc.euler(n)[-1],
1298
+ mpmath.eulernum,
1299
+ [IntArg(1, 10000)],
1300
+ n=10000,
1301
+ )
1302
+
1303
+ def test_expint(self):
1304
+ assert_mpmath_equal(
1305
+ sc.expn,
1306
+ mpmath.expint,
1307
+ [IntArg(0, 200), Arg(0, np.inf)],
1308
+ rtol=1e-13,
1309
+ dps=160,
1310
+ )
1311
+
1312
+ def test_fresnels(self):
1313
+ def fresnels(x):
1314
+ return sc.fresnel(x)[0]
1315
+ assert_mpmath_equal(fresnels, mpmath.fresnels, [Arg()])
1316
+
1317
+ def test_fresnelc(self):
1318
+ def fresnelc(x):
1319
+ return sc.fresnel(x)[1]
1320
+ assert_mpmath_equal(fresnelc, mpmath.fresnelc, [Arg()])
1321
+
1322
+ def test_gamma(self):
1323
+ assert_mpmath_equal(sc.gamma, exception_to_nan(mpmath.gamma), [Arg()])
1324
+
1325
+ def test_gamma_complex(self):
1326
+ assert_mpmath_equal(
1327
+ sc.gamma,
1328
+ exception_to_nan(mpmath.gamma),
1329
+ [ComplexArg()],
1330
+ rtol=5e-13,
1331
+ )
1332
+
1333
+ def test_gammainc(self):
1334
+ # Larger arguments are tested in test_data.py:test_local
1335
+ assert_mpmath_equal(
1336
+ sc.gammainc,
1337
+ lambda z, b: mpmath.gammainc(z, b=b, regularized=True),
1338
+ [Arg(0, 1e4, inclusive_a=False), Arg(0, 1e4)],
1339
+ nan_ok=False,
1340
+ rtol=1e-11,
1341
+ )
1342
+
1343
+ def test_gammaincc(self):
1344
+ # Larger arguments are tested in test_data.py:test_local
1345
+ assert_mpmath_equal(
1346
+ sc.gammaincc,
1347
+ lambda z, a: mpmath.gammainc(z, a=a, regularized=True),
1348
+ [Arg(0, 1e4, inclusive_a=False), Arg(0, 1e4)],
1349
+ nan_ok=False,
1350
+ rtol=1e-11,
1351
+ )
1352
+
1353
+ def test_gammaln(self):
1354
+ # The real part of loggamma is log(|gamma(z)|).
1355
+ def f(z):
1356
+ return mpmath.loggamma(z).real
1357
+
1358
+ assert_mpmath_equal(sc.gammaln, exception_to_nan(f), [Arg()])
1359
+
1360
+ @pytest.mark.xfail(run=False)
1361
+ def test_gegenbauer(self):
1362
+ assert_mpmath_equal(
1363
+ sc.eval_gegenbauer,
1364
+ exception_to_nan(mpmath.gegenbauer),
1365
+ [Arg(-1e3, 1e3), Arg(), Arg()],
1366
+ )
1367
+
1368
+ def test_gegenbauer_int(self):
1369
+ # Redefine functions to deal with numerical + mpmath issues
1370
+ def gegenbauer(n, a, x):
1371
+ # Avoid overflow at large `a` (mpmath would need an even larger
1372
+ # dps to handle this correctly, so just skip this region)
1373
+ if abs(a) > 1e100:
1374
+ return np.nan
1375
+
1376
+ # Deal with n=0, n=1 correctly; mpmath 0.17 doesn't do these
1377
+ # always correctly
1378
+ if n == 0:
1379
+ r = 0.0 if a == 0.0 else 1.0
1380
+ elif n == 1:
1381
+ r = 2*a*x
1382
+ else:
1383
+ r = mpmath.gegenbauer(n, a, x)
1384
+
1385
+ # Mpmath 0.17 gives wrong results (spurious zero) in some cases, so
1386
+ # compute the value by perturbing the result
1387
+ if float(r) == 0 and a < -1 and float(a) == int(float(a)):
1388
+ r = mpmath.gegenbauer(n, a + mpmath.mpf('1e-50'), x)
1389
+ if abs(r) < mpmath.mpf('1e-50'):
1390
+ r = mpmath.mpf('0.0')
1391
+
1392
+ # Differing overflow thresholds in scipy vs. mpmath
1393
+ if abs(r) > 1e270:
1394
+ return np.inf
1395
+ return r
1396
+
1397
+ def sc_gegenbauer(n, a, x):
1398
+ r = sc.eval_gegenbauer(int(n), a, x)
1399
+ # Differing overflow thresholds in scipy vs. mpmath
1400
+ if abs(r) > 1e270:
1401
+ return np.inf
1402
+ return r
1403
+ assert_mpmath_equal(
1404
+ sc_gegenbauer,
1405
+ exception_to_nan(gegenbauer),
1406
+ [IntArg(0, 100), Arg(-1e9, 1e9), Arg()],
1407
+ dps=100, ignore_inf_sign=True, rtol=1e-6,
1408
+ )
1409
+
1410
+ # Check the small-x expansion
1411
+ assert_mpmath_equal(
1412
+ sc_gegenbauer,
1413
+ exception_to_nan(gegenbauer),
1414
+ [IntArg(0, 100), Arg(), FixedArg(np.logspace(-30, -4, 30))],
1415
+ dps=100, ignore_inf_sign=True,
1416
+ )
1417
+
1418
+ @pytest.mark.xfail(run=False)
1419
+ def test_gegenbauer_complex(self):
1420
+ assert_mpmath_equal(
1421
+ lambda n, a, x: sc.eval_gegenbauer(int(n), a.real, x),
1422
+ exception_to_nan(mpmath.gegenbauer),
1423
+ [IntArg(0, 100), Arg(), ComplexArg()],
1424
+ )
1425
+
1426
+ @nonfunctional_tooslow
1427
+ def test_gegenbauer_complex_general(self):
1428
+ assert_mpmath_equal(
1429
+ lambda n, a, x: sc.eval_gegenbauer(n.real, a.real, x),
1430
+ exception_to_nan(mpmath.gegenbauer),
1431
+ [Arg(-1e3, 1e3), Arg(), ComplexArg()],
1432
+ )
1433
+
1434
+ def test_hankel1(self):
1435
+ assert_mpmath_equal(
1436
+ sc.hankel1,
1437
+ exception_to_nan(lambda v, x: mpmath.hankel1(v, x, **HYPERKW)),
1438
+ [Arg(-1e20, 1e20), Arg()],
1439
+ )
1440
+
1441
+ def test_hankel2(self):
1442
+ assert_mpmath_equal(
1443
+ sc.hankel2,
1444
+ exception_to_nan(lambda v, x: mpmath.hankel2(v, x, **HYPERKW)),
1445
+ [Arg(-1e20, 1e20), Arg()],
1446
+ )
1447
+
1448
+ @pytest.mark.xfail(run=False, reason="issues at intermediately large orders")
1449
+ def test_hermite(self):
1450
+ assert_mpmath_equal(
1451
+ lambda n, x: sc.eval_hermite(int(n), x),
1452
+ exception_to_nan(mpmath.hermite),
1453
+ [IntArg(0, 10000), Arg()],
1454
+ )
1455
+
1456
+ # hurwitz: same as zeta
1457
+
1458
+ def test_hyp0f1(self):
1459
+ # mpmath reports no convergence unless maxterms is large enough
1460
+ KW = dict(maxprec=400, maxterms=1500)
1461
+ # n=500 (non-xslow default) fails for one bad point
1462
+ assert_mpmath_equal(
1463
+ sc.hyp0f1,
1464
+ lambda a, x: mpmath.hyp0f1(a, x, **KW),
1465
+ [Arg(-1e7, 1e7), Arg(0, 1e5)],
1466
+ n=5000,
1467
+ )
1468
+ # NB: The range of the second parameter ("z") is limited from below
1469
+ # because of an overflow in the intermediate calculations. The way
1470
+ # for fix it is to implement an asymptotic expansion for Bessel J
1471
+ # (similar to what is implemented for Bessel I here).
1472
+
1473
+ def test_hyp0f1_complex(self):
1474
+ assert_mpmath_equal(
1475
+ lambda a, z: sc.hyp0f1(a.real, z),
1476
+ exception_to_nan(lambda a, x: mpmath.hyp0f1(a, x, **HYPERKW)),
1477
+ [Arg(-10, 10), ComplexArg(complex(-120, -120), complex(120, 120))],
1478
+ )
1479
+ # NB: The range of the first parameter ("v") are limited by an overflow
1480
+ # in the intermediate calculations. Can be fixed by implementing an
1481
+ # asymptotic expansion for Bessel functions for large order.
1482
+
1483
+ def test_hyp1f1(self):
1484
+ def mpmath_hyp1f1(a, b, x):
1485
+ try:
1486
+ return mpmath.hyp1f1(a, b, x)
1487
+ except ZeroDivisionError:
1488
+ return np.inf
1489
+
1490
+ assert_mpmath_equal(
1491
+ sc.hyp1f1,
1492
+ mpmath_hyp1f1,
1493
+ [Arg(-50, 50), Arg(1, 50, inclusive_a=False), Arg(-50, 50)],
1494
+ n=500,
1495
+ nan_ok=False,
1496
+ )
1497
+
1498
+ @pytest.mark.xfail(run=False)
1499
+ def test_hyp1f1_complex(self):
1500
+ assert_mpmath_equal(
1501
+ inf_to_nan(lambda a, b, x: sc.hyp1f1(a.real, b.real, x)),
1502
+ exception_to_nan(lambda a, b, x: mpmath.hyp1f1(a, b, x, **HYPERKW)),
1503
+ [Arg(-1e3, 1e3), Arg(-1e3, 1e3), ComplexArg()],
1504
+ n=2000,
1505
+ )
1506
+
1507
+ @nonfunctional_tooslow
1508
+ def test_hyp2f1_complex(self):
1509
+ # SciPy's hyp2f1 seems to have performance and accuracy problems
1510
+ assert_mpmath_equal(
1511
+ lambda a, b, c, x: sc.hyp2f1(a.real, b.real, c.real, x),
1512
+ exception_to_nan(lambda a, b, c, x: mpmath.hyp2f1(a, b, c, x, **HYPERKW)),
1513
+ [Arg(-1e2, 1e2), Arg(-1e2, 1e2), Arg(-1e2, 1e2), ComplexArg()],
1514
+ n=10,
1515
+ )
1516
+
1517
+ @pytest.mark.xfail(run=False)
1518
+ def test_hyperu(self):
1519
+ assert_mpmath_equal(
1520
+ sc.hyperu,
1521
+ exception_to_nan(lambda a, b, x: mpmath.hyperu(a, b, x, **HYPERKW)),
1522
+ [Arg(), Arg(), Arg()],
1523
+ )
1524
+
1525
+ @pytest.mark.xfail_on_32bit("mpmath issue gh-342: "
1526
+ "unsupported operand mpz, long for pow")
1527
+ def test_igam_fac(self):
1528
+ def mp_igam_fac(a, x):
1529
+ return mpmath.power(x, a)*mpmath.exp(-x)/mpmath.gamma(a)
1530
+
1531
+ assert_mpmath_equal(
1532
+ _igam_fac,
1533
+ mp_igam_fac,
1534
+ [Arg(0, 1e14, inclusive_a=False), Arg(0, 1e14)],
1535
+ rtol=1e-10,
1536
+ dps=29,
1537
+ )
1538
+
1539
+ def test_j0(self):
1540
+ # The Bessel function at large arguments is j0(x) ~ cos(x + phi)/sqrt(x)
1541
+ # and at large arguments the phase of the cosine loses precision.
1542
+ #
1543
+ # This is numerically expected behavior, so we compare only up to
1544
+ # 1e8 = 1e15 * 1e-7
1545
+ assert_mpmath_equal(sc.j0, mpmath.j0, [Arg(-1e3, 1e3)])
1546
+ assert_mpmath_equal(sc.j0, mpmath.j0, [Arg(-1e8, 1e8)], rtol=1e-5)
1547
+
1548
+ def test_j1(self):
1549
+ # See comment in test_j0
1550
+ assert_mpmath_equal(sc.j1, mpmath.j1, [Arg(-1e3, 1e3)])
1551
+ assert_mpmath_equal(sc.j1, mpmath.j1, [Arg(-1e8, 1e8)], rtol=1e-5)
1552
+
1553
+ @pytest.mark.xfail(run=False)
1554
+ def test_jacobi(self):
1555
+ assert_mpmath_equal(
1556
+ sc.eval_jacobi,
1557
+ exception_to_nan(lambda a, b, c, x: mpmath.jacobi(a, b, c, x, **HYPERKW)),
1558
+ [Arg(), Arg(), Arg(), Arg()],
1559
+ )
1560
+ assert_mpmath_equal(
1561
+ lambda n, b, c, x: sc.eval_jacobi(int(n), b, c, x),
1562
+ exception_to_nan(lambda a, b, c, x: mpmath.jacobi(a, b, c, x, **HYPERKW)),
1563
+ [IntArg(), Arg(), Arg(), Arg()],
1564
+ )
1565
+
1566
+ def test_jacobi_int(self):
1567
+ # Redefine functions to deal with numerical + mpmath issues
1568
+ def jacobi(n, a, b, x):
1569
+ # Mpmath does not handle n=0 case always correctly
1570
+ if n == 0:
1571
+ return 1.0
1572
+ return mpmath.jacobi(n, a, b, x)
1573
+ assert_mpmath_equal(
1574
+ lambda n, a, b, x: sc.eval_jacobi(int(n), a, b, x),
1575
+ lambda n, a, b, x: exception_to_nan(jacobi)(n, a, b, x, **HYPERKW),
1576
+ [IntArg(), Arg(), Arg(), Arg()],
1577
+ n=4095,
1578
+ dps=50,
1579
+ )
1580
+
1581
+ def test_kei(self):
1582
+ def kei(x):
1583
+ if x == 0:
1584
+ # work around mpmath issue at x=0
1585
+ return -pi/4
1586
+ return exception_to_nan(mpmath.kei)(0, x, **HYPERKW)
1587
+ assert_mpmath_equal(sc.kei, kei, [Arg(-1e30, 1e30)], n=1000)
1588
+
1589
+ def test_ker(self):
1590
+ assert_mpmath_equal(
1591
+ sc.ker,
1592
+ exception_to_nan(lambda x: mpmath.ker(0, x, **HYPERKW)),
1593
+ [Arg(-1e30, 1e30)],
1594
+ n=1000,
1595
+ )
1596
+
1597
+ @nonfunctional_tooslow
1598
+ def test_laguerre(self):
1599
+ assert_mpmath_equal(
1600
+ trace_args(sc.eval_laguerre),
1601
+ lambda n, x: exception_to_nan(mpmath.laguerre)(n, x, **HYPERKW),
1602
+ [Arg(), Arg()],
1603
+ )
1604
+
1605
+ def test_laguerre_int(self):
1606
+ assert_mpmath_equal(
1607
+ lambda n, x: sc.eval_laguerre(int(n), x),
1608
+ lambda n, x: exception_to_nan(mpmath.laguerre)(n, x, **HYPERKW),
1609
+ [IntArg(), Arg()],
1610
+ n=20000,
1611
+ )
1612
+
1613
+ @pytest.mark.xfail_on_32bit("see gh-3551 for bad points")
1614
+ def test_lambertw_real(self):
1615
+ assert_mpmath_equal(
1616
+ lambda x, k: sc.lambertw(x, int(k.real)),
1617
+ lambda x, k: mpmath.lambertw(x, int(k.real)),
1618
+ [ComplexArg(-np.inf, np.inf), IntArg(0, 10)],
1619
+ rtol=1e-13, nan_ok=False,
1620
+ )
1621
+
1622
+ def test_lanczos_sum_expg_scaled(self):
1623
+ maxgamma = 171.624376956302725
1624
+ e = np.exp(1)
1625
+ g = 6.024680040776729583740234375
1626
+
1627
+ def gamma(x):
1628
+ with np.errstate(over='ignore'):
1629
+ fac = ((x + g - 0.5)/e)**(x - 0.5)
1630
+ if fac != np.inf:
1631
+ res = fac*_lanczos_sum_expg_scaled(x)
1632
+ else:
1633
+ fac = ((x + g - 0.5)/e)**(0.5*(x - 0.5))
1634
+ res = fac*_lanczos_sum_expg_scaled(x)
1635
+ res *= fac
1636
+ return res
1637
+
1638
+ assert_mpmath_equal(
1639
+ gamma,
1640
+ mpmath.gamma,
1641
+ [Arg(0, maxgamma, inclusive_a=False)],
1642
+ rtol=1e-13,
1643
+ )
1644
+
1645
+ @nonfunctional_tooslow
1646
+ def test_legendre(self):
1647
+ assert_mpmath_equal(sc.eval_legendre, mpmath.legendre, [Arg(), Arg()])
1648
+
1649
+ def test_legendre_int(self):
1650
+ assert_mpmath_equal(
1651
+ lambda n, x: sc.eval_legendre(int(n), x),
1652
+ lambda n, x: exception_to_nan(mpmath.legendre)(n, x, **HYPERKW),
1653
+ [IntArg(), Arg()],
1654
+ n=20000,
1655
+ )
1656
+
1657
+ # Check the small-x expansion
1658
+ assert_mpmath_equal(
1659
+ lambda n, x: sc.eval_legendre(int(n), x),
1660
+ lambda n, x: exception_to_nan(mpmath.legendre)(n, x, **HYPERKW),
1661
+ [IntArg(), FixedArg(np.logspace(-30, -4, 20))],
1662
+ )
1663
+
1664
+ @pytest.mark.xfail(run=False, reason="apparently picks wrong function at |z| > 1")
1665
+ def test_legenq(self):
1666
+ def lqnm(n, m, z):
1667
+ return sc.lqmn(m, n, z)[0][-1,-1]
1668
+
1669
+ def legenq(n, m, z):
1670
+ if abs(z) < 1e-15:
1671
+ # mpmath has bad performance here
1672
+ return np.nan
1673
+ return exception_to_nan(mpmath.legenq)(n, m, z, type=2)
1674
+
1675
+ assert_mpmath_equal(
1676
+ lqnm,
1677
+ legenq,
1678
+ [IntArg(0, 100), IntArg(0, 100), Arg()],
1679
+ )
1680
+
1681
+ @nonfunctional_tooslow
1682
+ def test_legenq_complex(self):
1683
+ def lqnm(n, m, z):
1684
+ return sc.lqmn(int(m.real), int(n.real), z)[0][-1,-1]
1685
+
1686
+ def legenq(n, m, z):
1687
+ if abs(z) < 1e-15:
1688
+ # mpmath has bad performance here
1689
+ return np.nan
1690
+ return exception_to_nan(mpmath.legenq)(int(n.real), int(m.real), z, type=2)
1691
+
1692
+ assert_mpmath_equal(
1693
+ lqnm,
1694
+ legenq,
1695
+ [IntArg(0, 100), IntArg(0, 100), ComplexArg()],
1696
+ n=100,
1697
+ )
1698
+
1699
+ def test_lgam1p(self):
1700
+ def param_filter(x):
1701
+ # Filter the poles
1702
+ return np.where((np.floor(x) == x) & (x <= 0), False, True)
1703
+
1704
+ def mp_lgam1p(z):
1705
+ # The real part of loggamma is log(|gamma(z)|)
1706
+ return mpmath.loggamma(1 + z).real
1707
+
1708
+ assert_mpmath_equal(
1709
+ _lgam1p,
1710
+ mp_lgam1p,
1711
+ [Arg()],
1712
+ rtol=1e-13,
1713
+ dps=100,
1714
+ param_filter=param_filter,
1715
+ )
1716
+
1717
+ def test_loggamma(self):
1718
+ def mpmath_loggamma(z):
1719
+ try:
1720
+ res = mpmath.loggamma(z)
1721
+ except ValueError:
1722
+ res = complex(np.nan, np.nan)
1723
+ return res
1724
+
1725
+ assert_mpmath_equal(
1726
+ sc.loggamma,
1727
+ mpmath_loggamma,
1728
+ [ComplexArg()],
1729
+ nan_ok=False,
1730
+ distinguish_nan_and_inf=False,
1731
+ rtol=5e-14,
1732
+ )
1733
+
1734
+ @pytest.mark.xfail(run=False)
1735
+ def test_pcfd(self):
1736
+ def pcfd(v, x):
1737
+ return sc.pbdv(v, x)[0]
1738
+ assert_mpmath_equal(
1739
+ pcfd,
1740
+ exception_to_nan(lambda v, x: mpmath.pcfd(v, x, **HYPERKW)),
1741
+ [Arg(), Arg()],
1742
+ )
1743
+
1744
+ @pytest.mark.xfail(run=False, reason="it's not the same as the mpmath function --- "
1745
+ "maybe different definition?")
1746
+ def test_pcfv(self):
1747
+ def pcfv(v, x):
1748
+ return sc.pbvv(v, x)[0]
1749
+ assert_mpmath_equal(
1750
+ pcfv,
1751
+ lambda v, x: time_limited()(exception_to_nan(mpmath.pcfv))(v, x, **HYPERKW),
1752
+ [Arg(), Arg()],
1753
+ n=1000,
1754
+ )
1755
+
1756
+ def test_pcfw(self):
1757
+ def pcfw(a, x):
1758
+ return sc.pbwa(a, x)[0]
1759
+
1760
+ def dpcfw(a, x):
1761
+ return sc.pbwa(a, x)[1]
1762
+
1763
+ def mpmath_dpcfw(a, x):
1764
+ return mpmath.diff(mpmath.pcfw, (a, x), (0, 1))
1765
+
1766
+ # The Zhang and Jin implementation only uses Taylor series and
1767
+ # is thus accurate in only a very small range.
1768
+ assert_mpmath_equal(
1769
+ pcfw,
1770
+ mpmath.pcfw,
1771
+ [Arg(-5, 5), Arg(-5, 5)],
1772
+ rtol=2e-8,
1773
+ n=100,
1774
+ )
1775
+
1776
+ assert_mpmath_equal(
1777
+ dpcfw,
1778
+ mpmath_dpcfw,
1779
+ [Arg(-5, 5), Arg(-5, 5)],
1780
+ rtol=2e-9,
1781
+ n=100,
1782
+ )
1783
+
1784
+ @pytest.mark.xfail(run=False,
1785
+ reason="issues at large arguments (atol OK, rtol not) "
1786
+ "and <eps-close to z=0")
1787
+ def test_polygamma(self):
1788
+ assert_mpmath_equal(
1789
+ sc.polygamma,
1790
+ time_limited()(exception_to_nan(mpmath.polygamma)),
1791
+ [IntArg(0, 1000), Arg()],
1792
+ )
1793
+
1794
+ def test_rgamma(self):
1795
+ assert_mpmath_equal(
1796
+ sc.rgamma,
1797
+ mpmath.rgamma,
1798
+ [Arg(-8000, np.inf)],
1799
+ n=5000,
1800
+ nan_ok=False,
1801
+ ignore_inf_sign=True,
1802
+ )
1803
+
1804
+ def test_rgamma_complex(self):
1805
+ assert_mpmath_equal(
1806
+ sc.rgamma,
1807
+ exception_to_nan(mpmath.rgamma),
1808
+ [ComplexArg()],
1809
+ rtol=5e-13,
1810
+ )
1811
+
1812
+ @pytest.mark.xfail(reason=("see gh-3551 for bad points on 32 bit "
1813
+ "systems and gh-8095 for another bad "
1814
+ "point"))
1815
+ def test_rf(self):
1816
+ if version.parse(mpmath.__version__) >= version.Version("1.0.0"):
1817
+ # no workarounds needed
1818
+ mppoch = mpmath.rf
1819
+ else:
1820
+ def mppoch(a, m):
1821
+ # deal with cases where the result in double precision
1822
+ # hits exactly a non-positive integer, but the
1823
+ # corresponding extended-precision mpf floats don't
1824
+ if float(a + m) == int(a + m) and float(a + m) <= 0:
1825
+ a = mpmath.mpf(a)
1826
+ m = int(a + m) - a
1827
+ return mpmath.rf(a, m)
1828
+
1829
+ assert_mpmath_equal(sc.poch, mppoch, [Arg(), Arg()], dps=400)
1830
+
1831
+ def test_sinpi(self):
1832
+ eps = np.finfo(float).eps
1833
+ assert_mpmath_equal(
1834
+ _sinpi,
1835
+ mpmath.sinpi,
1836
+ [Arg()],
1837
+ nan_ok=False,
1838
+ rtol=2*eps,
1839
+ )
1840
+
1841
+ def test_sinpi_complex(self):
1842
+ assert_mpmath_equal(
1843
+ _sinpi,
1844
+ mpmath.sinpi,
1845
+ [ComplexArg()],
1846
+ nan_ok=False,
1847
+ rtol=2e-14,
1848
+ )
1849
+
1850
+ def test_shi(self):
1851
+ def shi(x):
1852
+ return sc.shichi(x)[0]
1853
+ assert_mpmath_equal(shi, mpmath.shi, [Arg()])
1854
+ # check asymptotic series cross-over
1855
+ assert_mpmath_equal(shi, mpmath.shi, [FixedArg([88 - 1e-9, 88, 88 + 1e-9])])
1856
+
1857
+ def test_shi_complex(self):
1858
+ def shi(z):
1859
+ return sc.shichi(z)[0]
1860
+ # shi oscillates as Im[z] -> +- inf, so limit range
1861
+ assert_mpmath_equal(
1862
+ shi,
1863
+ mpmath.shi,
1864
+ [ComplexArg(complex(-np.inf, -1e8), complex(np.inf, 1e8))],
1865
+ rtol=1e-12,
1866
+ )
1867
+
1868
+ def test_si(self):
1869
+ def si(x):
1870
+ return sc.sici(x)[0]
1871
+ assert_mpmath_equal(si, mpmath.si, [Arg()])
1872
+
1873
+ def test_si_complex(self):
1874
+ def si(z):
1875
+ return sc.sici(z)[0]
1876
+ # si oscillates as Re[z] -> +- inf, so limit range
1877
+ assert_mpmath_equal(
1878
+ si,
1879
+ mpmath.si,
1880
+ [ComplexArg(complex(-1e8, -np.inf), complex(1e8, np.inf))],
1881
+ rtol=1e-12,
1882
+ )
1883
+
1884
+ def test_spence(self):
1885
+ # mpmath uses a different convention for the dilogarithm
1886
+ def dilog(x):
1887
+ return mpmath.polylog(2, 1 - x)
1888
+ # Spence has a branch cut on the negative real axis
1889
+ assert_mpmath_equal(
1890
+ sc.spence,
1891
+ exception_to_nan(dilog),
1892
+ [Arg(0, np.inf)],
1893
+ rtol=1e-14,
1894
+ )
1895
+
1896
+ def test_spence_complex(self):
1897
+ def dilog(z):
1898
+ return mpmath.polylog(2, 1 - z)
1899
+ assert_mpmath_equal(
1900
+ sc.spence,
1901
+ exception_to_nan(dilog),
1902
+ [ComplexArg()],
1903
+ rtol=1e-14,
1904
+ )
1905
+
1906
+ def test_struveh(self):
1907
+ assert_mpmath_equal(
1908
+ sc.struve,
1909
+ exception_to_nan(mpmath.struveh),
1910
+ [Arg(-1e4, 1e4), Arg(0, 1e4)],
1911
+ rtol=5e-10,
1912
+ )
1913
+
1914
+ def test_struvel(self):
1915
+ def mp_struvel(v, z):
1916
+ if v < 0 and z < -v and abs(v) > 1000:
1917
+ # larger DPS needed for correct results
1918
+ old_dps = mpmath.mp.dps
1919
+ try:
1920
+ mpmath.mp.dps = 500
1921
+ return mpmath.struvel(v, z)
1922
+ finally:
1923
+ mpmath.mp.dps = old_dps
1924
+ return mpmath.struvel(v, z)
1925
+
1926
+ assert_mpmath_equal(
1927
+ sc.modstruve,
1928
+ exception_to_nan(mp_struvel),
1929
+ [Arg(-1e4, 1e4), Arg(0, 1e4)],
1930
+ rtol=5e-10,
1931
+ ignore_inf_sign=True,
1932
+ )
1933
+
1934
+ def test_wrightomega_real(self):
1935
+ def mpmath_wrightomega_real(x):
1936
+ return mpmath.lambertw(mpmath.exp(x), mpmath.mpf('-0.5'))
1937
+
1938
+ # For x < -1000 the Wright Omega function is just 0 to double
1939
+ # precision, and for x > 1e21 it is just x to double
1940
+ # precision.
1941
+ assert_mpmath_equal(
1942
+ sc.wrightomega,
1943
+ mpmath_wrightomega_real,
1944
+ [Arg(-1000, 1e21)],
1945
+ rtol=5e-15,
1946
+ atol=0,
1947
+ nan_ok=False,
1948
+ )
1949
+
1950
+ def test_wrightomega(self):
1951
+ assert_mpmath_equal(
1952
+ sc.wrightomega,
1953
+ lambda z: _mpmath_wrightomega(z, 25),
1954
+ [ComplexArg()],
1955
+ rtol=1e-14,
1956
+ nan_ok=False,
1957
+ )
1958
+
1959
+ def test_hurwitz_zeta(self):
1960
+ assert_mpmath_equal(
1961
+ sc.zeta,
1962
+ exception_to_nan(mpmath.zeta),
1963
+ [Arg(a=1, b=1e10, inclusive_a=False), Arg(a=0, inclusive_a=False)],
1964
+ )
1965
+
1966
+ def test_riemann_zeta(self):
1967
+ assert_mpmath_equal(
1968
+ sc.zeta,
1969
+ lambda x: mpmath.zeta(x) if x != 1 else mpmath.inf,
1970
+ [Arg(-100, 100)],
1971
+ nan_ok=False,
1972
+ rtol=5e-13,
1973
+ )
1974
+
1975
+ def test_zetac(self):
1976
+ assert_mpmath_equal(
1977
+ sc.zetac,
1978
+ lambda x: mpmath.zeta(x) - 1 if x != 1 else mpmath.inf,
1979
+ [Arg(-100, 100)],
1980
+ nan_ok=False,
1981
+ dps=45,
1982
+ rtol=5e-13,
1983
+ )
1984
+
1985
+ def test_boxcox(self):
1986
+
1987
+ def mp_boxcox(x, lmbda):
1988
+ x = mpmath.mp.mpf(x)
1989
+ lmbda = mpmath.mp.mpf(lmbda)
1990
+ if lmbda == 0:
1991
+ return mpmath.mp.log(x)
1992
+ else:
1993
+ return mpmath.mp.powm1(x, lmbda) / lmbda
1994
+
1995
+ assert_mpmath_equal(
1996
+ sc.boxcox,
1997
+ exception_to_nan(mp_boxcox),
1998
+ [Arg(a=0, inclusive_a=False), Arg()],
1999
+ n=200,
2000
+ dps=60,
2001
+ rtol=1e-13,
2002
+ )
2003
+
2004
+ def test_boxcox1p(self):
2005
+
2006
+ def mp_boxcox1p(x, lmbda):
2007
+ x = mpmath.mp.mpf(x)
2008
+ lmbda = mpmath.mp.mpf(lmbda)
2009
+ one = mpmath.mp.mpf(1)
2010
+ if lmbda == 0:
2011
+ return mpmath.mp.log(one + x)
2012
+ else:
2013
+ return mpmath.mp.powm1(one + x, lmbda) / lmbda
2014
+
2015
+ assert_mpmath_equal(
2016
+ sc.boxcox1p,
2017
+ exception_to_nan(mp_boxcox1p),
2018
+ [Arg(a=-1, inclusive_a=False), Arg()],
2019
+ n=200,
2020
+ dps=60,
2021
+ rtol=1e-13,
2022
+ )
2023
+
2024
+ def test_spherical_jn(self):
2025
+ def mp_spherical_jn(n, z):
2026
+ arg = mpmath.mpmathify(z)
2027
+ out = (mpmath.besselj(n + mpmath.mpf(1)/2, arg) /
2028
+ mpmath.sqrt(2*arg/mpmath.pi))
2029
+ if arg.imag == 0:
2030
+ return out.real
2031
+ else:
2032
+ return out
2033
+
2034
+ assert_mpmath_equal(
2035
+ lambda n, z: sc.spherical_jn(int(n), z),
2036
+ exception_to_nan(mp_spherical_jn),
2037
+ [IntArg(0, 200), Arg(-1e8, 1e8)],
2038
+ dps=300,
2039
+ # underflow of `spherical_jn` is a bit premature; see gh-21629
2040
+ param_filter=(None, lambda z: np.abs(z) > 1e-20),
2041
+ )
2042
+
2043
+ def test_spherical_jn_complex(self):
2044
+ def mp_spherical_jn(n, z):
2045
+ arg = mpmath.mpmathify(z)
2046
+ out = (mpmath.besselj(n + mpmath.mpf(1)/2, arg) /
2047
+ mpmath.sqrt(2*arg/mpmath.pi))
2048
+ if arg.imag == 0:
2049
+ return out.real
2050
+ else:
2051
+ return out
2052
+
2053
+ assert_mpmath_equal(
2054
+ lambda n, z: sc.spherical_jn(int(n.real), z),
2055
+ exception_to_nan(mp_spherical_jn),
2056
+ [IntArg(0, 200), ComplexArg()]
2057
+ )
2058
+
2059
+ def test_spherical_yn(self):
2060
+ def mp_spherical_yn(n, z):
2061
+ arg = mpmath.mpmathify(z)
2062
+ out = (mpmath.bessely(n + mpmath.mpf(1)/2, arg) /
2063
+ mpmath.sqrt(2*arg/mpmath.pi))
2064
+ if arg.imag == 0:
2065
+ return out.real
2066
+ else:
2067
+ return out
2068
+
2069
+ assert_mpmath_equal(
2070
+ lambda n, z: sc.spherical_yn(int(n), z),
2071
+ exception_to_nan(mp_spherical_yn),
2072
+ [IntArg(0, 200), Arg(-1e10, 1e10)],
2073
+ dps=100,
2074
+ )
2075
+
2076
+ def test_spherical_yn_complex(self):
2077
+ def mp_spherical_yn(n, z):
2078
+ arg = mpmath.mpmathify(z)
2079
+ out = (mpmath.bessely(n + mpmath.mpf(1)/2, arg) /
2080
+ mpmath.sqrt(2*arg/mpmath.pi))
2081
+ if arg.imag == 0:
2082
+ return out.real
2083
+ else:
2084
+ return out
2085
+
2086
+ assert_mpmath_equal(
2087
+ lambda n, z: sc.spherical_yn(int(n.real), z),
2088
+ exception_to_nan(mp_spherical_yn),
2089
+ [IntArg(0, 200), ComplexArg()],
2090
+ )
2091
+
2092
+ def test_spherical_in(self):
2093
+ def mp_spherical_in(n, z):
2094
+ arg = mpmath.mpmathify(z)
2095
+ out = (mpmath.besseli(n + mpmath.mpf(1)/2, arg) /
2096
+ mpmath.sqrt(2*arg/mpmath.pi))
2097
+ if arg.imag == 0:
2098
+ return out.real
2099
+ else:
2100
+ return out
2101
+
2102
+ assert_mpmath_equal(
2103
+ lambda n, z: sc.spherical_in(int(n), z),
2104
+ exception_to_nan(mp_spherical_in),
2105
+ [IntArg(0, 200), Arg()],
2106
+ dps=200,
2107
+ atol=10**(-278),
2108
+ )
2109
+
2110
+ def test_spherical_in_complex(self):
2111
+ def mp_spherical_in(n, z):
2112
+ arg = mpmath.mpmathify(z)
2113
+ out = (mpmath.besseli(n + mpmath.mpf(1)/2, arg) /
2114
+ mpmath.sqrt(2*arg/mpmath.pi))
2115
+ if arg.imag == 0:
2116
+ return out.real
2117
+ else:
2118
+ return out
2119
+
2120
+ assert_mpmath_equal(
2121
+ lambda n, z: sc.spherical_in(int(n.real), z),
2122
+ exception_to_nan(mp_spherical_in),
2123
+ [IntArg(0, 200), ComplexArg()],
2124
+ )
2125
+
2126
+ def test_spherical_kn(self):
2127
+ def mp_spherical_kn(n, z):
2128
+ arg = mpmath.mpmathify(z)
2129
+ out = (mpmath.besselk(n + mpmath.mpf(1)/2, arg) /
2130
+ mpmath.sqrt(2*arg/mpmath.pi))
2131
+ if mpmath.mpmathify(z).imag == 0:
2132
+ return out.real
2133
+ else:
2134
+ return out
2135
+
2136
+ assert_mpmath_equal(
2137
+ lambda n, z: sc.spherical_kn(int(n), z),
2138
+ exception_to_nan(mp_spherical_kn),
2139
+ [IntArg(0, 150), Arg()],
2140
+ dps=100,
2141
+ )
2142
+
2143
+ @pytest.mark.xfail(run=False,
2144
+ reason="Accuracy issues near z = -1 inherited from kv.")
2145
+ def test_spherical_kn_complex(self):
2146
+ def mp_spherical_kn(n, z):
2147
+ arg = mpmath.mpmathify(z)
2148
+ out = (mpmath.besselk(n + mpmath.mpf(1)/2, arg) /
2149
+ mpmath.sqrt(2*arg/mpmath.pi))
2150
+ if arg.imag == 0:
2151
+ return out.real
2152
+ else:
2153
+ return out
2154
+
2155
+ assert_mpmath_equal(
2156
+ lambda n, z: sc.spherical_kn(int(n.real), z),
2157
+ exception_to_nan(mp_spherical_kn),
2158
+ [IntArg(0, 200), ComplexArg()],
2159
+ dps=200,
2160
+ )
.venv/lib/python3.12/site-packages/scipy/special/tests/test_nan_inputs.py ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Test how the ufuncs in special handle nan inputs.
2
+
3
+ """
4
+ import warnings
5
+
6
+ from collections.abc import Callable
7
+
8
+ import numpy as np
9
+ from numpy.testing import assert_array_equal, assert_
10
+ import pytest
11
+ import scipy.special as sc
12
+
13
+
14
+ KNOWNFAILURES: dict[str, Callable] = {}
15
+
16
+ POSTPROCESSING: dict[str, Callable] = {}
17
+
18
+
19
+ def _get_ufuncs():
20
+ ufuncs = []
21
+ ufunc_names = []
22
+ for name in sorted(sc.__dict__):
23
+ obj = sc.__dict__[name]
24
+ if not isinstance(obj, np.ufunc):
25
+ continue
26
+ msg = KNOWNFAILURES.get(obj)
27
+ if msg is None:
28
+ ufuncs.append(obj)
29
+ ufunc_names.append(name)
30
+ else:
31
+ fail = pytest.mark.xfail(run=False, reason=msg)
32
+ ufuncs.append(pytest.param(obj, marks=fail))
33
+ ufunc_names.append(name)
34
+ return ufuncs, ufunc_names
35
+
36
+
37
+ UFUNCS, UFUNC_NAMES = _get_ufuncs()
38
+
39
+
40
+ @pytest.mark.parametrize("func", UFUNCS, ids=UFUNC_NAMES)
41
+ def test_nan_inputs(func):
42
+ args = (np.nan,)*func.nin
43
+ with warnings.catch_warnings():
44
+ # Ignore warnings about unsafe casts from legacy wrappers
45
+ warnings.filterwarnings(
46
+ "ignore",
47
+ "floating point number truncated to an integer",
48
+ RuntimeWarning
49
+ )
50
+ try:
51
+ with warnings.catch_warnings():
52
+ warnings.simplefilter("ignore", DeprecationWarning)
53
+ res = func(*args)
54
+ except TypeError:
55
+ # One of the arguments doesn't take real inputs
56
+ return
57
+ if func in POSTPROCESSING:
58
+ res = POSTPROCESSING[func](*res)
59
+
60
+ msg = f"got {res} instead of nan"
61
+ assert_array_equal(np.isnan(res), True, err_msg=msg)
62
+
63
+
64
+ def test_legacy_cast():
65
+ with warnings.catch_warnings():
66
+ warnings.filterwarnings(
67
+ "ignore",
68
+ "floating point number truncated to an integer",
69
+ RuntimeWarning
70
+ )
71
+ res = sc.bdtrc(np.nan, 1, 0.5)
72
+ assert_(np.isnan(res))
.venv/lib/python3.12/site-packages/scipy/special/tests/test_ndtr.py ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ from numpy.testing import assert_equal, assert_allclose
3
+ import scipy.special as sc
4
+
5
+
6
+ def test_ndtr():
7
+ assert_equal(sc.ndtr(0), 0.5)
8
+ assert_allclose(sc.ndtr(1), 0.8413447460685429)
9
+
10
+
11
+ class TestNdtri:
12
+
13
+ def test_zero(self):
14
+ assert sc.ndtri(0.5) == 0.0
15
+
16
+ def test_asymptotes(self):
17
+ assert_equal(sc.ndtri([0.0, 1.0]), [-np.inf, np.inf])
18
+
19
+ def test_outside_of_domain(self):
20
+ assert all(np.isnan(sc.ndtri([-1.5, 1.5])))
21
+
22
+
23
+ class TestLogNdtr:
24
+
25
+ # The expected values in these tests were computed with mpmath:
26
+ #
27
+ # def log_ndtr_mp(x):
28
+ # return mpmath.log(mpmath.ncdf(x))
29
+ #
30
+
31
+ def test_log_ndtr_moderate_le8(self):
32
+ x = np.array([-0.75, -0.25, 0, 0.5, 1.5, 2.5, 3, 4, 5, 7, 8])
33
+ expected = np.array([-1.4844482299196562,
34
+ -0.9130617648111351,
35
+ -0.6931471805599453,
36
+ -0.3689464152886564,
37
+ -0.06914345561223398,
38
+ -0.006229025485860002,
39
+ -0.0013508099647481938,
40
+ -3.167174337748927e-05,
41
+ -2.866516129637636e-07,
42
+ -1.279812543886654e-12,
43
+ -6.220960574271786e-16])
44
+ y = sc.log_ndtr(x)
45
+ assert_allclose(y, expected, rtol=1e-14)
46
+
47
+ def test_log_ndtr_values_8_16(self):
48
+ x = np.array([8.001, 8.06, 8.15, 8.5, 10, 12, 14, 16])
49
+ expected = [-6.170639424817055e-16,
50
+ -3.814722443652823e-16,
51
+ -1.819621363526629e-16,
52
+ -9.479534822203318e-18,
53
+ -7.619853024160525e-24,
54
+ -1.776482112077679e-33,
55
+ -7.7935368191928e-45,
56
+ -6.388754400538087e-58]
57
+ y = sc.log_ndtr(x)
58
+ assert_allclose(y, expected, rtol=5e-14)
59
+
60
+ def test_log_ndtr_values_16_31(self):
61
+ x = np.array([16.15, 20.3, 21.4, 26.2, 30.9])
62
+ expected = [-5.678084565148492e-59,
63
+ -6.429244467698346e-92,
64
+ -6.680402412553295e-102,
65
+ -1.328698078458869e-151,
66
+ -5.972288641838264e-210]
67
+ y = sc.log_ndtr(x)
68
+ assert_allclose(y, expected, rtol=2e-13)
69
+
70
+ def test_log_ndtr_values_gt31(self):
71
+ x = np.array([31.6, 32.8, 34.9, 37.1])
72
+ expected = [-1.846036234858162e-219,
73
+ -2.9440539964066835e-236,
74
+ -3.71721649450857e-267,
75
+ -1.4047119663106221e-301]
76
+ y = sc.log_ndtr(x)
77
+ assert_allclose(y, expected, rtol=3e-13)
.venv/lib/python3.12/site-packages/scipy/special/tests/test_ndtri_exp.py ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pytest
2
+ import numpy as np
3
+ from numpy.testing import assert_equal, assert_allclose
4
+ from scipy.special import log_ndtr, ndtri_exp
5
+ from scipy.special._testutils import assert_func_equal
6
+
7
+
8
+ def log_ndtr_ndtri_exp(y):
9
+ return log_ndtr(ndtri_exp(y))
10
+
11
+
12
+ @pytest.fixture(scope="class")
13
+ def uniform_random_points():
14
+ random_state = np.random.RandomState(1234)
15
+ points = random_state.random_sample(1000)
16
+ return points
17
+
18
+
19
+ class TestNdtriExp:
20
+ """Tests that ndtri_exp is sufficiently close to an inverse of log_ndtr.
21
+
22
+ We have separate tests for the five intervals (-inf, -10),
23
+ [-10, -2), [-2, -0.14542), [-0.14542, -1e-6), and [-1e-6, 0).
24
+ ndtri_exp(y) is computed in three different ways depending on if y
25
+ is in (-inf, -2), [-2, log(1 - exp(-2))], or [log(1 - exp(-2), 0).
26
+ Each of these intervals is given its own test with two additional tests
27
+ for handling very small values and values very close to zero.
28
+ """
29
+
30
+ @pytest.mark.parametrize(
31
+ "test_input", [-1e1, -1e2, -1e10, -1e20, -np.finfo(float).max]
32
+ )
33
+ def test_very_small_arg(self, test_input, uniform_random_points):
34
+ scale = test_input
35
+ points = scale * (0.5 * uniform_random_points + 0.5)
36
+ assert_func_equal(
37
+ log_ndtr_ndtri_exp,
38
+ lambda y: y, points,
39
+ rtol=1e-14,
40
+ nan_ok=True
41
+ )
42
+
43
+ @pytest.mark.parametrize(
44
+ "interval,expected_rtol",
45
+ [
46
+ ((-10, -2), 1e-14),
47
+ ((-2, -0.14542), 1e-12),
48
+ ((-0.14542, -1e-6), 1e-10),
49
+ ((-1e-6, 0), 1e-6),
50
+ ],
51
+ )
52
+ def test_in_interval(self, interval, expected_rtol, uniform_random_points):
53
+ left, right = interval
54
+ points = (right - left) * uniform_random_points + left
55
+ assert_func_equal(
56
+ log_ndtr_ndtri_exp,
57
+ lambda y: y, points,
58
+ rtol=expected_rtol,
59
+ nan_ok=True
60
+ )
61
+
62
+ def test_extreme(self):
63
+ # bigneg is not quite the largest negative double precision value.
64
+ # Here's why:
65
+ # The round-trip calculation
66
+ # y = ndtri_exp(bigneg)
67
+ # bigneg2 = log_ndtr(y)
68
+ # where bigneg is a very large negative value, would--with infinite
69
+ # precision--result in bigneg2 == bigneg. When bigneg is large enough,
70
+ # y is effectively equal to -sqrt(2)*sqrt(-bigneg), and log_ndtr(y) is
71
+ # effectively -(y/sqrt(2))**2. If we use bigneg = np.finfo(float).min,
72
+ # then by construction, the theoretical value is the most negative
73
+ # finite value that can be represented with 64 bit float point. This
74
+ # means tiny changes in how the computation proceeds can result in the
75
+ # return value being -inf. (E.g. changing the constant representation
76
+ # of 1/sqrt(2) from 0.7071067811865475--which is the value returned by
77
+ # 1/np.sqrt(2)--to 0.7071067811865476--which is the most accurate 64
78
+ # bit floating point representation of 1/sqrt(2)--results in the
79
+ # round-trip that starts with np.finfo(float).min returning -inf. So
80
+ # we'll move the bigneg value a few ULPs towards 0 to avoid this
81
+ # sensitivity.
82
+ # Use the reduce method to apply nextafter four times.
83
+ bigneg = np.nextafter.reduce([np.finfo(float).min, 0, 0, 0, 0])
84
+ # tinyneg is approx. -2.225e-308.
85
+ tinyneg = -np.finfo(float).tiny
86
+ x = np.array([tinyneg, bigneg])
87
+ result = log_ndtr_ndtri_exp(x)
88
+ assert_allclose(result, x, rtol=1e-12)
89
+
90
+ def test_asymptotes(self):
91
+ assert_equal(ndtri_exp([-np.inf, 0.0]), [-np.inf, np.inf])
92
+
93
+ def test_outside_domain(self):
94
+ assert np.isnan(ndtri_exp(1.0))
.venv/lib/python3.12/site-packages/scipy/special/tests/test_orthogonal.py ADDED
@@ -0,0 +1,823 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pytest
2
+ from pytest import raises as assert_raises
3
+
4
+ import numpy as np
5
+ from numpy import array, sqrt
6
+ from numpy.testing import assert_equal, assert_allclose
7
+
8
+ from scipy import integrate
9
+ import scipy.special as sc
10
+ from scipy.special import gamma
11
+ import scipy.special._orthogonal as orth
12
+
13
+
14
+ class TestCheby:
15
+ def test_chebyc(self):
16
+ C0 = orth.chebyc(0)
17
+ C1 = orth.chebyc(1)
18
+ with np.errstate(all='ignore'):
19
+ C2 = orth.chebyc(2)
20
+ C3 = orth.chebyc(3)
21
+ C4 = orth.chebyc(4)
22
+ C5 = orth.chebyc(5)
23
+
24
+ assert_allclose(C0.c, [2], atol=1.5e-13, rtol=0)
25
+ assert_allclose(C1.c, [1, 0], atol=1.5e-13, rtol=0)
26
+ assert_allclose(C2.c, [1, 0, -2], atol=1.5e-13, rtol=0)
27
+ assert_allclose(C3.c, [1, 0, -3, 0], atol=1.5e-13, rtol=0)
28
+ assert_allclose(C4.c, [1, 0, -4, 0, 2], atol=1.5e-13, rtol=0)
29
+ assert_allclose(C5.c, [1, 0, -5, 0, 5, 0],atol=1.5e-13, rtol=0)
30
+
31
+ def test_chebys(self):
32
+ S0 = orth.chebys(0)
33
+ S1 = orth.chebys(1)
34
+ S2 = orth.chebys(2)
35
+ S3 = orth.chebys(3)
36
+ S4 = orth.chebys(4)
37
+ S5 = orth.chebys(5)
38
+ assert_allclose(S0.c, [1], atol=1.5e-13, rtol=0)
39
+ assert_allclose(S1.c, [1, 0], atol=1.5e-13, rtol=0)
40
+ assert_allclose(S2.c, [1, 0, -1], atol=1.5e-13, rtol=0)
41
+ assert_allclose(S3.c, [1, 0, -2, 0], atol=1.5e-13, rtol=0)
42
+ assert_allclose(S4.c, [1, 0, -3, 0, 1], atol=1.5e-13, rtol=0)
43
+ assert_allclose(S5.c, [1, 0, -4, 0, 3, 0], atol=1.5e-13, rtol=0)
44
+
45
+ def test_chebyt(self):
46
+ T0 = orth.chebyt(0)
47
+ T1 = orth.chebyt(1)
48
+ T2 = orth.chebyt(2)
49
+ T3 = orth.chebyt(3)
50
+ T4 = orth.chebyt(4)
51
+ T5 = orth.chebyt(5)
52
+ assert_allclose(T0.c, [1], atol=1.5e-13, rtol=0)
53
+ assert_allclose(T1.c, [1, 0], atol=1.5e-13, rtol=0)
54
+ assert_allclose(T2.c, [2, 0, -1], atol=1.5e-13, rtol=0)
55
+ assert_allclose(T3.c, [4, 0, -3, 0], atol=1.5e-13, rtol=0)
56
+ assert_allclose(T4.c, [8, 0, -8, 0, 1], atol=1.5e-13, rtol=0)
57
+ assert_allclose(T5.c, [16, 0, -20, 0, 5, 0], atol=1.5e-13, rtol=0)
58
+
59
+ def test_chebyu(self):
60
+ U0 = orth.chebyu(0)
61
+ U1 = orth.chebyu(1)
62
+ U2 = orth.chebyu(2)
63
+ U3 = orth.chebyu(3)
64
+ U4 = orth.chebyu(4)
65
+ U5 = orth.chebyu(5)
66
+ assert_allclose(U0.c, [1], atol=1.5e-13, rtol=0)
67
+ assert_allclose(U1.c, [2, 0], atol=1.5e-13, rtol=0)
68
+ assert_allclose(U2.c, [4, 0, -1], atol=1.5e-13, rtol=0)
69
+ assert_allclose(U3.c, [8, 0, -4, 0], atol=1.5e-13, rtol=0)
70
+ assert_allclose(U4.c, [16, 0, -12, 0, 1], atol=1.5e-13, rtol=0)
71
+ assert_allclose(U5.c, [32, 0, -32, 0, 6, 0], atol=1.5e-13, rtol=0)
72
+
73
+
74
+ class TestGegenbauer:
75
+
76
+ def test_gegenbauer(self):
77
+ a = 5*np.random.random() - 0.5
78
+ if np.any(a == 0):
79
+ a = -0.2
80
+ Ca0 = orth.gegenbauer(0,a)
81
+ Ca1 = orth.gegenbauer(1,a)
82
+ Ca2 = orth.gegenbauer(2,a)
83
+ Ca3 = orth.gegenbauer(3,a)
84
+ Ca4 = orth.gegenbauer(4,a)
85
+ Ca5 = orth.gegenbauer(5,a)
86
+
87
+ assert_allclose(Ca0.c, array([1]), atol=1.5e-13, rtol=0)
88
+ assert_allclose(Ca1.c, array([2*a, 0]), atol=1.5e-13, rtol=0)
89
+ assert_allclose(Ca2.c, array([2*a*(a + 1), 0, -a]),
90
+ atol=1.5e-13, rtol=0)
91
+ assert_allclose(Ca3.c, array([4*sc.poch(a, 3), 0,-6*a*(a + 1), 0])/3.0,
92
+ atol=1.5e-11, rtol=0)
93
+ assert_allclose(Ca4.c, array([4*sc.poch(a, 4), 0, -12*sc.poch(a, 3),
94
+ 0, 3*a*(a + 1)])/6.0,
95
+ atol=1.5e-11, rtol=0)
96
+ assert_allclose(Ca5.c, array([4*sc.poch(a, 5), 0, -20*sc.poch(a, 4),
97
+ 0, 15*sc.poch(a, 3), 0])/15.0,
98
+ atol=1.5e-11, rtol=0)
99
+
100
+ @pytest.mark.parametrize('a', [0, 1])
101
+ def test_n_zero_gh8888(self, a):
102
+ # gh-8888 reported that gegenbauer(0, 0) returns NaN polynomial
103
+ Cn0 = orth.gegenbauer(0, a)
104
+ assert_equal(Cn0.c, np.asarray([1.]))
105
+
106
+ def test_valid_alpha(self):
107
+ # Check input validation of `alpha`
108
+ message = '`alpha` must be a finite number greater...'
109
+ with pytest.raises(ValueError, match=message):
110
+ orth.gegenbauer(0, np.nan)
111
+ with pytest.raises(ValueError, match=message):
112
+ orth.gegenbauer(1, -0.5)
113
+ with pytest.raises(ValueError, match=message):
114
+ orth.gegenbauer(2, -np.inf)
115
+
116
+
117
+ class TestHermite:
118
+ def test_hermite(self):
119
+ H0 = orth.hermite(0)
120
+ H1 = orth.hermite(1)
121
+ H2 = orth.hermite(2)
122
+ H3 = orth.hermite(3)
123
+ H4 = orth.hermite(4)
124
+ H5 = orth.hermite(5)
125
+ assert_allclose(H0.c, [1], atol=1.5e-13, rtol=0)
126
+ assert_allclose(H1.c, [2, 0], atol=1.5e-13, rtol=0)
127
+ assert_allclose(H2.c, [4, 0, -2], atol=1.5e-13, rtol=0)
128
+ assert_allclose(H3.c, [8, 0, -12, 0], atol=1.5e-13, rtol=0)
129
+ assert_allclose(H4.c, [16, 0, -48, 0, 12], atol=1.5e-12, rtol=0)
130
+ assert_allclose(H5.c, [32, 0, -160, 0, 120, 0], atol=1.5e-12, rtol=0)
131
+
132
+ def test_hermitenorm(self):
133
+ # He_n(x) = 2**(-n/2) H_n(x/sqrt(2))
134
+ psub = np.poly1d([1.0/sqrt(2),0])
135
+ H0 = orth.hermitenorm(0)
136
+ H1 = orth.hermitenorm(1)
137
+ H2 = orth.hermitenorm(2)
138
+ H3 = orth.hermitenorm(3)
139
+ H4 = orth.hermitenorm(4)
140
+ H5 = orth.hermitenorm(5)
141
+ he0 = orth.hermite(0)(psub)
142
+ he1 = orth.hermite(1)(psub) / sqrt(2)
143
+ he2 = orth.hermite(2)(psub) / 2.0
144
+ he3 = orth.hermite(3)(psub) / (2*sqrt(2))
145
+ he4 = orth.hermite(4)(psub) / 4.0
146
+ he5 = orth.hermite(5)(psub) / (4.0*sqrt(2))
147
+
148
+ assert_allclose(H0.c, he0.c, atol=1.5e-13, rtol=0)
149
+ assert_allclose(H1.c, he1.c, atol=1.5e-13, rtol=0)
150
+ assert_allclose(H2.c, he2.c, atol=1.5e-13, rtol=0)
151
+ assert_allclose(H3.c, he3.c, atol=1.5e-13, rtol=0)
152
+ assert_allclose(H4.c, he4.c, atol=1.5e-13, rtol=0)
153
+ assert_allclose(H5.c, he5.c, atol=1.5e-13, rtol=0)
154
+
155
+
156
+ class TestShLegendre:
157
+ def test_sh_legendre(self):
158
+ # P*_n(x) = P_n(2x-1)
159
+ psub = np.poly1d([2,-1])
160
+ Ps0 = orth.sh_legendre(0)
161
+ Ps1 = orth.sh_legendre(1)
162
+ Ps2 = orth.sh_legendre(2)
163
+ Ps3 = orth.sh_legendre(3)
164
+ Ps4 = orth.sh_legendre(4)
165
+ Ps5 = orth.sh_legendre(5)
166
+ pse0 = orth.legendre(0)(psub)
167
+ pse1 = orth.legendre(1)(psub)
168
+ pse2 = orth.legendre(2)(psub)
169
+ pse3 = orth.legendre(3)(psub)
170
+ pse4 = orth.legendre(4)(psub)
171
+ pse5 = orth.legendre(5)(psub)
172
+ assert_allclose(Ps0.c, pse0.c, atol=1.5e-13, rtol=0)
173
+ assert_allclose(Ps1.c, pse1.c, atol=1.5e-13, rtol=0)
174
+ assert_allclose(Ps2.c, pse2.c, atol=1.5e-13, rtol=0)
175
+ assert_allclose(Ps3.c, pse3.c, atol=1.5e-13, rtol=0)
176
+ assert_allclose(Ps4.c, pse4.c, atol=1.5e-12, rtol=0)
177
+ assert_allclose(Ps5.c, pse5.c, atol=1.5e-12, rtol=0)
178
+
179
+
180
+ class TestShChebyt:
181
+ def test_sh_chebyt(self):
182
+ # T*_n(x) = T_n(2x-1)
183
+ psub = np.poly1d([2,-1])
184
+ Ts0 = orth.sh_chebyt(0)
185
+ Ts1 = orth.sh_chebyt(1)
186
+ Ts2 = orth.sh_chebyt(2)
187
+ Ts3 = orth.sh_chebyt(3)
188
+ Ts4 = orth.sh_chebyt(4)
189
+ Ts5 = orth.sh_chebyt(5)
190
+ tse0 = orth.chebyt(0)(psub)
191
+ tse1 = orth.chebyt(1)(psub)
192
+ tse2 = orth.chebyt(2)(psub)
193
+ tse3 = orth.chebyt(3)(psub)
194
+ tse4 = orth.chebyt(4)(psub)
195
+ tse5 = orth.chebyt(5)(psub)
196
+ assert_allclose(Ts0.c, tse0.c, atol=1.5e-13, rtol=0)
197
+ assert_allclose(Ts1.c, tse1.c, atol=1.5e-13, rtol=0)
198
+ assert_allclose(Ts2.c, tse2.c, atol=1.5e-13, rtol=0)
199
+ assert_allclose(Ts3.c, tse3.c, atol=1.5e-13, rtol=0)
200
+ assert_allclose(Ts4.c, tse4.c, atol=1.5e-12, rtol=0)
201
+ assert_allclose(Ts5.c, tse5.c, atol=1.5e-12, rtol=0)
202
+
203
+
204
+ class TestShChebyu:
205
+ def test_sh_chebyu(self):
206
+ # U*_n(x) = U_n(2x-1)
207
+ psub = np.poly1d([2,-1])
208
+ Us0 = orth.sh_chebyu(0)
209
+ Us1 = orth.sh_chebyu(1)
210
+ Us2 = orth.sh_chebyu(2)
211
+ Us3 = orth.sh_chebyu(3)
212
+ Us4 = orth.sh_chebyu(4)
213
+ Us5 = orth.sh_chebyu(5)
214
+ use0 = orth.chebyu(0)(psub)
215
+ use1 = orth.chebyu(1)(psub)
216
+ use2 = orth.chebyu(2)(psub)
217
+ use3 = orth.chebyu(3)(psub)
218
+ use4 = orth.chebyu(4)(psub)
219
+ use5 = orth.chebyu(5)(psub)
220
+ assert_allclose(Us0.c, use0.c, atol=1.5e-13, rtol=0)
221
+ assert_allclose(Us1.c, use1.c, atol=1.5e-13, rtol=0)
222
+ assert_allclose(Us2.c, use2.c, atol=1.5e-13, rtol=0)
223
+ assert_allclose(Us3.c, use3.c, atol=1.5e-13, rtol=0)
224
+ assert_allclose(Us4.c, use4.c, atol=1.5e-12, rtol=0)
225
+ assert_allclose(Us5.c, use5.c, atol=1.5e-11, rtol=0)
226
+
227
+
228
+ class TestShJacobi:
229
+ def test_sh_jacobi(self):
230
+ # G^(p,q)_n(x) = n! gamma(n+p)/gamma(2*n+p) * P^(p-q,q-1)_n(2*x-1)
231
+ def conv(n, p):
232
+ return gamma(n + 1) * gamma(n + p) / gamma(2 * n + p)
233
+ psub = np.poly1d([2,-1])
234
+ q = 4 * np.random.random()
235
+ p = q-1 + 2*np.random.random()
236
+ # print("shifted jacobi p,q = ", p, q)
237
+ G0 = orth.sh_jacobi(0,p,q)
238
+ G1 = orth.sh_jacobi(1,p,q)
239
+ G2 = orth.sh_jacobi(2,p,q)
240
+ G3 = orth.sh_jacobi(3,p,q)
241
+ G4 = orth.sh_jacobi(4,p,q)
242
+ G5 = orth.sh_jacobi(5,p,q)
243
+ ge0 = orth.jacobi(0,p-q,q-1)(psub) * conv(0,p)
244
+ ge1 = orth.jacobi(1,p-q,q-1)(psub) * conv(1,p)
245
+ ge2 = orth.jacobi(2,p-q,q-1)(psub) * conv(2,p)
246
+ ge3 = orth.jacobi(3,p-q,q-1)(psub) * conv(3,p)
247
+ ge4 = orth.jacobi(4,p-q,q-1)(psub) * conv(4,p)
248
+ ge5 = orth.jacobi(5,p-q,q-1)(psub) * conv(5,p)
249
+
250
+ assert_allclose(G0.c, ge0.c, atol=1.5e-13, rtol=0)
251
+ assert_allclose(G1.c, ge1.c, atol=1.5e-13, rtol=0)
252
+ assert_allclose(G2.c, ge2.c, atol=1.5e-13, rtol=0)
253
+ assert_allclose(G3.c, ge3.c, atol=1.5e-13, rtol=0)
254
+ assert_allclose(G4.c, ge4.c, atol=1.5e-13, rtol=0)
255
+ assert_allclose(G5.c, ge5.c, atol=1.5e-13, rtol=0)
256
+
257
+
258
+ class TestCall:
259
+ def test_call(self):
260
+ poly = []
261
+ for n in range(5):
262
+ poly.extend([x.strip() for x in
263
+ (f"""
264
+ orth.jacobi({n},0.3,0.9)
265
+ orth.sh_jacobi({n},0.3,0.9)
266
+ orth.genlaguerre({n},0.3)
267
+ orth.laguerre({n})
268
+ orth.hermite({n})
269
+ orth.hermitenorm({n})
270
+ orth.gegenbauer({n},0.3)
271
+ orth.chebyt({n})
272
+ orth.chebyu({n})
273
+ orth.chebyc({n})
274
+ orth.chebys({n})
275
+ orth.sh_chebyt({n})
276
+ orth.sh_chebyu({n})
277
+ orth.legendre({n})
278
+ orth.sh_legendre({n})
279
+ """).split()])
280
+ with np.errstate(all='ignore'):
281
+ for pstr in poly:
282
+ p = eval(pstr)
283
+ assert_allclose(p(0.315), np.poly1d(p.coef)(0.315),
284
+ atol=1.5e-7, rtol=0, err_msg=pstr)
285
+
286
+
287
+ class TestGenlaguerre:
288
+ def test_regression(self):
289
+ assert_equal(orth.genlaguerre(1, 1, monic=False)(0), 2.)
290
+ assert_equal(orth.genlaguerre(1, 1, monic=True)(0), -2.)
291
+ assert_equal(orth.genlaguerre(1, 1, monic=False), np.poly1d([-1, 2]))
292
+ assert_equal(orth.genlaguerre(1, 1, monic=True), np.poly1d([1, -2]))
293
+
294
+
295
+ def verify_gauss_quad(root_func, eval_func, weight_func, a, b, N,
296
+ rtol=1e-15, atol=5e-14):
297
+ # this test is copied from numpy's TestGauss in test_hermite.py
298
+ x, w, mu = root_func(N, True)
299
+
300
+ n = np.arange(N, dtype=np.dtype("long"))
301
+ v = eval_func(n[:,np.newaxis], x)
302
+ vv = np.dot(v*w, v.T)
303
+ vd = 1 / np.sqrt(vv.diagonal())
304
+ vv = vd[:, np.newaxis] * vv * vd
305
+ assert_allclose(vv, np.eye(N), rtol, atol)
306
+
307
+ # check that the integral of 1 is correct
308
+ assert_allclose(w.sum(), mu, rtol, atol)
309
+
310
+ # compare the results of integrating a function with quad.
311
+ def f(x):
312
+ return x ** 3 - 3 * x ** 2 + x - 2
313
+ resI = integrate.quad(lambda x: f(x)*weight_func(x), a, b)
314
+ resG = np.vdot(f(x), w)
315
+ rtol = 1e-6 if 1e-6 < resI[1] else resI[1] * 10
316
+ assert_allclose(resI[0], resG, rtol=rtol)
317
+
318
+ def test_roots_jacobi():
319
+ def rf(a, b):
320
+ return lambda n, mu: sc.roots_jacobi(n, a, b, mu)
321
+ def ef(a, b):
322
+ return lambda n, x: sc.eval_jacobi(n, a, b, x)
323
+ def wf(a, b):
324
+ return lambda x: (1 - x) ** a * (1 + x) ** b
325
+
326
+ vgq = verify_gauss_quad
327
+ vgq(rf(-0.5, -0.75), ef(-0.5, -0.75), wf(-0.5, -0.75), -1., 1., 5)
328
+ vgq(rf(-0.5, -0.75), ef(-0.5, -0.75), wf(-0.5, -0.75), -1., 1.,
329
+ 25, atol=1e-12)
330
+ vgq(rf(-0.5, -0.75), ef(-0.5, -0.75), wf(-0.5, -0.75), -1., 1.,
331
+ 100, atol=1e-11)
332
+
333
+ vgq(rf(0.5, -0.5), ef(0.5, -0.5), wf(0.5, -0.5), -1., 1., 5)
334
+ vgq(rf(0.5, -0.5), ef(0.5, -0.5), wf(0.5, -0.5), -1., 1., 25, atol=1.5e-13)
335
+ vgq(rf(0.5, -0.5), ef(0.5, -0.5), wf(0.5, -0.5), -1., 1., 100, atol=2e-12)
336
+
337
+ vgq(rf(1, 0.5), ef(1, 0.5), wf(1, 0.5), -1., 1., 5, atol=2e-13)
338
+ vgq(rf(1, 0.5), ef(1, 0.5), wf(1, 0.5), -1., 1., 25, atol=2e-13)
339
+ vgq(rf(1, 0.5), ef(1, 0.5), wf(1, 0.5), -1., 1., 100, atol=1e-12)
340
+
341
+ vgq(rf(0.9, 2), ef(0.9, 2), wf(0.9, 2), -1., 1., 5)
342
+ vgq(rf(0.9, 2), ef(0.9, 2), wf(0.9, 2), -1., 1., 25, atol=1e-13)
343
+ vgq(rf(0.9, 2), ef(0.9, 2), wf(0.9, 2), -1., 1., 100, atol=3e-13)
344
+
345
+ vgq(rf(18.24, 27.3), ef(18.24, 27.3), wf(18.24, 27.3), -1., 1., 5)
346
+ vgq(rf(18.24, 27.3), ef(18.24, 27.3), wf(18.24, 27.3), -1., 1., 25,
347
+ atol=1.1e-14)
348
+ vgq(rf(18.24, 27.3), ef(18.24, 27.3), wf(18.24, 27.3), -1., 1.,
349
+ 100, atol=1e-13)
350
+
351
+ vgq(rf(47.1, -0.2), ef(47.1, -0.2), wf(47.1, -0.2), -1., 1., 5, atol=1e-13)
352
+ vgq(rf(47.1, -0.2), ef(47.1, -0.2), wf(47.1, -0.2), -1., 1., 25, atol=2e-13)
353
+ vgq(rf(47.1, -0.2), ef(47.1, -0.2), wf(47.1, -0.2), -1., 1.,
354
+ 100, atol=1e-11)
355
+
356
+ vgq(rf(1., 658.), ef(1., 658.), wf(1., 658.), -1., 1., 5, atol=2e-13)
357
+ vgq(rf(1., 658.), ef(1., 658.), wf(1., 658.), -1., 1., 25, atol=1e-12)
358
+ vgq(rf(1., 658.), ef(1., 658.), wf(1., 658.), -1., 1., 100, atol=1e-11)
359
+ vgq(rf(1., 658.), ef(1., 658.), wf(1., 658.), -1., 1., 250, atol=1e-11)
360
+
361
+ vgq(rf(511., 511.), ef(511., 511.), wf(511., 511.), -1., 1., 5,
362
+ atol=1e-12)
363
+ vgq(rf(511., 511.), ef(511., 511.), wf(511., 511.), -1., 1., 25,
364
+ atol=1e-11)
365
+ vgq(rf(511., 511.), ef(511., 511.), wf(511., 511.), -1., 1., 100,
366
+ atol=1e-10)
367
+
368
+ vgq(rf(511., 512.), ef(511., 512.), wf(511., 512.), -1., 1., 5,
369
+ atol=1e-12)
370
+ vgq(rf(511., 512.), ef(511., 512.), wf(511., 512.), -1., 1., 25,
371
+ atol=1e-11)
372
+ vgq(rf(511., 512.), ef(511., 512.), wf(511., 512.), -1., 1., 100,
373
+ atol=1e-10)
374
+
375
+ vgq(rf(1000., 500.), ef(1000., 500.), wf(1000., 500.), -1., 1., 5,
376
+ atol=1e-12)
377
+ vgq(rf(1000., 500.), ef(1000., 500.), wf(1000., 500.), -1., 1., 25,
378
+ atol=1e-11)
379
+ vgq(rf(1000., 500.), ef(1000., 500.), wf(1000., 500.), -1., 1., 100,
380
+ atol=1e-10)
381
+
382
+ vgq(rf(2.25, 68.9), ef(2.25, 68.9), wf(2.25, 68.9), -1., 1., 5)
383
+ vgq(rf(2.25, 68.9), ef(2.25, 68.9), wf(2.25, 68.9), -1., 1., 25,
384
+ atol=1e-13)
385
+ vgq(rf(2.25, 68.9), ef(2.25, 68.9), wf(2.25, 68.9), -1., 1., 100,
386
+ atol=1e-13)
387
+
388
+ # when alpha == beta == 0, P_n^{a,b}(x) == P_n(x)
389
+ xj, wj = sc.roots_jacobi(6, 0.0, 0.0)
390
+ xl, wl = sc.roots_legendre(6)
391
+ assert_allclose(xj, xl, 1e-14, 1e-14)
392
+ assert_allclose(wj, wl, 1e-14, 1e-14)
393
+
394
+ # when alpha == beta != 0, P_n^{a,b}(x) == C_n^{alpha+0.5}(x)
395
+ xj, wj = sc.roots_jacobi(6, 4.0, 4.0)
396
+ xc, wc = sc.roots_gegenbauer(6, 4.5)
397
+ assert_allclose(xj, xc, 1e-14, 1e-14)
398
+ assert_allclose(wj, wc, 1e-14, 1e-14)
399
+
400
+ x, w = sc.roots_jacobi(5, 2, 3, False)
401
+ y, v, m = sc.roots_jacobi(5, 2, 3, True)
402
+ assert_allclose(x, y, 1e-14, 1e-14)
403
+ assert_allclose(w, v, 1e-14, 1e-14)
404
+
405
+ muI, muI_err = integrate.quad(wf(2,3), -1, 1)
406
+ assert_allclose(m, muI, rtol=muI_err)
407
+
408
+ assert_raises(ValueError, sc.roots_jacobi, 0, 1, 1)
409
+ assert_raises(ValueError, sc.roots_jacobi, 3.3, 1, 1) # type: ignore[call-overload]
410
+ assert_raises(ValueError, sc.roots_jacobi, 3, -2, 1)
411
+ assert_raises(ValueError, sc.roots_jacobi, 3, 1, -2)
412
+ assert_raises(ValueError, sc.roots_jacobi, 3, -2, -2)
413
+
414
+ def test_roots_sh_jacobi():
415
+ def rf(a, b):
416
+ return lambda n, mu: sc.roots_sh_jacobi(n, a, b, mu)
417
+ def ef(a, b):
418
+ return lambda n, x: sc.eval_sh_jacobi(n, a, b, x)
419
+ def wf(a, b):
420
+ return lambda x: (1.0 - x) ** (a - b) * x ** (b - 1.0)
421
+
422
+ vgq = verify_gauss_quad
423
+ vgq(rf(-0.5, 0.25), ef(-0.5, 0.25), wf(-0.5, 0.25), 0., 1., 5)
424
+ vgq(rf(-0.5, 0.25), ef(-0.5, 0.25), wf(-0.5, 0.25), 0., 1.,
425
+ 25, atol=1e-12)
426
+ vgq(rf(-0.5, 0.25), ef(-0.5, 0.25), wf(-0.5, 0.25), 0., 1.,
427
+ 100, atol=1e-11)
428
+
429
+ vgq(rf(0.5, 0.5), ef(0.5, 0.5), wf(0.5, 0.5), 0., 1., 5)
430
+ vgq(rf(0.5, 0.5), ef(0.5, 0.5), wf(0.5, 0.5), 0., 1., 25, atol=1e-13)
431
+ vgq(rf(0.5, 0.5), ef(0.5, 0.5), wf(0.5, 0.5), 0., 1., 100, atol=1e-12)
432
+
433
+ vgq(rf(1, 0.5), ef(1, 0.5), wf(1, 0.5), 0., 1., 5)
434
+ vgq(rf(1, 0.5), ef(1, 0.5), wf(1, 0.5), 0., 1., 25, atol=1.5e-13)
435
+ vgq(rf(1, 0.5), ef(1, 0.5), wf(1, 0.5), 0., 1., 100, atol=2e-12)
436
+
437
+ vgq(rf(2, 0.9), ef(2, 0.9), wf(2, 0.9), 0., 1., 5)
438
+ vgq(rf(2, 0.9), ef(2, 0.9), wf(2, 0.9), 0., 1., 25, atol=1e-13)
439
+ vgq(rf(2, 0.9), ef(2, 0.9), wf(2, 0.9), 0., 1., 100, atol=1e-12)
440
+
441
+ vgq(rf(27.3, 18.24), ef(27.3, 18.24), wf(27.3, 18.24), 0., 1., 5)
442
+ vgq(rf(27.3, 18.24), ef(27.3, 18.24), wf(27.3, 18.24), 0., 1., 25)
443
+ vgq(rf(27.3, 18.24), ef(27.3, 18.24), wf(27.3, 18.24), 0., 1.,
444
+ 100, atol=1e-13)
445
+
446
+ vgq(rf(47.1, 0.2), ef(47.1, 0.2), wf(47.1, 0.2), 0., 1., 5, atol=1e-12)
447
+ vgq(rf(47.1, 0.2), ef(47.1, 0.2), wf(47.1, 0.2), 0., 1., 25, atol=1e-11)
448
+ vgq(rf(47.1, 0.2), ef(47.1, 0.2), wf(47.1, 0.2), 0., 1., 100, atol=1e-10)
449
+
450
+ vgq(rf(68.9, 2.25), ef(68.9, 2.25), wf(68.9, 2.25), 0., 1., 5, atol=3.5e-14)
451
+ vgq(rf(68.9, 2.25), ef(68.9, 2.25), wf(68.9, 2.25), 0., 1., 25, atol=2e-13)
452
+ vgq(rf(68.9, 2.25), ef(68.9, 2.25), wf(68.9, 2.25), 0., 1.,
453
+ 100, atol=1e-12)
454
+
455
+ x, w = sc.roots_sh_jacobi(5, 3, 2, False)
456
+ y, v, m = sc.roots_sh_jacobi(5, 3, 2, True)
457
+ assert_allclose(x, y, 1e-14, 1e-14)
458
+ assert_allclose(w, v, 1e-14, 1e-14)
459
+
460
+ muI, muI_err = integrate.quad(wf(3,2), 0, 1)
461
+ assert_allclose(m, muI, rtol=muI_err)
462
+
463
+ assert_raises(ValueError, sc.roots_sh_jacobi, 0, 1, 1)
464
+ assert_raises(ValueError, sc.roots_sh_jacobi, 3.3, 1, 1) # type: ignore[call-overload]
465
+ assert_raises(ValueError, sc.roots_sh_jacobi, 3, 1, 2) # p - q <= -1
466
+ assert_raises(ValueError, sc.roots_sh_jacobi, 3, 2, -1) # q <= 0
467
+ assert_raises(ValueError, sc.roots_sh_jacobi, 3, -2, -1) # both
468
+
469
+ def test_roots_hermite():
470
+ rootf = sc.roots_hermite
471
+ evalf = sc.eval_hermite
472
+ weightf = orth.hermite(5).weight_func
473
+
474
+ verify_gauss_quad(rootf, evalf, weightf, -np.inf, np.inf, 5)
475
+ verify_gauss_quad(rootf, evalf, weightf, -np.inf, np.inf, 25, atol=1e-13)
476
+ verify_gauss_quad(rootf, evalf, weightf, -np.inf, np.inf, 100, atol=1e-12)
477
+
478
+ # Golub-Welsch branch
479
+ x, w = sc.roots_hermite(5, False)
480
+ y, v, m = sc.roots_hermite(5, True)
481
+ assert_allclose(x, y, 1e-14, 1e-14)
482
+ assert_allclose(w, v, 1e-14, 1e-14)
483
+
484
+ muI, muI_err = integrate.quad(weightf, -np.inf, np.inf)
485
+ assert_allclose(m, muI, rtol=muI_err)
486
+
487
+ # Asymptotic branch (switch over at n >= 150)
488
+ x, w = sc.roots_hermite(200, False)
489
+ y, v, m = sc.roots_hermite(200, True)
490
+ assert_allclose(x, y, 1e-14, 1e-14)
491
+ assert_allclose(w, v, 1e-14, 1e-14)
492
+ assert_allclose(sum(v), m, 1e-14, 1e-14)
493
+
494
+ assert_raises(ValueError, sc.roots_hermite, 0)
495
+ assert_raises(ValueError, sc.roots_hermite, 3.3) # type: ignore[call-overload]
496
+
497
+ def test_roots_hermite_asy():
498
+ # Recursion for Hermite functions
499
+ def hermite_recursion(n, nodes):
500
+ H = np.zeros((n, nodes.size))
501
+ H[0,:] = np.pi**(-0.25) * np.exp(-0.5*nodes**2)
502
+ if n > 1:
503
+ H[1,:] = sqrt(2.0) * nodes * H[0,:]
504
+ for k in range(2, n):
505
+ H[k,:] = sqrt(2.0/k) * nodes * H[k-1,:] - sqrt((k-1.0)/k) * H[k-2,:]
506
+ return H
507
+
508
+ # This tests only the nodes
509
+ def test(N, rtol=1e-15, atol=1e-14):
510
+ x, w = orth._roots_hermite_asy(N)
511
+ H = hermite_recursion(N+1, x)
512
+ assert_allclose(H[-1,:], np.zeros(N), rtol, atol)
513
+ assert_allclose(sum(w), sqrt(np.pi), rtol, atol)
514
+
515
+ test(150, atol=1e-12)
516
+ test(151, atol=1e-12)
517
+ test(300, atol=1e-12)
518
+ test(301, atol=1e-12)
519
+ test(500, atol=1e-12)
520
+ test(501, atol=1e-12)
521
+ test(999, atol=1e-12)
522
+ test(1000, atol=1e-12)
523
+ test(2000, atol=1e-12)
524
+ test(5000, atol=1e-12)
525
+
526
+ def test_roots_hermitenorm():
527
+ rootf = sc.roots_hermitenorm
528
+ evalf = sc.eval_hermitenorm
529
+ weightf = orth.hermitenorm(5).weight_func
530
+
531
+ verify_gauss_quad(rootf, evalf, weightf, -np.inf, np.inf, 5)
532
+ verify_gauss_quad(rootf, evalf, weightf, -np.inf, np.inf, 25, atol=1e-13)
533
+ verify_gauss_quad(rootf, evalf, weightf, -np.inf, np.inf, 100, atol=1e-12)
534
+
535
+ x, w = sc.roots_hermitenorm(5, False)
536
+ y, v, m = sc.roots_hermitenorm(5, True)
537
+ assert_allclose(x, y, 1e-14, 1e-14)
538
+ assert_allclose(w, v, 1e-14, 1e-14)
539
+
540
+ muI, muI_err = integrate.quad(weightf, -np.inf, np.inf)
541
+ assert_allclose(m, muI, rtol=muI_err)
542
+
543
+ assert_raises(ValueError, sc.roots_hermitenorm, 0)
544
+ assert_raises(ValueError, sc.roots_hermitenorm, 3.3) # type: ignore[call-overload]
545
+
546
+ def test_roots_gegenbauer():
547
+ def rootf(a):
548
+ return lambda n, mu: sc.roots_gegenbauer(n, a, mu)
549
+ def evalf(a):
550
+ return lambda n, x: sc.eval_gegenbauer(n, a, x)
551
+ def weightf(a):
552
+ return lambda x: (1 - x ** 2) ** (a - 0.5)
553
+
554
+ vgq = verify_gauss_quad
555
+ vgq(rootf(-0.25), evalf(-0.25), weightf(-0.25), -1., 1., 5)
556
+ vgq(rootf(-0.25), evalf(-0.25), weightf(-0.25), -1., 1., 25, atol=1e-12)
557
+ vgq(rootf(-0.25), evalf(-0.25), weightf(-0.25), -1., 1., 100, atol=1e-11)
558
+
559
+ vgq(rootf(0.1), evalf(0.1), weightf(0.1), -1., 1., 5)
560
+ vgq(rootf(0.1), evalf(0.1), weightf(0.1), -1., 1., 25, atol=1e-13)
561
+ vgq(rootf(0.1), evalf(0.1), weightf(0.1), -1., 1., 100, atol=1e-12)
562
+
563
+ vgq(rootf(1), evalf(1), weightf(1), -1., 1., 5)
564
+ vgq(rootf(1), evalf(1), weightf(1), -1., 1., 25, atol=1e-13)
565
+ vgq(rootf(1), evalf(1), weightf(1), -1., 1., 100, atol=1e-12)
566
+
567
+ vgq(rootf(10), evalf(10), weightf(10), -1., 1., 5)
568
+ vgq(rootf(10), evalf(10), weightf(10), -1., 1., 25, atol=1e-13)
569
+ vgq(rootf(10), evalf(10), weightf(10), -1., 1., 100, atol=1e-12)
570
+
571
+ vgq(rootf(50), evalf(50), weightf(50), -1., 1., 5, atol=1e-13)
572
+ vgq(rootf(50), evalf(50), weightf(50), -1., 1., 25, atol=1e-12)
573
+ vgq(rootf(50), evalf(50), weightf(50), -1., 1., 100, atol=1e-11)
574
+
575
+ # Alpha=170 is where the approximation used in roots_gegenbauer changes
576
+ vgq(rootf(170), evalf(170), weightf(170), -1., 1., 5, atol=1e-13)
577
+ vgq(rootf(170), evalf(170), weightf(170), -1., 1., 25, atol=1e-12)
578
+ vgq(rootf(170), evalf(170), weightf(170), -1., 1., 100, atol=1e-11)
579
+ vgq(rootf(170.5), evalf(170.5), weightf(170.5), -1., 1., 5, atol=1.25e-13)
580
+ vgq(rootf(170.5), evalf(170.5), weightf(170.5), -1., 1., 25, atol=1e-12)
581
+ vgq(rootf(170.5), evalf(170.5), weightf(170.5), -1., 1., 100, atol=1e-11)
582
+
583
+ # Test for failures, e.g. overflows, resulting from large alphas
584
+ vgq(rootf(238), evalf(238), weightf(238), -1., 1., 5, atol=1e-13)
585
+ vgq(rootf(238), evalf(238), weightf(238), -1., 1., 25, atol=1e-12)
586
+ vgq(rootf(238), evalf(238), weightf(238), -1., 1., 100, atol=1e-11)
587
+ vgq(rootf(512.5), evalf(512.5), weightf(512.5), -1., 1., 5, atol=1e-12)
588
+ vgq(rootf(512.5), evalf(512.5), weightf(512.5), -1., 1., 25, atol=1e-11)
589
+ vgq(rootf(512.5), evalf(512.5), weightf(512.5), -1., 1., 100, atol=1e-10)
590
+
591
+ # this is a special case that the old code supported.
592
+ # when alpha = 0, the gegenbauer polynomial is uniformly 0. but it goes
593
+ # to a scaled down copy of T_n(x) there.
594
+ vgq(rootf(0), sc.eval_chebyt, weightf(0), -1., 1., 5)
595
+ vgq(rootf(0), sc.eval_chebyt, weightf(0), -1., 1., 25)
596
+ vgq(rootf(0), sc.eval_chebyt, weightf(0), -1., 1., 100, atol=1e-12)
597
+
598
+ x, w = sc.roots_gegenbauer(5, 2, False)
599
+ y, v, m = sc.roots_gegenbauer(5, 2, True)
600
+ assert_allclose(x, y, 1e-14, 1e-14)
601
+ assert_allclose(w, v, 1e-14, 1e-14)
602
+
603
+ muI, muI_err = integrate.quad(weightf(2), -1, 1)
604
+ assert_allclose(m, muI, rtol=muI_err)
605
+
606
+ assert_raises(ValueError, sc.roots_gegenbauer, 0, 2)
607
+ assert_raises(ValueError, sc.roots_gegenbauer, 3.3, 2) # type: ignore[call-overload]
608
+ assert_raises(ValueError, sc.roots_gegenbauer, 3, -.75)
609
+
610
+ def test_roots_chebyt():
611
+ weightf = orth.chebyt(5).weight_func
612
+ verify_gauss_quad(sc.roots_chebyt, sc.eval_chebyt, weightf, -1., 1., 5)
613
+ verify_gauss_quad(sc.roots_chebyt, sc.eval_chebyt, weightf, -1., 1., 25)
614
+ verify_gauss_quad(sc.roots_chebyt, sc.eval_chebyt, weightf, -1., 1., 100,
615
+ atol=1e-12)
616
+
617
+ x, w = sc.roots_chebyt(5, False)
618
+ y, v, m = sc.roots_chebyt(5, True)
619
+ assert_allclose(x, y, 1e-14, 1e-14)
620
+ assert_allclose(w, v, 1e-14, 1e-14)
621
+
622
+ muI, muI_err = integrate.quad(weightf, -1, 1)
623
+ assert_allclose(m, muI, rtol=muI_err)
624
+
625
+ assert_raises(ValueError, sc.roots_chebyt, 0)
626
+ assert_raises(ValueError, sc.roots_chebyt, 3.3) # type: ignore[call-overload]
627
+
628
+ def test_chebyt_symmetry():
629
+ x, w = sc.roots_chebyt(21)
630
+ pos, neg = x[:10], x[11:]
631
+ assert_equal(neg, -pos[::-1])
632
+ assert_equal(x[10], 0)
633
+
634
+ def test_roots_chebyu():
635
+ weightf = orth.chebyu(5).weight_func
636
+ verify_gauss_quad(sc.roots_chebyu, sc.eval_chebyu, weightf, -1., 1., 5)
637
+ verify_gauss_quad(sc.roots_chebyu, sc.eval_chebyu, weightf, -1., 1., 25)
638
+ verify_gauss_quad(sc.roots_chebyu, sc.eval_chebyu, weightf, -1., 1., 100)
639
+
640
+ x, w = sc.roots_chebyu(5, False)
641
+ y, v, m = sc.roots_chebyu(5, True)
642
+ assert_allclose(x, y, 1e-14, 1e-14)
643
+ assert_allclose(w, v, 1e-14, 1e-14)
644
+
645
+ muI, muI_err = integrate.quad(weightf, -1, 1)
646
+ assert_allclose(m, muI, rtol=muI_err)
647
+
648
+ assert_raises(ValueError, sc.roots_chebyu, 0)
649
+ assert_raises(ValueError, sc.roots_chebyu, 3.3) # type: ignore[call-overload]
650
+
651
+ def test_roots_chebyc():
652
+ weightf = orth.chebyc(5).weight_func
653
+ verify_gauss_quad(sc.roots_chebyc, sc.eval_chebyc, weightf, -2., 2., 5)
654
+ verify_gauss_quad(sc.roots_chebyc, sc.eval_chebyc, weightf, -2., 2., 25)
655
+ verify_gauss_quad(sc.roots_chebyc, sc.eval_chebyc, weightf, -2., 2., 100,
656
+ atol=1e-12)
657
+
658
+ x, w = sc.roots_chebyc(5, False)
659
+ y, v, m = sc.roots_chebyc(5, True)
660
+ assert_allclose(x, y, 1e-14, 1e-14)
661
+ assert_allclose(w, v, 1e-14, 1e-14)
662
+
663
+ muI, muI_err = integrate.quad(weightf, -2, 2)
664
+ assert_allclose(m, muI, rtol=muI_err)
665
+
666
+ assert_raises(ValueError, sc.roots_chebyc, 0)
667
+ assert_raises(ValueError, sc.roots_chebyc, 3.3) # type: ignore[call-overload]
668
+
669
+ def test_roots_chebys():
670
+ weightf = orth.chebys(5).weight_func
671
+ verify_gauss_quad(sc.roots_chebys, sc.eval_chebys, weightf, -2., 2., 5)
672
+ verify_gauss_quad(sc.roots_chebys, sc.eval_chebys, weightf, -2., 2., 25)
673
+ verify_gauss_quad(sc.roots_chebys, sc.eval_chebys, weightf, -2., 2., 100)
674
+
675
+ x, w = sc.roots_chebys(5, False)
676
+ y, v, m = sc.roots_chebys(5, True)
677
+ assert_allclose(x, y, 1e-14, 1e-14)
678
+ assert_allclose(w, v, 1e-14, 1e-14)
679
+
680
+ muI, muI_err = integrate.quad(weightf, -2, 2)
681
+ assert_allclose(m, muI, rtol=muI_err)
682
+
683
+ assert_raises(ValueError, sc.roots_chebys, 0)
684
+ assert_raises(ValueError, sc.roots_chebys, 3.3) # type: ignore[call-overload]
685
+
686
+ def test_roots_sh_chebyt():
687
+ weightf = orth.sh_chebyt(5).weight_func
688
+ verify_gauss_quad(sc.roots_sh_chebyt, sc.eval_sh_chebyt, weightf, 0., 1., 5)
689
+ verify_gauss_quad(sc.roots_sh_chebyt, sc.eval_sh_chebyt, weightf, 0., 1., 25)
690
+ verify_gauss_quad(sc.roots_sh_chebyt, sc.eval_sh_chebyt, weightf, 0., 1.,
691
+ 100, atol=1e-13)
692
+
693
+ x, w = sc.roots_sh_chebyt(5, False)
694
+ y, v, m = sc.roots_sh_chebyt(5, True)
695
+ assert_allclose(x, y, 1e-14, 1e-14)
696
+ assert_allclose(w, v, 1e-14, 1e-14)
697
+
698
+ muI, muI_err = integrate.quad(weightf, 0, 1)
699
+ assert_allclose(m, muI, rtol=muI_err)
700
+
701
+ assert_raises(ValueError, sc.roots_sh_chebyt, 0)
702
+ assert_raises(ValueError, sc.roots_sh_chebyt, 3.3) # type: ignore[call-overload]
703
+
704
+ def test_roots_sh_chebyu():
705
+ weightf = orth.sh_chebyu(5).weight_func
706
+ verify_gauss_quad(sc.roots_sh_chebyu, sc.eval_sh_chebyu, weightf, 0., 1., 5)
707
+ verify_gauss_quad(sc.roots_sh_chebyu, sc.eval_sh_chebyu, weightf, 0., 1., 25)
708
+ verify_gauss_quad(sc.roots_sh_chebyu, sc.eval_sh_chebyu, weightf, 0., 1.,
709
+ 100, atol=1e-13)
710
+
711
+ x, w = sc.roots_sh_chebyu(5, False)
712
+ y, v, m = sc.roots_sh_chebyu(5, True)
713
+ assert_allclose(x, y, 1e-14, 1e-14)
714
+ assert_allclose(w, v, 1e-14, 1e-14)
715
+
716
+ muI, muI_err = integrate.quad(weightf, 0, 1)
717
+ assert_allclose(m, muI, rtol=muI_err)
718
+
719
+ assert_raises(ValueError, sc.roots_sh_chebyu, 0)
720
+ assert_raises(ValueError, sc.roots_sh_chebyu, 3.3) # type: ignore[call-overload]
721
+
722
+ def test_roots_legendre():
723
+ weightf = orth.legendre(5).weight_func
724
+ verify_gauss_quad(sc.roots_legendre, sc.eval_legendre, weightf, -1., 1., 5)
725
+ verify_gauss_quad(sc.roots_legendre, sc.eval_legendre, weightf, -1., 1.,
726
+ 25, atol=1e-13)
727
+ verify_gauss_quad(sc.roots_legendre, sc.eval_legendre, weightf, -1., 1.,
728
+ 100, atol=1e-12)
729
+
730
+ x, w = sc.roots_legendre(5, False)
731
+ y, v, m = sc.roots_legendre(5, True)
732
+ assert_allclose(x, y, 1e-14, 1e-14)
733
+ assert_allclose(w, v, 1e-14, 1e-14)
734
+
735
+ muI, muI_err = integrate.quad(weightf, -1, 1)
736
+ assert_allclose(m, muI, rtol=muI_err)
737
+
738
+ assert_raises(ValueError, sc.roots_legendre, 0)
739
+ assert_raises(ValueError, sc.roots_legendre, 3.3) # type: ignore[call-overload]
740
+
741
+ def test_roots_sh_legendre():
742
+ weightf = orth.sh_legendre(5).weight_func
743
+ verify_gauss_quad(sc.roots_sh_legendre, sc.eval_sh_legendre, weightf, 0., 1., 5)
744
+ verify_gauss_quad(sc.roots_sh_legendre, sc.eval_sh_legendre, weightf, 0., 1.,
745
+ 25, atol=1e-13)
746
+ verify_gauss_quad(sc.roots_sh_legendre, sc.eval_sh_legendre, weightf, 0., 1.,
747
+ 100, atol=1e-12)
748
+
749
+ x, w = sc.roots_sh_legendre(5, False)
750
+ y, v, m = sc.roots_sh_legendre(5, True)
751
+ assert_allclose(x, y, 1e-14, 1e-14)
752
+ assert_allclose(w, v, 1e-14, 1e-14)
753
+
754
+ muI, muI_err = integrate.quad(weightf, 0, 1)
755
+ assert_allclose(m, muI, rtol=muI_err)
756
+
757
+ assert_raises(ValueError, sc.roots_sh_legendre, 0)
758
+ assert_raises(ValueError, sc.roots_sh_legendre, 3.3) # type: ignore[call-overload]
759
+
760
+ def test_roots_laguerre():
761
+ weightf = orth.laguerre(5).weight_func
762
+ verify_gauss_quad(sc.roots_laguerre, sc.eval_laguerre, weightf, 0., np.inf, 5)
763
+ verify_gauss_quad(sc.roots_laguerre, sc.eval_laguerre, weightf, 0., np.inf,
764
+ 25, atol=1e-13)
765
+ verify_gauss_quad(sc.roots_laguerre, sc.eval_laguerre, weightf, 0., np.inf,
766
+ 100, atol=1e-12)
767
+
768
+ x, w = sc.roots_laguerre(5, False)
769
+ y, v, m = sc.roots_laguerre(5, True)
770
+ assert_allclose(x, y, 1e-14, 1e-14)
771
+ assert_allclose(w, v, 1e-14, 1e-14)
772
+
773
+ muI, muI_err = integrate.quad(weightf, 0, np.inf)
774
+ assert_allclose(m, muI, rtol=muI_err)
775
+
776
+ assert_raises(ValueError, sc.roots_laguerre, 0)
777
+ assert_raises(ValueError, sc.roots_laguerre, 3.3) # type: ignore[call-overload]
778
+
779
+ def test_roots_genlaguerre():
780
+ def rootf(a):
781
+ return lambda n, mu: sc.roots_genlaguerre(n, a, mu)
782
+ def evalf(a):
783
+ return lambda n, x: sc.eval_genlaguerre(n, a, x)
784
+ def weightf(a):
785
+ return lambda x: x ** a * np.exp(-x)
786
+
787
+ vgq = verify_gauss_quad
788
+ vgq(rootf(-0.5), evalf(-0.5), weightf(-0.5), 0., np.inf, 5)
789
+ vgq(rootf(-0.5), evalf(-0.5), weightf(-0.5), 0., np.inf, 25, atol=1e-13)
790
+ vgq(rootf(-0.5), evalf(-0.5), weightf(-0.5), 0., np.inf, 100, atol=1e-12)
791
+
792
+ vgq(rootf(0.1), evalf(0.1), weightf(0.1), 0., np.inf, 5)
793
+ vgq(rootf(0.1), evalf(0.1), weightf(0.1), 0., np.inf, 25, atol=1e-13)
794
+ vgq(rootf(0.1), evalf(0.1), weightf(0.1), 0., np.inf, 100, atol=1.6e-13)
795
+
796
+ vgq(rootf(1), evalf(1), weightf(1), 0., np.inf, 5)
797
+ vgq(rootf(1), evalf(1), weightf(1), 0., np.inf, 25, atol=1e-13)
798
+ vgq(rootf(1), evalf(1), weightf(1), 0., np.inf, 100, atol=1.03e-13)
799
+
800
+ vgq(rootf(10), evalf(10), weightf(10), 0., np.inf, 5)
801
+ vgq(rootf(10), evalf(10), weightf(10), 0., np.inf, 25, atol=1e-13)
802
+ vgq(rootf(10), evalf(10), weightf(10), 0., np.inf, 100, atol=1e-12)
803
+
804
+ vgq(rootf(50), evalf(50), weightf(50), 0., np.inf, 5)
805
+ vgq(rootf(50), evalf(50), weightf(50), 0., np.inf, 25, atol=1e-13)
806
+ vgq(rootf(50), evalf(50), weightf(50), 0., np.inf, 100, rtol=1e-14, atol=2e-13)
807
+
808
+ x, w = sc.roots_genlaguerre(5, 2, False)
809
+ y, v, m = sc.roots_genlaguerre(5, 2, True)
810
+ assert_allclose(x, y, 1e-14, 1e-14)
811
+ assert_allclose(w, v, 1e-14, 1e-14)
812
+
813
+ muI, muI_err = integrate.quad(weightf(2.), 0., np.inf)
814
+ assert_allclose(m, muI, rtol=muI_err)
815
+
816
+ assert_raises(ValueError, sc.roots_genlaguerre, 0, 2)
817
+ assert_raises(ValueError, sc.roots_genlaguerre, 3.3, 2) # type: ignore[call-overload]
818
+ assert_raises(ValueError, sc.roots_genlaguerre, 3, -1.1)
819
+
820
+
821
+ def test_gh_6721():
822
+ # Regression test for gh_6721. This should not raise.
823
+ sc.chebyt(65)(0.2)
.venv/lib/python3.12/site-packages/scipy/special/tests/test_orthogonal_eval.py ADDED
@@ -0,0 +1,383 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ from numpy.testing import assert_, assert_allclose
3
+ import pytest
4
+
5
+ from scipy.special import _ufuncs, gammasgn
6
+ import scipy.special._orthogonal as orth
7
+ from scipy.special._testutils import FuncData
8
+
9
+
10
+ def test_eval_chebyt():
11
+ n = np.arange(0, 10000, 7, dtype=np.dtype("long"))
12
+ x = 2*np.random.rand() - 1
13
+ v1 = np.cos(n*np.arccos(x))
14
+ v2 = _ufuncs.eval_chebyt(n, x)
15
+ assert_(np.allclose(v1, v2, rtol=1e-15))
16
+
17
+
18
+ def test_eval_chebyt_gh20129():
19
+ # https://github.com/scipy/scipy/issues/20129
20
+ assert _ufuncs.eval_chebyt(7, 2 + 0j) == 5042.0
21
+
22
+
23
+ def test_eval_genlaguerre_restriction():
24
+ # check it returns nan for alpha <= -1
25
+ assert_(np.isnan(_ufuncs.eval_genlaguerre(0, -1, 0)))
26
+ assert_(np.isnan(_ufuncs.eval_genlaguerre(0.1, -1, 0)))
27
+
28
+
29
+ def test_warnings():
30
+ # ticket 1334
31
+ with np.errstate(all='raise'):
32
+ # these should raise no fp warnings
33
+ _ufuncs.eval_legendre(1, 0)
34
+ _ufuncs.eval_laguerre(1, 1)
35
+ _ufuncs.eval_gegenbauer(1, 1, 0)
36
+
37
+
38
+ class TestPolys:
39
+ """
40
+ Check that the eval_* functions agree with the constructed polynomials
41
+
42
+ """
43
+
44
+ def check_poly(self, func, cls, param_ranges=(), x_range=(), nn=10,
45
+ nparam=10, nx=10, rtol=1e-8):
46
+ rng = np.random.RandomState(1234)
47
+
48
+ dataset = []
49
+ for n in np.arange(nn):
50
+ params = [a + (b-a)*rng.rand(nparam) for a,b in param_ranges]
51
+ params = np.asarray(params).T
52
+ if not param_ranges:
53
+ params = [0]
54
+ for p in params:
55
+ if param_ranges:
56
+ p = (n,) + tuple(p)
57
+ else:
58
+ p = (n,)
59
+ x = x_range[0] + (x_range[1] - x_range[0])*rng.rand(nx)
60
+ x[0] = x_range[0] # always include domain start point
61
+ x[1] = x_range[1] # always include domain end point
62
+ poly = np.poly1d(cls(*p).coef)
63
+ z = np.c_[np.tile(p, (nx,1)), x, poly(x)]
64
+ dataset.append(z)
65
+
66
+ dataset = np.concatenate(dataset, axis=0)
67
+
68
+ def polyfunc(*p):
69
+ p = (p[0].astype(np.dtype("long")),) + p[1:]
70
+ return func(*p)
71
+
72
+ with np.errstate(all='raise'):
73
+ ds = FuncData(polyfunc, dataset, list(range(len(param_ranges)+2)), -1,
74
+ rtol=rtol)
75
+ ds.check()
76
+
77
+ def test_jacobi(self):
78
+ self.check_poly(_ufuncs.eval_jacobi, orth.jacobi,
79
+ param_ranges=[(-0.99, 10), (-0.99, 10)],
80
+ x_range=[-1, 1], rtol=1e-5)
81
+
82
+ def test_sh_jacobi(self):
83
+ self.check_poly(_ufuncs.eval_sh_jacobi, orth.sh_jacobi,
84
+ param_ranges=[(1, 10), (0, 1)], x_range=[0, 1],
85
+ rtol=1e-5)
86
+
87
+ def test_gegenbauer(self):
88
+ self.check_poly(_ufuncs.eval_gegenbauer, orth.gegenbauer,
89
+ param_ranges=[(-0.499, 10)], x_range=[-1, 1],
90
+ rtol=1e-7)
91
+
92
+ def test_chebyt(self):
93
+ self.check_poly(_ufuncs.eval_chebyt, orth.chebyt,
94
+ param_ranges=[], x_range=[-1, 1])
95
+
96
+ def test_chebyu(self):
97
+ self.check_poly(_ufuncs.eval_chebyu, orth.chebyu,
98
+ param_ranges=[], x_range=[-1, 1])
99
+
100
+ def test_chebys(self):
101
+ self.check_poly(_ufuncs.eval_chebys, orth.chebys,
102
+ param_ranges=[], x_range=[-2, 2])
103
+
104
+ def test_chebyc(self):
105
+ self.check_poly(_ufuncs.eval_chebyc, orth.chebyc,
106
+ param_ranges=[], x_range=[-2, 2])
107
+
108
+ def test_sh_chebyt(self):
109
+ with np.errstate(all='ignore'):
110
+ self.check_poly(_ufuncs.eval_sh_chebyt, orth.sh_chebyt,
111
+ param_ranges=[], x_range=[0, 1])
112
+
113
+ def test_sh_chebyu(self):
114
+ self.check_poly(_ufuncs.eval_sh_chebyu, orth.sh_chebyu,
115
+ param_ranges=[], x_range=[0, 1])
116
+
117
+ def test_legendre(self):
118
+ self.check_poly(_ufuncs.eval_legendre, orth.legendre,
119
+ param_ranges=[], x_range=[-1, 1])
120
+
121
+ def test_sh_legendre(self):
122
+ with np.errstate(all='ignore'):
123
+ self.check_poly(_ufuncs.eval_sh_legendre, orth.sh_legendre,
124
+ param_ranges=[], x_range=[0, 1])
125
+
126
+ def test_genlaguerre(self):
127
+ self.check_poly(_ufuncs.eval_genlaguerre, orth.genlaguerre,
128
+ param_ranges=[(-0.99, 10)], x_range=[0, 100])
129
+
130
+ def test_laguerre(self):
131
+ self.check_poly(_ufuncs.eval_laguerre, orth.laguerre,
132
+ param_ranges=[], x_range=[0, 100])
133
+
134
+ def test_hermite(self):
135
+ self.check_poly(_ufuncs.eval_hermite, orth.hermite,
136
+ param_ranges=[], x_range=[-100, 100])
137
+
138
+ def test_hermitenorm(self):
139
+ self.check_poly(_ufuncs.eval_hermitenorm, orth.hermitenorm,
140
+ param_ranges=[], x_range=[-100, 100])
141
+
142
+
143
+ class TestRecurrence:
144
+ """
145
+ Check that the eval_* functions sig='ld->d' and 'dd->d' agree.
146
+
147
+ """
148
+
149
+ def check_poly(self, func, param_ranges=(), x_range=(), nn=10,
150
+ nparam=10, nx=10, rtol=1e-8):
151
+ rng = np.random.default_rng(1234)
152
+
153
+ dataset = []
154
+ for n in np.arange(nn):
155
+ params = [a + (b-a)*rng.random(nparam) for a,b in param_ranges]
156
+ params = np.asarray(params).T
157
+ if not param_ranges:
158
+ params = [0]
159
+ for p in params:
160
+ if param_ranges:
161
+ p = (n,) + tuple(p)
162
+ else:
163
+ p = (n,)
164
+ x = x_range[0] + (x_range[1] - x_range[0])*rng.random(nx)
165
+ x[0] = x_range[0] # always include domain start point
166
+ x[1] = x_range[1] # always include domain end point
167
+ kw = dict(sig=(len(p)+1)*'d'+'->d')
168
+ z = np.c_[np.tile(p, (nx,1)), x, func(*(p + (x,)), **kw)]
169
+ dataset.append(z)
170
+
171
+ dataset = np.concatenate(dataset, axis=0)
172
+
173
+ def polyfunc(*p):
174
+ p0 = p[0].astype(np.intp)
175
+ p = (p0,) + p[1:]
176
+ p0_type_char = p0.dtype.char
177
+ kw = dict(sig=p0_type_char + (len(p)-1)*'d' + '->d')
178
+ return func(*p, **kw)
179
+
180
+ with np.errstate(all='raise'):
181
+ ds = FuncData(polyfunc, dataset, list(range(len(param_ranges)+2)), -1,
182
+ rtol=rtol)
183
+ ds.check()
184
+
185
+ def test_jacobi(self):
186
+ self.check_poly(_ufuncs.eval_jacobi,
187
+ param_ranges=[(-0.99, 10), (-0.99, 10)],
188
+ x_range=[-1, 1])
189
+
190
+ def test_sh_jacobi(self):
191
+ self.check_poly(_ufuncs.eval_sh_jacobi,
192
+ param_ranges=[(1, 10), (0, 1)], x_range=[0, 1])
193
+
194
+ def test_gegenbauer(self):
195
+ self.check_poly(_ufuncs.eval_gegenbauer,
196
+ param_ranges=[(-0.499, 10)], x_range=[-1, 1])
197
+
198
+ def test_chebyt(self):
199
+ self.check_poly(_ufuncs.eval_chebyt,
200
+ param_ranges=[], x_range=[-1, 1])
201
+
202
+ def test_chebyu(self):
203
+ self.check_poly(_ufuncs.eval_chebyu,
204
+ param_ranges=[], x_range=[-1, 1])
205
+
206
+ def test_chebys(self):
207
+ self.check_poly(_ufuncs.eval_chebys,
208
+ param_ranges=[], x_range=[-2, 2])
209
+
210
+ def test_chebyc(self):
211
+ self.check_poly(_ufuncs.eval_chebyc,
212
+ param_ranges=[], x_range=[-2, 2])
213
+
214
+ def test_sh_chebyt(self):
215
+ self.check_poly(_ufuncs.eval_sh_chebyt,
216
+ param_ranges=[], x_range=[0, 1])
217
+
218
+ def test_sh_chebyu(self):
219
+ self.check_poly(_ufuncs.eval_sh_chebyu,
220
+ param_ranges=[], x_range=[0, 1])
221
+
222
+ def test_legendre(self):
223
+ self.check_poly(_ufuncs.eval_legendre,
224
+ param_ranges=[], x_range=[-1, 1])
225
+
226
+ def test_sh_legendre(self):
227
+ self.check_poly(_ufuncs.eval_sh_legendre,
228
+ param_ranges=[], x_range=[0, 1])
229
+
230
+ def test_genlaguerre(self):
231
+ self.check_poly(_ufuncs.eval_genlaguerre,
232
+ param_ranges=[(-0.99, 10)], x_range=[0, 100])
233
+
234
+ def test_laguerre(self):
235
+ self.check_poly(_ufuncs.eval_laguerre,
236
+ param_ranges=[], x_range=[0, 100])
237
+
238
+ def test_hermite(self):
239
+ v = _ufuncs.eval_hermite(70, 1.0)
240
+ a = -1.457076485701412e60
241
+ assert_allclose(v, a)
242
+
243
+
244
+ def test_hermite_domain():
245
+ # Regression test for gh-11091.
246
+ assert np.isnan(_ufuncs.eval_hermite(-1, 1.0))
247
+ assert np.isnan(_ufuncs.eval_hermitenorm(-1, 1.0))
248
+
249
+
250
+ @pytest.mark.parametrize("n", [0, 1, 2])
251
+ @pytest.mark.parametrize("x", [0, 1, np.nan])
252
+ def test_hermite_nan(n, x):
253
+ # Regression test for gh-11369.
254
+ assert np.isnan(_ufuncs.eval_hermite(n, x)) == np.any(np.isnan([n, x]))
255
+ assert np.isnan(_ufuncs.eval_hermitenorm(n, x)) == np.any(np.isnan([n, x]))
256
+
257
+
258
+ @pytest.mark.parametrize('n', [0, 1, 2, 3.2])
259
+ @pytest.mark.parametrize('alpha', [1, np.nan])
260
+ @pytest.mark.parametrize('x', [2, np.nan])
261
+ def test_genlaguerre_nan(n, alpha, x):
262
+ # Regression test for gh-11361.
263
+ nan_laguerre = np.isnan(_ufuncs.eval_genlaguerre(n, alpha, x))
264
+ nan_arg = np.any(np.isnan([n, alpha, x]))
265
+ assert nan_laguerre == nan_arg
266
+
267
+
268
+ @pytest.mark.parametrize('n', [0, 1, 2, 3.2, np.nan])
269
+ @pytest.mark.parametrize('alpha', [0.0, 1, np.nan])
270
+ @pytest.mark.parametrize('x', [1e-6, 2, np.nan])
271
+ def test_gegenbauer_nan(n, alpha, x):
272
+ # Regression test for gh-11370.
273
+ nan_gegenbauer = np.isnan(_ufuncs.eval_gegenbauer(n, alpha, x))
274
+ nan_arg = np.any(np.isnan([n, alpha, x]))
275
+ assert nan_gegenbauer == nan_arg
276
+
277
+ @pytest.mark.parametrize("n", np.arange(10))
278
+ @pytest.mark.parametrize("alpha", [-0.45, -0.25, -0.125, 0.0, 0.25, 1.0, 2.0])
279
+ @pytest.mark.parametrize("x", [-np.inf, np.inf])
280
+ def test_gegenbauer_infinity(n, alpha, x):
281
+ # gh-11713 - check correct handling of x = +inf and x = -inf
282
+ if alpha == 0.0:
283
+ expected = 0.0
284
+ elif n == 0.0:
285
+ expected = 1.0
286
+ else:
287
+ # sign of leading coefficient: 2^n * Gamma(n+alpha) / (n! Gamma(alpha))
288
+ lead_sign = gammasgn(n + alpha) * gammasgn(alpha)
289
+ expected = lead_sign * (np.sign(x) ** n) * np.inf
290
+ assert_allclose(_ufuncs.eval_gegenbauer(int(n), alpha, x), expected, rtol=1e-10)
291
+ assert_allclose(_ufuncs.eval_gegenbauer(float(n), alpha, x), expected, rtol=1e-10)
292
+
293
+ @pytest.mark.parametrize(
294
+ "n, expected",
295
+ [
296
+ (0, [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]),
297
+ (1, [-2.0, -1.8, -1.6, -1.4, -1.2, -1.0, -0.8, -0.6, -0.4, -0.2, 0.0]),
298
+ (2, [3.0, 2.16, 1.44, 0.84, 0.36, 0.0, -0.24, -0.36, -0.36, -0.24, 0.0]),
299
+ (3, [-4.0, -1.98, -0.64, 0.14, 0.48, 0.5, 0.32, 0.06, -0.16, -0.22, 0.0]),
300
+ (
301
+ 4,
302
+ [5.0, 1.332, -0.288, -0.658, -0.408, 0.0, 0.272, 0.282, 0.072, -0.148, 0.0],
303
+ ),
304
+ (
305
+ 5,
306
+ [
307
+ -6.0,
308
+ -0.43308,
309
+ 0.79104,
310
+ 0.36876,
311
+ -0.21312,
312
+ -0.375,
313
+ -0.14208,
314
+ 0.15804,
315
+ 0.19776,
316
+ -0.04812,
317
+ 0.0,
318
+ ],
319
+ ),
320
+ ],
321
+ )
322
+ def test_jacobi_alpha_minus_one_beta_plus_one(n, expected):
323
+ # gh-7001 - expected values were computed with mathematica
324
+ x = np.linspace(-1.0, 1.0, 11)
325
+ a, b = -1, 1 # alpha, beta
326
+ assert_allclose(_ufuncs.eval_jacobi(n, a, b, x), expected, rtol=1e-10, atol=1e-14)
327
+ assert_allclose(
328
+ _ufuncs.eval_jacobi(float(n), a, b, x), expected, rtol=1e-10, atol=1e-14
329
+ )
330
+
331
+
332
+ @pytest.mark.parametrize(
333
+ "n, expected",
334
+ [
335
+ (0, [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]),
336
+ (1, [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]),
337
+ (2, [0.0, -0.09, -0.16, -0.21, -0.24, -0.25, -0.24, -0.21, -0.16, -0.09, 0.0]),
338
+ (
339
+ 3,
340
+ [0.0, 0.144, 0.192, 0.168, 0.096, 0.0, -0.096, -0.168, -0.192, -0.144, 0.0],
341
+ ),
342
+ (
343
+ 4,
344
+ [
345
+ 0.0,
346
+ -0.1485,
347
+ -0.096,
348
+ 0.0315,
349
+ 0.144,
350
+ 0.1875,
351
+ 0.144,
352
+ 0.0315,
353
+ -0.096,
354
+ -0.1485,
355
+ 0.0,
356
+ ],
357
+ ),
358
+ (
359
+ 5,
360
+ [
361
+ 0.0,
362
+ 0.10656,
363
+ -0.04608,
364
+ -0.15792,
365
+ -0.13056,
366
+ 0.0,
367
+ 0.13056,
368
+ 0.15792,
369
+ 0.04608,
370
+ -0.10656,
371
+ 0.0,
372
+ ],
373
+ ),
374
+ ],
375
+ )
376
+ def test_jacobi_alpha_minus_one_beta_minus_one(n, expected):
377
+ # gh-7001 - expected values were computed with mathematica
378
+ x = np.linspace(-1.0, 1.0, 11)
379
+ a, b = -1, -1 # alpha, beta
380
+ assert_allclose(_ufuncs.eval_jacobi(n, a, b, x), expected, rtol=1e-10, atol=1e-14)
381
+ assert_allclose(
382
+ _ufuncs.eval_jacobi(float(n), a, b, x), expected, rtol=1e-10, atol=1e-14
383
+ )
.venv/lib/python3.12/site-packages/scipy/special/tests/test_owens_t.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ from numpy.testing import assert_equal, assert_allclose
3
+
4
+ import scipy.special as sc
5
+
6
+
7
+ def test_symmetries():
8
+ np.random.seed(1234)
9
+ a, h = np.random.rand(100), np.random.rand(100)
10
+ assert_equal(sc.owens_t(h, a), sc.owens_t(-h, a))
11
+ assert_equal(sc.owens_t(h, a), -sc.owens_t(h, -a))
12
+
13
+
14
+ def test_special_cases():
15
+ assert_equal(sc.owens_t(5, 0), 0)
16
+ assert_allclose(sc.owens_t(0, 5), 0.5*np.arctan(5)/np.pi,
17
+ rtol=5e-14)
18
+ # Target value is 0.5*Phi(5)*(1 - Phi(5)) for Phi the CDF of the
19
+ # standard normal distribution
20
+ assert_allclose(sc.owens_t(5, 1), 1.4332574485503512543e-07,
21
+ rtol=5e-14)
22
+
23
+
24
+ def test_nans():
25
+ assert_equal(sc.owens_t(20, np.nan), np.nan)
26
+ assert_equal(sc.owens_t(np.nan, 20), np.nan)
27
+ assert_equal(sc.owens_t(np.nan, np.nan), np.nan)
28
+
29
+
30
+ def test_infs():
31
+ h, a = 0, np.inf
32
+ # T(0, a) = 1/2π * arctan(a)
33
+ res = 1/(2*np.pi) * np.arctan(a)
34
+ assert_allclose(sc.owens_t(h, a), res, rtol=5e-14)
35
+ assert_allclose(sc.owens_t(h, -a), -res, rtol=5e-14)
36
+
37
+ h = 1
38
+ # Refer Owens T function definition in Wikipedia
39
+ # https://en.wikipedia.org/wiki/Owen%27s_T_function
40
+ # Value approximated through Numerical Integration
41
+ # using scipy.integrate.quad
42
+ # quad(lambda x: 1/(2*pi)*(exp(-0.5*(1*1)*(1+x*x))/(1+x*x)), 0, inf)
43
+ res = 0.07932762696572854
44
+ assert_allclose(sc.owens_t(h, np.inf), res, rtol=5e-14)
45
+ assert_allclose(sc.owens_t(h, -np.inf), -res, rtol=5e-14)
46
+
47
+ assert_equal(sc.owens_t(np.inf, 1), 0)
48
+ assert_equal(sc.owens_t(-np.inf, 1), 0)
49
+
50
+ assert_equal(sc.owens_t(np.inf, np.inf), 0)
51
+ assert_equal(sc.owens_t(-np.inf, np.inf), 0)
52
+ assert_equal(sc.owens_t(np.inf, -np.inf), -0.0)
53
+ assert_equal(sc.owens_t(-np.inf, -np.inf), -0.0)
.venv/lib/python3.12/site-packages/scipy/special/tests/test_pcf.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Tests for parabolic cylinder functions.
2
+
3
+ """
4
+ import numpy as np
5
+ from numpy.testing import assert_allclose, assert_equal
6
+ import scipy.special as sc
7
+
8
+
9
+ def test_pbwa_segfault():
10
+ # Regression test for https://github.com/scipy/scipy/issues/6208.
11
+ #
12
+ # Data generated by mpmath.
13
+ #
14
+ w = 1.02276567211316867161
15
+ wp = -0.48887053372346189882
16
+ assert_allclose(sc.pbwa(0, 0), (w, wp), rtol=1e-13, atol=0)
17
+
18
+
19
+ def test_pbwa_nan():
20
+ # Check that NaN's are returned outside of the range in which the
21
+ # implementation is accurate.
22
+ pts = [(-6, -6), (-6, 6), (6, -6), (6, 6)]
23
+ for p in pts:
24
+ assert_equal(sc.pbwa(*p), (np.nan, np.nan))
.venv/lib/python3.12/site-packages/scipy/special/tests/test_pdtr.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import scipy.special as sc
3
+ from numpy.testing import assert_allclose, assert_array_equal
4
+
5
+
6
+ class TestPdtr:
7
+ def test(self):
8
+ val = sc.pdtr(0, 1)
9
+ assert_allclose(val, np.exp(-1), atol=1.5e-7, rtol=0)
10
+
11
+ def test_m_zero(self):
12
+ val = sc.pdtr([0, 1, 2], 0)
13
+ assert_allclose(val, [1, 1, 1], atol=1.5e-7, rtol=0)
14
+
15
+ def test_rounding(self):
16
+ double_val = sc.pdtr([0.1, 1.1, 2.1], 1.0)
17
+ int_val = sc.pdtr([0, 1, 2], 1.0)
18
+ assert_array_equal(double_val, int_val)
19
+
20
+ def test_inf(self):
21
+ val = sc.pdtr(np.inf, 1.0)
22
+ assert_allclose(val, 1.0, atol=1.5e-7, rtol=0)
23
+
24
+ def test_domain(self):
25
+ val = sc.pdtr(-1.1, 1.0)
26
+ assert np.isnan(val)
27
+
28
+ class TestPdtrc:
29
+ def test_value(self):
30
+ val = sc.pdtrc(0, 1)
31
+ assert_allclose(val, 1 - np.exp(-1), atol=1.5e-7, rtol=0)
32
+
33
+ def test_m_zero(self):
34
+ val = sc.pdtrc([0, 1, 2], 0.0)
35
+ assert_array_equal(val, [0, 0, 0])
36
+
37
+ def test_rounding(self):
38
+ double_val = sc.pdtrc([0.1, 1.1, 2.1], 1.0)
39
+ int_val = sc.pdtrc([0, 1, 2], 1.0)
40
+ assert_array_equal(double_val, int_val)
41
+
42
+ def test_inf(self):
43
+ val = sc.pdtrc(np.inf, 1.0)
44
+ assert_allclose(val, 0.0, atol=1.5e-7, rtol=0)
45
+
46
+ def test_domain(self):
47
+ val = sc.pdtrc(-1.1, 1.0)
48
+ assert np.isnan(val)
.venv/lib/python3.12/site-packages/scipy/special/tests/test_powm1.py ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pytest
2
+ import numpy as np
3
+ from numpy.testing import assert_allclose
4
+ from scipy.special import powm1
5
+
6
+
7
+ # Expected values were computed with mpmath, e.g.
8
+ #
9
+ # >>> import mpmath
10
+ # >>> mpmath.np.dps = 200
11
+ # >>> print(float(mpmath.powm1(2.0, 1e-7))
12
+ # 6.931472045825965e-08
13
+ #
14
+ powm1_test_cases = [
15
+ (1.25, 0.75, 0.18217701125396976, 1e-15),
16
+ (2.0, 1e-7, 6.931472045825965e-08, 1e-15),
17
+ (25.0, 5e-11, 1.6094379125636148e-10, 1e-15),
18
+ (0.99996, 0.75, -3.0000150002530058e-05, 1e-15),
19
+ (0.9999999999990905, 20, -1.81898940353014e-11, 1e-15),
20
+ (-1.25, 751.0, -6.017550852453444e+72, 2e-15)
21
+ ]
22
+
23
+
24
+ @pytest.mark.parametrize('x, y, expected, rtol', powm1_test_cases)
25
+ def test_powm1(x, y, expected, rtol):
26
+ p = powm1(x, y)
27
+ assert_allclose(p, expected, rtol=rtol)
28
+
29
+
30
+ @pytest.mark.parametrize('x, y, expected',
31
+ [(0.0, 0.0, 0.0),
32
+ (0.0, -1.5, np.inf),
33
+ (0.0, 1.75, -1.0),
34
+ (-1.5, 2.0, 1.25),
35
+ (-1.5, 3.0, -4.375),
36
+ (np.nan, 0.0, 0.0),
37
+ (1.0, np.nan, 0.0),
38
+ (1.0, np.inf, 0.0),
39
+ (1.0, -np.inf, 0.0),
40
+ (np.inf, 7.5, np.inf),
41
+ (np.inf, -7.5, -1.0),
42
+ (3.25, np.inf, np.inf),
43
+ (np.inf, np.inf, np.inf),
44
+ (np.inf, -np.inf, -1.0),
45
+ (np.inf, 0.0, 0.0),
46
+ (-np.inf, 0.0, 0.0),
47
+ (-np.inf, 2.0, np.inf),
48
+ (-np.inf, 3.0, -np.inf),
49
+ (-1.0, float(2**53 - 1), -2.0)])
50
+ def test_powm1_exact_cases(x, y, expected):
51
+ # Test cases where we have an exact expected value.
52
+ p = powm1(x, y)
53
+ assert p == expected
54
+
55
+
56
+ @pytest.mark.parametrize('x, y',
57
+ [(-1.25, 751.03),
58
+ (-1.25, np.inf),
59
+ (np.nan, np.nan),
60
+ (-np.inf, -np.inf),
61
+ (-np.inf, 2.5)])
62
+ def test_powm1_return_nan(x, y):
63
+ # Test cases where the expected return value is nan.
64
+ p = powm1(x, y)
65
+ assert np.isnan(p)
.venv/lib/python3.12/site-packages/scipy/special/tests/test_precompute_expn_asy.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from numpy.testing import assert_equal
2
+
3
+ from scipy.special._testutils import check_version, MissingModule
4
+ from scipy.special._precompute.expn_asy import generate_A
5
+
6
+ try:
7
+ import sympy
8
+ from sympy import Poly
9
+ except ImportError:
10
+ sympy = MissingModule("sympy")
11
+
12
+
13
+ @check_version(sympy, "1.0")
14
+ def test_generate_A():
15
+ # Data from DLMF 8.20.5
16
+ x = sympy.symbols('x')
17
+ Astd = [Poly(1, x),
18
+ Poly(1, x),
19
+ Poly(1 - 2*x),
20
+ Poly(1 - 8*x + 6*x**2)]
21
+ Ares = generate_A(len(Astd))
22
+
23
+ for p, q in zip(Astd, Ares):
24
+ assert_equal(p, q)
.venv/lib/python3.12/site-packages/scipy/special/tests/test_precompute_gammainc.py ADDED
@@ -0,0 +1,112 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pytest
2
+
3
+ from scipy.special._testutils import MissingModule, check_version
4
+ from scipy.special._mptestutils import (
5
+ Arg, IntArg, mp_assert_allclose, assert_mpmath_equal)
6
+ from scipy.special._precompute.gammainc_asy import (
7
+ compute_g, compute_alpha, compute_d)
8
+ from scipy.special._precompute.gammainc_data import gammainc, gammaincc
9
+
10
+ try:
11
+ import sympy
12
+ except ImportError:
13
+ sympy = MissingModule('sympy')
14
+
15
+ try:
16
+ import mpmath as mp
17
+ except ImportError:
18
+ mp = MissingModule('mpmath')
19
+
20
+
21
+ pytestmark = pytest.mark.thread_unsafe(
22
+ reason=("mpmath gmpy2 backend is not thread-safe, "
23
+ "see https://github.com/mpmath/mpmath/issues/974"))
24
+
25
+ @check_version(mp, '0.19')
26
+ def test_g():
27
+ # Test data for the g_k. See DLMF 5.11.4.
28
+ with mp.workdps(30):
29
+ g = [mp.mpf(1), mp.mpf(1)/12, mp.mpf(1)/288,
30
+ -mp.mpf(139)/51840, -mp.mpf(571)/2488320,
31
+ mp.mpf(163879)/209018880, mp.mpf(5246819)/75246796800]
32
+ mp_assert_allclose(compute_g(7), g)
33
+
34
+
35
+ @pytest.mark.slow
36
+ @check_version(mp, '0.19')
37
+ @check_version(sympy, '0.7')
38
+ @pytest.mark.xfail_on_32bit("rtol only 2e-11, see gh-6938")
39
+ def test_alpha():
40
+ # Test data for the alpha_k. See DLMF 8.12.14.
41
+ with mp.workdps(30):
42
+ alpha = [mp.mpf(0), mp.mpf(1), mp.mpf(1)/3, mp.mpf(1)/36,
43
+ -mp.mpf(1)/270, mp.mpf(1)/4320, mp.mpf(1)/17010,
44
+ -mp.mpf(139)/5443200, mp.mpf(1)/204120]
45
+ mp_assert_allclose(compute_alpha(9), alpha)
46
+
47
+
48
+ @pytest.mark.xslow
49
+ @check_version(mp, '0.19')
50
+ @check_version(sympy, '0.7')
51
+ def test_d():
52
+ # Compare the d_{k, n} to the results in appendix F of [1].
53
+ #
54
+ # Sources
55
+ # -------
56
+ # [1] DiDonato and Morris, Computation of the Incomplete Gamma
57
+ # Function Ratios and their Inverse, ACM Transactions on
58
+ # Mathematical Software, 1986.
59
+
60
+ with mp.workdps(50):
61
+ dataset = [(0, 0, -mp.mpf('0.333333333333333333333333333333')),
62
+ (0, 12, mp.mpf('0.102618097842403080425739573227e-7')),
63
+ (1, 0, -mp.mpf('0.185185185185185185185185185185e-2')),
64
+ (1, 12, mp.mpf('0.119516285997781473243076536700e-7')),
65
+ (2, 0, mp.mpf('0.413359788359788359788359788360e-2')),
66
+ (2, 12, -mp.mpf('0.140925299108675210532930244154e-7')),
67
+ (3, 0, mp.mpf('0.649434156378600823045267489712e-3')),
68
+ (3, 12, -mp.mpf('0.191111684859736540606728140873e-7')),
69
+ (4, 0, -mp.mpf('0.861888290916711698604702719929e-3')),
70
+ (4, 12, mp.mpf('0.288658297427087836297341274604e-7')),
71
+ (5, 0, -mp.mpf('0.336798553366358150308767592718e-3')),
72
+ (5, 12, mp.mpf('0.482409670378941807563762631739e-7')),
73
+ (6, 0, mp.mpf('0.531307936463992223165748542978e-3')),
74
+ (6, 12, -mp.mpf('0.882860074633048352505085243179e-7')),
75
+ (7, 0, mp.mpf('0.344367606892377671254279625109e-3')),
76
+ (7, 12, -mp.mpf('0.175629733590604619378669693914e-6')),
77
+ (8, 0, -mp.mpf('0.652623918595309418922034919727e-3')),
78
+ (8, 12, mp.mpf('0.377358774161109793380344937299e-6')),
79
+ (9, 0, -mp.mpf('0.596761290192746250124390067179e-3')),
80
+ (9, 12, mp.mpf('0.870823417786464116761231237189e-6'))]
81
+ d = compute_d(10, 13)
82
+ res = [d[k][n] for k, n, std in dataset]
83
+ std = [x[2] for x in dataset]
84
+ mp_assert_allclose(res, std)
85
+
86
+
87
+ @check_version(mp, '0.19')
88
+ def test_gammainc():
89
+ # Quick check that the gammainc in
90
+ # special._precompute.gammainc_data agrees with mpmath's
91
+ # gammainc.
92
+ assert_mpmath_equal(gammainc,
93
+ lambda a, x: mp.gammainc(a, b=x, regularized=True),
94
+ [Arg(0, 100, inclusive_a=False), Arg(0, 100)],
95
+ nan_ok=False, rtol=1e-17, n=50, dps=50)
96
+
97
+
98
+ @pytest.mark.xslow
99
+ @check_version(mp, '0.19')
100
+ def test_gammaincc():
101
+ # Check that the gammaincc in special._precompute.gammainc_data
102
+ # agrees with mpmath's gammainc.
103
+ assert_mpmath_equal(lambda a, x: gammaincc(a, x, dps=1000),
104
+ lambda a, x: mp.gammainc(a, a=x, regularized=True),
105
+ [Arg(20, 100), Arg(20, 100)],
106
+ nan_ok=False, rtol=1e-17, n=50, dps=1000)
107
+
108
+ # Test the fast integer path
109
+ assert_mpmath_equal(gammaincc,
110
+ lambda a, x: mp.gammainc(a, a=x, regularized=True),
111
+ [IntArg(1, 100), Arg(0, 100)],
112
+ nan_ok=False, rtol=1e-17, n=50, dps=50)
.venv/lib/python3.12/site-packages/scipy/special/tests/test_precompute_utils.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pytest
2
+
3
+ from scipy.special._testutils import MissingModule, check_version
4
+ from scipy.special._mptestutils import mp_assert_allclose
5
+ from scipy.special._precompute.utils import lagrange_inversion
6
+
7
+ try:
8
+ import sympy
9
+ except ImportError:
10
+ sympy = MissingModule('sympy')
11
+
12
+ try:
13
+ import mpmath as mp
14
+ except ImportError:
15
+ mp = MissingModule('mpmath')
16
+
17
+
18
+ @pytest.mark.slow
19
+ @check_version(sympy, '0.7')
20
+ @check_version(mp, '0.19')
21
+ class TestInversion:
22
+ @pytest.mark.xfail_on_32bit("rtol only 2e-9, see gh-6938")
23
+ def test_log(self):
24
+ with mp.workdps(30):
25
+ logcoeffs = mp.taylor(lambda x: mp.log(1 + x), 0, 10)
26
+ expcoeffs = mp.taylor(lambda x: mp.exp(x) - 1, 0, 10)
27
+ invlogcoeffs = lagrange_inversion(logcoeffs)
28
+ mp_assert_allclose(invlogcoeffs, expcoeffs)
29
+
30
+ @pytest.mark.xfail_on_32bit("rtol only 1e-15, see gh-6938")
31
+ def test_sin(self):
32
+ with mp.workdps(30):
33
+ sincoeffs = mp.taylor(mp.sin, 0, 10)
34
+ asincoeffs = mp.taylor(mp.asin, 0, 10)
35
+ invsincoeffs = lagrange_inversion(sincoeffs)
36
+ mp_assert_allclose(invsincoeffs, asincoeffs, atol=1e-30)
.venv/lib/python3.12/site-packages/scipy/special/tests/test_round.py ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import pytest
3
+
4
+ from scipy.special import _test_internal
5
+
6
+
7
+ @pytest.mark.fail_slow(20)
8
+ @pytest.mark.skipif(not _test_internal.have_fenv(), reason="no fenv()")
9
+ def test_add_round_up():
10
+ rng = np.random.RandomState(1234)
11
+ _test_internal.test_add_round(10**5, 'up', rng)
12
+
13
+
14
+ @pytest.mark.fail_slow(20)
15
+ @pytest.mark.skipif(not _test_internal.have_fenv(), reason="no fenv()")
16
+ def test_add_round_down():
17
+ rng = np.random.RandomState(1234)
18
+ _test_internal.test_add_round(10**5, 'down', rng)
.venv/lib/python3.12/site-packages/scipy/special/tests/test_sf_error.py ADDED
@@ -0,0 +1,153 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import sys
2
+ import warnings
3
+
4
+ import numpy as np
5
+ from numpy.testing import assert_, assert_equal, HAS_REFCOUNT
6
+ import pytest
7
+ from pytest import raises as assert_raises
8
+
9
+ import scipy.special as sc
10
+ from scipy.special._ufuncs import _sf_error_test_function
11
+
12
+ _sf_error_code_map = {
13
+ # skip 'ok'
14
+ 'singular': 1,
15
+ 'underflow': 2,
16
+ 'overflow': 3,
17
+ 'slow': 4,
18
+ 'loss': 5,
19
+ 'no_result': 6,
20
+ 'domain': 7,
21
+ 'arg': 8,
22
+ 'other': 9,
23
+ 'memory': 10,
24
+ }
25
+
26
+ _sf_error_actions = [
27
+ 'ignore',
28
+ 'warn',
29
+ 'raise'
30
+ ]
31
+
32
+
33
+ def _check_action(fun, args, action):
34
+ # TODO: special expert should correct
35
+ # the coercion at the true location?
36
+ args = np.asarray(args, dtype=np.dtype("long"))
37
+ if action == 'warn':
38
+ with pytest.warns(sc.SpecialFunctionWarning):
39
+ fun(*args)
40
+ elif action == 'raise':
41
+ with assert_raises(sc.SpecialFunctionError):
42
+ fun(*args)
43
+ else:
44
+ # action == 'ignore', make sure there are no warnings/exceptions
45
+ with warnings.catch_warnings():
46
+ warnings.simplefilter("error")
47
+ fun(*args)
48
+
49
+
50
+ def test_geterr():
51
+ err = sc.geterr()
52
+ for key, value in err.items():
53
+ assert_(key in _sf_error_code_map)
54
+ assert_(value in _sf_error_actions)
55
+
56
+
57
+ def test_seterr():
58
+ entry_err = sc.geterr()
59
+ try:
60
+ for category, error_code in _sf_error_code_map.items():
61
+ for action in _sf_error_actions:
62
+ geterr_olderr = sc.geterr()
63
+ seterr_olderr = sc.seterr(**{category: action})
64
+ assert_(geterr_olderr == seterr_olderr)
65
+ newerr = sc.geterr()
66
+ assert_(newerr[category] == action)
67
+ geterr_olderr.pop(category)
68
+ newerr.pop(category)
69
+ assert_(geterr_olderr == newerr)
70
+ _check_action(_sf_error_test_function, (error_code,), action)
71
+ finally:
72
+ sc.seterr(**entry_err)
73
+
74
+
75
+ @pytest.mark.thread_unsafe(reason="module refcounts are not stable in multiple threads")
76
+ @pytest.mark.skipif(not HAS_REFCOUNT, reason="Python lacks refcounts")
77
+ def test_sf_error_special_refcount():
78
+ # Regression test for gh-16233.
79
+ # Check that the reference count of scipy.special is not increased
80
+ # when a SpecialFunctionError is raised.
81
+ refcount_before = sys.getrefcount(sc)
82
+ with sc.errstate(all='raise'):
83
+ with pytest.raises(sc.SpecialFunctionError, match='domain error'):
84
+ sc.ndtri(2.0)
85
+ refcount_after = sys.getrefcount(sc)
86
+ assert refcount_after == refcount_before
87
+
88
+
89
+ def test_errstate_pyx_basic():
90
+ olderr = sc.geterr()
91
+ with sc.errstate(singular='raise'):
92
+ with assert_raises(sc.SpecialFunctionError):
93
+ sc.loggamma(0)
94
+ assert_equal(olderr, sc.geterr())
95
+
96
+
97
+ def test_errstate_c_basic():
98
+ olderr = sc.geterr()
99
+ with sc.errstate(domain='raise'):
100
+ with assert_raises(sc.SpecialFunctionError):
101
+ sc.spence(-1)
102
+ assert_equal(olderr, sc.geterr())
103
+
104
+
105
+ def test_errstate_cpp_basic():
106
+ olderr = sc.geterr()
107
+ with sc.errstate(underflow='raise'):
108
+ with assert_raises(sc.SpecialFunctionError):
109
+ sc.wrightomega(-1000)
110
+ assert_equal(olderr, sc.geterr())
111
+
112
+
113
+ def test_errstate_cpp_scipy_special():
114
+ olderr = sc.geterr()
115
+ with sc.errstate(singular='raise'):
116
+ with assert_raises(sc.SpecialFunctionError):
117
+ sc.lambertw(0, 1)
118
+ assert_equal(olderr, sc.geterr())
119
+
120
+
121
+ def test_errstate_cpp_alt_ufunc_machinery():
122
+ olderr = sc.geterr()
123
+ with sc.errstate(singular='raise'):
124
+ with assert_raises(sc.SpecialFunctionError):
125
+ sc.gammaln(0)
126
+ assert_equal(olderr, sc.geterr())
127
+
128
+
129
+ def test_errstate():
130
+ for category, error_code in _sf_error_code_map.items():
131
+ for action in _sf_error_actions:
132
+ olderr = sc.geterr()
133
+ with sc.errstate(**{category: action}):
134
+ _check_action(_sf_error_test_function, (error_code,), action)
135
+ assert_equal(olderr, sc.geterr())
136
+
137
+
138
+ def test_errstate_all_but_one():
139
+ olderr = sc.geterr()
140
+ with sc.errstate(all='raise', singular='ignore'):
141
+ sc.gammaln(0)
142
+ with assert_raises(sc.SpecialFunctionError):
143
+ sc.spence(-1.0)
144
+ assert_equal(olderr, sc.geterr())
145
+
146
+
147
+ def test_check_overflow_message():
148
+ # Regression test for a bug where the overflow and underflow
149
+ # messages were switched.
150
+ with pytest.raises(sc.SpecialFunctionError, match="overflow"):
151
+ with sc.errstate(all='raise'):
152
+ # This should trigger an overflow:
153
+ sc.yn(3, 1e-105)
.venv/lib/python3.12/site-packages/scipy/special/tests/test_sici.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+
3
+ import scipy.special as sc
4
+ from scipy.special._testutils import FuncData
5
+
6
+
7
+ def test_sici_consistency():
8
+ # Make sure the implementation of sici for real arguments agrees
9
+ # with the implementation of sici for complex arguments.
10
+
11
+ # On the negative real axis Cephes drops the imaginary part in ci
12
+ def sici(x):
13
+ si, ci = sc.sici(x + 0j)
14
+ return si.real, ci.real
15
+
16
+ x = np.r_[-np.logspace(8, -30, 200), 0, np.logspace(-30, 8, 200)]
17
+ si, ci = sc.sici(x)
18
+ dataset = np.column_stack((x, si, ci))
19
+ FuncData(sici, dataset, 0, (1, 2), rtol=1e-12).check()
20
+
21
+
22
+ def test_shichi_consistency():
23
+ # Make sure the implementation of shichi for real arguments agrees
24
+ # with the implementation of shichi for complex arguments.
25
+
26
+ # On the negative real axis Cephes drops the imaginary part in chi
27
+ def shichi(x):
28
+ shi, chi = sc.shichi(x + 0j)
29
+ return shi.real, chi.real
30
+
31
+ # Overflow happens quickly, so limit range
32
+ x = np.r_[-np.logspace(np.log10(700), -30, 200), 0,
33
+ np.logspace(-30, np.log10(700), 200)]
34
+ shi, chi = sc.shichi(x)
35
+ dataset = np.column_stack((x, shi, chi))
36
+ FuncData(shichi, dataset, 0, (1, 2), rtol=1e-14).check()
.venv/lib/python3.12/site-packages/scipy/special/tests/test_specfun.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Various made-up tests to hit different branches of the code in specfun.c
3
+ """
4
+
5
+ import numpy as np
6
+ from numpy.testing import assert_allclose
7
+ from scipy import special
8
+
9
+
10
+ def test_cva2_cv0_branches():
11
+ res, resp = special.mathieu_cem([40, 129], [13, 14], [30, 45])
12
+ assert_allclose(res, np.array([-0.3741211, 0.74441928]))
13
+ assert_allclose(resp, np.array([-37.02872758, -86.13549877]))
14
+
15
+ res, resp = special.mathieu_sem([40, 129], [13, 14], [30, 45])
16
+ assert_allclose(res, np.array([0.92955551, 0.66771207]))
17
+ assert_allclose(resp, np.array([-14.91073448, 96.02954185]))
18
+
19
+
20
+ def test_chgm_branches():
21
+ res = special.eval_genlaguerre(-3.2, 3, 2.5)
22
+ assert_allclose(res, -0.7077721935779854)
23
+
24
+
25
+ def test_hygfz_branches():
26
+ """(z == 1.0) && (c-a-b > 0.0)"""
27
+ res = special.hyp2f1(1.5, 2.5, 4.5, 1.+0.j)
28
+ assert_allclose(res, 10.30835089459151+0j)
29
+ """(cabs(z+1) < eps) && (fabs(c-a+b - 1.0) < eps)"""
30
+ res = special.hyp2f1(5+5e-16, 2, 2, -1.0 + 5e-16j)
31
+ assert_allclose(res, 0.031249999999999986+3.9062499999999994e-17j)
32
+
33
+
34
+ def test_pro_rad1():
35
+ # https://github.com/scipy/scipy/issues/21058
36
+ # Reference values taken from WolframAlpha
37
+ # SpheroidalS1(1, 1, 30, 1.1)
38
+ # SpheroidalS1Prime(1, 1, 30, 1.1)
39
+ res = special.pro_rad1(1, 1, 30, 1.1)
40
+ assert_allclose(res, (0.009657872296166435, 3.253369651472877), rtol=2e-5)
41
+
42
+ def test_pro_rad2():
43
+ # https://github.com/scipy/scipy/issues/21461
44
+ # Reference values taken from WolframAlpha
45
+ # SpheroidalS2(0, 0, 3, 1.02)
46
+ # SpheroidalS2Prime(0, 0, 3, 1.02)
47
+ res = special.pro_rad2(0, 0, 3, 1.02)
48
+ assert_allclose(res, (-0.35089596858528077, 13.652764213480872), rtol=10e-10)
.venv/lib/python3.12/site-packages/scipy/special/tests/test_spence.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ from numpy import sqrt, log, pi
3
+ from scipy.special._testutils import FuncData
4
+ from scipy.special import spence
5
+
6
+
7
+ def test_consistency():
8
+ # Make sure the implementation of spence for real arguments
9
+ # agrees with the implementation of spence for imaginary arguments.
10
+
11
+ x = np.logspace(-30, 300, 200)
12
+ dataset = np.vstack((x + 0j, spence(x))).T
13
+ FuncData(spence, dataset, 0, 1, rtol=1e-14).check()
14
+
15
+
16
+ def test_special_points():
17
+ # Check against known values of Spence's function.
18
+
19
+ phi = (1 + sqrt(5))/2
20
+ dataset = [(1, 0),
21
+ (2, -pi**2/12),
22
+ (0.5, pi**2/12 - log(2)**2/2),
23
+ (0, pi**2/6),
24
+ (-1, pi**2/4 - 1j*pi*log(2)),
25
+ ((-1 + sqrt(5))/2, pi**2/15 - log(phi)**2),
26
+ ((3 - sqrt(5))/2, pi**2/10 - log(phi)**2),
27
+ (phi, -pi**2/15 + log(phi)**2/2),
28
+ # Corrected from Zagier, "The Dilogarithm Function"
29
+ ((3 + sqrt(5))/2, -pi**2/10 - log(phi)**2)]
30
+
31
+ dataset = np.asarray(dataset)
32
+ FuncData(spence, dataset, 0, 1, rtol=1e-14).check()
.venv/lib/python3.12/site-packages/scipy/special/tests/test_spfun_stats.py ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ from numpy.testing import (assert_array_equal, assert_array_almost_equal_nulp,
3
+ assert_allclose)
4
+ from pytest import raises as assert_raises
5
+
6
+ from scipy.special import gammaln, multigammaln # type:ignore[attr-defined]
7
+
8
+
9
+ class TestMultiGammaLn:
10
+
11
+ def test1(self):
12
+ # A test of the identity
13
+ # Gamma_1(a) = Gamma(a)
14
+ np.random.seed(1234)
15
+ a = np.abs(np.random.randn())
16
+ assert_array_equal(multigammaln(a, 1), gammaln(a))
17
+
18
+ def test2(self):
19
+ # A test of the identity
20
+ # Gamma_2(a) = sqrt(pi) * Gamma(a) * Gamma(a - 0.5)
21
+ a = np.array([2.5, 10.0])
22
+ result = multigammaln(a, 2)
23
+ expected = np.log(np.sqrt(np.pi)) + gammaln(a) + gammaln(a - 0.5)
24
+ assert_allclose(result, expected, atol=1.5e-7, rtol=0)
25
+
26
+ def test_bararg(self):
27
+ assert_raises(ValueError, multigammaln, 0.5, 1.2)
28
+
29
+
30
+ def _check_multigammaln_array_result(a, d):
31
+ # Test that the shape of the array returned by multigammaln
32
+ # matches the input shape, and that all the values match
33
+ # the value computed when multigammaln is called with a scalar.
34
+ result = multigammaln(a, d)
35
+ assert_array_equal(a.shape, result.shape)
36
+ a1 = a.ravel()
37
+ result1 = result.ravel()
38
+ for i in range(a.size):
39
+ assert_array_almost_equal_nulp(result1[i], multigammaln(a1[i], d))
40
+
41
+
42
+ def test_multigammaln_array_arg():
43
+ # Check that the array returned by multigammaln has the correct
44
+ # shape and contains the correct values. The cases have arrays
45
+ # with several different shapes.
46
+ # The cases include a regression test for ticket #1849
47
+ # (a = np.array([2.0]), an array with a single element).
48
+ np.random.seed(1234)
49
+
50
+ cases = [
51
+ # a, d
52
+ (np.abs(np.random.randn(3, 2)) + 5, 5),
53
+ (np.abs(np.random.randn(1, 2)) + 5, 5),
54
+ (np.arange(10.0, 18.0).reshape(2, 2, 2), 3),
55
+ (np.array([2.0]), 3),
56
+ (np.float64(2.0), 3),
57
+ ]
58
+
59
+ for a, d in cases:
60
+ _check_multigammaln_array_result(a, d)
61
+
.venv/lib/python3.12/site-packages/scipy/special/tests/test_sph_harm.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import pytest
3
+
4
+ from numpy.testing import assert_allclose
5
+ import scipy.special as sc
6
+
7
+ class TestSphHarm:
8
+ @pytest.mark.slow
9
+ def test_p(self):
10
+ m_max = 20
11
+ n_max = 10
12
+
13
+ theta = np.linspace(0, np.pi)
14
+ phi = np.linspace(0, 2*np.pi)
15
+ theta, phi = np.meshgrid(theta, phi)
16
+
17
+ y, y_jac, y_hess = sc.sph_harm_y_all(n_max, m_max, theta, phi, diff_n=2)
18
+ p, p_jac, p_hess = sc.sph_legendre_p_all(n_max, m_max, theta, diff_n=2)
19
+
20
+ m = np.concatenate([np.arange(m_max + 1), np.arange(-m_max, 0)])
21
+ m = np.expand_dims(m, axis=(0,)+tuple(range(2,theta.ndim+2)))
22
+
23
+ assert_allclose(y, p * np.exp(1j * m * phi))
24
+
25
+ assert_allclose(y_jac[..., 0], p_jac * np.exp(1j * m * phi))
26
+ assert_allclose(y_jac[..., 1], 1j * m * p * np.exp(1j * m * phi))
27
+
28
+ assert_allclose(y_hess[..., 0, 0], p_hess * np.exp(1j * m * phi))
29
+ assert_allclose(y_hess[..., 0, 1], 1j * m * p_jac * np.exp(1j * m * phi))
30
+ assert_allclose(y_hess[..., 1, 0], y_hess[..., 0, 1])
31
+ assert_allclose(y_hess[..., 1, 1], -m * m * p * np.exp(1j * m * phi))
32
+
33
+ @pytest.mark.parametrize("n_max", [7, 10, 50])
34
+ @pytest.mark.parametrize("m_max", [1, 4, 5, 9, 14])
35
+ def test_all(self, n_max, m_max):
36
+ theta = np.linspace(0, np.pi)
37
+ phi = np.linspace(0, 2 * np.pi)
38
+
39
+ n = np.arange(n_max + 1)
40
+ n = np.expand_dims(n, axis=tuple(range(1,theta.ndim+2)))
41
+
42
+ m = np.concatenate([np.arange(m_max + 1), np.arange(-m_max, 0)])
43
+ m = np.expand_dims(m, axis=(0,)+tuple(range(2,theta.ndim+2)))
44
+
45
+ y_actual = sc.sph_harm_y_all(n_max, m_max, theta, phi)
46
+ y_desired = sc.sph_harm_y(n, m, theta, phi)
47
+
48
+ np.testing.assert_allclose(y_actual, y_desired, rtol=1e-05)