Ravenveil commited on
Commit
c75c5a8
·
verified ·
1 Parent(s): db4a9ed

backup 04_physworld 2026-11-08 10:11:26 (part 11)

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 +36 -0
  2. physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy-2.4.6.dist-info/INSTALLER +1 -0
  3. physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy-2.4.6.dist-info/METADATA +139 -0
  4. physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy-2.4.6.dist-info/RECORD +0 -0
  5. physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy-2.4.6.dist-info/REQUESTED +0 -0
  6. physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy-2.4.6.dist-info/WHEEL +6 -0
  7. physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy-2.4.6.dist-info/entry_points.txt +13 -0
  8. physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy-2.4.6.dist-info/licenses/LICENSE.txt +935 -0
  9. physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy-2.4.6.dist-info/licenses/numpy/_core/include/numpy/libdivide/LICENSE.txt +21 -0
  10. physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy-2.4.6.dist-info/licenses/numpy/_core/src/common/pythoncapi-compat/COPYING +14 -0
  11. physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy-2.4.6.dist-info/licenses/numpy/_core/src/highway/LICENSE +371 -0
  12. physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy-2.4.6.dist-info/licenses/numpy/_core/src/multiarray/dragon4_LICENSE.txt +27 -0
  13. physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy-2.4.6.dist-info/licenses/numpy/_core/src/npysort/x86-simd-sort/LICENSE.md +28 -0
  14. physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy-2.4.6.dist-info/licenses/numpy/_core/src/umath/svml/LICENSE +30 -0
  15. physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy-2.4.6.dist-info/licenses/numpy/fft/pocketfft/LICENSE.md +25 -0
  16. physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy-2.4.6.dist-info/licenses/numpy/linalg/lapack_lite/LICENSE.txt +48 -0
  17. physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy-2.4.6.dist-info/licenses/numpy/ma/LICENSE +24 -0
  18. physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy-2.4.6.dist-info/licenses/numpy/random/LICENSE.md +71 -0
  19. physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy-2.4.6.dist-info/licenses/numpy/random/src/distributions/LICENSE.md +61 -0
  20. physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy-2.4.6.dist-info/licenses/numpy/random/src/mt19937/LICENSE.md +61 -0
  21. physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy-2.4.6.dist-info/licenses/numpy/random/src/pcg64/LICENSE.md +22 -0
  22. physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy-2.4.6.dist-info/licenses/numpy/random/src/philox/LICENSE.md +31 -0
  23. physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy-2.4.6.dist-info/licenses/numpy/random/src/sfc64/LICENSE.md +27 -0
  24. physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy-2.4.6.dist-info/licenses/numpy/random/src/splitmix64/LICENSE.md +9 -0
  25. physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy.libs/libgfortran-040039e1-0352e75f.so.5.0.0 +3 -0
  26. physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy.libs/libquadmath-96973f99-934c22de.so.0.0.0 +3 -0
  27. physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy.libs/libscipy_openblas64_-32a4b2a6.so +3 -0
  28. physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy/polynomial/_polytypes.pyi +501 -0
  29. physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy/polynomial/chebyshev.py +2001 -0
  30. physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy/polynomial/chebyshev.pyi +180 -0
  31. physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy/polynomial/hermite.py +1738 -0
  32. physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy/polynomial/hermite.pyi +106 -0
  33. physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy/polynomial/hermite_e.py +1640 -0
  34. physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy/polynomial/hermite_e.pyi +106 -0
  35. physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy/polynomial/laguerre.py +1673 -0
  36. physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy/polynomial/laguerre.pyi +100 -0
  37. physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy/polynomial/legendre.py +1603 -0
  38. physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy/polynomial/legendre.pyi +100 -0
  39. physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy/polynomial/polynomial.py +1625 -0
  40. physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy/polynomial/polynomial.pyi +109 -0
  41. physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy/polynomial/polyutils.py +759 -0
  42. physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy/polynomial/polyutils.pyi +307 -0
  43. physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy/polynomial/tests/__init__.py +0 -0
  44. physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy/polynomial/tests/__pycache__/__init__.cpython-311.pyc +0 -0
  45. physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy/polynomial/tests/__pycache__/test_chebyshev.cpython-311.pyc +0 -0
  46. physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy/polynomial/tests/__pycache__/test_classes.cpython-311.pyc +0 -0
  47. physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy/polynomial/tests/__pycache__/test_hermite.cpython-311.pyc +0 -0
  48. physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy/polynomial/tests/__pycache__/test_hermite_e.cpython-311.pyc +0 -0
  49. physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy/polynomial/tests/__pycache__/test_laguerre.cpython-311.pyc +0 -0
  50. physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy/polynomial/tests/__pycache__/test_legendre.cpython-311.pyc +0 -0
.gitattributes CHANGED
@@ -3519,3 +3519,39 @@ physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy/linalg/tests/__
3519
  physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy/ma/__pycache__/core.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
3520
  physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy/ma/tests/__pycache__/test_core.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
3521
  physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy/ma/tests/__pycache__/test_extras.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3519
  physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy/ma/__pycache__/core.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
3520
  physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy/ma/tests/__pycache__/test_core.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
3521
  physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy/ma/tests/__pycache__/test_extras.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
3522
+ physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy/random/_bounded_integers.cpython-311-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
3523
+ physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy/random/_common.cpython-311-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
3524
+ physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy/random/_generator.cpython-311-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
3525
+ physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy/random/_mt19937.cpython-311-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
3526
+ physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy/random/_pcg64.cpython-311-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
3527
+ physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy/random/_philox.cpython-311-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
3528
+ physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy/random/bit_generator.cpython-311-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
3529
+ physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy/random/mtrand.cpython-311-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
3530
+ physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy/random/tests/__pycache__/test_generator_mt19937.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
3531
+ physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy/random/tests/__pycache__/test_random.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
3532
+ physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy/random/tests/__pycache__/test_randomstate.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
3533
+ physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy/testing/_private/__pycache__/utils.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
3534
+ physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy/testing/tests/__pycache__/test_utils.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
3535
+ physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy/typing/tests/data/pass/__pycache__/random.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
3536
+ physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy.libs/libgfortran-040039e1-0352e75f.so.5.0.0 filter=lfs diff=lfs merge=lfs -text
3537
+ physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy.libs/libquadmath-96973f99-934c22de.so.0.0.0 filter=lfs diff=lfs merge=lfs -text
3538
+ physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy.libs/libscipy_openblas64_-32a4b2a6.so filter=lfs diff=lfs merge=lfs -text
3539
+ physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/pillow.libs/libXau-154567c4.so.6.0.0 filter=lfs diff=lfs merge=lfs -text
3540
+ physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/pillow.libs/libavif-c6062d5f.so.16.4.2 filter=lfs diff=lfs merge=lfs -text
3541
+ physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/pillow.libs/libbrotlicommon-53534446.so.1.2.0 filter=lfs diff=lfs merge=lfs -text
3542
+ physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/pillow.libs/libfreetype-57f805ba.so.6.20.6 filter=lfs diff=lfs merge=lfs -text
3543
+ physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/pillow.libs/libharfbuzz-fb49c9fc.so.0.61450.0 filter=lfs diff=lfs merge=lfs -text
3544
+ physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/pillow.libs/libjpeg-6dc8d115.so.62.4.0 filter=lfs diff=lfs merge=lfs -text
3545
+ physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/pillow.libs/liblcms2-88eaba2f.so.2.0.19 filter=lfs diff=lfs merge=lfs -text
3546
+ physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/pillow.libs/liblzma-de26b416.so.5.8.4 filter=lfs diff=lfs merge=lfs -text
3547
+ physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/pillow.libs/libopenjp2-e530e1bf.so.2.5.4 filter=lfs diff=lfs merge=lfs -text
3548
+ physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/pillow.libs/libpng16-1d1ba958.so.16.58.0 filter=lfs diff=lfs merge=lfs -text
3549
+ physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/pillow.libs/libtiff-20b7e810.so.6.3.0 filter=lfs diff=lfs merge=lfs -text
3550
+ physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/pillow.libs/libwebp-51b0b3f7.so.7.2.0 filter=lfs diff=lfs merge=lfs -text
3551
+ physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/pillow.libs/libxcb-9065bb12.so.1.1.0 filter=lfs diff=lfs merge=lfs -text
3552
+ physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/pillow.libs/libzstd-40ad5e7e.so.1.5.7 filter=lfs diff=lfs merge=lfs -text
3553
+ physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/pip/_vendor/distlib/t64-arm.exe filter=lfs diff=lfs merge=lfs -text
3554
+ physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/pip/_vendor/distlib/t64.exe filter=lfs diff=lfs merge=lfs -text
3555
+ physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/pip/_vendor/distlib/w64-arm.exe filter=lfs diff=lfs merge=lfs -text
3556
+ physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/pip/_vendor/distlib/w64.exe filter=lfs diff=lfs merge=lfs -text
3557
+ physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/pip/_vendor/pkg_resources/__pycache__/__init__.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy-2.4.6.dist-info/INSTALLER ADDED
@@ -0,0 +1 @@
 
 
1
+ pip
physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy-2.4.6.dist-info/METADATA ADDED
@@ -0,0 +1,139 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Metadata-Version: 2.4
2
+ Name: numpy
3
+ Version: 2.4.6
4
+ Summary: Fundamental package for array computing in Python
5
+ Author: Travis E. Oliphant et al.
6
+ Maintainer-Email: NumPy Developers <numpy-discussion@python.org>
7
+ License-Expression: BSD-3-Clause AND 0BSD AND MIT AND Zlib AND CC0-1.0
8
+ License-File: LICENSE.txt
9
+ License-File: numpy/_core/include/numpy/libdivide/LICENSE.txt
10
+ License-File: numpy/_core/src/common/pythoncapi-compat/COPYING
11
+ License-File: numpy/_core/src/highway/LICENSE
12
+ License-File: numpy/_core/src/multiarray/dragon4_LICENSE.txt
13
+ License-File: numpy/_core/src/npysort/x86-simd-sort/LICENSE.md
14
+ License-File: numpy/_core/src/umath/svml/LICENSE
15
+ License-File: numpy/fft/pocketfft/LICENSE.md
16
+ License-File: numpy/linalg/lapack_lite/LICENSE.txt
17
+ License-File: numpy/ma/LICENSE
18
+ License-File: numpy/random/LICENSE.md
19
+ License-File: numpy/random/src/distributions/LICENSE.md
20
+ License-File: numpy/random/src/mt19937/LICENSE.md
21
+ License-File: numpy/random/src/pcg64/LICENSE.md
22
+ License-File: numpy/random/src/philox/LICENSE.md
23
+ License-File: numpy/random/src/sfc64/LICENSE.md
24
+ License-File: numpy/random/src/splitmix64/LICENSE.md
25
+ Classifier: Development Status :: 5 - Production/Stable
26
+ Classifier: Intended Audience :: Science/Research
27
+ Classifier: Intended Audience :: Developers
28
+ Classifier: Programming Language :: C
29
+ Classifier: Programming Language :: Python
30
+ Classifier: Programming Language :: Python :: 3
31
+ Classifier: Programming Language :: Python :: 3.11
32
+ Classifier: Programming Language :: Python :: 3.12
33
+ Classifier: Programming Language :: Python :: 3.13
34
+ Classifier: Programming Language :: Python :: 3.14
35
+ Classifier: Programming Language :: Python :: 3 :: Only
36
+ Classifier: Programming Language :: Python :: Implementation :: CPython
37
+ Classifier: Topic :: Software Development
38
+ Classifier: Topic :: Scientific/Engineering
39
+ Classifier: Typing :: Typed
40
+ Classifier: Operating System :: Microsoft :: Windows
41
+ Classifier: Operating System :: POSIX
42
+ Classifier: Operating System :: Unix
43
+ Classifier: Operating System :: MacOS
44
+ Project-URL: homepage, https://numpy.org
45
+ Project-URL: documentation, https://numpy.org/doc/
46
+ Project-URL: source, https://github.com/numpy/numpy
47
+ Project-URL: download, https://pypi.org/project/numpy/#files
48
+ Project-URL: tracker, https://github.com/numpy/numpy/issues
49
+ Project-URL: release notes, https://numpy.org/doc/stable/release
50
+ Requires-Python: >=3.11
51
+ Description-Content-Type: text/markdown
52
+
53
+ <h1 align="center">
54
+ <img src="https://raw.githubusercontent.com/numpy/numpy/main/branding/logo/primary/numpylogo.svg" width="300">
55
+ </h1><br>
56
+
57
+
58
+ [![Powered by NumFOCUS](https://img.shields.io/badge/powered%20by-NumFOCUS-orange.svg?style=flat&colorA=E1523D&colorB=007D8A)](
59
+ https://numfocus.org)
60
+ [![PyPI Downloads](https://img.shields.io/pypi/dm/numpy.svg?label=PyPI%20downloads)](
61
+ https://pypi.org/project/numpy/)
62
+ [![Conda Downloads](https://img.shields.io/conda/dn/conda-forge/numpy.svg?label=Conda%20downloads)](
63
+ https://anaconda.org/conda-forge/numpy)
64
+ [![Stack Overflow](https://img.shields.io/badge/stackoverflow-Ask%20questions-blue.svg)](
65
+ https://stackoverflow.com/questions/tagged/numpy)
66
+ [![Nature Paper](https://img.shields.io/badge/DOI-10.1038%2Fs41586--020--2649--2-blue)](
67
+ https://doi.org/10.1038/s41586-020-2649-2)
68
+ [![LFX Health Score](https://insights.linuxfoundation.org/api/badge/health-score?project=numpy)](https://insights.linuxfoundation.org/project/numpy)
69
+ [![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/numpy/numpy/badge)](https://securityscorecards.dev/viewer/?uri=github.com/numpy/numpy)
70
+ [![Typing](https://img.shields.io/pypi/types/numpy)](https://pypi.org/project/numpy/)
71
+
72
+
73
+ NumPy is the fundamental package for scientific computing with Python.
74
+
75
+ - **Website:** https://numpy.org
76
+ - **Documentation:** https://numpy.org/doc
77
+ - **Mailing list:** https://mail.python.org/mailman/listinfo/numpy-discussion
78
+ - **Source code:** https://github.com/numpy/numpy
79
+ - **Contributing:** https://numpy.org/devdocs/dev/index.html
80
+ - **Bug reports:** https://github.com/numpy/numpy/issues
81
+ - **Report a security vulnerability:** https://tidelift.com/docs/security
82
+
83
+ It provides:
84
+
85
+ - a powerful N-dimensional array object
86
+ - sophisticated (broadcasting) functions
87
+ - tools for integrating C/C++ and Fortran code
88
+ - useful linear algebra, Fourier transform, and random number capabilities
89
+
90
+ Testing:
91
+
92
+ NumPy requires `pytest` and `hypothesis`. Tests can then be run after installation with:
93
+
94
+ python -c "import numpy, sys; sys.exit(numpy.test() is False)"
95
+
96
+ Code of Conduct
97
+ ----------------------
98
+
99
+ NumPy is a community-driven open source project developed by a diverse group of
100
+ [contributors](https://numpy.org/teams/). The NumPy leadership has made a strong
101
+ commitment to creating an open, inclusive, and positive community. Please read the
102
+ [NumPy Code of Conduct](https://numpy.org/code-of-conduct/) for guidance on how to interact
103
+ with others in a way that makes our community thrive.
104
+
105
+ Call for Contributions
106
+ ----------------------
107
+
108
+ The NumPy project welcomes your expertise and enthusiasm!
109
+
110
+ Small improvements or fixes are always appreciated. If you are considering larger contributions
111
+ to the source code, please contact us through the [mailing
112
+ list](https://mail.python.org/mailman/listinfo/numpy-discussion) first.
113
+
114
+ Writing code isn’t the only way to contribute to NumPy. You can also:
115
+ - review pull requests
116
+ - help us stay on top of new and old issues
117
+ - develop tutorials, presentations, and other educational materials
118
+ - maintain and improve [our website](https://github.com/numpy/numpy.org)
119
+ - develop graphic design for our brand assets and promotional materials
120
+ - translate website content
121
+ - help with outreach and onboard new contributors
122
+ - write grant proposals and help with other fundraising efforts
123
+
124
+ For more information about the ways you can contribute to NumPy, visit [our website](https://numpy.org/contribute/).
125
+ If you’re unsure where to start or how your skills fit in, reach out! You can
126
+ ask on the mailing list or here, on GitHub, by opening a new issue or leaving a
127
+ comment on a relevant issue that is already open.
128
+
129
+ Our preferred channels of communication are all public, but if you’d like to
130
+ speak to us in private first, contact our community coordinators at
131
+ numpy-team@googlegroups.com or on Slack (write numpy-team@googlegroups.com for
132
+ an invitation).
133
+
134
+ We also have a biweekly community call, details of which are announced on the
135
+ mailing list. You are very welcome to join.
136
+
137
+ If you are new to contributing to open source, [this
138
+ guide](https://opensource.guide/how-to-contribute/) helps explain why, what,
139
+ and how to successfully get involved.
physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy-2.4.6.dist-info/RECORD ADDED
The diff for this file is too large to render. See raw diff
 
physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy-2.4.6.dist-info/REQUESTED ADDED
File without changes
physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy-2.4.6.dist-info/WHEEL ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ Wheel-Version: 1.0
2
+ Generator: meson
3
+ Root-Is-Purelib: false
4
+ Tag: cp311-cp311-manylinux_2_27_x86_64
5
+ Tag: cp311-cp311-manylinux_2_28_x86_64
6
+
physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy-2.4.6.dist-info/entry_points.txt ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [pkg_config]
2
+ numpy = numpy._core.lib.pkgconfig
3
+
4
+ [array_api]
5
+ numpy = numpy
6
+
7
+ [pyinstaller40]
8
+ hook-dirs = numpy:_pyinstaller_hooks_dir
9
+
10
+ [console_scripts]
11
+ f2py = numpy.f2py.f2py2e:main
12
+ numpy-config = numpy._configtool:main
13
+
physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy-2.4.6.dist-info/licenses/LICENSE.txt ADDED
@@ -0,0 +1,935 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Copyright (c) 2005-2025, NumPy 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 are
6
+ met:
7
+
8
+ * Redistributions of source code must retain the above copyright
9
+ notice, this list of conditions and the following disclaimer.
10
+
11
+ * 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
+ * Neither the name of the NumPy Developers nor the names of any
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 NumPy also bundles the following software:
38
+
39
+
40
+ Name: OpenBLAS
41
+ Files: numpy.libs/libscipy_openblas*.so
42
+ Description: bundled as a dynamically linked library
43
+ Availability: https://github.com/OpenMathLib/OpenBLAS/
44
+ License: BSD-3-Clause
45
+ Copyright (c) 2011-2014, The OpenBLAS Project
46
+ All rights reserved.
47
+
48
+ Redistribution and use in source and binary forms, with or without
49
+ modification, are permitted provided that the following conditions are
50
+ met:
51
+
52
+ 1. Redistributions of source code must retain the above copyright
53
+ notice, this list of conditions and the following disclaimer.
54
+
55
+ 2. Redistributions in binary form must reproduce the above copyright
56
+ notice, this list of conditions and the following disclaimer in
57
+ the documentation and/or other materials provided with the
58
+ distribution.
59
+ 3. Neither the name of the OpenBLAS project nor the names of
60
+ its contributors may be used to endorse or promote products
61
+ derived from this software without specific prior written
62
+ permission.
63
+
64
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
65
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
66
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
67
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
68
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
69
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
70
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
71
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
72
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
73
+ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
74
+
75
+
76
+ Name: LAPACK
77
+ Files: numpy.libs/libscipy_openblas*.so
78
+ Description: bundled in OpenBLAS
79
+ Availability: https://github.com/OpenMathLib/OpenBLAS/
80
+ License: BSD-3-Clause-Open-MPI
81
+ Copyright (c) 1992-2013 The University of Tennessee and The University
82
+ of Tennessee Research Foundation. All rights
83
+ reserved.
84
+ Copyright (c) 2000-2013 The University of California Berkeley. All
85
+ rights reserved.
86
+ Copyright (c) 2006-2013 The University of Colorado Denver. All rights
87
+ reserved.
88
+
89
+ $COPYRIGHT$
90
+
91
+ Additional copyrights may follow
92
+
93
+ $HEADER$
94
+
95
+ Redistribution and use in source and binary forms, with or without
96
+ modification, are permitted provided that the following conditions are
97
+ met:
98
+
99
+ - Redistributions of source code must retain the above copyright
100
+ notice, this list of conditions and the following disclaimer.
101
+
102
+ - Redistributions in binary form must reproduce the above copyright
103
+ notice, this list of conditions and the following disclaimer listed
104
+ in this license in the documentation and/or other materials
105
+ provided with the distribution.
106
+
107
+ - Neither the name of the copyright holders nor the names of its
108
+ contributors may be used to endorse or promote products derived from
109
+ this software without specific prior written permission.
110
+
111
+ The copyright holders provide no reassurances that the source code
112
+ provided does not infringe any patent, copyright, or any other
113
+ intellectual property rights of third parties. The copyright holders
114
+ disclaim any liability to any recipient for claims brought against
115
+ recipient by any third party for infringement of that parties
116
+ intellectual property rights.
117
+
118
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
119
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
120
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
121
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
122
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
123
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
124
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
125
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
126
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
127
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
128
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
129
+
130
+
131
+ Name: GCC runtime library
132
+ Files: numpy.libs/libgfortran*.so
133
+ Description: dynamically linked to files compiled with gcc
134
+ Availability: https://gcc.gnu.org/git/?p=gcc.git;a=tree;f=libgfortran
135
+ License: GPL-3.0-or-later WITH GCC-exception-3.1
136
+ Copyright (C) 2002-2017 Free Software Foundation, Inc.
137
+
138
+ Libgfortran is free software; you can redistribute it and/or modify
139
+ it under the terms of the GNU General Public License as published by
140
+ the Free Software Foundation; either version 3, or (at your option)
141
+ any later version.
142
+
143
+ Libgfortran is distributed in the hope that it will be useful,
144
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
145
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
146
+ GNU General Public License for more details.
147
+
148
+ Under Section 7 of GPL version 3, you are granted additional
149
+ permissions described in the GCC Runtime Library Exception, version
150
+ 3.1, as published by the Free Software Foundation.
151
+
152
+ You should have received a copy of the GNU General Public License and
153
+ a copy of the GCC Runtime Library Exception along with this program;
154
+ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
155
+ <http://www.gnu.org/licenses/>.
156
+
157
+ ----
158
+
159
+ Full text of license texts referred to above follows (that they are
160
+ listed below does not necessarily imply the conditions apply to the
161
+ present binary release):
162
+
163
+ ----
164
+
165
+ GCC RUNTIME LIBRARY EXCEPTION
166
+
167
+ Version 3.1, 31 March 2009
168
+
169
+ Copyright (C) 2009 Free Software Foundation, Inc. <https://fsf.org/>
170
+
171
+ Everyone is permitted to copy and distribute verbatim copies of this
172
+ license document, but changing it is not allowed.
173
+
174
+ This GCC Runtime Library Exception ("Exception") is an additional
175
+ permission under section 7 of the GNU General Public License, version
176
+ 3 ("GPLv3"). It applies to a given file (the "Runtime Library") that
177
+ bears a notice placed by the copyright holder of the file stating that
178
+ the file is governed by GPLv3 along with this Exception.
179
+
180
+ When you use GCC to compile a program, GCC may combine portions of
181
+ certain GCC header files and runtime libraries with the compiled
182
+ program. The purpose of this Exception is to allow compilation of
183
+ non-GPL (including proprietary) programs to use, in this way, the
184
+ header files and runtime libraries covered by this Exception.
185
+
186
+ 0. Definitions.
187
+
188
+ A file is an "Independent Module" if it either requires the Runtime
189
+ Library for execution after a Compilation Process, or makes use of an
190
+ interface provided by the Runtime Library, but is not otherwise based
191
+ on the Runtime Library.
192
+
193
+ "GCC" means a version of the GNU Compiler Collection, with or without
194
+ modifications, governed by version 3 (or a specified later version) of
195
+ the GNU General Public License (GPL) with the option of using any
196
+ subsequent versions published by the FSF.
197
+
198
+ "GPL-compatible Software" is software whose conditions of propagation,
199
+ modification and use would permit combination with GCC in accord with
200
+ the license of GCC.
201
+
202
+ "Target Code" refers to output from any compiler for a real or virtual
203
+ target processor architecture, in executable form or suitable for
204
+ input to an assembler, loader, linker and/or execution
205
+ phase. Notwithstanding that, Target Code does not include data in any
206
+ format that is used as a compiler intermediate representation, or used
207
+ for producing a compiler intermediate representation.
208
+
209
+ The "Compilation Process" transforms code entirely represented in
210
+ non-intermediate languages designed for human-written code, and/or in
211
+ Java Virtual Machine byte code, into Target Code. Thus, for example,
212
+ use of source code generators and preprocessors need not be considered
213
+ part of the Compilation Process, since the Compilation Process can be
214
+ understood as starting with the output of the generators or
215
+ preprocessors.
216
+
217
+ A Compilation Process is "Eligible" if it is done using GCC, alone or
218
+ with other GPL-compatible software, or if it is done without using any
219
+ work based on GCC. For example, using non-GPL-compatible Software to
220
+ optimize any GCC intermediate representations would not qualify as an
221
+ Eligible Compilation Process.
222
+
223
+ 1. Grant of Additional Permission.
224
+
225
+ You have permission to propagate a work of Target Code formed by
226
+ combining the Runtime Library with Independent Modules, even if such
227
+ propagation would otherwise violate the terms of GPLv3, provided that
228
+ all Target Code was generated by Eligible Compilation Processes. You
229
+ may then convey such a combination under terms of your choice,
230
+ consistent with the licensing of the Independent Modules.
231
+
232
+ 2. No Weakening of GCC Copyleft.
233
+
234
+ The availability of this Exception does not imply any general
235
+ presumption that third-party software is unaffected by the copyleft
236
+ requirements of the license of GCC.
237
+
238
+ ----
239
+
240
+ GNU GENERAL PUBLIC LICENSE
241
+ Version 3, 29 June 2007
242
+
243
+ Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
244
+ Everyone is permitted to copy and distribute verbatim copies
245
+ of this license document, but changing it is not allowed.
246
+
247
+ Preamble
248
+
249
+ The GNU General Public License is a free, copyleft license for
250
+ software and other kinds of works.
251
+
252
+ The licenses for most software and other practical works are designed
253
+ to take away your freedom to share and change the works. By contrast,
254
+ the GNU General Public License is intended to guarantee your freedom to
255
+ share and change all versions of a program--to make sure it remains free
256
+ software for all its users. We, the Free Software Foundation, use the
257
+ GNU General Public License for most of our software; it applies also to
258
+ any other work released this way by its authors. You can apply it to
259
+ your programs, too.
260
+
261
+ When we speak of free software, we are referring to freedom, not
262
+ price. Our General Public Licenses are designed to make sure that you
263
+ have the freedom to distribute copies of free software (and charge for
264
+ them if you wish), that you receive source code or can get it if you
265
+ want it, that you can change the software or use pieces of it in new
266
+ free programs, and that you know you can do these things.
267
+
268
+ To protect your rights, we need to prevent others from denying you
269
+ these rights or asking you to surrender the rights. Therefore, you have
270
+ certain responsibilities if you distribute copies of the software, or if
271
+ you modify it: responsibilities to respect the freedom of others.
272
+
273
+ For example, if you distribute copies of such a program, whether
274
+ gratis or for a fee, you must pass on to the recipients the same
275
+ freedoms that you received. You must make sure that they, too, receive
276
+ or can get the source code. And you must show them these terms so they
277
+ know their rights.
278
+
279
+ Developers that use the GNU GPL protect your rights with two steps:
280
+ (1) assert copyright on the software, and (2) offer you this License
281
+ giving you legal permission to copy, distribute and/or modify it.
282
+
283
+ For the developers' and authors' protection, the GPL clearly explains
284
+ that there is no warranty for this free software. For both users' and
285
+ authors' sake, the GPL requires that modified versions be marked as
286
+ changed, so that their problems will not be attributed erroneously to
287
+ authors of previous versions.
288
+
289
+ Some devices are designed to deny users access to install or run
290
+ modified versions of the software inside them, although the manufacturer
291
+ can do so. This is fundamentally incompatible with the aim of
292
+ protecting users' freedom to change the software. The systematic
293
+ pattern of such abuse occurs in the area of products for individuals to
294
+ use, which is precisely where it is most unacceptable. Therefore, we
295
+ have designed this version of the GPL to prohibit the practice for those
296
+ products. If such problems arise substantially in other domains, we
297
+ stand ready to extend this provision to those domains in future versions
298
+ of the GPL, as needed to protect the freedom of users.
299
+
300
+ Finally, every program is threatened constantly by software patents.
301
+ States should not allow patents to restrict development and use of
302
+ software on general-purpose computers, but in those that do, we wish to
303
+ avoid the special danger that patents applied to a free program could
304
+ make it effectively proprietary. To prevent this, the GPL assures that
305
+ patents cannot be used to render the program non-free.
306
+
307
+ The precise terms and conditions for copying, distribution and
308
+ modification follow.
309
+
310
+ TERMS AND CONDITIONS
311
+
312
+ 0. Definitions.
313
+
314
+ "This License" refers to version 3 of the GNU General Public License.
315
+
316
+ "Copyright" also means copyright-like laws that apply to other kinds of
317
+ works, such as semiconductor masks.
318
+
319
+ "The Program" refers to any copyrightable work licensed under this
320
+ License. Each licensee is addressed as "you". "Licensees" and
321
+ "recipients" may be individuals or organizations.
322
+
323
+ To "modify" a work means to copy from or adapt all or part of the work
324
+ in a fashion requiring copyright permission, other than the making of an
325
+ exact copy. The resulting work is called a "modified version" of the
326
+ earlier work or a work "based on" the earlier work.
327
+
328
+ A "covered work" means either the unmodified Program or a work based
329
+ on the Program.
330
+
331
+ To "propagate" a work means to do anything with it that, without
332
+ permission, would make you directly or secondarily liable for
333
+ infringement under applicable copyright law, except executing it on a
334
+ computer or modifying a private copy. Propagation includes copying,
335
+ distribution (with or without modification), making available to the
336
+ public, and in some countries other activities as well.
337
+
338
+ To "convey" a work means any kind of propagation that enables other
339
+ parties to make or receive copies. Mere interaction with a user through
340
+ a computer network, with no transfer of a copy, is not conveying.
341
+
342
+ An interactive user interface displays "Appropriate Legal Notices"
343
+ to the extent that it includes a convenient and prominently visible
344
+ feature that (1) displays an appropriate copyright notice, and (2)
345
+ tells the user that there is no warranty for the work (except to the
346
+ extent that warranties are provided), that licensees may convey the
347
+ work under this License, and how to view a copy of this License. If
348
+ the interface presents a list of user commands or options, such as a
349
+ menu, a prominent item in the list meets this criterion.
350
+
351
+ 1. Source Code.
352
+
353
+ The "source code" for a work means the preferred form of the work
354
+ for making modifications to it. "Object code" means any non-source
355
+ form of a work.
356
+
357
+ A "Standard Interface" means an interface that either is an official
358
+ standard defined by a recognized standards body, or, in the case of
359
+ interfaces specified for a particular programming language, one that
360
+ is widely used among developers working in that language.
361
+
362
+ The "System Libraries" of an executable work include anything, other
363
+ than the work as a whole, that (a) is included in the normal form of
364
+ packaging a Major Component, but which is not part of that Major
365
+ Component, and (b) serves only to enable use of the work with that
366
+ Major Component, or to implement a Standard Interface for which an
367
+ implementation is available to the public in source code form. A
368
+ "Major Component", in this context, means a major essential component
369
+ (kernel, window system, and so on) of the specific operating system
370
+ (if any) on which the executable work runs, or a compiler used to
371
+ produce the work, or an object code interpreter used to run it.
372
+
373
+ The "Corresponding Source" for a work in object code form means all
374
+ the source code needed to generate, install, and (for an executable
375
+ work) run the object code and to modify the work, including scripts to
376
+ control those activities. However, it does not include the work's
377
+ System Libraries, or general-purpose tools or generally available free
378
+ programs which are used unmodified in performing those activities but
379
+ which are not part of the work. For example, Corresponding Source
380
+ includes interface definition files associated with source files for
381
+ the work, and the source code for shared libraries and dynamically
382
+ linked subprograms that the work is specifically designed to require,
383
+ such as by intimate data communication or control flow between those
384
+ subprograms and other parts of the work.
385
+
386
+ The Corresponding Source need not include anything that users
387
+ can regenerate automatically from other parts of the Corresponding
388
+ Source.
389
+
390
+ The Corresponding Source for a work in source code form is that
391
+ same work.
392
+
393
+ 2. Basic Permissions.
394
+
395
+ All rights granted under this License are granted for the term of
396
+ copyright on the Program, and are irrevocable provided the stated
397
+ conditions are met. This License explicitly affirms your unlimited
398
+ permission to run the unmodified Program. The output from running a
399
+ covered work is covered by this License only if the output, given its
400
+ content, constitutes a covered work. This License acknowledges your
401
+ rights of fair use or other equivalent, as provided by copyright law.
402
+
403
+ You may make, run and propagate covered works that you do not
404
+ convey, without conditions so long as your license otherwise remains
405
+ in force. You may convey covered works to others for the sole purpose
406
+ of having them make modifications exclusively for you, or provide you
407
+ with facilities for running those works, provided that you comply with
408
+ the terms of this License in conveying all material for which you do
409
+ not control copyright. Those thus making or running the covered works
410
+ for you must do so exclusively on your behalf, under your direction
411
+ and control, on terms that prohibit them from making any copies of
412
+ your copyrighted material outside their relationship with you.
413
+
414
+ Conveying under any other circumstances is permitted solely under
415
+ the conditions stated below. Sublicensing is not allowed; section 10
416
+ makes it unnecessary.
417
+
418
+ 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
419
+
420
+ No covered work shall be deemed part of an effective technological
421
+ measure under any applicable law fulfilling obligations under article
422
+ 11 of the WIPO copyright treaty adopted on 20 December 1996, or
423
+ similar laws prohibiting or restricting circumvention of such
424
+ measures.
425
+
426
+ When you convey a covered work, you waive any legal power to forbid
427
+ circumvention of technological measures to the extent such circumvention
428
+ is effected by exercising rights under this License with respect to
429
+ the covered work, and you disclaim any intention to limit operation or
430
+ modification of the work as a means of enforcing, against the work's
431
+ users, your or third parties' legal rights to forbid circumvention of
432
+ technological measures.
433
+
434
+ 4. Conveying Verbatim Copies.
435
+
436
+ You may convey verbatim copies of the Program's source code as you
437
+ receive it, in any medium, provided that you conspicuously and
438
+ appropriately publish on each copy an appropriate copyright notice;
439
+ keep intact all notices stating that this License and any
440
+ non-permissive terms added in accord with section 7 apply to the code;
441
+ keep intact all notices of the absence of any warranty; and give all
442
+ recipients a copy of this License along with the Program.
443
+
444
+ You may charge any price or no price for each copy that you convey,
445
+ and you may offer support or warranty protection for a fee.
446
+
447
+ 5. Conveying Modified Source Versions.
448
+
449
+ You may convey a work based on the Program, or the modifications to
450
+ produce it from the Program, in the form of source code under the
451
+ terms of section 4, provided that you also meet all of these conditions:
452
+
453
+ a) The work must carry prominent notices stating that you modified
454
+ it, and giving a relevant date.
455
+
456
+ b) The work must carry prominent notices stating that it is
457
+ released under this License and any conditions added under section
458
+ 7. This requirement modifies the requirement in section 4 to
459
+ "keep intact all notices".
460
+
461
+ c) You must license the entire work, as a whole, under this
462
+ License to anyone who comes into possession of a copy. This
463
+ License will therefore apply, along with any applicable section 7
464
+ additional terms, to the whole of the work, and all its parts,
465
+ regardless of how they are packaged. This License gives no
466
+ permission to license the work in any other way, but it does not
467
+ invalidate such permission if you have separately received it.
468
+
469
+ d) If the work has interactive user interfaces, each must display
470
+ Appropriate Legal Notices; however, if the Program has interactive
471
+ interfaces that do not display Appropriate Legal Notices, your
472
+ work need not make them do so.
473
+
474
+ A compilation of a covered work with other separate and independent
475
+ works, which are not by their nature extensions of the covered work,
476
+ and which are not combined with it such as to form a larger program,
477
+ in or on a volume of a storage or distribution medium, is called an
478
+ "aggregate" if the compilation and its resulting copyright are not
479
+ used to limit the access or legal rights of the compilation's users
480
+ beyond what the individual works permit. Inclusion of a covered work
481
+ in an aggregate does not cause this License to apply to the other
482
+ parts of the aggregate.
483
+
484
+ 6. Conveying Non-Source Forms.
485
+
486
+ You may convey a covered work in object code form under the terms
487
+ of sections 4 and 5, provided that you also convey the
488
+ machine-readable Corresponding Source under the terms of this License,
489
+ in one of these ways:
490
+
491
+ a) Convey the object code in, or embodied in, a physical product
492
+ (including a physical distribution medium), accompanied by the
493
+ Corresponding Source fixed on a durable physical medium
494
+ customarily used for software interchange.
495
+
496
+ b) Convey the object code in, or embodied in, a physical product
497
+ (including a physical distribution medium), accompanied by a
498
+ written offer, valid for at least three years and valid for as
499
+ long as you offer spare parts or customer support for that product
500
+ model, to give anyone who possesses the object code either (1) a
501
+ copy of the Corresponding Source for all the software in the
502
+ product that is covered by this License, on a durable physical
503
+ medium customarily used for software interchange, for a price no
504
+ more than your reasonable cost of physically performing this
505
+ conveying of source, or (2) access to copy the
506
+ Corresponding Source from a network server at no charge.
507
+
508
+ c) Convey individual copies of the object code with a copy of the
509
+ written offer to provide the Corresponding Source. This
510
+ alternative is allowed only occasionally and noncommercially, and
511
+ only if you received the object code with such an offer, in accord
512
+ with subsection 6b.
513
+
514
+ d) Convey the object code by offering access from a designated
515
+ place (gratis or for a charge), and offer equivalent access to the
516
+ Corresponding Source in the same way through the same place at no
517
+ further charge. You need not require recipients to copy the
518
+ Corresponding Source along with the object code. If the place to
519
+ copy the object code is a network server, the Corresponding Source
520
+ may be on a different server (operated by you or a third party)
521
+ that supports equivalent copying facilities, provided you maintain
522
+ clear directions next to the object code saying where to find the
523
+ Corresponding Source. Regardless of what server hosts the
524
+ Corresponding Source, you remain obligated to ensure that it is
525
+ available for as long as needed to satisfy these requirements.
526
+
527
+ e) Convey the object code using peer-to-peer transmission, provided
528
+ you inform other peers where the object code and Corresponding
529
+ Source of the work are being offered to the general public at no
530
+ charge under subsection 6d.
531
+
532
+ A separable portion of the object code, whose source code is excluded
533
+ from the Corresponding Source as a System Library, need not be
534
+ included in conveying the object code work.
535
+
536
+ A "User Product" is either (1) a "consumer product", which means any
537
+ tangible personal property which is normally used for personal, family,
538
+ or household purposes, or (2) anything designed or sold for incorporation
539
+ into a dwelling. In determining whether a product is a consumer product,
540
+ doubtful cases shall be resolved in favor of coverage. For a particular
541
+ product received by a particular user, "normally used" refers to a
542
+ typical or common use of that class of product, regardless of the status
543
+ of the particular user or of the way in which the particular user
544
+ actually uses, or expects or is expected to use, the product. A product
545
+ is a consumer product regardless of whether the product has substantial
546
+ commercial, industrial or non-consumer uses, unless such uses represent
547
+ the only significant mode of use of the product.
548
+
549
+ "Installation Information" for a User Product means any methods,
550
+ procedures, authorization keys, or other information required to install
551
+ and execute modified versions of a covered work in that User Product from
552
+ a modified version of its Corresponding Source. The information must
553
+ suffice to ensure that the continued functioning of the modified object
554
+ code is in no case prevented or interfered with solely because
555
+ modification has been made.
556
+
557
+ If you convey an object code work under this section in, or with, or
558
+ specifically for use in, a User Product, and the conveying occurs as
559
+ part of a transaction in which the right of possession and use of the
560
+ User Product is transferred to the recipient in perpetuity or for a
561
+ fixed term (regardless of how the transaction is characterized), the
562
+ Corresponding Source conveyed under this section must be accompanied
563
+ by the Installation Information. But this requirement does not apply
564
+ if neither you nor any third party retains the ability to install
565
+ modified object code on the User Product (for example, the work has
566
+ been installed in ROM).
567
+
568
+ The requirement to provide Installation Information does not include a
569
+ requirement to continue to provide support service, warranty, or updates
570
+ for a work that has been modified or installed by the recipient, or for
571
+ the User Product in which it has been modified or installed. Access to a
572
+ network may be denied when the modification itself materially and
573
+ adversely affects the operation of the network or violates the rules and
574
+ protocols for communication across the network.
575
+
576
+ Corresponding Source conveyed, and Installation Information provided,
577
+ in accord with this section must be in a format that is publicly
578
+ documented (and with an implementation available to the public in
579
+ source code form), and must require no special password or key for
580
+ unpacking, reading or copying.
581
+
582
+ 7. Additional Terms.
583
+
584
+ "Additional permissions" are terms that supplement the terms of this
585
+ License by making exceptions from one or more of its conditions.
586
+ Additional permissions that are applicable to the entire Program shall
587
+ be treated as though they were included in this License, to the extent
588
+ that they are valid under applicable law. If additional permissions
589
+ apply only to part of the Program, that part may be used separately
590
+ under those permissions, but the entire Program remains governed by
591
+ this License without regard to the additional permissions.
592
+
593
+ When you convey a copy of a covered work, you may at your option
594
+ remove any additional permissions from that copy, or from any part of
595
+ it. (Additional permissions may be written to require their own
596
+ removal in certain cases when you modify the work.) You may place
597
+ additional permissions on material, added by you to a covered work,
598
+ for which you have or can give appropriate copyright permission.
599
+
600
+ Notwithstanding any other provision of this License, for material you
601
+ add to a covered work, you may (if authorized by the copyright holders of
602
+ that material) supplement the terms of this License with terms:
603
+
604
+ a) Disclaiming warranty or limiting liability differently from the
605
+ terms of sections 15 and 16 of this License; or
606
+
607
+ b) Requiring preservation of specified reasonable legal notices or
608
+ author attributions in that material or in the Appropriate Legal
609
+ Notices displayed by works containing it; or
610
+
611
+ c) Prohibiting misrepresentation of the origin of that material, or
612
+ requiring that modified versions of such material be marked in
613
+ reasonable ways as different from the original version; or
614
+
615
+ d) Limiting the use for publicity purposes of names of licensors or
616
+ authors of the material; or
617
+
618
+ e) Declining to grant rights under trademark law for use of some
619
+ trade names, trademarks, or service marks; or
620
+
621
+ f) Requiring indemnification of licensors and authors of that
622
+ material by anyone who conveys the material (or modified versions of
623
+ it) with contractual assumptions of liability to the recipient, for
624
+ any liability that these contractual assumptions directly impose on
625
+ those licensors and authors.
626
+
627
+ All other non-permissive additional terms are considered "further
628
+ restrictions" within the meaning of section 10. If the Program as you
629
+ received it, or any part of it, contains a notice stating that it is
630
+ governed by this License along with a term that is a further
631
+ restriction, you may remove that term. If a license document contains
632
+ a further restriction but permits relicensing or conveying under this
633
+ License, you may add to a covered work material governed by the terms
634
+ of that license document, provided that the further restriction does
635
+ not survive such relicensing or conveying.
636
+
637
+ If you add terms to a covered work in accord with this section, you
638
+ must place, in the relevant source files, a statement of the
639
+ additional terms that apply to those files, or a notice indicating
640
+ where to find the applicable terms.
641
+
642
+ Additional terms, permissive or non-permissive, may be stated in the
643
+ form of a separately written license, or stated as exceptions;
644
+ the above requirements apply either way.
645
+
646
+ 8. Termination.
647
+
648
+ You may not propagate or modify a covered work except as expressly
649
+ provided under this License. Any attempt otherwise to propagate or
650
+ modify it is void, and will automatically terminate your rights under
651
+ this License (including any patent licenses granted under the third
652
+ paragraph of section 11).
653
+
654
+ However, if you cease all violation of this License, then your
655
+ license from a particular copyright holder is reinstated (a)
656
+ provisionally, unless and until the copyright holder explicitly and
657
+ finally terminates your license, and (b) permanently, if the copyright
658
+ holder fails to notify you of the violation by some reasonable means
659
+ prior to 60 days after the cessation.
660
+
661
+ Moreover, your license from a particular copyright holder is
662
+ reinstated permanently if the copyright holder notifies you of the
663
+ violation by some reasonable means, this is the first time you have
664
+ received notice of violation of this License (for any work) from that
665
+ copyright holder, and you cure the violation prior to 30 days after
666
+ your receipt of the notice.
667
+
668
+ Termination of your rights under this section does not terminate the
669
+ licenses of parties who have received copies or rights from you under
670
+ this License. If your rights have been terminated and not permanently
671
+ reinstated, you do not qualify to receive new licenses for the same
672
+ material under section 10.
673
+
674
+ 9. Acceptance Not Required for Having Copies.
675
+
676
+ You are not required to accept this License in order to receive or
677
+ run a copy of the Program. Ancillary propagation of a covered work
678
+ occurring solely as a consequence of using peer-to-peer transmission
679
+ to receive a copy likewise does not require acceptance. However,
680
+ nothing other than this License grants you permission to propagate or
681
+ modify any covered work. These actions infringe copyright if you do
682
+ not accept this License. Therefore, by modifying or propagating a
683
+ covered work, you indicate your acceptance of this License to do so.
684
+
685
+ 10. Automatic Licensing of Downstream Recipients.
686
+
687
+ Each time you convey a covered work, the recipient automatically
688
+ receives a license from the original licensors, to run, modify and
689
+ propagate that work, subject to this License. You are not responsible
690
+ for enforcing compliance by third parties with this License.
691
+
692
+ An "entity transaction" is a transaction transferring control of an
693
+ organization, or substantially all assets of one, or subdividing an
694
+ organization, or merging organizations. If propagation of a covered
695
+ work results from an entity transaction, each party to that
696
+ transaction who receives a copy of the work also receives whatever
697
+ licenses to the work the party's predecessor in interest had or could
698
+ give under the previous paragraph, plus a right to possession of the
699
+ Corresponding Source of the work from the predecessor in interest, if
700
+ the predecessor has it or can get it with reasonable efforts.
701
+
702
+ You may not impose any further restrictions on the exercise of the
703
+ rights granted or affirmed under this License. For example, you may
704
+ not impose a license fee, royalty, or other charge for exercise of
705
+ rights granted under this License, and you may not initiate litigation
706
+ (including a cross-claim or counterclaim in a lawsuit) alleging that
707
+ any patent claim is infringed by making, using, selling, offering for
708
+ sale, or importing the Program or any portion of it.
709
+
710
+ 11. Patents.
711
+
712
+ A "contributor" is a copyright holder who authorizes use under this
713
+ License of the Program or a work on which the Program is based. The
714
+ work thus licensed is called the contributor's "contributor version".
715
+
716
+ A contributor's "essential patent claims" are all patent claims
717
+ owned or controlled by the contributor, whether already acquired or
718
+ hereafter acquired, that would be infringed by some manner, permitted
719
+ by this License, of making, using, or selling its contributor version,
720
+ but do not include claims that would be infringed only as a
721
+ consequence of further modification of the contributor version. For
722
+ purposes of this definition, "control" includes the right to grant
723
+ patent sublicenses in a manner consistent with the requirements of
724
+ this License.
725
+
726
+ Each contributor grants you a non-exclusive, worldwide, royalty-free
727
+ patent license under the contributor's essential patent claims, to
728
+ make, use, sell, offer for sale, import and otherwise run, modify and
729
+ propagate the contents of its contributor version.
730
+
731
+ In the following three paragraphs, a "patent license" is any express
732
+ agreement or commitment, however denominated, not to enforce a patent
733
+ (such as an express permission to practice a patent or covenant not to
734
+ sue for patent infringement). To "grant" such a patent license to a
735
+ party means to make such an agreement or commitment not to enforce a
736
+ patent against the party.
737
+
738
+ If you convey a covered work, knowingly relying on a patent license,
739
+ and the Corresponding Source of the work is not available for anyone
740
+ to copy, free of charge and under the terms of this License, through a
741
+ publicly available network server or other readily accessible means,
742
+ then you must either (1) cause the Corresponding Source to be so
743
+ available, or (2) arrange to deprive yourself of the benefit of the
744
+ patent license for this particular work, or (3) arrange, in a manner
745
+ consistent with the requirements of this License, to extend the patent
746
+ license to downstream recipients. "Knowingly relying" means you have
747
+ actual knowledge that, but for the patent license, your conveying the
748
+ covered work in a country, or your recipient's use of the covered work
749
+ in a country, would infringe one or more identifiable patents in that
750
+ country that you have reason to believe are valid.
751
+
752
+ If, pursuant to or in connection with a single transaction or
753
+ arrangement, you convey, or propagate by procuring conveyance of, a
754
+ covered work, and grant a patent license to some of the parties
755
+ receiving the covered work authorizing them to use, propagate, modify
756
+ or convey a specific copy of the covered work, then the patent license
757
+ you grant is automatically extended to all recipients of the covered
758
+ work and works based on it.
759
+
760
+ A patent license is "discriminatory" if it does not include within
761
+ the scope of its coverage, prohibits the exercise of, or is
762
+ conditioned on the non-exercise of one or more of the rights that are
763
+ specifically granted under this License. You may not convey a covered
764
+ work if you are a party to an arrangement with a third party that is
765
+ in the business of distributing software, under which you make payment
766
+ to the third party based on the extent of your activity of conveying
767
+ the work, and under which the third party grants, to any of the
768
+ parties who would receive the covered work from you, a discriminatory
769
+ patent license (a) in connection with copies of the covered work
770
+ conveyed by you (or copies made from those copies), or (b) primarily
771
+ for and in connection with specific products or compilations that
772
+ contain the covered work, unless you entered into that arrangement,
773
+ or that patent license was granted, prior to 28 March 2007.
774
+
775
+ Nothing in this License shall be construed as excluding or limiting
776
+ any implied license or other defenses to infringement that may
777
+ otherwise be available to you under applicable patent law.
778
+
779
+ 12. No Surrender of Others' Freedom.
780
+
781
+ If conditions are imposed on you (whether by court order, agreement or
782
+ otherwise) that contradict the conditions of this License, they do not
783
+ excuse you from the conditions of this License. If you cannot convey a
784
+ covered work so as to satisfy simultaneously your obligations under this
785
+ License and any other pertinent obligations, then as a consequence you may
786
+ not convey it at all. For example, if you agree to terms that obligate you
787
+ to collect a royalty for further conveying from those to whom you convey
788
+ the Program, the only way you could satisfy both those terms and this
789
+ License would be to refrain entirely from conveying the Program.
790
+
791
+ 13. Use with the GNU Affero General Public License.
792
+
793
+ Notwithstanding any other provision of this License, you have
794
+ permission to link or combine any covered work with a work licensed
795
+ under version 3 of the GNU Affero General Public License into a single
796
+ combined work, and to convey the resulting work. The terms of this
797
+ License will continue to apply to the part which is the covered work,
798
+ but the special requirements of the GNU Affero General Public License,
799
+ section 13, concerning interaction through a network will apply to the
800
+ combination as such.
801
+
802
+ 14. Revised Versions of this License.
803
+
804
+ The Free Software Foundation may publish revised and/or new versions of
805
+ the GNU General Public License from time to time. Such new versions will
806
+ be similar in spirit to the present version, but may differ in detail to
807
+ address new problems or concerns.
808
+
809
+ Each version is given a distinguishing version number. If the
810
+ Program specifies that a certain numbered version of the GNU General
811
+ Public License "or any later version" applies to it, you have the
812
+ option of following the terms and conditions either of that numbered
813
+ version or of any later version published by the Free Software
814
+ Foundation. If the Program does not specify a version number of the
815
+ GNU General Public License, you may choose any version ever published
816
+ by the Free Software Foundation.
817
+
818
+ If the Program specifies that a proxy can decide which future
819
+ versions of the GNU General Public License can be used, that proxy's
820
+ public statement of acceptance of a version permanently authorizes you
821
+ to choose that version for the Program.
822
+
823
+ Later license versions may give you additional or different
824
+ permissions. However, no additional obligations are imposed on any
825
+ author or copyright holder as a result of your choosing to follow a
826
+ later version.
827
+
828
+ 15. Disclaimer of Warranty.
829
+
830
+ THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
831
+ APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
832
+ HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
833
+ OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
834
+ THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
835
+ PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
836
+ IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
837
+ ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
838
+
839
+ 16. Limitation of Liability.
840
+
841
+ IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
842
+ WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
843
+ THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
844
+ GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
845
+ USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
846
+ DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
847
+ PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
848
+ EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
849
+ SUCH DAMAGES.
850
+
851
+ 17. Interpretation of Sections 15 and 16.
852
+
853
+ If the disclaimer of warranty and limitation of liability provided
854
+ above cannot be given local legal effect according to their terms,
855
+ reviewing courts shall apply local law that most closely approximates
856
+ an absolute waiver of all civil liability in connection with the
857
+ Program, unless a warranty or assumption of liability accompanies a
858
+ copy of the Program in return for a fee.
859
+
860
+ END OF TERMS AND CONDITIONS
861
+
862
+ How to Apply These Terms to Your New Programs
863
+
864
+ If you develop a new program, and you want it to be of the greatest
865
+ possible use to the public, the best way to achieve this is to make it
866
+ free software which everyone can redistribute and change under these terms.
867
+
868
+ To do so, attach the following notices to the program. It is safest
869
+ to attach them to the start of each source file to most effectively
870
+ state the exclusion of warranty; and each file should have at least
871
+ the "copyright" line and a pointer to where the full notice is found.
872
+
873
+ <one line to give the program's name and a brief idea of what it does.>
874
+ Copyright (C) <year> <name of author>
875
+
876
+ This program is free software: you can redistribute it and/or modify
877
+ it under the terms of the GNU General Public License as published by
878
+ the Free Software Foundation, either version 3 of the License, or
879
+ (at your option) any later version.
880
+
881
+ This program is distributed in the hope that it will be useful,
882
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
883
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
884
+ GNU General Public License for more details.
885
+
886
+ You should have received a copy of the GNU General Public License
887
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
888
+
889
+ Also add information on how to contact you by electronic and paper mail.
890
+
891
+ If the program does terminal interaction, make it output a short
892
+ notice like this when it starts in an interactive mode:
893
+
894
+ <program> Copyright (C) <year> <name of author>
895
+ This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
896
+ This is free software, and you are welcome to redistribute it
897
+ under certain conditions; type `show c' for details.
898
+
899
+ The hypothetical commands `show w' and `show c' should show the appropriate
900
+ parts of the General Public License. Of course, your program's commands
901
+ might be different; for a GUI interface, you would use an "about box".
902
+
903
+ You should also get your employer (if you work as a programmer) or school,
904
+ if any, to sign a "copyright disclaimer" for the program, if necessary.
905
+ For more information on this, and how to apply and follow the GNU GPL, see
906
+ <https://www.gnu.org/licenses/>.
907
+
908
+ The GNU General Public License does not permit incorporating your program
909
+ into proprietary programs. If your program is a subroutine library, you
910
+ may consider it more useful to permit linking proprietary applications with
911
+ the library. If this is what you want to do, use the GNU Lesser General
912
+ Public License instead of this License. But first, please read
913
+ <https://www.gnu.org/licenses/why-not-lgpl.html>.
914
+
915
+ Name: libquadmath
916
+ Files: numpy.libs/libquadmath*.so
917
+ Description: dynamically linked to files compiled with gcc
918
+ Availability: https://gcc.gnu.org/git/?p=gcc.git;a=tree;f=libquadmath
919
+ License: LGPL-2.1-or-later
920
+
921
+ GCC Quad-Precision Math Library
922
+ Copyright (C) 2010-2019 Free Software Foundation, Inc.
923
+ Written by Francois-Xavier Coudert <fxcoudert@gcc.gnu.org>
924
+
925
+ This file is part of the libquadmath library.
926
+ Libquadmath is free software; you can redistribute it and/or
927
+ modify it under the terms of the GNU Library General Public
928
+ License as published by the Free Software Foundation; either
929
+ version 2.1 of the License, or (at your option) any later version.
930
+
931
+ Libquadmath is distributed in the hope that it will be useful,
932
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
933
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
934
+ Lesser General Public License for more details.
935
+ https://www.gnu.org/licenses/old-licenses/lgpl-2.1.html
physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy-2.4.6.dist-info/licenses/numpy/_core/include/numpy/libdivide/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ zlib License
2
+ ------------
3
+
4
+ Copyright (C) 2010 - 2019 ridiculous_fish, <libdivide@ridiculousfish.com>
5
+ Copyright (C) 2016 - 2019 Kim Walisch, <kim.walisch@gmail.com>
6
+
7
+ This software is provided 'as-is', without any express or implied
8
+ warranty. In no event will the authors be held liable for any damages
9
+ arising from the use of this software.
10
+
11
+ Permission is granted to anyone to use this software for any purpose,
12
+ including commercial applications, and to alter it and redistribute it
13
+ freely, subject to the following restrictions:
14
+
15
+ 1. The origin of this software must not be misrepresented; you must not
16
+ claim that you wrote the original software. If you use this software
17
+ in a product, an acknowledgment in the product documentation would be
18
+ appreciated but is not required.
19
+ 2. Altered source versions must be plainly marked as such, and must not be
20
+ misrepresented as being the original software.
21
+ 3. This notice may not be removed or altered from any source distribution.
physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy-2.4.6.dist-info/licenses/numpy/_core/src/common/pythoncapi-compat/COPYING ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ BSD Zero Clause License
2
+
3
+ Copyright Contributors to the pythoncapi_compat project.
4
+
5
+ Permission to use, copy, modify, and/or distribute this software for any
6
+ purpose with or without fee is hereby granted.
7
+
8
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
9
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
10
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
11
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
12
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
13
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
14
+ PERFORMANCE OF THIS SOFTWARE.
physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy-2.4.6.dist-info/licenses/numpy/_core/src/highway/LICENSE ADDED
@@ -0,0 +1,371 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ This project is primarily dual-licensed under your choice of either the Apache
2
+ License 2.0 or the BSD 3-Clause License.
3
+
4
+ The following files are licensed under different terms:
5
+ * hwy/contrib/random/random-inl.h: CC0 1.0 Universal
6
+
7
+ The full texts of all applicable licenses are included below, separated by
8
+ '---'.
9
+
10
+ --------------------------------------------------------------------------------
11
+ Apache License 2.0
12
+ --------------------------------------------------------------------------------
13
+
14
+ Apache License
15
+ Version 2.0, January 2004
16
+ http://www.apache.org/licenses/
17
+
18
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
19
+
20
+ 1. Definitions.
21
+
22
+ "License" shall mean the terms and conditions for use, reproduction,
23
+ and distribution as defined by Sections 1 through 9 of this document.
24
+
25
+ "Licensor" shall mean the copyright owner or entity authorized by
26
+ the copyright owner that is granting the License.
27
+
28
+ "Legal Entity" shall mean the union of the acting entity and all
29
+ other entities that control, are controlled by, or are under common
30
+ control with that entity. For the purposes of this definition,
31
+ "control" means (i) the power, direct or indirect, to cause the
32
+ direction or management of such entity, whether by contract or
33
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
34
+ outstanding shares, or (iii) beneficial ownership of such entity.
35
+
36
+ "You" (or "Your") shall mean an individual or Legal Entity
37
+ exercising permissions granted by this License.
38
+
39
+ "Source" form shall mean the preferred form for making modifications,
40
+ including but not limited to software source code, documentation
41
+ source, and configuration files.
42
+
43
+ "Object" form shall mean any form resulting from mechanical
44
+ transformation or translation of a Source form, including but
45
+ not limited to compiled object code, generated documentation,
46
+ and conversions to other media types.
47
+
48
+ "Work" shall mean the work of authorship, whether in Source or
49
+ Object form, made available under the License, as indicated by a
50
+ copyright notice that is included in or attached to the work
51
+ (an example is provided in the Appendix below).
52
+
53
+ "Derivative Works" shall mean any work, whether in Source or Object
54
+ form, that is based on (or derived from) the Work and for which the
55
+ editorial revisions, annotations, elaborations, or other modifications
56
+ represent, as a whole, an original work of authorship. For the purposes
57
+ of this License, Derivative Works shall not include works that remain
58
+ separable from, or merely link (or bind by name) to the interfaces of,
59
+ the Work and Derivative Works thereof.
60
+
61
+ "Contribution" shall mean any work of authorship, including
62
+ the original version of the Work and any modifications or additions
63
+ to that Work or Derivative Works thereof, that is intentionally
64
+ submitted to Licensor for inclusion in the Work by the copyright owner
65
+ or by an individual or Legal Entity authorized to submit on behalf of
66
+ the copyright owner. For the purposes of this definition, "submitted"
67
+ means any form of electronic, verbal, or written communication sent
68
+ to the Licensor or its representatives, including but not limited to
69
+ communication on electronic mailing lists, source code control systems,
70
+ and issue tracking systems that are managed by, or on behalf of, the
71
+ Licensor for the purpose of discussing and improving the Work, but
72
+ excluding communication that is conspicuously marked or otherwise
73
+ designated in writing by the copyright owner as "Not a Contribution."
74
+
75
+ "Contributor" shall mean Licensor and any individual or Legal Entity
76
+ on behalf of whom a Contribution has been received by Licensor and
77
+ subsequently incorporated within the Work.
78
+
79
+ 2. Grant of Copyright License. Subject to the terms and conditions of
80
+ this License, each Contributor hereby grants to You a perpetual,
81
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
82
+ copyright license to reproduce, prepare Derivative Works of,
83
+ publicly display, publicly perform, sublicense, and distribute the
84
+ Work and such Derivative Works in Source or Object form.
85
+
86
+ 3. Grant of Patent License. Subject to the terms and conditions of
87
+ this License, each Contributor hereby grants to You a perpetual,
88
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
89
+ (except as stated in this section) patent license to make, have made,
90
+ use, offer to sell, sell, import, and otherwise transfer the Work,
91
+ where such license applies only to those patent claims licensable
92
+ by such Contributor that are necessarily infringed by their
93
+ Contribution(s) alone or by combination of their Contribution(s)
94
+ with the Work to which such Contribution(s) was submitted. If You
95
+ institute patent litigation against any entity (including a
96
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
97
+ or a Contribution incorporated within the Work constitutes direct
98
+ or contributory patent infringement, then any patent licenses
99
+ granted to You under this License for that Work shall terminate
100
+ as of the date such litigation is filed.
101
+
102
+ 4. Redistribution. You may reproduce and distribute copies of the
103
+ Work or Derivative Works thereof in any medium, with or without
104
+ modifications, and in Source or Object form, provided that You
105
+ meet the following conditions:
106
+
107
+ (a) You must give any other recipients of the Work or
108
+ Derivative Works a copy of this License; and
109
+
110
+ (b) You must cause any modified files to carry prominent notices
111
+ stating that You changed the files; and
112
+
113
+ (c) You must retain, in the Source form of any Derivative Works
114
+ that You distribute, all copyright, patent, trademark, and
115
+ attribution notices from the Source form of the Work,
116
+ excluding those notices that do not pertain to any part of
117
+ the Derivative Works; and
118
+
119
+ (d) If the Work includes a "NOTICE" text file as part of its
120
+ distribution, then any Derivative Works that You distribute must
121
+ include a readable copy of the attribution notices contained
122
+ within such NOTICE file, excluding those notices that do not
123
+ pertain to any part of the Derivative Works, in at least one
124
+ of the following places: within a NOTICE text file distributed
125
+ as part of the Derivative Works; within the Source form or
126
+ documentation, if provided along with the Derivative Works; or,
127
+ within a display generated by the Derivative Works, if and
128
+ wherever such third-party notices normally appear. The contents
129
+ of the NOTICE file are for informational purposes only and
130
+ do not modify the License. You may add Your own attribution
131
+ notices within Derivative Works that You distribute, alongside
132
+ or as an addendum to the NOTICE text from the Work, provided
133
+ that such additional attribution notices cannot be construed
134
+ as modifying the License.
135
+
136
+ You may add Your own copyright statement to Your modifications and
137
+ may provide additional or different license terms and conditions
138
+ for use, reproduction, or distribution of Your modifications, or
139
+ for any such Derivative Works as a whole, provided Your use,
140
+ reproduction, and distribution of the Work otherwise complies with
141
+ the conditions stated in this License.
142
+
143
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
144
+ any Contribution intentionally submitted for inclusion in the Work
145
+ by You to the Licensor shall be under the terms and conditions of
146
+ this License, without any additional terms or conditions.
147
+ Notwithstanding the above, nothing herein shall supersede or modify
148
+ the terms of any separate license agreement you may have executed
149
+ with Licensor regarding such Contributions.
150
+
151
+ 6. Trademarks. This License does not grant permission to use the trade
152
+ names, trademarks, service marks, or product names of the Licensor,
153
+ except as required for reasonable and customary use in describing the
154
+ origin of the Work and reproducing the content of the NOTICE file.
155
+
156
+ 7. Disclaimer of Warranty. Unless required by applicable law or
157
+ agreed to in writing, Licensor provides the Work (and each
158
+ Contributor provides its Contributions) on an "AS IS" BASIS,
159
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
160
+ implied, including, without limitation, any warranties or conditions
161
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
162
+ PARTICULAR PURPOSE. You are solely responsible for determining the
163
+ appropriateness of using or redistributing the Work and assume any
164
+ risks associated with Your exercise of permissions under this License.
165
+
166
+ 8. Limitation of Liability. In no event and under no legal theory,
167
+ whether in tort (including negligence), contract, or otherwise,
168
+ unless required by applicable law (such as deliberate and grossly
169
+ negligent acts) or agreed to in writing, shall any Contributor be
170
+ liable to You for damages, including any direct, indirect, special,
171
+ incidental, or consequential damages of any character arising as a
172
+ result of this License or out of the use or inability to use the
173
+ Work (including but not limited to damages for loss of goodwill,
174
+ work stoppage, computer failure or malfunction, or any and all
175
+ other commercial damages or losses), even if such Contributor
176
+ has been advised of the possibility of such damages.
177
+
178
+ 9. Accepting Warranty or Additional Liability. While redistributing
179
+ the Work or Derivative Works thereof, You may choose to offer,
180
+ and charge a fee for, acceptance of support, warranty, indemnity,
181
+ or other liability obligations and/or rights consistent with this
182
+ License. However, in accepting such obligations, You may act only
183
+ on Your own behalf and on Your sole responsibility, not on behalf
184
+ of any other Contributor, and only if You agree to indemnify,
185
+ defend, and hold each Contributor harmless for any liability
186
+ incurred by, or claims asserted against, such Contributor by reason
187
+ of your accepting any such warranty or additional liability.
188
+
189
+ END OF TERMS AND CONDITIONS
190
+
191
+ APPENDIX: How to apply the Apache License to your work.
192
+
193
+ To apply the Apache License to your work, attach the following
194
+ boilerplate notice, with the fields enclosed by brackets "[]"
195
+ replaced with your own identifying information. (Don't include
196
+ the brackets!) The text should be enclosed in the appropriate
197
+ comment syntax for the file format. We also recommend that a
198
+ file or class name and description of purpose be included on the
199
+ same "printed page" as the copyright notice for easier
200
+ identification within third-party archives.
201
+
202
+ Copyright [yyyy] [name of copyright owner]
203
+
204
+ Licensed under the Apache License, Version 2.0 (the "License");
205
+ you may not use this file except in compliance with the License.
206
+ You may obtain a copy of the License at
207
+
208
+ http://www.apache.org/licenses/LICENSE-2.0
209
+
210
+ Unless required by applicable law or agreed to in writing, software
211
+ distributed under the License is distributed on an "AS IS" BASIS,
212
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
213
+ See the License for the specific language governing permissions and
214
+ limitations under the License.
215
+
216
+ --------------------------------------------------------------------------------
217
+ BSD 3-Clause License
218
+ --------------------------------------------------------------------------------
219
+
220
+ Copyright (c) The Highway Project Authors. All rights reserved.
221
+
222
+ Redistribution and use in source and binary forms, with or without modification,
223
+ are permitted provided that the following conditions are met:
224
+
225
+ 1. Redistributions of source code must retain the above copyright notice, this
226
+ list of conditions and the following disclaimer.
227
+
228
+ 2. Redistributions in binary form must reproduce the above copyright notice,
229
+ this list of conditions and the following disclaimer in the documentation
230
+ and/or other materials provided with the distribution.
231
+
232
+ 3. Neither the name of the copyright holder nor the names of its
233
+ contributors may be used to endorse or promote products derived from
234
+ this software without specific prior written permission.
235
+
236
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
237
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
238
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
239
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
240
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
241
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
242
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
243
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
244
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
245
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
246
+
247
+ --------------------------------------------------------------------------------
248
+ CC0 1.0 Universal
249
+ --------------------------------------------------------------------------------
250
+
251
+ Creative Commons Legal Code
252
+
253
+ CC0 1.0 Universal
254
+
255
+ CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
256
+ LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN
257
+ ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
258
+ INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
259
+ REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS
260
+ PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM
261
+ THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED
262
+ HEREUNDER.
263
+
264
+ Statement of Purpose
265
+
266
+ The laws of most jurisdictions throughout the world automatically confer
267
+ exclusive Copyright and Related Rights (defined below) upon the creator
268
+ and subsequent owner(s) (each and all, an "owner") of an original work of
269
+ authorship and/or a database (each, a "Work").
270
+
271
+ Certain owners wish to permanently relinquish those rights to a Work for
272
+ the purpose of contributing to a commons of creative, cultural and
273
+ scientific works ("Commons") that the public can reliably and without fear
274
+ of later claims of infringement build upon, modify, incorporate in other
275
+ works, reuse and redistribute as freely as possible in any form whatsoever
276
+ and for any purposes, including without limitation commercial purposes.
277
+ These owners may contribute to the Commons to promote the ideal of a free
278
+ culture and the further production of creative, cultural and scientific
279
+ works, or to gain reputation or greater distribution for their Work in
280
+ part through the use and efforts of others.
281
+
282
+ For these and/or other purposes and motivations, and without any
283
+ expectation of additional consideration or compensation, the person
284
+ associating CC0 with a Work (the "Affirmer"), to the extent that he or she
285
+ is an owner of Copyright and Related Rights in the Work, voluntarily
286
+ elects to apply CC0 to the Work and publicly distribute the Work under its
287
+ terms, with knowledge of his or her Copyright and Related Rights in the
288
+ Work and the meaning and intended legal effect of CC0 on those rights.
289
+
290
+ 1. Copyright and Related Rights. A Work made available under CC0 may be
291
+ protected by copyright and related or neighboring rights ("Copyright and
292
+ Related Rights"). Copyright and Related Rights include, but are not
293
+ limited to, the following:
294
+
295
+ i. the right to reproduce, adapt, distribute, perform, display,
296
+ communicate, and translate a Work;
297
+ ii. moral rights retained by the original author(s) and/or performer(s);
298
+ iii. publicity and privacy rights pertaining to a person's image or
299
+ likeness depicted in a Work;
300
+ iv. rights protecting against unfair competition in regards to a Work,
301
+ subject to the limitations in paragraph 4(a), below;
302
+ v. rights protecting the extraction, dissemination, use and reuse of data
303
+ in a Work;
304
+ vi. database rights (such as those arising under Directive 96/9/EC of the
305
+ European Parliament and of the Council of 11 March 1996 on the legal
306
+ protection of databases, and under any national implementation
307
+ thereof, including any amended or successor version of such
308
+ directive); and
309
+ vii. other similar, equivalent or corresponding rights throughout the
310
+ world based on applicable law or treaty, and any national
311
+ implementations thereof.
312
+
313
+ 2. Waiver. To the greatest extent permitted by, but not in contravention
314
+ of, applicable law, Affirmer hereby overtly, fully, permanently,
315
+ irrevocably and unconditionally waives, abandons, and surrenders all of
316
+ Affirmer's Copyright and Related Rights and associated claims and causes
317
+ of action, whether now known or unknown (including existing as well as
318
+ future claims and causes of action), in the Work (i) in all territories
319
+ worldwide, (ii) for the maximum duration provided by applicable law or
320
+ treaty (including future time extensions), (iii) in any current or future
321
+ medium and for any number of copies, and (iv) for any purpose whatsoever,
322
+ including without limitation commercial, advertising or promotional
323
+ purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each
324
+ member of the public at large and to the detriment of Affirmer's heirs and
325
+ successors, fully intending that such Waiver shall not be subject to
326
+ revocation, rescission, cancellation, termination, or any other legal or
327
+ equitable action to disrupt the quiet enjoyment of the Work by the public
328
+ as contemplated by Affirmer's express Statement of Purpose.
329
+
330
+ 3. Public License Fallback. Should any part of the Waiver for any reason
331
+ be judged legally invalid or ineffective under applicable law, then the
332
+ Waiver shall be preserved to the maximum extent permitted taking into
333
+ account Affirmer's express Statement of Purpose. In addition, to the
334
+ extent the Waiver is so judged Affirmer hereby grants to each affected
335
+ person a royalty-free, non transferable, non sublicensable, non exclusive,
336
+ irrevocable and unconditional license to exercise Affirmer's Copyright and
337
+ Related Rights in the Work (i) in all territories worldwide, (ii) for the
338
+ maximum duration provided by applicable law or treaty (including future
339
+ time extensions), (iii) in any current or future medium and for any number
340
+ of copies, and (iv) for any purpose whatsoever, including without
341
+ limitation commercial, advertising or promotional purposes (the
342
+ "License"). The License shall be deemed effective as of the date CC0 was
343
+ applied by Affirmer to the Work. Should any part of the License for any
344
+ reason be judged legally invalid or ineffective under applicable law, such
345
+ partial invalidity or ineffectiveness shall not invalidate the remainder
346
+ of the License, and in such case Affirmer hereby affirms that he or she
347
+ will not (i) exercise any of his or her remaining Copyright and Related
348
+ Rights in the Work or (ii) assert any associated claims and causes of
349
+ action with respect to the Work, in either case contrary to Affirmer's
350
+ express Statement of Purpose.
351
+
352
+ 4. Limitations and Disclaimers.
353
+
354
+ a. No trademark or patent rights held by Affirmer are waived, abandoned,
355
+ surrendered, licensed or otherwise affected by this document.
356
+ b. Affirmer offers the Work as-is and makes no representations or
357
+ warranties of any kind concerning the Work, express, implied,
358
+ statutory or otherwise, including without limitation warranties of
359
+ title, merchantability, fitness for a particular purpose, non
360
+ infringement, or the absence of latent or other defects, accuracy, or
361
+ the present or absence of errors, whether or not discoverable, all to
362
+ the greatest extent permissible under applicable law.
363
+ c. Affirmer disclaims responsibility for clearing rights of other persons
364
+ that may apply to the Work or any use thereof, including without
365
+ limitation any person's Copyright and Related Rights in the Work.
366
+ Further, Affirmer disclaims responsibility for obtaining any necessary
367
+ consents, permissions or other rights required for any use of the
368
+ Work.
369
+ d. Affirmer understands and acknowledges that Creative Commons is not a
370
+ party to this document and has no duty or obligation with respect to
371
+ this CC0 or use of the Work.
physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy-2.4.6.dist-info/licenses/numpy/_core/src/multiarray/dragon4_LICENSE.txt ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Copyright (c) 2014 Ryan Juckett
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to
5
+ deal in the Software without restriction, including without limitation the
6
+ rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7
+ sell copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19
+ IN THE SOFTWARE.
20
+
21
+ dragon4.c|h h contains a modified version of Ryan Juckett's Dragon4
22
+ implementation, obtained from https://www.ryanjuckett.com,
23
+ which has been ported from C++ to C and which has
24
+ modifications specific to printing floats in numpy.
25
+
26
+ Ryan Juckett's original code was under the Zlib license; he gave numpy
27
+ permission to include it under the MIT license instead.
physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy-2.4.6.dist-info/licenses/numpy/_core/src/npysort/x86-simd-sort/LICENSE.md ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2022, Intel. All rights reserved.
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
7
+
8
+ 1. Redistributions of source code must retain the above copyright notice, this
9
+ list of conditions and the following disclaimer.
10
+
11
+ 2. Redistributions in binary form must reproduce the above copyright notice,
12
+ this list of conditions and the following disclaimer in the documentation
13
+ and/or other materials provided with the distribution.
14
+
15
+ 3. Neither the name of the copyright holder nor the names of its
16
+ contributors may be used to endorse or promote products derived from
17
+ this software without specific prior written permission.
18
+
19
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy-2.4.6.dist-info/licenses/numpy/_core/src/umath/svml/LICENSE ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Copyright (c) 2005-2021, NumPy 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 are
6
+ met:
7
+
8
+ * Redistributions of source code must retain the above copyright
9
+ notice, this list of conditions and the following disclaimer.
10
+
11
+ * 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
+ * Neither the name of the NumPy Developers nor the names of any
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.
physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy-2.4.6.dist-info/licenses/numpy/fft/pocketfft/LICENSE.md ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Copyright (C) 2010-2018 Max-Planck-Society
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without modification,
5
+ are permitted provided that the following conditions are met:
6
+
7
+ * Redistributions of source code must retain the above copyright notice, this
8
+ list of conditions and the following disclaimer.
9
+ * Redistributions in binary form must reproduce the above copyright notice, this
10
+ list of conditions and the following disclaimer in the documentation and/or
11
+ other materials provided with the distribution.
12
+ * Neither the name of the copyright holder nor the names of its contributors may
13
+ be used to endorse or promote products derived from this software without
14
+ specific prior written permission.
15
+
16
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
20
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
23
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy-2.4.6.dist-info/licenses/numpy/linalg/lapack_lite/LICENSE.txt ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Copyright (c) 1992-2013 The University of Tennessee and The University
2
+ of Tennessee Research Foundation. All rights
3
+ reserved.
4
+ Copyright (c) 2000-2013 The University of California Berkeley. All
5
+ rights reserved.
6
+ Copyright (c) 2006-2013 The University of Colorado Denver. All rights
7
+ reserved.
8
+
9
+ $COPYRIGHT$
10
+
11
+ Additional copyrights may follow
12
+
13
+ $HEADER$
14
+
15
+ Redistribution and use in source and binary forms, with or without
16
+ modification, are permitted provided that the following conditions are
17
+ met:
18
+
19
+ - Redistributions of source code must retain the above copyright
20
+ notice, this list of conditions and the following disclaimer.
21
+
22
+ - Redistributions in binary form must reproduce the above copyright
23
+ notice, this list of conditions and the following disclaimer listed
24
+ in this license in the documentation and/or other materials
25
+ provided with the distribution.
26
+
27
+ - Neither the name of the copyright holders nor the names of its
28
+ contributors may be used to endorse or promote products derived from
29
+ this software without specific prior written permission.
30
+
31
+ The copyright holders provide no reassurances that the source code
32
+ provided does not infringe any patent, copyright, or any other
33
+ intellectual property rights of third parties. The copyright holders
34
+ disclaim any liability to any recipient for claims brought against
35
+ recipient by any third party for infringement of that parties
36
+ intellectual property rights.
37
+
38
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
39
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
40
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
41
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
42
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
44
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
45
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
46
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
47
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
48
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy-2.4.6.dist-info/licenses/numpy/ma/LICENSE ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ * Copyright (c) 2006, University of Georgia and Pierre G.F. Gerard-Marchant
2
+ * All rights reserved.
3
+ * Redistribution and use in source and binary forms, with or without
4
+ * modification, are permitted provided that the following conditions are met:
5
+ *
6
+ * * Redistributions of source code must retain the above copyright
7
+ * notice, this list of conditions and the following disclaimer.
8
+ * * Redistributions in binary form must reproduce the above copyright
9
+ * notice, this list of conditions and the following disclaimer in the
10
+ * documentation and/or other materials provided with the distribution.
11
+ * * Neither the name of the University of Georgia nor the
12
+ * names of its contributors may be used to endorse or promote products
13
+ * derived from this software without specific prior written permission.
14
+ *
15
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
16
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18
+ * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
19
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy-2.4.6.dist-info/licenses/numpy/random/LICENSE.md ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ **This software is dual-licensed under the The University of Illinois/NCSA
2
+ Open Source License (NCSA) and The 3-Clause BSD License**
3
+
4
+ # NCSA Open Source License
5
+ **Copyright (c) 2019 Kevin Sheppard. All rights reserved.**
6
+
7
+ Developed by: Kevin Sheppard (<kevin.sheppard@economics.ox.ac.uk>,
8
+ <kevin.k.sheppard@gmail.com>)
9
+ [http://www.kevinsheppard.com](http://www.kevinsheppard.com)
10
+
11
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
12
+ this software and associated documentation files (the "Software"), to deal with
13
+ the Software without restriction, including without limitation the rights to
14
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
15
+ of the Software, and to permit persons to whom the Software is furnished to do
16
+ so, subject to the following conditions:
17
+
18
+ Redistributions of source code must retain the above copyright notice, this
19
+ list of conditions and the following disclaimers.
20
+
21
+ Redistributions in binary form must reproduce the above copyright notice, this
22
+ list of conditions and the following disclaimers in the documentation and/or
23
+ other materials provided with the distribution.
24
+
25
+ Neither the names of Kevin Sheppard, nor the names of any contributors may be
26
+ used to endorse or promote products derived from this Software without specific
27
+ prior written permission.
28
+
29
+ **THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
32
+ CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
33
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
34
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH
35
+ THE SOFTWARE.**
36
+
37
+
38
+ # 3-Clause BSD License
39
+ **Copyright (c) 2019 Kevin Sheppard. All rights reserved.**
40
+
41
+ Redistribution and use in source and binary forms, with or without
42
+ modification, are permitted provided that the following conditions are met:
43
+
44
+ 1. Redistributions of source code must retain the above copyright notice,
45
+ this list of conditions and the following disclaimer.
46
+
47
+ 2. Redistributions in binary form must reproduce the above copyright notice,
48
+ this list of conditions and the following disclaimer in the documentation
49
+ and/or other materials provided with the distribution.
50
+
51
+ 3. Neither the name of the copyright holder nor the names of its contributors
52
+ may be used to endorse or promote products derived from this software
53
+ without specific prior written permission.
54
+
55
+ **THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
56
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
57
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
58
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
59
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
60
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
61
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
62
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
63
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
64
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
65
+ THE POSSIBILITY OF SUCH DAMAGE.**
66
+
67
+ # Components
68
+
69
+ Many parts of this module have been derived from original sources,
70
+ often the algorithm's designer. Component licenses are located with
71
+ the component code.
physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy-2.4.6.dist-info/licenses/numpy/random/src/distributions/LICENSE.md ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ## NumPy
2
+
3
+ Copyright (c) 2005-2017, NumPy Developers.
4
+ All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms, with or without
7
+ modification, are permitted provided that the following conditions are
8
+ met:
9
+
10
+ * Redistributions of source code must retain the above copyright
11
+ notice, this list of conditions and the following disclaimer.
12
+
13
+ * Redistributions in binary form must reproduce the above
14
+ copyright notice, this list of conditions and the following
15
+ disclaimer in the documentation and/or other materials provided
16
+ with the distribution.
17
+
18
+ * Neither the name of the NumPy Developers nor the names of any
19
+ contributors may be used to endorse or promote products derived
20
+ from this software without specific prior written permission.
21
+
22
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33
+
34
+
35
+ ## Julia
36
+
37
+ The ziggurat methods were derived from Julia.
38
+
39
+ Copyright (c) 2009-2019: Jeff Bezanson, Stefan Karpinski, Viral B. Shah,
40
+ and other contributors:
41
+
42
+ https://github.com/JuliaLang/julia/contributors
43
+
44
+ Permission is hereby granted, free of charge, to any person obtaining
45
+ a copy of this software and associated documentation files (the
46
+ "Software"), to deal in the Software without restriction, including
47
+ without limitation the rights to use, copy, modify, merge, publish,
48
+ distribute, sublicense, and/or sell copies of the Software, and to
49
+ permit persons to whom the Software is furnished to do so, subject to
50
+ the following conditions:
51
+
52
+ The above copyright notice and this permission notice shall be
53
+ included in all copies or substantial portions of the Software.
54
+
55
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
56
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
57
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
58
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
59
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
60
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
61
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy-2.4.6.dist-info/licenses/numpy/random/src/mt19937/LICENSE.md ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # MT19937
2
+
3
+ Copyright (c) 2003-2005, Jean-Sebastien Roy (js@jeannot.org)
4
+
5
+ The rk_random and rk_seed functions algorithms and the original design of
6
+ the Mersenne Twister RNG:
7
+
8
+ Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura,
9
+ All rights reserved.
10
+
11
+ Redistribution and use in source and binary forms, with or without
12
+ modification, are permitted provided that the following conditions
13
+ are met:
14
+
15
+ 1. Redistributions of source code must retain the above copyright
16
+ notice, this list of conditions and the following disclaimer.
17
+
18
+ 2. Redistributions in binary form must reproduce the above copyright
19
+ notice, this list of conditions and the following disclaimer in the
20
+ documentation and/or other materials provided with the distribution.
21
+
22
+ 3. The names of its contributors may not be used to endorse or promote
23
+ products derived from this software without specific prior written
24
+ permission.
25
+
26
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
30
+ OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37
+
38
+ Original algorithm for the implementation of rk_interval function from
39
+ Richard J. Wagner's implementation of the Mersenne Twister RNG, optimised by
40
+ Magnus Jonsson.
41
+
42
+ Constants used in the rk_double implementation by Isaku Wada.
43
+
44
+ Permission is hereby granted, free of charge, to any person obtaining a
45
+ copy of this software and associated documentation files (the
46
+ "Software"), to deal in the Software without restriction, including
47
+ without limitation the rights to use, copy, modify, merge, publish,
48
+ distribute, sublicense, and/or sell copies of the Software, and to
49
+ permit persons to whom the Software is furnished to do so, subject to
50
+ the following conditions:
51
+
52
+ The above copyright notice and this permission notice shall be included
53
+ in all copies or substantial portions of the Software.
54
+
55
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
56
+ OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
57
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
58
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
59
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
60
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
61
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy-2.4.6.dist-info/licenses/numpy/random/src/pcg64/LICENSE.md ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # PCG64
2
+
3
+ ## The MIT License
4
+
5
+ PCG Random Number Generation for C.
6
+
7
+ Copyright 2014 Melissa O'Neill <oneill@pcg-random.org>
8
+
9
+ Permission is hereby granted, free of charge, to any person obtaining
10
+ a copy of this software and associated documentation files (the "Software"),
11
+ to deal in the Software without restriction, including without limitation
12
+ the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be included in
15
+ all copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy-2.4.6.dist-info/licenses/numpy/random/src/philox/LICENSE.md ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # PHILOX
2
+
3
+ Copyright 2010-2012, D. E. Shaw Research.
4
+ All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms, with or without
7
+ modification, are permitted provided that the following conditions are
8
+ met:
9
+
10
+ * Redistributions of source code must retain the above copyright
11
+ notice, this list of conditions, and the following disclaimer.
12
+
13
+ * Redistributions in binary form must reproduce the above copyright
14
+ notice, this list of conditions, and the following disclaimer in the
15
+ documentation and/or other materials provided with the distribution.
16
+
17
+ * Neither the name of D. E. Shaw Research nor the names of its
18
+ contributors may be used to endorse or promote products derived from
19
+ this software without specific prior written permission.
20
+
21
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy-2.4.6.dist-info/licenses/numpy/random/src/sfc64/LICENSE.md ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # SFC64
2
+
3
+ ## The MIT License
4
+
5
+ Adapted from a C++ implementation of Chris Doty-Humphrey's SFC PRNG.
6
+
7
+ https://gist.github.com/imneme/f1f7821f07cf76504a97f6537c818083
8
+
9
+ Copyright (c) 2018 Melissa E. O'Neill
10
+
11
+ Permission is hereby granted, free of charge, to any person obtaining a
12
+ copy of this software and associated documentation files (the "Software"),
13
+ to deal in the Software without restriction, including without limitation
14
+ the rights to use, copy, modify, merge, publish, distribute, sublicense,
15
+ and/or sell copies of the Software, and to permit persons to whom the
16
+ Software is furnished to do so, subject to the following conditions:
17
+
18
+ The above copyright notice and this permission notice shall be included in
19
+ all copies or substantial portions of the Software.
20
+
21
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27
+ DEALINGS IN THE SOFTWARE.
physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy-2.4.6.dist-info/licenses/numpy/random/src/splitmix64/LICENSE.md ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ # SPLITMIX64
2
+
3
+ Written in 2015 by Sebastiano Vigna (vigna@acm.org)
4
+
5
+ To the extent possible under law, the author has dedicated all copyright
6
+ and related and neighboring rights to this software to the public domain
7
+ worldwide. This software is distributed without any warranty.
8
+
9
+ See <http://creativecommons.org/publicdomain/zero/1.0/>.
physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy.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
physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy.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
physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy.libs/libscipy_openblas64_-32a4b2a6.so ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:05c9f9eb89ee68a4b9d673184fa91c99587e736392c0c2d49180a8aa5303d080
3
+ size 25409073
physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy/polynomial/_polytypes.pyi ADDED
@@ -0,0 +1,501 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # ruff: noqa: PYI046
2
+
3
+ from collections.abc import Sequence
4
+ from typing import (
5
+ Any,
6
+ Literal,
7
+ NoReturn,
8
+ Protocol,
9
+ Self,
10
+ SupportsIndex,
11
+ SupportsInt,
12
+ TypeAlias,
13
+ TypeVar,
14
+ overload,
15
+ type_check_only,
16
+ )
17
+
18
+ import numpy as np
19
+ import numpy.typing as npt
20
+ from numpy._typing import (
21
+ _ArrayLikeComplex_co,
22
+ # array-likes
23
+ _ArrayLikeFloat_co,
24
+ _ArrayLikeNumber_co,
25
+ _ComplexLike_co,
26
+ _FloatLike_co,
27
+ # scalar-likes
28
+ _IntLike_co,
29
+ _NestedSequence,
30
+ _NumberLike_co,
31
+ _SupportsArray,
32
+ )
33
+
34
+ _T = TypeVar("_T")
35
+ _T_contra = TypeVar("_T_contra", contravariant=True)
36
+ _ScalarT = TypeVar("_ScalarT", bound=np.number | np.bool | np.object_)
37
+
38
+ # compatible with e.g. int, float, complex, Decimal, Fraction, and ABCPolyBase
39
+ @type_check_only
40
+ class _SupportsCoefOps(Protocol[_T_contra]):
41
+ def __eq__(self, x: object, /) -> bool: ...
42
+ def __ne__(self, x: object, /) -> bool: ...
43
+ def __neg__(self, /) -> Self: ...
44
+ def __pos__(self, /) -> Self: ...
45
+ def __add__(self, x: _T_contra, /) -> Self: ...
46
+ def __sub__(self, x: _T_contra, /) -> Self: ...
47
+ def __mul__(self, x: _T_contra, /) -> Self: ...
48
+ def __pow__(self, x: _T_contra, /) -> Self | float: ...
49
+ def __radd__(self, x: _T_contra, /) -> Self: ...
50
+ def __rsub__(self, x: _T_contra, /) -> Self: ...
51
+ def __rmul__(self, x: _T_contra, /) -> Self: ...
52
+
53
+ _Series: TypeAlias = np.ndarray[tuple[int], np.dtype[_ScalarT]]
54
+
55
+ _FloatSeries: TypeAlias = _Series[np.floating]
56
+ _ComplexSeries: TypeAlias = _Series[np.complexfloating]
57
+ _ObjectSeries: TypeAlias = _Series[np.object_]
58
+ _CoefSeries: TypeAlias = _Series[np.inexact | np.object_]
59
+
60
+ _FloatArray: TypeAlias = npt.NDArray[np.floating]
61
+ _ComplexArray: TypeAlias = npt.NDArray[np.complexfloating]
62
+ _ObjectArray: TypeAlias = npt.NDArray[np.object_]
63
+ _CoefArray: TypeAlias = npt.NDArray[np.inexact | np.object_]
64
+
65
+ _Tuple2: TypeAlias = tuple[_T, _T]
66
+ _Array1: TypeAlias = np.ndarray[tuple[Literal[1]], np.dtype[_ScalarT]]
67
+ _Array2: TypeAlias = np.ndarray[tuple[Literal[2]], np.dtype[_ScalarT]]
68
+
69
+ _AnyInt: TypeAlias = SupportsInt | SupportsIndex
70
+
71
+ _CoefObjectLike_co: TypeAlias = np.object_ | _SupportsCoefOps[Any]
72
+ _CoefLike_co: TypeAlias = _NumberLike_co | _CoefObjectLike_co
73
+
74
+ # The term "series" is used here to refer to 1-d arrays of numeric scalars.
75
+ _SeriesLikeBool_co: TypeAlias = _SupportsArray[np.dtype[np.bool]] | Sequence[bool | np.bool]
76
+ _SeriesLikeInt_co: TypeAlias = _SupportsArray[np.dtype[np.integer | np.bool]] | Sequence[_IntLike_co]
77
+ _SeriesLikeFloat_co: TypeAlias = _SupportsArray[np.dtype[np.floating | np.integer | np.bool]] | Sequence[_FloatLike_co]
78
+ _SeriesLikeComplex_co: TypeAlias = _SupportsArray[np.dtype[np.number | np.bool]] | Sequence[_ComplexLike_co]
79
+ _SeriesLikeObject_co: TypeAlias = _SupportsArray[np.dtype[np.object_]] | Sequence[_CoefObjectLike_co]
80
+ _SeriesLikeCoef_co: TypeAlias = _SupportsArray[np.dtype[np.number | np.bool | np.object_]] | Sequence[_CoefLike_co]
81
+
82
+ _ArrayLikeCoefObject_co: TypeAlias = _CoefObjectLike_co | _SeriesLikeObject_co | _NestedSequence[_SeriesLikeObject_co]
83
+ _ArrayLikeCoef_co: TypeAlias = npt.NDArray[np.number | np.bool | np.object_] | _ArrayLikeNumber_co | _ArrayLikeCoefObject_co
84
+
85
+ _Line: TypeAlias = np.ndarray[tuple[int], np.dtype[_ScalarT]]
86
+
87
+ @type_check_only
88
+ class _FuncLine(Protocol):
89
+ @overload
90
+ def __call__(self, /, off: _ScalarT, scl: _ScalarT) -> _Line[_ScalarT]: ...
91
+ @overload
92
+ def __call__(self, /, off: int, scl: int) -> _Line[np.int_]: ...
93
+ @overload
94
+ def __call__(self, /, off: float, scl: float) -> _Line[np.float64]: ...
95
+ @overload
96
+ def __call__(self, /, off: complex, scl: complex) -> _Line[np.complex128]: ...
97
+ @overload
98
+ def __call__(self, /, off: _SupportsCoefOps[Any], scl: _SupportsCoefOps[Any]) -> _Line[np.object_]: ...
99
+
100
+ @type_check_only
101
+ class _FuncFromRoots(Protocol):
102
+ @overload
103
+ def __call__(self, /, roots: _SeriesLikeFloat_co) -> _FloatSeries: ...
104
+ @overload
105
+ def __call__(self, /, roots: _SeriesLikeComplex_co) -> _ComplexSeries: ...
106
+ @overload
107
+ def __call__(self, /, roots: _SeriesLikeCoef_co) -> _ObjectSeries: ...
108
+
109
+ @type_check_only
110
+ class _FuncBinOp(Protocol):
111
+ @overload
112
+ def __call__(self, /, c1: _SeriesLikeBool_co, c2: _SeriesLikeBool_co) -> NoReturn: ...
113
+ @overload
114
+ def __call__(self, /, c1: _SeriesLikeFloat_co, c2: _SeriesLikeFloat_co) -> _FloatSeries: ...
115
+ @overload
116
+ def __call__(self, /, c1: _SeriesLikeComplex_co, c2: _SeriesLikeComplex_co) -> _ComplexSeries: ...
117
+ @overload
118
+ def __call__(self, /, c1: _SeriesLikeCoef_co, c2: _SeriesLikeCoef_co) -> _ObjectSeries: ...
119
+
120
+ @type_check_only
121
+ class _FuncUnOp(Protocol):
122
+ @overload
123
+ def __call__(self, /, c: _SeriesLikeFloat_co) -> _FloatSeries: ...
124
+ @overload
125
+ def __call__(self, /, c: _SeriesLikeComplex_co) -> _ComplexSeries: ...
126
+ @overload
127
+ def __call__(self, /, c: _SeriesLikeCoef_co) -> _ObjectSeries: ...
128
+
129
+ @type_check_only
130
+ class _FuncPoly2Ortho(Protocol):
131
+ @overload
132
+ def __call__(self, /, pol: _SeriesLikeFloat_co) -> _FloatSeries: ...
133
+ @overload
134
+ def __call__(self, /, pol: _SeriesLikeComplex_co) -> _ComplexSeries: ...
135
+ @overload
136
+ def __call__(self, /, pol: _SeriesLikeCoef_co) -> _ObjectSeries: ...
137
+
138
+ @type_check_only
139
+ class _FuncPow(Protocol):
140
+ @overload
141
+ def __call__(self, /, c: _SeriesLikeFloat_co, pow: _IntLike_co, maxpower: _IntLike_co | None = ...) -> _FloatSeries: ...
142
+ @overload
143
+ def __call__(self, /, c: _SeriesLikeComplex_co, pow: _IntLike_co, maxpower: _IntLike_co | None = ...) -> _ComplexSeries: ...
144
+ @overload
145
+ def __call__(self, /, c: _SeriesLikeCoef_co, pow: _IntLike_co, maxpower: _IntLike_co | None = ...) -> _ObjectSeries: ...
146
+
147
+ @type_check_only
148
+ class _FuncDer(Protocol):
149
+ @overload
150
+ def __call__(
151
+ self,
152
+ /,
153
+ c: _ArrayLikeFloat_co,
154
+ m: SupportsIndex = 1,
155
+ scl: _FloatLike_co = 1,
156
+ axis: SupportsIndex = 0,
157
+ ) -> _FloatArray: ...
158
+ @overload
159
+ def __call__(
160
+ self,
161
+ /,
162
+ c: _ArrayLikeComplex_co,
163
+ m: SupportsIndex = 1,
164
+ scl: _ComplexLike_co = 1,
165
+ axis: SupportsIndex = 0,
166
+ ) -> _ComplexArray: ...
167
+ @overload
168
+ def __call__(
169
+ self,
170
+ /,
171
+ c: _ArrayLikeCoef_co,
172
+ m: SupportsIndex = 1,
173
+ scl: _CoefLike_co = 1,
174
+ axis: SupportsIndex = 0,
175
+ ) -> _ObjectArray: ...
176
+
177
+ @type_check_only
178
+ class _FuncInteg(Protocol):
179
+ @overload
180
+ def __call__(
181
+ self,
182
+ /,
183
+ c: _ArrayLikeFloat_co,
184
+ m: SupportsIndex = 1,
185
+ k: _FloatLike_co | _SeriesLikeFloat_co = [],
186
+ lbnd: _FloatLike_co = 0,
187
+ scl: _FloatLike_co = 1,
188
+ axis: SupportsIndex = 0,
189
+ ) -> _FloatArray: ...
190
+ @overload
191
+ def __call__(
192
+ self,
193
+ /,
194
+ c: _ArrayLikeComplex_co,
195
+ m: SupportsIndex = 1,
196
+ k: _ComplexLike_co | _SeriesLikeComplex_co = [],
197
+ lbnd: _ComplexLike_co = 0,
198
+ scl: _ComplexLike_co = 1,
199
+ axis: SupportsIndex = 0,
200
+ ) -> _ComplexArray: ...
201
+ @overload
202
+ def __call__(
203
+ self,
204
+ /,
205
+ c: _ArrayLikeCoef_co,
206
+ m: SupportsIndex = 1,
207
+ k: _CoefLike_co | _SeriesLikeCoef_co = [],
208
+ lbnd: _CoefLike_co = 0,
209
+ scl: _CoefLike_co = 1,
210
+ axis: SupportsIndex = 0,
211
+ ) -> _ObjectArray: ...
212
+
213
+ @type_check_only
214
+ class _FuncVal(Protocol):
215
+ @overload
216
+ def __call__(self, /, x: _FloatLike_co, c: _SeriesLikeFloat_co, tensor: bool = True) -> np.floating: ...
217
+ @overload
218
+ def __call__(self, /, x: _NumberLike_co, c: _SeriesLikeComplex_co, tensor: bool = True) -> np.complexfloating: ...
219
+ @overload
220
+ def __call__(self, /, x: _ArrayLikeFloat_co, c: _ArrayLikeFloat_co, tensor: bool = True) -> _FloatArray: ...
221
+ @overload
222
+ def __call__(self, /, x: _ArrayLikeComplex_co, c: _ArrayLikeComplex_co, tensor: bool = True) -> _ComplexArray: ...
223
+ @overload
224
+ def __call__(self, /, x: _ArrayLikeCoef_co, c: _ArrayLikeCoef_co, tensor: bool = True) -> _ObjectArray: ...
225
+ @overload
226
+ def __call__(self, /, x: _CoefLike_co, c: _SeriesLikeObject_co, tensor: bool = True) -> _SupportsCoefOps[Any]: ...
227
+
228
+ @type_check_only
229
+ class _FuncVal2D(Protocol):
230
+ @overload
231
+ def __call__(self, /, x: _FloatLike_co, y: _FloatLike_co, c: _SeriesLikeFloat_co) -> np.floating: ...
232
+ @overload
233
+ def __call__(self, /, x: _NumberLike_co, y: _NumberLike_co, c: _SeriesLikeComplex_co) -> np.complexfloating: ...
234
+ @overload
235
+ def __call__(self, /, x: _ArrayLikeFloat_co, y: _ArrayLikeFloat_co, c: _ArrayLikeFloat_co) -> _FloatArray: ...
236
+ @overload
237
+ def __call__(self, /, x: _ArrayLikeComplex_co, y: _ArrayLikeComplex_co, c: _ArrayLikeComplex_co) -> _ComplexArray: ...
238
+ @overload
239
+ def __call__(self, /, x: _ArrayLikeCoef_co, y: _ArrayLikeCoef_co, c: _ArrayLikeCoef_co) -> _ObjectArray: ...
240
+ @overload
241
+ def __call__(self, /, x: _CoefLike_co, y: _CoefLike_co, c: _SeriesLikeCoef_co) -> _SupportsCoefOps[Any]: ...
242
+
243
+ @type_check_only
244
+ class _FuncVal3D(Protocol):
245
+ @overload
246
+ def __call__(
247
+ self,
248
+ /,
249
+ x: _FloatLike_co,
250
+ y: _FloatLike_co,
251
+ z: _FloatLike_co,
252
+ c: _SeriesLikeFloat_co,
253
+ ) -> np.floating: ...
254
+ @overload
255
+ def __call__(
256
+ self,
257
+ /,
258
+ x: _NumberLike_co,
259
+ y: _NumberLike_co,
260
+ z: _NumberLike_co,
261
+ c: _SeriesLikeComplex_co,
262
+ ) -> np.complexfloating: ...
263
+ @overload
264
+ def __call__(
265
+ self,
266
+ /,
267
+ x: _ArrayLikeFloat_co,
268
+ y: _ArrayLikeFloat_co,
269
+ z: _ArrayLikeFloat_co,
270
+ c: _ArrayLikeFloat_co,
271
+ ) -> _FloatArray: ...
272
+ @overload
273
+ def __call__(
274
+ self,
275
+ /,
276
+ x: _ArrayLikeComplex_co,
277
+ y: _ArrayLikeComplex_co,
278
+ z: _ArrayLikeComplex_co,
279
+ c: _ArrayLikeComplex_co,
280
+ ) -> _ComplexArray: ...
281
+ @overload
282
+ def __call__(
283
+ self,
284
+ /,
285
+ x: _ArrayLikeCoef_co,
286
+ y: _ArrayLikeCoef_co,
287
+ z: _ArrayLikeCoef_co,
288
+ c: _ArrayLikeCoef_co,
289
+ ) -> _ObjectArray: ...
290
+ @overload
291
+ def __call__(
292
+ self,
293
+ /,
294
+ x: _CoefLike_co,
295
+ y: _CoefLike_co,
296
+ z: _CoefLike_co,
297
+ c: _SeriesLikeCoef_co,
298
+ ) -> _SupportsCoefOps[Any]: ...
299
+
300
+ @type_check_only
301
+ class _FuncVander(Protocol):
302
+ @overload
303
+ def __call__(self, /, x: _ArrayLikeFloat_co, deg: SupportsIndex) -> _FloatArray: ...
304
+ @overload
305
+ def __call__(self, /, x: _ArrayLikeComplex_co, deg: SupportsIndex) -> _ComplexArray: ...
306
+ @overload
307
+ def __call__(self, /, x: _ArrayLikeCoef_co, deg: SupportsIndex) -> _ObjectArray: ...
308
+ @overload
309
+ def __call__(self, /, x: npt.ArrayLike, deg: SupportsIndex) -> _CoefArray: ...
310
+
311
+ _AnyDegrees: TypeAlias = Sequence[SupportsIndex]
312
+
313
+ @type_check_only
314
+ class _FuncVander2D(Protocol):
315
+ @overload
316
+ def __call__(self, /, x: _ArrayLikeFloat_co, y: _ArrayLikeFloat_co, deg: _AnyDegrees) -> _FloatArray: ...
317
+ @overload
318
+ def __call__(self, /, x: _ArrayLikeComplex_co, y: _ArrayLikeComplex_co, deg: _AnyDegrees) -> _ComplexArray: ...
319
+ @overload
320
+ def __call__(self, /, x: _ArrayLikeCoef_co, y: _ArrayLikeCoef_co, deg: _AnyDegrees) -> _ObjectArray: ...
321
+ @overload
322
+ def __call__(self, /, x: npt.ArrayLike, y: npt.ArrayLike, deg: _AnyDegrees) -> _CoefArray: ...
323
+
324
+ @type_check_only
325
+ class _FuncVander3D(Protocol):
326
+ @overload
327
+ def __call__(
328
+ self,
329
+ /,
330
+ x: _ArrayLikeFloat_co,
331
+ y: _ArrayLikeFloat_co,
332
+ z: _ArrayLikeFloat_co,
333
+ deg: _AnyDegrees,
334
+ ) -> _FloatArray: ...
335
+ @overload
336
+ def __call__(
337
+ self,
338
+ /,
339
+ x: _ArrayLikeComplex_co,
340
+ y: _ArrayLikeComplex_co,
341
+ z: _ArrayLikeComplex_co,
342
+ deg: _AnyDegrees,
343
+ ) -> _ComplexArray: ...
344
+ @overload
345
+ def __call__(
346
+ self,
347
+ /,
348
+ x: _ArrayLikeCoef_co,
349
+ y: _ArrayLikeCoef_co,
350
+ z: _ArrayLikeCoef_co,
351
+ deg: _AnyDegrees,
352
+ ) -> _ObjectArray: ...
353
+ @overload
354
+ def __call__(
355
+ self,
356
+ /,
357
+ x: npt.ArrayLike,
358
+ y: npt.ArrayLike,
359
+ z: npt.ArrayLike,
360
+ deg: _AnyDegrees,
361
+ ) -> _CoefArray: ...
362
+
363
+ _FullFitResult: TypeAlias = Sequence[np.inexact | np.int32]
364
+
365
+ @type_check_only
366
+ class _FuncFit(Protocol):
367
+ @overload
368
+ def __call__(
369
+ self,
370
+ /,
371
+ x: _SeriesLikeFloat_co,
372
+ y: _ArrayLikeFloat_co,
373
+ deg: int | _SeriesLikeInt_co,
374
+ rcond: float | None = ...,
375
+ full: Literal[False] = False,
376
+ w: _SeriesLikeFloat_co | None = ...,
377
+ ) -> _FloatArray: ...
378
+ @overload
379
+ def __call__(
380
+ self,
381
+ x: _SeriesLikeFloat_co,
382
+ y: _ArrayLikeFloat_co,
383
+ deg: int | _SeriesLikeInt_co,
384
+ rcond: float | None,
385
+ full: Literal[True],
386
+ /,
387
+ w: _SeriesLikeFloat_co | None = ...,
388
+ ) -> tuple[_FloatArray, _FullFitResult]: ...
389
+ @overload
390
+ def __call__(
391
+ self,
392
+ /,
393
+ x: _SeriesLikeFloat_co,
394
+ y: _ArrayLikeFloat_co,
395
+ deg: int | _SeriesLikeInt_co,
396
+ rcond: float | None = ...,
397
+ *,
398
+ full: Literal[True],
399
+ w: _SeriesLikeFloat_co | None = ...,
400
+ ) -> tuple[_FloatArray, _FullFitResult]: ...
401
+ @overload
402
+ def __call__(
403
+ self,
404
+ /,
405
+ x: _SeriesLikeComplex_co,
406
+ y: _ArrayLikeComplex_co,
407
+ deg: int | _SeriesLikeInt_co,
408
+ rcond: float | None = ...,
409
+ full: Literal[False] = False,
410
+ w: _SeriesLikeFloat_co | None = ...,
411
+ ) -> _ComplexArray: ...
412
+ @overload
413
+ def __call__(
414
+ self,
415
+ x: _SeriesLikeComplex_co,
416
+ y: _ArrayLikeComplex_co,
417
+ deg: int | _SeriesLikeInt_co,
418
+ rcond: float | None,
419
+ full: Literal[True],
420
+ /,
421
+ w: _SeriesLikeFloat_co | None = ...,
422
+ ) -> tuple[_ComplexArray, _FullFitResult]: ...
423
+ @overload
424
+ def __call__(
425
+ self,
426
+ /,
427
+ x: _SeriesLikeComplex_co,
428
+ y: _ArrayLikeComplex_co,
429
+ deg: int | _SeriesLikeInt_co,
430
+ rcond: float | None = ...,
431
+ *,
432
+ full: Literal[True],
433
+ w: _SeriesLikeFloat_co | None = ...,
434
+ ) -> tuple[_ComplexArray, _FullFitResult]: ...
435
+ @overload
436
+ def __call__(
437
+ self,
438
+ /,
439
+ x: _SeriesLikeComplex_co,
440
+ y: _ArrayLikeCoef_co,
441
+ deg: int | _SeriesLikeInt_co,
442
+ rcond: float | None = ...,
443
+ full: Literal[False] = False,
444
+ w: _SeriesLikeFloat_co | None = ...,
445
+ ) -> _ObjectArray: ...
446
+ @overload
447
+ def __call__(
448
+ self,
449
+ x: _SeriesLikeComplex_co,
450
+ y: _ArrayLikeCoef_co,
451
+ deg: int | _SeriesLikeInt_co,
452
+ rcond: float | None,
453
+ full: Literal[True],
454
+ /,
455
+ w: _SeriesLikeFloat_co | None = ...,
456
+ ) -> tuple[_ObjectArray, _FullFitResult]: ...
457
+ @overload
458
+ def __call__(
459
+ self,
460
+ /,
461
+ x: _SeriesLikeComplex_co,
462
+ y: _ArrayLikeCoef_co,
463
+ deg: int | _SeriesLikeInt_co,
464
+ rcond: float | None = ...,
465
+ *,
466
+ full: Literal[True],
467
+ w: _SeriesLikeFloat_co | None = ...,
468
+ ) -> tuple[_ObjectArray, _FullFitResult]: ...
469
+
470
+ @type_check_only
471
+ class _FuncRoots(Protocol):
472
+ @overload
473
+ def __call__(self, /, c: _SeriesLikeFloat_co) -> _Series[np.float64]: ...
474
+ @overload
475
+ def __call__(self, /, c: _SeriesLikeComplex_co) -> _Series[np.complex128]: ...
476
+ @overload
477
+ def __call__(self, /, c: _SeriesLikeCoef_co) -> _ObjectSeries: ...
478
+
479
+ _Companion: TypeAlias = np.ndarray[tuple[int, int], np.dtype[_ScalarT]]
480
+
481
+ @type_check_only
482
+ class _FuncCompanion(Protocol):
483
+ @overload
484
+ def __call__(self, /, c: _SeriesLikeFloat_co) -> _Companion[np.float64]: ...
485
+ @overload
486
+ def __call__(self, /, c: _SeriesLikeComplex_co) -> _Companion[np.complex128]: ...
487
+ @overload
488
+ def __call__(self, /, c: _SeriesLikeCoef_co) -> _Companion[np.object_]: ...
489
+
490
+ @type_check_only
491
+ class _FuncGauss(Protocol):
492
+ def __call__(self, /, deg: SupportsIndex) -> _Tuple2[_Series[np.float64]]: ...
493
+
494
+ @type_check_only
495
+ class _FuncWeight(Protocol):
496
+ @overload
497
+ def __call__(self, /, x: _ArrayLikeFloat_co) -> npt.NDArray[np.float64]: ...
498
+ @overload
499
+ def __call__(self, /, x: _ArrayLikeComplex_co) -> npt.NDArray[np.complex128]: ...
500
+ @overload
501
+ def __call__(self, /, x: _ArrayLikeCoef_co) -> _ObjectArray: ...
physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy/polynomial/chebyshev.py ADDED
@@ -0,0 +1,2001 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ ====================================================
3
+ Chebyshev Series (:mod:`numpy.polynomial.chebyshev`)
4
+ ====================================================
5
+
6
+ This module provides a number of objects (mostly functions) useful for
7
+ dealing with Chebyshev series, including a `Chebyshev` class that
8
+ encapsulates the usual arithmetic operations. (General information
9
+ on how this module represents and works with such polynomials is in the
10
+ docstring for its "parent" sub-package, `numpy.polynomial`).
11
+
12
+ Classes
13
+ -------
14
+
15
+ .. autosummary::
16
+ :toctree: generated/
17
+
18
+ Chebyshev
19
+
20
+
21
+ Constants
22
+ ---------
23
+
24
+ .. autosummary::
25
+ :toctree: generated/
26
+
27
+ chebdomain
28
+ chebzero
29
+ chebone
30
+ chebx
31
+
32
+ Arithmetic
33
+ ----------
34
+
35
+ .. autosummary::
36
+ :toctree: generated/
37
+
38
+ chebadd
39
+ chebsub
40
+ chebmulx
41
+ chebmul
42
+ chebdiv
43
+ chebpow
44
+ chebval
45
+ chebval2d
46
+ chebval3d
47
+ chebgrid2d
48
+ chebgrid3d
49
+
50
+ Calculus
51
+ --------
52
+
53
+ .. autosummary::
54
+ :toctree: generated/
55
+
56
+ chebder
57
+ chebint
58
+
59
+ Misc Functions
60
+ --------------
61
+
62
+ .. autosummary::
63
+ :toctree: generated/
64
+
65
+ chebfromroots
66
+ chebroots
67
+ chebvander
68
+ chebvander2d
69
+ chebvander3d
70
+ chebgauss
71
+ chebweight
72
+ chebcompanion
73
+ chebfit
74
+ chebpts1
75
+ chebpts2
76
+ chebtrim
77
+ chebline
78
+ cheb2poly
79
+ poly2cheb
80
+ chebinterpolate
81
+
82
+ See also
83
+ --------
84
+ `numpy.polynomial`
85
+
86
+ Notes
87
+ -----
88
+ The implementations of multiplication, division, integration, and
89
+ differentiation use the algebraic identities [1]_:
90
+
91
+ .. math::
92
+ T_n(x) = \\frac{z^n + z^{-n}}{2} \\\\
93
+ z\\frac{dx}{dz} = \\frac{z - z^{-1}}{2}.
94
+
95
+ where
96
+
97
+ .. math:: x = \\frac{z + z^{-1}}{2}.
98
+
99
+ These identities allow a Chebyshev series to be expressed as a finite,
100
+ symmetric Laurent series. In this module, this sort of Laurent series
101
+ is referred to as a "z-series."
102
+
103
+ References
104
+ ----------
105
+ .. [1] A. T. Benjamin, et al., "Combinatorial Trigonometry with Chebyshev
106
+ Polynomials," *Journal of Statistical Planning and Inference 14*, 2008
107
+ (https://web.archive.org/web/20080221202153/https://www.math.hmc.edu/~benjamin/papers/CombTrig.pdf, pg. 4)
108
+
109
+ """ # noqa: E501
110
+ import numpy as np
111
+
112
+ from . import polyutils as pu
113
+ from ._polybase import ABCPolyBase
114
+
115
+ __all__ = [
116
+ 'chebzero', 'chebone', 'chebx', 'chebdomain', 'chebline', 'chebadd',
117
+ 'chebsub', 'chebmulx', 'chebmul', 'chebdiv', 'chebpow', 'chebval',
118
+ 'chebder', 'chebint', 'cheb2poly', 'poly2cheb', 'chebfromroots',
119
+ 'chebvander', 'chebfit', 'chebtrim', 'chebroots', 'chebpts1',
120
+ 'chebpts2', 'Chebyshev', 'chebval2d', 'chebval3d', 'chebgrid2d',
121
+ 'chebgrid3d', 'chebvander2d', 'chebvander3d', 'chebcompanion',
122
+ 'chebgauss', 'chebweight', 'chebinterpolate']
123
+
124
+ chebtrim = pu.trimcoef
125
+
126
+ #
127
+ # A collection of functions for manipulating z-series. These are private
128
+ # functions and do minimal error checking.
129
+ #
130
+
131
+ def _cseries_to_zseries(c):
132
+ """Convert Chebyshev series to z-series.
133
+
134
+ Convert a Chebyshev series to the equivalent z-series. The result is
135
+ never an empty array. The dtype of the return is the same as that of
136
+ the input. No checks are run on the arguments as this routine is for
137
+ internal use.
138
+
139
+ Parameters
140
+ ----------
141
+ c : 1-D ndarray
142
+ Chebyshev coefficients, ordered from low to high
143
+
144
+ Returns
145
+ -------
146
+ zs : 1-D ndarray
147
+ Odd length symmetric z-series, ordered from low to high.
148
+
149
+ """
150
+ n = c.size
151
+ zs = np.zeros(2 * n - 1, dtype=c.dtype)
152
+ zs[n - 1:] = c / 2
153
+ return zs + zs[::-1]
154
+
155
+
156
+ def _zseries_to_cseries(zs):
157
+ """Convert z-series to a Chebyshev series.
158
+
159
+ Convert a z series to the equivalent Chebyshev series. The result is
160
+ never an empty array. The dtype of the return is the same as that of
161
+ the input. No checks are run on the arguments as this routine is for
162
+ internal use.
163
+
164
+ Parameters
165
+ ----------
166
+ zs : 1-D ndarray
167
+ Odd length symmetric z-series, ordered from low to high.
168
+
169
+ Returns
170
+ -------
171
+ c : 1-D ndarray
172
+ Chebyshev coefficients, ordered from low to high.
173
+
174
+ """
175
+ n = (zs.size + 1) // 2
176
+ c = zs[n - 1:].copy()
177
+ c[1:n] *= 2
178
+ return c
179
+
180
+
181
+ def _zseries_mul(z1, z2):
182
+ """Multiply two z-series.
183
+
184
+ Multiply two z-series to produce a z-series.
185
+
186
+ Parameters
187
+ ----------
188
+ z1, z2 : 1-D ndarray
189
+ The arrays must be 1-D but this is not checked.
190
+
191
+ Returns
192
+ -------
193
+ product : 1-D ndarray
194
+ The product z-series.
195
+
196
+ Notes
197
+ -----
198
+ This is simply convolution. If symmetric/anti-symmetric z-series are
199
+ denoted by S/A then the following rules apply:
200
+
201
+ S*S, A*A -> S
202
+ S*A, A*S -> A
203
+
204
+ """
205
+ return np.convolve(z1, z2)
206
+
207
+
208
+ def _zseries_div(z1, z2):
209
+ """Divide the first z-series by the second.
210
+
211
+ Divide `z1` by `z2` and return the quotient and remainder as z-series.
212
+ Warning: this implementation only applies when both z1 and z2 have the
213
+ same symmetry, which is sufficient for present purposes.
214
+
215
+ Parameters
216
+ ----------
217
+ z1, z2 : 1-D ndarray
218
+ The arrays must be 1-D and have the same symmetry, but this is not
219
+ checked.
220
+
221
+ Returns
222
+ -------
223
+
224
+ (quotient, remainder) : 1-D ndarrays
225
+ Quotient and remainder as z-series.
226
+
227
+ Notes
228
+ -----
229
+ This is not the same as polynomial division on account of the desired form
230
+ of the remainder. If symmetric/anti-symmetric z-series are denoted by S/A
231
+ then the following rules apply:
232
+
233
+ S/S -> S,S
234
+ A/A -> S,A
235
+
236
+ The restriction to types of the same symmetry could be fixed but seems like
237
+ unneeded generality. There is no natural form for the remainder in the case
238
+ where there is no symmetry.
239
+
240
+ """
241
+ z1 = z1.copy()
242
+ z2 = z2.copy()
243
+ lc1 = len(z1)
244
+ lc2 = len(z2)
245
+ if lc2 == 1:
246
+ z1 /= z2
247
+ return z1, z1[:1] * 0
248
+ elif lc1 < lc2:
249
+ return z1[:1] * 0, z1
250
+ else:
251
+ dlen = lc1 - lc2
252
+ scl = z2[0]
253
+ z2 /= scl
254
+ quo = np.empty(dlen + 1, dtype=z1.dtype)
255
+ i = 0
256
+ j = dlen
257
+ while i < j:
258
+ r = z1[i]
259
+ quo[i] = z1[i]
260
+ quo[dlen - i] = r
261
+ tmp = r * z2
262
+ z1[i:i + lc2] -= tmp
263
+ z1[j:j + lc2] -= tmp
264
+ i += 1
265
+ j -= 1
266
+ r = z1[i]
267
+ quo[i] = r
268
+ tmp = r * z2
269
+ z1[i:i + lc2] -= tmp
270
+ quo /= scl
271
+ rem = z1[i + 1:i - 1 + lc2].copy()
272
+ return quo, rem
273
+
274
+
275
+ def _zseries_der(zs):
276
+ """Differentiate a z-series.
277
+
278
+ The derivative is with respect to x, not z. This is achieved using the
279
+ chain rule and the value of dx/dz given in the module notes.
280
+
281
+ Parameters
282
+ ----------
283
+ zs : z-series
284
+ The z-series to differentiate.
285
+
286
+ Returns
287
+ -------
288
+ derivative : z-series
289
+ The derivative
290
+
291
+ Notes
292
+ -----
293
+ The zseries for x (ns) has been multiplied by two in order to avoid
294
+ using floats that are incompatible with Decimal and likely other
295
+ specialized scalar types. This scaling has been compensated by
296
+ multiplying the value of zs by two also so that the two cancels in the
297
+ division.
298
+
299
+ """
300
+ n = len(zs) // 2
301
+ ns = np.array([-1, 0, 1], dtype=zs.dtype)
302
+ zs *= np.arange(-n, n + 1) * 2
303
+ d, r = _zseries_div(zs, ns)
304
+ return d
305
+
306
+
307
+ def _zseries_int(zs):
308
+ """Integrate a z-series.
309
+
310
+ The integral is with respect to x, not z. This is achieved by a change
311
+ of variable using dx/dz given in the module notes.
312
+
313
+ Parameters
314
+ ----------
315
+ zs : z-series
316
+ The z-series to integrate
317
+
318
+ Returns
319
+ -------
320
+ integral : z-series
321
+ The indefinite integral
322
+
323
+ Notes
324
+ -----
325
+ The zseries for x (ns) has been multiplied by two in order to avoid
326
+ using floats that are incompatible with Decimal and likely other
327
+ specialized scalar types. This scaling has been compensated by
328
+ dividing the resulting zs by two.
329
+
330
+ """
331
+ n = 1 + len(zs) // 2
332
+ ns = np.array([-1, 0, 1], dtype=zs.dtype)
333
+ zs = _zseries_mul(zs, ns)
334
+ div = np.arange(-n, n + 1) * 2
335
+ zs[:n] /= div[:n]
336
+ zs[n + 1:] /= div[n + 1:]
337
+ zs[n] = 0
338
+ return zs
339
+
340
+ #
341
+ # Chebyshev series functions
342
+ #
343
+
344
+
345
+ def poly2cheb(pol):
346
+ """
347
+ Convert a polynomial to a Chebyshev series.
348
+
349
+ Convert an array representing the coefficients of a polynomial (relative
350
+ to the "standard" basis) ordered from lowest degree to highest, to an
351
+ array of the coefficients of the equivalent Chebyshev series, ordered
352
+ from lowest to highest degree.
353
+
354
+ Parameters
355
+ ----------
356
+ pol : array_like
357
+ 1-D array containing the polynomial coefficients
358
+
359
+ Returns
360
+ -------
361
+ c : ndarray
362
+ 1-D array containing the coefficients of the equivalent Chebyshev
363
+ series.
364
+
365
+ See Also
366
+ --------
367
+ cheb2poly
368
+
369
+ Notes
370
+ -----
371
+ The easy way to do conversions between polynomial basis sets
372
+ is to use the convert method of a class instance.
373
+
374
+ Examples
375
+ --------
376
+ >>> from numpy import polynomial as P
377
+ >>> p = P.Polynomial(range(4))
378
+ >>> p
379
+ Polynomial([0., 1., 2., 3.], domain=[-1., 1.], window=[-1., 1.], symbol='x')
380
+ >>> c = p.convert(kind=P.Chebyshev)
381
+ >>> c
382
+ Chebyshev([1. , 3.25, 1. , 0.75], domain=[-1., 1.], window=[-1., ...
383
+ >>> P.chebyshev.poly2cheb(range(4))
384
+ array([1. , 3.25, 1. , 0.75])
385
+
386
+ """
387
+ [pol] = pu.as_series([pol])
388
+ deg = len(pol) - 1
389
+ res = 0
390
+ for i in range(deg, -1, -1):
391
+ res = chebadd(chebmulx(res), pol[i])
392
+ return res
393
+
394
+
395
+ def cheb2poly(c):
396
+ """
397
+ Convert a Chebyshev series to a polynomial.
398
+
399
+ Convert an array representing the coefficients of a Chebyshev series,
400
+ ordered from lowest degree to highest, to an array of the coefficients
401
+ of the equivalent polynomial (relative to the "standard" basis) ordered
402
+ from lowest to highest degree.
403
+
404
+ Parameters
405
+ ----------
406
+ c : array_like
407
+ 1-D array containing the Chebyshev series coefficients, ordered
408
+ from lowest order term to highest.
409
+
410
+ Returns
411
+ -------
412
+ pol : ndarray
413
+ 1-D array containing the coefficients of the equivalent polynomial
414
+ (relative to the "standard" basis) ordered from lowest order term
415
+ to highest.
416
+
417
+ See Also
418
+ --------
419
+ poly2cheb
420
+
421
+ Notes
422
+ -----
423
+ The easy way to do conversions between polynomial basis sets
424
+ is to use the convert method of a class instance.
425
+
426
+ Examples
427
+ --------
428
+ >>> from numpy import polynomial as P
429
+ >>> c = P.Chebyshev(range(4))
430
+ >>> c
431
+ Chebyshev([0., 1., 2., 3.], domain=[-1., 1.], window=[-1., 1.], symbol='x')
432
+ >>> p = c.convert(kind=P.Polynomial)
433
+ >>> p
434
+ Polynomial([-2., -8., 4., 12.], domain=[-1., 1.], window=[-1., 1.], ...
435
+ >>> P.chebyshev.cheb2poly(range(4))
436
+ array([-2., -8., 4., 12.])
437
+
438
+ """
439
+ from .polynomial import polyadd, polymulx, polysub
440
+
441
+ [c] = pu.as_series([c])
442
+ n = len(c)
443
+ if n < 3:
444
+ return c
445
+ else:
446
+ c0 = c[-2]
447
+ c1 = c[-1]
448
+ # i is the current degree of c1
449
+ for i in range(n - 1, 1, -1):
450
+ tmp = c0
451
+ c0 = polysub(c[i - 2], c1)
452
+ c1 = polyadd(tmp, polymulx(c1) * 2)
453
+ return polyadd(c0, polymulx(c1))
454
+
455
+
456
+ #
457
+ # These are constant arrays are of integer type so as to be compatible
458
+ # with the widest range of other types, such as Decimal.
459
+ #
460
+
461
+ # Chebyshev default domain.
462
+ chebdomain = np.array([-1., 1.])
463
+
464
+ # Chebyshev coefficients representing zero.
465
+ chebzero = np.array([0])
466
+
467
+ # Chebyshev coefficients representing one.
468
+ chebone = np.array([1])
469
+
470
+ # Chebyshev coefficients representing the identity x.
471
+ chebx = np.array([0, 1])
472
+
473
+
474
+ def chebline(off, scl):
475
+ """
476
+ Chebyshev series whose graph is a straight line.
477
+
478
+ Parameters
479
+ ----------
480
+ off, scl : scalars
481
+ The specified line is given by ``off + scl*x``.
482
+
483
+ Returns
484
+ -------
485
+ y : ndarray
486
+ This module's representation of the Chebyshev series for
487
+ ``off + scl*x``.
488
+
489
+ See Also
490
+ --------
491
+ numpy.polynomial.polynomial.polyline
492
+ numpy.polynomial.legendre.legline
493
+ numpy.polynomial.laguerre.lagline
494
+ numpy.polynomial.hermite.hermline
495
+ numpy.polynomial.hermite_e.hermeline
496
+
497
+ Examples
498
+ --------
499
+ >>> import numpy.polynomial.chebyshev as C
500
+ >>> C.chebline(3,2)
501
+ array([3, 2])
502
+ >>> C.chebval(-3, C.chebline(3,2)) # should be -3
503
+ -3.0
504
+
505
+ """
506
+ if scl != 0:
507
+ return np.array([off, scl])
508
+ else:
509
+ return np.array([off])
510
+
511
+
512
+ def chebfromroots(roots):
513
+ """
514
+ Generate a Chebyshev series with given roots.
515
+
516
+ The function returns the coefficients of the polynomial
517
+
518
+ .. math:: p(x) = (x - r_0) * (x - r_1) * ... * (x - r_n),
519
+
520
+ in Chebyshev form, where the :math:`r_n` are the roots specified in
521
+ `roots`. If a zero has multiplicity n, then it must appear in `roots`
522
+ n times. For instance, if 2 is a root of multiplicity three and 3 is a
523
+ root of multiplicity 2, then `roots` looks something like [2, 2, 2, 3, 3].
524
+ The roots can appear in any order.
525
+
526
+ If the returned coefficients are `c`, then
527
+
528
+ .. math:: p(x) = c_0 + c_1 * T_1(x) + ... + c_n * T_n(x)
529
+
530
+ The coefficient of the last term is not generally 1 for monic
531
+ polynomials in Chebyshev form.
532
+
533
+ Parameters
534
+ ----------
535
+ roots : array_like
536
+ Sequence containing the roots.
537
+
538
+ Returns
539
+ -------
540
+ out : ndarray
541
+ 1-D array of coefficients. If all roots are real then `out` is a
542
+ real array, if some of the roots are complex, then `out` is complex
543
+ even if all the coefficients in the result are real (see Examples
544
+ below).
545
+
546
+ See Also
547
+ --------
548
+ numpy.polynomial.polynomial.polyfromroots
549
+ numpy.polynomial.legendre.legfromroots
550
+ numpy.polynomial.laguerre.lagfromroots
551
+ numpy.polynomial.hermite.hermfromroots
552
+ numpy.polynomial.hermite_e.hermefromroots
553
+
554
+ Examples
555
+ --------
556
+ >>> import numpy.polynomial.chebyshev as C
557
+ >>> C.chebfromroots((-1,0,1)) # x^3 - x relative to the standard basis
558
+ array([ 0. , -0.25, 0. , 0.25])
559
+ >>> j = complex(0,1)
560
+ >>> C.chebfromroots((-j,j)) # x^2 + 1 relative to the standard basis
561
+ array([1.5+0.j, 0. +0.j, 0.5+0.j])
562
+
563
+ """
564
+ return pu._fromroots(chebline, chebmul, roots)
565
+
566
+
567
+ def chebadd(c1, c2):
568
+ """
569
+ Add one Chebyshev series to another.
570
+
571
+ Returns the sum of two Chebyshev series `c1` + `c2`. The arguments
572
+ are sequences of coefficients ordered from lowest order term to
573
+ highest, i.e., [1,2,3] represents the series ``T_0 + 2*T_1 + 3*T_2``.
574
+
575
+ Parameters
576
+ ----------
577
+ c1, c2 : array_like
578
+ 1-D arrays of Chebyshev series coefficients ordered from low to
579
+ high.
580
+
581
+ Returns
582
+ -------
583
+ out : ndarray
584
+ Array representing the Chebyshev series of their sum.
585
+
586
+ See Also
587
+ --------
588
+ chebsub, chebmulx, chebmul, chebdiv, chebpow
589
+
590
+ Notes
591
+ -----
592
+ Unlike multiplication, division, etc., the sum of two Chebyshev series
593
+ is a Chebyshev series (without having to "reproject" the result onto
594
+ the basis set) so addition, just like that of "standard" polynomials,
595
+ is simply "component-wise."
596
+
597
+ Examples
598
+ --------
599
+ >>> from numpy.polynomial import chebyshev as C
600
+ >>> c1 = (1,2,3)
601
+ >>> c2 = (3,2,1)
602
+ >>> C.chebadd(c1,c2)
603
+ array([4., 4., 4.])
604
+
605
+ """
606
+ return pu._add(c1, c2)
607
+
608
+
609
+ def chebsub(c1, c2):
610
+ """
611
+ Subtract one Chebyshev series from another.
612
+
613
+ Returns the difference of two Chebyshev series `c1` - `c2`. The
614
+ sequences of coefficients are from lowest order term to highest, i.e.,
615
+ [1,2,3] represents the series ``T_0 + 2*T_1 + 3*T_2``.
616
+
617
+ Parameters
618
+ ----------
619
+ c1, c2 : array_like
620
+ 1-D arrays of Chebyshev series coefficients ordered from low to
621
+ high.
622
+
623
+ Returns
624
+ -------
625
+ out : ndarray
626
+ Of Chebyshev series coefficients representing their difference.
627
+
628
+ See Also
629
+ --------
630
+ chebadd, chebmulx, chebmul, chebdiv, chebpow
631
+
632
+ Notes
633
+ -----
634
+ Unlike multiplication, division, etc., the difference of two Chebyshev
635
+ series is a Chebyshev series (without having to "reproject" the result
636
+ onto the basis set) so subtraction, just like that of "standard"
637
+ polynomials, is simply "component-wise."
638
+
639
+ Examples
640
+ --------
641
+ >>> from numpy.polynomial import chebyshev as C
642
+ >>> c1 = (1,2,3)
643
+ >>> c2 = (3,2,1)
644
+ >>> C.chebsub(c1,c2)
645
+ array([-2., 0., 2.])
646
+ >>> C.chebsub(c2,c1) # -C.chebsub(c1,c2)
647
+ array([ 2., 0., -2.])
648
+
649
+ """
650
+ return pu._sub(c1, c2)
651
+
652
+
653
+ def chebmulx(c):
654
+ """Multiply a Chebyshev series by x.
655
+
656
+ Multiply the polynomial `c` by x, where x is the independent
657
+ variable.
658
+
659
+
660
+ Parameters
661
+ ----------
662
+ c : array_like
663
+ 1-D array of Chebyshev series coefficients ordered from low to
664
+ high.
665
+
666
+ Returns
667
+ -------
668
+ out : ndarray
669
+ Array representing the result of the multiplication.
670
+
671
+ See Also
672
+ --------
673
+ chebadd, chebsub, chebmul, chebdiv, chebpow
674
+
675
+ Examples
676
+ --------
677
+ >>> from numpy.polynomial import chebyshev as C
678
+ >>> C.chebmulx([1,2,3])
679
+ array([1. , 2.5, 1. , 1.5])
680
+
681
+ """
682
+ # c is a trimmed copy
683
+ [c] = pu.as_series([c])
684
+ # The zero series needs special treatment
685
+ if len(c) == 1 and c[0] == 0:
686
+ return c
687
+
688
+ prd = np.empty(len(c) + 1, dtype=c.dtype)
689
+ prd[0] = c[0] * 0
690
+ prd[1] = c[0]
691
+ if len(c) > 1:
692
+ tmp = c[1:] / 2
693
+ prd[2:] = tmp
694
+ prd[0:-2] += tmp
695
+ return prd
696
+
697
+
698
+ def chebmul(c1, c2):
699
+ """
700
+ Multiply one Chebyshev series by another.
701
+
702
+ Returns the product of two Chebyshev series `c1` * `c2`. The arguments
703
+ are sequences of coefficients, from lowest order "term" to highest,
704
+ e.g., [1,2,3] represents the series ``T_0 + 2*T_1 + 3*T_2``.
705
+
706
+ Parameters
707
+ ----------
708
+ c1, c2 : array_like
709
+ 1-D arrays of Chebyshev series coefficients ordered from low to
710
+ high.
711
+
712
+ Returns
713
+ -------
714
+ out : ndarray
715
+ Of Chebyshev series coefficients representing their product.
716
+
717
+ See Also
718
+ --------
719
+ chebadd, chebsub, chebmulx, chebdiv, chebpow
720
+
721
+ Notes
722
+ -----
723
+ In general, the (polynomial) product of two C-series results in terms
724
+ that are not in the Chebyshev polynomial basis set. Thus, to express
725
+ the product as a C-series, it is typically necessary to "reproject"
726
+ the product onto said basis set, which typically produces
727
+ "unintuitive live" (but correct) results; see Examples section below.
728
+
729
+ Examples
730
+ --------
731
+ >>> from numpy.polynomial import chebyshev as C
732
+ >>> c1 = (1,2,3)
733
+ >>> c2 = (3,2,1)
734
+ >>> C.chebmul(c1,c2) # multiplication requires "reprojection"
735
+ array([ 6.5, 12. , 12. , 4. , 1.5])
736
+
737
+ """
738
+ # c1, c2 are trimmed copies
739
+ [c1, c2] = pu.as_series([c1, c2])
740
+ z1 = _cseries_to_zseries(c1)
741
+ z2 = _cseries_to_zseries(c2)
742
+ prd = _zseries_mul(z1, z2)
743
+ ret = _zseries_to_cseries(prd)
744
+ return pu.trimseq(ret)
745
+
746
+
747
+ def chebdiv(c1, c2):
748
+ """
749
+ Divide one Chebyshev series by another.
750
+
751
+ Returns the quotient-with-remainder of two Chebyshev series
752
+ `c1` / `c2`. The arguments are sequences of coefficients from lowest
753
+ order "term" to highest, e.g., [1,2,3] represents the series
754
+ ``T_0 + 2*T_1 + 3*T_2``.
755
+
756
+ Parameters
757
+ ----------
758
+ c1, c2 : array_like
759
+ 1-D arrays of Chebyshev series coefficients ordered from low to
760
+ high.
761
+
762
+ Returns
763
+ -------
764
+ [quo, rem] : ndarrays
765
+ Of Chebyshev series coefficients representing the quotient and
766
+ remainder.
767
+
768
+ See Also
769
+ --------
770
+ chebadd, chebsub, chebmulx, chebmul, chebpow
771
+
772
+ Notes
773
+ -----
774
+ In general, the (polynomial) division of one C-series by another
775
+ results in quotient and remainder terms that are not in the Chebyshev
776
+ polynomial basis set. Thus, to express these results as C-series, it
777
+ is typically necessary to "reproject" the results onto said basis
778
+ set, which typically produces "unintuitive" (but correct) results;
779
+ see Examples section below.
780
+
781
+ Examples
782
+ --------
783
+ >>> from numpy.polynomial import chebyshev as C
784
+ >>> c1 = (1,2,3)
785
+ >>> c2 = (3,2,1)
786
+ >>> C.chebdiv(c1,c2) # quotient "intuitive," remainder not
787
+ (array([3.]), array([-8., -4.]))
788
+ >>> c2 = (0,1,2,3)
789
+ >>> C.chebdiv(c2,c1) # neither "intuitive"
790
+ (array([0., 2.]), array([-2., -4.]))
791
+
792
+ """
793
+ # c1, c2 are trimmed copies
794
+ [c1, c2] = pu.as_series([c1, c2])
795
+ if c2[-1] == 0:
796
+ raise ZeroDivisionError # FIXME: add message with details to exception
797
+
798
+ # note: this is more efficient than `pu._div(chebmul, c1, c2)`
799
+ lc1 = len(c1)
800
+ lc2 = len(c2)
801
+ if lc1 < lc2:
802
+ return c1[:1] * 0, c1
803
+ elif lc2 == 1:
804
+ return c1 / c2[-1], c1[:1] * 0
805
+ else:
806
+ z1 = _cseries_to_zseries(c1)
807
+ z2 = _cseries_to_zseries(c2)
808
+ quo, rem = _zseries_div(z1, z2)
809
+ quo = pu.trimseq(_zseries_to_cseries(quo))
810
+ rem = pu.trimseq(_zseries_to_cseries(rem))
811
+ return quo, rem
812
+
813
+
814
+ def chebpow(c, pow, maxpower=16):
815
+ """Raise a Chebyshev series to a power.
816
+
817
+ Returns the Chebyshev series `c` raised to the power `pow`. The
818
+ argument `c` is a sequence of coefficients ordered from low to high.
819
+ i.e., [1,2,3] is the series ``T_0 + 2*T_1 + 3*T_2.``
820
+
821
+ Parameters
822
+ ----------
823
+ c : array_like
824
+ 1-D array of Chebyshev series coefficients ordered from low to
825
+ high.
826
+ pow : integer
827
+ Power to which the series will be raised
828
+ maxpower : integer, optional
829
+ Maximum power allowed. This is mainly to limit growth of the series
830
+ to unmanageable size. Default is 16
831
+
832
+ Returns
833
+ -------
834
+ coef : ndarray
835
+ Chebyshev series of power.
836
+
837
+ See Also
838
+ --------
839
+ chebadd, chebsub, chebmulx, chebmul, chebdiv
840
+
841
+ Examples
842
+ --------
843
+ >>> from numpy.polynomial import chebyshev as C
844
+ >>> C.chebpow([1, 2, 3, 4], 2)
845
+ array([15.5, 22. , 16. , ..., 12.5, 12. , 8. ])
846
+
847
+ """
848
+ # note: this is more efficient than `pu._pow(chebmul, c1, c2)`, as it
849
+ # avoids converting between z and c series repeatedly
850
+
851
+ # c is a trimmed copy
852
+ [c] = pu.as_series([c])
853
+ power = int(pow)
854
+ if power != pow or power < 0:
855
+ raise ValueError("Power must be a non-negative integer.")
856
+ elif maxpower is not None and power > maxpower:
857
+ raise ValueError("Power is too large")
858
+ elif power == 0:
859
+ return np.array([1], dtype=c.dtype)
860
+ elif power == 1:
861
+ return c
862
+ else:
863
+ # This can be made more efficient by using powers of two
864
+ # in the usual way.
865
+ zs = _cseries_to_zseries(c)
866
+ prd = zs
867
+ for i in range(2, power + 1):
868
+ prd = np.convolve(prd, zs)
869
+ return _zseries_to_cseries(prd)
870
+
871
+
872
+ def chebder(c, m=1, scl=1, axis=0):
873
+ """
874
+ Differentiate a Chebyshev series.
875
+
876
+ Returns the Chebyshev series coefficients `c` differentiated `m` times
877
+ along `axis`. At each iteration the result is multiplied by `scl` (the
878
+ scaling factor is for use in a linear change of variable). The argument
879
+ `c` is an array of coefficients from low to high degree along each
880
+ axis, e.g., [1,2,3] represents the series ``1*T_0 + 2*T_1 + 3*T_2``
881
+ while [[1,2],[1,2]] represents ``1*T_0(x)*T_0(y) + 1*T_1(x)*T_0(y) +
882
+ 2*T_0(x)*T_1(y) + 2*T_1(x)*T_1(y)`` if axis=0 is ``x`` and axis=1 is
883
+ ``y``.
884
+
885
+ Parameters
886
+ ----------
887
+ c : array_like
888
+ Array of Chebyshev series coefficients. If c is multidimensional
889
+ the different axis correspond to different variables with the
890
+ degree in each axis given by the corresponding index.
891
+ m : int, optional
892
+ Number of derivatives taken, must be non-negative. (Default: 1)
893
+ scl : scalar, optional
894
+ Each differentiation is multiplied by `scl`. The end result is
895
+ multiplication by ``scl**m``. This is for use in a linear change of
896
+ variable. (Default: 1)
897
+ axis : int, optional
898
+ Axis over which the derivative is taken. (Default: 0).
899
+
900
+ Returns
901
+ -------
902
+ der : ndarray
903
+ Chebyshev series of the derivative.
904
+
905
+ See Also
906
+ --------
907
+ chebint
908
+
909
+ Notes
910
+ -----
911
+ In general, the result of differentiating a C-series needs to be
912
+ "reprojected" onto the C-series basis set. Thus, typically, the
913
+ result of this function is "unintuitive," albeit correct; see Examples
914
+ section below.
915
+
916
+ Examples
917
+ --------
918
+ >>> from numpy.polynomial import chebyshev as C
919
+ >>> c = (1,2,3,4)
920
+ >>> C.chebder(c)
921
+ array([14., 12., 24.])
922
+ >>> C.chebder(c,3)
923
+ array([96.])
924
+ >>> C.chebder(c,scl=-1)
925
+ array([-14., -12., -24.])
926
+ >>> C.chebder(c,2,-1)
927
+ array([12., 96.])
928
+
929
+ """
930
+ c = np.array(c, ndmin=1, copy=True)
931
+ if c.dtype.char in '?bBhHiIlLqQpP':
932
+ c = c.astype(np.double)
933
+ cnt = pu._as_int(m, "the order of derivation")
934
+ iaxis = pu._as_int(axis, "the axis")
935
+ if cnt < 0:
936
+ raise ValueError("The order of derivation must be non-negative")
937
+ iaxis = np.lib.array_utils.normalize_axis_index(iaxis, c.ndim)
938
+
939
+ if cnt == 0:
940
+ return c
941
+
942
+ c = np.moveaxis(c, iaxis, 0)
943
+ n = len(c)
944
+ if cnt >= n:
945
+ c = c[:1] * 0
946
+ else:
947
+ for i in range(cnt):
948
+ n = n - 1
949
+ c *= scl
950
+ der = np.empty((n,) + c.shape[1:], dtype=c.dtype)
951
+ for j in range(n, 2, -1):
952
+ der[j - 1] = (2 * j) * c[j]
953
+ c[j - 2] += (j * c[j]) / (j - 2)
954
+ if n > 1:
955
+ der[1] = 4 * c[2]
956
+ der[0] = c[1]
957
+ c = der
958
+ c = np.moveaxis(c, 0, iaxis)
959
+ return c
960
+
961
+
962
+ def chebint(c, m=1, k=[], lbnd=0, scl=1, axis=0):
963
+ """
964
+ Integrate a Chebyshev series.
965
+
966
+ Returns the Chebyshev series coefficients `c` integrated `m` times from
967
+ `lbnd` along `axis`. At each iteration the resulting series is
968
+ **multiplied** by `scl` and an integration constant, `k`, is added.
969
+ The scaling factor is for use in a linear change of variable. ("Buyer
970
+ beware": note that, depending on what one is doing, one may want `scl`
971
+ to be the reciprocal of what one might expect; for more information,
972
+ see the Notes section below.) The argument `c` is an array of
973
+ coefficients from low to high degree along each axis, e.g., [1,2,3]
974
+ represents the series ``T_0 + 2*T_1 + 3*T_2`` while [[1,2],[1,2]]
975
+ represents ``1*T_0(x)*T_0(y) + 1*T_1(x)*T_0(y) + 2*T_0(x)*T_1(y) +
976
+ 2*T_1(x)*T_1(y)`` if axis=0 is ``x`` and axis=1 is ``y``.
977
+
978
+ Parameters
979
+ ----------
980
+ c : array_like
981
+ Array of Chebyshev series coefficients. If c is multidimensional
982
+ the different axis correspond to different variables with the
983
+ degree in each axis given by the corresponding index.
984
+ m : int, optional
985
+ Order of integration, must be positive. (Default: 1)
986
+ k : {[], list, scalar}, optional
987
+ Integration constant(s). The value of the first integral at zero
988
+ is the first value in the list, the value of the second integral
989
+ at zero is the second value, etc. If ``k == []`` (the default),
990
+ all constants are set to zero. If ``m == 1``, a single scalar can
991
+ be given instead of a list.
992
+ lbnd : scalar, optional
993
+ The lower bound of the integral. (Default: 0)
994
+ scl : scalar, optional
995
+ Following each integration the result is *multiplied* by `scl`
996
+ before the integration constant is added. (Default: 1)
997
+ axis : int, optional
998
+ Axis over which the integral is taken. (Default: 0).
999
+
1000
+ Returns
1001
+ -------
1002
+ S : ndarray
1003
+ C-series coefficients of the integral.
1004
+
1005
+ Raises
1006
+ ------
1007
+ ValueError
1008
+ If ``m < 1``, ``len(k) > m``, ``np.ndim(lbnd) != 0``, or
1009
+ ``np.ndim(scl) != 0``.
1010
+
1011
+ See Also
1012
+ --------
1013
+ chebder
1014
+
1015
+ Notes
1016
+ -----
1017
+ Note that the result of each integration is *multiplied* by `scl`.
1018
+ Why is this important to note? Say one is making a linear change of
1019
+ variable :math:`u = ax + b` in an integral relative to `x`. Then
1020
+ :math:`dx = du/a`, so one will need to set `scl` equal to
1021
+ :math:`1/a`- perhaps not what one would have first thought.
1022
+
1023
+ Also note that, in general, the result of integrating a C-series needs
1024
+ to be "reprojected" onto the C-series basis set. Thus, typically,
1025
+ the result of this function is "unintuitive," albeit correct; see
1026
+ Examples section below.
1027
+
1028
+ Examples
1029
+ --------
1030
+ >>> from numpy.polynomial import chebyshev as C
1031
+ >>> c = (1,2,3)
1032
+ >>> C.chebint(c)
1033
+ array([ 0.5, -0.5, 0.5, 0.5])
1034
+ >>> C.chebint(c,3)
1035
+ array([ 0.03125 , -0.1875 , 0.04166667, -0.05208333, 0.01041667, # may vary
1036
+ 0.00625 ])
1037
+ >>> C.chebint(c, k=3)
1038
+ array([ 3.5, -0.5, 0.5, 0.5])
1039
+ >>> C.chebint(c,lbnd=-2)
1040
+ array([ 8.5, -0.5, 0.5, 0.5])
1041
+ >>> C.chebint(c,scl=-2)
1042
+ array([-1., 1., -1., -1.])
1043
+
1044
+ """
1045
+ c = np.array(c, ndmin=1, copy=True)
1046
+ if c.dtype.char in '?bBhHiIlLqQpP':
1047
+ c = c.astype(np.double)
1048
+ if not np.iterable(k):
1049
+ k = [k]
1050
+ cnt = pu._as_int(m, "the order of integration")
1051
+ iaxis = pu._as_int(axis, "the axis")
1052
+ if cnt < 0:
1053
+ raise ValueError("The order of integration must be non-negative")
1054
+ if len(k) > cnt:
1055
+ raise ValueError("Too many integration constants")
1056
+ if np.ndim(lbnd) != 0:
1057
+ raise ValueError("lbnd must be a scalar.")
1058
+ if np.ndim(scl) != 0:
1059
+ raise ValueError("scl must be a scalar.")
1060
+ iaxis = np.lib.array_utils.normalize_axis_index(iaxis, c.ndim)
1061
+
1062
+ if cnt == 0:
1063
+ return c
1064
+
1065
+ c = np.moveaxis(c, iaxis, 0)
1066
+ k = list(k) + [0] * (cnt - len(k))
1067
+ for i in range(cnt):
1068
+ n = len(c)
1069
+ c *= scl
1070
+ if n == 1 and np.all(c[0] == 0):
1071
+ c[0] += k[i]
1072
+ else:
1073
+ tmp = np.empty((n + 1,) + c.shape[1:], dtype=c.dtype)
1074
+ tmp[0] = c[0] * 0
1075
+ tmp[1] = c[0]
1076
+ if n > 1:
1077
+ tmp[2] = c[1] / 4
1078
+ for j in range(2, n):
1079
+ tmp[j + 1] = c[j] / (2 * (j + 1))
1080
+ tmp[j - 1] -= c[j] / (2 * (j - 1))
1081
+ tmp[0] += k[i] - chebval(lbnd, tmp)
1082
+ c = tmp
1083
+ c = np.moveaxis(c, 0, iaxis)
1084
+ return c
1085
+
1086
+
1087
+ def chebval(x, c, tensor=True):
1088
+ """
1089
+ Evaluate a Chebyshev series at points x.
1090
+
1091
+ If `c` is of length `n + 1`, this function returns the value:
1092
+
1093
+ .. math:: p(x) = c_0 * T_0(x) + c_1 * T_1(x) + ... + c_n * T_n(x)
1094
+
1095
+ The parameter `x` is converted to an array only if it is a tuple or a
1096
+ list, otherwise it is treated as a scalar. In either case, either `x`
1097
+ or its elements must support multiplication and addition both with
1098
+ themselves and with the elements of `c`.
1099
+
1100
+ If `c` is a 1-D array, then ``p(x)`` will have the same shape as `x`. If
1101
+ `c` is multidimensional, then the shape of the result depends on the
1102
+ value of `tensor`. If `tensor` is true the shape will be c.shape[1:] +
1103
+ x.shape. If `tensor` is false the shape will be c.shape[1:]. Note that
1104
+ scalars have shape (,).
1105
+
1106
+ Trailing zeros in the coefficients will be used in the evaluation, so
1107
+ they should be avoided if efficiency is a concern.
1108
+
1109
+ Parameters
1110
+ ----------
1111
+ x : array_like, compatible object
1112
+ If `x` is a list or tuple, it is converted to an ndarray, otherwise
1113
+ it is left unchanged and treated as a scalar. In either case, `x`
1114
+ or its elements must support addition and multiplication with
1115
+ themselves and with the elements of `c`.
1116
+ c : array_like
1117
+ Array of coefficients ordered so that the coefficients for terms of
1118
+ degree n are contained in c[n]. If `c` is multidimensional the
1119
+ remaining indices enumerate multiple polynomials. In the two
1120
+ dimensional case the coefficients may be thought of as stored in
1121
+ the columns of `c`.
1122
+ tensor : boolean, optional
1123
+ If True, the shape of the coefficient array is extended with ones
1124
+ on the right, one for each dimension of `x`. Scalars have dimension 0
1125
+ for this action. The result is that every column of coefficients in
1126
+ `c` is evaluated for every element of `x`. If False, `x` is broadcast
1127
+ over the columns of `c` for the evaluation. This keyword is useful
1128
+ when `c` is multidimensional. The default value is True.
1129
+
1130
+ Returns
1131
+ -------
1132
+ values : ndarray, algebra_like
1133
+ The shape of the return value is described above.
1134
+
1135
+ See Also
1136
+ --------
1137
+ chebval2d, chebgrid2d, chebval3d, chebgrid3d
1138
+
1139
+ Notes
1140
+ -----
1141
+ The evaluation uses Clenshaw recursion, aka synthetic division.
1142
+
1143
+ """
1144
+ c = np.array(c, ndmin=1, copy=True)
1145
+ if c.dtype.char in '?bBhHiIlLqQpP':
1146
+ c = c.astype(np.double)
1147
+ if isinstance(x, (tuple, list)):
1148
+ x = np.asarray(x)
1149
+ if isinstance(x, np.ndarray) and tensor:
1150
+ c = c.reshape(c.shape + (1,) * x.ndim)
1151
+
1152
+ if len(c) == 1:
1153
+ c0 = c[0]
1154
+ c1 = 0
1155
+ elif len(c) == 2:
1156
+ c0 = c[0]
1157
+ c1 = c[1]
1158
+ else:
1159
+ x2 = 2 * x
1160
+ c0 = c[-2]
1161
+ c1 = c[-1]
1162
+ for i in range(3, len(c) + 1):
1163
+ tmp = c0
1164
+ c0 = c[-i] - c1
1165
+ c1 = tmp + c1 * x2
1166
+ return c0 + c1 * x
1167
+
1168
+
1169
+ def chebval2d(x, y, c):
1170
+ """
1171
+ Evaluate a 2-D Chebyshev series at points (x, y).
1172
+
1173
+ This function returns the values:
1174
+
1175
+ .. math:: p(x,y) = \\sum_{i,j} c_{i,j} * T_i(x) * T_j(y)
1176
+
1177
+ The parameters `x` and `y` are converted to arrays only if they are
1178
+ tuples or a lists, otherwise they are treated as a scalars and they
1179
+ must have the same shape after conversion. In either case, either `x`
1180
+ and `y` or their elements must support multiplication and addition both
1181
+ with themselves and with the elements of `c`.
1182
+
1183
+ If `c` is a 1-D array a one is implicitly appended to its shape to make
1184
+ it 2-D. The shape of the result will be c.shape[2:] + x.shape.
1185
+
1186
+ Parameters
1187
+ ----------
1188
+ x, y : array_like, compatible objects
1189
+ The two dimensional series is evaluated at the points ``(x, y)``,
1190
+ where `x` and `y` must have the same shape. If `x` or `y` is a list
1191
+ or tuple, it is first converted to an ndarray, otherwise it is left
1192
+ unchanged and if it isn't an ndarray it is treated as a scalar.
1193
+ c : array_like
1194
+ Array of coefficients ordered so that the coefficient of the term
1195
+ of multi-degree i,j is contained in ``c[i,j]``. If `c` has
1196
+ dimension greater than 2 the remaining indices enumerate multiple
1197
+ sets of coefficients.
1198
+
1199
+ Returns
1200
+ -------
1201
+ values : ndarray, compatible object
1202
+ The values of the two dimensional Chebyshev series at points formed
1203
+ from pairs of corresponding values from `x` and `y`.
1204
+
1205
+ See Also
1206
+ --------
1207
+ chebval, chebgrid2d, chebval3d, chebgrid3d
1208
+ """
1209
+ return pu._valnd(chebval, c, x, y)
1210
+
1211
+
1212
+ def chebgrid2d(x, y, c):
1213
+ """
1214
+ Evaluate a 2-D Chebyshev series on the Cartesian product of x and y.
1215
+
1216
+ This function returns the values:
1217
+
1218
+ .. math:: p(a,b) = \\sum_{i,j} c_{i,j} * T_i(a) * T_j(b),
1219
+
1220
+ where the points `(a, b)` consist of all pairs formed by taking
1221
+ `a` from `x` and `b` from `y`. The resulting points form a grid with
1222
+ `x` in the first dimension and `y` in the second.
1223
+
1224
+ The parameters `x` and `y` are converted to arrays only if they are
1225
+ tuples or a lists, otherwise they are treated as a scalars. In either
1226
+ case, either `x` and `y` or their elements must support multiplication
1227
+ and addition both with themselves and with the elements of `c`.
1228
+
1229
+ If `c` has fewer than two dimensions, ones are implicitly appended to
1230
+ its shape to make it 2-D. The shape of the result will be c.shape[2:] +
1231
+ x.shape + y.shape.
1232
+
1233
+ Parameters
1234
+ ----------
1235
+ x, y : array_like, compatible objects
1236
+ The two dimensional series is evaluated at the points in the
1237
+ Cartesian product of `x` and `y`. If `x` or `y` is a list or
1238
+ tuple, it is first converted to an ndarray, otherwise it is left
1239
+ unchanged and, if it isn't an ndarray, it is treated as a scalar.
1240
+ c : array_like
1241
+ Array of coefficients ordered so that the coefficient of the term of
1242
+ multi-degree i,j is contained in ``c[i,j]``. If `c` has dimension
1243
+ greater than two the remaining indices enumerate multiple sets of
1244
+ coefficients.
1245
+
1246
+ Returns
1247
+ -------
1248
+ values : ndarray, compatible object
1249
+ The values of the two dimensional Chebyshev series at points in the
1250
+ Cartesian product of `x` and `y`.
1251
+
1252
+ See Also
1253
+ --------
1254
+ chebval, chebval2d, chebval3d, chebgrid3d
1255
+ """
1256
+ return pu._gridnd(chebval, c, x, y)
1257
+
1258
+
1259
+ def chebval3d(x, y, z, c):
1260
+ """
1261
+ Evaluate a 3-D Chebyshev series at points (x, y, z).
1262
+
1263
+ This function returns the values:
1264
+
1265
+ .. math:: p(x,y,z) = \\sum_{i,j,k} c_{i,j,k} * T_i(x) * T_j(y) * T_k(z)
1266
+
1267
+ The parameters `x`, `y`, and `z` are converted to arrays only if
1268
+ they are tuples or a lists, otherwise they are treated as a scalars and
1269
+ they must have the same shape after conversion. In either case, either
1270
+ `x`, `y`, and `z` or their elements must support multiplication and
1271
+ addition both with themselves and with the elements of `c`.
1272
+
1273
+ If `c` has fewer than 3 dimensions, ones are implicitly appended to its
1274
+ shape to make it 3-D. The shape of the result will be c.shape[3:] +
1275
+ x.shape.
1276
+
1277
+ Parameters
1278
+ ----------
1279
+ x, y, z : array_like, compatible object
1280
+ The three dimensional series is evaluated at the points
1281
+ ``(x, y, z)``, where `x`, `y`, and `z` must have the same shape. If
1282
+ any of `x`, `y`, or `z` is a list or tuple, it is first converted
1283
+ to an ndarray, otherwise it is left unchanged and if it isn't an
1284
+ ndarray it is treated as a scalar.
1285
+ c : array_like
1286
+ Array of coefficients ordered so that the coefficient of the term of
1287
+ multi-degree i,j,k is contained in ``c[i,j,k]``. If `c` has dimension
1288
+ greater than 3 the remaining indices enumerate multiple sets of
1289
+ coefficients.
1290
+
1291
+ Returns
1292
+ -------
1293
+ values : ndarray, compatible object
1294
+ The values of the multidimensional polynomial on points formed with
1295
+ triples of corresponding values from `x`, `y`, and `z`.
1296
+
1297
+ See Also
1298
+ --------
1299
+ chebval, chebval2d, chebgrid2d, chebgrid3d
1300
+ """
1301
+ return pu._valnd(chebval, c, x, y, z)
1302
+
1303
+
1304
+ def chebgrid3d(x, y, z, c):
1305
+ """
1306
+ Evaluate a 3-D Chebyshev series on the Cartesian product of x, y, and z.
1307
+
1308
+ This function returns the values:
1309
+
1310
+ .. math:: p(a,b,c) = \\sum_{i,j,k} c_{i,j,k} * T_i(a) * T_j(b) * T_k(c)
1311
+
1312
+ where the points ``(a, b, c)`` consist of all triples formed by taking
1313
+ `a` from `x`, `b` from `y`, and `c` from `z`. The resulting points form
1314
+ a grid with `x` in the first dimension, `y` in the second, and `z` in
1315
+ the third.
1316
+
1317
+ The parameters `x`, `y`, and `z` are converted to arrays only if they
1318
+ are tuples or a lists, otherwise they are treated as a scalars. In
1319
+ either case, either `x`, `y`, and `z` or their elements must support
1320
+ multiplication and addition both with themselves and with the elements
1321
+ of `c`.
1322
+
1323
+ If `c` has fewer than three dimensions, ones are implicitly appended to
1324
+ its shape to make it 3-D. The shape of the result will be c.shape[3:] +
1325
+ x.shape + y.shape + z.shape.
1326
+
1327
+ Parameters
1328
+ ----------
1329
+ x, y, z : array_like, compatible objects
1330
+ The three dimensional series is evaluated at the points in the
1331
+ Cartesian product of `x`, `y`, and `z`. If `x`, `y`, or `z` is a
1332
+ list or tuple, it is first converted to an ndarray, otherwise it is
1333
+ left unchanged and, if it isn't an ndarray, it is treated as a
1334
+ scalar.
1335
+ c : array_like
1336
+ Array of coefficients ordered so that the coefficients for terms of
1337
+ degree i,j are contained in ``c[i,j]``. If `c` has dimension
1338
+ greater than two the remaining indices enumerate multiple sets of
1339
+ coefficients.
1340
+
1341
+ Returns
1342
+ -------
1343
+ values : ndarray, compatible object
1344
+ The values of the two dimensional polynomial at points in the Cartesian
1345
+ product of `x` and `y`.
1346
+
1347
+ See Also
1348
+ --------
1349
+ chebval, chebval2d, chebgrid2d, chebval3d
1350
+ """
1351
+ return pu._gridnd(chebval, c, x, y, z)
1352
+
1353
+
1354
+ def chebvander(x, deg):
1355
+ """Pseudo-Vandermonde matrix of given degree.
1356
+
1357
+ Returns the pseudo-Vandermonde matrix of degree `deg` and sample points
1358
+ `x`. The pseudo-Vandermonde matrix is defined by
1359
+
1360
+ .. math:: V[..., i] = T_i(x),
1361
+
1362
+ where ``0 <= i <= deg``. The leading indices of `V` index the elements of
1363
+ `x` and the last index is the degree of the Chebyshev polynomial.
1364
+
1365
+ If `c` is a 1-D array of coefficients of length ``n + 1`` and `V` is the
1366
+ matrix ``V = chebvander(x, n)``, then ``np.dot(V, c)`` and
1367
+ ``chebval(x, c)`` are the same up to roundoff. This equivalence is
1368
+ useful both for least squares fitting and for the evaluation of a large
1369
+ number of Chebyshev series of the same degree and sample points.
1370
+
1371
+ Parameters
1372
+ ----------
1373
+ x : array_like
1374
+ Array of points. The dtype is converted to float64 or complex128
1375
+ depending on whether any of the elements are complex. If `x` is
1376
+ scalar it is converted to a 1-D array.
1377
+ deg : int
1378
+ Degree of the resulting matrix.
1379
+
1380
+ Returns
1381
+ -------
1382
+ vander : ndarray
1383
+ The pseudo Vandermonde matrix. The shape of the returned matrix is
1384
+ ``x.shape + (deg + 1,)``, where The last index is the degree of the
1385
+ corresponding Chebyshev polynomial. The dtype will be the same as
1386
+ the converted `x`.
1387
+
1388
+ """
1389
+ ideg = pu._as_int(deg, "deg")
1390
+ if ideg < 0:
1391
+ raise ValueError("deg must be non-negative")
1392
+
1393
+ x = np.array(x, copy=None, ndmin=1) + 0.0
1394
+ dims = (ideg + 1,) + x.shape
1395
+ dtyp = x.dtype
1396
+ v = np.empty(dims, dtype=dtyp)
1397
+ # Use forward recursion to generate the entries.
1398
+ v[0] = x * 0 + 1
1399
+ if ideg > 0:
1400
+ x2 = 2 * x
1401
+ v[1] = x
1402
+ for i in range(2, ideg + 1):
1403
+ v[i] = v[i - 1] * x2 - v[i - 2]
1404
+ return np.moveaxis(v, 0, -1)
1405
+
1406
+
1407
+ def chebvander2d(x, y, deg):
1408
+ """Pseudo-Vandermonde matrix of given degrees.
1409
+
1410
+ Returns the pseudo-Vandermonde matrix of degrees `deg` and sample
1411
+ points ``(x, y)``. The pseudo-Vandermonde matrix is defined by
1412
+
1413
+ .. math:: V[..., (deg[1] + 1)*i + j] = T_i(x) * T_j(y),
1414
+
1415
+ where ``0 <= i <= deg[0]`` and ``0 <= j <= deg[1]``. The leading indices of
1416
+ `V` index the points ``(x, y)`` and the last index encodes the degrees of
1417
+ the Chebyshev polynomials.
1418
+
1419
+ If ``V = chebvander2d(x, y, [xdeg, ydeg])``, then the columns of `V`
1420
+ correspond to the elements of a 2-D coefficient array `c` of shape
1421
+ (xdeg + 1, ydeg + 1) in the order
1422
+
1423
+ .. math:: c_{00}, c_{01}, c_{02} ... , c_{10}, c_{11}, c_{12} ...
1424
+
1425
+ and ``np.dot(V, c.flat)`` and ``chebval2d(x, y, c)`` will be the same
1426
+ up to roundoff. This equivalence is useful both for least squares
1427
+ fitting and for the evaluation of a large number of 2-D Chebyshev
1428
+ series of the same degrees and sample points.
1429
+
1430
+ Parameters
1431
+ ----------
1432
+ x, y : array_like
1433
+ Arrays of point coordinates, all of the same shape. The dtypes
1434
+ will be converted to either float64 or complex128 depending on
1435
+ whether any of the elements are complex. Scalars are converted to
1436
+ 1-D arrays.
1437
+ deg : list of ints
1438
+ List of maximum degrees of the form [x_deg, y_deg].
1439
+
1440
+ Returns
1441
+ -------
1442
+ vander2d : ndarray
1443
+ The shape of the returned matrix is ``x.shape + (order,)``, where
1444
+ :math:`order = (deg[0]+1)*(deg[1]+1)`. The dtype will be the same
1445
+ as the converted `x` and `y`.
1446
+
1447
+ See Also
1448
+ --------
1449
+ chebvander, chebvander3d, chebval2d, chebval3d
1450
+ """
1451
+ return pu._vander_nd_flat((chebvander, chebvander), (x, y), deg)
1452
+
1453
+
1454
+ def chebvander3d(x, y, z, deg):
1455
+ """Pseudo-Vandermonde matrix of given degrees.
1456
+
1457
+ Returns the pseudo-Vandermonde matrix of degrees `deg` and sample
1458
+ points ``(x, y, z)``. If `l`, `m`, `n` are the given degrees in `x`, `y`, `z`,
1459
+ then The pseudo-Vandermonde matrix is defined by
1460
+
1461
+ .. math:: V[..., (m+1)(n+1)i + (n+1)j + k] = T_i(x)*T_j(y)*T_k(z),
1462
+
1463
+ where ``0 <= i <= l``, ``0 <= j <= m``, and ``0 <= j <= n``. The leading
1464
+ indices of `V` index the points ``(x, y, z)`` and the last index encodes
1465
+ the degrees of the Chebyshev polynomials.
1466
+
1467
+ If ``V = chebvander3d(x, y, z, [xdeg, ydeg, zdeg])``, then the columns
1468
+ of `V` correspond to the elements of a 3-D coefficient array `c` of
1469
+ shape (xdeg + 1, ydeg + 1, zdeg + 1) in the order
1470
+
1471
+ .. math:: c_{000}, c_{001}, c_{002},... , c_{010}, c_{011}, c_{012},...
1472
+
1473
+ and ``np.dot(V, c.flat)`` and ``chebval3d(x, y, z, c)`` will be the
1474
+ same up to roundoff. This equivalence is useful both for least squares
1475
+ fitting and for the evaluation of a large number of 3-D Chebyshev
1476
+ series of the same degrees and sample points.
1477
+
1478
+ Parameters
1479
+ ----------
1480
+ x, y, z : array_like
1481
+ Arrays of point coordinates, all of the same shape. The dtypes will
1482
+ be converted to either float64 or complex128 depending on whether
1483
+ any of the elements are complex. Scalars are converted to 1-D
1484
+ arrays.
1485
+ deg : list of ints
1486
+ List of maximum degrees of the form [x_deg, y_deg, z_deg].
1487
+
1488
+ Returns
1489
+ -------
1490
+ vander3d : ndarray
1491
+ The shape of the returned matrix is ``x.shape + (order,)``, where
1492
+ :math:`order = (deg[0]+1)*(deg[1]+1)*(deg[2]+1)`. The dtype will
1493
+ be the same as the converted `x`, `y`, and `z`.
1494
+
1495
+ See Also
1496
+ --------
1497
+ chebvander, chebvander3d, chebval2d, chebval3d
1498
+ """
1499
+ return pu._vander_nd_flat((chebvander, chebvander, chebvander), (x, y, z), deg)
1500
+
1501
+
1502
+ def chebfit(x, y, deg, rcond=None, full=False, w=None):
1503
+ """
1504
+ Least squares fit of Chebyshev series to data.
1505
+
1506
+ Return the coefficients of a Chebyshev series of degree `deg` that is the
1507
+ least squares fit to the data values `y` given at points `x`. If `y` is
1508
+ 1-D the returned coefficients will also be 1-D. If `y` is 2-D multiple
1509
+ fits are done, one for each column of `y`, and the resulting
1510
+ coefficients are stored in the corresponding columns of a 2-D return.
1511
+ The fitted polynomial(s) are in the form
1512
+
1513
+ .. math:: p(x) = c_0 + c_1 * T_1(x) + ... + c_n * T_n(x),
1514
+
1515
+ where `n` is `deg`.
1516
+
1517
+ Parameters
1518
+ ----------
1519
+ x : array_like, shape (M,)
1520
+ x-coordinates of the M sample points ``(x[i], y[i])``.
1521
+ y : array_like, shape (M,) or (M, K)
1522
+ y-coordinates of the sample points. Several data sets of sample
1523
+ points sharing the same x-coordinates can be fitted at once by
1524
+ passing in a 2D-array that contains one dataset per column.
1525
+ deg : int or 1-D array_like
1526
+ Degree(s) of the fitting polynomials. If `deg` is a single integer,
1527
+ all terms up to and including the `deg`'th term are included in the
1528
+ fit. For NumPy versions >= 1.11.0 a list of integers specifying the
1529
+ degrees of the terms to include may be used instead.
1530
+ rcond : float, optional
1531
+ Relative condition number of the fit. Singular values smaller than
1532
+ this relative to the largest singular value will be ignored. The
1533
+ default value is ``len(x)*eps``, where eps is the relative precision of
1534
+ the float type, about 2e-16 in most cases.
1535
+ full : bool, optional
1536
+ Switch determining nature of return value. When it is False (the
1537
+ default) just the coefficients are returned, when True diagnostic
1538
+ information from the singular value decomposition is also returned.
1539
+ w : array_like, shape (`M`,), optional
1540
+ Weights. If not None, the weight ``w[i]`` applies to the unsquared
1541
+ residual ``y[i] - y_hat[i]`` at ``x[i]``. Ideally the weights are
1542
+ chosen so that the errors of the products ``w[i]*y[i]`` all have the
1543
+ same variance. When using inverse-variance weighting, use
1544
+ ``w[i] = 1/sigma(y[i])``. The default value is None.
1545
+
1546
+ Returns
1547
+ -------
1548
+ coef : ndarray, shape (M,) or (M, K)
1549
+ Chebyshev coefficients ordered from low to high. If `y` was 2-D,
1550
+ the coefficients for the data in column k of `y` are in column
1551
+ `k`.
1552
+
1553
+ [residuals, rank, singular_values, rcond] : list
1554
+ These values are only returned if ``full == True``
1555
+
1556
+ - residuals -- sum of squared residuals of the least squares fit
1557
+ - rank -- the numerical rank of the scaled Vandermonde matrix
1558
+ - singular_values -- singular values of the scaled Vandermonde matrix
1559
+ - rcond -- value of `rcond`.
1560
+
1561
+ For more details, see `numpy.linalg.lstsq`.
1562
+
1563
+ Warns
1564
+ -----
1565
+ RankWarning
1566
+ The rank of the coefficient matrix in the least-squares fit is
1567
+ deficient. The warning is only raised if ``full == False``. The
1568
+ warnings can be turned off by
1569
+
1570
+ >>> import warnings
1571
+ >>> warnings.simplefilter('ignore', np.exceptions.RankWarning)
1572
+
1573
+ See Also
1574
+ --------
1575
+ numpy.polynomial.polynomial.polyfit
1576
+ numpy.polynomial.legendre.legfit
1577
+ numpy.polynomial.laguerre.lagfit
1578
+ numpy.polynomial.hermite.hermfit
1579
+ numpy.polynomial.hermite_e.hermefit
1580
+ chebval : Evaluates a Chebyshev series.
1581
+ chebvander : Vandermonde matrix of Chebyshev series.
1582
+ chebweight : Chebyshev weight function.
1583
+ numpy.linalg.lstsq : Computes a least-squares fit from the matrix.
1584
+ scipy.interpolate.UnivariateSpline : Computes spline fits.
1585
+
1586
+ Notes
1587
+ -----
1588
+ The solution is the coefficients of the Chebyshev series `p` that
1589
+ minimizes the sum of the weighted squared errors
1590
+
1591
+ .. math:: E = \\sum_j w_j^2 * |y_j - p(x_j)|^2,
1592
+
1593
+ where :math:`w_j` are the weights. This problem is solved by setting up
1594
+ as the (typically) overdetermined matrix equation
1595
+
1596
+ .. math:: V(x) * c = w * y,
1597
+
1598
+ where `V` is the weighted pseudo Vandermonde matrix of `x`, `c` are the
1599
+ coefficients to be solved for, `w` are the weights, and `y` are the
1600
+ observed values. This equation is then solved using the singular value
1601
+ decomposition of `V`.
1602
+
1603
+ If some of the singular values of `V` are so small that they are
1604
+ neglected, then a `~exceptions.RankWarning` will be issued. This means that
1605
+ the coefficient values may be poorly determined. Using a lower order fit
1606
+ will usually get rid of the warning. The `rcond` parameter can also be
1607
+ set to a value smaller than its default, but the resulting fit may be
1608
+ spurious and have large contributions from roundoff error.
1609
+
1610
+ Fits using Chebyshev series are usually better conditioned than fits
1611
+ using power series, but much can depend on the distribution of the
1612
+ sample points and the smoothness of the data. If the quality of the fit
1613
+ is inadequate splines may be a good alternative.
1614
+
1615
+ References
1616
+ ----------
1617
+ .. [1] Wikipedia, "Curve fitting",
1618
+ https://en.wikipedia.org/wiki/Curve_fitting
1619
+
1620
+ Examples
1621
+ --------
1622
+
1623
+ """
1624
+ return pu._fit(chebvander, x, y, deg, rcond, full, w)
1625
+
1626
+
1627
+ def chebcompanion(c):
1628
+ """Return the scaled companion matrix of c.
1629
+
1630
+ The basis polynomials are scaled so that the companion matrix is
1631
+ symmetric when `c` is a Chebyshev basis polynomial. This provides
1632
+ better eigenvalue estimates than the unscaled case and for basis
1633
+ polynomials the eigenvalues are guaranteed to be real if
1634
+ `numpy.linalg.eigvalsh` is used to obtain them.
1635
+
1636
+ Parameters
1637
+ ----------
1638
+ c : array_like
1639
+ 1-D array of Chebyshev series coefficients ordered from low to high
1640
+ degree.
1641
+
1642
+ Returns
1643
+ -------
1644
+ mat : ndarray
1645
+ Scaled companion matrix of dimensions (deg, deg).
1646
+ """
1647
+ # c is a trimmed copy
1648
+ [c] = pu.as_series([c])
1649
+ if len(c) < 2:
1650
+ raise ValueError('Series must have maximum degree of at least 1.')
1651
+ if len(c) == 2:
1652
+ return np.array([[-c[0] / c[1]]])
1653
+
1654
+ n = len(c) - 1
1655
+ mat = np.zeros((n, n), dtype=c.dtype)
1656
+ scl = np.array([1.] + [np.sqrt(.5)] * (n - 1))
1657
+ top = mat.reshape(-1)[1::n + 1]
1658
+ bot = mat.reshape(-1)[n::n + 1]
1659
+ top[0] = np.sqrt(.5)
1660
+ top[1:] = 1 / 2
1661
+ bot[...] = top
1662
+ mat[:, -1] -= (c[:-1] / c[-1]) * (scl / scl[-1]) * .5
1663
+ return mat
1664
+
1665
+
1666
+ def chebroots(c):
1667
+ """
1668
+ Compute the roots of a Chebyshev series.
1669
+
1670
+ Return the roots (a.k.a. "zeros") of the polynomial
1671
+
1672
+ .. math:: p(x) = \\sum_i c[i] * T_i(x).
1673
+
1674
+ Parameters
1675
+ ----------
1676
+ c : 1-D array_like
1677
+ 1-D array of coefficients.
1678
+
1679
+ Returns
1680
+ -------
1681
+ out : ndarray
1682
+ Array of the roots of the series. If all the roots are real,
1683
+ then `out` is also real, otherwise it is complex.
1684
+
1685
+ See Also
1686
+ --------
1687
+ numpy.polynomial.polynomial.polyroots
1688
+ numpy.polynomial.legendre.legroots
1689
+ numpy.polynomial.laguerre.lagroots
1690
+ numpy.polynomial.hermite.hermroots
1691
+ numpy.polynomial.hermite_e.hermeroots
1692
+
1693
+ Notes
1694
+ -----
1695
+ The root estimates are obtained as the eigenvalues of the companion
1696
+ matrix, Roots far from the origin of the complex plane may have large
1697
+ errors due to the numerical instability of the series for such
1698
+ values. Roots with multiplicity greater than 1 will also show larger
1699
+ errors as the value of the series near such points is relatively
1700
+ insensitive to errors in the roots. Isolated roots near the origin can
1701
+ be improved by a few iterations of Newton's method.
1702
+
1703
+ The Chebyshev series basis polynomials aren't powers of `x` so the
1704
+ results of this function may seem unintuitive.
1705
+
1706
+ Examples
1707
+ --------
1708
+ >>> import numpy.polynomial.chebyshev as cheb
1709
+ >>> cheb.chebroots((-1, 1,-1, 1)) # T3 - T2 + T1 - T0 has real roots
1710
+ array([ -5.00000000e-01, 2.60860684e-17, 1.00000000e+00]) # may vary
1711
+
1712
+ """
1713
+ # c is a trimmed copy
1714
+ [c] = pu.as_series([c])
1715
+ if len(c) < 2:
1716
+ return np.array([], dtype=c.dtype)
1717
+ if len(c) == 2:
1718
+ return np.array([-c[0] / c[1]])
1719
+
1720
+ # rotated companion matrix reduces error
1721
+ m = chebcompanion(c)[::-1, ::-1]
1722
+ r = np.linalg.eigvals(m)
1723
+ r.sort()
1724
+ return r
1725
+
1726
+
1727
+ def chebinterpolate(func, deg, args=()):
1728
+ """Interpolate a function at the Chebyshev points of the first kind.
1729
+
1730
+ Returns the Chebyshev series that interpolates `func` at the Chebyshev
1731
+ points of the first kind in the interval [-1, 1]. The interpolating
1732
+ series tends to a minmax approximation to `func` with increasing `deg`
1733
+ if the function is continuous in the interval.
1734
+
1735
+ Parameters
1736
+ ----------
1737
+ func : function
1738
+ The function to be approximated. It must be a function of a single
1739
+ variable of the form ``f(x, a, b, c...)``, where ``a, b, c...`` are
1740
+ extra arguments passed in the `args` parameter.
1741
+ deg : int
1742
+ Degree of the interpolating polynomial
1743
+ args : tuple, optional
1744
+ Extra arguments to be used in the function call. Default is no extra
1745
+ arguments.
1746
+
1747
+ Returns
1748
+ -------
1749
+ coef : ndarray, shape (deg + 1,)
1750
+ Chebyshev coefficients of the interpolating series ordered from low to
1751
+ high.
1752
+
1753
+ Examples
1754
+ --------
1755
+ >>> import numpy.polynomial.chebyshev as C
1756
+ >>> C.chebinterpolate(lambda x: np.tanh(x) + 0.5, 8)
1757
+ array([ 5.00000000e-01, 8.11675684e-01, -9.86864911e-17,
1758
+ -5.42457905e-02, -2.71387850e-16, 4.51658839e-03,
1759
+ 2.46716228e-17, -3.79694221e-04, -3.26899002e-16])
1760
+
1761
+ Notes
1762
+ -----
1763
+ The Chebyshev polynomials used in the interpolation are orthogonal when
1764
+ sampled at the Chebyshev points of the first kind. If it is desired to
1765
+ constrain some of the coefficients they can simply be set to the desired
1766
+ value after the interpolation, no new interpolation or fit is needed. This
1767
+ is especially useful if it is known apriori that some of coefficients are
1768
+ zero. For instance, if the function is even then the coefficients of the
1769
+ terms of odd degree in the result can be set to zero.
1770
+
1771
+ """
1772
+ deg = np.asarray(deg)
1773
+
1774
+ # check arguments.
1775
+ if deg.ndim > 0 or deg.dtype.kind not in 'iu' or deg.size == 0:
1776
+ raise TypeError("deg must be an int")
1777
+ if deg < 0:
1778
+ raise ValueError("expected deg >= 0")
1779
+
1780
+ order = deg + 1
1781
+ xcheb = chebpts1(order)
1782
+ yfunc = func(xcheb, *args)
1783
+ m = chebvander(xcheb, deg)
1784
+ c = np.dot(m.T, yfunc)
1785
+ c[0] /= order
1786
+ c[1:] /= 0.5 * order
1787
+
1788
+ return c
1789
+
1790
+
1791
+ def chebgauss(deg):
1792
+ """
1793
+ Gauss-Chebyshev quadrature.
1794
+
1795
+ Computes the sample points and weights for Gauss-Chebyshev quadrature.
1796
+ These sample points and weights will correctly integrate polynomials of
1797
+ degree :math:`2*deg - 1` or less over the interval :math:`[-1, 1]` with
1798
+ the weight function :math:`f(x) = 1/\\sqrt{1 - x^2}`.
1799
+
1800
+ Parameters
1801
+ ----------
1802
+ deg : int
1803
+ Number of sample points and weights. It must be >= 1.
1804
+
1805
+ Returns
1806
+ -------
1807
+ x : ndarray
1808
+ 1-D ndarray containing the sample points.
1809
+ y : ndarray
1810
+ 1-D ndarray containing the weights.
1811
+
1812
+ Notes
1813
+ -----
1814
+ The results have only been tested up to degree 100, higher degrees may
1815
+ be problematic. For Gauss-Chebyshev there are closed form solutions for
1816
+ the sample points and weights. If n = `deg`, then
1817
+
1818
+ .. math:: x_i = \\cos(\\pi (2 i - 1) / (2 n))
1819
+
1820
+ .. math:: w_i = \\pi / n
1821
+
1822
+ """
1823
+ ideg = pu._as_int(deg, "deg")
1824
+ if ideg <= 0:
1825
+ raise ValueError("deg must be a positive integer")
1826
+
1827
+ x = np.cos(np.pi * np.arange(1, 2 * ideg, 2) / (2.0 * ideg))
1828
+ w = np.ones(ideg) * (np.pi / ideg)
1829
+
1830
+ return x, w
1831
+
1832
+
1833
+ def chebweight(x):
1834
+ """
1835
+ The weight function of the Chebyshev polynomials.
1836
+
1837
+ The weight function is :math:`1/\\sqrt{1 - x^2}` and the interval of
1838
+ integration is :math:`[-1, 1]`. The Chebyshev polynomials are
1839
+ orthogonal, but not normalized, with respect to this weight function.
1840
+
1841
+ Parameters
1842
+ ----------
1843
+ x : array_like
1844
+ Values at which the weight function will be computed.
1845
+
1846
+ Returns
1847
+ -------
1848
+ w : ndarray
1849
+ The weight function at `x`.
1850
+ """
1851
+ w = 1. / (np.sqrt(1. + x) * np.sqrt(1. - x))
1852
+ return w
1853
+
1854
+
1855
+ def chebpts1(npts):
1856
+ """
1857
+ Chebyshev points of the first kind.
1858
+
1859
+ The Chebyshev points of the first kind are the points ``cos(x)``,
1860
+ where ``x = [pi*(k + .5)/npts for k in range(npts)]``.
1861
+
1862
+ Parameters
1863
+ ----------
1864
+ npts : int
1865
+ Number of sample points desired.
1866
+
1867
+ Returns
1868
+ -------
1869
+ pts : ndarray
1870
+ The Chebyshev points of the first kind.
1871
+
1872
+ See Also
1873
+ --------
1874
+ chebpts2
1875
+ """
1876
+ _npts = int(npts)
1877
+ if _npts != npts:
1878
+ raise ValueError("npts must be integer")
1879
+ if _npts < 1:
1880
+ raise ValueError("npts must be >= 1")
1881
+
1882
+ x = 0.5 * np.pi / _npts * np.arange(-_npts + 1, _npts + 1, 2)
1883
+ return np.sin(x)
1884
+
1885
+
1886
+ def chebpts2(npts):
1887
+ """
1888
+ Chebyshev points of the second kind.
1889
+
1890
+ The Chebyshev points of the second kind are the points ``cos(x)``,
1891
+ where ``x = [pi*k/(npts - 1) for k in range(npts)]`` sorted in ascending
1892
+ order.
1893
+
1894
+ Parameters
1895
+ ----------
1896
+ npts : int
1897
+ Number of sample points desired.
1898
+
1899
+ Returns
1900
+ -------
1901
+ pts : ndarray
1902
+ The Chebyshev points of the second kind.
1903
+ """
1904
+ _npts = int(npts)
1905
+ if _npts != npts:
1906
+ raise ValueError("npts must be integer")
1907
+ if _npts < 2:
1908
+ raise ValueError("npts must be >= 2")
1909
+
1910
+ x = np.linspace(-np.pi, 0, _npts)
1911
+ return np.cos(x)
1912
+
1913
+
1914
+ #
1915
+ # Chebyshev series class
1916
+ #
1917
+
1918
+ class Chebyshev(ABCPolyBase):
1919
+ """A Chebyshev series class.
1920
+
1921
+ The Chebyshev class provides the standard Python numerical methods
1922
+ '+', '-', '*', '//', '%', 'divmod', '**', and '()' as well as the
1923
+ attributes and methods listed below.
1924
+
1925
+ Parameters
1926
+ ----------
1927
+ coef : array_like
1928
+ Chebyshev coefficients in order of increasing degree, i.e.,
1929
+ ``(1, 2, 3)`` gives ``1*T_0(x) + 2*T_1(x) + 3*T_2(x)``.
1930
+ domain : (2,) array_like, optional
1931
+ Domain to use. The interval ``[domain[0], domain[1]]`` is mapped
1932
+ to the interval ``[window[0], window[1]]`` by shifting and scaling.
1933
+ The default value is [-1., 1.].
1934
+ window : (2,) array_like, optional
1935
+ Window, see `domain` for its use. The default value is [-1., 1.].
1936
+ symbol : str, optional
1937
+ Symbol used to represent the independent variable in string
1938
+ representations of the polynomial expression, e.g. for printing.
1939
+ The symbol must be a valid Python identifier. Default value is 'x'.
1940
+
1941
+ .. versionadded:: 1.24
1942
+
1943
+ """
1944
+ # Virtual Functions
1945
+ _add = staticmethod(chebadd)
1946
+ _sub = staticmethod(chebsub)
1947
+ _mul = staticmethod(chebmul)
1948
+ _div = staticmethod(chebdiv)
1949
+ _pow = staticmethod(chebpow)
1950
+ _val = staticmethod(chebval)
1951
+ _int = staticmethod(chebint)
1952
+ _der = staticmethod(chebder)
1953
+ _fit = staticmethod(chebfit)
1954
+ _line = staticmethod(chebline)
1955
+ _roots = staticmethod(chebroots)
1956
+ _fromroots = staticmethod(chebfromroots)
1957
+
1958
+ @classmethod
1959
+ def interpolate(cls, func, deg, domain=None, args=()):
1960
+ """Interpolate a function at the Chebyshev points of the first kind.
1961
+
1962
+ Returns the series that interpolates `func` at the Chebyshev points of
1963
+ the first kind scaled and shifted to the `domain`. The resulting series
1964
+ tends to a minmax approximation of `func` when the function is
1965
+ continuous in the domain.
1966
+
1967
+ Parameters
1968
+ ----------
1969
+ func : function
1970
+ The function to be interpolated. It must be a function of a single
1971
+ variable of the form ``f(x, a, b, c...)``, where ``a, b, c...`` are
1972
+ extra arguments passed in the `args` parameter.
1973
+ deg : int
1974
+ Degree of the interpolating polynomial.
1975
+ domain : {None, [beg, end]}, optional
1976
+ Domain over which `func` is interpolated. The default is None, in
1977
+ which case the domain is [-1, 1].
1978
+ args : tuple, optional
1979
+ Extra arguments to be used in the function call. Default is no
1980
+ extra arguments.
1981
+
1982
+ Returns
1983
+ -------
1984
+ polynomial : Chebyshev instance
1985
+ Interpolating Chebyshev instance.
1986
+
1987
+ Notes
1988
+ -----
1989
+ See `numpy.polynomial.chebinterpolate` for more details.
1990
+
1991
+ """
1992
+ if domain is None:
1993
+ domain = cls.domain
1994
+ xfunc = lambda x: func(pu.mapdomain(x, cls.window, domain), *args)
1995
+ coef = chebinterpolate(xfunc, deg)
1996
+ return cls(coef, domain=domain)
1997
+
1998
+ # Virtual properties
1999
+ domain = np.array(chebdomain)
2000
+ window = np.array(chebdomain)
2001
+ basis_name = 'T'
physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy/polynomial/chebyshev.pyi ADDED
@@ -0,0 +1,180 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from _typeshed import ConvertibleToInt
2
+ from collections.abc import Callable, Iterable
3
+ from typing import (
4
+ Any,
5
+ ClassVar,
6
+ Concatenate,
7
+ Final,
8
+ Literal as L,
9
+ Self,
10
+ TypeVar,
11
+ overload,
12
+ )
13
+
14
+ import numpy as np
15
+ import numpy.typing as npt
16
+ from numpy._typing import _IntLike_co
17
+
18
+ from ._polybase import ABCPolyBase
19
+ from ._polytypes import (
20
+ _Array1,
21
+ _Array2,
22
+ _CoefSeries,
23
+ _FuncBinOp,
24
+ _FuncCompanion,
25
+ _FuncDer,
26
+ _FuncFit,
27
+ _FuncFromRoots,
28
+ _FuncGauss,
29
+ _FuncInteg,
30
+ _FuncLine,
31
+ _FuncPoly2Ortho,
32
+ _FuncPow,
33
+ _FuncRoots,
34
+ _FuncUnOp,
35
+ _FuncVal,
36
+ _FuncVal2D,
37
+ _FuncVal3D,
38
+ _FuncVander,
39
+ _FuncVander2D,
40
+ _FuncVander3D,
41
+ _FuncWeight,
42
+ _Series,
43
+ _SeriesLikeCoef_co,
44
+ )
45
+ from .polyutils import trimcoef as chebtrim
46
+
47
+ __all__ = [
48
+ "chebzero",
49
+ "chebone",
50
+ "chebx",
51
+ "chebdomain",
52
+ "chebline",
53
+ "chebadd",
54
+ "chebsub",
55
+ "chebmulx",
56
+ "chebmul",
57
+ "chebdiv",
58
+ "chebpow",
59
+ "chebval",
60
+ "chebder",
61
+ "chebint",
62
+ "cheb2poly",
63
+ "poly2cheb",
64
+ "chebfromroots",
65
+ "chebvander",
66
+ "chebfit",
67
+ "chebtrim",
68
+ "chebroots",
69
+ "chebpts1",
70
+ "chebpts2",
71
+ "Chebyshev",
72
+ "chebval2d",
73
+ "chebval3d",
74
+ "chebgrid2d",
75
+ "chebgrid3d",
76
+ "chebvander2d",
77
+ "chebvander3d",
78
+ "chebcompanion",
79
+ "chebgauss",
80
+ "chebweight",
81
+ "chebinterpolate",
82
+ ]
83
+
84
+ _NumberOrObjectT = TypeVar("_NumberOrObjectT", bound=np.number | np.object_)
85
+ _CoefScalarT = TypeVar("_CoefScalarT", bound=np.number | np.bool | np.object_)
86
+
87
+ def _cseries_to_zseries(c: npt.NDArray[_NumberOrObjectT]) -> _Series[_NumberOrObjectT]: ...
88
+ def _zseries_to_cseries(zs: npt.NDArray[_NumberOrObjectT]) -> _Series[_NumberOrObjectT]: ...
89
+ def _zseries_mul(z1: npt.NDArray[_NumberOrObjectT], z2: npt.NDArray[_NumberOrObjectT]) -> _Series[_NumberOrObjectT]: ...
90
+ def _zseries_div(z1: npt.NDArray[_NumberOrObjectT], z2: npt.NDArray[_NumberOrObjectT]) -> _Series[_NumberOrObjectT]: ...
91
+ def _zseries_der(zs: npt.NDArray[_NumberOrObjectT]) -> _Series[_NumberOrObjectT]: ...
92
+ def _zseries_int(zs: npt.NDArray[_NumberOrObjectT]) -> _Series[_NumberOrObjectT]: ...
93
+
94
+ poly2cheb: Final[_FuncPoly2Ortho] = ...
95
+ cheb2poly: Final[_FuncUnOp] = ...
96
+
97
+ chebdomain: Final[_Array2[np.float64]] = ...
98
+ chebzero: Final[_Array1[np.int_]] = ...
99
+ chebone: Final[_Array1[np.int_]] = ...
100
+ chebx: Final[_Array2[np.int_]] = ...
101
+
102
+ chebline: Final[_FuncLine] = ...
103
+ chebfromroots: Final[_FuncFromRoots] = ...
104
+ chebadd: Final[_FuncBinOp] = ...
105
+ chebsub: Final[_FuncBinOp] = ...
106
+ chebmulx: Final[_FuncUnOp] = ...
107
+ chebmul: Final[_FuncBinOp] = ...
108
+ chebdiv: Final[_FuncBinOp] = ...
109
+ chebpow: Final[_FuncPow] = ...
110
+ chebder: Final[_FuncDer] = ...
111
+ chebint: Final[_FuncInteg] = ...
112
+ chebval: Final[_FuncVal] = ...
113
+ chebval2d: Final[_FuncVal2D] = ...
114
+ chebval3d: Final[_FuncVal3D] = ...
115
+ chebgrid2d: Final[_FuncVal2D] = ...
116
+ chebgrid3d: Final[_FuncVal3D] = ...
117
+ chebvander: Final[_FuncVander] = ...
118
+ chebvander2d: Final[_FuncVander2D] = ...
119
+ chebvander3d: Final[_FuncVander3D] = ...
120
+ chebfit: Final[_FuncFit] = ...
121
+ chebcompanion: Final[_FuncCompanion] = ...
122
+ chebroots: Final[_FuncRoots] = ...
123
+ chebgauss: Final[_FuncGauss] = ...
124
+ chebweight: Final[_FuncWeight] = ...
125
+ def chebpts1(npts: ConvertibleToInt) -> np.ndarray[tuple[int], np.dtype[np.float64]]: ...
126
+ def chebpts2(npts: ConvertibleToInt) -> np.ndarray[tuple[int], np.dtype[np.float64]]: ...
127
+
128
+ # keep in sync with `Chebyshev.interpolate` (minus `domain` parameter)
129
+ @overload
130
+ def chebinterpolate(
131
+ func: np.ufunc,
132
+ deg: _IntLike_co,
133
+ args: tuple[()] = (),
134
+ ) -> npt.NDArray[np.float64 | np.complex128 | np.object_]: ...
135
+ @overload
136
+ def chebinterpolate(
137
+ func: Callable[[npt.NDArray[np.float64]], _CoefScalarT],
138
+ deg: _IntLike_co,
139
+ args: tuple[()] = (),
140
+ ) -> npt.NDArray[_CoefScalarT]: ...
141
+ @overload
142
+ def chebinterpolate(
143
+ func: Callable[Concatenate[npt.NDArray[np.float64], ...], _CoefScalarT],
144
+ deg: _IntLike_co,
145
+ args: Iterable[Any],
146
+ ) -> npt.NDArray[_CoefScalarT]: ...
147
+
148
+ class Chebyshev(ABCPolyBase[L["T"]]):
149
+ basis_name: ClassVar[L["T"]] = "T" # pyright: ignore[reportIncompatibleMethodOverride]
150
+ domain: _Array2[np.float64 | Any] = ... # pyright: ignore[reportIncompatibleMethodOverride]
151
+ window: _Array2[np.float64 | Any] = ... # pyright: ignore[reportIncompatibleMethodOverride]
152
+
153
+ @overload
154
+ @classmethod
155
+ def interpolate(
156
+ cls,
157
+ func: Callable[[npt.NDArray[np.float64]], _CoefSeries],
158
+ deg: _IntLike_co,
159
+ domain: _SeriesLikeCoef_co | None = None,
160
+ args: tuple[()] = (),
161
+ ) -> Self: ...
162
+ @overload
163
+ @classmethod
164
+ def interpolate(
165
+ cls,
166
+ func: Callable[Concatenate[npt.NDArray[np.float64], ...], _CoefSeries],
167
+ deg: _IntLike_co,
168
+ domain: _SeriesLikeCoef_co | None = None,
169
+ *,
170
+ args: Iterable[Any],
171
+ ) -> Self: ...
172
+ @overload
173
+ @classmethod
174
+ def interpolate(
175
+ cls,
176
+ func: Callable[Concatenate[npt.NDArray[np.float64], ...], _CoefSeries],
177
+ deg: _IntLike_co,
178
+ domain: _SeriesLikeCoef_co | None,
179
+ args: Iterable[Any],
180
+ ) -> Self: ...
physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy/polynomial/hermite.py ADDED
@@ -0,0 +1,1738 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ ==============================================================
3
+ Hermite Series, "Physicists" (:mod:`numpy.polynomial.hermite`)
4
+ ==============================================================
5
+
6
+ This module provides a number of objects (mostly functions) useful for
7
+ dealing with Hermite series, including a `Hermite` class that
8
+ encapsulates the usual arithmetic operations. (General information
9
+ on how this module represents and works with such polynomials is in the
10
+ docstring for its "parent" sub-package, `numpy.polynomial`).
11
+
12
+ Classes
13
+ -------
14
+ .. autosummary::
15
+ :toctree: generated/
16
+
17
+ Hermite
18
+
19
+ Constants
20
+ ---------
21
+ .. autosummary::
22
+ :toctree: generated/
23
+
24
+ hermdomain
25
+ hermzero
26
+ hermone
27
+ hermx
28
+
29
+ Arithmetic
30
+ ----------
31
+ .. autosummary::
32
+ :toctree: generated/
33
+
34
+ hermadd
35
+ hermsub
36
+ hermmulx
37
+ hermmul
38
+ hermdiv
39
+ hermpow
40
+ hermval
41
+ hermval2d
42
+ hermval3d
43
+ hermgrid2d
44
+ hermgrid3d
45
+
46
+ Calculus
47
+ --------
48
+ .. autosummary::
49
+ :toctree: generated/
50
+
51
+ hermder
52
+ hermint
53
+
54
+ Misc Functions
55
+ --------------
56
+ .. autosummary::
57
+ :toctree: generated/
58
+
59
+ hermfromroots
60
+ hermroots
61
+ hermvander
62
+ hermvander2d
63
+ hermvander3d
64
+ hermgauss
65
+ hermweight
66
+ hermcompanion
67
+ hermfit
68
+ hermtrim
69
+ hermline
70
+ herm2poly
71
+ poly2herm
72
+
73
+ See also
74
+ --------
75
+ `numpy.polynomial`
76
+
77
+ """
78
+ import numpy as np
79
+
80
+ from . import polyutils as pu
81
+ from ._polybase import ABCPolyBase
82
+
83
+ __all__ = [
84
+ 'hermzero', 'hermone', 'hermx', 'hermdomain', 'hermline', 'hermadd',
85
+ 'hermsub', 'hermmulx', 'hermmul', 'hermdiv', 'hermpow', 'hermval',
86
+ 'hermder', 'hermint', 'herm2poly', 'poly2herm', 'hermfromroots',
87
+ 'hermvander', 'hermfit', 'hermtrim', 'hermroots', 'Hermite',
88
+ 'hermval2d', 'hermval3d', 'hermgrid2d', 'hermgrid3d', 'hermvander2d',
89
+ 'hermvander3d', 'hermcompanion', 'hermgauss', 'hermweight']
90
+
91
+ hermtrim = pu.trimcoef
92
+
93
+
94
+ def poly2herm(pol):
95
+ """
96
+ poly2herm(pol)
97
+
98
+ Convert a polynomial to a Hermite series.
99
+
100
+ Convert an array representing the coefficients of a polynomial (relative
101
+ to the "standard" basis) ordered from lowest degree to highest, to an
102
+ array of the coefficients of the equivalent Hermite series, ordered
103
+ from lowest to highest degree.
104
+
105
+ Parameters
106
+ ----------
107
+ pol : array_like
108
+ 1-D array containing the polynomial coefficients
109
+
110
+ Returns
111
+ -------
112
+ c : ndarray
113
+ 1-D array containing the coefficients of the equivalent Hermite
114
+ series.
115
+
116
+ See Also
117
+ --------
118
+ herm2poly
119
+
120
+ Notes
121
+ -----
122
+ The easy way to do conversions between polynomial basis sets
123
+ is to use the convert method of a class instance.
124
+
125
+ Examples
126
+ --------
127
+ >>> from numpy.polynomial.hermite import poly2herm
128
+ >>> poly2herm(np.arange(4))
129
+ array([1. , 2.75 , 0.5 , 0.375])
130
+
131
+ """
132
+ [pol] = pu.as_series([pol])
133
+ deg = len(pol) - 1
134
+ res = 0
135
+ for i in range(deg, -1, -1):
136
+ res = hermadd(hermmulx(res), pol[i])
137
+ return res
138
+
139
+
140
+ def herm2poly(c):
141
+ """
142
+ Convert a Hermite series to a polynomial.
143
+
144
+ Convert an array representing the coefficients of a Hermite series,
145
+ ordered from lowest degree to highest, to an array of the coefficients
146
+ of the equivalent polynomial (relative to the "standard" basis) ordered
147
+ from lowest to highest degree.
148
+
149
+ Parameters
150
+ ----------
151
+ c : array_like
152
+ 1-D array containing the Hermite series coefficients, ordered
153
+ from lowest order term to highest.
154
+
155
+ Returns
156
+ -------
157
+ pol : ndarray
158
+ 1-D array containing the coefficients of the equivalent polynomial
159
+ (relative to the "standard" basis) ordered from lowest order term
160
+ to highest.
161
+
162
+ See Also
163
+ --------
164
+ poly2herm
165
+
166
+ Notes
167
+ -----
168
+ The easy way to do conversions between polynomial basis sets
169
+ is to use the convert method of a class instance.
170
+
171
+ Examples
172
+ --------
173
+ >>> from numpy.polynomial.hermite import herm2poly
174
+ >>> herm2poly([ 1. , 2.75 , 0.5 , 0.375])
175
+ array([0., 1., 2., 3.])
176
+
177
+ """
178
+ from .polynomial import polyadd, polymulx, polysub
179
+
180
+ [c] = pu.as_series([c])
181
+ n = len(c)
182
+ if n == 1:
183
+ return c
184
+ if n == 2:
185
+ c[1] *= 2
186
+ return c
187
+ else:
188
+ c0 = c[-2]
189
+ c1 = c[-1]
190
+ # i is the current degree of c1
191
+ for i in range(n - 1, 1, -1):
192
+ tmp = c0
193
+ c0 = polysub(c[i - 2], c1 * (2 * (i - 1)))
194
+ c1 = polyadd(tmp, polymulx(c1) * 2)
195
+ return polyadd(c0, polymulx(c1) * 2)
196
+
197
+
198
+ #
199
+ # These are constant arrays are of integer type so as to be compatible
200
+ # with the widest range of other types, such as Decimal.
201
+ #
202
+
203
+ # Hermite
204
+ hermdomain = np.array([-1., 1.])
205
+
206
+ # Hermite coefficients representing zero.
207
+ hermzero = np.array([0])
208
+
209
+ # Hermite coefficients representing one.
210
+ hermone = np.array([1])
211
+
212
+ # Hermite coefficients representing the identity x.
213
+ hermx = np.array([0, 1 / 2])
214
+
215
+
216
+ def hermline(off, scl):
217
+ """
218
+ Hermite series whose graph is a straight line.
219
+
220
+
221
+
222
+ Parameters
223
+ ----------
224
+ off, scl : scalars
225
+ The specified line is given by ``off + scl*x``.
226
+
227
+ Returns
228
+ -------
229
+ y : ndarray
230
+ This module's representation of the Hermite series for
231
+ ``off + scl*x``.
232
+
233
+ See Also
234
+ --------
235
+ numpy.polynomial.polynomial.polyline
236
+ numpy.polynomial.chebyshev.chebline
237
+ numpy.polynomial.legendre.legline
238
+ numpy.polynomial.laguerre.lagline
239
+ numpy.polynomial.hermite_e.hermeline
240
+
241
+ Examples
242
+ --------
243
+ >>> from numpy.polynomial.hermite import hermline, hermval
244
+ >>> hermval(0,hermline(3, 2))
245
+ 3.0
246
+ >>> hermval(1,hermline(3, 2))
247
+ 5.0
248
+
249
+ """
250
+ if scl != 0:
251
+ return np.array([off, scl / 2])
252
+ else:
253
+ return np.array([off])
254
+
255
+
256
+ def hermfromroots(roots):
257
+ """
258
+ Generate a Hermite series with given roots.
259
+
260
+ The function returns the coefficients of the polynomial
261
+
262
+ .. math:: p(x) = (x - r_0) * (x - r_1) * ... * (x - r_n),
263
+
264
+ in Hermite form, where the :math:`r_n` are the roots specified in `roots`.
265
+ If a zero has multiplicity n, then it must appear in `roots` n times.
266
+ For instance, if 2 is a root of multiplicity three and 3 is a root of
267
+ multiplicity 2, then `roots` looks something like [2, 2, 2, 3, 3]. The
268
+ roots can appear in any order.
269
+
270
+ If the returned coefficients are `c`, then
271
+
272
+ .. math:: p(x) = c_0 + c_1 * H_1(x) + ... + c_n * H_n(x)
273
+
274
+ The coefficient of the last term is not generally 1 for monic
275
+ polynomials in Hermite form.
276
+
277
+ Parameters
278
+ ----------
279
+ roots : array_like
280
+ Sequence containing the roots.
281
+
282
+ Returns
283
+ -------
284
+ out : ndarray
285
+ 1-D array of coefficients. If all roots are real then `out` is a
286
+ real array, if some of the roots are complex, then `out` is complex
287
+ even if all the coefficients in the result are real (see Examples
288
+ below).
289
+
290
+ See Also
291
+ --------
292
+ numpy.polynomial.polynomial.polyfromroots
293
+ numpy.polynomial.legendre.legfromroots
294
+ numpy.polynomial.laguerre.lagfromroots
295
+ numpy.polynomial.chebyshev.chebfromroots
296
+ numpy.polynomial.hermite_e.hermefromroots
297
+
298
+ Examples
299
+ --------
300
+ >>> from numpy.polynomial.hermite import hermfromroots, hermval
301
+ >>> coef = hermfromroots((-1, 0, 1))
302
+ >>> hermval((-1, 0, 1), coef)
303
+ array([0., 0., 0.])
304
+ >>> coef = hermfromroots((-1j, 1j))
305
+ >>> hermval((-1j, 1j), coef)
306
+ array([0.+0.j, 0.+0.j])
307
+
308
+ """
309
+ return pu._fromroots(hermline, hermmul, roots)
310
+
311
+
312
+ def hermadd(c1, c2):
313
+ """
314
+ Add one Hermite series to another.
315
+
316
+ Returns the sum of two Hermite series `c1` + `c2`. The arguments
317
+ are sequences of coefficients ordered from lowest order term to
318
+ highest, i.e., [1,2,3] represents the series ``P_0 + 2*P_1 + 3*P_2``.
319
+
320
+ Parameters
321
+ ----------
322
+ c1, c2 : array_like
323
+ 1-D arrays of Hermite series coefficients ordered from low to
324
+ high.
325
+
326
+ Returns
327
+ -------
328
+ out : ndarray
329
+ Array representing the Hermite series of their sum.
330
+
331
+ See Also
332
+ --------
333
+ hermsub, hermmulx, hermmul, hermdiv, hermpow
334
+
335
+ Notes
336
+ -----
337
+ Unlike multiplication, division, etc., the sum of two Hermite series
338
+ is a Hermite series (without having to "reproject" the result onto
339
+ the basis set) so addition, just like that of "standard" polynomials,
340
+ is simply "component-wise."
341
+
342
+ Examples
343
+ --------
344
+ >>> from numpy.polynomial.hermite import hermadd
345
+ >>> hermadd([1, 2, 3], [1, 2, 3, 4])
346
+ array([2., 4., 6., 4.])
347
+
348
+ """
349
+ return pu._add(c1, c2)
350
+
351
+
352
+ def hermsub(c1, c2):
353
+ """
354
+ Subtract one Hermite series from another.
355
+
356
+ Returns the difference of two Hermite series `c1` - `c2`. The
357
+ sequences of coefficients are from lowest order term to highest, i.e.,
358
+ [1,2,3] represents the series ``P_0 + 2*P_1 + 3*P_2``.
359
+
360
+ Parameters
361
+ ----------
362
+ c1, c2 : array_like
363
+ 1-D arrays of Hermite series coefficients ordered from low to
364
+ high.
365
+
366
+ Returns
367
+ -------
368
+ out : ndarray
369
+ Of Hermite series coefficients representing their difference.
370
+
371
+ See Also
372
+ --------
373
+ hermadd, hermmulx, hermmul, hermdiv, hermpow
374
+
375
+ Notes
376
+ -----
377
+ Unlike multiplication, division, etc., the difference of two Hermite
378
+ series is a Hermite series (without having to "reproject" the result
379
+ onto the basis set) so subtraction, just like that of "standard"
380
+ polynomials, is simply "component-wise."
381
+
382
+ Examples
383
+ --------
384
+ >>> from numpy.polynomial.hermite import hermsub
385
+ >>> hermsub([1, 2, 3, 4], [1, 2, 3])
386
+ array([0., 0., 0., 4.])
387
+
388
+ """
389
+ return pu._sub(c1, c2)
390
+
391
+
392
+ def hermmulx(c):
393
+ """Multiply a Hermite series by x.
394
+
395
+ Multiply the Hermite series `c` by x, where x is the independent
396
+ variable.
397
+
398
+
399
+ Parameters
400
+ ----------
401
+ c : array_like
402
+ 1-D array of Hermite series coefficients ordered from low to
403
+ high.
404
+
405
+ Returns
406
+ -------
407
+ out : ndarray
408
+ Array representing the result of the multiplication.
409
+
410
+ See Also
411
+ --------
412
+ hermadd, hermsub, hermmul, hermdiv, hermpow
413
+
414
+ Notes
415
+ -----
416
+ The multiplication uses the recursion relationship for Hermite
417
+ polynomials in the form
418
+
419
+ .. math::
420
+
421
+ xP_i(x) = (P_{i + 1}(x)/2 + i*P_{i - 1}(x))
422
+
423
+ Examples
424
+ --------
425
+ >>> from numpy.polynomial.hermite import hermmulx
426
+ >>> hermmulx([1, 2, 3])
427
+ array([2. , 6.5, 1. , 1.5])
428
+
429
+ """
430
+ # c is a trimmed copy
431
+ [c] = pu.as_series([c])
432
+ # The zero series needs special treatment
433
+ if len(c) == 1 and c[0] == 0:
434
+ return c
435
+
436
+ prd = np.empty(len(c) + 1, dtype=c.dtype)
437
+ prd[0] = c[0] * 0
438
+ prd[1] = c[0] / 2
439
+ for i in range(1, len(c)):
440
+ prd[i + 1] = c[i] / 2
441
+ prd[i - 1] += c[i] * i
442
+ return prd
443
+
444
+
445
+ def hermmul(c1, c2):
446
+ """
447
+ Multiply one Hermite series by another.
448
+
449
+ Returns the product of two Hermite series `c1` * `c2`. The arguments
450
+ are sequences of coefficients, from lowest order "term" to highest,
451
+ e.g., [1,2,3] represents the series ``P_0 + 2*P_1 + 3*P_2``.
452
+
453
+ Parameters
454
+ ----------
455
+ c1, c2 : array_like
456
+ 1-D arrays of Hermite series coefficients ordered from low to
457
+ high.
458
+
459
+ Returns
460
+ -------
461
+ out : ndarray
462
+ Of Hermite series coefficients representing their product.
463
+
464
+ See Also
465
+ --------
466
+ hermadd, hermsub, hermmulx, hermdiv, hermpow
467
+
468
+ Notes
469
+ -----
470
+ In general, the (polynomial) product of two C-series results in terms
471
+ that are not in the Hermite polynomial basis set. Thus, to express
472
+ the product as a Hermite series, it is necessary to "reproject" the
473
+ product onto said basis set, which may produce "unintuitive" (but
474
+ correct) results; see Examples section below.
475
+
476
+ Examples
477
+ --------
478
+ >>> from numpy.polynomial.hermite import hermmul
479
+ >>> hermmul([1, 2, 3], [0, 1, 2])
480
+ array([52., 29., 52., 7., 6.])
481
+
482
+ """
483
+ # s1, s2 are trimmed copies
484
+ [c1, c2] = pu.as_series([c1, c2])
485
+
486
+ if len(c1) > len(c2):
487
+ c = c2
488
+ xs = c1
489
+ else:
490
+ c = c1
491
+ xs = c2
492
+
493
+ if len(c) == 1:
494
+ c0 = c[0] * xs
495
+ c1 = 0
496
+ elif len(c) == 2:
497
+ c0 = c[0] * xs
498
+ c1 = c[1] * xs
499
+ else:
500
+ nd = len(c)
501
+ c0 = c[-2] * xs
502
+ c1 = c[-1] * xs
503
+ for i in range(3, len(c) + 1):
504
+ tmp = c0
505
+ nd = nd - 1
506
+ c0 = hermsub(c[-i] * xs, c1 * (2 * (nd - 1)))
507
+ c1 = hermadd(tmp, hermmulx(c1) * 2)
508
+ return hermadd(c0, hermmulx(c1) * 2)
509
+
510
+
511
+ def hermdiv(c1, c2):
512
+ """
513
+ Divide one Hermite series by another.
514
+
515
+ Returns the quotient-with-remainder of two Hermite series
516
+ `c1` / `c2`. The arguments are sequences of coefficients from lowest
517
+ order "term" to highest, e.g., [1,2,3] represents the series
518
+ ``P_0 + 2*P_1 + 3*P_2``.
519
+
520
+ Parameters
521
+ ----------
522
+ c1, c2 : array_like
523
+ 1-D arrays of Hermite series coefficients ordered from low to
524
+ high.
525
+
526
+ Returns
527
+ -------
528
+ [quo, rem] : ndarrays
529
+ Of Hermite series coefficients representing the quotient and
530
+ remainder.
531
+
532
+ See Also
533
+ --------
534
+ hermadd, hermsub, hermmulx, hermmul, hermpow
535
+
536
+ Notes
537
+ -----
538
+ In general, the (polynomial) division of one Hermite series by another
539
+ results in quotient and remainder terms that are not in the Hermite
540
+ polynomial basis set. Thus, to express these results as a Hermite
541
+ series, it is necessary to "reproject" the results onto the Hermite
542
+ basis set, which may produce "unintuitive" (but correct) results; see
543
+ Examples section below.
544
+
545
+ Examples
546
+ --------
547
+ >>> from numpy.polynomial.hermite import hermdiv
548
+ >>> hermdiv([ 52., 29., 52., 7., 6.], [0, 1, 2])
549
+ (array([1., 2., 3.]), array([0.]))
550
+ >>> hermdiv([ 54., 31., 52., 7., 6.], [0, 1, 2])
551
+ (array([1., 2., 3.]), array([2., 2.]))
552
+ >>> hermdiv([ 53., 30., 52., 7., 6.], [0, 1, 2])
553
+ (array([1., 2., 3.]), array([1., 1.]))
554
+
555
+ """
556
+ return pu._div(hermmul, c1, c2)
557
+
558
+
559
+ def hermpow(c, pow, maxpower=16):
560
+ """Raise a Hermite series to a power.
561
+
562
+ Returns the Hermite series `c` raised to the power `pow`. The
563
+ argument `c` is a sequence of coefficients ordered from low to high.
564
+ i.e., [1,2,3] is the series ``P_0 + 2*P_1 + 3*P_2.``
565
+
566
+ Parameters
567
+ ----------
568
+ c : array_like
569
+ 1-D array of Hermite series coefficients ordered from low to
570
+ high.
571
+ pow : integer
572
+ Power to which the series will be raised
573
+ maxpower : integer, optional
574
+ Maximum power allowed. This is mainly to limit growth of the series
575
+ to unmanageable size. Default is 16
576
+
577
+ Returns
578
+ -------
579
+ coef : ndarray
580
+ Hermite series of power.
581
+
582
+ See Also
583
+ --------
584
+ hermadd, hermsub, hermmulx, hermmul, hermdiv
585
+
586
+ Examples
587
+ --------
588
+ >>> from numpy.polynomial.hermite import hermpow
589
+ >>> hermpow([1, 2, 3], 2)
590
+ array([81., 52., 82., 12., 9.])
591
+
592
+ """
593
+ return pu._pow(hermmul, c, pow, maxpower)
594
+
595
+
596
+ def hermder(c, m=1, scl=1, axis=0):
597
+ """
598
+ Differentiate a Hermite series.
599
+
600
+ Returns the Hermite series coefficients `c` differentiated `m` times
601
+ along `axis`. At each iteration the result is multiplied by `scl` (the
602
+ scaling factor is for use in a linear change of variable). The argument
603
+ `c` is an array of coefficients from low to high degree along each
604
+ axis, e.g., [1,2,3] represents the series ``1*H_0 + 2*H_1 + 3*H_2``
605
+ while [[1,2],[1,2]] represents ``1*H_0(x)*H_0(y) + 1*H_1(x)*H_0(y) +
606
+ 2*H_0(x)*H_1(y) + 2*H_1(x)*H_1(y)`` if axis=0 is ``x`` and axis=1 is
607
+ ``y``.
608
+
609
+ Parameters
610
+ ----------
611
+ c : array_like
612
+ Array of Hermite series coefficients. If `c` is multidimensional the
613
+ different axis correspond to different variables with the degree in
614
+ each axis given by the corresponding index.
615
+ m : int, optional
616
+ Number of derivatives taken, must be non-negative. (Default: 1)
617
+ scl : scalar, optional
618
+ Each differentiation is multiplied by `scl`. The end result is
619
+ multiplication by ``scl**m``. This is for use in a linear change of
620
+ variable. (Default: 1)
621
+ axis : int, optional
622
+ Axis over which the derivative is taken. (Default: 0).
623
+
624
+ Returns
625
+ -------
626
+ der : ndarray
627
+ Hermite series of the derivative.
628
+
629
+ See Also
630
+ --------
631
+ hermint
632
+
633
+ Notes
634
+ -----
635
+ In general, the result of differentiating a Hermite series does not
636
+ resemble the same operation on a power series. Thus the result of this
637
+ function may be "unintuitive," albeit correct; see Examples section
638
+ below.
639
+
640
+ Examples
641
+ --------
642
+ >>> from numpy.polynomial.hermite import hermder
643
+ >>> hermder([ 1. , 0.5, 0.5, 0.5])
644
+ array([1., 2., 3.])
645
+ >>> hermder([-0.5, 1./2., 1./8., 1./12., 1./16.], m=2)
646
+ array([1., 2., 3.])
647
+
648
+ """
649
+ c = np.array(c, ndmin=1, copy=True)
650
+ if c.dtype.char in '?bBhHiIlLqQpP':
651
+ c = c.astype(np.double)
652
+ cnt = pu._as_int(m, "the order of derivation")
653
+ iaxis = pu._as_int(axis, "the axis")
654
+ if cnt < 0:
655
+ raise ValueError("The order of derivation must be non-negative")
656
+ iaxis = np.lib.array_utils.normalize_axis_index(iaxis, c.ndim)
657
+
658
+ if cnt == 0:
659
+ return c
660
+
661
+ c = np.moveaxis(c, iaxis, 0)
662
+ n = len(c)
663
+ if cnt >= n:
664
+ c = c[:1] * 0
665
+ else:
666
+ for i in range(cnt):
667
+ n = n - 1
668
+ c *= scl
669
+ der = np.empty((n,) + c.shape[1:], dtype=c.dtype)
670
+ for j in range(n, 0, -1):
671
+ der[j - 1] = (2 * j) * c[j]
672
+ c = der
673
+ c = np.moveaxis(c, 0, iaxis)
674
+ return c
675
+
676
+
677
+ def hermint(c, m=1, k=[], lbnd=0, scl=1, axis=0):
678
+ """
679
+ Integrate a Hermite series.
680
+
681
+ Returns the Hermite series coefficients `c` integrated `m` times from
682
+ `lbnd` along `axis`. At each iteration the resulting series is
683
+ **multiplied** by `scl` and an integration constant, `k`, is added.
684
+ The scaling factor is for use in a linear change of variable. ("Buyer
685
+ beware": note that, depending on what one is doing, one may want `scl`
686
+ to be the reciprocal of what one might expect; for more information,
687
+ see the Notes section below.) The argument `c` is an array of
688
+ coefficients from low to high degree along each axis, e.g., [1,2,3]
689
+ represents the series ``H_0 + 2*H_1 + 3*H_2`` while [[1,2],[1,2]]
690
+ represents ``1*H_0(x)*H_0(y) + 1*H_1(x)*H_0(y) + 2*H_0(x)*H_1(y) +
691
+ 2*H_1(x)*H_1(y)`` if axis=0 is ``x`` and axis=1 is ``y``.
692
+
693
+ Parameters
694
+ ----------
695
+ c : array_like
696
+ Array of Hermite series coefficients. If c is multidimensional the
697
+ different axis correspond to different variables with the degree in
698
+ each axis given by the corresponding index.
699
+ m : int, optional
700
+ Order of integration, must be positive. (Default: 1)
701
+ k : {[], list, scalar}, optional
702
+ Integration constant(s). The value of the first integral at
703
+ ``lbnd`` is the first value in the list, the value of the second
704
+ integral at ``lbnd`` is the second value, etc. If ``k == []`` (the
705
+ default), all constants are set to zero. If ``m == 1``, a single
706
+ scalar can be given instead of a list.
707
+ lbnd : scalar, optional
708
+ The lower bound of the integral. (Default: 0)
709
+ scl : scalar, optional
710
+ Following each integration the result is *multiplied* by `scl`
711
+ before the integration constant is added. (Default: 1)
712
+ axis : int, optional
713
+ Axis over which the integral is taken. (Default: 0).
714
+
715
+ Returns
716
+ -------
717
+ S : ndarray
718
+ Hermite series coefficients of the integral.
719
+
720
+ Raises
721
+ ------
722
+ ValueError
723
+ If ``m < 0``, ``len(k) > m``, ``np.ndim(lbnd) != 0``, or
724
+ ``np.ndim(scl) != 0``.
725
+
726
+ See Also
727
+ --------
728
+ hermder
729
+
730
+ Notes
731
+ -----
732
+ Note that the result of each integration is *multiplied* by `scl`.
733
+ Why is this important to note? Say one is making a linear change of
734
+ variable :math:`u = ax + b` in an integral relative to `x`. Then
735
+ :math:`dx = du/a`, so one will need to set `scl` equal to
736
+ :math:`1/a` - perhaps not what one would have first thought.
737
+
738
+ Also note that, in general, the result of integrating a C-series needs
739
+ to be "reprojected" onto the C-series basis set. Thus, typically,
740
+ the result of this function is "unintuitive," albeit correct; see
741
+ Examples section below.
742
+
743
+ Examples
744
+ --------
745
+ >>> from numpy.polynomial.hermite import hermint
746
+ >>> hermint([1,2,3]) # integrate once, value 0 at 0.
747
+ array([1. , 0.5, 0.5, 0.5])
748
+ >>> hermint([1,2,3], m=2) # integrate twice, value & deriv 0 at 0
749
+ array([-0.5 , 0.5 , 0.125 , 0.08333333, 0.0625 ]) # may vary
750
+ >>> hermint([1,2,3], k=1) # integrate once, value 1 at 0.
751
+ array([2. , 0.5, 0.5, 0.5])
752
+ >>> hermint([1,2,3], lbnd=-1) # integrate once, value 0 at -1
753
+ array([-2. , 0.5, 0.5, 0.5])
754
+ >>> hermint([1,2,3], m=2, k=[1,2], lbnd=-1)
755
+ array([ 1.66666667, -0.5 , 0.125 , 0.08333333, 0.0625 ]) # may vary
756
+
757
+ """
758
+ c = np.array(c, ndmin=1, copy=True)
759
+ if c.dtype.char in '?bBhHiIlLqQpP':
760
+ c = c.astype(np.double)
761
+ if not np.iterable(k):
762
+ k = [k]
763
+ cnt = pu._as_int(m, "the order of integration")
764
+ iaxis = pu._as_int(axis, "the axis")
765
+ if cnt < 0:
766
+ raise ValueError("The order of integration must be non-negative")
767
+ if len(k) > cnt:
768
+ raise ValueError("Too many integration constants")
769
+ if np.ndim(lbnd) != 0:
770
+ raise ValueError("lbnd must be a scalar.")
771
+ if np.ndim(scl) != 0:
772
+ raise ValueError("scl must be a scalar.")
773
+ iaxis = np.lib.array_utils.normalize_axis_index(iaxis, c.ndim)
774
+
775
+ if cnt == 0:
776
+ return c
777
+
778
+ c = np.moveaxis(c, iaxis, 0)
779
+ k = list(k) + [0] * (cnt - len(k))
780
+ for i in range(cnt):
781
+ n = len(c)
782
+ c *= scl
783
+ if n == 1 and np.all(c[0] == 0):
784
+ c[0] += k[i]
785
+ else:
786
+ tmp = np.empty((n + 1,) + c.shape[1:], dtype=c.dtype)
787
+ tmp[0] = c[0] * 0
788
+ tmp[1] = c[0] / 2
789
+ for j in range(1, n):
790
+ tmp[j + 1] = c[j] / (2 * (j + 1))
791
+ tmp[0] += k[i] - hermval(lbnd, tmp)
792
+ c = tmp
793
+ c = np.moveaxis(c, 0, iaxis)
794
+ return c
795
+
796
+
797
+ def hermval(x, c, tensor=True):
798
+ """
799
+ Evaluate a Hermite series at points x.
800
+
801
+ If `c` is of length ``n + 1``, this function returns the value:
802
+
803
+ .. math:: p(x) = c_0 * H_0(x) + c_1 * H_1(x) + ... + c_n * H_n(x)
804
+
805
+ The parameter `x` is converted to an array only if it is a tuple or a
806
+ list, otherwise it is treated as a scalar. In either case, either `x`
807
+ or its elements must support multiplication and addition both with
808
+ themselves and with the elements of `c`.
809
+
810
+ If `c` is a 1-D array, then ``p(x)`` will have the same shape as `x`. If
811
+ `c` is multidimensional, then the shape of the result depends on the
812
+ value of `tensor`. If `tensor` is true the shape will be c.shape[1:] +
813
+ x.shape. If `tensor` is false the shape will be c.shape[1:]. Note that
814
+ scalars have shape (,).
815
+
816
+ Trailing zeros in the coefficients will be used in the evaluation, so
817
+ they should be avoided if efficiency is a concern.
818
+
819
+ Parameters
820
+ ----------
821
+ x : array_like, compatible object
822
+ If `x` is a list or tuple, it is converted to an ndarray, otherwise
823
+ it is left unchanged and treated as a scalar. In either case, `x`
824
+ or its elements must support addition and multiplication with
825
+ themselves and with the elements of `c`.
826
+ c : array_like
827
+ Array of coefficients ordered so that the coefficients for terms of
828
+ degree n are contained in c[n]. If `c` is multidimensional the
829
+ remaining indices enumerate multiple polynomials. In the two
830
+ dimensional case the coefficients may be thought of as stored in
831
+ the columns of `c`.
832
+ tensor : boolean, optional
833
+ If True, the shape of the coefficient array is extended with ones
834
+ on the right, one for each dimension of `x`. Scalars have dimension 0
835
+ for this action. The result is that every column of coefficients in
836
+ `c` is evaluated for every element of `x`. If False, `x` is broadcast
837
+ over the columns of `c` for the evaluation. This keyword is useful
838
+ when `c` is multidimensional. The default value is True.
839
+
840
+ Returns
841
+ -------
842
+ values : ndarray, algebra_like
843
+ The shape of the return value is described above.
844
+
845
+ See Also
846
+ --------
847
+ hermval2d, hermgrid2d, hermval3d, hermgrid3d
848
+
849
+ Notes
850
+ -----
851
+ The evaluation uses Clenshaw recursion, aka synthetic division.
852
+
853
+ Examples
854
+ --------
855
+ >>> from numpy.polynomial.hermite import hermval
856
+ >>> coef = [1,2,3]
857
+ >>> hermval(1, coef)
858
+ 11.0
859
+ >>> hermval([[1,2],[3,4]], coef)
860
+ array([[ 11., 51.],
861
+ [115., 203.]])
862
+
863
+ """
864
+ c = np.array(c, ndmin=1, copy=None)
865
+ if c.dtype.char in '?bBhHiIlLqQpP':
866
+ c = c.astype(np.double)
867
+ if isinstance(x, (tuple, list)):
868
+ x = np.asarray(x)
869
+ if isinstance(x, np.ndarray) and tensor:
870
+ c = c.reshape(c.shape + (1,) * x.ndim)
871
+
872
+ x2 = x * 2
873
+ if len(c) == 1:
874
+ c0 = c[0]
875
+ c1 = 0
876
+ elif len(c) == 2:
877
+ c0 = c[0]
878
+ c1 = c[1]
879
+ else:
880
+ nd = len(c)
881
+ c0 = c[-2]
882
+ c1 = c[-1]
883
+ for i in range(3, len(c) + 1):
884
+ tmp = c0
885
+ nd = nd - 1
886
+ c0 = c[-i] - c1 * (2 * (nd - 1))
887
+ c1 = tmp + c1 * x2
888
+ return c0 + c1 * x2
889
+
890
+
891
+ def hermval2d(x, y, c):
892
+ """
893
+ Evaluate a 2-D Hermite series at points (x, y).
894
+
895
+ This function returns the values:
896
+
897
+ .. math:: p(x,y) = \\sum_{i,j} c_{i,j} * H_i(x) * H_j(y)
898
+
899
+ The parameters `x` and `y` are converted to arrays only if they are
900
+ tuples or a lists, otherwise they are treated as a scalars and they
901
+ must have the same shape after conversion. In either case, either `x`
902
+ and `y` or their elements must support multiplication and addition both
903
+ with themselves and with the elements of `c`.
904
+
905
+ If `c` is a 1-D array a one is implicitly appended to its shape to make
906
+ it 2-D. The shape of the result will be c.shape[2:] + x.shape.
907
+
908
+ Parameters
909
+ ----------
910
+ x, y : array_like, compatible objects
911
+ The two dimensional series is evaluated at the points ``(x, y)``,
912
+ where `x` and `y` must have the same shape. If `x` or `y` is a list
913
+ or tuple, it is first converted to an ndarray, otherwise it is left
914
+ unchanged and if it isn't an ndarray it is treated as a scalar.
915
+ c : array_like
916
+ Array of coefficients ordered so that the coefficient of the term
917
+ of multi-degree i,j is contained in ``c[i,j]``. If `c` has
918
+ dimension greater than two the remaining indices enumerate multiple
919
+ sets of coefficients.
920
+
921
+ Returns
922
+ -------
923
+ values : ndarray, compatible object
924
+ The values of the two dimensional polynomial at points formed with
925
+ pairs of corresponding values from `x` and `y`.
926
+
927
+ See Also
928
+ --------
929
+ hermval, hermgrid2d, hermval3d, hermgrid3d
930
+
931
+ Examples
932
+ --------
933
+ >>> from numpy.polynomial.hermite import hermval2d
934
+ >>> x = [1, 2]
935
+ >>> y = [4, 5]
936
+ >>> c = [[1, 2, 3], [4, 5, 6]]
937
+ >>> hermval2d(x, y, c)
938
+ array([1035., 2883.])
939
+
940
+ """
941
+ return pu._valnd(hermval, c, x, y)
942
+
943
+
944
+ def hermgrid2d(x, y, c):
945
+ """
946
+ Evaluate a 2-D Hermite series on the Cartesian product of x and y.
947
+
948
+ This function returns the values:
949
+
950
+ .. math:: p(a,b) = \\sum_{i,j} c_{i,j} * H_i(a) * H_j(b)
951
+
952
+ where the points ``(a, b)`` consist of all pairs formed by taking
953
+ `a` from `x` and `b` from `y`. The resulting points form a grid with
954
+ `x` in the first dimension and `y` in the second.
955
+
956
+ The parameters `x` and `y` are converted to arrays only if they are
957
+ tuples or a lists, otherwise they are treated as a scalars. In either
958
+ case, either `x` and `y` or their elements must support multiplication
959
+ and addition both with themselves and with the elements of `c`.
960
+
961
+ If `c` has fewer than two dimensions, ones are implicitly appended to
962
+ its shape to make it 2-D. The shape of the result will be c.shape[2:] +
963
+ x.shape.
964
+
965
+ Parameters
966
+ ----------
967
+ x, y : array_like, compatible objects
968
+ The two dimensional series is evaluated at the points in the
969
+ Cartesian product of `x` and `y`. If `x` or `y` is a list or
970
+ tuple, it is first converted to an ndarray, otherwise it is left
971
+ unchanged and, if it isn't an ndarray, it is treated as a scalar.
972
+ c : array_like
973
+ Array of coefficients ordered so that the coefficients for terms of
974
+ degree i,j are contained in ``c[i,j]``. If `c` has dimension
975
+ greater than two the remaining indices enumerate multiple sets of
976
+ coefficients.
977
+
978
+ Returns
979
+ -------
980
+ values : ndarray, compatible object
981
+ The values of the two dimensional polynomial at points in the Cartesian
982
+ product of `x` and `y`.
983
+
984
+ See Also
985
+ --------
986
+ hermval, hermval2d, hermval3d, hermgrid3d
987
+
988
+ Examples
989
+ --------
990
+ >>> from numpy.polynomial.hermite import hermgrid2d
991
+ >>> x = [1, 2, 3]
992
+ >>> y = [4, 5]
993
+ >>> c = [[1, 2, 3], [4, 5, 6]]
994
+ >>> hermgrid2d(x, y, c)
995
+ array([[1035., 1599.],
996
+ [1867., 2883.],
997
+ [2699., 4167.]])
998
+
999
+ """
1000
+ return pu._gridnd(hermval, c, x, y)
1001
+
1002
+
1003
+ def hermval3d(x, y, z, c):
1004
+ """
1005
+ Evaluate a 3-D Hermite series at points (x, y, z).
1006
+
1007
+ This function returns the values:
1008
+
1009
+ .. math:: p(x,y,z) = \\sum_{i,j,k} c_{i,j,k} * H_i(x) * H_j(y) * H_k(z)
1010
+
1011
+ The parameters `x`, `y`, and `z` are converted to arrays only if
1012
+ they are tuples or a lists, otherwise they are treated as a scalars and
1013
+ they must have the same shape after conversion. In either case, either
1014
+ `x`, `y`, and `z` or their elements must support multiplication and
1015
+ addition both with themselves and with the elements of `c`.
1016
+
1017
+ If `c` has fewer than 3 dimensions, ones are implicitly appended to its
1018
+ shape to make it 3-D. The shape of the result will be c.shape[3:] +
1019
+ x.shape.
1020
+
1021
+ Parameters
1022
+ ----------
1023
+ x, y, z : array_like, compatible object
1024
+ The three dimensional series is evaluated at the points
1025
+ ``(x, y, z)``, where `x`, `y`, and `z` must have the same shape. If
1026
+ any of `x`, `y`, or `z` is a list or tuple, it is first converted
1027
+ to an ndarray, otherwise it is left unchanged and if it isn't an
1028
+ ndarray it is treated as a scalar.
1029
+ c : array_like
1030
+ Array of coefficients ordered so that the coefficient of the term of
1031
+ multi-degree i,j,k is contained in ``c[i,j,k]``. If `c` has dimension
1032
+ greater than 3 the remaining indices enumerate multiple sets of
1033
+ coefficients.
1034
+
1035
+ Returns
1036
+ -------
1037
+ values : ndarray, compatible object
1038
+ The values of the multidimensional polynomial on points formed with
1039
+ triples of corresponding values from `x`, `y`, and `z`.
1040
+
1041
+ See Also
1042
+ --------
1043
+ hermval, hermval2d, hermgrid2d, hermgrid3d
1044
+
1045
+ Examples
1046
+ --------
1047
+ >>> from numpy.polynomial.hermite import hermval3d
1048
+ >>> x = [1, 2]
1049
+ >>> y = [4, 5]
1050
+ >>> z = [6, 7]
1051
+ >>> c = [[[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [10, 11, 12]]]
1052
+ >>> hermval3d(x, y, z, c)
1053
+ array([ 40077., 120131.])
1054
+
1055
+ """
1056
+ return pu._valnd(hermval, c, x, y, z)
1057
+
1058
+
1059
+ def hermgrid3d(x, y, z, c):
1060
+ """
1061
+ Evaluate a 3-D Hermite series on the Cartesian product of x, y, and z.
1062
+
1063
+ This function returns the values:
1064
+
1065
+ .. math:: p(a,b,c) = \\sum_{i,j,k} c_{i,j,k} * H_i(a) * H_j(b) * H_k(c)
1066
+
1067
+ where the points ``(a, b, c)`` consist of all triples formed by taking
1068
+ `a` from `x`, `b` from `y`, and `c` from `z`. The resulting points form
1069
+ a grid with `x` in the first dimension, `y` in the second, and `z` in
1070
+ the third.
1071
+
1072
+ The parameters `x`, `y`, and `z` are converted to arrays only if they
1073
+ are tuples or a lists, otherwise they are treated as a scalars. In
1074
+ either case, either `x`, `y`, and `z` or their elements must support
1075
+ multiplication and addition both with themselves and with the elements
1076
+ of `c`.
1077
+
1078
+ If `c` has fewer than three dimensions, ones are implicitly appended to
1079
+ its shape to make it 3-D. The shape of the result will be c.shape[3:] +
1080
+ x.shape + y.shape + z.shape.
1081
+
1082
+ Parameters
1083
+ ----------
1084
+ x, y, z : array_like, compatible objects
1085
+ The three dimensional series is evaluated at the points in the
1086
+ Cartesian product of `x`, `y`, and `z`. If `x`, `y`, or `z` is a
1087
+ list or tuple, it is first converted to an ndarray, otherwise it is
1088
+ left unchanged and, if it isn't an ndarray, it is treated as a
1089
+ scalar.
1090
+ c : array_like
1091
+ Array of coefficients ordered so that the coefficients for terms of
1092
+ degree i,j are contained in ``c[i,j]``. If `c` has dimension
1093
+ greater than two the remaining indices enumerate multiple sets of
1094
+ coefficients.
1095
+
1096
+ Returns
1097
+ -------
1098
+ values : ndarray, compatible object
1099
+ The values of the two dimensional polynomial at points in the Cartesian
1100
+ product of `x` and `y`.
1101
+
1102
+ See Also
1103
+ --------
1104
+ hermval, hermval2d, hermgrid2d, hermval3d
1105
+
1106
+ Examples
1107
+ --------
1108
+ >>> from numpy.polynomial.hermite import hermgrid3d
1109
+ >>> x = [1, 2]
1110
+ >>> y = [4, 5]
1111
+ >>> z = [6, 7]
1112
+ >>> c = [[[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [10, 11, 12]]]
1113
+ >>> hermgrid3d(x, y, z, c)
1114
+ array([[[ 40077., 54117.],
1115
+ [ 49293., 66561.]],
1116
+ [[ 72375., 97719.],
1117
+ [ 88975., 120131.]]])
1118
+
1119
+ """
1120
+ return pu._gridnd(hermval, c, x, y, z)
1121
+
1122
+
1123
+ def hermvander(x, deg):
1124
+ """Pseudo-Vandermonde matrix of given degree.
1125
+
1126
+ Returns the pseudo-Vandermonde matrix of degree `deg` and sample points
1127
+ `x`. The pseudo-Vandermonde matrix is defined by
1128
+
1129
+ .. math:: V[..., i] = H_i(x),
1130
+
1131
+ where ``0 <= i <= deg``. The leading indices of `V` index the elements of
1132
+ `x` and the last index is the degree of the Hermite polynomial.
1133
+
1134
+ If `c` is a 1-D array of coefficients of length ``n + 1`` and `V` is the
1135
+ array ``V = hermvander(x, n)``, then ``np.dot(V, c)`` and
1136
+ ``hermval(x, c)`` are the same up to roundoff. This equivalence is
1137
+ useful both for least squares fitting and for the evaluation of a large
1138
+ number of Hermite series of the same degree and sample points.
1139
+
1140
+ Parameters
1141
+ ----------
1142
+ x : array_like
1143
+ Array of points. The dtype is converted to float64 or complex128
1144
+ depending on whether any of the elements are complex. If `x` is
1145
+ scalar it is converted to a 1-D array.
1146
+ deg : int
1147
+ Degree of the resulting matrix.
1148
+
1149
+ Returns
1150
+ -------
1151
+ vander : ndarray
1152
+ The pseudo-Vandermonde matrix. The shape of the returned matrix is
1153
+ ``x.shape + (deg + 1,)``, where The last index is the degree of the
1154
+ corresponding Hermite polynomial. The dtype will be the same as
1155
+ the converted `x`.
1156
+
1157
+ Examples
1158
+ --------
1159
+ >>> import numpy as np
1160
+ >>> from numpy.polynomial.hermite import hermvander
1161
+ >>> x = np.array([-1, 0, 1])
1162
+ >>> hermvander(x, 3)
1163
+ array([[ 1., -2., 2., 4.],
1164
+ [ 1., 0., -2., -0.],
1165
+ [ 1., 2., 2., -4.]])
1166
+
1167
+ """
1168
+ ideg = pu._as_int(deg, "deg")
1169
+ if ideg < 0:
1170
+ raise ValueError("deg must be non-negative")
1171
+
1172
+ x = np.array(x, copy=None, ndmin=1) + 0.0
1173
+ dims = (ideg + 1,) + x.shape
1174
+ dtyp = x.dtype
1175
+ v = np.empty(dims, dtype=dtyp)
1176
+ v[0] = x * 0 + 1
1177
+ if ideg > 0:
1178
+ x2 = x * 2
1179
+ v[1] = x2
1180
+ for i in range(2, ideg + 1):
1181
+ v[i] = (v[i - 1] * x2 - v[i - 2] * (2 * (i - 1)))
1182
+ return np.moveaxis(v, 0, -1)
1183
+
1184
+
1185
+ def hermvander2d(x, y, deg):
1186
+ """Pseudo-Vandermonde matrix of given degrees.
1187
+
1188
+ Returns the pseudo-Vandermonde matrix of degrees `deg` and sample
1189
+ points ``(x, y)``. The pseudo-Vandermonde matrix is defined by
1190
+
1191
+ .. math:: V[..., (deg[1] + 1)*i + j] = H_i(x) * H_j(y),
1192
+
1193
+ where ``0 <= i <= deg[0]`` and ``0 <= j <= deg[1]``. The leading indices of
1194
+ `V` index the points ``(x, y)`` and the last index encodes the degrees of
1195
+ the Hermite polynomials.
1196
+
1197
+ If ``V = hermvander2d(x, y, [xdeg, ydeg])``, then the columns of `V`
1198
+ correspond to the elements of a 2-D coefficient array `c` of shape
1199
+ (xdeg + 1, ydeg + 1) in the order
1200
+
1201
+ .. math:: c_{00}, c_{01}, c_{02} ... , c_{10}, c_{11}, c_{12} ...
1202
+
1203
+ and ``np.dot(V, c.flat)`` and ``hermval2d(x, y, c)`` will be the same
1204
+ up to roundoff. This equivalence is useful both for least squares
1205
+ fitting and for the evaluation of a large number of 2-D Hermite
1206
+ series of the same degrees and sample points.
1207
+
1208
+ Parameters
1209
+ ----------
1210
+ x, y : array_like
1211
+ Arrays of point coordinates, all of the same shape. The dtypes
1212
+ will be converted to either float64 or complex128 depending on
1213
+ whether any of the elements are complex. Scalars are converted to 1-D
1214
+ arrays.
1215
+ deg : list of ints
1216
+ List of maximum degrees of the form [x_deg, y_deg].
1217
+
1218
+ Returns
1219
+ -------
1220
+ vander2d : ndarray
1221
+ The shape of the returned matrix is ``x.shape + (order,)``, where
1222
+ :math:`order = (deg[0]+1)*(deg[1]+1)`. The dtype will be the same
1223
+ as the converted `x` and `y`.
1224
+
1225
+ See Also
1226
+ --------
1227
+ hermvander, hermvander3d, hermval2d, hermval3d
1228
+
1229
+ Examples
1230
+ --------
1231
+ >>> import numpy as np
1232
+ >>> from numpy.polynomial.hermite import hermvander2d
1233
+ >>> x = np.array([-1, 0, 1])
1234
+ >>> y = np.array([-1, 0, 1])
1235
+ >>> hermvander2d(x, y, [2, 2])
1236
+ array([[ 1., -2., 2., -2., 4., -4., 2., -4., 4.],
1237
+ [ 1., 0., -2., 0., 0., -0., -2., -0., 4.],
1238
+ [ 1., 2., 2., 2., 4., 4., 2., 4., 4.]])
1239
+
1240
+ """
1241
+ return pu._vander_nd_flat((hermvander, hermvander), (x, y), deg)
1242
+
1243
+
1244
+ def hermvander3d(x, y, z, deg):
1245
+ """Pseudo-Vandermonde matrix of given degrees.
1246
+
1247
+ Returns the pseudo-Vandermonde matrix of degrees `deg` and sample
1248
+ points ``(x, y, z)``. If `l`, `m`, `n` are the given degrees in `x`, `y`, `z`,
1249
+ then The pseudo-Vandermonde matrix is defined by
1250
+
1251
+ .. math:: V[..., (m+1)(n+1)i + (n+1)j + k] = H_i(x)*H_j(y)*H_k(z),
1252
+
1253
+ where ``0 <= i <= l``, ``0 <= j <= m``, and ``0 <= j <= n``. The leading
1254
+ indices of `V` index the points ``(x, y, z)`` and the last index encodes
1255
+ the degrees of the Hermite polynomials.
1256
+
1257
+ If ``V = hermvander3d(x, y, z, [xdeg, ydeg, zdeg])``, then the columns
1258
+ of `V` correspond to the elements of a 3-D coefficient array `c` of
1259
+ shape (xdeg + 1, ydeg + 1, zdeg + 1) in the order
1260
+
1261
+ .. math:: c_{000}, c_{001}, c_{002},... , c_{010}, c_{011}, c_{012},...
1262
+
1263
+ and ``np.dot(V, c.flat)`` and ``hermval3d(x, y, z, c)`` will be the
1264
+ same up to roundoff. This equivalence is useful both for least squares
1265
+ fitting and for the evaluation of a large number of 3-D Hermite
1266
+ series of the same degrees and sample points.
1267
+
1268
+ Parameters
1269
+ ----------
1270
+ x, y, z : array_like
1271
+ Arrays of point coordinates, all of the same shape. The dtypes will
1272
+ be converted to either float64 or complex128 depending on whether
1273
+ any of the elements are complex. Scalars are converted to 1-D
1274
+ arrays.
1275
+ deg : list of ints
1276
+ List of maximum degrees of the form [x_deg, y_deg, z_deg].
1277
+
1278
+ Returns
1279
+ -------
1280
+ vander3d : ndarray
1281
+ The shape of the returned matrix is ``x.shape + (order,)``, where
1282
+ :math:`order = (deg[0]+1)*(deg[1]+1)*(deg[2]+1)`. The dtype will
1283
+ be the same as the converted `x`, `y`, and `z`.
1284
+
1285
+ See Also
1286
+ --------
1287
+ hermvander, hermvander3d, hermval2d, hermval3d
1288
+
1289
+ Examples
1290
+ --------
1291
+ >>> from numpy.polynomial.hermite import hermvander3d
1292
+ >>> x = np.array([-1, 0, 1])
1293
+ >>> y = np.array([-1, 0, 1])
1294
+ >>> z = np.array([-1, 0, 1])
1295
+ >>> hermvander3d(x, y, z, [0, 1, 2])
1296
+ array([[ 1., -2., 2., -2., 4., -4.],
1297
+ [ 1., 0., -2., 0., 0., -0.],
1298
+ [ 1., 2., 2., 2., 4., 4.]])
1299
+
1300
+ """
1301
+ return pu._vander_nd_flat((hermvander, hermvander, hermvander), (x, y, z), deg)
1302
+
1303
+
1304
+ def hermfit(x, y, deg, rcond=None, full=False, w=None):
1305
+ """
1306
+ Least squares fit of Hermite series to data.
1307
+
1308
+ Return the coefficients of a Hermite series of degree `deg` that is the
1309
+ least squares fit to the data values `y` given at points `x`. If `y` is
1310
+ 1-D the returned coefficients will also be 1-D. If `y` is 2-D multiple
1311
+ fits are done, one for each column of `y`, and the resulting
1312
+ coefficients are stored in the corresponding columns of a 2-D return.
1313
+ The fitted polynomial(s) are in the form
1314
+
1315
+ .. math:: p(x) = c_0 + c_1 * H_1(x) + ... + c_n * H_n(x),
1316
+
1317
+ where `n` is `deg`.
1318
+
1319
+ Parameters
1320
+ ----------
1321
+ x : array_like, shape (M,)
1322
+ x-coordinates of the M sample points ``(x[i], y[i])``.
1323
+ y : array_like, shape (M,) or (M, K)
1324
+ y-coordinates of the sample points. Several data sets of sample
1325
+ points sharing the same x-coordinates can be fitted at once by
1326
+ passing in a 2D-array that contains one dataset per column.
1327
+ deg : int or 1-D array_like
1328
+ Degree(s) of the fitting polynomials. If `deg` is a single integer
1329
+ all terms up to and including the `deg`'th term are included in the
1330
+ fit. For NumPy versions >= 1.11.0 a list of integers specifying the
1331
+ degrees of the terms to include may be used instead.
1332
+ rcond : float, optional
1333
+ Relative condition number of the fit. Singular values smaller than
1334
+ this relative to the largest singular value will be ignored. The
1335
+ default value is len(x)*eps, where eps is the relative precision of
1336
+ the float type, about 2e-16 in most cases.
1337
+ full : bool, optional
1338
+ Switch determining nature of return value. When it is False (the
1339
+ default) just the coefficients are returned, when True diagnostic
1340
+ information from the singular value decomposition is also returned.
1341
+ w : array_like, shape (`M`,), optional
1342
+ Weights. If not None, the weight ``w[i]`` applies to the unsquared
1343
+ residual ``y[i] - y_hat[i]`` at ``x[i]``. Ideally the weights are
1344
+ chosen so that the errors of the products ``w[i]*y[i]`` all have the
1345
+ same variance. When using inverse-variance weighting, use
1346
+ ``w[i] = 1/sigma(y[i])``. The default value is None.
1347
+
1348
+ Returns
1349
+ -------
1350
+ coef : ndarray, shape (M,) or (M, K)
1351
+ Hermite coefficients ordered from low to high. If `y` was 2-D,
1352
+ the coefficients for the data in column k of `y` are in column
1353
+ `k`.
1354
+
1355
+ [residuals, rank, singular_values, rcond] : list
1356
+ These values are only returned if ``full == True``
1357
+
1358
+ - residuals -- sum of squared residuals of the least squares fit
1359
+ - rank -- the numerical rank of the scaled Vandermonde matrix
1360
+ - singular_values -- singular values of the scaled Vandermonde matrix
1361
+ - rcond -- value of `rcond`.
1362
+
1363
+ For more details, see `numpy.linalg.lstsq`.
1364
+
1365
+ Warns
1366
+ -----
1367
+ RankWarning
1368
+ The rank of the coefficient matrix in the least-squares fit is
1369
+ deficient. The warning is only raised if ``full == False``. The
1370
+ warnings can be turned off by
1371
+
1372
+ >>> import warnings
1373
+ >>> warnings.simplefilter('ignore', np.exceptions.RankWarning)
1374
+
1375
+ See Also
1376
+ --------
1377
+ numpy.polynomial.chebyshev.chebfit
1378
+ numpy.polynomial.legendre.legfit
1379
+ numpy.polynomial.laguerre.lagfit
1380
+ numpy.polynomial.polynomial.polyfit
1381
+ numpy.polynomial.hermite_e.hermefit
1382
+ hermval : Evaluates a Hermite series.
1383
+ hermvander : Vandermonde matrix of Hermite series.
1384
+ hermweight : Hermite weight function
1385
+ numpy.linalg.lstsq : Computes a least-squares fit from the matrix.
1386
+ scipy.interpolate.UnivariateSpline : Computes spline fits.
1387
+
1388
+ Notes
1389
+ -----
1390
+ The solution is the coefficients of the Hermite series `p` that
1391
+ minimizes the sum of the weighted squared errors
1392
+
1393
+ .. math:: E = \\sum_j w_j^2 * |y_j - p(x_j)|^2,
1394
+
1395
+ where the :math:`w_j` are the weights. This problem is solved by
1396
+ setting up the (typically) overdetermined matrix equation
1397
+
1398
+ .. math:: V(x) * c = w * y,
1399
+
1400
+ where `V` is the weighted pseudo Vandermonde matrix of `x`, `c` are the
1401
+ coefficients to be solved for, `w` are the weights, `y` are the
1402
+ observed values. This equation is then solved using the singular value
1403
+ decomposition of `V`.
1404
+
1405
+ If some of the singular values of `V` are so small that they are
1406
+ neglected, then a `~exceptions.RankWarning` will be issued. This means that
1407
+ the coefficient values may be poorly determined. Using a lower order fit
1408
+ will usually get rid of the warning. The `rcond` parameter can also be
1409
+ set to a value smaller than its default, but the resulting fit may be
1410
+ spurious and have large contributions from roundoff error.
1411
+
1412
+ Fits using Hermite series are probably most useful when the data can be
1413
+ approximated by ``sqrt(w(x)) * p(x)``, where ``w(x)`` is the Hermite
1414
+ weight. In that case the weight ``sqrt(w(x[i]))`` should be used
1415
+ together with data values ``y[i]/sqrt(w(x[i]))``. The weight function is
1416
+ available as `hermweight`.
1417
+
1418
+ References
1419
+ ----------
1420
+ .. [1] Wikipedia, "Curve fitting",
1421
+ https://en.wikipedia.org/wiki/Curve_fitting
1422
+
1423
+ Examples
1424
+ --------
1425
+ >>> import numpy as np
1426
+ >>> from numpy.polynomial.hermite import hermfit, hermval
1427
+ >>> x = np.linspace(-10, 10)
1428
+ >>> rng = np.random.default_rng()
1429
+ >>> err = rng.normal(scale=1./10, size=len(x))
1430
+ >>> y = hermval(x, [1, 2, 3]) + err
1431
+ >>> hermfit(x, y, 2)
1432
+ array([1.02294967, 2.00016403, 2.99994614]) # may vary
1433
+
1434
+ """
1435
+ return pu._fit(hermvander, x, y, deg, rcond, full, w)
1436
+
1437
+
1438
+ def hermcompanion(c):
1439
+ """Return the scaled companion matrix of c.
1440
+
1441
+ The basis polynomials are scaled so that the companion matrix is
1442
+ symmetric when `c` is a Hermite basis polynomial. This provides
1443
+ better eigenvalue estimates than the unscaled case and for basis
1444
+ polynomials the eigenvalues are guaranteed to be real if
1445
+ `numpy.linalg.eigvalsh` is used to obtain them.
1446
+
1447
+ Parameters
1448
+ ----------
1449
+ c : array_like
1450
+ 1-D array of Hermite series coefficients ordered from low to high
1451
+ degree.
1452
+
1453
+ Returns
1454
+ -------
1455
+ mat : ndarray
1456
+ Scaled companion matrix of dimensions (deg, deg).
1457
+
1458
+ Examples
1459
+ --------
1460
+ >>> from numpy.polynomial.hermite import hermcompanion
1461
+ >>> hermcompanion([1, 0, 1])
1462
+ array([[0. , 0.35355339],
1463
+ [0.70710678, 0. ]])
1464
+
1465
+ """
1466
+ # c is a trimmed copy
1467
+ [c] = pu.as_series([c])
1468
+ if len(c) < 2:
1469
+ raise ValueError('Series must have maximum degree of at least 1.')
1470
+ if len(c) == 2:
1471
+ return np.array([[-.5 * c[0] / c[1]]])
1472
+
1473
+ n = len(c) - 1
1474
+ mat = np.zeros((n, n), dtype=c.dtype)
1475
+ scl = np.hstack((1., 1. / np.sqrt(2. * np.arange(n - 1, 0, -1))))
1476
+ scl = np.multiply.accumulate(scl)[::-1]
1477
+ top = mat.reshape(-1)[1::n + 1]
1478
+ bot = mat.reshape(-1)[n::n + 1]
1479
+ top[...] = np.sqrt(.5 * np.arange(1, n))
1480
+ bot[...] = top
1481
+ mat[:, -1] -= scl * c[:-1] / (2.0 * c[-1])
1482
+ return mat
1483
+
1484
+
1485
+ def hermroots(c):
1486
+ """
1487
+ Compute the roots of a Hermite series.
1488
+
1489
+ Return the roots (a.k.a. "zeros") of the polynomial
1490
+
1491
+ .. math:: p(x) = \\sum_i c[i] * H_i(x).
1492
+
1493
+ Parameters
1494
+ ----------
1495
+ c : 1-D array_like
1496
+ 1-D array of coefficients.
1497
+
1498
+ Returns
1499
+ -------
1500
+ out : ndarray
1501
+ Array of the roots of the series. If all the roots are real,
1502
+ then `out` is also real, otherwise it is complex.
1503
+
1504
+ See Also
1505
+ --------
1506
+ numpy.polynomial.polynomial.polyroots
1507
+ numpy.polynomial.legendre.legroots
1508
+ numpy.polynomial.laguerre.lagroots
1509
+ numpy.polynomial.chebyshev.chebroots
1510
+ numpy.polynomial.hermite_e.hermeroots
1511
+
1512
+ Notes
1513
+ -----
1514
+ The root estimates are obtained as the eigenvalues of the companion
1515
+ matrix, Roots far from the origin of the complex plane may have large
1516
+ errors due to the numerical instability of the series for such
1517
+ values. Roots with multiplicity greater than 1 will also show larger
1518
+ errors as the value of the series near such points is relatively
1519
+ insensitive to errors in the roots. Isolated roots near the origin can
1520
+ be improved by a few iterations of Newton's method.
1521
+
1522
+ The Hermite series basis polynomials aren't powers of `x` so the
1523
+ results of this function may seem unintuitive.
1524
+
1525
+ Examples
1526
+ --------
1527
+ >>> from numpy.polynomial.hermite import hermroots, hermfromroots
1528
+ >>> coef = hermfromroots([-1, 0, 1])
1529
+ >>> coef
1530
+ array([0. , 0.25 , 0. , 0.125])
1531
+ >>> hermroots(coef)
1532
+ array([-1.00000000e+00, -1.38777878e-17, 1.00000000e+00])
1533
+
1534
+ """
1535
+ # c is a trimmed copy
1536
+ [c] = pu.as_series([c])
1537
+ if len(c) <= 1:
1538
+ return np.array([], dtype=c.dtype)
1539
+ if len(c) == 2:
1540
+ return np.array([-.5 * c[0] / c[1]])
1541
+
1542
+ # rotated companion matrix reduces error
1543
+ m = hermcompanion(c)[::-1, ::-1]
1544
+ r = np.linalg.eigvals(m)
1545
+ r.sort()
1546
+ return r
1547
+
1548
+
1549
+ def _normed_hermite_n(x, n):
1550
+ """
1551
+ Evaluate a normalized Hermite polynomial.
1552
+
1553
+ Compute the value of the normalized Hermite polynomial of degree ``n``
1554
+ at the points ``x``.
1555
+
1556
+
1557
+ Parameters
1558
+ ----------
1559
+ x : ndarray of double.
1560
+ Points at which to evaluate the function
1561
+ n : int
1562
+ Degree of the normalized Hermite function to be evaluated.
1563
+
1564
+ Returns
1565
+ -------
1566
+ values : ndarray
1567
+ The shape of the return value is described above.
1568
+
1569
+ Notes
1570
+ -----
1571
+ This function is needed for finding the Gauss points and integration
1572
+ weights for high degrees. The values of the standard Hermite functions
1573
+ overflow when n >= 207.
1574
+
1575
+ """
1576
+ if n == 0:
1577
+ return np.full(x.shape, 1 / np.sqrt(np.sqrt(np.pi)))
1578
+
1579
+ c0 = 0.
1580
+ c1 = 1. / np.sqrt(np.sqrt(np.pi))
1581
+ nd = float(n)
1582
+ for i in range(n - 1):
1583
+ tmp = c0
1584
+ c0 = -c1 * np.sqrt((nd - 1.) / nd)
1585
+ c1 = tmp + c1 * x * np.sqrt(2. / nd)
1586
+ nd = nd - 1.0
1587
+ return c0 + c1 * x * np.sqrt(2)
1588
+
1589
+
1590
+ def hermgauss(deg):
1591
+ """
1592
+ Gauss-Hermite quadrature.
1593
+
1594
+ Computes the sample points and weights for Gauss-Hermite quadrature.
1595
+ These sample points and weights will correctly integrate polynomials of
1596
+ degree :math:`2*deg - 1` or less over the interval :math:`[-\\inf, \\inf]`
1597
+ with the weight function :math:`f(x) = \\exp(-x^2)`.
1598
+
1599
+ Parameters
1600
+ ----------
1601
+ deg : int
1602
+ Number of sample points and weights. It must be >= 1.
1603
+
1604
+ Returns
1605
+ -------
1606
+ x : ndarray
1607
+ 1-D ndarray containing the sample points.
1608
+ y : ndarray
1609
+ 1-D ndarray containing the weights.
1610
+
1611
+ Notes
1612
+ -----
1613
+ The results have only been tested up to degree 100, higher degrees may
1614
+ be problematic. The weights are determined by using the fact that
1615
+
1616
+ .. math:: w_k = c / (H'_n(x_k) * H_{n-1}(x_k))
1617
+
1618
+ where :math:`c` is a constant independent of :math:`k` and :math:`x_k`
1619
+ is the k'th root of :math:`H_n`, and then scaling the results to get
1620
+ the right value when integrating 1.
1621
+
1622
+ Examples
1623
+ --------
1624
+ >>> from numpy.polynomial.hermite import hermgauss
1625
+ >>> hermgauss(2)
1626
+ (array([-0.70710678, 0.70710678]), array([0.88622693, 0.88622693]))
1627
+
1628
+ """
1629
+ ideg = pu._as_int(deg, "deg")
1630
+ if ideg <= 0:
1631
+ raise ValueError("deg must be a positive integer")
1632
+
1633
+ # first approximation of roots. We use the fact that the companion
1634
+ # matrix is symmetric in this case in order to obtain better zeros.
1635
+ c = np.array([0] * deg + [1], dtype=np.float64)
1636
+ m = hermcompanion(c)
1637
+ x = np.linalg.eigvalsh(m)
1638
+
1639
+ # improve roots by one application of Newton
1640
+ dy = _normed_hermite_n(x, ideg)
1641
+ df = _normed_hermite_n(x, ideg - 1) * np.sqrt(2 * ideg)
1642
+ x -= dy / df
1643
+
1644
+ # compute the weights. We scale the factor to avoid possible numerical
1645
+ # overflow.
1646
+ fm = _normed_hermite_n(x, ideg - 1)
1647
+ fm /= np.abs(fm).max()
1648
+ w = 1 / (fm * fm)
1649
+
1650
+ # for Hermite we can also symmetrize
1651
+ w = (w + w[::-1]) / 2
1652
+ x = (x - x[::-1]) / 2
1653
+
1654
+ # scale w to get the right value
1655
+ w *= np.sqrt(np.pi) / w.sum()
1656
+
1657
+ return x, w
1658
+
1659
+
1660
+ def hermweight(x):
1661
+ """
1662
+ Weight function of the Hermite polynomials.
1663
+
1664
+ The weight function is :math:`\\exp(-x^2)` and the interval of
1665
+ integration is :math:`[-\\inf, \\inf]`. the Hermite polynomials are
1666
+ orthogonal, but not normalized, with respect to this weight function.
1667
+
1668
+ Parameters
1669
+ ----------
1670
+ x : array_like
1671
+ Values at which the weight function will be computed.
1672
+
1673
+ Returns
1674
+ -------
1675
+ w : ndarray
1676
+ The weight function at `x`.
1677
+
1678
+ Examples
1679
+ --------
1680
+ >>> import numpy as np
1681
+ >>> from numpy.polynomial.hermite import hermweight
1682
+ >>> x = np.arange(-2, 2)
1683
+ >>> hermweight(x)
1684
+ array([0.01831564, 0.36787944, 1. , 0.36787944])
1685
+
1686
+ """
1687
+ w = np.exp(-x**2)
1688
+ return w
1689
+
1690
+
1691
+ #
1692
+ # Hermite series class
1693
+ #
1694
+
1695
+ class Hermite(ABCPolyBase):
1696
+ """A Hermite series class.
1697
+
1698
+ The Hermite class provides the standard Python numerical methods
1699
+ '+', '-', '*', '//', '%', 'divmod', '**', and '()' as well as the
1700
+ attributes and methods listed below.
1701
+
1702
+ Parameters
1703
+ ----------
1704
+ coef : array_like
1705
+ Hermite coefficients in order of increasing degree, i.e,
1706
+ ``(1, 2, 3)`` gives ``1*H_0(x) + 2*H_1(x) + 3*H_2(x)``.
1707
+ domain : (2,) array_like, optional
1708
+ Domain to use. The interval ``[domain[0], domain[1]]`` is mapped
1709
+ to the interval ``[window[0], window[1]]`` by shifting and scaling.
1710
+ The default value is [-1., 1.].
1711
+ window : (2,) array_like, optional
1712
+ Window, see `domain` for its use. The default value is [-1., 1.].
1713
+ symbol : str, optional
1714
+ Symbol used to represent the independent variable in string
1715
+ representations of the polynomial expression, e.g. for printing.
1716
+ The symbol must be a valid Python identifier. Default value is 'x'.
1717
+
1718
+ .. versionadded:: 1.24
1719
+
1720
+ """
1721
+ # Virtual Functions
1722
+ _add = staticmethod(hermadd)
1723
+ _sub = staticmethod(hermsub)
1724
+ _mul = staticmethod(hermmul)
1725
+ _div = staticmethod(hermdiv)
1726
+ _pow = staticmethod(hermpow)
1727
+ _val = staticmethod(hermval)
1728
+ _int = staticmethod(hermint)
1729
+ _der = staticmethod(hermder)
1730
+ _fit = staticmethod(hermfit)
1731
+ _line = staticmethod(hermline)
1732
+ _roots = staticmethod(hermroots)
1733
+ _fromroots = staticmethod(hermfromroots)
1734
+
1735
+ # Virtual properties
1736
+ domain = np.array(hermdomain)
1737
+ window = np.array(hermdomain)
1738
+ basis_name = 'H'
physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy/polynomial/hermite.pyi ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import Any, ClassVar, Final, Literal as L, TypeVar
2
+
3
+ import numpy as np
4
+ from numpy._typing import _Shape
5
+
6
+ from ._polybase import ABCPolyBase
7
+ from ._polytypes import (
8
+ _Array1,
9
+ _Array2,
10
+ _FuncBinOp,
11
+ _FuncCompanion,
12
+ _FuncDer,
13
+ _FuncFit,
14
+ _FuncFromRoots,
15
+ _FuncGauss,
16
+ _FuncInteg,
17
+ _FuncLine,
18
+ _FuncPoly2Ortho,
19
+ _FuncPow,
20
+ _FuncRoots,
21
+ _FuncUnOp,
22
+ _FuncVal,
23
+ _FuncVal2D,
24
+ _FuncVal3D,
25
+ _FuncVander,
26
+ _FuncVander2D,
27
+ _FuncVander3D,
28
+ _FuncWeight,
29
+ )
30
+ from .polyutils import trimcoef as hermtrim
31
+
32
+ __all__ = [
33
+ "hermzero",
34
+ "hermone",
35
+ "hermx",
36
+ "hermdomain",
37
+ "hermline",
38
+ "hermadd",
39
+ "hermsub",
40
+ "hermmulx",
41
+ "hermmul",
42
+ "hermdiv",
43
+ "hermpow",
44
+ "hermval",
45
+ "hermder",
46
+ "hermint",
47
+ "herm2poly",
48
+ "poly2herm",
49
+ "hermfromroots",
50
+ "hermvander",
51
+ "hermfit",
52
+ "hermtrim",
53
+ "hermroots",
54
+ "Hermite",
55
+ "hermval2d",
56
+ "hermval3d",
57
+ "hermgrid2d",
58
+ "hermgrid3d",
59
+ "hermvander2d",
60
+ "hermvander3d",
61
+ "hermcompanion",
62
+ "hermgauss",
63
+ "hermweight",
64
+ ]
65
+
66
+ _ShapeT = TypeVar("_ShapeT", bound=_Shape)
67
+
68
+ poly2herm: Final[_FuncPoly2Ortho] = ...
69
+ herm2poly: Final[_FuncUnOp] = ...
70
+
71
+ hermdomain: Final[_Array2[np.float64]] = ...
72
+ hermzero: Final[_Array1[np.int_]] = ...
73
+ hermone: Final[_Array1[np.int_]] = ...
74
+ hermx: Final[_Array2[np.int_]] = ...
75
+
76
+ hermline: Final[_FuncLine] = ...
77
+ hermfromroots: Final[_FuncFromRoots] = ...
78
+ hermadd: Final[_FuncBinOp] = ...
79
+ hermsub: Final[_FuncBinOp] = ...
80
+ hermmulx: Final[_FuncUnOp] = ...
81
+ hermmul: Final[_FuncBinOp] = ...
82
+ hermdiv: Final[_FuncBinOp] = ...
83
+ hermpow: Final[_FuncPow] = ...
84
+ hermder: Final[_FuncDer] = ...
85
+ hermint: Final[_FuncInteg] = ...
86
+ hermval: Final[_FuncVal] = ...
87
+ hermval2d: Final[_FuncVal2D] = ...
88
+ hermval3d: Final[_FuncVal3D] = ...
89
+ hermgrid2d: Final[_FuncVal2D] = ...
90
+ hermgrid3d: Final[_FuncVal3D] = ...
91
+ hermvander: Final[_FuncVander] = ...
92
+ hermvander2d: Final[_FuncVander2D] = ...
93
+ hermvander3d: Final[_FuncVander3D] = ...
94
+ hermfit: Final[_FuncFit] = ...
95
+ hermcompanion: Final[_FuncCompanion] = ...
96
+ hermroots: Final[_FuncRoots] = ...
97
+
98
+ def _normed_hermite_n(x: np.ndarray[_ShapeT, np.dtype[np.float64]], n: int) -> np.ndarray[_ShapeT, np.dtype[np.float64]]: ...
99
+
100
+ hermgauss: Final[_FuncGauss] = ...
101
+ hermweight: Final[_FuncWeight] = ...
102
+
103
+ class Hermite(ABCPolyBase[L["H"]]):
104
+ basis_name: ClassVar[L["H"]] = "H" # pyright: ignore[reportIncompatibleMethodOverride]
105
+ domain: _Array2[np.float64 | Any] = ... # pyright: ignore[reportIncompatibleMethodOverride]
106
+ window: _Array2[np.float64 | Any] = ... # pyright: ignore[reportIncompatibleMethodOverride]
physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy/polynomial/hermite_e.py ADDED
@@ -0,0 +1,1640 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ ===================================================================
3
+ HermiteE Series, "Probabilists" (:mod:`numpy.polynomial.hermite_e`)
4
+ ===================================================================
5
+
6
+ This module provides a number of objects (mostly functions) useful for
7
+ dealing with Hermite_e series, including a `HermiteE` class that
8
+ encapsulates the usual arithmetic operations. (General information
9
+ on how this module represents and works with such polynomials is in the
10
+ docstring for its "parent" sub-package, `numpy.polynomial`).
11
+
12
+ Classes
13
+ -------
14
+ .. autosummary::
15
+ :toctree: generated/
16
+
17
+ HermiteE
18
+
19
+ Constants
20
+ ---------
21
+ .. autosummary::
22
+ :toctree: generated/
23
+
24
+ hermedomain
25
+ hermezero
26
+ hermeone
27
+ hermex
28
+
29
+ Arithmetic
30
+ ----------
31
+ .. autosummary::
32
+ :toctree: generated/
33
+
34
+ hermeadd
35
+ hermesub
36
+ hermemulx
37
+ hermemul
38
+ hermediv
39
+ hermepow
40
+ hermeval
41
+ hermeval2d
42
+ hermeval3d
43
+ hermegrid2d
44
+ hermegrid3d
45
+
46
+ Calculus
47
+ --------
48
+ .. autosummary::
49
+ :toctree: generated/
50
+
51
+ hermeder
52
+ hermeint
53
+
54
+ Misc Functions
55
+ --------------
56
+ .. autosummary::
57
+ :toctree: generated/
58
+
59
+ hermefromroots
60
+ hermeroots
61
+ hermevander
62
+ hermevander2d
63
+ hermevander3d
64
+ hermegauss
65
+ hermeweight
66
+ hermecompanion
67
+ hermefit
68
+ hermetrim
69
+ hermeline
70
+ herme2poly
71
+ poly2herme
72
+
73
+ See also
74
+ --------
75
+ `numpy.polynomial`
76
+
77
+ """
78
+ import numpy as np
79
+
80
+ from . import polyutils as pu
81
+ from ._polybase import ABCPolyBase
82
+
83
+ __all__ = [
84
+ 'hermezero', 'hermeone', 'hermex', 'hermedomain', 'hermeline',
85
+ 'hermeadd', 'hermesub', 'hermemulx', 'hermemul', 'hermediv',
86
+ 'hermepow', 'hermeval', 'hermeder', 'hermeint', 'herme2poly',
87
+ 'poly2herme', 'hermefromroots', 'hermevander', 'hermefit', 'hermetrim',
88
+ 'hermeroots', 'HermiteE', 'hermeval2d', 'hermeval3d', 'hermegrid2d',
89
+ 'hermegrid3d', 'hermevander2d', 'hermevander3d', 'hermecompanion',
90
+ 'hermegauss', 'hermeweight']
91
+
92
+ hermetrim = pu.trimcoef
93
+
94
+
95
+ def poly2herme(pol):
96
+ """
97
+ poly2herme(pol)
98
+
99
+ Convert a polynomial to a Hermite series.
100
+
101
+ Convert an array representing the coefficients of a polynomial (relative
102
+ to the "standard" basis) ordered from lowest degree to highest, to an
103
+ array of the coefficients of the equivalent Hermite series, ordered
104
+ from lowest to highest degree.
105
+
106
+ Parameters
107
+ ----------
108
+ pol : array_like
109
+ 1-D array containing the polynomial coefficients
110
+
111
+ Returns
112
+ -------
113
+ c : ndarray
114
+ 1-D array containing the coefficients of the equivalent Hermite
115
+ series.
116
+
117
+ See Also
118
+ --------
119
+ herme2poly
120
+
121
+ Notes
122
+ -----
123
+ The easy way to do conversions between polynomial basis sets
124
+ is to use the convert method of a class instance.
125
+
126
+ Examples
127
+ --------
128
+ >>> import numpy as np
129
+ >>> from numpy.polynomial.hermite_e import poly2herme
130
+ >>> poly2herme(np.arange(4))
131
+ array([ 2., 10., 2., 3.])
132
+
133
+ """
134
+ [pol] = pu.as_series([pol])
135
+ deg = len(pol) - 1
136
+ res = 0
137
+ for i in range(deg, -1, -1):
138
+ res = hermeadd(hermemulx(res), pol[i])
139
+ return res
140
+
141
+
142
+ def herme2poly(c):
143
+ """
144
+ Convert a Hermite series to a polynomial.
145
+
146
+ Convert an array representing the coefficients of a Hermite series,
147
+ ordered from lowest degree to highest, to an array of the coefficients
148
+ of the equivalent polynomial (relative to the "standard" basis) ordered
149
+ from lowest to highest degree.
150
+
151
+ Parameters
152
+ ----------
153
+ c : array_like
154
+ 1-D array containing the Hermite series coefficients, ordered
155
+ from lowest order term to highest.
156
+
157
+ Returns
158
+ -------
159
+ pol : ndarray
160
+ 1-D array containing the coefficients of the equivalent polynomial
161
+ (relative to the "standard" basis) ordered from lowest order term
162
+ to highest.
163
+
164
+ See Also
165
+ --------
166
+ poly2herme
167
+
168
+ Notes
169
+ -----
170
+ The easy way to do conversions between polynomial basis sets
171
+ is to use the convert method of a class instance.
172
+
173
+ Examples
174
+ --------
175
+ >>> from numpy.polynomial.hermite_e import herme2poly
176
+ >>> herme2poly([ 2., 10., 2., 3.])
177
+ array([0., 1., 2., 3.])
178
+
179
+ """
180
+ from .polynomial import polyadd, polymulx, polysub
181
+
182
+ [c] = pu.as_series([c])
183
+ n = len(c)
184
+ if n == 1:
185
+ return c
186
+ if n == 2:
187
+ return c
188
+ else:
189
+ c0 = c[-2]
190
+ c1 = c[-1]
191
+ # i is the current degree of c1
192
+ for i in range(n - 1, 1, -1):
193
+ tmp = c0
194
+ c0 = polysub(c[i - 2], c1 * (i - 1))
195
+ c1 = polyadd(tmp, polymulx(c1))
196
+ return polyadd(c0, polymulx(c1))
197
+
198
+
199
+ #
200
+ # These are constant arrays are of integer type so as to be compatible
201
+ # with the widest range of other types, such as Decimal.
202
+ #
203
+
204
+ # Hermite
205
+ hermedomain = np.array([-1., 1.])
206
+
207
+ # Hermite coefficients representing zero.
208
+ hermezero = np.array([0])
209
+
210
+ # Hermite coefficients representing one.
211
+ hermeone = np.array([1])
212
+
213
+ # Hermite coefficients representing the identity x.
214
+ hermex = np.array([0, 1])
215
+
216
+
217
+ def hermeline(off, scl):
218
+ """
219
+ Hermite series whose graph is a straight line.
220
+
221
+ Parameters
222
+ ----------
223
+ off, scl : scalars
224
+ The specified line is given by ``off + scl*x``.
225
+
226
+ Returns
227
+ -------
228
+ y : ndarray
229
+ This module's representation of the Hermite series for
230
+ ``off + scl*x``.
231
+
232
+ See Also
233
+ --------
234
+ numpy.polynomial.polynomial.polyline
235
+ numpy.polynomial.chebyshev.chebline
236
+ numpy.polynomial.legendre.legline
237
+ numpy.polynomial.laguerre.lagline
238
+ numpy.polynomial.hermite.hermline
239
+
240
+ Examples
241
+ --------
242
+ >>> from numpy.polynomial.hermite_e import hermeline
243
+ >>> from numpy.polynomial.hermite_e import hermeline, hermeval
244
+ >>> hermeval(0,hermeline(3, 2))
245
+ 3.0
246
+ >>> hermeval(1,hermeline(3, 2))
247
+ 5.0
248
+
249
+ """
250
+ if scl != 0:
251
+ return np.array([off, scl])
252
+ else:
253
+ return np.array([off])
254
+
255
+
256
+ def hermefromroots(roots):
257
+ """
258
+ Generate a HermiteE series with given roots.
259
+
260
+ The function returns the coefficients of the polynomial
261
+
262
+ .. math:: p(x) = (x - r_0) * (x - r_1) * ... * (x - r_n),
263
+
264
+ in HermiteE form, where the :math:`r_n` are the roots specified in `roots`.
265
+ If a zero has multiplicity n, then it must appear in `roots` n times.
266
+ For instance, if 2 is a root of multiplicity three and 3 is a root of
267
+ multiplicity 2, then `roots` looks something like [2, 2, 2, 3, 3]. The
268
+ roots can appear in any order.
269
+
270
+ If the returned coefficients are `c`, then
271
+
272
+ .. math:: p(x) = c_0 + c_1 * He_1(x) + ... + c_n * He_n(x)
273
+
274
+ The coefficient of the last term is not generally 1 for monic
275
+ polynomials in HermiteE form.
276
+
277
+ Parameters
278
+ ----------
279
+ roots : array_like
280
+ Sequence containing the roots.
281
+
282
+ Returns
283
+ -------
284
+ out : ndarray
285
+ 1-D array of coefficients. If all roots are real then `out` is a
286
+ real array, if some of the roots are complex, then `out` is complex
287
+ even if all the coefficients in the result are real (see Examples
288
+ below).
289
+
290
+ See Also
291
+ --------
292
+ numpy.polynomial.polynomial.polyfromroots
293
+ numpy.polynomial.legendre.legfromroots
294
+ numpy.polynomial.laguerre.lagfromroots
295
+ numpy.polynomial.hermite.hermfromroots
296
+ numpy.polynomial.chebyshev.chebfromroots
297
+
298
+ Examples
299
+ --------
300
+ >>> from numpy.polynomial.hermite_e import hermefromroots, hermeval
301
+ >>> coef = hermefromroots((-1, 0, 1))
302
+ >>> hermeval((-1, 0, 1), coef)
303
+ array([0., 0., 0.])
304
+ >>> coef = hermefromroots((-1j, 1j))
305
+ >>> hermeval((-1j, 1j), coef)
306
+ array([0.+0.j, 0.+0.j])
307
+
308
+ """
309
+ return pu._fromroots(hermeline, hermemul, roots)
310
+
311
+
312
+ def hermeadd(c1, c2):
313
+ """
314
+ Add one Hermite series to another.
315
+
316
+ Returns the sum of two Hermite series `c1` + `c2`. The arguments
317
+ are sequences of coefficients ordered from lowest order term to
318
+ highest, i.e., [1,2,3] represents the series ``P_0 + 2*P_1 + 3*P_2``.
319
+
320
+ Parameters
321
+ ----------
322
+ c1, c2 : array_like
323
+ 1-D arrays of Hermite series coefficients ordered from low to
324
+ high.
325
+
326
+ Returns
327
+ -------
328
+ out : ndarray
329
+ Array representing the Hermite series of their sum.
330
+
331
+ See Also
332
+ --------
333
+ hermesub, hermemulx, hermemul, hermediv, hermepow
334
+
335
+ Notes
336
+ -----
337
+ Unlike multiplication, division, etc., the sum of two Hermite series
338
+ is a Hermite series (without having to "reproject" the result onto
339
+ the basis set) so addition, just like that of "standard" polynomials,
340
+ is simply "component-wise."
341
+
342
+ Examples
343
+ --------
344
+ >>> from numpy.polynomial.hermite_e import hermeadd
345
+ >>> hermeadd([1, 2, 3], [1, 2, 3, 4])
346
+ array([2., 4., 6., 4.])
347
+
348
+ """
349
+ return pu._add(c1, c2)
350
+
351
+
352
+ def hermesub(c1, c2):
353
+ """
354
+ Subtract one Hermite series from another.
355
+
356
+ Returns the difference of two Hermite series `c1` - `c2`. The
357
+ sequences of coefficients are from lowest order term to highest, i.e.,
358
+ [1,2,3] represents the series ``P_0 + 2*P_1 + 3*P_2``.
359
+
360
+ Parameters
361
+ ----------
362
+ c1, c2 : array_like
363
+ 1-D arrays of Hermite series coefficients ordered from low to
364
+ high.
365
+
366
+ Returns
367
+ -------
368
+ out : ndarray
369
+ Of Hermite series coefficients representing their difference.
370
+
371
+ See Also
372
+ --------
373
+ hermeadd, hermemulx, hermemul, hermediv, hermepow
374
+
375
+ Notes
376
+ -----
377
+ Unlike multiplication, division, etc., the difference of two Hermite
378
+ series is a Hermite series (without having to "reproject" the result
379
+ onto the basis set) so subtraction, just like that of "standard"
380
+ polynomials, is simply "component-wise."
381
+
382
+ Examples
383
+ --------
384
+ >>> from numpy.polynomial.hermite_e import hermesub
385
+ >>> hermesub([1, 2, 3, 4], [1, 2, 3])
386
+ array([0., 0., 0., 4.])
387
+
388
+ """
389
+ return pu._sub(c1, c2)
390
+
391
+
392
+ def hermemulx(c):
393
+ """Multiply a Hermite series by x.
394
+
395
+ Multiply the Hermite series `c` by x, where x is the independent
396
+ variable.
397
+
398
+
399
+ Parameters
400
+ ----------
401
+ c : array_like
402
+ 1-D array of Hermite series coefficients ordered from low to
403
+ high.
404
+
405
+ Returns
406
+ -------
407
+ out : ndarray
408
+ Array representing the result of the multiplication.
409
+
410
+ See Also
411
+ --------
412
+ hermeadd, hermesub, hermemul, hermediv, hermepow
413
+
414
+ Notes
415
+ -----
416
+ The multiplication uses the recursion relationship for Hermite
417
+ polynomials in the form
418
+
419
+ .. math::
420
+
421
+ xP_i(x) = (P_{i + 1}(x) + iP_{i - 1}(x)))
422
+
423
+ Examples
424
+ --------
425
+ >>> from numpy.polynomial.hermite_e import hermemulx
426
+ >>> hermemulx([1, 2, 3])
427
+ array([2., 7., 2., 3.])
428
+
429
+ """
430
+ # c is a trimmed copy
431
+ [c] = pu.as_series([c])
432
+ # The zero series needs special treatment
433
+ if len(c) == 1 and c[0] == 0:
434
+ return c
435
+
436
+ prd = np.empty(len(c) + 1, dtype=c.dtype)
437
+ prd[0] = c[0] * 0
438
+ prd[1] = c[0]
439
+ for i in range(1, len(c)):
440
+ prd[i + 1] = c[i]
441
+ prd[i - 1] += c[i] * i
442
+ return prd
443
+
444
+
445
+ def hermemul(c1, c2):
446
+ """
447
+ Multiply one Hermite series by another.
448
+
449
+ Returns the product of two Hermite series `c1` * `c2`. The arguments
450
+ are sequences of coefficients, from lowest order "term" to highest,
451
+ e.g., [1,2,3] represents the series ``P_0 + 2*P_1 + 3*P_2``.
452
+
453
+ Parameters
454
+ ----------
455
+ c1, c2 : array_like
456
+ 1-D arrays of Hermite series coefficients ordered from low to
457
+ high.
458
+
459
+ Returns
460
+ -------
461
+ out : ndarray
462
+ Of Hermite series coefficients representing their product.
463
+
464
+ See Also
465
+ --------
466
+ hermeadd, hermesub, hermemulx, hermediv, hermepow
467
+
468
+ Notes
469
+ -----
470
+ In general, the (polynomial) product of two C-series results in terms
471
+ that are not in the Hermite polynomial basis set. Thus, to express
472
+ the product as a Hermite series, it is necessary to "reproject" the
473
+ product onto said basis set, which may produce "unintuitive" (but
474
+ correct) results; see Examples section below.
475
+
476
+ Examples
477
+ --------
478
+ >>> from numpy.polynomial.hermite_e import hermemul
479
+ >>> hermemul([1, 2, 3], [0, 1, 2])
480
+ array([14., 15., 28., 7., 6.])
481
+
482
+ """
483
+ # s1, s2 are trimmed copies
484
+ [c1, c2] = pu.as_series([c1, c2])
485
+
486
+ if len(c1) > len(c2):
487
+ c = c2
488
+ xs = c1
489
+ else:
490
+ c = c1
491
+ xs = c2
492
+
493
+ if len(c) == 1:
494
+ c0 = c[0] * xs
495
+ c1 = 0
496
+ elif len(c) == 2:
497
+ c0 = c[0] * xs
498
+ c1 = c[1] * xs
499
+ else:
500
+ nd = len(c)
501
+ c0 = c[-2] * xs
502
+ c1 = c[-1] * xs
503
+ for i in range(3, len(c) + 1):
504
+ tmp = c0
505
+ nd = nd - 1
506
+ c0 = hermesub(c[-i] * xs, c1 * (nd - 1))
507
+ c1 = hermeadd(tmp, hermemulx(c1))
508
+ return hermeadd(c0, hermemulx(c1))
509
+
510
+
511
+ def hermediv(c1, c2):
512
+ """
513
+ Divide one Hermite series by another.
514
+
515
+ Returns the quotient-with-remainder of two Hermite series
516
+ `c1` / `c2`. The arguments are sequences of coefficients from lowest
517
+ order "term" to highest, e.g., [1,2,3] represents the series
518
+ ``P_0 + 2*P_1 + 3*P_2``.
519
+
520
+ Parameters
521
+ ----------
522
+ c1, c2 : array_like
523
+ 1-D arrays of Hermite series coefficients ordered from low to
524
+ high.
525
+
526
+ Returns
527
+ -------
528
+ [quo, rem] : ndarrays
529
+ Of Hermite series coefficients representing the quotient and
530
+ remainder.
531
+
532
+ See Also
533
+ --------
534
+ hermeadd, hermesub, hermemulx, hermemul, hermepow
535
+
536
+ Notes
537
+ -----
538
+ In general, the (polynomial) division of one Hermite series by another
539
+ results in quotient and remainder terms that are not in the Hermite
540
+ polynomial basis set. Thus, to express these results as a Hermite
541
+ series, it is necessary to "reproject" the results onto the Hermite
542
+ basis set, which may produce "unintuitive" (but correct) results; see
543
+ Examples section below.
544
+
545
+ Examples
546
+ --------
547
+ >>> from numpy.polynomial.hermite_e import hermediv
548
+ >>> hermediv([ 14., 15., 28., 7., 6.], [0, 1, 2])
549
+ (array([1., 2., 3.]), array([0.]))
550
+ >>> hermediv([ 15., 17., 28., 7., 6.], [0, 1, 2])
551
+ (array([1., 2., 3.]), array([1., 2.]))
552
+
553
+ """
554
+ return pu._div(hermemul, c1, c2)
555
+
556
+
557
+ def hermepow(c, pow, maxpower=16):
558
+ """Raise a Hermite series to a power.
559
+
560
+ Returns the Hermite series `c` raised to the power `pow`. The
561
+ argument `c` is a sequence of coefficients ordered from low to high.
562
+ i.e., [1,2,3] is the series ``P_0 + 2*P_1 + 3*P_2.``
563
+
564
+ Parameters
565
+ ----------
566
+ c : array_like
567
+ 1-D array of Hermite series coefficients ordered from low to
568
+ high.
569
+ pow : integer
570
+ Power to which the series will be raised
571
+ maxpower : integer, optional
572
+ Maximum power allowed. This is mainly to limit growth of the series
573
+ to unmanageable size. Default is 16
574
+
575
+ Returns
576
+ -------
577
+ coef : ndarray
578
+ Hermite series of power.
579
+
580
+ See Also
581
+ --------
582
+ hermeadd, hermesub, hermemulx, hermemul, hermediv
583
+
584
+ Examples
585
+ --------
586
+ >>> from numpy.polynomial.hermite_e import hermepow
587
+ >>> hermepow([1, 2, 3], 2)
588
+ array([23., 28., 46., 12., 9.])
589
+
590
+ """
591
+ return pu._pow(hermemul, c, pow, maxpower)
592
+
593
+
594
+ def hermeder(c, m=1, scl=1, axis=0):
595
+ """
596
+ Differentiate a Hermite_e series.
597
+
598
+ Returns the series coefficients `c` differentiated `m` times along
599
+ `axis`. At each iteration the result is multiplied by `scl` (the
600
+ scaling factor is for use in a linear change of variable). The argument
601
+ `c` is an array of coefficients from low to high degree along each
602
+ axis, e.g., [1,2,3] represents the series ``1*He_0 + 2*He_1 + 3*He_2``
603
+ while [[1,2],[1,2]] represents ``1*He_0(x)*He_0(y) + 1*He_1(x)*He_0(y)
604
+ + 2*He_0(x)*He_1(y) + 2*He_1(x)*He_1(y)`` if axis=0 is ``x`` and axis=1
605
+ is ``y``.
606
+
607
+ Parameters
608
+ ----------
609
+ c : array_like
610
+ Array of Hermite_e series coefficients. If `c` is multidimensional
611
+ the different axis correspond to different variables with the
612
+ degree in each axis given by the corresponding index.
613
+ m : int, optional
614
+ Number of derivatives taken, must be non-negative. (Default: 1)
615
+ scl : scalar, optional
616
+ Each differentiation is multiplied by `scl`. The end result is
617
+ multiplication by ``scl**m``. This is for use in a linear change of
618
+ variable. (Default: 1)
619
+ axis : int, optional
620
+ Axis over which the derivative is taken. (Default: 0).
621
+
622
+ Returns
623
+ -------
624
+ der : ndarray
625
+ Hermite series of the derivative.
626
+
627
+ See Also
628
+ --------
629
+ hermeint
630
+
631
+ Notes
632
+ -----
633
+ In general, the result of differentiating a Hermite series does not
634
+ resemble the same operation on a power series. Thus the result of this
635
+ function may be "unintuitive," albeit correct; see Examples section
636
+ below.
637
+
638
+ Examples
639
+ --------
640
+ >>> from numpy.polynomial.hermite_e import hermeder
641
+ >>> hermeder([ 1., 1., 1., 1.])
642
+ array([1., 2., 3.])
643
+ >>> hermeder([-0.25, 1., 1./2., 1./3., 1./4 ], m=2)
644
+ array([1., 2., 3.])
645
+
646
+ """
647
+ c = np.array(c, ndmin=1, copy=True)
648
+ if c.dtype.char in '?bBhHiIlLqQpP':
649
+ c = c.astype(np.double)
650
+ cnt = pu._as_int(m, "the order of derivation")
651
+ iaxis = pu._as_int(axis, "the axis")
652
+ if cnt < 0:
653
+ raise ValueError("The order of derivation must be non-negative")
654
+ iaxis = np.lib.array_utils.normalize_axis_index(iaxis, c.ndim)
655
+
656
+ if cnt == 0:
657
+ return c
658
+
659
+ c = np.moveaxis(c, iaxis, 0)
660
+ n = len(c)
661
+ if cnt >= n:
662
+ return c[:1] * 0
663
+ else:
664
+ for i in range(cnt):
665
+ n = n - 1
666
+ c *= scl
667
+ der = np.empty((n,) + c.shape[1:], dtype=c.dtype)
668
+ for j in range(n, 0, -1):
669
+ der[j - 1] = j * c[j]
670
+ c = der
671
+ c = np.moveaxis(c, 0, iaxis)
672
+ return c
673
+
674
+
675
+ def hermeint(c, m=1, k=[], lbnd=0, scl=1, axis=0):
676
+ """
677
+ Integrate a Hermite_e series.
678
+
679
+ Returns the Hermite_e series coefficients `c` integrated `m` times from
680
+ `lbnd` along `axis`. At each iteration the resulting series is
681
+ **multiplied** by `scl` and an integration constant, `k`, is added.
682
+ The scaling factor is for use in a linear change of variable. ("Buyer
683
+ beware": note that, depending on what one is doing, one may want `scl`
684
+ to be the reciprocal of what one might expect; for more information,
685
+ see the Notes section below.) The argument `c` is an array of
686
+ coefficients from low to high degree along each axis, e.g., [1,2,3]
687
+ represents the series ``H_0 + 2*H_1 + 3*H_2`` while [[1,2],[1,2]]
688
+ represents ``1*H_0(x)*H_0(y) + 1*H_1(x)*H_0(y) + 2*H_0(x)*H_1(y) +
689
+ 2*H_1(x)*H_1(y)`` if axis=0 is ``x`` and axis=1 is ``y``.
690
+
691
+ Parameters
692
+ ----------
693
+ c : array_like
694
+ Array of Hermite_e series coefficients. If c is multidimensional
695
+ the different axis correspond to different variables with the
696
+ degree in each axis given by the corresponding index.
697
+ m : int, optional
698
+ Order of integration, must be positive. (Default: 1)
699
+ k : {[], list, scalar}, optional
700
+ Integration constant(s). The value of the first integral at
701
+ ``lbnd`` is the first value in the list, the value of the second
702
+ integral at ``lbnd`` is the second value, etc. If ``k == []`` (the
703
+ default), all constants are set to zero. If ``m == 1``, a single
704
+ scalar can be given instead of a list.
705
+ lbnd : scalar, optional
706
+ The lower bound of the integral. (Default: 0)
707
+ scl : scalar, optional
708
+ Following each integration the result is *multiplied* by `scl`
709
+ before the integration constant is added. (Default: 1)
710
+ axis : int, optional
711
+ Axis over which the integral is taken. (Default: 0).
712
+
713
+ Returns
714
+ -------
715
+ S : ndarray
716
+ Hermite_e series coefficients of the integral.
717
+
718
+ Raises
719
+ ------
720
+ ValueError
721
+ If ``m < 0``, ``len(k) > m``, ``np.ndim(lbnd) != 0``, or
722
+ ``np.ndim(scl) != 0``.
723
+
724
+ See Also
725
+ --------
726
+ hermeder
727
+
728
+ Notes
729
+ -----
730
+ Note that the result of each integration is *multiplied* by `scl`.
731
+ Why is this important to note? Say one is making a linear change of
732
+ variable :math:`u = ax + b` in an integral relative to `x`. Then
733
+ :math:`dx = du/a`, so one will need to set `scl` equal to
734
+ :math:`1/a` - perhaps not what one would have first thought.
735
+
736
+ Also note that, in general, the result of integrating a C-series needs
737
+ to be "reprojected" onto the C-series basis set. Thus, typically,
738
+ the result of this function is "unintuitive," albeit correct; see
739
+ Examples section below.
740
+
741
+ Examples
742
+ --------
743
+ >>> from numpy.polynomial.hermite_e import hermeint
744
+ >>> hermeint([1, 2, 3]) # integrate once, value 0 at 0.
745
+ array([1., 1., 1., 1.])
746
+ >>> hermeint([1, 2, 3], m=2) # integrate twice, value & deriv 0 at 0
747
+ array([-0.25 , 1. , 0.5 , 0.33333333, 0.25 ]) # may vary
748
+ >>> hermeint([1, 2, 3], k=1) # integrate once, value 1 at 0.
749
+ array([2., 1., 1., 1.])
750
+ >>> hermeint([1, 2, 3], lbnd=-1) # integrate once, value 0 at -1
751
+ array([-1., 1., 1., 1.])
752
+ >>> hermeint([1, 2, 3], m=2, k=[1, 2], lbnd=-1)
753
+ array([ 1.83333333, 0. , 0.5 , 0.33333333, 0.25 ]) # may vary
754
+
755
+ """
756
+ c = np.array(c, ndmin=1, copy=True)
757
+ if c.dtype.char in '?bBhHiIlLqQpP':
758
+ c = c.astype(np.double)
759
+ if not np.iterable(k):
760
+ k = [k]
761
+ cnt = pu._as_int(m, "the order of integration")
762
+ iaxis = pu._as_int(axis, "the axis")
763
+ if cnt < 0:
764
+ raise ValueError("The order of integration must be non-negative")
765
+ if len(k) > cnt:
766
+ raise ValueError("Too many integration constants")
767
+ if np.ndim(lbnd) != 0:
768
+ raise ValueError("lbnd must be a scalar.")
769
+ if np.ndim(scl) != 0:
770
+ raise ValueError("scl must be a scalar.")
771
+ iaxis = np.lib.array_utils.normalize_axis_index(iaxis, c.ndim)
772
+
773
+ if cnt == 0:
774
+ return c
775
+
776
+ c = np.moveaxis(c, iaxis, 0)
777
+ k = list(k) + [0] * (cnt - len(k))
778
+ for i in range(cnt):
779
+ n = len(c)
780
+ c *= scl
781
+ if n == 1 and np.all(c[0] == 0):
782
+ c[0] += k[i]
783
+ else:
784
+ tmp = np.empty((n + 1,) + c.shape[1:], dtype=c.dtype)
785
+ tmp[0] = c[0] * 0
786
+ tmp[1] = c[0]
787
+ for j in range(1, n):
788
+ tmp[j + 1] = c[j] / (j + 1)
789
+ tmp[0] += k[i] - hermeval(lbnd, tmp)
790
+ c = tmp
791
+ c = np.moveaxis(c, 0, iaxis)
792
+ return c
793
+
794
+
795
+ def hermeval(x, c, tensor=True):
796
+ """
797
+ Evaluate a HermiteE series at points x.
798
+
799
+ If `c` is of length ``n + 1``, this function returns the value:
800
+
801
+ .. math:: p(x) = c_0 * He_0(x) + c_1 * He_1(x) + ... + c_n * He_n(x)
802
+
803
+ The parameter `x` is converted to an array only if it is a tuple or a
804
+ list, otherwise it is treated as a scalar. In either case, either `x`
805
+ or its elements must support multiplication and addition both with
806
+ themselves and with the elements of `c`.
807
+
808
+ If `c` is a 1-D array, then ``p(x)`` will have the same shape as `x`. If
809
+ `c` is multidimensional, then the shape of the result depends on the
810
+ value of `tensor`. If `tensor` is true the shape will be c.shape[1:] +
811
+ x.shape. If `tensor` is false the shape will be c.shape[1:]. Note that
812
+ scalars have shape (,).
813
+
814
+ Trailing zeros in the coefficients will be used in the evaluation, so
815
+ they should be avoided if efficiency is a concern.
816
+
817
+ Parameters
818
+ ----------
819
+ x : array_like, compatible object
820
+ If `x` is a list or tuple, it is converted to an ndarray, otherwise
821
+ it is left unchanged and treated as a scalar. In either case, `x`
822
+ or its elements must support addition and multiplication with
823
+ with themselves and with the elements of `c`.
824
+ c : array_like
825
+ Array of coefficients ordered so that the coefficients for terms of
826
+ degree n are contained in c[n]. If `c` is multidimensional the
827
+ remaining indices enumerate multiple polynomials. In the two
828
+ dimensional case the coefficients may be thought of as stored in
829
+ the columns of `c`.
830
+ tensor : boolean, optional
831
+ If True, the shape of the coefficient array is extended with ones
832
+ on the right, one for each dimension of `x`. Scalars have dimension 0
833
+ for this action. The result is that every column of coefficients in
834
+ `c` is evaluated for every element of `x`. If False, `x` is broadcast
835
+ over the columns of `c` for the evaluation. This keyword is useful
836
+ when `c` is multidimensional. The default value is True.
837
+
838
+ Returns
839
+ -------
840
+ values : ndarray, algebra_like
841
+ The shape of the return value is described above.
842
+
843
+ See Also
844
+ --------
845
+ hermeval2d, hermegrid2d, hermeval3d, hermegrid3d
846
+
847
+ Notes
848
+ -----
849
+ The evaluation uses Clenshaw recursion, aka synthetic division.
850
+
851
+ Examples
852
+ --------
853
+ >>> from numpy.polynomial.hermite_e import hermeval
854
+ >>> coef = [1,2,3]
855
+ >>> hermeval(1, coef)
856
+ 3.0
857
+ >>> hermeval([[1,2],[3,4]], coef)
858
+ array([[ 3., 14.],
859
+ [31., 54.]])
860
+
861
+ """
862
+ c = np.array(c, ndmin=1, copy=None)
863
+ if c.dtype.char in '?bBhHiIlLqQpP':
864
+ c = c.astype(np.double)
865
+ if isinstance(x, (tuple, list)):
866
+ x = np.asarray(x)
867
+ if isinstance(x, np.ndarray) and tensor:
868
+ c = c.reshape(c.shape + (1,) * x.ndim)
869
+
870
+ if len(c) == 1:
871
+ c0 = c[0]
872
+ c1 = 0
873
+ elif len(c) == 2:
874
+ c0 = c[0]
875
+ c1 = c[1]
876
+ else:
877
+ nd = len(c)
878
+ c0 = c[-2]
879
+ c1 = c[-1]
880
+ for i in range(3, len(c) + 1):
881
+ tmp = c0
882
+ nd = nd - 1
883
+ c0 = c[-i] - c1 * (nd - 1)
884
+ c1 = tmp + c1 * x
885
+ return c0 + c1 * x
886
+
887
+
888
+ def hermeval2d(x, y, c):
889
+ """
890
+ Evaluate a 2-D HermiteE series at points (x, y).
891
+
892
+ This function returns the values:
893
+
894
+ .. math:: p(x,y) = \\sum_{i,j} c_{i,j} * He_i(x) * He_j(y)
895
+
896
+ The parameters `x` and `y` are converted to arrays only if they are
897
+ tuples or a lists, otherwise they are treated as a scalars and they
898
+ must have the same shape after conversion. In either case, either `x`
899
+ and `y` or their elements must support multiplication and addition both
900
+ with themselves and with the elements of `c`.
901
+
902
+ If `c` is a 1-D array a one is implicitly appended to its shape to make
903
+ it 2-D. The shape of the result will be c.shape[2:] + x.shape.
904
+
905
+ Parameters
906
+ ----------
907
+ x, y : array_like, compatible objects
908
+ The two dimensional series is evaluated at the points ``(x, y)``,
909
+ where `x` and `y` must have the same shape. If `x` or `y` is a list
910
+ or tuple, it is first converted to an ndarray, otherwise it is left
911
+ unchanged and if it isn't an ndarray it is treated as a scalar.
912
+ c : array_like
913
+ Array of coefficients ordered so that the coefficient of the term
914
+ of multi-degree i,j is contained in ``c[i,j]``. If `c` has
915
+ dimension greater than two the remaining indices enumerate multiple
916
+ sets of coefficients.
917
+
918
+ Returns
919
+ -------
920
+ values : ndarray, compatible object
921
+ The values of the two dimensional polynomial at points formed with
922
+ pairs of corresponding values from `x` and `y`.
923
+
924
+ See Also
925
+ --------
926
+ hermeval, hermegrid2d, hermeval3d, hermegrid3d
927
+ """
928
+ return pu._valnd(hermeval, c, x, y)
929
+
930
+
931
+ def hermegrid2d(x, y, c):
932
+ """
933
+ Evaluate a 2-D HermiteE series on the Cartesian product of x and y.
934
+
935
+ This function returns the values:
936
+
937
+ .. math:: p(a,b) = \\sum_{i,j} c_{i,j} * H_i(a) * H_j(b)
938
+
939
+ where the points ``(a, b)`` consist of all pairs formed by taking
940
+ `a` from `x` and `b` from `y`. The resulting points form a grid with
941
+ `x` in the first dimension and `y` in the second.
942
+
943
+ The parameters `x` and `y` are converted to arrays only if they are
944
+ tuples or a lists, otherwise they are treated as a scalars. In either
945
+ case, either `x` and `y` or their elements must support multiplication
946
+ and addition both with themselves and with the elements of `c`.
947
+
948
+ If `c` has fewer than two dimensions, ones are implicitly appended to
949
+ its shape to make it 2-D. The shape of the result will be c.shape[2:] +
950
+ x.shape.
951
+
952
+ Parameters
953
+ ----------
954
+ x, y : array_like, compatible objects
955
+ The two dimensional series is evaluated at the points in the
956
+ Cartesian product of `x` and `y`. If `x` or `y` is a list or
957
+ tuple, it is first converted to an ndarray, otherwise it is left
958
+ unchanged and, if it isn't an ndarray, it is treated as a scalar.
959
+ c : array_like
960
+ Array of coefficients ordered so that the coefficients for terms of
961
+ degree i,j are contained in ``c[i,j]``. If `c` has dimension
962
+ greater than two the remaining indices enumerate multiple sets of
963
+ coefficients.
964
+
965
+ Returns
966
+ -------
967
+ values : ndarray, compatible object
968
+ The values of the two dimensional polynomial at points in the Cartesian
969
+ product of `x` and `y`.
970
+
971
+ See Also
972
+ --------
973
+ hermeval, hermeval2d, hermeval3d, hermegrid3d
974
+ """
975
+ return pu._gridnd(hermeval, c, x, y)
976
+
977
+
978
+ def hermeval3d(x, y, z, c):
979
+ """
980
+ Evaluate a 3-D Hermite_e series at points (x, y, z).
981
+
982
+ This function returns the values:
983
+
984
+ .. math:: p(x,y,z) = \\sum_{i,j,k} c_{i,j,k} * He_i(x) * He_j(y) * He_k(z)
985
+
986
+ The parameters `x`, `y`, and `z` are converted to arrays only if
987
+ they are tuples or a lists, otherwise they are treated as a scalars and
988
+ they must have the same shape after conversion. In either case, either
989
+ `x`, `y`, and `z` or their elements must support multiplication and
990
+ addition both with themselves and with the elements of `c`.
991
+
992
+ If `c` has fewer than 3 dimensions, ones are implicitly appended to its
993
+ shape to make it 3-D. The shape of the result will be c.shape[3:] +
994
+ x.shape.
995
+
996
+ Parameters
997
+ ----------
998
+ x, y, z : array_like, compatible object
999
+ The three dimensional series is evaluated at the points
1000
+ `(x, y, z)`, where `x`, `y`, and `z` must have the same shape. If
1001
+ any of `x`, `y`, or `z` is a list or tuple, it is first converted
1002
+ to an ndarray, otherwise it is left unchanged and if it isn't an
1003
+ ndarray it is treated as a scalar.
1004
+ c : array_like
1005
+ Array of coefficients ordered so that the coefficient of the term of
1006
+ multi-degree i,j,k is contained in ``c[i,j,k]``. If `c` has dimension
1007
+ greater than 3 the remaining indices enumerate multiple sets of
1008
+ coefficients.
1009
+
1010
+ Returns
1011
+ -------
1012
+ values : ndarray, compatible object
1013
+ The values of the multidimensional polynomial on points formed with
1014
+ triples of corresponding values from `x`, `y`, and `z`.
1015
+
1016
+ See Also
1017
+ --------
1018
+ hermeval, hermeval2d, hermegrid2d, hermegrid3d
1019
+ """
1020
+ return pu._valnd(hermeval, c, x, y, z)
1021
+
1022
+
1023
+ def hermegrid3d(x, y, z, c):
1024
+ """
1025
+ Evaluate a 3-D HermiteE series on the Cartesian product of x, y, and z.
1026
+
1027
+ This function returns the values:
1028
+
1029
+ .. math:: p(a,b,c) = \\sum_{i,j,k} c_{i,j,k} * He_i(a) * He_j(b) * He_k(c)
1030
+
1031
+ where the points ``(a, b, c)`` consist of all triples formed by taking
1032
+ `a` from `x`, `b` from `y`, and `c` from `z`. The resulting points form
1033
+ a grid with `x` in the first dimension, `y` in the second, and `z` in
1034
+ the third.
1035
+
1036
+ The parameters `x`, `y`, and `z` are converted to arrays only if they
1037
+ are tuples or a lists, otherwise they are treated as a scalars. In
1038
+ either case, either `x`, `y`, and `z` or their elements must support
1039
+ multiplication and addition both with themselves and with the elements
1040
+ of `c`.
1041
+
1042
+ If `c` has fewer than three dimensions, ones are implicitly appended to
1043
+ its shape to make it 3-D. The shape of the result will be c.shape[3:] +
1044
+ x.shape + y.shape + z.shape.
1045
+
1046
+ Parameters
1047
+ ----------
1048
+ x, y, z : array_like, compatible objects
1049
+ The three dimensional series is evaluated at the points in the
1050
+ Cartesian product of `x`, `y`, and `z`. If `x`, `y`, or `z` is a
1051
+ list or tuple, it is first converted to an ndarray, otherwise it is
1052
+ left unchanged and, if it isn't an ndarray, it is treated as a
1053
+ scalar.
1054
+ c : array_like
1055
+ Array of coefficients ordered so that the coefficients for terms of
1056
+ degree i,j are contained in ``c[i,j]``. If `c` has dimension
1057
+ greater than two the remaining indices enumerate multiple sets of
1058
+ coefficients.
1059
+
1060
+ Returns
1061
+ -------
1062
+ values : ndarray, compatible object
1063
+ The values of the two dimensional polynomial at points in the Cartesian
1064
+ product of `x` and `y`.
1065
+
1066
+ See Also
1067
+ --------
1068
+ hermeval, hermeval2d, hermegrid2d, hermeval3d
1069
+ """
1070
+ return pu._gridnd(hermeval, c, x, y, z)
1071
+
1072
+
1073
+ def hermevander(x, deg):
1074
+ """Pseudo-Vandermonde matrix of given degree.
1075
+
1076
+ Returns the pseudo-Vandermonde matrix of degree `deg` and sample points
1077
+ `x`. The pseudo-Vandermonde matrix is defined by
1078
+
1079
+ .. math:: V[..., i] = He_i(x),
1080
+
1081
+ where ``0 <= i <= deg``. The leading indices of `V` index the elements of
1082
+ `x` and the last index is the degree of the HermiteE polynomial.
1083
+
1084
+ If `c` is a 1-D array of coefficients of length ``n + 1`` and `V` is the
1085
+ array ``V = hermevander(x, n)``, then ``np.dot(V, c)`` and
1086
+ ``hermeval(x, c)`` are the same up to roundoff. This equivalence is
1087
+ useful both for least squares fitting and for the evaluation of a large
1088
+ number of HermiteE series of the same degree and sample points.
1089
+
1090
+ Parameters
1091
+ ----------
1092
+ x : array_like
1093
+ Array of points. The dtype is converted to float64 or complex128
1094
+ depending on whether any of the elements are complex. If `x` is
1095
+ scalar it is converted to a 1-D array.
1096
+ deg : int
1097
+ Degree of the resulting matrix.
1098
+
1099
+ Returns
1100
+ -------
1101
+ vander : ndarray
1102
+ The pseudo-Vandermonde matrix. The shape of the returned matrix is
1103
+ ``x.shape + (deg + 1,)``, where The last index is the degree of the
1104
+ corresponding HermiteE polynomial. The dtype will be the same as
1105
+ the converted `x`.
1106
+
1107
+ Examples
1108
+ --------
1109
+ >>> import numpy as np
1110
+ >>> from numpy.polynomial.hermite_e import hermevander
1111
+ >>> x = np.array([-1, 0, 1])
1112
+ >>> hermevander(x, 3)
1113
+ array([[ 1., -1., 0., 2.],
1114
+ [ 1., 0., -1., -0.],
1115
+ [ 1., 1., 0., -2.]])
1116
+
1117
+ """
1118
+ ideg = pu._as_int(deg, "deg")
1119
+ if ideg < 0:
1120
+ raise ValueError("deg must be non-negative")
1121
+
1122
+ x = np.array(x, copy=None, ndmin=1) + 0.0
1123
+ dims = (ideg + 1,) + x.shape
1124
+ dtyp = x.dtype
1125
+ v = np.empty(dims, dtype=dtyp)
1126
+ v[0] = x * 0 + 1
1127
+ if ideg > 0:
1128
+ v[1] = x
1129
+ for i in range(2, ideg + 1):
1130
+ v[i] = (v[i - 1] * x - v[i - 2] * (i - 1))
1131
+ return np.moveaxis(v, 0, -1)
1132
+
1133
+
1134
+ def hermevander2d(x, y, deg):
1135
+ """Pseudo-Vandermonde matrix of given degrees.
1136
+
1137
+ Returns the pseudo-Vandermonde matrix of degrees `deg` and sample
1138
+ points ``(x, y)``. The pseudo-Vandermonde matrix is defined by
1139
+
1140
+ .. math:: V[..., (deg[1] + 1)*i + j] = He_i(x) * He_j(y),
1141
+
1142
+ where ``0 <= i <= deg[0]`` and ``0 <= j <= deg[1]``. The leading indices of
1143
+ `V` index the points ``(x, y)`` and the last index encodes the degrees of
1144
+ the HermiteE polynomials.
1145
+
1146
+ If ``V = hermevander2d(x, y, [xdeg, ydeg])``, then the columns of `V`
1147
+ correspond to the elements of a 2-D coefficient array `c` of shape
1148
+ (xdeg + 1, ydeg + 1) in the order
1149
+
1150
+ .. math:: c_{00}, c_{01}, c_{02} ... , c_{10}, c_{11}, c_{12} ...
1151
+
1152
+ and ``np.dot(V, c.flat)`` and ``hermeval2d(x, y, c)`` will be the same
1153
+ up to roundoff. This equivalence is useful both for least squares
1154
+ fitting and for the evaluation of a large number of 2-D HermiteE
1155
+ series of the same degrees and sample points.
1156
+
1157
+ Parameters
1158
+ ----------
1159
+ x, y : array_like
1160
+ Arrays of point coordinates, all of the same shape. The dtypes
1161
+ will be converted to either float64 or complex128 depending on
1162
+ whether any of the elements are complex. Scalars are converted to
1163
+ 1-D arrays.
1164
+ deg : list of ints
1165
+ List of maximum degrees of the form [x_deg, y_deg].
1166
+
1167
+ Returns
1168
+ -------
1169
+ vander2d : ndarray
1170
+ The shape of the returned matrix is ``x.shape + (order,)``, where
1171
+ :math:`order = (deg[0]+1)*(deg[1]+1)`. The dtype will be the same
1172
+ as the converted `x` and `y`.
1173
+
1174
+ See Also
1175
+ --------
1176
+ hermevander, hermevander3d, hermeval2d, hermeval3d
1177
+ """
1178
+ return pu._vander_nd_flat((hermevander, hermevander), (x, y), deg)
1179
+
1180
+
1181
+ def hermevander3d(x, y, z, deg):
1182
+ """Pseudo-Vandermonde matrix of given degrees.
1183
+
1184
+ Returns the pseudo-Vandermonde matrix of degrees `deg` and sample
1185
+ points ``(x, y, z)``. If `l`, `m`, `n` are the given degrees in `x`, `y`, `z`,
1186
+ then Hehe pseudo-Vandermonde matrix is defined by
1187
+
1188
+ .. math:: V[..., (m+1)(n+1)i + (n+1)j + k] = He_i(x)*He_j(y)*He_k(z),
1189
+
1190
+ where ``0 <= i <= l``, ``0 <= j <= m``, and ``0 <= j <= n``. The leading
1191
+ indices of `V` index the points ``(x, y, z)`` and the last index encodes
1192
+ the degrees of the HermiteE polynomials.
1193
+
1194
+ If ``V = hermevander3d(x, y, z, [xdeg, ydeg, zdeg])``, then the columns
1195
+ of `V` correspond to the elements of a 3-D coefficient array `c` of
1196
+ shape (xdeg + 1, ydeg + 1, zdeg + 1) in the order
1197
+
1198
+ .. math:: c_{000}, c_{001}, c_{002},... , c_{010}, c_{011}, c_{012},...
1199
+
1200
+ and ``np.dot(V, c.flat)`` and ``hermeval3d(x, y, z, c)`` will be the
1201
+ same up to roundoff. This equivalence is useful both for least squares
1202
+ fitting and for the evaluation of a large number of 3-D HermiteE
1203
+ series of the same degrees and sample points.
1204
+
1205
+ Parameters
1206
+ ----------
1207
+ x, y, z : array_like
1208
+ Arrays of point coordinates, all of the same shape. The dtypes will
1209
+ be converted to either float64 or complex128 depending on whether
1210
+ any of the elements are complex. Scalars are converted to 1-D
1211
+ arrays.
1212
+ deg : list of ints
1213
+ List of maximum degrees of the form [x_deg, y_deg, z_deg].
1214
+
1215
+ Returns
1216
+ -------
1217
+ vander3d : ndarray
1218
+ The shape of the returned matrix is ``x.shape + (order,)``, where
1219
+ :math:`order = (deg[0]+1)*(deg[1]+1)*(deg[2]+1)`. The dtype will
1220
+ be the same as the converted `x`, `y`, and `z`.
1221
+
1222
+ See Also
1223
+ --------
1224
+ hermevander, hermevander3d, hermeval2d, hermeval3d
1225
+ """
1226
+ return pu._vander_nd_flat((hermevander, hermevander, hermevander), (x, y, z), deg)
1227
+
1228
+
1229
+ def hermefit(x, y, deg, rcond=None, full=False, w=None):
1230
+ """
1231
+ Least squares fit of Hermite series to data.
1232
+
1233
+ Return the coefficients of a HermiteE series of degree `deg` that is
1234
+ the least squares fit to the data values `y` given at points `x`. If
1235
+ `y` is 1-D the returned coefficients will also be 1-D. If `y` is 2-D
1236
+ multiple fits are done, one for each column of `y`, and the resulting
1237
+ coefficients are stored in the corresponding columns of a 2-D return.
1238
+ The fitted polynomial(s) are in the form
1239
+
1240
+ .. math:: p(x) = c_0 + c_1 * He_1(x) + ... + c_n * He_n(x),
1241
+
1242
+ where `n` is `deg`.
1243
+
1244
+ Parameters
1245
+ ----------
1246
+ x : array_like, shape (M,)
1247
+ x-coordinates of the M sample points ``(x[i], y[i])``.
1248
+ y : array_like, shape (M,) or (M, K)
1249
+ y-coordinates of the sample points. Several data sets of sample
1250
+ points sharing the same x-coordinates can be fitted at once by
1251
+ passing in a 2D-array that contains one dataset per column.
1252
+ deg : int or 1-D array_like
1253
+ Degree(s) of the fitting polynomials. If `deg` is a single integer
1254
+ all terms up to and including the `deg`'th term are included in the
1255
+ fit. For NumPy versions >= 1.11.0 a list of integers specifying the
1256
+ degrees of the terms to include may be used instead.
1257
+ rcond : float, optional
1258
+ Relative condition number of the fit. Singular values smaller than
1259
+ this relative to the largest singular value will be ignored. The
1260
+ default value is len(x)*eps, where eps is the relative precision of
1261
+ the float type, about 2e-16 in most cases.
1262
+ full : bool, optional
1263
+ Switch determining nature of return value. When it is False (the
1264
+ default) just the coefficients are returned, when True diagnostic
1265
+ information from the singular value decomposition is also returned.
1266
+ w : array_like, shape (`M`,), optional
1267
+ Weights. If not None, the weight ``w[i]`` applies to the unsquared
1268
+ residual ``y[i] - y_hat[i]`` at ``x[i]``. Ideally the weights are
1269
+ chosen so that the errors of the products ``w[i]*y[i]`` all have the
1270
+ same variance. When using inverse-variance weighting, use
1271
+ ``w[i] = 1/sigma(y[i])``. The default value is None.
1272
+
1273
+ Returns
1274
+ -------
1275
+ coef : ndarray, shape (M,) or (M, K)
1276
+ Hermite coefficients ordered from low to high. If `y` was 2-D,
1277
+ the coefficients for the data in column k of `y` are in column
1278
+ `k`.
1279
+
1280
+ [residuals, rank, singular_values, rcond] : list
1281
+ These values are only returned if ``full == True``
1282
+
1283
+ - residuals -- sum of squared residuals of the least squares fit
1284
+ - rank -- the numerical rank of the scaled Vandermonde matrix
1285
+ - singular_values -- singular values of the scaled Vandermonde matrix
1286
+ - rcond -- value of `rcond`.
1287
+
1288
+ For more details, see `numpy.linalg.lstsq`.
1289
+
1290
+ Warns
1291
+ -----
1292
+ RankWarning
1293
+ The rank of the coefficient matrix in the least-squares fit is
1294
+ deficient. The warning is only raised if ``full = False``. The
1295
+ warnings can be turned off by
1296
+
1297
+ >>> import warnings
1298
+ >>> warnings.simplefilter('ignore', np.exceptions.RankWarning)
1299
+
1300
+ See Also
1301
+ --------
1302
+ numpy.polynomial.chebyshev.chebfit
1303
+ numpy.polynomial.legendre.legfit
1304
+ numpy.polynomial.polynomial.polyfit
1305
+ numpy.polynomial.hermite.hermfit
1306
+ numpy.polynomial.laguerre.lagfit
1307
+ hermeval : Evaluates a Hermite series.
1308
+ hermevander : pseudo Vandermonde matrix of Hermite series.
1309
+ hermeweight : HermiteE weight function.
1310
+ numpy.linalg.lstsq : Computes a least-squares fit from the matrix.
1311
+ scipy.interpolate.UnivariateSpline : Computes spline fits.
1312
+
1313
+ Notes
1314
+ -----
1315
+ The solution is the coefficients of the HermiteE series `p` that
1316
+ minimizes the sum of the weighted squared errors
1317
+
1318
+ .. math:: E = \\sum_j w_j^2 * |y_j - p(x_j)|^2,
1319
+
1320
+ where the :math:`w_j` are the weights. This problem is solved by
1321
+ setting up the (typically) overdetermined matrix equation
1322
+
1323
+ .. math:: V(x) * c = w * y,
1324
+
1325
+ where `V` is the pseudo Vandermonde matrix of `x`, the elements of `c`
1326
+ are the coefficients to be solved for, and the elements of `y` are the
1327
+ observed values. This equation is then solved using the singular value
1328
+ decomposition of `V`.
1329
+
1330
+ If some of the singular values of `V` are so small that they are
1331
+ neglected, then a `~exceptions.RankWarning` will be issued. This means that
1332
+ the coefficient values may be poorly determined. Using a lower order fit
1333
+ will usually get rid of the warning. The `rcond` parameter can also be
1334
+ set to a value smaller than its default, but the resulting fit may be
1335
+ spurious and have large contributions from roundoff error.
1336
+
1337
+ Fits using HermiteE series are probably most useful when the data can
1338
+ be approximated by ``sqrt(w(x)) * p(x)``, where ``w(x)`` is the HermiteE
1339
+ weight. In that case the weight ``sqrt(w(x[i]))`` should be used
1340
+ together with data values ``y[i]/sqrt(w(x[i]))``. The weight function is
1341
+ available as `hermeweight`.
1342
+
1343
+ References
1344
+ ----------
1345
+ .. [1] Wikipedia, "Curve fitting",
1346
+ https://en.wikipedia.org/wiki/Curve_fitting
1347
+
1348
+ Examples
1349
+ --------
1350
+ >>> import numpy as np
1351
+ >>> from numpy.polynomial.hermite_e import hermefit, hermeval
1352
+ >>> x = np.linspace(-10, 10)
1353
+ >>> rng = np.random.default_rng()
1354
+ >>> err = rng.normal(scale=1./10, size=len(x))
1355
+ >>> y = hermeval(x, [1, 2, 3]) + err
1356
+ >>> hermefit(x, y, 2)
1357
+ array([1.02284196, 2.00032805, 2.99978457]) # may vary
1358
+
1359
+ """
1360
+ return pu._fit(hermevander, x, y, deg, rcond, full, w)
1361
+
1362
+
1363
+ def hermecompanion(c):
1364
+ """
1365
+ Return the scaled companion matrix of c.
1366
+
1367
+ The basis polynomials are scaled so that the companion matrix is
1368
+ symmetric when `c` is a HermiteE basis polynomial. This provides
1369
+ better eigenvalue estimates than the unscaled case and for basis
1370
+ polynomials the eigenvalues are guaranteed to be real if
1371
+ `numpy.linalg.eigvalsh` is used to obtain them.
1372
+
1373
+ Parameters
1374
+ ----------
1375
+ c : array_like
1376
+ 1-D array of HermiteE series coefficients ordered from low to high
1377
+ degree.
1378
+
1379
+ Returns
1380
+ -------
1381
+ mat : ndarray
1382
+ Scaled companion matrix of dimensions (deg, deg).
1383
+ """
1384
+ # c is a trimmed copy
1385
+ [c] = pu.as_series([c])
1386
+ if len(c) < 2:
1387
+ raise ValueError('Series must have maximum degree of at least 1.')
1388
+ if len(c) == 2:
1389
+ return np.array([[-c[0] / c[1]]])
1390
+
1391
+ n = len(c) - 1
1392
+ mat = np.zeros((n, n), dtype=c.dtype)
1393
+ scl = np.hstack((1., 1. / np.sqrt(np.arange(n - 1, 0, -1))))
1394
+ scl = np.multiply.accumulate(scl)[::-1]
1395
+ top = mat.reshape(-1)[1::n + 1]
1396
+ bot = mat.reshape(-1)[n::n + 1]
1397
+ top[...] = np.sqrt(np.arange(1, n))
1398
+ bot[...] = top
1399
+ mat[:, -1] -= scl * c[:-1] / c[-1]
1400
+ return mat
1401
+
1402
+
1403
+ def hermeroots(c):
1404
+ """
1405
+ Compute the roots of a HermiteE series.
1406
+
1407
+ Return the roots (a.k.a. "zeros") of the polynomial
1408
+
1409
+ .. math:: p(x) = \\sum_i c[i] * He_i(x).
1410
+
1411
+ Parameters
1412
+ ----------
1413
+ c : 1-D array_like
1414
+ 1-D array of coefficients.
1415
+
1416
+ Returns
1417
+ -------
1418
+ out : ndarray
1419
+ Array of the roots of the series. If all the roots are real,
1420
+ then `out` is also real, otherwise it is complex.
1421
+
1422
+ See Also
1423
+ --------
1424
+ numpy.polynomial.polynomial.polyroots
1425
+ numpy.polynomial.legendre.legroots
1426
+ numpy.polynomial.laguerre.lagroots
1427
+ numpy.polynomial.hermite.hermroots
1428
+ numpy.polynomial.chebyshev.chebroots
1429
+
1430
+ Notes
1431
+ -----
1432
+ The root estimates are obtained as the eigenvalues of the companion
1433
+ matrix, Roots far from the origin of the complex plane may have large
1434
+ errors due to the numerical instability of the series for such
1435
+ values. Roots with multiplicity greater than 1 will also show larger
1436
+ errors as the value of the series near such points is relatively
1437
+ insensitive to errors in the roots. Isolated roots near the origin can
1438
+ be improved by a few iterations of Newton's method.
1439
+
1440
+ The HermiteE series basis polynomials aren't powers of `x` so the
1441
+ results of this function may seem unintuitive.
1442
+
1443
+ Examples
1444
+ --------
1445
+ >>> from numpy.polynomial.hermite_e import hermeroots, hermefromroots
1446
+ >>> coef = hermefromroots([-1, 0, 1])
1447
+ >>> coef
1448
+ array([0., 2., 0., 1.])
1449
+ >>> hermeroots(coef)
1450
+ array([-1., 0., 1.]) # may vary
1451
+
1452
+ """
1453
+ # c is a trimmed copy
1454
+ [c] = pu.as_series([c])
1455
+ if len(c) <= 1:
1456
+ return np.array([], dtype=c.dtype)
1457
+ if len(c) == 2:
1458
+ return np.array([-c[0] / c[1]])
1459
+
1460
+ # rotated companion matrix reduces error
1461
+ m = hermecompanion(c)[::-1, ::-1]
1462
+ r = np.linalg.eigvals(m)
1463
+ r.sort()
1464
+ return r
1465
+
1466
+
1467
+ def _normed_hermite_e_n(x, n):
1468
+ """
1469
+ Evaluate a normalized HermiteE polynomial.
1470
+
1471
+ Compute the value of the normalized HermiteE polynomial of degree ``n``
1472
+ at the points ``x``.
1473
+
1474
+
1475
+ Parameters
1476
+ ----------
1477
+ x : ndarray of double.
1478
+ Points at which to evaluate the function
1479
+ n : int
1480
+ Degree of the normalized HermiteE function to be evaluated.
1481
+
1482
+ Returns
1483
+ -------
1484
+ values : ndarray
1485
+ The shape of the return value is described above.
1486
+
1487
+ Notes
1488
+ -----
1489
+ This function is needed for finding the Gauss points and integration
1490
+ weights for high degrees. The values of the standard HermiteE functions
1491
+ overflow when n >= 207.
1492
+
1493
+ """
1494
+ if n == 0:
1495
+ return np.full(x.shape, 1 / np.sqrt(np.sqrt(2 * np.pi)))
1496
+
1497
+ c0 = 0.
1498
+ c1 = 1. / np.sqrt(np.sqrt(2 * np.pi))
1499
+ nd = float(n)
1500
+ for i in range(n - 1):
1501
+ tmp = c0
1502
+ c0 = -c1 * np.sqrt((nd - 1.) / nd)
1503
+ c1 = tmp + c1 * x * np.sqrt(1. / nd)
1504
+ nd = nd - 1.0
1505
+ return c0 + c1 * x
1506
+
1507
+
1508
+ def hermegauss(deg):
1509
+ """
1510
+ Gauss-HermiteE quadrature.
1511
+
1512
+ Computes the sample points and weights for Gauss-HermiteE quadrature.
1513
+ These sample points and weights will correctly integrate polynomials of
1514
+ degree :math:`2*deg - 1` or less over the interval :math:`[-\\inf, \\inf]`
1515
+ with the weight function :math:`f(x) = \\exp(-x^2/2)`.
1516
+
1517
+ Parameters
1518
+ ----------
1519
+ deg : int
1520
+ Number of sample points and weights. It must be >= 1.
1521
+
1522
+ Returns
1523
+ -------
1524
+ x : ndarray
1525
+ 1-D ndarray containing the sample points.
1526
+ y : ndarray
1527
+ 1-D ndarray containing the weights.
1528
+
1529
+ Notes
1530
+ -----
1531
+ The results have only been tested up to degree 100, higher degrees may
1532
+ be problematic. The weights are determined by using the fact that
1533
+
1534
+ .. math:: w_k = c / (He'_n(x_k) * He_{n-1}(x_k))
1535
+
1536
+ where :math:`c` is a constant independent of :math:`k` and :math:`x_k`
1537
+ is the k'th root of :math:`He_n`, and then scaling the results to get
1538
+ the right value when integrating 1.
1539
+
1540
+ """
1541
+ ideg = pu._as_int(deg, "deg")
1542
+ if ideg <= 0:
1543
+ raise ValueError("deg must be a positive integer")
1544
+
1545
+ # first approximation of roots. We use the fact that the companion
1546
+ # matrix is symmetric in this case in order to obtain better zeros.
1547
+ c = np.array([0] * deg + [1])
1548
+ m = hermecompanion(c)
1549
+ x = np.linalg.eigvalsh(m)
1550
+
1551
+ # improve roots by one application of Newton
1552
+ dy = _normed_hermite_e_n(x, ideg)
1553
+ df = _normed_hermite_e_n(x, ideg - 1) * np.sqrt(ideg)
1554
+ x -= dy / df
1555
+
1556
+ # compute the weights. We scale the factor to avoid possible numerical
1557
+ # overflow.
1558
+ fm = _normed_hermite_e_n(x, ideg - 1)
1559
+ fm /= np.abs(fm).max()
1560
+ w = 1 / (fm * fm)
1561
+
1562
+ # for Hermite_e we can also symmetrize
1563
+ w = (w + w[::-1]) / 2
1564
+ x = (x - x[::-1]) / 2
1565
+
1566
+ # scale w to get the right value
1567
+ w *= np.sqrt(2 * np.pi) / w.sum()
1568
+
1569
+ return x, w
1570
+
1571
+
1572
+ def hermeweight(x):
1573
+ """Weight function of the Hermite_e polynomials.
1574
+
1575
+ The weight function is :math:`\\exp(-x^2/2)` and the interval of
1576
+ integration is :math:`[-\\inf, \\inf]`. the HermiteE polynomials are
1577
+ orthogonal, but not normalized, with respect to this weight function.
1578
+
1579
+ Parameters
1580
+ ----------
1581
+ x : array_like
1582
+ Values at which the weight function will be computed.
1583
+
1584
+ Returns
1585
+ -------
1586
+ w : ndarray
1587
+ The weight function at `x`.
1588
+ """
1589
+ w = np.exp(-.5 * x**2)
1590
+ return w
1591
+
1592
+
1593
+ #
1594
+ # HermiteE series class
1595
+ #
1596
+
1597
+ class HermiteE(ABCPolyBase):
1598
+ """A HermiteE series class.
1599
+
1600
+ The HermiteE class provides the standard Python numerical methods
1601
+ '+', '-', '*', '//', '%', 'divmod', '**', and '()' as well as the
1602
+ attributes and methods listed below.
1603
+
1604
+ Parameters
1605
+ ----------
1606
+ coef : array_like
1607
+ HermiteE coefficients in order of increasing degree, i.e,
1608
+ ``(1, 2, 3)`` gives ``1*He_0(x) + 2*He_1(X) + 3*He_2(x)``.
1609
+ domain : (2,) array_like, optional
1610
+ Domain to use. The interval ``[domain[0], domain[1]]`` is mapped
1611
+ to the interval ``[window[0], window[1]]`` by shifting and scaling.
1612
+ The default value is [-1., 1.].
1613
+ window : (2,) array_like, optional
1614
+ Window, see `domain` for its use. The default value is [-1., 1.].
1615
+ symbol : str, optional
1616
+ Symbol used to represent the independent variable in string
1617
+ representations of the polynomial expression, e.g. for printing.
1618
+ The symbol must be a valid Python identifier. Default value is 'x'.
1619
+
1620
+ .. versionadded:: 1.24
1621
+
1622
+ """
1623
+ # Virtual Functions
1624
+ _add = staticmethod(hermeadd)
1625
+ _sub = staticmethod(hermesub)
1626
+ _mul = staticmethod(hermemul)
1627
+ _div = staticmethod(hermediv)
1628
+ _pow = staticmethod(hermepow)
1629
+ _val = staticmethod(hermeval)
1630
+ _int = staticmethod(hermeint)
1631
+ _der = staticmethod(hermeder)
1632
+ _fit = staticmethod(hermefit)
1633
+ _line = staticmethod(hermeline)
1634
+ _roots = staticmethod(hermeroots)
1635
+ _fromroots = staticmethod(hermefromroots)
1636
+
1637
+ # Virtual properties
1638
+ domain = np.array(hermedomain)
1639
+ window = np.array(hermedomain)
1640
+ basis_name = 'He'
physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy/polynomial/hermite_e.pyi ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import Any, ClassVar, Final, Literal as L, TypeVar
2
+
3
+ import numpy as np
4
+ from numpy._typing import _Shape
5
+
6
+ from ._polybase import ABCPolyBase
7
+ from ._polytypes import (
8
+ _Array1,
9
+ _Array2,
10
+ _FuncBinOp,
11
+ _FuncCompanion,
12
+ _FuncDer,
13
+ _FuncFit,
14
+ _FuncFromRoots,
15
+ _FuncGauss,
16
+ _FuncInteg,
17
+ _FuncLine,
18
+ _FuncPoly2Ortho,
19
+ _FuncPow,
20
+ _FuncRoots,
21
+ _FuncUnOp,
22
+ _FuncVal,
23
+ _FuncVal2D,
24
+ _FuncVal3D,
25
+ _FuncVander,
26
+ _FuncVander2D,
27
+ _FuncVander3D,
28
+ _FuncWeight,
29
+ )
30
+ from .polyutils import trimcoef as hermetrim
31
+
32
+ __all__ = [
33
+ "hermezero",
34
+ "hermeone",
35
+ "hermex",
36
+ "hermedomain",
37
+ "hermeline",
38
+ "hermeadd",
39
+ "hermesub",
40
+ "hermemulx",
41
+ "hermemul",
42
+ "hermediv",
43
+ "hermepow",
44
+ "hermeval",
45
+ "hermeder",
46
+ "hermeint",
47
+ "herme2poly",
48
+ "poly2herme",
49
+ "hermefromroots",
50
+ "hermevander",
51
+ "hermefit",
52
+ "hermetrim",
53
+ "hermeroots",
54
+ "HermiteE",
55
+ "hermeval2d",
56
+ "hermeval3d",
57
+ "hermegrid2d",
58
+ "hermegrid3d",
59
+ "hermevander2d",
60
+ "hermevander3d",
61
+ "hermecompanion",
62
+ "hermegauss",
63
+ "hermeweight",
64
+ ]
65
+
66
+ _ShapeT = TypeVar("_ShapeT", bound=_Shape)
67
+
68
+ poly2herme: Final[_FuncPoly2Ortho] = ...
69
+ herme2poly: Final[_FuncUnOp] = ...
70
+
71
+ hermedomain: Final[_Array2[np.float64]] = ...
72
+ hermezero: Final[_Array1[np.int_]] = ...
73
+ hermeone: Final[_Array1[np.int_]] = ...
74
+ hermex: Final[_Array2[np.int_]] = ...
75
+
76
+ hermeline: Final[_FuncLine] = ...
77
+ hermefromroots: Final[_FuncFromRoots] = ...
78
+ hermeadd: Final[_FuncBinOp] = ...
79
+ hermesub: Final[_FuncBinOp] = ...
80
+ hermemulx: Final[_FuncUnOp] = ...
81
+ hermemul: Final[_FuncBinOp] = ...
82
+ hermediv: Final[_FuncBinOp] = ...
83
+ hermepow: Final[_FuncPow] = ...
84
+ hermeder: Final[_FuncDer] = ...
85
+ hermeint: Final[_FuncInteg] = ...
86
+ hermeval: Final[_FuncVal] = ...
87
+ hermeval2d: Final[_FuncVal2D] = ...
88
+ hermeval3d: Final[_FuncVal3D] = ...
89
+ hermegrid2d: Final[_FuncVal2D] = ...
90
+ hermegrid3d: Final[_FuncVal3D] = ...
91
+ hermevander: Final[_FuncVander] = ...
92
+ hermevander2d: Final[_FuncVander2D] = ...
93
+ hermevander3d: Final[_FuncVander3D] = ...
94
+ hermefit: Final[_FuncFit] = ...
95
+ hermecompanion: Final[_FuncCompanion] = ...
96
+ hermeroots: Final[_FuncRoots] = ...
97
+
98
+ def _normed_hermite_e_n(x: np.ndarray[_ShapeT, np.dtype[np.float64]], n: int) -> np.ndarray[_ShapeT, np.dtype[np.float64]]: ...
99
+
100
+ hermegauss: Final[_FuncGauss] = ...
101
+ hermeweight: Final[_FuncWeight] = ...
102
+
103
+ class HermiteE(ABCPolyBase[L["He"]]):
104
+ basis_name: ClassVar[L["He"]] = "He" # pyright: ignore[reportIncompatibleMethodOverride]
105
+ domain: _Array2[np.float64 | Any] = ... # pyright: ignore[reportIncompatibleMethodOverride]
106
+ window: _Array2[np.float64 | Any] = ... # pyright: ignore[reportIncompatibleMethodOverride]
physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy/polynomial/laguerre.py ADDED
@@ -0,0 +1,1673 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ ==================================================
3
+ Laguerre Series (:mod:`numpy.polynomial.laguerre`)
4
+ ==================================================
5
+
6
+ This module provides a number of objects (mostly functions) useful for
7
+ dealing with Laguerre series, including a `Laguerre` class that
8
+ encapsulates the usual arithmetic operations. (General information
9
+ on how this module represents and works with such polynomials is in the
10
+ docstring for its "parent" sub-package, `numpy.polynomial`).
11
+
12
+ Classes
13
+ -------
14
+ .. autosummary::
15
+ :toctree: generated/
16
+
17
+ Laguerre
18
+
19
+ Constants
20
+ ---------
21
+ .. autosummary::
22
+ :toctree: generated/
23
+
24
+ lagdomain
25
+ lagzero
26
+ lagone
27
+ lagx
28
+
29
+ Arithmetic
30
+ ----------
31
+ .. autosummary::
32
+ :toctree: generated/
33
+
34
+ lagadd
35
+ lagsub
36
+ lagmulx
37
+ lagmul
38
+ lagdiv
39
+ lagpow
40
+ lagval
41
+ lagval2d
42
+ lagval3d
43
+ laggrid2d
44
+ laggrid3d
45
+
46
+ Calculus
47
+ --------
48
+ .. autosummary::
49
+ :toctree: generated/
50
+
51
+ lagder
52
+ lagint
53
+
54
+ Misc Functions
55
+ --------------
56
+ .. autosummary::
57
+ :toctree: generated/
58
+
59
+ lagfromroots
60
+ lagroots
61
+ lagvander
62
+ lagvander2d
63
+ lagvander3d
64
+ laggauss
65
+ lagweight
66
+ lagcompanion
67
+ lagfit
68
+ lagtrim
69
+ lagline
70
+ lag2poly
71
+ poly2lag
72
+
73
+ See also
74
+ --------
75
+ `numpy.polynomial`
76
+
77
+ """
78
+ import numpy as np
79
+
80
+ from . import polyutils as pu
81
+ from ._polybase import ABCPolyBase
82
+
83
+ __all__ = [
84
+ 'lagzero', 'lagone', 'lagx', 'lagdomain', 'lagline', 'lagadd',
85
+ 'lagsub', 'lagmulx', 'lagmul', 'lagdiv', 'lagpow', 'lagval', 'lagder',
86
+ 'lagint', 'lag2poly', 'poly2lag', 'lagfromroots', 'lagvander',
87
+ 'lagfit', 'lagtrim', 'lagroots', 'Laguerre', 'lagval2d', 'lagval3d',
88
+ 'laggrid2d', 'laggrid3d', 'lagvander2d', 'lagvander3d', 'lagcompanion',
89
+ 'laggauss', 'lagweight']
90
+
91
+ lagtrim = pu.trimcoef
92
+
93
+
94
+ def poly2lag(pol):
95
+ """
96
+ poly2lag(pol)
97
+
98
+ Convert a polynomial to a Laguerre series.
99
+
100
+ Convert an array representing the coefficients of a polynomial (relative
101
+ to the "standard" basis) ordered from lowest degree to highest, to an
102
+ array of the coefficients of the equivalent Laguerre series, ordered
103
+ from lowest to highest degree.
104
+
105
+ Parameters
106
+ ----------
107
+ pol : array_like
108
+ 1-D array containing the polynomial coefficients
109
+
110
+ Returns
111
+ -------
112
+ c : ndarray
113
+ 1-D array containing the coefficients of the equivalent Laguerre
114
+ series.
115
+
116
+ See Also
117
+ --------
118
+ lag2poly
119
+
120
+ Notes
121
+ -----
122
+ The easy way to do conversions between polynomial basis sets
123
+ is to use the convert method of a class instance.
124
+
125
+ Examples
126
+ --------
127
+ >>> import numpy as np
128
+ >>> from numpy.polynomial.laguerre import poly2lag
129
+ >>> poly2lag(np.arange(4))
130
+ array([ 23., -63., 58., -18.])
131
+
132
+ """
133
+ [pol] = pu.as_series([pol])
134
+ res = 0
135
+ for p in pol[::-1]:
136
+ res = lagadd(lagmulx(res), p)
137
+ return res
138
+
139
+
140
+ def lag2poly(c):
141
+ """
142
+ Convert a Laguerre series to a polynomial.
143
+
144
+ Convert an array representing the coefficients of a Laguerre series,
145
+ ordered from lowest degree to highest, to an array of the coefficients
146
+ of the equivalent polynomial (relative to the "standard" basis) ordered
147
+ from lowest to highest degree.
148
+
149
+ Parameters
150
+ ----------
151
+ c : array_like
152
+ 1-D array containing the Laguerre series coefficients, ordered
153
+ from lowest order term to highest.
154
+
155
+ Returns
156
+ -------
157
+ pol : ndarray
158
+ 1-D array containing the coefficients of the equivalent polynomial
159
+ (relative to the "standard" basis) ordered from lowest order term
160
+ to highest.
161
+
162
+ See Also
163
+ --------
164
+ poly2lag
165
+
166
+ Notes
167
+ -----
168
+ The easy way to do conversions between polynomial basis sets
169
+ is to use the convert method of a class instance.
170
+
171
+ Examples
172
+ --------
173
+ >>> from numpy.polynomial.laguerre import lag2poly
174
+ >>> lag2poly([ 23., -63., 58., -18.])
175
+ array([0., 1., 2., 3.])
176
+
177
+ """
178
+ from .polynomial import polyadd, polymulx, polysub
179
+
180
+ [c] = pu.as_series([c])
181
+ n = len(c)
182
+ if n == 1:
183
+ return c
184
+ else:
185
+ c0 = c[-2]
186
+ c1 = c[-1]
187
+ # i is the current degree of c1
188
+ for i in range(n - 1, 1, -1):
189
+ tmp = c0
190
+ c0 = polysub(c[i - 2], (c1 * (i - 1)) / i)
191
+ c1 = polyadd(tmp, polysub((2 * i - 1) * c1, polymulx(c1)) / i)
192
+ return polyadd(c0, polysub(c1, polymulx(c1)))
193
+
194
+
195
+ #
196
+ # These are constant arrays are of integer type so as to be compatible
197
+ # with the widest range of other types, such as Decimal.
198
+ #
199
+
200
+ # Laguerre
201
+ lagdomain = np.array([0., 1.])
202
+
203
+ # Laguerre coefficients representing zero.
204
+ lagzero = np.array([0])
205
+
206
+ # Laguerre coefficients representing one.
207
+ lagone = np.array([1])
208
+
209
+ # Laguerre coefficients representing the identity x.
210
+ lagx = np.array([1, -1])
211
+
212
+
213
+ def lagline(off, scl):
214
+ """
215
+ Laguerre series whose graph is a straight line.
216
+
217
+ Parameters
218
+ ----------
219
+ off, scl : scalars
220
+ The specified line is given by ``off + scl*x``.
221
+
222
+ Returns
223
+ -------
224
+ y : ndarray
225
+ This module's representation of the Laguerre series for
226
+ ``off + scl*x``.
227
+
228
+ See Also
229
+ --------
230
+ numpy.polynomial.polynomial.polyline
231
+ numpy.polynomial.chebyshev.chebline
232
+ numpy.polynomial.legendre.legline
233
+ numpy.polynomial.hermite.hermline
234
+ numpy.polynomial.hermite_e.hermeline
235
+
236
+ Examples
237
+ --------
238
+ >>> from numpy.polynomial.laguerre import lagline, lagval
239
+ >>> lagval(0,lagline(3, 2))
240
+ 3.0
241
+ >>> lagval(1,lagline(3, 2))
242
+ 5.0
243
+
244
+ """
245
+ if scl != 0:
246
+ return np.array([off + scl, -scl])
247
+ else:
248
+ return np.array([off])
249
+
250
+
251
+ def lagfromroots(roots):
252
+ """
253
+ Generate a Laguerre series with given roots.
254
+
255
+ The function returns the coefficients of the polynomial
256
+
257
+ .. math:: p(x) = (x - r_0) * (x - r_1) * ... * (x - r_n),
258
+
259
+ in Laguerre form, where the :math:`r_n` are the roots specified in `roots`.
260
+ If a zero has multiplicity n, then it must appear in `roots` n times.
261
+ For instance, if 2 is a root of multiplicity three and 3 is a root of
262
+ multiplicity 2, then `roots` looks something like [2, 2, 2, 3, 3]. The
263
+ roots can appear in any order.
264
+
265
+ If the returned coefficients are `c`, then
266
+
267
+ .. math:: p(x) = c_0 + c_1 * L_1(x) + ... + c_n * L_n(x)
268
+
269
+ The coefficient of the last term is not generally 1 for monic
270
+ polynomials in Laguerre form.
271
+
272
+ Parameters
273
+ ----------
274
+ roots : array_like
275
+ Sequence containing the roots.
276
+
277
+ Returns
278
+ -------
279
+ out : ndarray
280
+ 1-D array of coefficients. If all roots are real then `out` is a
281
+ real array, if some of the roots are complex, then `out` is complex
282
+ even if all the coefficients in the result are real (see Examples
283
+ below).
284
+
285
+ See Also
286
+ --------
287
+ numpy.polynomial.polynomial.polyfromroots
288
+ numpy.polynomial.legendre.legfromroots
289
+ numpy.polynomial.chebyshev.chebfromroots
290
+ numpy.polynomial.hermite.hermfromroots
291
+ numpy.polynomial.hermite_e.hermefromroots
292
+
293
+ Examples
294
+ --------
295
+ >>> from numpy.polynomial.laguerre import lagfromroots, lagval
296
+ >>> coef = lagfromroots((-1, 0, 1))
297
+ >>> lagval((-1, 0, 1), coef)
298
+ array([0., 0., 0.])
299
+ >>> coef = lagfromroots((-1j, 1j))
300
+ >>> lagval((-1j, 1j), coef)
301
+ array([0.+0.j, 0.+0.j])
302
+
303
+ """
304
+ return pu._fromroots(lagline, lagmul, roots)
305
+
306
+
307
+ def lagadd(c1, c2):
308
+ """
309
+ Add one Laguerre series to another.
310
+
311
+ Returns the sum of two Laguerre series `c1` + `c2`. The arguments
312
+ are sequences of coefficients ordered from lowest order term to
313
+ highest, i.e., [1,2,3] represents the series ``P_0 + 2*P_1 + 3*P_2``.
314
+
315
+ Parameters
316
+ ----------
317
+ c1, c2 : array_like
318
+ 1-D arrays of Laguerre series coefficients ordered from low to
319
+ high.
320
+
321
+ Returns
322
+ -------
323
+ out : ndarray
324
+ Array representing the Laguerre series of their sum.
325
+
326
+ See Also
327
+ --------
328
+ lagsub, lagmulx, lagmul, lagdiv, lagpow
329
+
330
+ Notes
331
+ -----
332
+ Unlike multiplication, division, etc., the sum of two Laguerre series
333
+ is a Laguerre series (without having to "reproject" the result onto
334
+ the basis set) so addition, just like that of "standard" polynomials,
335
+ is simply "component-wise."
336
+
337
+ Examples
338
+ --------
339
+ >>> from numpy.polynomial.laguerre import lagadd
340
+ >>> lagadd([1, 2, 3], [1, 2, 3, 4])
341
+ array([2., 4., 6., 4.])
342
+
343
+ """
344
+ return pu._add(c1, c2)
345
+
346
+
347
+ def lagsub(c1, c2):
348
+ """
349
+ Subtract one Laguerre series from another.
350
+
351
+ Returns the difference of two Laguerre series `c1` - `c2`. The
352
+ sequences of coefficients are from lowest order term to highest, i.e.,
353
+ [1,2,3] represents the series ``P_0 + 2*P_1 + 3*P_2``.
354
+
355
+ Parameters
356
+ ----------
357
+ c1, c2 : array_like
358
+ 1-D arrays of Laguerre series coefficients ordered from low to
359
+ high.
360
+
361
+ Returns
362
+ -------
363
+ out : ndarray
364
+ Of Laguerre series coefficients representing their difference.
365
+
366
+ See Also
367
+ --------
368
+ lagadd, lagmulx, lagmul, lagdiv, lagpow
369
+
370
+ Notes
371
+ -----
372
+ Unlike multiplication, division, etc., the difference of two Laguerre
373
+ series is a Laguerre series (without having to "reproject" the result
374
+ onto the basis set) so subtraction, just like that of "standard"
375
+ polynomials, is simply "component-wise."
376
+
377
+ Examples
378
+ --------
379
+ >>> from numpy.polynomial.laguerre import lagsub
380
+ >>> lagsub([1, 2, 3, 4], [1, 2, 3])
381
+ array([0., 0., 0., 4.])
382
+
383
+ """
384
+ return pu._sub(c1, c2)
385
+
386
+
387
+ def lagmulx(c):
388
+ """Multiply a Laguerre series by x.
389
+
390
+ Multiply the Laguerre series `c` by x, where x is the independent
391
+ variable.
392
+
393
+
394
+ Parameters
395
+ ----------
396
+ c : array_like
397
+ 1-D array of Laguerre series coefficients ordered from low to
398
+ high.
399
+
400
+ Returns
401
+ -------
402
+ out : ndarray
403
+ Array representing the result of the multiplication.
404
+
405
+ See Also
406
+ --------
407
+ lagadd, lagsub, lagmul, lagdiv, lagpow
408
+
409
+ Notes
410
+ -----
411
+ The multiplication uses the recursion relationship for Laguerre
412
+ polynomials in the form
413
+
414
+ .. math::
415
+
416
+ xP_i(x) = (-(i + 1)*P_{i + 1}(x) + (2i + 1)P_{i}(x) - iP_{i - 1}(x))
417
+
418
+ Examples
419
+ --------
420
+ >>> from numpy.polynomial.laguerre import lagmulx
421
+ >>> lagmulx([1, 2, 3])
422
+ array([-1., -1., 11., -9.])
423
+
424
+ """
425
+ # c is a trimmed copy
426
+ [c] = pu.as_series([c])
427
+ # The zero series needs special treatment
428
+ if len(c) == 1 and c[0] == 0:
429
+ return c
430
+
431
+ prd = np.empty(len(c) + 1, dtype=c.dtype)
432
+ prd[0] = c[0]
433
+ prd[1] = -c[0]
434
+ for i in range(1, len(c)):
435
+ prd[i + 1] = -c[i] * (i + 1)
436
+ prd[i] += c[i] * (2 * i + 1)
437
+ prd[i - 1] -= c[i] * i
438
+ return prd
439
+
440
+
441
+ def lagmul(c1, c2):
442
+ """
443
+ Multiply one Laguerre series by another.
444
+
445
+ Returns the product of two Laguerre series `c1` * `c2`. The arguments
446
+ are sequences of coefficients, from lowest order "term" to highest,
447
+ e.g., [1,2,3] represents the series ``P_0 + 2*P_1 + 3*P_2``.
448
+
449
+ Parameters
450
+ ----------
451
+ c1, c2 : array_like
452
+ 1-D arrays of Laguerre series coefficients ordered from low to
453
+ high.
454
+
455
+ Returns
456
+ -------
457
+ out : ndarray
458
+ Of Laguerre series coefficients representing their product.
459
+
460
+ See Also
461
+ --------
462
+ lagadd, lagsub, lagmulx, lagdiv, lagpow
463
+
464
+ Notes
465
+ -----
466
+ In general, the (polynomial) product of two C-series results in terms
467
+ that are not in the Laguerre polynomial basis set. Thus, to express
468
+ the product as a Laguerre series, it is necessary to "reproject" the
469
+ product onto said basis set, which may produce "unintuitive" (but
470
+ correct) results; see Examples section below.
471
+
472
+ Examples
473
+ --------
474
+ >>> from numpy.polynomial.laguerre import lagmul
475
+ >>> lagmul([1, 2, 3], [0, 1, 2])
476
+ array([ 8., -13., 38., -51., 36.])
477
+
478
+ """
479
+ # s1, s2 are trimmed copies
480
+ [c1, c2] = pu.as_series([c1, c2])
481
+
482
+ if len(c1) > len(c2):
483
+ c = c2
484
+ xs = c1
485
+ else:
486
+ c = c1
487
+ xs = c2
488
+
489
+ if len(c) == 1:
490
+ c0 = c[0] * xs
491
+ c1 = 0
492
+ elif len(c) == 2:
493
+ c0 = c[0] * xs
494
+ c1 = c[1] * xs
495
+ else:
496
+ nd = len(c)
497
+ c0 = c[-2] * xs
498
+ c1 = c[-1] * xs
499
+ for i in range(3, len(c) + 1):
500
+ tmp = c0
501
+ nd = nd - 1
502
+ c0 = lagsub(c[-i] * xs, (c1 * (nd - 1)) / nd)
503
+ c1 = lagadd(tmp, lagsub((2 * nd - 1) * c1, lagmulx(c1)) / nd)
504
+ return lagadd(c0, lagsub(c1, lagmulx(c1)))
505
+
506
+
507
+ def lagdiv(c1, c2):
508
+ """
509
+ Divide one Laguerre series by another.
510
+
511
+ Returns the quotient-with-remainder of two Laguerre series
512
+ `c1` / `c2`. The arguments are sequences of coefficients from lowest
513
+ order "term" to highest, e.g., [1,2,3] represents the series
514
+ ``P_0 + 2*P_1 + 3*P_2``.
515
+
516
+ Parameters
517
+ ----------
518
+ c1, c2 : array_like
519
+ 1-D arrays of Laguerre series coefficients ordered from low to
520
+ high.
521
+
522
+ Returns
523
+ -------
524
+ [quo, rem] : ndarrays
525
+ Of Laguerre series coefficients representing the quotient and
526
+ remainder.
527
+
528
+ See Also
529
+ --------
530
+ lagadd, lagsub, lagmulx, lagmul, lagpow
531
+
532
+ Notes
533
+ -----
534
+ In general, the (polynomial) division of one Laguerre series by another
535
+ results in quotient and remainder terms that are not in the Laguerre
536
+ polynomial basis set. Thus, to express these results as a Laguerre
537
+ series, it is necessary to "reproject" the results onto the Laguerre
538
+ basis set, which may produce "unintuitive" (but correct) results; see
539
+ Examples section below.
540
+
541
+ Examples
542
+ --------
543
+ >>> from numpy.polynomial.laguerre import lagdiv
544
+ >>> lagdiv([ 8., -13., 38., -51., 36.], [0, 1, 2])
545
+ (array([1., 2., 3.]), array([0.]))
546
+ >>> lagdiv([ 9., -12., 38., -51., 36.], [0, 1, 2])
547
+ (array([1., 2., 3.]), array([1., 1.]))
548
+
549
+ """
550
+ return pu._div(lagmul, c1, c2)
551
+
552
+
553
+ def lagpow(c, pow, maxpower=16):
554
+ """Raise a Laguerre series to a power.
555
+
556
+ Returns the Laguerre series `c` raised to the power `pow`. The
557
+ argument `c` is a sequence of coefficients ordered from low to high.
558
+ i.e., [1,2,3] is the series ``P_0 + 2*P_1 + 3*P_2.``
559
+
560
+ Parameters
561
+ ----------
562
+ c : array_like
563
+ 1-D array of Laguerre series coefficients ordered from low to
564
+ high.
565
+ pow : integer
566
+ Power to which the series will be raised
567
+ maxpower : integer, optional
568
+ Maximum power allowed. This is mainly to limit growth of the series
569
+ to unmanageable size. Default is 16
570
+
571
+ Returns
572
+ -------
573
+ coef : ndarray
574
+ Laguerre series of power.
575
+
576
+ See Also
577
+ --------
578
+ lagadd, lagsub, lagmulx, lagmul, lagdiv
579
+
580
+ Examples
581
+ --------
582
+ >>> from numpy.polynomial.laguerre import lagpow
583
+ >>> lagpow([1, 2, 3], 2)
584
+ array([ 14., -16., 56., -72., 54.])
585
+
586
+ """
587
+ return pu._pow(lagmul, c, pow, maxpower)
588
+
589
+
590
+ def lagder(c, m=1, scl=1, axis=0):
591
+ """
592
+ Differentiate a Laguerre series.
593
+
594
+ Returns the Laguerre series coefficients `c` differentiated `m` times
595
+ along `axis`. At each iteration the result is multiplied by `scl` (the
596
+ scaling factor is for use in a linear change of variable). The argument
597
+ `c` is an array of coefficients from low to high degree along each
598
+ axis, e.g., [1,2,3] represents the series ``1*L_0 + 2*L_1 + 3*L_2``
599
+ while [[1,2],[1,2]] represents ``1*L_0(x)*L_0(y) + 1*L_1(x)*L_0(y) +
600
+ 2*L_0(x)*L_1(y) + 2*L_1(x)*L_1(y)`` if axis=0 is ``x`` and axis=1 is
601
+ ``y``.
602
+
603
+ Parameters
604
+ ----------
605
+ c : array_like
606
+ Array of Laguerre series coefficients. If `c` is multidimensional
607
+ the different axis correspond to different variables with the
608
+ degree in each axis given by the corresponding index.
609
+ m : int, optional
610
+ Number of derivatives taken, must be non-negative. (Default: 1)
611
+ scl : scalar, optional
612
+ Each differentiation is multiplied by `scl`. The end result is
613
+ multiplication by ``scl**m``. This is for use in a linear change of
614
+ variable. (Default: 1)
615
+ axis : int, optional
616
+ Axis over which the derivative is taken. (Default: 0).
617
+
618
+ Returns
619
+ -------
620
+ der : ndarray
621
+ Laguerre series of the derivative.
622
+
623
+ See Also
624
+ --------
625
+ lagint
626
+
627
+ Notes
628
+ -----
629
+ In general, the result of differentiating a Laguerre series does not
630
+ resemble the same operation on a power series. Thus the result of this
631
+ function may be "unintuitive," albeit correct; see Examples section
632
+ below.
633
+
634
+ Examples
635
+ --------
636
+ >>> from numpy.polynomial.laguerre import lagder
637
+ >>> lagder([ 1., 1., 1., -3.])
638
+ array([1., 2., 3.])
639
+ >>> lagder([ 1., 0., 0., -4., 3.], m=2)
640
+ array([1., 2., 3.])
641
+
642
+ """
643
+ c = np.array(c, ndmin=1, copy=True)
644
+ if c.dtype.char in '?bBhHiIlLqQpP':
645
+ c = c.astype(np.double)
646
+
647
+ cnt = pu._as_int(m, "the order of derivation")
648
+ iaxis = pu._as_int(axis, "the axis")
649
+ if cnt < 0:
650
+ raise ValueError("The order of derivation must be non-negative")
651
+ iaxis = np.lib.array_utils.normalize_axis_index(iaxis, c.ndim)
652
+
653
+ if cnt == 0:
654
+ return c
655
+
656
+ c = np.moveaxis(c, iaxis, 0)
657
+ n = len(c)
658
+ if cnt >= n:
659
+ c = c[:1] * 0
660
+ else:
661
+ for i in range(cnt):
662
+ n = n - 1
663
+ c *= scl
664
+ der = np.empty((n,) + c.shape[1:], dtype=c.dtype)
665
+ for j in range(n, 1, -1):
666
+ der[j - 1] = -c[j]
667
+ c[j - 1] += c[j]
668
+ der[0] = -c[1]
669
+ c = der
670
+ c = np.moveaxis(c, 0, iaxis)
671
+ return c
672
+
673
+
674
+ def lagint(c, m=1, k=[], lbnd=0, scl=1, axis=0):
675
+ """
676
+ Integrate a Laguerre series.
677
+
678
+ Returns the Laguerre series coefficients `c` integrated `m` times from
679
+ `lbnd` along `axis`. At each iteration the resulting series is
680
+ **multiplied** by `scl` and an integration constant, `k`, is added.
681
+ The scaling factor is for use in a linear change of variable. ("Buyer
682
+ beware": note that, depending on what one is doing, one may want `scl`
683
+ to be the reciprocal of what one might expect; for more information,
684
+ see the Notes section below.) The argument `c` is an array of
685
+ coefficients from low to high degree along each axis, e.g., [1,2,3]
686
+ represents the series ``L_0 + 2*L_1 + 3*L_2`` while [[1,2],[1,2]]
687
+ represents ``1*L_0(x)*L_0(y) + 1*L_1(x)*L_0(y) + 2*L_0(x)*L_1(y) +
688
+ 2*L_1(x)*L_1(y)`` if axis=0 is ``x`` and axis=1 is ``y``.
689
+
690
+
691
+ Parameters
692
+ ----------
693
+ c : array_like
694
+ Array of Laguerre series coefficients. If `c` is multidimensional
695
+ the different axis correspond to different variables with the
696
+ degree in each axis given by the corresponding index.
697
+ m : int, optional
698
+ Order of integration, must be positive. (Default: 1)
699
+ k : {[], list, scalar}, optional
700
+ Integration constant(s). The value of the first integral at
701
+ ``lbnd`` is the first value in the list, the value of the second
702
+ integral at ``lbnd`` is the second value, etc. If ``k == []`` (the
703
+ default), all constants are set to zero. If ``m == 1``, a single
704
+ scalar can be given instead of a list.
705
+ lbnd : scalar, optional
706
+ The lower bound of the integral. (Default: 0)
707
+ scl : scalar, optional
708
+ Following each integration the result is *multiplied* by `scl`
709
+ before the integration constant is added. (Default: 1)
710
+ axis : int, optional
711
+ Axis over which the integral is taken. (Default: 0).
712
+
713
+ Returns
714
+ -------
715
+ S : ndarray
716
+ Laguerre series coefficients of the integral.
717
+
718
+ Raises
719
+ ------
720
+ ValueError
721
+ If ``m < 0``, ``len(k) > m``, ``np.ndim(lbnd) != 0``, or
722
+ ``np.ndim(scl) != 0``.
723
+
724
+ See Also
725
+ --------
726
+ lagder
727
+
728
+ Notes
729
+ -----
730
+ Note that the result of each integration is *multiplied* by `scl`.
731
+ Why is this important to note? Say one is making a linear change of
732
+ variable :math:`u = ax + b` in an integral relative to `x`. Then
733
+ :math:`dx = du/a`, so one will need to set `scl` equal to
734
+ :math:`1/a` - perhaps not what one would have first thought.
735
+
736
+ Also note that, in general, the result of integrating a C-series needs
737
+ to be "reprojected" onto the C-series basis set. Thus, typically,
738
+ the result of this function is "unintuitive," albeit correct; see
739
+ Examples section below.
740
+
741
+ Examples
742
+ --------
743
+ >>> from numpy.polynomial.laguerre import lagint
744
+ >>> lagint([1,2,3])
745
+ array([ 1., 1., 1., -3.])
746
+ >>> lagint([1,2,3], m=2)
747
+ array([ 1., 0., 0., -4., 3.])
748
+ >>> lagint([1,2,3], k=1)
749
+ array([ 2., 1., 1., -3.])
750
+ >>> lagint([1,2,3], lbnd=-1)
751
+ array([11.5, 1. , 1. , -3. ])
752
+ >>> lagint([1,2], m=2, k=[1,2], lbnd=-1)
753
+ array([ 11.16666667, -5. , -3. , 2. ]) # may vary
754
+
755
+ """
756
+ c = np.array(c, ndmin=1, copy=True)
757
+ if c.dtype.char in '?bBhHiIlLqQpP':
758
+ c = c.astype(np.double)
759
+ if not np.iterable(k):
760
+ k = [k]
761
+ cnt = pu._as_int(m, "the order of integration")
762
+ iaxis = pu._as_int(axis, "the axis")
763
+ if cnt < 0:
764
+ raise ValueError("The order of integration must be non-negative")
765
+ if len(k) > cnt:
766
+ raise ValueError("Too many integration constants")
767
+ if np.ndim(lbnd) != 0:
768
+ raise ValueError("lbnd must be a scalar.")
769
+ if np.ndim(scl) != 0:
770
+ raise ValueError("scl must be a scalar.")
771
+ iaxis = np.lib.array_utils.normalize_axis_index(iaxis, c.ndim)
772
+
773
+ if cnt == 0:
774
+ return c
775
+
776
+ c = np.moveaxis(c, iaxis, 0)
777
+ k = list(k) + [0] * (cnt - len(k))
778
+ for i in range(cnt):
779
+ n = len(c)
780
+ c *= scl
781
+ if n == 1 and np.all(c[0] == 0):
782
+ c[0] += k[i]
783
+ else:
784
+ tmp = np.empty((n + 1,) + c.shape[1:], dtype=c.dtype)
785
+ tmp[0] = c[0]
786
+ tmp[1] = -c[0]
787
+ for j in range(1, n):
788
+ tmp[j] += c[j]
789
+ tmp[j + 1] = -c[j]
790
+ tmp[0] += k[i] - lagval(lbnd, tmp)
791
+ c = tmp
792
+ c = np.moveaxis(c, 0, iaxis)
793
+ return c
794
+
795
+
796
+ def lagval(x, c, tensor=True):
797
+ """
798
+ Evaluate a Laguerre series at points x.
799
+
800
+ If `c` is of length ``n + 1``, this function returns the value:
801
+
802
+ .. math:: p(x) = c_0 * L_0(x) + c_1 * L_1(x) + ... + c_n * L_n(x)
803
+
804
+ The parameter `x` is converted to an array only if it is a tuple or a
805
+ list, otherwise it is treated as a scalar. In either case, either `x`
806
+ or its elements must support multiplication and addition both with
807
+ themselves and with the elements of `c`.
808
+
809
+ If `c` is a 1-D array, then ``p(x)`` will have the same shape as `x`. If
810
+ `c` is multidimensional, then the shape of the result depends on the
811
+ value of `tensor`. If `tensor` is true the shape will be c.shape[1:] +
812
+ x.shape. If `tensor` is false the shape will be c.shape[1:]. Note that
813
+ scalars have shape (,).
814
+
815
+ Trailing zeros in the coefficients will be used in the evaluation, so
816
+ they should be avoided if efficiency is a concern.
817
+
818
+ Parameters
819
+ ----------
820
+ x : array_like, compatible object
821
+ If `x` is a list or tuple, it is converted to an ndarray, otherwise
822
+ it is left unchanged and treated as a scalar. In either case, `x`
823
+ or its elements must support addition and multiplication with
824
+ themselves and with the elements of `c`.
825
+ c : array_like
826
+ Array of coefficients ordered so that the coefficients for terms of
827
+ degree n are contained in c[n]. If `c` is multidimensional the
828
+ remaining indices enumerate multiple polynomials. In the two
829
+ dimensional case the coefficients may be thought of as stored in
830
+ the columns of `c`.
831
+ tensor : boolean, optional
832
+ If True, the shape of the coefficient array is extended with ones
833
+ on the right, one for each dimension of `x`. Scalars have dimension 0
834
+ for this action. The result is that every column of coefficients in
835
+ `c` is evaluated for every element of `x`. If False, `x` is broadcast
836
+ over the columns of `c` for the evaluation. This keyword is useful
837
+ when `c` is multidimensional. The default value is True.
838
+
839
+ Returns
840
+ -------
841
+ values : ndarray, algebra_like
842
+ The shape of the return value is described above.
843
+
844
+ See Also
845
+ --------
846
+ lagval2d, laggrid2d, lagval3d, laggrid3d
847
+
848
+ Notes
849
+ -----
850
+ The evaluation uses Clenshaw recursion, aka synthetic division.
851
+
852
+ Examples
853
+ --------
854
+ >>> from numpy.polynomial.laguerre import lagval
855
+ >>> coef = [1, 2, 3]
856
+ >>> lagval(1, coef)
857
+ -0.5
858
+ >>> lagval([[1, 2],[3, 4]], coef)
859
+ array([[-0.5, -4. ],
860
+ [-4.5, -2. ]])
861
+
862
+ """
863
+ c = np.array(c, ndmin=1, copy=None)
864
+ if c.dtype.char in '?bBhHiIlLqQpP':
865
+ c = c.astype(np.double)
866
+ if isinstance(x, (tuple, list)):
867
+ x = np.asarray(x)
868
+ if isinstance(x, np.ndarray) and tensor:
869
+ c = c.reshape(c.shape + (1,) * x.ndim)
870
+
871
+ if len(c) == 1:
872
+ c0 = c[0]
873
+ c1 = 0
874
+ elif len(c) == 2:
875
+ c0 = c[0]
876
+ c1 = c[1]
877
+ else:
878
+ nd = len(c)
879
+ c0 = c[-2]
880
+ c1 = c[-1]
881
+ for i in range(3, len(c) + 1):
882
+ tmp = c0
883
+ nd = nd - 1
884
+ c0 = c[-i] - (c1 * (nd - 1)) / nd
885
+ c1 = tmp + (c1 * ((2 * nd - 1) - x)) / nd
886
+ return c0 + c1 * (1 - x)
887
+
888
+
889
+ def lagval2d(x, y, c):
890
+ """
891
+ Evaluate a 2-D Laguerre series at points (x, y).
892
+
893
+ This function returns the values:
894
+
895
+ .. math:: p(x,y) = \\sum_{i,j} c_{i,j} * L_i(x) * L_j(y)
896
+
897
+ The parameters `x` and `y` are converted to arrays only if they are
898
+ tuples or a lists, otherwise they are treated as a scalars and they
899
+ must have the same shape after conversion. In either case, either `x`
900
+ and `y` or their elements must support multiplication and addition both
901
+ with themselves and with the elements of `c`.
902
+
903
+ If `c` is a 1-D array a one is implicitly appended to its shape to make
904
+ it 2-D. The shape of the result will be c.shape[2:] + x.shape.
905
+
906
+ Parameters
907
+ ----------
908
+ x, y : array_like, compatible objects
909
+ The two dimensional series is evaluated at the points ``(x, y)``,
910
+ where `x` and `y` must have the same shape. If `x` or `y` is a list
911
+ or tuple, it is first converted to an ndarray, otherwise it is left
912
+ unchanged and if it isn't an ndarray it is treated as a scalar.
913
+ c : array_like
914
+ Array of coefficients ordered so that the coefficient of the term
915
+ of multi-degree i,j is contained in ``c[i,j]``. If `c` has
916
+ dimension greater than two the remaining indices enumerate multiple
917
+ sets of coefficients.
918
+
919
+ Returns
920
+ -------
921
+ values : ndarray, compatible object
922
+ The values of the two dimensional polynomial at points formed with
923
+ pairs of corresponding values from `x` and `y`.
924
+
925
+ See Also
926
+ --------
927
+ lagval, laggrid2d, lagval3d, laggrid3d
928
+
929
+ Examples
930
+ --------
931
+ >>> from numpy.polynomial.laguerre import lagval2d
932
+ >>> c = [[1, 2],[3, 4]]
933
+ >>> lagval2d(1, 1, c)
934
+ 1.0
935
+ """
936
+ return pu._valnd(lagval, c, x, y)
937
+
938
+
939
+ def laggrid2d(x, y, c):
940
+ """
941
+ Evaluate a 2-D Laguerre series on the Cartesian product of x and y.
942
+
943
+ This function returns the values:
944
+
945
+ .. math:: p(a,b) = \\sum_{i,j} c_{i,j} * L_i(a) * L_j(b)
946
+
947
+ where the points ``(a, b)`` consist of all pairs formed by taking
948
+ `a` from `x` and `b` from `y`. The resulting points form a grid with
949
+ `x` in the first dimension and `y` in the second.
950
+
951
+ The parameters `x` and `y` are converted to arrays only if they are
952
+ tuples or a lists, otherwise they are treated as a scalars. In either
953
+ case, either `x` and `y` or their elements must support multiplication
954
+ and addition both with themselves and with the elements of `c`.
955
+
956
+ If `c` has fewer than two dimensions, ones are implicitly appended to
957
+ its shape to make it 2-D. The shape of the result will be c.shape[2:] +
958
+ x.shape + y.shape.
959
+
960
+ Parameters
961
+ ----------
962
+ x, y : array_like, compatible objects
963
+ The two dimensional series is evaluated at the points in the
964
+ Cartesian product of `x` and `y`. If `x` or `y` is a list or
965
+ tuple, it is first converted to an ndarray, otherwise it is left
966
+ unchanged and, if it isn't an ndarray, it is treated as a scalar.
967
+ c : array_like
968
+ Array of coefficients ordered so that the coefficient of the term of
969
+ multi-degree i,j is contained in ``c[i,j]``. If `c` has dimension
970
+ greater than two the remaining indices enumerate multiple sets of
971
+ coefficients.
972
+
973
+ Returns
974
+ -------
975
+ values : ndarray, compatible object
976
+ The values of the two dimensional Chebyshev series at points in the
977
+ Cartesian product of `x` and `y`.
978
+
979
+ See Also
980
+ --------
981
+ lagval, lagval2d, lagval3d, laggrid3d
982
+
983
+ Examples
984
+ --------
985
+ >>> from numpy.polynomial.laguerre import laggrid2d
986
+ >>> c = [[1, 2], [3, 4]]
987
+ >>> laggrid2d([0, 1], [0, 1], c)
988
+ array([[10., 4.],
989
+ [ 3., 1.]])
990
+
991
+ """
992
+ return pu._gridnd(lagval, c, x, y)
993
+
994
+
995
+ def lagval3d(x, y, z, c):
996
+ """
997
+ Evaluate a 3-D Laguerre series at points (x, y, z).
998
+
999
+ This function returns the values:
1000
+
1001
+ .. math:: p(x,y,z) = \\sum_{i,j,k} c_{i,j,k} * L_i(x) * L_j(y) * L_k(z)
1002
+
1003
+ The parameters `x`, `y`, and `z` are converted to arrays only if
1004
+ they are tuples or a lists, otherwise they are treated as a scalars and
1005
+ they must have the same shape after conversion. In either case, either
1006
+ `x`, `y`, and `z` or their elements must support multiplication and
1007
+ addition both with themselves and with the elements of `c`.
1008
+
1009
+ If `c` has fewer than 3 dimensions, ones are implicitly appended to its
1010
+ shape to make it 3-D. The shape of the result will be c.shape[3:] +
1011
+ x.shape.
1012
+
1013
+ Parameters
1014
+ ----------
1015
+ x, y, z : array_like, compatible object
1016
+ The three dimensional series is evaluated at the points
1017
+ ``(x, y, z)``, where `x`, `y`, and `z` must have the same shape. If
1018
+ any of `x`, `y`, or `z` is a list or tuple, it is first converted
1019
+ to an ndarray, otherwise it is left unchanged and if it isn't an
1020
+ ndarray it is treated as a scalar.
1021
+ c : array_like
1022
+ Array of coefficients ordered so that the coefficient of the term of
1023
+ multi-degree i,j,k is contained in ``c[i,j,k]``. If `c` has dimension
1024
+ greater than 3 the remaining indices enumerate multiple sets of
1025
+ coefficients.
1026
+
1027
+ Returns
1028
+ -------
1029
+ values : ndarray, compatible object
1030
+ The values of the multidimensional polynomial on points formed with
1031
+ triples of corresponding values from `x`, `y`, and `z`.
1032
+
1033
+ See Also
1034
+ --------
1035
+ lagval, lagval2d, laggrid2d, laggrid3d
1036
+
1037
+ Examples
1038
+ --------
1039
+ >>> from numpy.polynomial.laguerre import lagval3d
1040
+ >>> c = [[[1, 2], [3, 4]], [[5, 6], [7, 8]]]
1041
+ >>> lagval3d(1, 1, 2, c)
1042
+ -1.0
1043
+
1044
+ """
1045
+ return pu._valnd(lagval, c, x, y, z)
1046
+
1047
+
1048
+ def laggrid3d(x, y, z, c):
1049
+ """
1050
+ Evaluate a 3-D Laguerre series on the Cartesian product of x, y, and z.
1051
+
1052
+ This function returns the values:
1053
+
1054
+ .. math:: p(a,b,c) = \\sum_{i,j,k} c_{i,j,k} * L_i(a) * L_j(b) * L_k(c)
1055
+
1056
+ where the points ``(a, b, c)`` consist of all triples formed by taking
1057
+ `a` from `x`, `b` from `y`, and `c` from `z`. The resulting points form
1058
+ a grid with `x` in the first dimension, `y` in the second, and `z` in
1059
+ the third.
1060
+
1061
+ The parameters `x`, `y`, and `z` are converted to arrays only if they
1062
+ are tuples or a lists, otherwise they are treated as a scalars. In
1063
+ either case, either `x`, `y`, and `z` or their elements must support
1064
+ multiplication and addition both with themselves and with the elements
1065
+ of `c`.
1066
+
1067
+ If `c` has fewer than three dimensions, ones are implicitly appended to
1068
+ its shape to make it 3-D. The shape of the result will be c.shape[3:] +
1069
+ x.shape + y.shape + z.shape.
1070
+
1071
+ Parameters
1072
+ ----------
1073
+ x, y, z : array_like, compatible objects
1074
+ The three dimensional series is evaluated at the points in the
1075
+ Cartesian product of `x`, `y`, and `z`. If `x`, `y`, or `z` is a
1076
+ list or tuple, it is first converted to an ndarray, otherwise it is
1077
+ left unchanged and, if it isn't an ndarray, it is treated as a
1078
+ scalar.
1079
+ c : array_like
1080
+ Array of coefficients ordered so that the coefficients for terms of
1081
+ degree i,j are contained in ``c[i,j]``. If `c` has dimension
1082
+ greater than two the remaining indices enumerate multiple sets of
1083
+ coefficients.
1084
+
1085
+ Returns
1086
+ -------
1087
+ values : ndarray, compatible object
1088
+ The values of the two dimensional polynomial at points in the Cartesian
1089
+ product of `x` and `y`.
1090
+
1091
+ See Also
1092
+ --------
1093
+ lagval, lagval2d, laggrid2d, lagval3d
1094
+
1095
+ Examples
1096
+ --------
1097
+ >>> from numpy.polynomial.laguerre import laggrid3d
1098
+ >>> c = [[[1, 2], [3, 4]], [[5, 6], [7, 8]]]
1099
+ >>> laggrid3d([0, 1], [0, 1], [2, 4], c)
1100
+ array([[[ -4., -44.],
1101
+ [ -2., -18.]],
1102
+ [[ -2., -14.],
1103
+ [ -1., -5.]]])
1104
+
1105
+ """
1106
+ return pu._gridnd(lagval, c, x, y, z)
1107
+
1108
+
1109
+ def lagvander(x, deg):
1110
+ """Pseudo-Vandermonde matrix of given degree.
1111
+
1112
+ Returns the pseudo-Vandermonde matrix of degree `deg` and sample points
1113
+ `x`. The pseudo-Vandermonde matrix is defined by
1114
+
1115
+ .. math:: V[..., i] = L_i(x)
1116
+
1117
+ where ``0 <= i <= deg``. The leading indices of `V` index the elements of
1118
+ `x` and the last index is the degree of the Laguerre polynomial.
1119
+
1120
+ If `c` is a 1-D array of coefficients of length ``n + 1`` and `V` is the
1121
+ array ``V = lagvander(x, n)``, then ``np.dot(V, c)`` and
1122
+ ``lagval(x, c)`` are the same up to roundoff. This equivalence is
1123
+ useful both for least squares fitting and for the evaluation of a large
1124
+ number of Laguerre series of the same degree and sample points.
1125
+
1126
+ Parameters
1127
+ ----------
1128
+ x : array_like
1129
+ Array of points. The dtype is converted to float64 or complex128
1130
+ depending on whether any of the elements are complex. If `x` is
1131
+ scalar it is converted to a 1-D array.
1132
+ deg : int
1133
+ Degree of the resulting matrix.
1134
+
1135
+ Returns
1136
+ -------
1137
+ vander : ndarray
1138
+ The pseudo-Vandermonde matrix. The shape of the returned matrix is
1139
+ ``x.shape + (deg + 1,)``, where The last index is the degree of the
1140
+ corresponding Laguerre polynomial. The dtype will be the same as
1141
+ the converted `x`.
1142
+
1143
+ Examples
1144
+ --------
1145
+ >>> import numpy as np
1146
+ >>> from numpy.polynomial.laguerre import lagvander
1147
+ >>> x = np.array([0, 1, 2])
1148
+ >>> lagvander(x, 3)
1149
+ array([[ 1. , 1. , 1. , 1. ],
1150
+ [ 1. , 0. , -0.5 , -0.66666667],
1151
+ [ 1. , -1. , -1. , -0.33333333]])
1152
+
1153
+ """
1154
+ ideg = pu._as_int(deg, "deg")
1155
+ if ideg < 0:
1156
+ raise ValueError("deg must be non-negative")
1157
+
1158
+ x = np.array(x, copy=None, ndmin=1) + 0.0
1159
+ dims = (ideg + 1,) + x.shape
1160
+ dtyp = x.dtype
1161
+ v = np.empty(dims, dtype=dtyp)
1162
+ v[0] = x * 0 + 1
1163
+ if ideg > 0:
1164
+ v[1] = 1 - x
1165
+ for i in range(2, ideg + 1):
1166
+ v[i] = (v[i - 1] * (2 * i - 1 - x) - v[i - 2] * (i - 1)) / i
1167
+ return np.moveaxis(v, 0, -1)
1168
+
1169
+
1170
+ def lagvander2d(x, y, deg):
1171
+ """Pseudo-Vandermonde matrix of given degrees.
1172
+
1173
+ Returns the pseudo-Vandermonde matrix of degrees `deg` and sample
1174
+ points ``(x, y)``. The pseudo-Vandermonde matrix is defined by
1175
+
1176
+ .. math:: V[..., (deg[1] + 1)*i + j] = L_i(x) * L_j(y),
1177
+
1178
+ where ``0 <= i <= deg[0]`` and ``0 <= j <= deg[1]``. The leading indices of
1179
+ `V` index the points ``(x, y)`` and the last index encodes the degrees of
1180
+ the Laguerre polynomials.
1181
+
1182
+ If ``V = lagvander2d(x, y, [xdeg, ydeg])``, then the columns of `V`
1183
+ correspond to the elements of a 2-D coefficient array `c` of shape
1184
+ (xdeg + 1, ydeg + 1) in the order
1185
+
1186
+ .. math:: c_{00}, c_{01}, c_{02}, ... , c_{10}, c_{11}, c_{12}, ...
1187
+
1188
+ and ``np.dot(V, c.flat)`` and ``lagval2d(x, y, c)`` will be the same
1189
+ up to roundoff. This equivalence is useful both for least squares
1190
+ fitting and for the evaluation of a large number of 2-D Laguerre
1191
+ series of the same degrees and sample points.
1192
+
1193
+ Parameters
1194
+ ----------
1195
+ x, y : array_like
1196
+ Arrays of point coordinates, all of the same shape. The dtypes
1197
+ will be converted to either float64 or complex128 depending on
1198
+ whether any of the elements are complex. Scalars are converted to
1199
+ 1-D arrays.
1200
+ deg : list of ints
1201
+ List of maximum degrees of the form [x_deg, y_deg].
1202
+
1203
+ Returns
1204
+ -------
1205
+ vander2d : ndarray
1206
+ The shape of the returned matrix is ``x.shape + (order,)``, where
1207
+ :math:`order = (deg[0]+1)*(deg[1]+1)`. The dtype will be the same
1208
+ as the converted `x` and `y`.
1209
+
1210
+ See Also
1211
+ --------
1212
+ lagvander, lagvander3d, lagval2d, lagval3d
1213
+
1214
+ Examples
1215
+ --------
1216
+ >>> import numpy as np
1217
+ >>> from numpy.polynomial.laguerre import lagvander2d
1218
+ >>> x = np.array([0])
1219
+ >>> y = np.array([2])
1220
+ >>> lagvander2d(x, y, [2, 1])
1221
+ array([[ 1., -1., 1., -1., 1., -1.]])
1222
+
1223
+ """
1224
+ return pu._vander_nd_flat((lagvander, lagvander), (x, y), deg)
1225
+
1226
+
1227
+ def lagvander3d(x, y, z, deg):
1228
+ """Pseudo-Vandermonde matrix of given degrees.
1229
+
1230
+ Returns the pseudo-Vandermonde matrix of degrees `deg` and sample
1231
+ points ``(x, y, z)``. If `l`, `m`, `n` are the given degrees in `x`, `y`, `z`,
1232
+ then The pseudo-Vandermonde matrix is defined by
1233
+
1234
+ .. math:: V[..., (m+1)(n+1)i + (n+1)j + k] = L_i(x)*L_j(y)*L_k(z),
1235
+
1236
+ where ``0 <= i <= l``, ``0 <= j <= m``, and ``0 <= j <= n``. The leading
1237
+ indices of `V` index the points ``(x, y, z)`` and the last index encodes
1238
+ the degrees of the Laguerre polynomials.
1239
+
1240
+ If ``V = lagvander3d(x, y, z, [xdeg, ydeg, zdeg])``, then the columns
1241
+ of `V` correspond to the elements of a 3-D coefficient array `c` of
1242
+ shape (xdeg + 1, ydeg + 1, zdeg + 1) in the order
1243
+
1244
+ .. math:: c_{000}, c_{001}, c_{002},... , c_{010}, c_{011}, c_{012},...
1245
+
1246
+ and ``np.dot(V, c.flat)`` and ``lagval3d(x, y, z, c)`` will be the
1247
+ same up to roundoff. This equivalence is useful both for least squares
1248
+ fitting and for the evaluation of a large number of 3-D Laguerre
1249
+ series of the same degrees and sample points.
1250
+
1251
+ Parameters
1252
+ ----------
1253
+ x, y, z : array_like
1254
+ Arrays of point coordinates, all of the same shape. The dtypes will
1255
+ be converted to either float64 or complex128 depending on whether
1256
+ any of the elements are complex. Scalars are converted to 1-D
1257
+ arrays.
1258
+ deg : list of ints
1259
+ List of maximum degrees of the form [x_deg, y_deg, z_deg].
1260
+
1261
+ Returns
1262
+ -------
1263
+ vander3d : ndarray
1264
+ The shape of the returned matrix is ``x.shape + (order,)``, where
1265
+ :math:`order = (deg[0]+1)*(deg[1]+1)*(deg[2]+1)`. The dtype will
1266
+ be the same as the converted `x`, `y`, and `z`.
1267
+
1268
+ See Also
1269
+ --------
1270
+ lagvander, lagvander3d, lagval2d, lagval3d
1271
+
1272
+ Examples
1273
+ --------
1274
+ >>> import numpy as np
1275
+ >>> from numpy.polynomial.laguerre import lagvander3d
1276
+ >>> x = np.array([0])
1277
+ >>> y = np.array([2])
1278
+ >>> z = np.array([0])
1279
+ >>> lagvander3d(x, y, z, [2, 1, 3])
1280
+ array([[ 1., 1., 1., 1., -1., -1., -1., -1., 1., 1., 1., 1., -1.,
1281
+ -1., -1., -1., 1., 1., 1., 1., -1., -1., -1., -1.]])
1282
+
1283
+ """
1284
+ return pu._vander_nd_flat((lagvander, lagvander, lagvander), (x, y, z), deg)
1285
+
1286
+
1287
+ def lagfit(x, y, deg, rcond=None, full=False, w=None):
1288
+ """
1289
+ Least squares fit of Laguerre series to data.
1290
+
1291
+ Return the coefficients of a Laguerre series of degree `deg` that is the
1292
+ least squares fit to the data values `y` given at points `x`. If `y` is
1293
+ 1-D the returned coefficients will also be 1-D. If `y` is 2-D multiple
1294
+ fits are done, one for each column of `y`, and the resulting
1295
+ coefficients are stored in the corresponding columns of a 2-D return.
1296
+ The fitted polynomial(s) are in the form
1297
+
1298
+ .. math:: p(x) = c_0 + c_1 * L_1(x) + ... + c_n * L_n(x),
1299
+
1300
+ where ``n`` is `deg`.
1301
+
1302
+ Parameters
1303
+ ----------
1304
+ x : array_like, shape (M,)
1305
+ x-coordinates of the M sample points ``(x[i], y[i])``.
1306
+ y : array_like, shape (M,) or (M, K)
1307
+ y-coordinates of the sample points. Several data sets of sample
1308
+ points sharing the same x-coordinates can be fitted at once by
1309
+ passing in a 2D-array that contains one dataset per column.
1310
+ deg : int or 1-D array_like
1311
+ Degree(s) of the fitting polynomials. If `deg` is a single integer
1312
+ all terms up to and including the `deg`'th term are included in the
1313
+ fit. For NumPy versions >= 1.11.0 a list of integers specifying the
1314
+ degrees of the terms to include may be used instead.
1315
+ rcond : float, optional
1316
+ Relative condition number of the fit. Singular values smaller than
1317
+ this relative to the largest singular value will be ignored. The
1318
+ default value is len(x)*eps, where eps is the relative precision of
1319
+ the float type, about 2e-16 in most cases.
1320
+ full : bool, optional
1321
+ Switch determining nature of return value. When it is False (the
1322
+ default) just the coefficients are returned, when True diagnostic
1323
+ information from the singular value decomposition is also returned.
1324
+ w : array_like, shape (`M`,), optional
1325
+ Weights. If not None, the weight ``w[i]`` applies to the unsquared
1326
+ residual ``y[i] - y_hat[i]`` at ``x[i]``. Ideally the weights are
1327
+ chosen so that the errors of the products ``w[i]*y[i]`` all have the
1328
+ same variance. When using inverse-variance weighting, use
1329
+ ``w[i] = 1/sigma(y[i])``. The default value is None.
1330
+
1331
+ Returns
1332
+ -------
1333
+ coef : ndarray, shape (M,) or (M, K)
1334
+ Laguerre coefficients ordered from low to high. If `y` was 2-D,
1335
+ the coefficients for the data in column *k* of `y` are in column
1336
+ *k*.
1337
+
1338
+ [residuals, rank, singular_values, rcond] : list
1339
+ These values are only returned if ``full == True``
1340
+
1341
+ - residuals -- sum of squared residuals of the least squares fit
1342
+ - rank -- the numerical rank of the scaled Vandermonde matrix
1343
+ - singular_values -- singular values of the scaled Vandermonde matrix
1344
+ - rcond -- value of `rcond`.
1345
+
1346
+ For more details, see `numpy.linalg.lstsq`.
1347
+
1348
+ Warns
1349
+ -----
1350
+ RankWarning
1351
+ The rank of the coefficient matrix in the least-squares fit is
1352
+ deficient. The warning is only raised if ``full == False``. The
1353
+ warnings can be turned off by
1354
+
1355
+ >>> import warnings
1356
+ >>> warnings.simplefilter('ignore', np.exceptions.RankWarning)
1357
+
1358
+ See Also
1359
+ --------
1360
+ numpy.polynomial.polynomial.polyfit
1361
+ numpy.polynomial.legendre.legfit
1362
+ numpy.polynomial.chebyshev.chebfit
1363
+ numpy.polynomial.hermite.hermfit
1364
+ numpy.polynomial.hermite_e.hermefit
1365
+ lagval : Evaluates a Laguerre series.
1366
+ lagvander : pseudo Vandermonde matrix of Laguerre series.
1367
+ lagweight : Laguerre weight function.
1368
+ numpy.linalg.lstsq : Computes a least-squares fit from the matrix.
1369
+ scipy.interpolate.UnivariateSpline : Computes spline fits.
1370
+
1371
+ Notes
1372
+ -----
1373
+ The solution is the coefficients of the Laguerre series ``p`` that
1374
+ minimizes the sum of the weighted squared errors
1375
+
1376
+ .. math:: E = \\sum_j w_j^2 * |y_j - p(x_j)|^2,
1377
+
1378
+ where the :math:`w_j` are the weights. This problem is solved by
1379
+ setting up as the (typically) overdetermined matrix equation
1380
+
1381
+ .. math:: V(x) * c = w * y,
1382
+
1383
+ where ``V`` is the weighted pseudo Vandermonde matrix of `x`, ``c`` are the
1384
+ coefficients to be solved for, `w` are the weights, and `y` are the
1385
+ observed values. This equation is then solved using the singular value
1386
+ decomposition of ``V``.
1387
+
1388
+ If some of the singular values of `V` are so small that they are
1389
+ neglected, then a `~exceptions.RankWarning` will be issued. This means that
1390
+ the coefficient values may be poorly determined. Using a lower order fit
1391
+ will usually get rid of the warning. The `rcond` parameter can also be
1392
+ set to a value smaller than its default, but the resulting fit may be
1393
+ spurious and have large contributions from roundoff error.
1394
+
1395
+ Fits using Laguerre series are probably most useful when the data can
1396
+ be approximated by ``sqrt(w(x)) * p(x)``, where ``w(x)`` is the Laguerre
1397
+ weight. In that case the weight ``sqrt(w(x[i]))`` should be used
1398
+ together with data values ``y[i]/sqrt(w(x[i]))``. The weight function is
1399
+ available as `lagweight`.
1400
+
1401
+ References
1402
+ ----------
1403
+ .. [1] Wikipedia, "Curve fitting",
1404
+ https://en.wikipedia.org/wiki/Curve_fitting
1405
+
1406
+ Examples
1407
+ --------
1408
+ >>> import numpy as np
1409
+ >>> from numpy.polynomial.laguerre import lagfit, lagval
1410
+ >>> x = np.linspace(0, 10)
1411
+ >>> rng = np.random.default_rng()
1412
+ >>> err = rng.normal(scale=1./10, size=len(x))
1413
+ >>> y = lagval(x, [1, 2, 3]) + err
1414
+ >>> lagfit(x, y, 2)
1415
+ array([1.00578369, 1.99417356, 2.99827656]) # may vary
1416
+
1417
+ """
1418
+ return pu._fit(lagvander, x, y, deg, rcond, full, w)
1419
+
1420
+
1421
+ def lagcompanion(c):
1422
+ """
1423
+ Return the companion matrix of c.
1424
+
1425
+ The usual companion matrix of the Laguerre polynomials is already
1426
+ symmetric when `c` is a basis Laguerre polynomial, so no scaling is
1427
+ applied.
1428
+
1429
+ Parameters
1430
+ ----------
1431
+ c : array_like
1432
+ 1-D array of Laguerre series coefficients ordered from low to high
1433
+ degree.
1434
+
1435
+ Returns
1436
+ -------
1437
+ mat : ndarray
1438
+ Companion matrix of dimensions (deg, deg).
1439
+
1440
+ Examples
1441
+ --------
1442
+ >>> from numpy.polynomial.laguerre import lagcompanion
1443
+ >>> lagcompanion([1, 2, 3])
1444
+ array([[ 1. , -0.33333333],
1445
+ [-1. , 4.33333333]])
1446
+
1447
+ """
1448
+ # c is a trimmed copy
1449
+ [c] = pu.as_series([c])
1450
+ if len(c) < 2:
1451
+ raise ValueError('Series must have maximum degree of at least 1.')
1452
+ if len(c) == 2:
1453
+ return np.array([[1 + c[0] / c[1]]])
1454
+
1455
+ n = len(c) - 1
1456
+ mat = np.zeros((n, n), dtype=c.dtype)
1457
+ top = mat.reshape(-1)[1::n + 1]
1458
+ mid = mat.reshape(-1)[0::n + 1]
1459
+ bot = mat.reshape(-1)[n::n + 1]
1460
+ top[...] = -np.arange(1, n)
1461
+ mid[...] = 2. * np.arange(n) + 1.
1462
+ bot[...] = top
1463
+ mat[:, -1] += (c[:-1] / c[-1]) * n
1464
+ return mat
1465
+
1466
+
1467
+ def lagroots(c):
1468
+ """
1469
+ Compute the roots of a Laguerre series.
1470
+
1471
+ Return the roots (a.k.a. "zeros") of the polynomial
1472
+
1473
+ .. math:: p(x) = \\sum_i c[i] * L_i(x).
1474
+
1475
+ Parameters
1476
+ ----------
1477
+ c : 1-D array_like
1478
+ 1-D array of coefficients.
1479
+
1480
+ Returns
1481
+ -------
1482
+ out : ndarray
1483
+ Array of the roots of the series. If all the roots are real,
1484
+ then `out` is also real, otherwise it is complex.
1485
+
1486
+ See Also
1487
+ --------
1488
+ numpy.polynomial.polynomial.polyroots
1489
+ numpy.polynomial.legendre.legroots
1490
+ numpy.polynomial.chebyshev.chebroots
1491
+ numpy.polynomial.hermite.hermroots
1492
+ numpy.polynomial.hermite_e.hermeroots
1493
+
1494
+ Notes
1495
+ -----
1496
+ The root estimates are obtained as the eigenvalues of the companion
1497
+ matrix, Roots far from the origin of the complex plane may have large
1498
+ errors due to the numerical instability of the series for such
1499
+ values. Roots with multiplicity greater than 1 will also show larger
1500
+ errors as the value of the series near such points is relatively
1501
+ insensitive to errors in the roots. Isolated roots near the origin can
1502
+ be improved by a few iterations of Newton's method.
1503
+
1504
+ The Laguerre series basis polynomials aren't powers of `x` so the
1505
+ results of this function may seem unintuitive.
1506
+
1507
+ Examples
1508
+ --------
1509
+ >>> from numpy.polynomial.laguerre import lagroots, lagfromroots
1510
+ >>> coef = lagfromroots([0, 1, 2])
1511
+ >>> coef
1512
+ array([ 2., -8., 12., -6.])
1513
+ >>> lagroots(coef)
1514
+ array([-4.4408921e-16, 1.0000000e+00, 2.0000000e+00])
1515
+
1516
+ """
1517
+ # c is a trimmed copy
1518
+ [c] = pu.as_series([c])
1519
+ if len(c) <= 1:
1520
+ return np.array([], dtype=c.dtype)
1521
+ if len(c) == 2:
1522
+ return np.array([1 + c[0] / c[1]])
1523
+
1524
+ # rotated companion matrix reduces error
1525
+ m = lagcompanion(c)[::-1, ::-1]
1526
+ r = np.linalg.eigvals(m)
1527
+ r.sort()
1528
+ return r
1529
+
1530
+
1531
+ def laggauss(deg):
1532
+ """
1533
+ Gauss-Laguerre quadrature.
1534
+
1535
+ Computes the sample points and weights for Gauss-Laguerre quadrature.
1536
+ These sample points and weights will correctly integrate polynomials of
1537
+ degree :math:`2*deg - 1` or less over the interval :math:`[0, \\inf]`
1538
+ with the weight function :math:`f(x) = \\exp(-x)`.
1539
+
1540
+ Parameters
1541
+ ----------
1542
+ deg : int
1543
+ Number of sample points and weights. It must be >= 1.
1544
+
1545
+ Returns
1546
+ -------
1547
+ x : ndarray
1548
+ 1-D ndarray containing the sample points.
1549
+ y : ndarray
1550
+ 1-D ndarray containing the weights.
1551
+
1552
+ Notes
1553
+ -----
1554
+ The results have only been tested up to degree 100 higher degrees may
1555
+ be problematic. The weights are determined by using the fact that
1556
+
1557
+ .. math:: w_k = c / (L'_n(x_k) * L_{n-1}(x_k))
1558
+
1559
+ where :math:`c` is a constant independent of :math:`k` and :math:`x_k`
1560
+ is the k'th root of :math:`L_n`, and then scaling the results to get
1561
+ the right value when integrating 1.
1562
+
1563
+ Examples
1564
+ --------
1565
+ >>> from numpy.polynomial.laguerre import laggauss
1566
+ >>> laggauss(2)
1567
+ (array([0.58578644, 3.41421356]), array([0.85355339, 0.14644661]))
1568
+
1569
+ """
1570
+ ideg = pu._as_int(deg, "deg")
1571
+ if ideg <= 0:
1572
+ raise ValueError("deg must be a positive integer")
1573
+
1574
+ # first approximation of roots. We use the fact that the companion
1575
+ # matrix is symmetric in this case in order to obtain better zeros.
1576
+ c = np.array([0] * deg + [1])
1577
+ m = lagcompanion(c)
1578
+ x = np.linalg.eigvalsh(m)
1579
+
1580
+ # improve roots by one application of Newton
1581
+ dy = lagval(x, c)
1582
+ df = lagval(x, lagder(c))
1583
+ x -= dy / df
1584
+
1585
+ # compute the weights. We scale the factor to avoid possible numerical
1586
+ # overflow.
1587
+ fm = lagval(x, c[1:])
1588
+ fm /= np.abs(fm).max()
1589
+ df /= np.abs(df).max()
1590
+ w = 1 / (fm * df)
1591
+
1592
+ # scale w to get the right value, 1 in this case
1593
+ w /= w.sum()
1594
+
1595
+ return x, w
1596
+
1597
+
1598
+ def lagweight(x):
1599
+ """Weight function of the Laguerre polynomials.
1600
+
1601
+ The weight function is :math:`exp(-x)` and the interval of integration
1602
+ is :math:`[0, \\inf]`. The Laguerre polynomials are orthogonal, but not
1603
+ normalized, with respect to this weight function.
1604
+
1605
+ Parameters
1606
+ ----------
1607
+ x : array_like
1608
+ Values at which the weight function will be computed.
1609
+
1610
+ Returns
1611
+ -------
1612
+ w : ndarray
1613
+ The weight function at `x`.
1614
+
1615
+ Examples
1616
+ --------
1617
+ >>> from numpy.polynomial.laguerre import lagweight
1618
+ >>> x = np.array([0, 1, 2])
1619
+ >>> lagweight(x)
1620
+ array([1. , 0.36787944, 0.13533528])
1621
+
1622
+ """
1623
+ w = np.exp(-x)
1624
+ return w
1625
+
1626
+ #
1627
+ # Laguerre series class
1628
+ #
1629
+
1630
+ class Laguerre(ABCPolyBase):
1631
+ """A Laguerre series class.
1632
+
1633
+ The Laguerre class provides the standard Python numerical methods
1634
+ '+', '-', '*', '//', '%', 'divmod', '**', and '()' as well as the
1635
+ attributes and methods listed below.
1636
+
1637
+ Parameters
1638
+ ----------
1639
+ coef : array_like
1640
+ Laguerre coefficients in order of increasing degree, i.e,
1641
+ ``(1, 2, 3)`` gives ``1*L_0(x) + 2*L_1(X) + 3*L_2(x)``.
1642
+ domain : (2,) array_like, optional
1643
+ Domain to use. The interval ``[domain[0], domain[1]]`` is mapped
1644
+ to the interval ``[window[0], window[1]]`` by shifting and scaling.
1645
+ The default value is [0., 1.].
1646
+ window : (2,) array_like, optional
1647
+ Window, see `domain` for its use. The default value is [0., 1.].
1648
+ symbol : str, optional
1649
+ Symbol used to represent the independent variable in string
1650
+ representations of the polynomial expression, e.g. for printing.
1651
+ The symbol must be a valid Python identifier. Default value is 'x'.
1652
+
1653
+ .. versionadded:: 1.24
1654
+
1655
+ """
1656
+ # Virtual Functions
1657
+ _add = staticmethod(lagadd)
1658
+ _sub = staticmethod(lagsub)
1659
+ _mul = staticmethod(lagmul)
1660
+ _div = staticmethod(lagdiv)
1661
+ _pow = staticmethod(lagpow)
1662
+ _val = staticmethod(lagval)
1663
+ _int = staticmethod(lagint)
1664
+ _der = staticmethod(lagder)
1665
+ _fit = staticmethod(lagfit)
1666
+ _line = staticmethod(lagline)
1667
+ _roots = staticmethod(lagroots)
1668
+ _fromroots = staticmethod(lagfromroots)
1669
+
1670
+ # Virtual properties
1671
+ domain = np.array(lagdomain)
1672
+ window = np.array(lagdomain)
1673
+ basis_name = 'L'
physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy/polynomial/laguerre.pyi ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import Any, ClassVar, Final, Literal as L
2
+
3
+ import numpy as np
4
+
5
+ from ._polybase import ABCPolyBase
6
+ from ._polytypes import (
7
+ _Array1,
8
+ _Array2,
9
+ _FuncBinOp,
10
+ _FuncCompanion,
11
+ _FuncDer,
12
+ _FuncFit,
13
+ _FuncFromRoots,
14
+ _FuncGauss,
15
+ _FuncInteg,
16
+ _FuncLine,
17
+ _FuncPoly2Ortho,
18
+ _FuncPow,
19
+ _FuncRoots,
20
+ _FuncUnOp,
21
+ _FuncVal,
22
+ _FuncVal2D,
23
+ _FuncVal3D,
24
+ _FuncVander,
25
+ _FuncVander2D,
26
+ _FuncVander3D,
27
+ _FuncWeight,
28
+ )
29
+ from .polyutils import trimcoef as lagtrim
30
+
31
+ __all__ = [
32
+ "lagzero",
33
+ "lagone",
34
+ "lagx",
35
+ "lagdomain",
36
+ "lagline",
37
+ "lagadd",
38
+ "lagsub",
39
+ "lagmulx",
40
+ "lagmul",
41
+ "lagdiv",
42
+ "lagpow",
43
+ "lagval",
44
+ "lagder",
45
+ "lagint",
46
+ "lag2poly",
47
+ "poly2lag",
48
+ "lagfromroots",
49
+ "lagvander",
50
+ "lagfit",
51
+ "lagtrim",
52
+ "lagroots",
53
+ "Laguerre",
54
+ "lagval2d",
55
+ "lagval3d",
56
+ "laggrid2d",
57
+ "laggrid3d",
58
+ "lagvander2d",
59
+ "lagvander3d",
60
+ "lagcompanion",
61
+ "laggauss",
62
+ "lagweight",
63
+ ]
64
+
65
+ poly2lag: Final[_FuncPoly2Ortho] = ...
66
+ lag2poly: Final[_FuncUnOp] = ...
67
+
68
+ lagdomain: Final[_Array2[np.float64]] = ...
69
+ lagzero: Final[_Array1[np.int_]] = ...
70
+ lagone: Final[_Array1[np.int_]] = ...
71
+ lagx: Final[_Array2[np.int_]] = ...
72
+
73
+ lagline: Final[_FuncLine] = ...
74
+ lagfromroots: Final[_FuncFromRoots] = ...
75
+ lagadd: Final[_FuncBinOp] = ...
76
+ lagsub: Final[_FuncBinOp] = ...
77
+ lagmulx: Final[_FuncUnOp] = ...
78
+ lagmul: Final[_FuncBinOp] = ...
79
+ lagdiv: Final[_FuncBinOp] = ...
80
+ lagpow: Final[_FuncPow] = ...
81
+ lagder: Final[_FuncDer] = ...
82
+ lagint: Final[_FuncInteg] = ...
83
+ lagval: Final[_FuncVal] = ...
84
+ lagval2d: Final[_FuncVal2D] = ...
85
+ lagval3d: Final[_FuncVal3D] = ...
86
+ laggrid2d: Final[_FuncVal2D] = ...
87
+ laggrid3d: Final[_FuncVal3D] = ...
88
+ lagvander: Final[_FuncVander] = ...
89
+ lagvander2d: Final[_FuncVander2D] = ...
90
+ lagvander3d: Final[_FuncVander3D] = ...
91
+ lagfit: Final[_FuncFit] = ...
92
+ lagcompanion: Final[_FuncCompanion] = ...
93
+ lagroots: Final[_FuncRoots] = ...
94
+ laggauss: Final[_FuncGauss] = ...
95
+ lagweight: Final[_FuncWeight] = ...
96
+
97
+ class Laguerre(ABCPolyBase[L["L"]]):
98
+ basis_name: ClassVar[L["L"]] = "L" # pyright: ignore[reportIncompatibleMethodOverride]
99
+ domain: _Array2[np.float64 | Any] = ... # pyright: ignore[reportIncompatibleMethodOverride]
100
+ window: _Array2[np.float64 | Any] = ... # pyright: ignore[reportIncompatibleMethodOverride]
physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy/polynomial/legendre.py ADDED
@@ -0,0 +1,1603 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ ==================================================
3
+ Legendre Series (:mod:`numpy.polynomial.legendre`)
4
+ ==================================================
5
+
6
+ This module provides a number of objects (mostly functions) useful for
7
+ dealing with Legendre series, including a `Legendre` class that
8
+ encapsulates the usual arithmetic operations. (General information
9
+ on how this module represents and works with such polynomials is in the
10
+ docstring for its "parent" sub-package, `numpy.polynomial`).
11
+
12
+ Classes
13
+ -------
14
+ .. autosummary::
15
+ :toctree: generated/
16
+
17
+ Legendre
18
+
19
+ Constants
20
+ ---------
21
+
22
+ .. autosummary::
23
+ :toctree: generated/
24
+
25
+ legdomain
26
+ legzero
27
+ legone
28
+ legx
29
+
30
+ Arithmetic
31
+ ----------
32
+
33
+ .. autosummary::
34
+ :toctree: generated/
35
+
36
+ legadd
37
+ legsub
38
+ legmulx
39
+ legmul
40
+ legdiv
41
+ legpow
42
+ legval
43
+ legval2d
44
+ legval3d
45
+ leggrid2d
46
+ leggrid3d
47
+
48
+ Calculus
49
+ --------
50
+
51
+ .. autosummary::
52
+ :toctree: generated/
53
+
54
+ legder
55
+ legint
56
+
57
+ Misc Functions
58
+ --------------
59
+
60
+ .. autosummary::
61
+ :toctree: generated/
62
+
63
+ legfromroots
64
+ legroots
65
+ legvander
66
+ legvander2d
67
+ legvander3d
68
+ leggauss
69
+ legweight
70
+ legcompanion
71
+ legfit
72
+ legtrim
73
+ legline
74
+ leg2poly
75
+ poly2leg
76
+
77
+ See also
78
+ --------
79
+ numpy.polynomial
80
+
81
+ """
82
+ import numpy as np
83
+
84
+ from . import polyutils as pu
85
+ from ._polybase import ABCPolyBase
86
+
87
+ __all__ = [
88
+ 'legzero', 'legone', 'legx', 'legdomain', 'legline', 'legadd',
89
+ 'legsub', 'legmulx', 'legmul', 'legdiv', 'legpow', 'legval', 'legder',
90
+ 'legint', 'leg2poly', 'poly2leg', 'legfromroots', 'legvander',
91
+ 'legfit', 'legtrim', 'legroots', 'Legendre', 'legval2d', 'legval3d',
92
+ 'leggrid2d', 'leggrid3d', 'legvander2d', 'legvander3d', 'legcompanion',
93
+ 'leggauss', 'legweight']
94
+
95
+ legtrim = pu.trimcoef
96
+
97
+
98
+ def poly2leg(pol):
99
+ """
100
+ Convert a polynomial to a Legendre series.
101
+
102
+ Convert an array representing the coefficients of a polynomial (relative
103
+ to the "standard" basis) ordered from lowest degree to highest, to an
104
+ array of the coefficients of the equivalent Legendre series, ordered
105
+ from lowest to highest degree.
106
+
107
+ Parameters
108
+ ----------
109
+ pol : array_like
110
+ 1-D array containing the polynomial coefficients
111
+
112
+ Returns
113
+ -------
114
+ c : ndarray
115
+ 1-D array containing the coefficients of the equivalent Legendre
116
+ series.
117
+
118
+ See Also
119
+ --------
120
+ leg2poly
121
+
122
+ Notes
123
+ -----
124
+ The easy way to do conversions between polynomial basis sets
125
+ is to use the convert method of a class instance.
126
+
127
+ Examples
128
+ --------
129
+ >>> import numpy as np
130
+ >>> from numpy import polynomial as P
131
+ >>> p = P.Polynomial(np.arange(4))
132
+ >>> p
133
+ Polynomial([0., 1., 2., 3.], domain=[-1., 1.], window=[-1., 1.], ...
134
+ >>> c = P.Legendre(P.legendre.poly2leg(p.coef))
135
+ >>> c
136
+ Legendre([ 1. , 3.25, 1. , 0.75], domain=[-1, 1], window=[-1, 1]) # may vary
137
+
138
+ """
139
+ [pol] = pu.as_series([pol])
140
+ deg = len(pol) - 1
141
+ res = 0
142
+ for i in range(deg, -1, -1):
143
+ res = legadd(legmulx(res), pol[i])
144
+ return res
145
+
146
+
147
+ def leg2poly(c):
148
+ """
149
+ Convert a Legendre series to a polynomial.
150
+
151
+ Convert an array representing the coefficients of a Legendre series,
152
+ ordered from lowest degree to highest, to an array of the coefficients
153
+ of the equivalent polynomial (relative to the "standard" basis) ordered
154
+ from lowest to highest degree.
155
+
156
+ Parameters
157
+ ----------
158
+ c : array_like
159
+ 1-D array containing the Legendre series coefficients, ordered
160
+ from lowest order term to highest.
161
+
162
+ Returns
163
+ -------
164
+ pol : ndarray
165
+ 1-D array containing the coefficients of the equivalent polynomial
166
+ (relative to the "standard" basis) ordered from lowest order term
167
+ to highest.
168
+
169
+ See Also
170
+ --------
171
+ poly2leg
172
+
173
+ Notes
174
+ -----
175
+ The easy way to do conversions between polynomial basis sets
176
+ is to use the convert method of a class instance.
177
+
178
+ Examples
179
+ --------
180
+ >>> from numpy import polynomial as P
181
+ >>> c = P.Legendre(range(4))
182
+ >>> c
183
+ Legendre([0., 1., 2., 3.], domain=[-1., 1.], window=[-1., 1.], symbol='x')
184
+ >>> p = c.convert(kind=P.Polynomial)
185
+ >>> p
186
+ Polynomial([-1. , -3.5, 3. , 7.5], domain=[-1., 1.], window=[-1., ...
187
+ >>> P.legendre.leg2poly(range(4))
188
+ array([-1. , -3.5, 3. , 7.5])
189
+
190
+
191
+ """
192
+ from .polynomial import polyadd, polymulx, polysub
193
+
194
+ [c] = pu.as_series([c])
195
+ n = len(c)
196
+ if n < 3:
197
+ return c
198
+ else:
199
+ c0 = c[-2]
200
+ c1 = c[-1]
201
+ # i is the current degree of c1
202
+ for i in range(n - 1, 1, -1):
203
+ tmp = c0
204
+ c0 = polysub(c[i - 2], (c1 * (i - 1)) / i)
205
+ c1 = polyadd(tmp, (polymulx(c1) * (2 * i - 1)) / i)
206
+ return polyadd(c0, polymulx(c1))
207
+
208
+
209
+ #
210
+ # These are constant arrays are of integer type so as to be compatible
211
+ # with the widest range of other types, such as Decimal.
212
+ #
213
+
214
+ # Legendre
215
+ legdomain = np.array([-1., 1.])
216
+
217
+ # Legendre coefficients representing zero.
218
+ legzero = np.array([0])
219
+
220
+ # Legendre coefficients representing one.
221
+ legone = np.array([1])
222
+
223
+ # Legendre coefficients representing the identity x.
224
+ legx = np.array([0, 1])
225
+
226
+
227
+ def legline(off, scl):
228
+ """
229
+ Legendre series whose graph is a straight line.
230
+
231
+
232
+
233
+ Parameters
234
+ ----------
235
+ off, scl : scalars
236
+ The specified line is given by ``off + scl*x``.
237
+
238
+ Returns
239
+ -------
240
+ y : ndarray
241
+ This module's representation of the Legendre series for
242
+ ``off + scl*x``.
243
+
244
+ See Also
245
+ --------
246
+ numpy.polynomial.polynomial.polyline
247
+ numpy.polynomial.chebyshev.chebline
248
+ numpy.polynomial.laguerre.lagline
249
+ numpy.polynomial.hermite.hermline
250
+ numpy.polynomial.hermite_e.hermeline
251
+
252
+ Examples
253
+ --------
254
+ >>> import numpy.polynomial.legendre as L
255
+ >>> L.legline(3,2)
256
+ array([3, 2])
257
+ >>> L.legval(-3, L.legline(3,2)) # should be -3
258
+ -3.0
259
+
260
+ """
261
+ if scl != 0:
262
+ return np.array([off, scl])
263
+ else:
264
+ return np.array([off])
265
+
266
+
267
+ def legfromroots(roots):
268
+ """
269
+ Generate a Legendre series with given roots.
270
+
271
+ The function returns the coefficients of the polynomial
272
+
273
+ .. math:: p(x) = (x - r_0) * (x - r_1) * ... * (x - r_n),
274
+
275
+ in Legendre form, where the :math:`r_n` are the roots specified in `roots`.
276
+ If a zero has multiplicity n, then it must appear in `roots` n times.
277
+ For instance, if 2 is a root of multiplicity three and 3 is a root of
278
+ multiplicity 2, then `roots` looks something like [2, 2, 2, 3, 3]. The
279
+ roots can appear in any order.
280
+
281
+ If the returned coefficients are `c`, then
282
+
283
+ .. math:: p(x) = c_0 + c_1 * L_1(x) + ... + c_n * L_n(x)
284
+
285
+ The coefficient of the last term is not generally 1 for monic
286
+ polynomials in Legendre form.
287
+
288
+ Parameters
289
+ ----------
290
+ roots : array_like
291
+ Sequence containing the roots.
292
+
293
+ Returns
294
+ -------
295
+ out : ndarray
296
+ 1-D array of coefficients. If all roots are real then `out` is a
297
+ real array, if some of the roots are complex, then `out` is complex
298
+ even if all the coefficients in the result are real (see Examples
299
+ below).
300
+
301
+ See Also
302
+ --------
303
+ numpy.polynomial.polynomial.polyfromroots
304
+ numpy.polynomial.chebyshev.chebfromroots
305
+ numpy.polynomial.laguerre.lagfromroots
306
+ numpy.polynomial.hermite.hermfromroots
307
+ numpy.polynomial.hermite_e.hermefromroots
308
+
309
+ Examples
310
+ --------
311
+ >>> import numpy.polynomial.legendre as L
312
+ >>> L.legfromroots((-1,0,1)) # x^3 - x relative to the standard basis
313
+ array([ 0. , -0.4, 0. , 0.4])
314
+ >>> j = complex(0,1)
315
+ >>> L.legfromroots((-j,j)) # x^2 + 1 relative to the standard basis
316
+ array([ 1.33333333+0.j, 0.00000000+0.j, 0.66666667+0.j]) # may vary
317
+
318
+ """
319
+ return pu._fromroots(legline, legmul, roots)
320
+
321
+
322
+ def legadd(c1, c2):
323
+ """
324
+ Add one Legendre series to another.
325
+
326
+ Returns the sum of two Legendre series `c1` + `c2`. The arguments
327
+ are sequences of coefficients ordered from lowest order term to
328
+ highest, i.e., [1,2,3] represents the series ``P_0 + 2*P_1 + 3*P_2``.
329
+
330
+ Parameters
331
+ ----------
332
+ c1, c2 : array_like
333
+ 1-D arrays of Legendre series coefficients ordered from low to
334
+ high.
335
+
336
+ Returns
337
+ -------
338
+ out : ndarray
339
+ Array representing the Legendre series of their sum.
340
+
341
+ See Also
342
+ --------
343
+ legsub, legmulx, legmul, legdiv, legpow
344
+
345
+ Notes
346
+ -----
347
+ Unlike multiplication, division, etc., the sum of two Legendre series
348
+ is a Legendre series (without having to "reproject" the result onto
349
+ the basis set) so addition, just like that of "standard" polynomials,
350
+ is simply "component-wise."
351
+
352
+ Examples
353
+ --------
354
+ >>> from numpy.polynomial import legendre as L
355
+ >>> c1 = (1,2,3)
356
+ >>> c2 = (3,2,1)
357
+ >>> L.legadd(c1,c2)
358
+ array([4., 4., 4.])
359
+
360
+ """
361
+ return pu._add(c1, c2)
362
+
363
+
364
+ def legsub(c1, c2):
365
+ """
366
+ Subtract one Legendre series from another.
367
+
368
+ Returns the difference of two Legendre series `c1` - `c2`. The
369
+ sequences of coefficients are from lowest order term to highest, i.e.,
370
+ [1,2,3] represents the series ``P_0 + 2*P_1 + 3*P_2``.
371
+
372
+ Parameters
373
+ ----------
374
+ c1, c2 : array_like
375
+ 1-D arrays of Legendre series coefficients ordered from low to
376
+ high.
377
+
378
+ Returns
379
+ -------
380
+ out : ndarray
381
+ Of Legendre series coefficients representing their difference.
382
+
383
+ See Also
384
+ --------
385
+ legadd, legmulx, legmul, legdiv, legpow
386
+
387
+ Notes
388
+ -----
389
+ Unlike multiplication, division, etc., the difference of two Legendre
390
+ series is a Legendre series (without having to "reproject" the result
391
+ onto the basis set) so subtraction, just like that of "standard"
392
+ polynomials, is simply "component-wise."
393
+
394
+ Examples
395
+ --------
396
+ >>> from numpy.polynomial import legendre as L
397
+ >>> c1 = (1,2,3)
398
+ >>> c2 = (3,2,1)
399
+ >>> L.legsub(c1,c2)
400
+ array([-2., 0., 2.])
401
+ >>> L.legsub(c2,c1) # -C.legsub(c1,c2)
402
+ array([ 2., 0., -2.])
403
+
404
+ """
405
+ return pu._sub(c1, c2)
406
+
407
+
408
+ def legmulx(c):
409
+ """Multiply a Legendre series by x.
410
+
411
+ Multiply the Legendre series `c` by x, where x is the independent
412
+ variable.
413
+
414
+
415
+ Parameters
416
+ ----------
417
+ c : array_like
418
+ 1-D array of Legendre series coefficients ordered from low to
419
+ high.
420
+
421
+ Returns
422
+ -------
423
+ out : ndarray
424
+ Array representing the result of the multiplication.
425
+
426
+ See Also
427
+ --------
428
+ legadd, legsub, legmul, legdiv, legpow
429
+
430
+ Notes
431
+ -----
432
+ The multiplication uses the recursion relationship for Legendre
433
+ polynomials in the form
434
+
435
+ .. math::
436
+
437
+ xP_i(x) = ((i + 1)*P_{i + 1}(x) + i*P_{i - 1}(x))/(2i + 1)
438
+
439
+ Examples
440
+ --------
441
+ >>> from numpy.polynomial import legendre as L
442
+ >>> L.legmulx([1,2,3])
443
+ array([ 0.66666667, 2.2, 1.33333333, 1.8]) # may vary
444
+
445
+ """
446
+ # c is a trimmed copy
447
+ [c] = pu.as_series([c])
448
+ # The zero series needs special treatment
449
+ if len(c) == 1 and c[0] == 0:
450
+ return c
451
+
452
+ prd = np.empty(len(c) + 1, dtype=c.dtype)
453
+ prd[0] = c[0] * 0
454
+ prd[1] = c[0]
455
+ for i in range(1, len(c)):
456
+ j = i + 1
457
+ k = i - 1
458
+ s = i + j
459
+ prd[j] = (c[i] * j) / s
460
+ prd[k] += (c[i] * i) / s
461
+ return prd
462
+
463
+
464
+ def legmul(c1, c2):
465
+ """
466
+ Multiply one Legendre series by another.
467
+
468
+ Returns the product of two Legendre series `c1` * `c2`. The arguments
469
+ are sequences of coefficients, from lowest order "term" to highest,
470
+ e.g., [1,2,3] represents the series ``P_0 + 2*P_1 + 3*P_2``.
471
+
472
+ Parameters
473
+ ----------
474
+ c1, c2 : array_like
475
+ 1-D arrays of Legendre series coefficients ordered from low to
476
+ high.
477
+
478
+ Returns
479
+ -------
480
+ out : ndarray
481
+ Of Legendre series coefficients representing their product.
482
+
483
+ See Also
484
+ --------
485
+ legadd, legsub, legmulx, legdiv, legpow
486
+
487
+ Notes
488
+ -----
489
+ In general, the (polynomial) product of two C-series results in terms
490
+ that are not in the Legendre polynomial basis set. Thus, to express
491
+ the product as a Legendre series, it is necessary to "reproject" the
492
+ product onto said basis set, which may produce "unintuitive" (but
493
+ correct) results; see Examples section below.
494
+
495
+ Examples
496
+ --------
497
+ >>> from numpy.polynomial import legendre as L
498
+ >>> c1 = (1,2,3)
499
+ >>> c2 = (3,2)
500
+ >>> L.legmul(c1,c2) # multiplication requires "reprojection"
501
+ array([ 4.33333333, 10.4 , 11.66666667, 3.6 ]) # may vary
502
+
503
+ """
504
+ # s1, s2 are trimmed copies
505
+ [c1, c2] = pu.as_series([c1, c2])
506
+
507
+ if len(c1) > len(c2):
508
+ c = c2
509
+ xs = c1
510
+ else:
511
+ c = c1
512
+ xs = c2
513
+
514
+ if len(c) == 1:
515
+ c0 = c[0] * xs
516
+ c1 = 0
517
+ elif len(c) == 2:
518
+ c0 = c[0] * xs
519
+ c1 = c[1] * xs
520
+ else:
521
+ nd = len(c)
522
+ c0 = c[-2] * xs
523
+ c1 = c[-1] * xs
524
+ for i in range(3, len(c) + 1):
525
+ tmp = c0
526
+ nd = nd - 1
527
+ c0 = legsub(c[-i] * xs, (c1 * (nd - 1)) / nd)
528
+ c1 = legadd(tmp, (legmulx(c1) * (2 * nd - 1)) / nd)
529
+ return legadd(c0, legmulx(c1))
530
+
531
+
532
+ def legdiv(c1, c2):
533
+ """
534
+ Divide one Legendre series by another.
535
+
536
+ Returns the quotient-with-remainder of two Legendre series
537
+ `c1` / `c2`. The arguments are sequences of coefficients from lowest
538
+ order "term" to highest, e.g., [1,2,3] represents the series
539
+ ``P_0 + 2*P_1 + 3*P_2``.
540
+
541
+ Parameters
542
+ ----------
543
+ c1, c2 : array_like
544
+ 1-D arrays of Legendre series coefficients ordered from low to
545
+ high.
546
+
547
+ Returns
548
+ -------
549
+ quo, rem : ndarrays
550
+ Of Legendre series coefficients representing the quotient and
551
+ remainder.
552
+
553
+ See Also
554
+ --------
555
+ legadd, legsub, legmulx, legmul, legpow
556
+
557
+ Notes
558
+ -----
559
+ In general, the (polynomial) division of one Legendre series by another
560
+ results in quotient and remainder terms that are not in the Legendre
561
+ polynomial basis set. Thus, to express these results as a Legendre
562
+ series, it is necessary to "reproject" the results onto the Legendre
563
+ basis set, which may produce "unintuitive" (but correct) results; see
564
+ Examples section below.
565
+
566
+ Examples
567
+ --------
568
+ >>> from numpy.polynomial import legendre as L
569
+ >>> c1 = (1,2,3)
570
+ >>> c2 = (3,2,1)
571
+ >>> L.legdiv(c1,c2) # quotient "intuitive," remainder not
572
+ (array([3.]), array([-8., -4.]))
573
+ >>> c2 = (0,1,2,3)
574
+ >>> L.legdiv(c2,c1) # neither "intuitive"
575
+ (array([-0.07407407, 1.66666667]), array([-1.03703704, -2.51851852])) # may vary
576
+
577
+ """
578
+ return pu._div(legmul, c1, c2)
579
+
580
+
581
+ def legpow(c, pow, maxpower=16):
582
+ """Raise a Legendre series to a power.
583
+
584
+ Returns the Legendre series `c` raised to the power `pow`. The
585
+ argument `c` is a sequence of coefficients ordered from low to high.
586
+ i.e., [1,2,3] is the series ``P_0 + 2*P_1 + 3*P_2.``
587
+
588
+ Parameters
589
+ ----------
590
+ c : array_like
591
+ 1-D array of Legendre series coefficients ordered from low to
592
+ high.
593
+ pow : integer
594
+ Power to which the series will be raised
595
+ maxpower : integer, optional
596
+ Maximum power allowed. This is mainly to limit growth of the series
597
+ to unmanageable size. Default is 16
598
+
599
+ Returns
600
+ -------
601
+ coef : ndarray
602
+ Legendre series of power.
603
+
604
+ See Also
605
+ --------
606
+ legadd, legsub, legmulx, legmul, legdiv
607
+
608
+ """
609
+ return pu._pow(legmul, c, pow, maxpower)
610
+
611
+
612
+ def legder(c, m=1, scl=1, axis=0):
613
+ """
614
+ Differentiate a Legendre series.
615
+
616
+ Returns the Legendre series coefficients `c` differentiated `m` times
617
+ along `axis`. At each iteration the result is multiplied by `scl` (the
618
+ scaling factor is for use in a linear change of variable). The argument
619
+ `c` is an array of coefficients from low to high degree along each
620
+ axis, e.g., [1,2,3] represents the series ``1*L_0 + 2*L_1 + 3*L_2``
621
+ while [[1,2],[1,2]] represents ``1*L_0(x)*L_0(y) + 1*L_1(x)*L_0(y) +
622
+ 2*L_0(x)*L_1(y) + 2*L_1(x)*L_1(y)`` if axis=0 is ``x`` and axis=1 is
623
+ ``y``.
624
+
625
+ Parameters
626
+ ----------
627
+ c : array_like
628
+ Array of Legendre series coefficients. If c is multidimensional the
629
+ different axis correspond to different variables with the degree in
630
+ each axis given by the corresponding index.
631
+ m : int, optional
632
+ Number of derivatives taken, must be non-negative. (Default: 1)
633
+ scl : scalar, optional
634
+ Each differentiation is multiplied by `scl`. The end result is
635
+ multiplication by ``scl**m``. This is for use in a linear change of
636
+ variable. (Default: 1)
637
+ axis : int, optional
638
+ Axis over which the derivative is taken. (Default: 0).
639
+
640
+ Returns
641
+ -------
642
+ der : ndarray
643
+ Legendre series of the derivative.
644
+
645
+ See Also
646
+ --------
647
+ legint
648
+
649
+ Notes
650
+ -----
651
+ In general, the result of differentiating a Legendre series does not
652
+ resemble the same operation on a power series. Thus the result of this
653
+ function may be "unintuitive," albeit correct; see Examples section
654
+ below.
655
+
656
+ Examples
657
+ --------
658
+ >>> from numpy.polynomial import legendre as L
659
+ >>> c = (1,2,3,4)
660
+ >>> L.legder(c)
661
+ array([ 6., 9., 20.])
662
+ >>> L.legder(c, 3)
663
+ array([60.])
664
+ >>> L.legder(c, scl=-1)
665
+ array([ -6., -9., -20.])
666
+ >>> L.legder(c, 2,-1)
667
+ array([ 9., 60.])
668
+
669
+ """
670
+ c = np.array(c, ndmin=1, copy=True)
671
+ if c.dtype.char in '?bBhHiIlLqQpP':
672
+ c = c.astype(np.double)
673
+ cnt = pu._as_int(m, "the order of derivation")
674
+ iaxis = pu._as_int(axis, "the axis")
675
+ if cnt < 0:
676
+ raise ValueError("The order of derivation must be non-negative")
677
+ iaxis = np.lib.array_utils.normalize_axis_index(iaxis, c.ndim)
678
+
679
+ if cnt == 0:
680
+ return c
681
+
682
+ c = np.moveaxis(c, iaxis, 0)
683
+ n = len(c)
684
+ if cnt >= n:
685
+ c = c[:1] * 0
686
+ else:
687
+ for i in range(cnt):
688
+ n = n - 1
689
+ c *= scl
690
+ der = np.empty((n,) + c.shape[1:], dtype=c.dtype)
691
+ for j in range(n, 2, -1):
692
+ der[j - 1] = (2 * j - 1) * c[j]
693
+ c[j - 2] += c[j]
694
+ if n > 1:
695
+ der[1] = 3 * c[2]
696
+ der[0] = c[1]
697
+ c = der
698
+ c = np.moveaxis(c, 0, iaxis)
699
+ return c
700
+
701
+
702
+ def legint(c, m=1, k=[], lbnd=0, scl=1, axis=0):
703
+ """
704
+ Integrate a Legendre series.
705
+
706
+ Returns the Legendre series coefficients `c` integrated `m` times from
707
+ `lbnd` along `axis`. At each iteration the resulting series is
708
+ **multiplied** by `scl` and an integration constant, `k`, is added.
709
+ The scaling factor is for use in a linear change of variable. ("Buyer
710
+ beware": note that, depending on what one is doing, one may want `scl`
711
+ to be the reciprocal of what one might expect; for more information,
712
+ see the Notes section below.) The argument `c` is an array of
713
+ coefficients from low to high degree along each axis, e.g., [1,2,3]
714
+ represents the series ``L_0 + 2*L_1 + 3*L_2`` while [[1,2],[1,2]]
715
+ represents ``1*L_0(x)*L_0(y) + 1*L_1(x)*L_0(y) + 2*L_0(x)*L_1(y) +
716
+ 2*L_1(x)*L_1(y)`` if axis=0 is ``x`` and axis=1 is ``y``.
717
+
718
+ Parameters
719
+ ----------
720
+ c : array_like
721
+ Array of Legendre series coefficients. If c is multidimensional the
722
+ different axis correspond to different variables with the degree in
723
+ each axis given by the corresponding index.
724
+ m : int, optional
725
+ Order of integration, must be positive. (Default: 1)
726
+ k : {[], list, scalar}, optional
727
+ Integration constant(s). The value of the first integral at
728
+ ``lbnd`` is the first value in the list, the value of the second
729
+ integral at ``lbnd`` is the second value, etc. If ``k == []`` (the
730
+ default), all constants are set to zero. If ``m == 1``, a single
731
+ scalar can be given instead of a list.
732
+ lbnd : scalar, optional
733
+ The lower bound of the integral. (Default: 0)
734
+ scl : scalar, optional
735
+ Following each integration the result is *multiplied* by `scl`
736
+ before the integration constant is added. (Default: 1)
737
+ axis : int, optional
738
+ Axis over which the integral is taken. (Default: 0).
739
+
740
+ Returns
741
+ -------
742
+ S : ndarray
743
+ Legendre series coefficient array of the integral.
744
+
745
+ Raises
746
+ ------
747
+ ValueError
748
+ If ``m < 0``, ``len(k) > m``, ``np.ndim(lbnd) != 0``, or
749
+ ``np.ndim(scl) != 0``.
750
+
751
+ See Also
752
+ --------
753
+ legder
754
+
755
+ Notes
756
+ -----
757
+ Note that the result of each integration is *multiplied* by `scl`.
758
+ Why is this important to note? Say one is making a linear change of
759
+ variable :math:`u = ax + b` in an integral relative to `x`. Then
760
+ :math:`dx = du/a`, so one will need to set `scl` equal to
761
+ :math:`1/a` - perhaps not what one would have first thought.
762
+
763
+ Also note that, in general, the result of integrating a C-series needs
764
+ to be "reprojected" onto the C-series basis set. Thus, typically,
765
+ the result of this function is "unintuitive," albeit correct; see
766
+ Examples section below.
767
+
768
+ Examples
769
+ --------
770
+ >>> from numpy.polynomial import legendre as L
771
+ >>> c = (1,2,3)
772
+ >>> L.legint(c)
773
+ array([ 0.33333333, 0.4 , 0.66666667, 0.6 ]) # may vary
774
+ >>> L.legint(c, 3)
775
+ array([ 1.66666667e-02, -1.78571429e-02, 4.76190476e-02, # may vary
776
+ -1.73472348e-18, 1.90476190e-02, 9.52380952e-03])
777
+ >>> L.legint(c, k=3)
778
+ array([ 3.33333333, 0.4 , 0.66666667, 0.6 ]) # may vary
779
+ >>> L.legint(c, lbnd=-2)
780
+ array([ 7.33333333, 0.4 , 0.66666667, 0.6 ]) # may vary
781
+ >>> L.legint(c, scl=2)
782
+ array([ 0.66666667, 0.8 , 1.33333333, 1.2 ]) # may vary
783
+
784
+ """
785
+ c = np.array(c, ndmin=1, copy=True)
786
+ if c.dtype.char in '?bBhHiIlLqQpP':
787
+ c = c.astype(np.double)
788
+ if not np.iterable(k):
789
+ k = [k]
790
+ cnt = pu._as_int(m, "the order of integration")
791
+ iaxis = pu._as_int(axis, "the axis")
792
+ if cnt < 0:
793
+ raise ValueError("The order of integration must be non-negative")
794
+ if len(k) > cnt:
795
+ raise ValueError("Too many integration constants")
796
+ if np.ndim(lbnd) != 0:
797
+ raise ValueError("lbnd must be a scalar.")
798
+ if np.ndim(scl) != 0:
799
+ raise ValueError("scl must be a scalar.")
800
+ iaxis = np.lib.array_utils.normalize_axis_index(iaxis, c.ndim)
801
+
802
+ if cnt == 0:
803
+ return c
804
+
805
+ c = np.moveaxis(c, iaxis, 0)
806
+ k = list(k) + [0] * (cnt - len(k))
807
+ for i in range(cnt):
808
+ n = len(c)
809
+ c *= scl
810
+ if n == 1 and np.all(c[0] == 0):
811
+ c[0] += k[i]
812
+ else:
813
+ tmp = np.empty((n + 1,) + c.shape[1:], dtype=c.dtype)
814
+ tmp[0] = c[0] * 0
815
+ tmp[1] = c[0]
816
+ if n > 1:
817
+ tmp[2] = c[1] / 3
818
+ for j in range(2, n):
819
+ t = c[j] / (2 * j + 1)
820
+ tmp[j + 1] = t
821
+ tmp[j - 1] -= t
822
+ tmp[0] += k[i] - legval(lbnd, tmp)
823
+ c = tmp
824
+ c = np.moveaxis(c, 0, iaxis)
825
+ return c
826
+
827
+
828
+ def legval(x, c, tensor=True):
829
+ """
830
+ Evaluate a Legendre series at points x.
831
+
832
+ If `c` is of length ``n + 1``, this function returns the value:
833
+
834
+ .. math:: p(x) = c_0 * L_0(x) + c_1 * L_1(x) + ... + c_n * L_n(x)
835
+
836
+ The parameter `x` is converted to an array only if it is a tuple or a
837
+ list, otherwise it is treated as a scalar. In either case, either `x`
838
+ or its elements must support multiplication and addition both with
839
+ themselves and with the elements of `c`.
840
+
841
+ If `c` is a 1-D array, then ``p(x)`` will have the same shape as `x`. If
842
+ `c` is multidimensional, then the shape of the result depends on the
843
+ value of `tensor`. If `tensor` is true the shape will be c.shape[1:] +
844
+ x.shape. If `tensor` is false the shape will be c.shape[1:]. Note that
845
+ scalars have shape (,).
846
+
847
+ Trailing zeros in the coefficients will be used in the evaluation, so
848
+ they should be avoided if efficiency is a concern.
849
+
850
+ Parameters
851
+ ----------
852
+ x : array_like, compatible object
853
+ If `x` is a list or tuple, it is converted to an ndarray, otherwise
854
+ it is left unchanged and treated as a scalar. In either case, `x`
855
+ or its elements must support addition and multiplication with
856
+ themselves and with the elements of `c`.
857
+ c : array_like
858
+ Array of coefficients ordered so that the coefficients for terms of
859
+ degree n are contained in c[n]. If `c` is multidimensional the
860
+ remaining indices enumerate multiple polynomials. In the two
861
+ dimensional case the coefficients may be thought of as stored in
862
+ the columns of `c`.
863
+ tensor : boolean, optional
864
+ If True, the shape of the coefficient array is extended with ones
865
+ on the right, one for each dimension of `x`. Scalars have dimension 0
866
+ for this action. The result is that every column of coefficients in
867
+ `c` is evaluated for every element of `x`. If False, `x` is broadcast
868
+ over the columns of `c` for the evaluation. This keyword is useful
869
+ when `c` is multidimensional. The default value is True.
870
+
871
+ Returns
872
+ -------
873
+ values : ndarray, algebra_like
874
+ The shape of the return value is described above.
875
+
876
+ See Also
877
+ --------
878
+ legval2d, leggrid2d, legval3d, leggrid3d
879
+
880
+ Notes
881
+ -----
882
+ The evaluation uses Clenshaw recursion, aka synthetic division.
883
+
884
+ """
885
+ c = np.array(c, ndmin=1, copy=None)
886
+ if c.dtype.char in '?bBhHiIlLqQpP':
887
+ c = c.astype(np.double)
888
+ if isinstance(x, (tuple, list)):
889
+ x = np.asarray(x)
890
+ if isinstance(x, np.ndarray) and tensor:
891
+ c = c.reshape(c.shape + (1,) * x.ndim)
892
+
893
+ if len(c) == 1:
894
+ c0 = c[0]
895
+ c1 = 0
896
+ elif len(c) == 2:
897
+ c0 = c[0]
898
+ c1 = c[1]
899
+ else:
900
+ nd = len(c)
901
+ c0 = c[-2]
902
+ c1 = c[-1]
903
+ for i in range(3, len(c) + 1):
904
+ tmp = c0
905
+ nd = nd - 1
906
+ c0 = c[-i] - c1 * ((nd - 1) / nd)
907
+ c1 = tmp + c1 * x * ((2 * nd - 1) / nd)
908
+ return c0 + c1 * x
909
+
910
+
911
+ def legval2d(x, y, c):
912
+ """
913
+ Evaluate a 2-D Legendre series at points (x, y).
914
+
915
+ This function returns the values:
916
+
917
+ .. math:: p(x,y) = \\sum_{i,j} c_{i,j} * L_i(x) * L_j(y)
918
+
919
+ The parameters `x` and `y` are converted to arrays only if they are
920
+ tuples or a lists, otherwise they are treated as a scalars and they
921
+ must have the same shape after conversion. In either case, either `x`
922
+ and `y` or their elements must support multiplication and addition both
923
+ with themselves and with the elements of `c`.
924
+
925
+ If `c` is a 1-D array a one is implicitly appended to its shape to make
926
+ it 2-D. The shape of the result will be c.shape[2:] + x.shape.
927
+
928
+ Parameters
929
+ ----------
930
+ x, y : array_like, compatible objects
931
+ The two dimensional series is evaluated at the points ``(x, y)``,
932
+ where `x` and `y` must have the same shape. If `x` or `y` is a list
933
+ or tuple, it is first converted to an ndarray, otherwise it is left
934
+ unchanged and if it isn't an ndarray it is treated as a scalar.
935
+ c : array_like
936
+ Array of coefficients ordered so that the coefficient of the term
937
+ of multi-degree i,j is contained in ``c[i,j]``. If `c` has
938
+ dimension greater than two the remaining indices enumerate multiple
939
+ sets of coefficients.
940
+
941
+ Returns
942
+ -------
943
+ values : ndarray, compatible object
944
+ The values of the two dimensional Legendre series at points formed
945
+ from pairs of corresponding values from `x` and `y`.
946
+
947
+ See Also
948
+ --------
949
+ legval, leggrid2d, legval3d, leggrid3d
950
+ """
951
+ return pu._valnd(legval, c, x, y)
952
+
953
+
954
+ def leggrid2d(x, y, c):
955
+ """
956
+ Evaluate a 2-D Legendre series on the Cartesian product of x and y.
957
+
958
+ This function returns the values:
959
+
960
+ .. math:: p(a,b) = \\sum_{i,j} c_{i,j} * L_i(a) * L_j(b)
961
+
962
+ where the points ``(a, b)`` consist of all pairs formed by taking
963
+ `a` from `x` and `b` from `y`. The resulting points form a grid with
964
+ `x` in the first dimension and `y` in the second.
965
+
966
+ The parameters `x` and `y` are converted to arrays only if they are
967
+ tuples or a lists, otherwise they are treated as a scalars. In either
968
+ case, either `x` and `y` or their elements must support multiplication
969
+ and addition both with themselves and with the elements of `c`.
970
+
971
+ If `c` has fewer than two dimensions, ones are implicitly appended to
972
+ its shape to make it 2-D. The shape of the result will be c.shape[2:] +
973
+ x.shape + y.shape.
974
+
975
+ Parameters
976
+ ----------
977
+ x, y : array_like, compatible objects
978
+ The two dimensional series is evaluated at the points in the
979
+ Cartesian product of `x` and `y`. If `x` or `y` is a list or
980
+ tuple, it is first converted to an ndarray, otherwise it is left
981
+ unchanged and, if it isn't an ndarray, it is treated as a scalar.
982
+ c : array_like
983
+ Array of coefficients ordered so that the coefficient of the term of
984
+ multi-degree i,j is contained in ``c[i,j]``. If `c` has dimension
985
+ greater than two the remaining indices enumerate multiple sets of
986
+ coefficients.
987
+
988
+ Returns
989
+ -------
990
+ values : ndarray, compatible object
991
+ The values of the two dimensional Chebyshev series at points in the
992
+ Cartesian product of `x` and `y`.
993
+
994
+ See Also
995
+ --------
996
+ legval, legval2d, legval3d, leggrid3d
997
+ """
998
+ return pu._gridnd(legval, c, x, y)
999
+
1000
+
1001
+ def legval3d(x, y, z, c):
1002
+ """
1003
+ Evaluate a 3-D Legendre series at points (x, y, z).
1004
+
1005
+ This function returns the values:
1006
+
1007
+ .. math:: p(x,y,z) = \\sum_{i,j,k} c_{i,j,k} * L_i(x) * L_j(y) * L_k(z)
1008
+
1009
+ The parameters `x`, `y`, and `z` are converted to arrays only if
1010
+ they are tuples or a lists, otherwise they are treated as a scalars and
1011
+ they must have the same shape after conversion. In either case, either
1012
+ `x`, `y`, and `z` or their elements must support multiplication and
1013
+ addition both with themselves and with the elements of `c`.
1014
+
1015
+ If `c` has fewer than 3 dimensions, ones are implicitly appended to its
1016
+ shape to make it 3-D. The shape of the result will be c.shape[3:] +
1017
+ x.shape.
1018
+
1019
+ Parameters
1020
+ ----------
1021
+ x, y, z : array_like, compatible object
1022
+ The three dimensional series is evaluated at the points
1023
+ ``(x, y, z)``, where `x`, `y`, and `z` must have the same shape. If
1024
+ any of `x`, `y`, or `z` is a list or tuple, it is first converted
1025
+ to an ndarray, otherwise it is left unchanged and if it isn't an
1026
+ ndarray it is treated as a scalar.
1027
+ c : array_like
1028
+ Array of coefficients ordered so that the coefficient of the term of
1029
+ multi-degree i,j,k is contained in ``c[i,j,k]``. If `c` has dimension
1030
+ greater than 3 the remaining indices enumerate multiple sets of
1031
+ coefficients.
1032
+
1033
+ Returns
1034
+ -------
1035
+ values : ndarray, compatible object
1036
+ The values of the multidimensional polynomial on points formed with
1037
+ triples of corresponding values from `x`, `y`, and `z`.
1038
+
1039
+ See Also
1040
+ --------
1041
+ legval, legval2d, leggrid2d, leggrid3d
1042
+ """
1043
+ return pu._valnd(legval, c, x, y, z)
1044
+
1045
+
1046
+ def leggrid3d(x, y, z, c):
1047
+ """
1048
+ Evaluate a 3-D Legendre series on the Cartesian product of x, y, and z.
1049
+
1050
+ This function returns the values:
1051
+
1052
+ .. math:: p(a,b,c) = \\sum_{i,j,k} c_{i,j,k} * L_i(a) * L_j(b) * L_k(c)
1053
+
1054
+ where the points ``(a, b, c)`` consist of all triples formed by taking
1055
+ `a` from `x`, `b` from `y`, and `c` from `z`. The resulting points form
1056
+ a grid with `x` in the first dimension, `y` in the second, and `z` in
1057
+ the third.
1058
+
1059
+ The parameters `x`, `y`, and `z` are converted to arrays only if they
1060
+ are tuples or a lists, otherwise they are treated as a scalars. In
1061
+ either case, either `x`, `y`, and `z` or their elements must support
1062
+ multiplication and addition both with themselves and with the elements
1063
+ of `c`.
1064
+
1065
+ If `c` has fewer than three dimensions, ones are implicitly appended to
1066
+ its shape to make it 3-D. The shape of the result will be c.shape[3:] +
1067
+ x.shape + y.shape + z.shape.
1068
+
1069
+ Parameters
1070
+ ----------
1071
+ x, y, z : array_like, compatible objects
1072
+ The three dimensional series is evaluated at the points in the
1073
+ Cartesian product of `x`, `y`, and `z`. If `x`, `y`, or `z` is a
1074
+ list or tuple, it is first converted to an ndarray, otherwise it is
1075
+ left unchanged and, if it isn't an ndarray, it is treated as a
1076
+ scalar.
1077
+ c : array_like
1078
+ Array of coefficients ordered so that the coefficients for terms of
1079
+ degree i,j are contained in ``c[i,j]``. If `c` has dimension
1080
+ greater than two the remaining indices enumerate multiple sets of
1081
+ coefficients.
1082
+
1083
+ Returns
1084
+ -------
1085
+ values : ndarray, compatible object
1086
+ The values of the two dimensional polynomial at points in the Cartesian
1087
+ product of `x` and `y`.
1088
+
1089
+ See Also
1090
+ --------
1091
+ legval, legval2d, leggrid2d, legval3d
1092
+ """
1093
+ return pu._gridnd(legval, c, x, y, z)
1094
+
1095
+
1096
+ def legvander(x, deg):
1097
+ """Pseudo-Vandermonde matrix of given degree.
1098
+
1099
+ Returns the pseudo-Vandermonde matrix of degree `deg` and sample points
1100
+ `x`. The pseudo-Vandermonde matrix is defined by
1101
+
1102
+ .. math:: V[..., i] = L_i(x)
1103
+
1104
+ where ``0 <= i <= deg``. The leading indices of `V` index the elements of
1105
+ `x` and the last index is the degree of the Legendre polynomial.
1106
+
1107
+ If `c` is a 1-D array of coefficients of length ``n + 1`` and `V` is the
1108
+ array ``V = legvander(x, n)``, then ``np.dot(V, c)`` and
1109
+ ``legval(x, c)`` are the same up to roundoff. This equivalence is
1110
+ useful both for least squares fitting and for the evaluation of a large
1111
+ number of Legendre series of the same degree and sample points.
1112
+
1113
+ Parameters
1114
+ ----------
1115
+ x : array_like
1116
+ Array of points. The dtype is converted to float64 or complex128
1117
+ depending on whether any of the elements are complex. If `x` is
1118
+ scalar it is converted to a 1-D array.
1119
+ deg : int
1120
+ Degree of the resulting matrix.
1121
+
1122
+ Returns
1123
+ -------
1124
+ vander : ndarray
1125
+ The pseudo-Vandermonde matrix. The shape of the returned matrix is
1126
+ ``x.shape + (deg + 1,)``, where The last index is the degree of the
1127
+ corresponding Legendre polynomial. The dtype will be the same as
1128
+ the converted `x`.
1129
+
1130
+ """
1131
+ ideg = pu._as_int(deg, "deg")
1132
+ if ideg < 0:
1133
+ raise ValueError("deg must be non-negative")
1134
+
1135
+ x = np.array(x, copy=None, ndmin=1) + 0.0
1136
+ dims = (ideg + 1,) + x.shape
1137
+ dtyp = x.dtype
1138
+ v = np.empty(dims, dtype=dtyp)
1139
+ # Use forward recursion to generate the entries. This is not as accurate
1140
+ # as reverse recursion in this application but it is more efficient.
1141
+ v[0] = x * 0 + 1
1142
+ if ideg > 0:
1143
+ v[1] = x
1144
+ for i in range(2, ideg + 1):
1145
+ v[i] = (v[i - 1] * x * (2 * i - 1) - v[i - 2] * (i - 1)) / i
1146
+ return np.moveaxis(v, 0, -1)
1147
+
1148
+
1149
+ def legvander2d(x, y, deg):
1150
+ """Pseudo-Vandermonde matrix of given degrees.
1151
+
1152
+ Returns the pseudo-Vandermonde matrix of degrees `deg` and sample
1153
+ points ``(x, y)``. The pseudo-Vandermonde matrix is defined by
1154
+
1155
+ .. math:: V[..., (deg[1] + 1)*i + j] = L_i(x) * L_j(y),
1156
+
1157
+ where ``0 <= i <= deg[0]`` and ``0 <= j <= deg[1]``. The leading indices of
1158
+ `V` index the points ``(x, y)`` and the last index encodes the degrees of
1159
+ the Legendre polynomials.
1160
+
1161
+ If ``V = legvander2d(x, y, [xdeg, ydeg])``, then the columns of `V`
1162
+ correspond to the elements of a 2-D coefficient array `c` of shape
1163
+ (xdeg + 1, ydeg + 1) in the order
1164
+
1165
+ .. math:: c_{00}, c_{01}, c_{02}, ... , c_{10}, c_{11}, c_{12}, ...
1166
+
1167
+ and ``np.dot(V, c.flat)`` and ``legval2d(x, y, c)`` will be the same
1168
+ up to roundoff. This equivalence is useful both for least squares
1169
+ fitting and for the evaluation of a large number of 2-D Legendre
1170
+ series of the same degrees and sample points.
1171
+
1172
+ Parameters
1173
+ ----------
1174
+ x, y : array_like
1175
+ Arrays of point coordinates, all of the same shape. The dtypes
1176
+ will be converted to either float64 or complex128 depending on
1177
+ whether any of the elements are complex. Scalars are converted to
1178
+ 1-D arrays.
1179
+ deg : list of ints
1180
+ List of maximum degrees of the form [x_deg, y_deg].
1181
+
1182
+ Returns
1183
+ -------
1184
+ vander2d : ndarray
1185
+ The shape of the returned matrix is ``x.shape + (order,)``, where
1186
+ :math:`order = (deg[0]+1)*(deg[1]+1)`. The dtype will be the same
1187
+ as the converted `x` and `y`.
1188
+
1189
+ See Also
1190
+ --------
1191
+ legvander, legvander3d, legval2d, legval3d
1192
+ """
1193
+ return pu._vander_nd_flat((legvander, legvander), (x, y), deg)
1194
+
1195
+
1196
+ def legvander3d(x, y, z, deg):
1197
+ """Pseudo-Vandermonde matrix of given degrees.
1198
+
1199
+ Returns the pseudo-Vandermonde matrix of degrees `deg` and sample
1200
+ points ``(x, y, z)``. If `l`, `m`, `n` are the given degrees in `x`, `y`, `z`,
1201
+ then The pseudo-Vandermonde matrix is defined by
1202
+
1203
+ .. math:: V[..., (m+1)(n+1)i + (n+1)j + k] = L_i(x)*L_j(y)*L_k(z),
1204
+
1205
+ where ``0 <= i <= l``, ``0 <= j <= m``, and ``0 <= j <= n``. The leading
1206
+ indices of `V` index the points ``(x, y, z)`` and the last index encodes
1207
+ the degrees of the Legendre polynomials.
1208
+
1209
+ If ``V = legvander3d(x, y, z, [xdeg, ydeg, zdeg])``, then the columns
1210
+ of `V` correspond to the elements of a 3-D coefficient array `c` of
1211
+ shape (xdeg + 1, ydeg + 1, zdeg + 1) in the order
1212
+
1213
+ .. math:: c_{000}, c_{001}, c_{002},... , c_{010}, c_{011}, c_{012},...
1214
+
1215
+ and ``np.dot(V, c.flat)`` and ``legval3d(x, y, z, c)`` will be the
1216
+ same up to roundoff. This equivalence is useful both for least squares
1217
+ fitting and for the evaluation of a large number of 3-D Legendre
1218
+ series of the same degrees and sample points.
1219
+
1220
+ Parameters
1221
+ ----------
1222
+ x, y, z : array_like
1223
+ Arrays of point coordinates, all of the same shape. The dtypes will
1224
+ be converted to either float64 or complex128 depending on whether
1225
+ any of the elements are complex. Scalars are converted to 1-D
1226
+ arrays.
1227
+ deg : list of ints
1228
+ List of maximum degrees of the form [x_deg, y_deg, z_deg].
1229
+
1230
+ Returns
1231
+ -------
1232
+ vander3d : ndarray
1233
+ The shape of the returned matrix is ``x.shape + (order,)``, where
1234
+ :math:`order = (deg[0]+1)*(deg[1]+1)*(deg[2]+1)`. The dtype will
1235
+ be the same as the converted `x`, `y`, and `z`.
1236
+
1237
+ See Also
1238
+ --------
1239
+ legvander, legvander3d, legval2d, legval3d
1240
+ """
1241
+ return pu._vander_nd_flat((legvander, legvander, legvander), (x, y, z), deg)
1242
+
1243
+
1244
+ def legfit(x, y, deg, rcond=None, full=False, w=None):
1245
+ """
1246
+ Least squares fit of Legendre series to data.
1247
+
1248
+ Return the coefficients of a Legendre series of degree `deg` that is the
1249
+ least squares fit to the data values `y` given at points `x`. If `y` is
1250
+ 1-D the returned coefficients will also be 1-D. If `y` is 2-D multiple
1251
+ fits are done, one for each column of `y`, and the resulting
1252
+ coefficients are stored in the corresponding columns of a 2-D return.
1253
+ The fitted polynomial(s) are in the form
1254
+
1255
+ .. math:: p(x) = c_0 + c_1 * L_1(x) + ... + c_n * L_n(x),
1256
+
1257
+ where `n` is `deg`.
1258
+
1259
+ Parameters
1260
+ ----------
1261
+ x : array_like, shape (M,)
1262
+ x-coordinates of the M sample points ``(x[i], y[i])``.
1263
+ y : array_like, shape (M,) or (M, K)
1264
+ y-coordinates of the sample points. Several data sets of sample
1265
+ points sharing the same x-coordinates can be fitted at once by
1266
+ passing in a 2D-array that contains one dataset per column.
1267
+ deg : int or 1-D array_like
1268
+ Degree(s) of the fitting polynomials. If `deg` is a single integer
1269
+ all terms up to and including the `deg`'th term are included in the
1270
+ fit. For NumPy versions >= 1.11.0 a list of integers specifying the
1271
+ degrees of the terms to include may be used instead.
1272
+ rcond : float, optional
1273
+ Relative condition number of the fit. Singular values smaller than
1274
+ this relative to the largest singular value will be ignored. The
1275
+ default value is len(x)*eps, where eps is the relative precision of
1276
+ the float type, about 2e-16 in most cases.
1277
+ full : bool, optional
1278
+ Switch determining nature of return value. When it is False (the
1279
+ default) just the coefficients are returned, when True diagnostic
1280
+ information from the singular value decomposition is also returned.
1281
+ w : array_like, shape (`M`,), optional
1282
+ Weights. If not None, the weight ``w[i]`` applies to the unsquared
1283
+ residual ``y[i] - y_hat[i]`` at ``x[i]``. Ideally the weights are
1284
+ chosen so that the errors of the products ``w[i]*y[i]`` all have the
1285
+ same variance. When using inverse-variance weighting, use
1286
+ ``w[i] = 1/sigma(y[i])``. The default value is None.
1287
+
1288
+ Returns
1289
+ -------
1290
+ coef : ndarray, shape (M,) or (M, K)
1291
+ Legendre coefficients ordered from low to high. If `y` was
1292
+ 2-D, the coefficients for the data in column k of `y` are in
1293
+ column `k`. If `deg` is specified as a list, coefficients for
1294
+ terms not included in the fit are set equal to zero in the
1295
+ returned `coef`.
1296
+
1297
+ [residuals, rank, singular_values, rcond] : list
1298
+ These values are only returned if ``full == True``
1299
+
1300
+ - residuals -- sum of squared residuals of the least squares fit
1301
+ - rank -- the numerical rank of the scaled Vandermonde matrix
1302
+ - singular_values -- singular values of the scaled Vandermonde matrix
1303
+ - rcond -- value of `rcond`.
1304
+
1305
+ For more details, see `numpy.linalg.lstsq`.
1306
+
1307
+ Warns
1308
+ -----
1309
+ RankWarning
1310
+ The rank of the coefficient matrix in the least-squares fit is
1311
+ deficient. The warning is only raised if ``full == False``. The
1312
+ warnings can be turned off by
1313
+
1314
+ >>> import warnings
1315
+ >>> warnings.simplefilter('ignore', np.exceptions.RankWarning)
1316
+
1317
+ See Also
1318
+ --------
1319
+ numpy.polynomial.polynomial.polyfit
1320
+ numpy.polynomial.chebyshev.chebfit
1321
+ numpy.polynomial.laguerre.lagfit
1322
+ numpy.polynomial.hermite.hermfit
1323
+ numpy.polynomial.hermite_e.hermefit
1324
+ legval : Evaluates a Legendre series.
1325
+ legvander : Vandermonde matrix of Legendre series.
1326
+ legweight : Legendre weight function (= 1).
1327
+ numpy.linalg.lstsq : Computes a least-squares fit from the matrix.
1328
+ scipy.interpolate.UnivariateSpline : Computes spline fits.
1329
+
1330
+ Notes
1331
+ -----
1332
+ The solution is the coefficients of the Legendre series `p` that
1333
+ minimizes the sum of the weighted squared errors
1334
+
1335
+ .. math:: E = \\sum_j w_j^2 * |y_j - p(x_j)|^2,
1336
+
1337
+ where :math:`w_j` are the weights. This problem is solved by setting up
1338
+ as the (typically) overdetermined matrix equation
1339
+
1340
+ .. math:: V(x) * c = w * y,
1341
+
1342
+ where `V` is the weighted pseudo Vandermonde matrix of `x`, `c` are the
1343
+ coefficients to be solved for, `w` are the weights, and `y` are the
1344
+ observed values. This equation is then solved using the singular value
1345
+ decomposition of `V`.
1346
+
1347
+ If some of the singular values of `V` are so small that they are
1348
+ neglected, then a `~exceptions.RankWarning` will be issued. This means that
1349
+ the coefficient values may be poorly determined. Using a lower order fit
1350
+ will usually get rid of the warning. The `rcond` parameter can also be
1351
+ set to a value smaller than its default, but the resulting fit may be
1352
+ spurious and have large contributions from roundoff error.
1353
+
1354
+ Fits using Legendre series are usually better conditioned than fits
1355
+ using power series, but much can depend on the distribution of the
1356
+ sample points and the smoothness of the data. If the quality of the fit
1357
+ is inadequate splines may be a good alternative.
1358
+
1359
+ References
1360
+ ----------
1361
+ .. [1] Wikipedia, "Curve fitting",
1362
+ https://en.wikipedia.org/wiki/Curve_fitting
1363
+
1364
+ Examples
1365
+ --------
1366
+
1367
+ """
1368
+ return pu._fit(legvander, x, y, deg, rcond, full, w)
1369
+
1370
+
1371
+ def legcompanion(c):
1372
+ """Return the scaled companion matrix of c.
1373
+
1374
+ The basis polynomials are scaled so that the companion matrix is
1375
+ symmetric when `c` is an Legendre basis polynomial. This provides
1376
+ better eigenvalue estimates than the unscaled case and for basis
1377
+ polynomials the eigenvalues are guaranteed to be real if
1378
+ `numpy.linalg.eigvalsh` is used to obtain them.
1379
+
1380
+ Parameters
1381
+ ----------
1382
+ c : array_like
1383
+ 1-D array of Legendre series coefficients ordered from low to high
1384
+ degree.
1385
+
1386
+ Returns
1387
+ -------
1388
+ mat : ndarray
1389
+ Scaled companion matrix of dimensions (deg, deg).
1390
+ """
1391
+ # c is a trimmed copy
1392
+ [c] = pu.as_series([c])
1393
+ if len(c) < 2:
1394
+ raise ValueError('Series must have maximum degree of at least 1.')
1395
+ if len(c) == 2:
1396
+ return np.array([[-c[0] / c[1]]])
1397
+
1398
+ n = len(c) - 1
1399
+ mat = np.zeros((n, n), dtype=c.dtype)
1400
+ scl = 1. / np.sqrt(2 * np.arange(n) + 1)
1401
+ top = mat.reshape(-1)[1::n + 1]
1402
+ bot = mat.reshape(-1)[n::n + 1]
1403
+ top[...] = np.arange(1, n) * scl[:n - 1] * scl[1:n]
1404
+ bot[...] = top
1405
+ mat[:, -1] -= (c[:-1] / c[-1]) * (scl / scl[-1]) * (n / (2 * n - 1))
1406
+ return mat
1407
+
1408
+
1409
+ def legroots(c):
1410
+ """
1411
+ Compute the roots of a Legendre series.
1412
+
1413
+ Return the roots (a.k.a. "zeros") of the polynomial
1414
+
1415
+ .. math:: p(x) = \\sum_i c[i] * L_i(x).
1416
+
1417
+ Parameters
1418
+ ----------
1419
+ c : 1-D array_like
1420
+ 1-D array of coefficients.
1421
+
1422
+ Returns
1423
+ -------
1424
+ out : ndarray
1425
+ Array of the roots of the series. If all the roots are real,
1426
+ then `out` is also real, otherwise it is complex.
1427
+
1428
+ See Also
1429
+ --------
1430
+ numpy.polynomial.polynomial.polyroots
1431
+ numpy.polynomial.chebyshev.chebroots
1432
+ numpy.polynomial.laguerre.lagroots
1433
+ numpy.polynomial.hermite.hermroots
1434
+ numpy.polynomial.hermite_e.hermeroots
1435
+
1436
+ Notes
1437
+ -----
1438
+ The root estimates are obtained as the eigenvalues of the companion
1439
+ matrix, Roots far from the origin of the complex plane may have large
1440
+ errors due to the numerical instability of the series for such values.
1441
+ Roots with multiplicity greater than 1 will also show larger errors as
1442
+ the value of the series near such points is relatively insensitive to
1443
+ errors in the roots. Isolated roots near the origin can be improved by
1444
+ a few iterations of Newton's method.
1445
+
1446
+ The Legendre series basis polynomials aren't powers of ``x`` so the
1447
+ results of this function may seem unintuitive.
1448
+
1449
+ Examples
1450
+ --------
1451
+ >>> import numpy.polynomial.legendre as leg
1452
+ >>> leg.legroots((1, 2, 3, 4)) # 4L_3 + 3L_2 + 2L_1 + 1L_0, all real roots
1453
+ array([-0.85099543, -0.11407192, 0.51506735]) # may vary
1454
+
1455
+ """
1456
+ # c is a trimmed copy
1457
+ [c] = pu.as_series([c])
1458
+ if len(c) < 2:
1459
+ return np.array([], dtype=c.dtype)
1460
+ if len(c) == 2:
1461
+ return np.array([-c[0] / c[1]])
1462
+
1463
+ # rotated companion matrix reduces error
1464
+ m = legcompanion(c)[::-1, ::-1]
1465
+ r = np.linalg.eigvals(m)
1466
+ r.sort()
1467
+ return r
1468
+
1469
+
1470
+ def leggauss(deg):
1471
+ """
1472
+ Gauss-Legendre quadrature.
1473
+
1474
+ Computes the sample points and weights for Gauss-Legendre quadrature.
1475
+ These sample points and weights will correctly integrate polynomials of
1476
+ degree :math:`2*deg - 1` or less over the interval :math:`[-1, 1]` with
1477
+ the weight function :math:`f(x) = 1`.
1478
+
1479
+ Parameters
1480
+ ----------
1481
+ deg : int
1482
+ Number of sample points and weights. It must be >= 1.
1483
+
1484
+ Returns
1485
+ -------
1486
+ x : ndarray
1487
+ 1-D ndarray containing the sample points.
1488
+ y : ndarray
1489
+ 1-D ndarray containing the weights.
1490
+
1491
+ Notes
1492
+ -----
1493
+ The results have only been tested up to degree 100, higher degrees may
1494
+ be problematic. The weights are determined by using the fact that
1495
+
1496
+ .. math:: w_k = c / (L'_n(x_k) * L_{n-1}(x_k))
1497
+
1498
+ where :math:`c` is a constant independent of :math:`k` and :math:`x_k`
1499
+ is the k'th root of :math:`L_n`, and then scaling the results to get
1500
+ the right value when integrating 1.
1501
+
1502
+ """
1503
+ ideg = pu._as_int(deg, "deg")
1504
+ if ideg <= 0:
1505
+ raise ValueError("deg must be a positive integer")
1506
+
1507
+ # first approximation of roots. We use the fact that the companion
1508
+ # matrix is symmetric in this case in order to obtain better zeros.
1509
+ c = np.array([0] * deg + [1])
1510
+ m = legcompanion(c)
1511
+ x = np.linalg.eigvalsh(m)
1512
+
1513
+ # improve roots by one application of Newton
1514
+ dy = legval(x, c)
1515
+ df = legval(x, legder(c))
1516
+ x -= dy / df
1517
+
1518
+ # compute the weights. We scale the factor to avoid possible numerical
1519
+ # overflow.
1520
+ fm = legval(x, c[1:])
1521
+ fm /= np.abs(fm).max()
1522
+ df /= np.abs(df).max()
1523
+ w = 1 / (fm * df)
1524
+
1525
+ # for Legendre we can also symmetrize
1526
+ w = (w + w[::-1]) / 2
1527
+ x = (x - x[::-1]) / 2
1528
+
1529
+ # scale w to get the right value
1530
+ w *= 2. / w.sum()
1531
+
1532
+ return x, w
1533
+
1534
+
1535
+ def legweight(x):
1536
+ """
1537
+ Weight function of the Legendre polynomials.
1538
+
1539
+ The weight function is :math:`1` and the interval of integration is
1540
+ :math:`[-1, 1]`. The Legendre polynomials are orthogonal, but not
1541
+ normalized, with respect to this weight function.
1542
+
1543
+ Parameters
1544
+ ----------
1545
+ x : array_like
1546
+ Values at which the weight function will be computed.
1547
+
1548
+ Returns
1549
+ -------
1550
+ w : ndarray
1551
+ The weight function at `x`.
1552
+ """
1553
+ w = x * 0.0 + 1.0
1554
+ return w
1555
+
1556
+ #
1557
+ # Legendre series class
1558
+ #
1559
+
1560
+ class Legendre(ABCPolyBase):
1561
+ """A Legendre series class.
1562
+
1563
+ The Legendre class provides the standard Python numerical methods
1564
+ '+', '-', '*', '//', '%', 'divmod', '**', and '()' as well as the
1565
+ attributes and methods listed below.
1566
+
1567
+ Parameters
1568
+ ----------
1569
+ coef : array_like
1570
+ Legendre coefficients in order of increasing degree, i.e.,
1571
+ ``(1, 2, 3)`` gives ``1*P_0(x) + 2*P_1(x) + 3*P_2(x)``.
1572
+ domain : (2,) array_like, optional
1573
+ Domain to use. The interval ``[domain[0], domain[1]]`` is mapped
1574
+ to the interval ``[window[0], window[1]]`` by shifting and scaling.
1575
+ The default value is [-1., 1.].
1576
+ window : (2,) array_like, optional
1577
+ Window, see `domain` for its use. The default value is [-1., 1.].
1578
+ symbol : str, optional
1579
+ Symbol used to represent the independent variable in string
1580
+ representations of the polynomial expression, e.g. for printing.
1581
+ The symbol must be a valid Python identifier. Default value is 'x'.
1582
+
1583
+ .. versionadded:: 1.24
1584
+
1585
+ """
1586
+ # Virtual Functions
1587
+ _add = staticmethod(legadd)
1588
+ _sub = staticmethod(legsub)
1589
+ _mul = staticmethod(legmul)
1590
+ _div = staticmethod(legdiv)
1591
+ _pow = staticmethod(legpow)
1592
+ _val = staticmethod(legval)
1593
+ _int = staticmethod(legint)
1594
+ _der = staticmethod(legder)
1595
+ _fit = staticmethod(legfit)
1596
+ _line = staticmethod(legline)
1597
+ _roots = staticmethod(legroots)
1598
+ _fromroots = staticmethod(legfromroots)
1599
+
1600
+ # Virtual properties
1601
+ domain = np.array(legdomain)
1602
+ window = np.array(legdomain)
1603
+ basis_name = 'P'
physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy/polynomial/legendre.pyi ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import Any, ClassVar, Final, Literal as L
2
+
3
+ import numpy as np
4
+
5
+ from ._polybase import ABCPolyBase
6
+ from ._polytypes import (
7
+ _Array1,
8
+ _Array2,
9
+ _FuncBinOp,
10
+ _FuncCompanion,
11
+ _FuncDer,
12
+ _FuncFit,
13
+ _FuncFromRoots,
14
+ _FuncGauss,
15
+ _FuncInteg,
16
+ _FuncLine,
17
+ _FuncPoly2Ortho,
18
+ _FuncPow,
19
+ _FuncRoots,
20
+ _FuncUnOp,
21
+ _FuncVal,
22
+ _FuncVal2D,
23
+ _FuncVal3D,
24
+ _FuncVander,
25
+ _FuncVander2D,
26
+ _FuncVander3D,
27
+ _FuncWeight,
28
+ )
29
+ from .polyutils import trimcoef as legtrim
30
+
31
+ __all__ = [
32
+ "legzero",
33
+ "legone",
34
+ "legx",
35
+ "legdomain",
36
+ "legline",
37
+ "legadd",
38
+ "legsub",
39
+ "legmulx",
40
+ "legmul",
41
+ "legdiv",
42
+ "legpow",
43
+ "legval",
44
+ "legder",
45
+ "legint",
46
+ "leg2poly",
47
+ "poly2leg",
48
+ "legfromroots",
49
+ "legvander",
50
+ "legfit",
51
+ "legtrim",
52
+ "legroots",
53
+ "Legendre",
54
+ "legval2d",
55
+ "legval3d",
56
+ "leggrid2d",
57
+ "leggrid3d",
58
+ "legvander2d",
59
+ "legvander3d",
60
+ "legcompanion",
61
+ "leggauss",
62
+ "legweight",
63
+ ]
64
+
65
+ poly2leg: Final[_FuncPoly2Ortho] = ...
66
+ leg2poly: Final[_FuncUnOp] = ...
67
+
68
+ legdomain: Final[_Array2[np.float64]] = ...
69
+ legzero: Final[_Array1[np.int_]] = ...
70
+ legone: Final[_Array1[np.int_]] = ...
71
+ legx: Final[_Array2[np.int_]] = ...
72
+
73
+ legline: Final[_FuncLine] = ...
74
+ legfromroots: Final[_FuncFromRoots] = ...
75
+ legadd: Final[_FuncBinOp] = ...
76
+ legsub: Final[_FuncBinOp] = ...
77
+ legmulx: Final[_FuncUnOp] = ...
78
+ legmul: Final[_FuncBinOp] = ...
79
+ legdiv: Final[_FuncBinOp] = ...
80
+ legpow: Final[_FuncPow] = ...
81
+ legder: Final[_FuncDer] = ...
82
+ legint: Final[_FuncInteg] = ...
83
+ legval: Final[_FuncVal] = ...
84
+ legval2d: Final[_FuncVal2D] = ...
85
+ legval3d: Final[_FuncVal3D] = ...
86
+ leggrid2d: Final[_FuncVal2D] = ...
87
+ leggrid3d: Final[_FuncVal3D] = ...
88
+ legvander: Final[_FuncVander] = ...
89
+ legvander2d: Final[_FuncVander2D] = ...
90
+ legvander3d: Final[_FuncVander3D] = ...
91
+ legfit: Final[_FuncFit] = ...
92
+ legcompanion: Final[_FuncCompanion] = ...
93
+ legroots: Final[_FuncRoots] = ...
94
+ leggauss: Final[_FuncGauss] = ...
95
+ legweight: Final[_FuncWeight] = ...
96
+
97
+ class Legendre(ABCPolyBase[L["P"]]):
98
+ basis_name: ClassVar[L["P"]] = "P" # pyright: ignore[reportIncompatibleMethodOverride]
99
+ domain: _Array2[np.float64 | Any] = ... # pyright: ignore[reportIncompatibleMethodOverride]
100
+ window: _Array2[np.float64 | Any] = ... # pyright: ignore[reportIncompatibleMethodOverride]
physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy/polynomial/polynomial.py ADDED
@@ -0,0 +1,1625 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ =================================================
3
+ Power Series (:mod:`numpy.polynomial.polynomial`)
4
+ =================================================
5
+
6
+ This module provides a number of objects (mostly functions) useful for
7
+ dealing with polynomials, including a `Polynomial` class that
8
+ encapsulates the usual arithmetic operations. (General information
9
+ on how this module represents and works with polynomial objects is in
10
+ the docstring for its "parent" sub-package, `numpy.polynomial`).
11
+
12
+ Classes
13
+ -------
14
+ .. autosummary::
15
+ :toctree: generated/
16
+
17
+ Polynomial
18
+
19
+ Constants
20
+ ---------
21
+ .. autosummary::
22
+ :toctree: generated/
23
+
24
+ polydomain
25
+ polyzero
26
+ polyone
27
+ polyx
28
+
29
+ Arithmetic
30
+ ----------
31
+ .. autosummary::
32
+ :toctree: generated/
33
+
34
+ polyadd
35
+ polysub
36
+ polymulx
37
+ polymul
38
+ polydiv
39
+ polypow
40
+ polyval
41
+ polyval2d
42
+ polyval3d
43
+ polygrid2d
44
+ polygrid3d
45
+
46
+ Calculus
47
+ --------
48
+ .. autosummary::
49
+ :toctree: generated/
50
+
51
+ polyder
52
+ polyint
53
+
54
+ Misc Functions
55
+ --------------
56
+ .. autosummary::
57
+ :toctree: generated/
58
+
59
+ polyfromroots
60
+ polyroots
61
+ polyvalfromroots
62
+ polyvander
63
+ polyvander2d
64
+ polyvander3d
65
+ polycompanion
66
+ polyfit
67
+ polytrim
68
+ polyline
69
+
70
+ See Also
71
+ --------
72
+ `numpy.polynomial`
73
+
74
+ """
75
+ __all__ = [
76
+ 'polyzero', 'polyone', 'polyx', 'polydomain', 'polyline', 'polyadd',
77
+ 'polysub', 'polymulx', 'polymul', 'polydiv', 'polypow', 'polyval',
78
+ 'polyvalfromroots', 'polyder', 'polyint', 'polyfromroots', 'polyvander',
79
+ 'polyfit', 'polytrim', 'polyroots', 'Polynomial', 'polyval2d', 'polyval3d',
80
+ 'polygrid2d', 'polygrid3d', 'polyvander2d', 'polyvander3d',
81
+ 'polycompanion']
82
+
83
+ import numpy as np
84
+ from numpy._core.overrides import array_function_dispatch as _array_function_dispatch
85
+
86
+ from . import polyutils as pu
87
+ from ._polybase import ABCPolyBase
88
+
89
+ polytrim = pu.trimcoef
90
+
91
+ #
92
+ # These are constant arrays are of integer type so as to be compatible
93
+ # with the widest range of other types, such as Decimal.
94
+ #
95
+
96
+ # Polynomial default domain.
97
+ polydomain = np.array([-1., 1.])
98
+
99
+ # Polynomial coefficients representing zero.
100
+ polyzero = np.array([0])
101
+
102
+ # Polynomial coefficients representing one.
103
+ polyone = np.array([1])
104
+
105
+ # Polynomial coefficients representing the identity x.
106
+ polyx = np.array([0, 1])
107
+
108
+ #
109
+ # Polynomial series functions
110
+ #
111
+
112
+
113
+ def polyline(off, scl):
114
+ """
115
+ Returns an array representing a linear polynomial.
116
+
117
+ Parameters
118
+ ----------
119
+ off, scl : scalars
120
+ The "y-intercept" and "slope" of the line, respectively.
121
+
122
+ Returns
123
+ -------
124
+ y : ndarray
125
+ This module's representation of the linear polynomial ``off +
126
+ scl*x``.
127
+
128
+ See Also
129
+ --------
130
+ numpy.polynomial.chebyshev.chebline
131
+ numpy.polynomial.legendre.legline
132
+ numpy.polynomial.laguerre.lagline
133
+ numpy.polynomial.hermite.hermline
134
+ numpy.polynomial.hermite_e.hermeline
135
+
136
+ Examples
137
+ --------
138
+ >>> from numpy.polynomial import polynomial as P
139
+ >>> P.polyline(1, -1)
140
+ array([ 1, -1])
141
+ >>> P.polyval(1, P.polyline(1, -1)) # should be 0
142
+ 0.0
143
+
144
+ """
145
+ if scl != 0:
146
+ return np.array([off, scl])
147
+ else:
148
+ return np.array([off])
149
+
150
+
151
+ def polyfromroots(roots):
152
+ """
153
+ Generate a monic polynomial with given roots.
154
+
155
+ Return the coefficients of the polynomial
156
+
157
+ .. math:: p(x) = (x - r_0) * (x - r_1) * ... * (x - r_n),
158
+
159
+ where the :math:`r_n` are the roots specified in `roots`. If a zero has
160
+ multiplicity n, then it must appear in `roots` n times. For instance,
161
+ if 2 is a root of multiplicity three and 3 is a root of multiplicity 2,
162
+ then `roots` looks something like [2, 2, 2, 3, 3]. The roots can appear
163
+ in any order.
164
+
165
+ If the returned coefficients are `c`, then
166
+
167
+ .. math:: p(x) = c_0 + c_1 * x + ... + x^n
168
+
169
+ The coefficient of the last term is 1 for monic polynomials in this
170
+ form.
171
+
172
+ Parameters
173
+ ----------
174
+ roots : array_like
175
+ Sequence containing the roots.
176
+
177
+ Returns
178
+ -------
179
+ out : ndarray
180
+ 1-D array of the polynomial's coefficients If all the roots are
181
+ real, then `out` is also real, otherwise it is complex. (see
182
+ Examples below).
183
+
184
+ See Also
185
+ --------
186
+ numpy.polynomial.chebyshev.chebfromroots
187
+ numpy.polynomial.legendre.legfromroots
188
+ numpy.polynomial.laguerre.lagfromroots
189
+ numpy.polynomial.hermite.hermfromroots
190
+ numpy.polynomial.hermite_e.hermefromroots
191
+
192
+ Notes
193
+ -----
194
+ The coefficients are determined by multiplying together linear factors
195
+ of the form ``(x - r_i)``, i.e.
196
+
197
+ .. math:: p(x) = (x - r_0) (x - r_1) ... (x - r_n)
198
+
199
+ where ``n == len(roots) - 1``; note that this implies that ``1`` is always
200
+ returned for :math:`a_n`.
201
+
202
+ Examples
203
+ --------
204
+ >>> from numpy.polynomial import polynomial as P
205
+ >>> P.polyfromroots((-1,0,1)) # x(x - 1)(x + 1) = x^3 - x
206
+ array([ 0., -1., 0., 1.])
207
+ >>> j = complex(0,1)
208
+ >>> P.polyfromroots((-j,j)) # complex returned, though values are real
209
+ array([1.+0.j, 0.+0.j, 1.+0.j])
210
+
211
+ """
212
+ return pu._fromroots(polyline, polymul, roots)
213
+
214
+
215
+ def polyadd(c1, c2):
216
+ """
217
+ Add one polynomial to another.
218
+
219
+ Returns the sum of two polynomials `c1` + `c2`. The arguments are
220
+ sequences of coefficients from lowest order term to highest, i.e.,
221
+ [1,2,3] represents the polynomial ``1 + 2*x + 3*x**2``.
222
+
223
+ Parameters
224
+ ----------
225
+ c1, c2 : array_like
226
+ 1-D arrays of polynomial coefficients ordered from low to high.
227
+
228
+ Returns
229
+ -------
230
+ out : ndarray
231
+ The coefficient array representing their sum.
232
+
233
+ See Also
234
+ --------
235
+ polysub, polymulx, polymul, polydiv, polypow
236
+
237
+ Examples
238
+ --------
239
+ >>> from numpy.polynomial import polynomial as P
240
+ >>> c1 = (1, 2, 3)
241
+ >>> c2 = (3, 2, 1)
242
+ >>> sum = P.polyadd(c1,c2); sum
243
+ array([4., 4., 4.])
244
+ >>> P.polyval(2, sum) # 4 + 4(2) + 4(2**2)
245
+ 28.0
246
+
247
+ """
248
+ return pu._add(c1, c2)
249
+
250
+
251
+ def polysub(c1, c2):
252
+ """
253
+ Subtract one polynomial from another.
254
+
255
+ Returns the difference of two polynomials `c1` - `c2`. The arguments
256
+ are sequences of coefficients from lowest order term to highest, i.e.,
257
+ [1,2,3] represents the polynomial ``1 + 2*x + 3*x**2``.
258
+
259
+ Parameters
260
+ ----------
261
+ c1, c2 : array_like
262
+ 1-D arrays of polynomial coefficients ordered from low to
263
+ high.
264
+
265
+ Returns
266
+ -------
267
+ out : ndarray
268
+ Of coefficients representing their difference.
269
+
270
+ See Also
271
+ --------
272
+ polyadd, polymulx, polymul, polydiv, polypow
273
+
274
+ Examples
275
+ --------
276
+ >>> from numpy.polynomial import polynomial as P
277
+ >>> c1 = (1, 2, 3)
278
+ >>> c2 = (3, 2, 1)
279
+ >>> P.polysub(c1,c2)
280
+ array([-2., 0., 2.])
281
+ >>> P.polysub(c2, c1) # -P.polysub(c1,c2)
282
+ array([ 2., 0., -2.])
283
+
284
+ """
285
+ return pu._sub(c1, c2)
286
+
287
+
288
+ def polymulx(c):
289
+ """Multiply a polynomial by x.
290
+
291
+ Multiply the polynomial `c` by x, where x is the independent
292
+ variable.
293
+
294
+
295
+ Parameters
296
+ ----------
297
+ c : array_like
298
+ 1-D array of polynomial coefficients ordered from low to
299
+ high.
300
+
301
+ Returns
302
+ -------
303
+ out : ndarray
304
+ Array representing the result of the multiplication.
305
+
306
+ See Also
307
+ --------
308
+ polyadd, polysub, polymul, polydiv, polypow
309
+
310
+ Examples
311
+ --------
312
+ >>> from numpy.polynomial import polynomial as P
313
+ >>> c = (1, 2, 3)
314
+ >>> P.polymulx(c)
315
+ array([0., 1., 2., 3.])
316
+
317
+ """
318
+ # c is a trimmed copy
319
+ [c] = pu.as_series([c])
320
+ # The zero series needs special treatment
321
+ if len(c) == 1 and c[0] == 0:
322
+ return c
323
+
324
+ prd = np.empty(len(c) + 1, dtype=c.dtype)
325
+ prd[0] = c[0] * 0
326
+ prd[1:] = c
327
+ return prd
328
+
329
+
330
+ def polymul(c1, c2):
331
+ """
332
+ Multiply one polynomial by another.
333
+
334
+ Returns the product of two polynomials `c1` * `c2`. The arguments are
335
+ sequences of coefficients, from lowest order term to highest, e.g.,
336
+ [1,2,3] represents the polynomial ``1 + 2*x + 3*x**2.``
337
+
338
+ Parameters
339
+ ----------
340
+ c1, c2 : array_like
341
+ 1-D arrays of coefficients representing a polynomial, relative to the
342
+ "standard" basis, and ordered from lowest order term to highest.
343
+
344
+ Returns
345
+ -------
346
+ out : ndarray
347
+ Of the coefficients of their product.
348
+
349
+ See Also
350
+ --------
351
+ polyadd, polysub, polymulx, polydiv, polypow
352
+
353
+ Examples
354
+ --------
355
+ >>> from numpy.polynomial import polynomial as P
356
+ >>> c1 = (1, 2, 3)
357
+ >>> c2 = (3, 2, 1)
358
+ >>> P.polymul(c1, c2)
359
+ array([ 3., 8., 14., 8., 3.])
360
+
361
+ """
362
+ # c1, c2 are trimmed copies
363
+ [c1, c2] = pu.as_series([c1, c2])
364
+ ret = np.convolve(c1, c2)
365
+ return pu.trimseq(ret)
366
+
367
+
368
+ def polydiv(c1, c2):
369
+ """
370
+ Divide one polynomial by another.
371
+
372
+ Returns the quotient-with-remainder of two polynomials `c1` / `c2`.
373
+ The arguments are sequences of coefficients, from lowest order term
374
+ to highest, e.g., [1,2,3] represents ``1 + 2*x + 3*x**2``.
375
+
376
+ Parameters
377
+ ----------
378
+ c1, c2 : array_like
379
+ 1-D arrays of polynomial coefficients ordered from low to high.
380
+
381
+ Returns
382
+ -------
383
+ [quo, rem] : ndarrays
384
+ Of coefficient series representing the quotient and remainder.
385
+
386
+ See Also
387
+ --------
388
+ polyadd, polysub, polymulx, polymul, polypow
389
+
390
+ Examples
391
+ --------
392
+ >>> from numpy.polynomial import polynomial as P
393
+ >>> c1 = (1, 2, 3)
394
+ >>> c2 = (3, 2, 1)
395
+ >>> P.polydiv(c1, c2)
396
+ (array([3.]), array([-8., -4.]))
397
+ >>> P.polydiv(c2, c1)
398
+ (array([ 0.33333333]), array([ 2.66666667, 1.33333333])) # may vary
399
+
400
+ """
401
+ # c1, c2 are trimmed copies
402
+ [c1, c2] = pu.as_series([c1, c2])
403
+ if c2[-1] == 0:
404
+ raise ZeroDivisionError # FIXME: add message with details to exception
405
+
406
+ # note: this is more efficient than `pu._div(polymul, c1, c2)`
407
+ lc1 = len(c1)
408
+ lc2 = len(c2)
409
+ if lc1 < lc2:
410
+ return c1[:1] * 0, c1
411
+ elif lc2 == 1:
412
+ return c1 / c2[-1], c1[:1] * 0
413
+ else:
414
+ dlen = lc1 - lc2
415
+ scl = c2[-1]
416
+ c2 = c2[:-1] / scl
417
+ i = dlen
418
+ j = lc1 - 1
419
+ while i >= 0:
420
+ c1[i:j] -= c2 * c1[j]
421
+ i -= 1
422
+ j -= 1
423
+ return c1[j + 1:] / scl, pu.trimseq(c1[:j + 1])
424
+
425
+
426
+ def polypow(c, pow, maxpower=None):
427
+ """Raise a polynomial to a power.
428
+
429
+ Returns the polynomial `c` raised to the power `pow`. The argument
430
+ `c` is a sequence of coefficients ordered from low to high. i.e.,
431
+ [1,2,3] is the series ``1 + 2*x + 3*x**2.``
432
+
433
+ Parameters
434
+ ----------
435
+ c : array_like
436
+ 1-D array of array of series coefficients ordered from low to
437
+ high degree.
438
+ pow : integer
439
+ Power to which the series will be raised
440
+ maxpower : integer, optional
441
+ Maximum power allowed. This is mainly to limit growth of the series
442
+ to unmanageable size. Default is 16
443
+
444
+ Returns
445
+ -------
446
+ coef : ndarray
447
+ Power series of power.
448
+
449
+ See Also
450
+ --------
451
+ polyadd, polysub, polymulx, polymul, polydiv
452
+
453
+ Examples
454
+ --------
455
+ >>> from numpy.polynomial import polynomial as P
456
+ >>> P.polypow([1, 2, 3], 2)
457
+ array([ 1., 4., 10., 12., 9.])
458
+
459
+ """
460
+ # note: this is more efficient than `pu._pow(polymul, c1, c2)`, as it
461
+ # avoids calling `as_series` repeatedly
462
+ return pu._pow(np.convolve, c, pow, maxpower)
463
+
464
+
465
+ def polyder(c, m=1, scl=1, axis=0):
466
+ """
467
+ Differentiate a polynomial.
468
+
469
+ Returns the polynomial coefficients `c` differentiated `m` times along
470
+ `axis`. At each iteration the result is multiplied by `scl` (the
471
+ scaling factor is for use in a linear change of variable). The
472
+ argument `c` is an array of coefficients from low to high degree along
473
+ each axis, e.g., [1,2,3] represents the polynomial ``1 + 2*x + 3*x**2``
474
+ while [[1,2],[1,2]] represents ``1 + 1*x + 2*y + 2*x*y`` if axis=0 is
475
+ ``x`` and axis=1 is ``y``.
476
+
477
+ Parameters
478
+ ----------
479
+ c : array_like
480
+ Array of polynomial coefficients. If c is multidimensional the
481
+ different axis correspond to different variables with the degree
482
+ in each axis given by the corresponding index.
483
+ m : int, optional
484
+ Number of derivatives taken, must be non-negative. (Default: 1)
485
+ scl : scalar, optional
486
+ Each differentiation is multiplied by `scl`. The end result is
487
+ multiplication by ``scl**m``. This is for use in a linear change
488
+ of variable. (Default: 1)
489
+ axis : int, optional
490
+ Axis over which the derivative is taken. (Default: 0).
491
+
492
+ Returns
493
+ -------
494
+ der : ndarray
495
+ Polynomial coefficients of the derivative.
496
+
497
+ See Also
498
+ --------
499
+ polyint
500
+
501
+ Examples
502
+ --------
503
+ >>> from numpy.polynomial import polynomial as P
504
+ >>> c = (1, 2, 3, 4)
505
+ >>> P.polyder(c) # (d/dx)(c)
506
+ array([ 2., 6., 12.])
507
+ >>> P.polyder(c, 3) # (d**3/dx**3)(c)
508
+ array([24.])
509
+ >>> P.polyder(c, scl=-1) # (d/d(-x))(c)
510
+ array([ -2., -6., -12.])
511
+ >>> P.polyder(c, 2, -1) # (d**2/d(-x)**2)(c)
512
+ array([ 6., 24.])
513
+
514
+ """
515
+ c = np.array(c, ndmin=1, copy=True)
516
+ if c.dtype.char in '?bBhHiIlLqQpP':
517
+ # astype fails with NA
518
+ c = c + 0.0
519
+ cdt = c.dtype
520
+ cnt = pu._as_int(m, "the order of derivation")
521
+ iaxis = pu._as_int(axis, "the axis")
522
+ if cnt < 0:
523
+ raise ValueError("The order of derivation must be non-negative")
524
+ iaxis = np.lib.array_utils.normalize_axis_index(iaxis, c.ndim)
525
+
526
+ if cnt == 0:
527
+ return c
528
+
529
+ c = np.moveaxis(c, iaxis, 0)
530
+ n = len(c)
531
+ if cnt >= n:
532
+ c = c[:1] * 0
533
+ else:
534
+ for i in range(cnt):
535
+ n = n - 1
536
+ c *= scl
537
+ der = np.empty((n,) + c.shape[1:], dtype=cdt)
538
+ for j in range(n, 0, -1):
539
+ der[j - 1] = j * c[j]
540
+ c = der
541
+ c = np.moveaxis(c, 0, iaxis)
542
+ return c
543
+
544
+
545
+ def polyint(c, m=1, k=[], lbnd=0, scl=1, axis=0):
546
+ """
547
+ Integrate a polynomial.
548
+
549
+ Returns the polynomial coefficients `c` integrated `m` times from
550
+ `lbnd` along `axis`. At each iteration the resulting series is
551
+ **multiplied** by `scl` and an integration constant, `k`, is added.
552
+ The scaling factor is for use in a linear change of variable. ("Buyer
553
+ beware": note that, depending on what one is doing, one may want `scl`
554
+ to be the reciprocal of what one might expect; for more information,
555
+ see the Notes section below.) The argument `c` is an array of
556
+ coefficients, from low to high degree along each axis, e.g., [1,2,3]
557
+ represents the polynomial ``1 + 2*x + 3*x**2`` while [[1,2],[1,2]]
558
+ represents ``1 + 1*x + 2*y + 2*x*y`` if axis=0 is ``x`` and axis=1 is
559
+ ``y``.
560
+
561
+ Parameters
562
+ ----------
563
+ c : array_like
564
+ 1-D array of polynomial coefficients, ordered from low to high.
565
+ m : int, optional
566
+ Order of integration, must be positive. (Default: 1)
567
+ k : {[], list, scalar}, optional
568
+ Integration constant(s). The value of the first integral at zero
569
+ is the first value in the list, the value of the second integral
570
+ at zero is the second value, etc. If ``k == []`` (the default),
571
+ all constants are set to zero. If ``m == 1``, a single scalar can
572
+ be given instead of a list.
573
+ lbnd : scalar, optional
574
+ The lower bound of the integral. (Default: 0)
575
+ scl : scalar, optional
576
+ Following each integration the result is *multiplied* by `scl`
577
+ before the integration constant is added. (Default: 1)
578
+ axis : int, optional
579
+ Axis over which the integral is taken. (Default: 0).
580
+
581
+ Returns
582
+ -------
583
+ S : ndarray
584
+ Coefficient array of the integral.
585
+
586
+ Raises
587
+ ------
588
+ ValueError
589
+ If ``m < 1``, ``len(k) > m``, ``np.ndim(lbnd) != 0``, or
590
+ ``np.ndim(scl) != 0``.
591
+
592
+ See Also
593
+ --------
594
+ polyder
595
+
596
+ Notes
597
+ -----
598
+ Note that the result of each integration is *multiplied* by `scl`. Why
599
+ is this important to note? Say one is making a linear change of
600
+ variable :math:`u = ax + b` in an integral relative to `x`. Then
601
+ :math:`dx = du/a`, so one will need to set `scl` equal to
602
+ :math:`1/a` - perhaps not what one would have first thought.
603
+
604
+ Examples
605
+ --------
606
+ >>> from numpy.polynomial import polynomial as P
607
+ >>> c = (1, 2, 3)
608
+ >>> P.polyint(c) # should return array([0, 1, 1, 1])
609
+ array([0., 1., 1., 1.])
610
+ >>> P.polyint(c, 3) # should return array([0, 0, 0, 1/6, 1/12, 1/20])
611
+ array([ 0. , 0. , 0. , 0.16666667, 0.08333333, # may vary
612
+ 0.05 ])
613
+ >>> P.polyint(c, k=3) # should return array([3, 1, 1, 1])
614
+ array([3., 1., 1., 1.])
615
+ >>> P.polyint(c,lbnd=-2) # should return array([6, 1, 1, 1])
616
+ array([6., 1., 1., 1.])
617
+ >>> P.polyint(c,scl=-2) # should return array([0, -2, -2, -2])
618
+ array([ 0., -2., -2., -2.])
619
+
620
+ """
621
+ c = np.array(c, ndmin=1, copy=True)
622
+ if c.dtype.char in '?bBhHiIlLqQpP':
623
+ # astype doesn't preserve mask attribute.
624
+ c = c + 0.0
625
+ cdt = c.dtype
626
+ if not np.iterable(k):
627
+ k = [k]
628
+ cnt = pu._as_int(m, "the order of integration")
629
+ iaxis = pu._as_int(axis, "the axis")
630
+ if cnt < 0:
631
+ raise ValueError("The order of integration must be non-negative")
632
+ if len(k) > cnt:
633
+ raise ValueError("Too many integration constants")
634
+ if np.ndim(lbnd) != 0:
635
+ raise ValueError("lbnd must be a scalar.")
636
+ if np.ndim(scl) != 0:
637
+ raise ValueError("scl must be a scalar.")
638
+ iaxis = np.lib.array_utils.normalize_axis_index(iaxis, c.ndim)
639
+
640
+ if cnt == 0:
641
+ return c
642
+
643
+ k = list(k) + [0] * (cnt - len(k))
644
+ c = np.moveaxis(c, iaxis, 0)
645
+ for i in range(cnt):
646
+ n = len(c)
647
+ c *= scl
648
+ if n == 1 and np.all(c[0] == 0):
649
+ c[0] += k[i]
650
+ else:
651
+ tmp = np.empty((n + 1,) + c.shape[1:], dtype=cdt)
652
+ tmp[0] = c[0] * 0
653
+ tmp[1] = c[0]
654
+ for j in range(1, n):
655
+ tmp[j + 1] = c[j] / (j + 1)
656
+ tmp[0] += k[i] - polyval(lbnd, tmp)
657
+ c = tmp
658
+ c = np.moveaxis(c, 0, iaxis)
659
+ return c
660
+
661
+
662
+ def polyval(x, c, tensor=True):
663
+ """
664
+ Evaluate a polynomial at points x.
665
+
666
+ If `c` is of length ``n + 1``, this function returns the value
667
+
668
+ .. math:: p(x) = c_0 + c_1 * x + ... + c_n * x^n
669
+
670
+ The parameter `x` is converted to an array only if it is a tuple or a
671
+ list, otherwise it is treated as a scalar. In either case, either `x`
672
+ or its elements must support multiplication and addition both with
673
+ themselves and with the elements of `c`.
674
+
675
+ If `c` is a 1-D array, then ``p(x)`` will have the same shape as `x`. If
676
+ `c` is multidimensional, then the shape of the result depends on the
677
+ value of `tensor`. If `tensor` is true the shape will be c.shape[1:] +
678
+ x.shape. If `tensor` is false the shape will be c.shape[1:]. Note that
679
+ scalars have shape (,).
680
+
681
+ Trailing zeros in the coefficients will be used in the evaluation, so
682
+ they should be avoided if efficiency is a concern.
683
+
684
+ Parameters
685
+ ----------
686
+ x : array_like, compatible object
687
+ If `x` is a list or tuple, it is converted to an ndarray, otherwise
688
+ it is left unchanged and treated as a scalar. In either case, `x`
689
+ or its elements must support addition and multiplication with
690
+ with themselves and with the elements of `c`.
691
+ c : array_like
692
+ Array of coefficients ordered so that the coefficients for terms of
693
+ degree n are contained in c[n]. If `c` is multidimensional the
694
+ remaining indices enumerate multiple polynomials. In the two
695
+ dimensional case the coefficients may be thought of as stored in
696
+ the columns of `c`.
697
+ tensor : boolean, optional
698
+ If True, the shape of the coefficient array is extended with ones
699
+ on the right, one for each dimension of `x`. Scalars have dimension 0
700
+ for this action. The result is that every column of coefficients in
701
+ `c` is evaluated for every element of `x`. If False, `x` is broadcast
702
+ over the columns of `c` for the evaluation. This keyword is useful
703
+ when `c` is multidimensional. The default value is True.
704
+
705
+ Returns
706
+ -------
707
+ values : ndarray, compatible object
708
+ The shape of the returned array is described above.
709
+
710
+ See Also
711
+ --------
712
+ polyval2d, polygrid2d, polyval3d, polygrid3d
713
+
714
+ Notes
715
+ -----
716
+ The evaluation uses Horner's method.
717
+
718
+ When using coefficients from polynomials created with ``Polynomial.fit()``,
719
+ use ``p(x)`` or ``polyval(x, p.convert().coef)`` to handle domain/window
720
+ scaling correctly, not ``polyval(x, p.coef)``.
721
+
722
+ Examples
723
+ --------
724
+ >>> import numpy as np
725
+ >>> from numpy.polynomial.polynomial import polyval
726
+ >>> polyval(1, [1,2,3])
727
+ 6.0
728
+ >>> a = np.arange(4).reshape(2,2)
729
+ >>> a
730
+ array([[0, 1],
731
+ [2, 3]])
732
+ >>> polyval(a, [1, 2, 3])
733
+ array([[ 1., 6.],
734
+ [17., 34.]])
735
+ >>> coef = np.arange(4).reshape(2, 2) # multidimensional coefficients
736
+ >>> coef
737
+ array([[0, 1],
738
+ [2, 3]])
739
+ >>> polyval([1, 2], coef, tensor=True)
740
+ array([[2., 4.],
741
+ [4., 7.]])
742
+ >>> polyval([1, 2], coef, tensor=False)
743
+ array([2., 7.])
744
+
745
+ """
746
+ c = np.array(c, ndmin=1, copy=None)
747
+ if c.dtype.char in '?bBhHiIlLqQpP':
748
+ # astype fails with NA
749
+ c = c + 0.0
750
+ if isinstance(x, (tuple, list)):
751
+ x = np.asarray(x)
752
+ if isinstance(x, np.ndarray) and tensor:
753
+ c = c.reshape(c.shape + (1,) * x.ndim)
754
+
755
+ c0 = c[-1] + x * 0
756
+ for i in range(2, len(c) + 1):
757
+ c0 = c[-i] + c0 * x
758
+ return c0
759
+
760
+
761
+ def polyvalfromroots(x, r, tensor=True):
762
+ """
763
+ Evaluate a polynomial specified by its roots at points x.
764
+
765
+ If `r` is of length ``N``, this function returns the value
766
+
767
+ .. math:: p(x) = \\prod_{n=1}^{N} (x - r_n)
768
+
769
+ The parameter `x` is converted to an array only if it is a tuple or a
770
+ list, otherwise it is treated as a scalar. In either case, either `x`
771
+ or its elements must support multiplication and addition both with
772
+ themselves and with the elements of `r`.
773
+
774
+ If `r` is a 1-D array, then ``p(x)`` will have the same shape as `x`. If `r`
775
+ is multidimensional, then the shape of the result depends on the value of
776
+ `tensor`. If `tensor` is ``True`` the shape will be r.shape[1:] + x.shape;
777
+ that is, each polynomial is evaluated at every value of `x`. If `tensor` is
778
+ ``False``, the shape will be r.shape[1:]; that is, each polynomial is
779
+ evaluated only for the corresponding broadcast value of `x`. Note that
780
+ scalars have shape (,).
781
+
782
+ Parameters
783
+ ----------
784
+ x : array_like, compatible object
785
+ If `x` is a list or tuple, it is converted to an ndarray, otherwise
786
+ it is left unchanged and treated as a scalar. In either case, `x`
787
+ or its elements must support addition and multiplication with
788
+ with themselves and with the elements of `r`.
789
+ r : array_like
790
+ Array of roots. If `r` is multidimensional the first index is the
791
+ root index, while the remaining indices enumerate multiple
792
+ polynomials. For instance, in the two dimensional case the roots
793
+ of each polynomial may be thought of as stored in the columns of `r`.
794
+ tensor : boolean, optional
795
+ If True, the shape of the roots array is extended with ones on the
796
+ right, one for each dimension of `x`. Scalars have dimension 0 for this
797
+ action. The result is that every column of coefficients in `r` is
798
+ evaluated for every element of `x`. If False, `x` is broadcast over the
799
+ columns of `r` for the evaluation. This keyword is useful when `r` is
800
+ multidimensional. The default value is True.
801
+
802
+ Returns
803
+ -------
804
+ values : ndarray, compatible object
805
+ The shape of the returned array is described above.
806
+
807
+ See Also
808
+ --------
809
+ polyroots, polyfromroots, polyval
810
+
811
+ Examples
812
+ --------
813
+ >>> from numpy.polynomial.polynomial import polyvalfromroots
814
+ >>> polyvalfromroots(1, [1, 2, 3])
815
+ 0.0
816
+ >>> a = np.arange(4).reshape(2, 2)
817
+ >>> a
818
+ array([[0, 1],
819
+ [2, 3]])
820
+ >>> polyvalfromroots(a, [-1, 0, 1])
821
+ array([[-0., 0.],
822
+ [ 6., 24.]])
823
+ >>> r = np.arange(-2, 2).reshape(2,2) # multidimensional coefficients
824
+ >>> r # each column of r defines one polynomial
825
+ array([[-2, -1],
826
+ [ 0, 1]])
827
+ >>> b = [-2, 1]
828
+ >>> polyvalfromroots(b, r, tensor=True)
829
+ array([[-0., 3.],
830
+ [ 3., 0.]])
831
+ >>> polyvalfromroots(b, r, tensor=False)
832
+ array([-0., 0.])
833
+
834
+ """
835
+ r = np.array(r, ndmin=1, copy=None)
836
+ if r.dtype.char in '?bBhHiIlLqQpP':
837
+ r = r.astype(np.double)
838
+ if isinstance(x, (tuple, list)):
839
+ x = np.asarray(x)
840
+ if isinstance(x, np.ndarray):
841
+ if tensor:
842
+ r = r.reshape(r.shape + (1,) * x.ndim)
843
+ elif x.ndim >= r.ndim:
844
+ raise ValueError("x.ndim must be < r.ndim when tensor == False")
845
+ return np.prod(x - r, axis=0)
846
+
847
+ def _polyval2d_dispatcher(x, y, c):
848
+ return (x, y, c)
849
+
850
+ def _polygrid2d_dispatcher(x, y, c):
851
+ return (x, y, c)
852
+
853
+ @_array_function_dispatch(_polyval2d_dispatcher)
854
+ def polyval2d(x, y, c):
855
+ """
856
+ Evaluate a 2-D polynomial at points (x, y).
857
+
858
+ This function returns the value
859
+
860
+ .. math:: p(x,y) = \\sum_{i,j} c_{i,j} * x^i * y^j
861
+
862
+ The parameters `x` and `y` are converted to arrays only if they are
863
+ tuples or a lists, otherwise they are treated as a scalars and they
864
+ must have the same shape after conversion. In either case, either `x`
865
+ and `y` or their elements must support multiplication and addition both
866
+ with themselves and with the elements of `c`.
867
+
868
+ If `c` has fewer than two dimensions, ones are implicitly appended to
869
+ its shape to make it 2-D. The shape of the result will be c.shape[2:] +
870
+ x.shape.
871
+
872
+ Parameters
873
+ ----------
874
+ x, y : array_like, compatible objects
875
+ The two dimensional series is evaluated at the points ``(x, y)``,
876
+ where `x` and `y` must have the same shape. If `x` or `y` is a list
877
+ or tuple, it is first converted to an ndarray, otherwise it is left
878
+ unchanged and, if it isn't an ndarray, it is treated as a scalar.
879
+ c : array_like
880
+ Array of coefficients ordered so that the coefficient of the term
881
+ of multi-degree i,j is contained in ``c[i,j]``. If `c` has
882
+ dimension greater than two the remaining indices enumerate multiple
883
+ sets of coefficients.
884
+
885
+ Returns
886
+ -------
887
+ values : ndarray, compatible object
888
+ The values of the two dimensional polynomial at points formed with
889
+ pairs of corresponding values from `x` and `y`.
890
+
891
+ See Also
892
+ --------
893
+ polyval, polygrid2d, polyval3d, polygrid3d
894
+
895
+ Examples
896
+ --------
897
+ >>> from numpy.polynomial import polynomial as P
898
+ >>> c = ((1, 2, 3), (4, 5, 6))
899
+ >>> P.polyval2d(1, 1, c)
900
+ 21.0
901
+
902
+ """
903
+ return pu._valnd(polyval, c, x, y)
904
+
905
+ @_array_function_dispatch(_polygrid2d_dispatcher)
906
+ def polygrid2d(x, y, c):
907
+ """
908
+ Evaluate a 2-D polynomial on the Cartesian product of x and y.
909
+
910
+ This function returns the values:
911
+
912
+ .. math:: p(a,b) = \\sum_{i,j} c_{i,j} * a^i * b^j
913
+
914
+ where the points ``(a, b)`` consist of all pairs formed by taking
915
+ `a` from `x` and `b` from `y`. The resulting points form a grid with
916
+ `x` in the first dimension and `y` in the second.
917
+
918
+ The parameters `x` and `y` are converted to arrays only if they are
919
+ tuples or a lists, otherwise they are treated as a scalars. In either
920
+ case, either `x` and `y` or their elements must support multiplication
921
+ and addition both with themselves and with the elements of `c`.
922
+
923
+ If `c` has fewer than two dimensions, ones are implicitly appended to
924
+ its shape to make it 2-D. The shape of the result will be c.shape[2:] +
925
+ x.shape + y.shape.
926
+
927
+ Parameters
928
+ ----------
929
+ x, y : array_like, compatible objects
930
+ The two dimensional series is evaluated at the points in the
931
+ Cartesian product of `x` and `y`. If `x` or `y` is a list or
932
+ tuple, it is first converted to an ndarray, otherwise it is left
933
+ unchanged and, if it isn't an ndarray, it is treated as a scalar.
934
+ c : array_like
935
+ Array of coefficients ordered so that the coefficients for terms of
936
+ degree i,j are contained in ``c[i,j]``. If `c` has dimension
937
+ greater than two the remaining indices enumerate multiple sets of
938
+ coefficients.
939
+
940
+ Returns
941
+ -------
942
+ values : ndarray, compatible object
943
+ The values of the two dimensional polynomial at points in the Cartesian
944
+ product of `x` and `y`.
945
+
946
+ See Also
947
+ --------
948
+ polyval, polyval2d, polyval3d, polygrid3d
949
+
950
+ Examples
951
+ --------
952
+ >>> from numpy.polynomial import polynomial as P
953
+ >>> c = ((1, 2, 3), (4, 5, 6))
954
+ >>> P.polygrid2d([0, 1], [0, 1], c)
955
+ array([[ 1., 6.],
956
+ [ 5., 21.]])
957
+
958
+ """
959
+ return pu._gridnd(polyval, c, x, y)
960
+
961
+
962
+ def polyval3d(x, y, z, c):
963
+ """
964
+ Evaluate a 3-D polynomial at points (x, y, z).
965
+
966
+ This function returns the values:
967
+
968
+ .. math:: p(x,y,z) = \\sum_{i,j,k} c_{i,j,k} * x^i * y^j * z^k
969
+
970
+ The parameters `x`, `y`, and `z` are converted to arrays only if
971
+ they are tuples or a lists, otherwise they are treated as a scalars and
972
+ they must have the same shape after conversion. In either case, either
973
+ `x`, `y`, and `z` or their elements must support multiplication and
974
+ addition both with themselves and with the elements of `c`.
975
+
976
+ If `c` has fewer than 3 dimensions, ones are implicitly appended to its
977
+ shape to make it 3-D. The shape of the result will be c.shape[3:] +
978
+ x.shape.
979
+
980
+ Parameters
981
+ ----------
982
+ x, y, z : array_like, compatible object
983
+ The three dimensional series is evaluated at the points
984
+ ``(x, y, z)``, where `x`, `y`, and `z` must have the same shape. If
985
+ any of `x`, `y`, or `z` is a list or tuple, it is first converted
986
+ to an ndarray, otherwise it is left unchanged and if it isn't an
987
+ ndarray it is treated as a scalar.
988
+ c : array_like
989
+ Array of coefficients ordered so that the coefficient of the term of
990
+ multi-degree i,j,k is contained in ``c[i,j,k]``. If `c` has dimension
991
+ greater than 3 the remaining indices enumerate multiple sets of
992
+ coefficients.
993
+
994
+ Returns
995
+ -------
996
+ values : ndarray, compatible object
997
+ The values of the multidimensional polynomial on points formed with
998
+ triples of corresponding values from `x`, `y`, and `z`.
999
+
1000
+ See Also
1001
+ --------
1002
+ polyval, polyval2d, polygrid2d, polygrid3d
1003
+
1004
+ Examples
1005
+ --------
1006
+ >>> from numpy.polynomial import polynomial as P
1007
+ >>> c = ((1, 2, 3), (4, 5, 6), (7, 8, 9))
1008
+ >>> P.polyval3d(1, 1, 1, c)
1009
+ 45.0
1010
+
1011
+ """
1012
+ return pu._valnd(polyval, c, x, y, z)
1013
+
1014
+
1015
+ def polygrid3d(x, y, z, c):
1016
+ """
1017
+ Evaluate a 3-D polynomial on the Cartesian product of x, y and z.
1018
+
1019
+ This function returns the values:
1020
+
1021
+ .. math:: p(a,b,c) = \\sum_{i,j,k} c_{i,j,k} * a^i * b^j * c^k
1022
+
1023
+ where the points ``(a, b, c)`` consist of all triples formed by taking
1024
+ `a` from `x`, `b` from `y`, and `c` from `z`. The resulting points form
1025
+ a grid with `x` in the first dimension, `y` in the second, and `z` in
1026
+ the third.
1027
+
1028
+ The parameters `x`, `y`, and `z` are converted to arrays only if they
1029
+ are tuples or a lists, otherwise they are treated as a scalars. In
1030
+ either case, either `x`, `y`, and `z` or their elements must support
1031
+ multiplication and addition both with themselves and with the elements
1032
+ of `c`.
1033
+
1034
+ If `c` has fewer than three dimensions, ones are implicitly appended to
1035
+ its shape to make it 3-D. The shape of the result will be c.shape[3:] +
1036
+ x.shape + y.shape + z.shape.
1037
+
1038
+ Parameters
1039
+ ----------
1040
+ x, y, z : array_like, compatible objects
1041
+ The three dimensional series is evaluated at the points in the
1042
+ Cartesian product of `x`, `y`, and `z`. If `x`, `y`, or `z` is a
1043
+ list or tuple, it is first converted to an ndarray, otherwise it is
1044
+ left unchanged and, if it isn't an ndarray, it is treated as a
1045
+ scalar.
1046
+ c : array_like
1047
+ Array of coefficients ordered so that the coefficients for terms of
1048
+ degree i,j are contained in ``c[i,j]``. If `c` has dimension
1049
+ greater than two the remaining indices enumerate multiple sets of
1050
+ coefficients.
1051
+
1052
+ Returns
1053
+ -------
1054
+ values : ndarray, compatible object
1055
+ The values of the two dimensional polynomial at points in the Cartesian
1056
+ product of `x` and `y`.
1057
+
1058
+ See Also
1059
+ --------
1060
+ polyval, polyval2d, polygrid2d, polyval3d
1061
+
1062
+ Examples
1063
+ --------
1064
+ >>> from numpy.polynomial import polynomial as P
1065
+ >>> c = ((1, 2, 3), (4, 5, 6), (7, 8, 9))
1066
+ >>> P.polygrid3d([0, 1], [0, 1], [0, 1], c)
1067
+ array([[ 1., 13.],
1068
+ [ 6., 51.]])
1069
+
1070
+ """
1071
+ return pu._gridnd(polyval, c, x, y, z)
1072
+
1073
+
1074
+ def polyvander(x, deg):
1075
+ """Vandermonde matrix of given degree.
1076
+
1077
+ Returns the Vandermonde matrix of degree `deg` and sample points
1078
+ `x`. The Vandermonde matrix is defined by
1079
+
1080
+ .. math:: V[..., i] = x^i,
1081
+
1082
+ where ``0 <= i <= deg``. The leading indices of `V` index the elements of
1083
+ `x` and the last index is the power of `x`.
1084
+
1085
+ If `c` is a 1-D array of coefficients of length ``n + 1`` and `V` is the
1086
+ matrix ``V = polyvander(x, n)``, then ``np.dot(V, c)`` and
1087
+ ``polyval(x, c)`` are the same up to roundoff. This equivalence is
1088
+ useful both for least squares fitting and for the evaluation of a large
1089
+ number of polynomials of the same degree and sample points.
1090
+
1091
+ Parameters
1092
+ ----------
1093
+ x : array_like
1094
+ Array of points. The dtype is converted to float64 or complex128
1095
+ depending on whether any of the elements are complex. If `x` is
1096
+ scalar it is converted to a 1-D array.
1097
+ deg : int
1098
+ Degree of the resulting matrix.
1099
+
1100
+ Returns
1101
+ -------
1102
+ vander : ndarray.
1103
+ The Vandermonde matrix. The shape of the returned matrix is
1104
+ ``x.shape + (deg + 1,)``, where the last index is the power of `x`.
1105
+ The dtype will be the same as the converted `x`.
1106
+
1107
+ See Also
1108
+ --------
1109
+ polyvander2d, polyvander3d
1110
+
1111
+ Examples
1112
+ --------
1113
+ The Vandermonde matrix of degree ``deg = 5`` and sample points
1114
+ ``x = [-1, 2, 3]`` contains the element-wise powers of `x`
1115
+ from 0 to 5 as its columns.
1116
+
1117
+ >>> from numpy.polynomial import polynomial as P
1118
+ >>> x, deg = [-1, 2, 3], 5
1119
+ >>> P.polyvander(x=x, deg=deg)
1120
+ array([[ 1., -1., 1., -1., 1., -1.],
1121
+ [ 1., 2., 4., 8., 16., 32.],
1122
+ [ 1., 3., 9., 27., 81., 243.]])
1123
+
1124
+ """
1125
+ ideg = pu._as_int(deg, "deg")
1126
+ if ideg < 0:
1127
+ raise ValueError("deg must be non-negative")
1128
+
1129
+ x = np.array(x, copy=None, ndmin=1) + 0.0
1130
+ dims = (ideg + 1,) + x.shape
1131
+ dtyp = x.dtype
1132
+ v = np.empty(dims, dtype=dtyp)
1133
+ v[0] = x * 0 + 1
1134
+ if ideg > 0:
1135
+ v[1] = x
1136
+ for i in range(2, ideg + 1):
1137
+ v[i] = v[i - 1] * x
1138
+ return np.moveaxis(v, 0, -1)
1139
+
1140
+
1141
+ def polyvander2d(x, y, deg):
1142
+ """Pseudo-Vandermonde matrix of given degrees.
1143
+
1144
+ Returns the pseudo-Vandermonde matrix of degrees `deg` and sample
1145
+ points ``(x, y)``. The pseudo-Vandermonde matrix is defined by
1146
+
1147
+ .. math:: V[..., (deg[1] + 1)*i + j] = x^i * y^j,
1148
+
1149
+ where ``0 <= i <= deg[0]`` and ``0 <= j <= deg[1]``. The leading indices of
1150
+ `V` index the points ``(x, y)`` and the last index encodes the powers of
1151
+ `x` and `y`.
1152
+
1153
+ If ``V = polyvander2d(x, y, [xdeg, ydeg])``, then the columns of `V`
1154
+ correspond to the elements of a 2-D coefficient array `c` of shape
1155
+ (xdeg + 1, ydeg + 1) in the order
1156
+
1157
+ .. math:: c_{00}, c_{01}, c_{02} ... , c_{10}, c_{11}, c_{12} ...
1158
+
1159
+ and ``np.dot(V, c.flat)`` and ``polyval2d(x, y, c)`` will be the same
1160
+ up to roundoff. This equivalence is useful both for least squares
1161
+ fitting and for the evaluation of a large number of 2-D polynomials
1162
+ of the same degrees and sample points.
1163
+
1164
+ Parameters
1165
+ ----------
1166
+ x, y : array_like
1167
+ Arrays of point coordinates, all of the same shape. The dtypes
1168
+ will be converted to either float64 or complex128 depending on
1169
+ whether any of the elements are complex. Scalars are converted to
1170
+ 1-D arrays.
1171
+ deg : list of ints
1172
+ List of maximum degrees of the form [x_deg, y_deg].
1173
+
1174
+ Returns
1175
+ -------
1176
+ vander2d : ndarray
1177
+ The shape of the returned matrix is ``x.shape + (order,)``, where
1178
+ :math:`order = (deg[0]+1)*(deg([1]+1)`. The dtype will be the same
1179
+ as the converted `x` and `y`.
1180
+
1181
+ See Also
1182
+ --------
1183
+ polyvander, polyvander3d, polyval2d, polyval3d
1184
+
1185
+ Examples
1186
+ --------
1187
+ >>> import numpy as np
1188
+
1189
+ The 2-D pseudo-Vandermonde matrix of degree ``[1, 2]`` and sample
1190
+ points ``x = [-1, 2]`` and ``y = [1, 3]`` is as follows:
1191
+
1192
+ >>> from numpy.polynomial import polynomial as P
1193
+ >>> x = np.array([-1, 2])
1194
+ >>> y = np.array([1, 3])
1195
+ >>> m, n = 1, 2
1196
+ >>> deg = np.array([m, n])
1197
+ >>> V = P.polyvander2d(x=x, y=y, deg=deg)
1198
+ >>> V
1199
+ array([[ 1., 1., 1., -1., -1., -1.],
1200
+ [ 1., 3., 9., 2., 6., 18.]])
1201
+
1202
+ We can verify the columns for any ``0 <= i <= m`` and ``0 <= j <= n``:
1203
+
1204
+ >>> i, j = 0, 1
1205
+ >>> V[:, (deg[1]+1)*i + j] == x**i * y**j
1206
+ array([ True, True])
1207
+
1208
+ The (1D) Vandermonde matrix of sample points ``x`` and degree ``m`` is a
1209
+ special case of the (2D) pseudo-Vandermonde matrix with ``y`` points all
1210
+ zero and degree ``[m, 0]``.
1211
+
1212
+ >>> P.polyvander2d(x=x, y=0*x, deg=(m, 0)) == P.polyvander(x=x, deg=m)
1213
+ array([[ True, True],
1214
+ [ True, True]])
1215
+
1216
+ """
1217
+ return pu._vander_nd_flat((polyvander, polyvander), (x, y), deg)
1218
+
1219
+
1220
+ def polyvander3d(x, y, z, deg):
1221
+ """Pseudo-Vandermonde matrix of given degrees.
1222
+
1223
+ Returns the pseudo-Vandermonde matrix of degrees `deg` and sample
1224
+ points ``(x, y, z)``. If `l`, `m`, `n` are the given degrees in `x`, `y`, `z`,
1225
+ then The pseudo-Vandermonde matrix is defined by
1226
+
1227
+ .. math:: V[..., (m+1)(n+1)i + (n+1)j + k] = x^i * y^j * z^k,
1228
+
1229
+ where ``0 <= i <= l``, ``0 <= j <= m``, and ``0 <= j <= n``. The leading
1230
+ indices of `V` index the points ``(x, y, z)`` and the last index encodes
1231
+ the powers of `x`, `y`, and `z`.
1232
+
1233
+ If ``V = polyvander3d(x, y, z, [xdeg, ydeg, zdeg])``, then the columns
1234
+ of `V` correspond to the elements of a 3-D coefficient array `c` of
1235
+ shape (xdeg + 1, ydeg + 1, zdeg + 1) in the order
1236
+
1237
+ .. math:: c_{000}, c_{001}, c_{002},... , c_{010}, c_{011}, c_{012},...
1238
+
1239
+ and ``np.dot(V, c.flat)`` and ``polyval3d(x, y, z, c)`` will be the
1240
+ same up to roundoff. This equivalence is useful both for least squares
1241
+ fitting and for the evaluation of a large number of 3-D polynomials
1242
+ of the same degrees and sample points.
1243
+
1244
+ Parameters
1245
+ ----------
1246
+ x, y, z : array_like
1247
+ Arrays of point coordinates, all of the same shape. The dtypes will
1248
+ be converted to either float64 or complex128 depending on whether
1249
+ any of the elements are complex. Scalars are converted to 1-D
1250
+ arrays.
1251
+ deg : list of ints
1252
+ List of maximum degrees of the form [x_deg, y_deg, z_deg].
1253
+
1254
+ Returns
1255
+ -------
1256
+ vander3d : ndarray
1257
+ The shape of the returned matrix is ``x.shape + (order,)``, where
1258
+ :math:`order = (deg[0]+1)*(deg([1]+1)*(deg[2]+1)`. The dtype will
1259
+ be the same as the converted `x`, `y`, and `z`.
1260
+
1261
+ See Also
1262
+ --------
1263
+ polyvander, polyvander3d, polyval2d, polyval3d
1264
+
1265
+ Examples
1266
+ --------
1267
+ >>> import numpy as np
1268
+ >>> from numpy.polynomial import polynomial as P
1269
+ >>> x = np.asarray([-1, 2, 1])
1270
+ >>> y = np.asarray([1, -2, -3])
1271
+ >>> z = np.asarray([2, 2, 5])
1272
+ >>> l, m, n = [2, 2, 1]
1273
+ >>> deg = [l, m, n]
1274
+ >>> V = P.polyvander3d(x=x, y=y, z=z, deg=deg)
1275
+ >>> V
1276
+ array([[ 1., 2., 1., 2., 1., 2., -1., -2., -1.,
1277
+ -2., -1., -2., 1., 2., 1., 2., 1., 2.],
1278
+ [ 1., 2., -2., -4., 4., 8., 2., 4., -4.,
1279
+ -8., 8., 16., 4., 8., -8., -16., 16., 32.],
1280
+ [ 1., 5., -3., -15., 9., 45., 1., 5., -3.,
1281
+ -15., 9., 45., 1., 5., -3., -15., 9., 45.]])
1282
+
1283
+ We can verify the columns for any ``0 <= i <= l``, ``0 <= j <= m``,
1284
+ and ``0 <= k <= n``
1285
+
1286
+ >>> i, j, k = 2, 1, 0
1287
+ >>> V[:, (m+1)*(n+1)*i + (n+1)*j + k] == x**i * y**j * z**k
1288
+ array([ True, True, True])
1289
+
1290
+ """
1291
+ return pu._vander_nd_flat((polyvander, polyvander, polyvander), (x, y, z), deg)
1292
+
1293
+
1294
+ def polyfit(x, y, deg, rcond=None, full=False, w=None):
1295
+ """
1296
+ Least-squares fit of a polynomial to data.
1297
+
1298
+ Return the coefficients of a polynomial of degree `deg` that is the
1299
+ least squares fit to the data values `y` given at points `x`. If `y` is
1300
+ 1-D the returned coefficients will also be 1-D. If `y` is 2-D multiple
1301
+ fits are done, one for each column of `y`, and the resulting
1302
+ coefficients are stored in the corresponding columns of a 2-D return.
1303
+ The fitted polynomial(s) are in the form
1304
+
1305
+ .. math:: p(x) = c_0 + c_1 * x + ... + c_n * x^n,
1306
+
1307
+ where `n` is `deg`.
1308
+
1309
+ Parameters
1310
+ ----------
1311
+ x : array_like, shape (`M`,)
1312
+ x-coordinates of the `M` sample (data) points ``(x[i], y[i])``.
1313
+ y : array_like, shape (`M`,) or (`M`, `K`)
1314
+ y-coordinates of the sample points. Several sets of sample points
1315
+ sharing the same x-coordinates can be (independently) fit with one
1316
+ call to `polyfit` by passing in for `y` a 2-D array that contains
1317
+ one data set per column.
1318
+ deg : int or 1-D array_like
1319
+ Degree(s) of the fitting polynomials. If `deg` is a single integer
1320
+ all terms up to and including the `deg`'th term are included in the
1321
+ fit. For NumPy versions >= 1.11.0 a list of integers specifying the
1322
+ degrees of the terms to include may be used instead.
1323
+ rcond : float, optional
1324
+ Relative condition number of the fit. Singular values smaller
1325
+ than `rcond`, relative to the largest singular value, will be
1326
+ ignored. The default value is ``len(x)*eps``, where `eps` is the
1327
+ relative precision of the platform's float type, about 2e-16 in
1328
+ most cases.
1329
+ full : bool, optional
1330
+ Switch determining the nature of the return value. When ``False``
1331
+ (the default) just the coefficients are returned; when ``True``,
1332
+ diagnostic information from the singular value decomposition (used
1333
+ to solve the fit's matrix equation) is also returned.
1334
+ w : array_like, shape (`M`,), optional
1335
+ Weights. If not None, the weight ``w[i]`` applies to the unsquared
1336
+ residual ``y[i] - y_hat[i]`` at ``x[i]``. Ideally the weights are
1337
+ chosen so that the errors of the products ``w[i]*y[i]`` all have the
1338
+ same variance. When using inverse-variance weighting, use
1339
+ ``w[i] = 1/sigma(y[i])``. The default value is None.
1340
+
1341
+ Returns
1342
+ -------
1343
+ coef : ndarray, shape (`deg` + 1,) or (`deg` + 1, `K`)
1344
+ Polynomial coefficients ordered from low to high. If `y` was 2-D,
1345
+ the coefficients in column `k` of `coef` represent the polynomial
1346
+ fit to the data in `y`'s `k`-th column.
1347
+
1348
+ [residuals, rank, singular_values, rcond] : list
1349
+ These values are only returned if ``full == True``
1350
+
1351
+ - residuals -- sum of squared residuals of the least squares fit
1352
+ - rank -- the numerical rank of the scaled Vandermonde matrix
1353
+ - singular_values -- singular values of the scaled Vandermonde matrix
1354
+ - rcond -- value of `rcond`.
1355
+
1356
+ For more details, see `numpy.linalg.lstsq`.
1357
+
1358
+ Raises
1359
+ ------
1360
+ RankWarning
1361
+ Raised if the matrix in the least-squares fit is rank deficient.
1362
+ The warning is only raised if ``full == False``. The warnings can
1363
+ be turned off by:
1364
+
1365
+ >>> import warnings
1366
+ >>> warnings.simplefilter('ignore', np.exceptions.RankWarning)
1367
+
1368
+ See Also
1369
+ --------
1370
+ numpy.polynomial.chebyshev.chebfit
1371
+ numpy.polynomial.legendre.legfit
1372
+ numpy.polynomial.laguerre.lagfit
1373
+ numpy.polynomial.hermite.hermfit
1374
+ numpy.polynomial.hermite_e.hermefit
1375
+ polyval : Evaluates a polynomial.
1376
+ polyvander : Vandermonde matrix for powers.
1377
+ numpy.linalg.lstsq : Computes a least-squares fit from the matrix.
1378
+ scipy.interpolate.UnivariateSpline : Computes spline fits.
1379
+
1380
+ Notes
1381
+ -----
1382
+ The solution is the coefficients of the polynomial `p` that minimizes
1383
+ the sum of the weighted squared errors
1384
+
1385
+ .. math:: E = \\sum_j w_j^2 * |y_j - p(x_j)|^2,
1386
+
1387
+ where the :math:`w_j` are the weights. This problem is solved by
1388
+ setting up the (typically) over-determined matrix equation:
1389
+
1390
+ .. math:: V(x) * c = w * y,
1391
+
1392
+ where `V` is the weighted pseudo Vandermonde matrix of `x`, `c` are the
1393
+ coefficients to be solved for, `w` are the weights, and `y` are the
1394
+ observed values. This equation is then solved using the singular value
1395
+ decomposition of `V`.
1396
+
1397
+ If some of the singular values of `V` are so small that they are
1398
+ neglected (and `full` == ``False``), a `~exceptions.RankWarning` will be
1399
+ raised. This means that the coefficient values may be poorly determined.
1400
+ Fitting to a lower order polynomial will usually get rid of the warning
1401
+ (but may not be what you want, of course; if you have independent
1402
+ reason(s) for choosing the degree which isn't working, you may have to:
1403
+ a) reconsider those reasons, and/or b) reconsider the quality of your
1404
+ data). The `rcond` parameter can also be set to a value smaller than
1405
+ its default, but the resulting fit may be spurious and have large
1406
+ contributions from roundoff error.
1407
+
1408
+ Polynomial fits using double precision tend to "fail" at about
1409
+ (polynomial) degree 20. Fits using Chebyshev or Legendre series are
1410
+ generally better conditioned, but much can still depend on the
1411
+ distribution of the sample points and the smoothness of the data. If
1412
+ the quality of the fit is inadequate, splines may be a good
1413
+ alternative.
1414
+
1415
+ Examples
1416
+ --------
1417
+ >>> import numpy as np
1418
+ >>> from numpy.polynomial import polynomial as P
1419
+ >>> x = np.linspace(-1,1,51) # x "data": [-1, -0.96, ..., 0.96, 1]
1420
+ >>> rng = np.random.default_rng()
1421
+ >>> err = rng.normal(size=len(x))
1422
+ >>> y = x**3 - x + err # x^3 - x + Gaussian noise
1423
+ >>> c, stats = P.polyfit(x,y,3,full=True)
1424
+ >>> c # c[0], c[1] approx. -1, c[2] should be approx. 0, c[3] approx. 1
1425
+ array([ 0.23111996, -1.02785049, -0.2241444 , 1.08405657]) # may vary
1426
+ >>> stats # note the large SSR, explaining the rather poor results
1427
+ [array([48.312088]), # may vary
1428
+ 4,
1429
+ array([1.38446749, 1.32119158, 0.50443316, 0.28853036]),
1430
+ 1.1324274851176597e-14]
1431
+
1432
+ Same thing without the added noise
1433
+
1434
+ >>> y = x**3 - x
1435
+ >>> c, stats = P.polyfit(x,y,3,full=True)
1436
+ >>> c # c[0], c[1] ~= -1, c[2] should be "very close to 0", c[3] ~= 1
1437
+ array([-6.73496154e-17, -1.00000000e+00, 0.00000000e+00, 1.00000000e+00])
1438
+ >>> stats # note the minuscule SSR
1439
+ [array([8.79579319e-31]),
1440
+ np.int32(4),
1441
+ array([1.38446749, 1.32119158, 0.50443316, 0.28853036]),
1442
+ 1.1324274851176597e-14]
1443
+
1444
+ """
1445
+ return pu._fit(polyvander, x, y, deg, rcond, full, w)
1446
+
1447
+
1448
+ def polycompanion(c):
1449
+ """
1450
+ Return the companion matrix of c.
1451
+
1452
+ The companion matrix for power series cannot be made symmetric by
1453
+ scaling the basis, so this function differs from those for the
1454
+ orthogonal polynomials.
1455
+
1456
+ Parameters
1457
+ ----------
1458
+ c : array_like
1459
+ 1-D array of polynomial coefficients ordered from low to high
1460
+ degree.
1461
+
1462
+ Returns
1463
+ -------
1464
+ mat : ndarray
1465
+ Companion matrix of dimensions (deg, deg).
1466
+
1467
+ Examples
1468
+ --------
1469
+ >>> from numpy.polynomial import polynomial as P
1470
+ >>> c = (1, 2, 3)
1471
+ >>> P.polycompanion(c)
1472
+ array([[ 0. , -0.33333333],
1473
+ [ 1. , -0.66666667]])
1474
+
1475
+ """
1476
+ # c is a trimmed copy
1477
+ [c] = pu.as_series([c])
1478
+ if len(c) < 2:
1479
+ raise ValueError('Series must have maximum degree of at least 1.')
1480
+ if len(c) == 2:
1481
+ return np.array([[-c[0] / c[1]]])
1482
+
1483
+ n = len(c) - 1
1484
+ mat = np.zeros((n, n), dtype=c.dtype)
1485
+ bot = mat.reshape(-1)[n::n + 1]
1486
+ bot[...] = 1
1487
+ mat[:, -1] -= c[:-1] / c[-1]
1488
+ return mat
1489
+
1490
+
1491
+ def polyroots(c):
1492
+ """
1493
+ Compute the roots of a polynomial.
1494
+
1495
+ Return the roots (a.k.a. "zeros") of the polynomial
1496
+
1497
+ .. math:: p(x) = \\sum_i c[i] * x^i.
1498
+
1499
+ Parameters
1500
+ ----------
1501
+ c : 1-D array_like
1502
+ 1-D array of polynomial coefficients.
1503
+
1504
+ Returns
1505
+ -------
1506
+ out : ndarray
1507
+ Array of the roots of the polynomial. If all the roots are real,
1508
+ then `out` is also real, otherwise it is complex.
1509
+
1510
+ See Also
1511
+ --------
1512
+ numpy.polynomial.chebyshev.chebroots
1513
+ numpy.polynomial.legendre.legroots
1514
+ numpy.polynomial.laguerre.lagroots
1515
+ numpy.polynomial.hermite.hermroots
1516
+ numpy.polynomial.hermite_e.hermeroots
1517
+
1518
+ Notes
1519
+ -----
1520
+ The root estimates are obtained as the eigenvalues of the companion
1521
+ matrix, Roots far from the origin of the complex plane may have large
1522
+ errors due to the numerical instability of the power series for such
1523
+ values. Roots with multiplicity greater than 1 will also show larger
1524
+ errors as the value of the series near such points is relatively
1525
+ insensitive to errors in the roots. Isolated roots near the origin can
1526
+ be improved by a few iterations of Newton's method.
1527
+
1528
+ Examples
1529
+ --------
1530
+ >>> import numpy.polynomial.polynomial as poly
1531
+ >>> poly.polyroots(poly.polyfromroots((-1,0,1)))
1532
+ array([-1., 0., 1.])
1533
+ >>> poly.polyroots(poly.polyfromroots((-1,0,1))).dtype
1534
+ dtype('float64')
1535
+ >>> j = complex(0,1)
1536
+ >>> poly.polyroots(poly.polyfromroots((-j,0,j)))
1537
+ array([ 0.00000000e+00+0.j, 0.00000000e+00+1.j, 2.77555756e-17-1.j]) # may vary
1538
+
1539
+ """ # noqa: E501
1540
+ # c is a trimmed copy
1541
+ [c] = pu.as_series([c])
1542
+ if len(c) < 2:
1543
+ return np.array([], dtype=c.dtype)
1544
+ if len(c) == 2:
1545
+ return np.array([-c[0] / c[1]])
1546
+
1547
+ m = polycompanion(c)
1548
+ r = np.linalg.eigvals(m)
1549
+ r.sort()
1550
+ return r
1551
+
1552
+
1553
+ #
1554
+ # polynomial class
1555
+ #
1556
+
1557
+ class Polynomial(ABCPolyBase):
1558
+ """A power series class.
1559
+
1560
+ The Polynomial class provides the standard Python numerical methods
1561
+ '+', '-', '*', '//', '%', 'divmod', '**', and '()' as well as the
1562
+ attributes and methods listed below.
1563
+
1564
+ Parameters
1565
+ ----------
1566
+ coef : array_like
1567
+ Polynomial coefficients in order of increasing degree, i.e.,
1568
+ ``(1, 2, 3)`` give ``1 + 2*x + 3*x**2``.
1569
+ domain : (2,) array_like, optional
1570
+ Domain to use. The interval ``[domain[0], domain[1]]`` is mapped
1571
+ to the interval ``[window[0], window[1]]`` by shifting and scaling.
1572
+ The default value is [-1., 1.].
1573
+ window : (2,) array_like, optional
1574
+ Window, see `domain` for its use. The default value is [-1., 1.].
1575
+ symbol : str, optional
1576
+ Symbol used to represent the independent variable in string
1577
+ representations of the polynomial expression, e.g. for printing.
1578
+ The symbol must be a valid Python identifier. Default value is 'x'.
1579
+
1580
+ .. versionadded:: 1.24
1581
+
1582
+ """
1583
+ # Virtual Functions
1584
+ _add = staticmethod(polyadd)
1585
+ _sub = staticmethod(polysub)
1586
+ _mul = staticmethod(polymul)
1587
+ _div = staticmethod(polydiv)
1588
+ _pow = staticmethod(polypow)
1589
+ _val = staticmethod(polyval)
1590
+ _int = staticmethod(polyint)
1591
+ _der = staticmethod(polyder)
1592
+ _fit = staticmethod(polyfit)
1593
+ _line = staticmethod(polyline)
1594
+ _roots = staticmethod(polyroots)
1595
+ _fromroots = staticmethod(polyfromroots)
1596
+
1597
+ # Virtual properties
1598
+ domain = np.array(polydomain)
1599
+ window = np.array(polydomain)
1600
+ basis_name = None
1601
+
1602
+ @classmethod
1603
+ def _str_term_unicode(cls, i, arg_str):
1604
+ if i == '1':
1605
+ return f"·{arg_str}"
1606
+ else:
1607
+ return f"·{arg_str}{i.translate(cls._superscript_mapping)}"
1608
+
1609
+ @staticmethod
1610
+ def _str_term_ascii(i, arg_str):
1611
+ if i == '1':
1612
+ return f" {arg_str}"
1613
+ else:
1614
+ return f" {arg_str}**{i}"
1615
+
1616
+ @staticmethod
1617
+ def _repr_latex_term(i, arg_str, needs_parens):
1618
+ if needs_parens:
1619
+ arg_str = rf"\left({arg_str}\right)"
1620
+ if i == 0:
1621
+ return '1'
1622
+ elif i == 1:
1623
+ return arg_str
1624
+ else:
1625
+ return f"{arg_str}^{{{i}}}"
physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy/polynomial/polynomial.pyi ADDED
@@ -0,0 +1,109 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import Any, ClassVar, Final, overload
2
+
3
+ import numpy as np
4
+ import numpy.typing as npt
5
+ from numpy._typing import (
6
+ _ArrayLikeFloat_co,
7
+ _ArrayLikeNumber_co,
8
+ _FloatLike_co,
9
+ _NumberLike_co,
10
+ )
11
+
12
+ from ._polybase import ABCPolyBase
13
+ from ._polytypes import (
14
+ _Array1,
15
+ _Array2,
16
+ _ArrayLikeCoef_co,
17
+ _FuncBinOp,
18
+ _FuncCompanion,
19
+ _FuncDer,
20
+ _FuncFit,
21
+ _FuncFromRoots,
22
+ _FuncInteg,
23
+ _FuncLine,
24
+ _FuncPow,
25
+ _FuncRoots,
26
+ _FuncUnOp,
27
+ _FuncVal,
28
+ _FuncVal2D,
29
+ _FuncVal3D,
30
+ _FuncVander,
31
+ _FuncVander2D,
32
+ _FuncVander3D,
33
+ )
34
+ from .polyutils import trimcoef as polytrim
35
+
36
+ __all__ = [
37
+ "polyzero",
38
+ "polyone",
39
+ "polyx",
40
+ "polydomain",
41
+ "polyline",
42
+ "polyadd",
43
+ "polysub",
44
+ "polymulx",
45
+ "polymul",
46
+ "polydiv",
47
+ "polypow",
48
+ "polyval",
49
+ "polyvalfromroots",
50
+ "polyder",
51
+ "polyint",
52
+ "polyfromroots",
53
+ "polyvander",
54
+ "polyfit",
55
+ "polytrim",
56
+ "polyroots",
57
+ "Polynomial",
58
+ "polyval2d",
59
+ "polyval3d",
60
+ "polygrid2d",
61
+ "polygrid3d",
62
+ "polyvander2d",
63
+ "polyvander3d",
64
+ "polycompanion",
65
+ ]
66
+
67
+ polydomain: Final[_Array2[np.float64]] = ...
68
+ polyzero: Final[_Array1[np.int_]] = ...
69
+ polyone: Final[_Array1[np.int_]] = ...
70
+ polyx: Final[_Array2[np.int_]] = ...
71
+
72
+ polyline: Final[_FuncLine] = ...
73
+ polyfromroots: Final[_FuncFromRoots] = ...
74
+ polyadd: Final[_FuncBinOp] = ...
75
+ polysub: Final[_FuncBinOp] = ...
76
+ polymulx: Final[_FuncUnOp] = ...
77
+ polymul: Final[_FuncBinOp] = ...
78
+ polydiv: Final[_FuncBinOp] = ...
79
+ polypow: Final[_FuncPow] = ...
80
+ polyder: Final[_FuncDer] = ...
81
+ polyint: Final[_FuncInteg] = ...
82
+ polyval: Final[_FuncVal] = ...
83
+ polyval2d: Final[_FuncVal2D] = ...
84
+ polyval3d: Final[_FuncVal3D] = ...
85
+
86
+ @overload
87
+ def polyvalfromroots(x: _FloatLike_co, r: _FloatLike_co, tensor: bool = True) -> np.float64 | Any: ...
88
+ @overload
89
+ def polyvalfromroots(x: _NumberLike_co, r: _NumberLike_co, tensor: bool = True) -> np.complex128 | Any: ...
90
+ @overload
91
+ def polyvalfromroots(x: _ArrayLikeFloat_co, r: _ArrayLikeFloat_co, tensor: bool = True) -> npt.NDArray[np.float64 | Any]: ...
92
+ @overload
93
+ def polyvalfromroots(x: _ArrayLikeNumber_co, r: _ArrayLikeNumber_co, tensor: bool = True) -> npt.NDArray[np.complex128 | Any]: ...
94
+ @overload
95
+ def polyvalfromroots(x: _ArrayLikeCoef_co, r: _ArrayLikeCoef_co, tensor: bool = True) -> npt.NDArray[np.object_ | Any]: ...
96
+
97
+ polygrid2d: Final[_FuncVal2D] = ...
98
+ polygrid3d: Final[_FuncVal3D] = ...
99
+ polyvander: Final[_FuncVander] = ...
100
+ polyvander2d: Final[_FuncVander2D] = ...
101
+ polyvander3d: Final[_FuncVander3D] = ...
102
+ polyfit: Final[_FuncFit] = ...
103
+ polycompanion: Final[_FuncCompanion] = ...
104
+ polyroots: Final[_FuncRoots] = ...
105
+
106
+ class Polynomial(ABCPolyBase[None]):
107
+ basis_name: ClassVar[None] = None # pyright: ignore[reportIncompatibleMethodOverride]
108
+ domain: _Array2[np.float64 | Any] = ... # pyright: ignore[reportIncompatibleMethodOverride]
109
+ window: _Array2[np.float64 | Any] = ... # pyright: ignore[reportIncompatibleMethodOverride]
physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy/polynomial/polyutils.py ADDED
@@ -0,0 +1,759 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Utility classes and functions for the polynomial modules.
3
+
4
+ This module provides: error and warning objects; a polynomial base class;
5
+ and some routines used in both the `polynomial` and `chebyshev` modules.
6
+
7
+ Functions
8
+ ---------
9
+
10
+ .. autosummary::
11
+ :toctree: generated/
12
+
13
+ as_series convert list of array_likes into 1-D arrays of common type.
14
+ trimseq remove trailing zeros.
15
+ trimcoef remove small trailing coefficients.
16
+ getdomain return the domain appropriate for a given set of abscissae.
17
+ mapdomain maps points between domains.
18
+ mapparms parameters of the linear map between domains.
19
+
20
+ """
21
+ import functools
22
+ import operator
23
+ import warnings
24
+
25
+ import numpy as np
26
+
27
+ __all__ = [
28
+ 'as_series', 'trimseq', 'trimcoef', 'getdomain', 'mapdomain', 'mapparms',
29
+ 'format_float']
30
+
31
+ #
32
+ # Helper functions to convert inputs to 1-D arrays
33
+ #
34
+ def trimseq(seq):
35
+ """Remove small Poly series coefficients.
36
+
37
+ Parameters
38
+ ----------
39
+ seq : sequence
40
+ Sequence of Poly series coefficients.
41
+
42
+ Returns
43
+ -------
44
+ series : sequence
45
+ Subsequence with trailing zeros removed. If the resulting sequence
46
+ would be empty, return the first element. The returned sequence may
47
+ or may not be a view.
48
+
49
+ Notes
50
+ -----
51
+ Do not lose the type info if the sequence contains unknown objects.
52
+
53
+ """
54
+ if len(seq) == 0 or seq[-1] != 0:
55
+ return seq
56
+ else:
57
+ for i in range(len(seq) - 1, -1, -1):
58
+ if seq[i] != 0:
59
+ break
60
+ return seq[:i + 1]
61
+
62
+
63
+ def as_series(alist, trim=True):
64
+ """
65
+ Return argument as a list of 1-d arrays.
66
+
67
+ The returned list contains array(s) of dtype double, complex double, or
68
+ object. A 1-d argument of shape ``(N,)`` is parsed into ``N`` arrays of
69
+ size one; a 2-d argument of shape ``(M,N)`` is parsed into ``M`` arrays
70
+ of size ``N`` (i.e., is "parsed by row"); and a higher dimensional array
71
+ raises a Value Error if it is not first reshaped into either a 1-d or 2-d
72
+ array.
73
+
74
+ Parameters
75
+ ----------
76
+ alist : array_like
77
+ A 1- or 2-d array_like
78
+ trim : boolean, optional
79
+ When True, trailing zeros are removed from the inputs.
80
+ When False, the inputs are passed through intact.
81
+
82
+ Returns
83
+ -------
84
+ [a1, a2,...] : list of 1-D arrays
85
+ A copy of the input data as a list of 1-d arrays.
86
+
87
+ Raises
88
+ ------
89
+ ValueError
90
+ Raised when `as_series` cannot convert its input to 1-d arrays, or at
91
+ least one of the resulting arrays is empty.
92
+
93
+ Examples
94
+ --------
95
+ >>> import numpy as np
96
+ >>> from numpy.polynomial import polyutils as pu
97
+ >>> a = np.arange(4)
98
+ >>> pu.as_series(a)
99
+ [array([0.]), array([1.]), array([2.]), array([3.])]
100
+ >>> b = np.arange(6).reshape((2,3))
101
+ >>> pu.as_series(b)
102
+ [array([0., 1., 2.]), array([3., 4., 5.])]
103
+
104
+ >>> pu.as_series((1, np.arange(3), np.arange(2, dtype=np.float16)))
105
+ [array([1.]), array([0., 1., 2.]), array([0., 1.])]
106
+
107
+ >>> pu.as_series([2, [1.1, 0.]])
108
+ [array([2.]), array([1.1])]
109
+
110
+ >>> pu.as_series([2, [1.1, 0.]], trim=False)
111
+ [array([2.]), array([1.1, 0. ])]
112
+
113
+ """
114
+ arrays = [np.array(a, ndmin=1, copy=None) for a in alist]
115
+ for a in arrays:
116
+ if a.size == 0:
117
+ raise ValueError("Coefficient array is empty")
118
+ if a.ndim != 1:
119
+ raise ValueError("Coefficient array is not 1-d")
120
+ if trim:
121
+ arrays = [trimseq(a) for a in arrays]
122
+
123
+ try:
124
+ dtype = np.common_type(*arrays)
125
+ except Exception as e:
126
+ object_dtype = np.dtypes.ObjectDType()
127
+ has_one_object_type = False
128
+ ret = []
129
+ for a in arrays:
130
+ if a.dtype != object_dtype:
131
+ tmp = np.empty(len(a), dtype=object_dtype)
132
+ tmp[:] = a[:]
133
+ ret.append(tmp)
134
+ else:
135
+ has_one_object_type = True
136
+ ret.append(a.copy())
137
+ if not has_one_object_type:
138
+ raise ValueError("Coefficient arrays have no common type") from e
139
+ else:
140
+ ret = [np.array(a, copy=True, dtype=dtype) for a in arrays]
141
+ return ret
142
+
143
+
144
+ def trimcoef(c, tol=0):
145
+ """
146
+ Remove "small" "trailing" coefficients from a polynomial.
147
+
148
+ "Small" means "small in absolute value" and is controlled by the
149
+ parameter `tol`; "trailing" means highest order coefficient(s), e.g., in
150
+ ``[0, 1, 1, 0, 0]`` (which represents ``0 + x + x**2 + 0*x**3 + 0*x**4``)
151
+ both the 3-rd and 4-th order coefficients would be "trimmed."
152
+
153
+ Parameters
154
+ ----------
155
+ c : array_like
156
+ 1-d array of coefficients, ordered from lowest order to highest.
157
+ tol : number, optional
158
+ Trailing (i.e., highest order) elements with absolute value less
159
+ than or equal to `tol` (default value is zero) are removed.
160
+
161
+ Returns
162
+ -------
163
+ trimmed : ndarray
164
+ 1-d array with trailing zeros removed. If the resulting series
165
+ would be empty, a series containing a single zero is returned.
166
+
167
+ Raises
168
+ ------
169
+ ValueError
170
+ If `tol` < 0
171
+
172
+ Examples
173
+ --------
174
+ >>> from numpy.polynomial import polyutils as pu
175
+ >>> pu.trimcoef((0,0,3,0,5,0,0))
176
+ array([0., 0., 3., 0., 5.])
177
+ >>> pu.trimcoef((0,0,1e-3,0,1e-5,0,0),1e-3) # item == tol is trimmed
178
+ array([0.])
179
+ >>> i = complex(0,1) # works for complex
180
+ >>> pu.trimcoef((3e-4,1e-3*(1-i),5e-4,2e-5*(1+i)), 1e-3)
181
+ array([0.0003+0.j , 0.001 -0.001j])
182
+
183
+ """
184
+ if tol < 0:
185
+ raise ValueError("tol must be non-negative")
186
+
187
+ [c] = as_series([c])
188
+ [ind] = np.nonzero(np.abs(c) > tol)
189
+ if len(ind) == 0:
190
+ return c[:1] * 0
191
+ else:
192
+ return c[:ind[-1] + 1].copy()
193
+
194
+ def getdomain(x):
195
+ """
196
+ Return a domain suitable for given abscissae.
197
+
198
+ Find a domain suitable for a polynomial or Chebyshev series
199
+ defined at the values supplied.
200
+
201
+ Parameters
202
+ ----------
203
+ x : array_like
204
+ 1-d array of abscissae whose domain will be determined.
205
+
206
+ Returns
207
+ -------
208
+ domain : ndarray
209
+ 1-d array containing two values. If the inputs are complex, then
210
+ the two returned points are the lower left and upper right corners
211
+ of the smallest rectangle (aligned with the axes) in the complex
212
+ plane containing the points `x`. If the inputs are real, then the
213
+ two points are the ends of the smallest interval containing the
214
+ points `x`.
215
+
216
+ See Also
217
+ --------
218
+ mapparms, mapdomain
219
+
220
+ Examples
221
+ --------
222
+ >>> import numpy as np
223
+ >>> from numpy.polynomial import polyutils as pu
224
+ >>> points = np.arange(4)**2 - 5; points
225
+ array([-5, -4, -1, 4])
226
+ >>> pu.getdomain(points)
227
+ array([-5., 4.])
228
+ >>> c = np.exp(complex(0,1)*np.pi*np.arange(12)/6) # unit circle
229
+ >>> pu.getdomain(c)
230
+ array([-1.-1.j, 1.+1.j])
231
+
232
+ """
233
+ [x] = as_series([x], trim=False)
234
+ if x.dtype.char in np.typecodes['Complex']:
235
+ rmin, rmax = x.real.min(), x.real.max()
236
+ imin, imax = x.imag.min(), x.imag.max()
237
+ return np.array((complex(rmin, imin), complex(rmax, imax)))
238
+ else:
239
+ return np.array((x.min(), x.max()))
240
+
241
+ def mapparms(old, new):
242
+ """
243
+ Linear map parameters between domains.
244
+
245
+ Return the parameters of the linear map ``offset + scale*x`` that maps
246
+ `old` to `new` such that ``old[i] -> new[i]``, ``i = 0, 1``.
247
+
248
+ Parameters
249
+ ----------
250
+ old, new : array_like
251
+ Domains. Each domain must (successfully) convert to a 1-d array
252
+ containing precisely two values.
253
+
254
+ Returns
255
+ -------
256
+ offset, scale : scalars
257
+ The map ``L(x) = offset + scale*x`` maps the first domain to the
258
+ second.
259
+
260
+ See Also
261
+ --------
262
+ getdomain, mapdomain
263
+
264
+ Notes
265
+ -----
266
+ Also works for complex numbers, and thus can be used to calculate the
267
+ parameters required to map any line in the complex plane to any other
268
+ line therein.
269
+
270
+ Examples
271
+ --------
272
+ >>> from numpy.polynomial import polyutils as pu
273
+ >>> pu.mapparms((-1,1),(-1,1))
274
+ (0.0, 1.0)
275
+ >>> pu.mapparms((1,-1),(-1,1))
276
+ (-0.0, -1.0)
277
+ >>> i = complex(0,1)
278
+ >>> pu.mapparms((-i,-1),(1,i))
279
+ ((1+1j), (1-0j))
280
+
281
+ """
282
+ oldlen = old[1] - old[0]
283
+ newlen = new[1] - new[0]
284
+ off = (old[1] * new[0] - old[0] * new[1]) / oldlen
285
+ scl = newlen / oldlen
286
+ return off, scl
287
+
288
+ def mapdomain(x, old, new):
289
+ """
290
+ Apply linear map to input points.
291
+
292
+ The linear map ``offset + scale*x`` that maps the domain `old` to
293
+ the domain `new` is applied to the points `x`.
294
+
295
+ Parameters
296
+ ----------
297
+ x : array_like
298
+ Points to be mapped. If `x` is a subtype of ndarray the subtype
299
+ will be preserved.
300
+ old, new : array_like
301
+ The two domains that determine the map. Each must (successfully)
302
+ convert to 1-d arrays containing precisely two values.
303
+
304
+ Returns
305
+ -------
306
+ x_out : ndarray
307
+ Array of points of the same shape as `x`, after application of the
308
+ linear map between the two domains.
309
+
310
+ See Also
311
+ --------
312
+ getdomain, mapparms
313
+
314
+ Notes
315
+ -----
316
+ Effectively, this implements:
317
+
318
+ .. math::
319
+ x\\_out = new[0] + m(x - old[0])
320
+
321
+ where
322
+
323
+ .. math::
324
+ m = \\frac{new[1]-new[0]}{old[1]-old[0]}
325
+
326
+ Examples
327
+ --------
328
+ >>> import numpy as np
329
+ >>> from numpy.polynomial import polyutils as pu
330
+ >>> old_domain = (-1,1)
331
+ >>> new_domain = (0,2*np.pi)
332
+ >>> x = np.linspace(-1,1,6); x
333
+ array([-1. , -0.6, -0.2, 0.2, 0.6, 1. ])
334
+ >>> x_out = pu.mapdomain(x, old_domain, new_domain); x_out
335
+ array([ 0. , 1.25663706, 2.51327412, 3.76991118, 5.02654825, # may vary
336
+ 6.28318531])
337
+ >>> x - pu.mapdomain(x_out, new_domain, old_domain)
338
+ array([0., 0., 0., 0., 0., 0.])
339
+
340
+ Also works for complex numbers (and thus can be used to map any line in
341
+ the complex plane to any other line therein).
342
+
343
+ >>> i = complex(0,1)
344
+ >>> old = (-1 - i, 1 + i)
345
+ >>> new = (-1 + i, 1 - i)
346
+ >>> z = np.linspace(old[0], old[1], 6); z
347
+ array([-1. -1.j , -0.6-0.6j, -0.2-0.2j, 0.2+0.2j, 0.6+0.6j, 1. +1.j ])
348
+ >>> new_z = pu.mapdomain(z, old, new); new_z
349
+ array([-1.0+1.j , -0.6+0.6j, -0.2+0.2j, 0.2-0.2j, 0.6-0.6j, 1.0-1.j ]) # may vary
350
+
351
+ """
352
+ if type(x) not in (int, float, complex) and not isinstance(x, np.generic):
353
+ x = np.asanyarray(x)
354
+ off, scl = mapparms(old, new)
355
+ return off + scl * x
356
+
357
+
358
+ def _nth_slice(i, ndim):
359
+ sl = [np.newaxis] * ndim
360
+ sl[i] = slice(None)
361
+ return tuple(sl)
362
+
363
+
364
+ def _vander_nd(vander_fs, points, degrees):
365
+ r"""
366
+ A generalization of the Vandermonde matrix for N dimensions
367
+
368
+ The result is built by combining the results of 1d Vandermonde matrices,
369
+
370
+ .. math::
371
+ W[i_0, \ldots, i_M, j_0, \ldots, j_N] = \prod_{k=0}^N{V_k(x_k)[i_0, \ldots, i_M, j_k]}
372
+
373
+ where
374
+
375
+ .. math::
376
+ N &= \texttt{len(points)} = \texttt{len(degrees)} = \texttt{len(vander\_fs)} \\
377
+ M &= \texttt{points[k].ndim} \\
378
+ V_k &= \texttt{vander\_fs[k]} \\
379
+ x_k &= \texttt{points[k]} \\
380
+ 0 \le j_k &\le \texttt{degrees[k]}
381
+
382
+ Expanding the one-dimensional :math:`V_k` functions gives:
383
+
384
+ .. math::
385
+ W[i_0, \ldots, i_M, j_0, \ldots, j_N] = \prod_{k=0}^N{B_{k, j_k}(x_k[i_0, \ldots, i_M])}
386
+
387
+ where :math:`B_{k,m}` is the m'th basis of the polynomial construction used along
388
+ dimension :math:`k`. For a regular polynomial, :math:`B_{k, m}(x) = P_m(x) = x^m`.
389
+
390
+ Parameters
391
+ ----------
392
+ vander_fs : Sequence[function(array_like, int) -> ndarray]
393
+ The 1d vander function to use for each axis, such as ``polyvander``
394
+ points : Sequence[array_like]
395
+ Arrays of point coordinates, all of the same shape. The dtypes
396
+ will be converted to either float64 or complex128 depending on
397
+ whether any of the elements are complex. Scalars are converted to
398
+ 1-D arrays.
399
+ This must be the same length as `vander_fs`.
400
+ degrees : Sequence[int]
401
+ The maximum degree (inclusive) to use for each axis.
402
+ This must be the same length as `vander_fs`.
403
+
404
+ Returns
405
+ -------
406
+ vander_nd : ndarray
407
+ An array of shape ``points[0].shape + tuple(d + 1 for d in degrees)``.
408
+ """ # noqa: E501
409
+ n_dims = len(vander_fs)
410
+ if n_dims != len(points):
411
+ raise ValueError(
412
+ f"Expected {n_dims} dimensions of sample points, got {len(points)}")
413
+ if n_dims != len(degrees):
414
+ raise ValueError(
415
+ f"Expected {n_dims} dimensions of degrees, got {len(degrees)}")
416
+ if n_dims == 0:
417
+ raise ValueError("Unable to guess a dtype or shape when no points are given")
418
+
419
+ # convert to the same shape and type
420
+ points = tuple(np.asarray(tuple(points)) + 0.0)
421
+
422
+ # produce the vandermonde matrix for each dimension, placing the last
423
+ # axis of each in an independent trailing axis of the output
424
+ vander_arrays = (
425
+ vander_fs[i](points[i], degrees[i])[(...,) + _nth_slice(i, n_dims)]
426
+ for i in range(n_dims)
427
+ )
428
+
429
+ # we checked this wasn't empty already, so no `initial` needed
430
+ return functools.reduce(operator.mul, vander_arrays)
431
+
432
+
433
+ def _vander_nd_flat(vander_fs, points, degrees):
434
+ """
435
+ Like `_vander_nd`, but flattens the last ``len(degrees)`` axes into a single axis
436
+
437
+ Used to implement the public ``<type>vander<n>d`` functions.
438
+ """
439
+ v = _vander_nd(vander_fs, points, degrees)
440
+ return v.reshape(v.shape[:-len(degrees)] + (-1,))
441
+
442
+
443
+ def _fromroots(line_f, mul_f, roots):
444
+ """
445
+ Helper function used to implement the ``<type>fromroots`` functions.
446
+
447
+ Parameters
448
+ ----------
449
+ line_f : function(float, float) -> ndarray
450
+ The ``<type>line`` function, such as ``polyline``
451
+ mul_f : function(array_like, array_like) -> ndarray
452
+ The ``<type>mul`` function, such as ``polymul``
453
+ roots
454
+ See the ``<type>fromroots`` functions for more detail
455
+ """
456
+ if len(roots) == 0:
457
+ return np.ones(1)
458
+ else:
459
+ [roots] = as_series([roots], trim=False)
460
+ roots.sort()
461
+ p = [line_f(-r, 1) for r in roots]
462
+ n = len(p)
463
+ while n > 1:
464
+ m, r = divmod(n, 2)
465
+ tmp = [mul_f(p[i], p[i + m]) for i in range(m)]
466
+ if r:
467
+ tmp[0] = mul_f(tmp[0], p[-1])
468
+ p = tmp
469
+ n = m
470
+ return p[0]
471
+
472
+
473
+ def _valnd(val_f, c, *args):
474
+ """
475
+ Helper function used to implement the ``<type>val<n>d`` functions.
476
+
477
+ Parameters
478
+ ----------
479
+ val_f : function(array_like, array_like, tensor: bool) -> array_like
480
+ The ``<type>val`` function, such as ``polyval``
481
+ c, args
482
+ See the ``<type>val<n>d`` functions for more detail
483
+ """
484
+ args = [np.asanyarray(a) for a in args]
485
+ shape0 = args[0].shape
486
+ if not all(a.shape == shape0 for a in args[1:]):
487
+ if len(args) == 3:
488
+ raise ValueError('x, y, z are incompatible')
489
+ elif len(args) == 2:
490
+ raise ValueError('x, y are incompatible')
491
+ else:
492
+ raise ValueError('ordinates are incompatible')
493
+ it = iter(args)
494
+ x0 = next(it)
495
+
496
+ # use tensor on only the first
497
+ c = val_f(x0, c)
498
+ for xi in it:
499
+ c = val_f(xi, c, tensor=False)
500
+ return c
501
+
502
+
503
+ def _gridnd(val_f, c, *args):
504
+ """
505
+ Helper function used to implement the ``<type>grid<n>d`` functions.
506
+
507
+ Parameters
508
+ ----------
509
+ val_f : function(array_like, array_like, tensor: bool) -> array_like
510
+ The ``<type>val`` function, such as ``polyval``
511
+ c, args
512
+ See the ``<type>grid<n>d`` functions for more detail
513
+ """
514
+ for xi in args:
515
+ c = val_f(xi, c)
516
+ return c
517
+
518
+
519
+ def _div(mul_f, c1, c2):
520
+ """
521
+ Helper function used to implement the ``<type>div`` functions.
522
+
523
+ Implementation uses repeated subtraction of c2 multiplied by the nth basis.
524
+ For some polynomial types, a more efficient approach may be possible.
525
+
526
+ Parameters
527
+ ----------
528
+ mul_f : function(array_like, array_like) -> array_like
529
+ The ``<type>mul`` function, such as ``polymul``
530
+ c1, c2
531
+ See the ``<type>div`` functions for more detail
532
+ """
533
+ # c1, c2 are trimmed copies
534
+ [c1, c2] = as_series([c1, c2])
535
+ if c2[-1] == 0:
536
+ raise ZeroDivisionError # FIXME: add message with details to exception
537
+
538
+ lc1 = len(c1)
539
+ lc2 = len(c2)
540
+ if lc1 < lc2:
541
+ return c1[:1] * 0, c1
542
+ elif lc2 == 1:
543
+ return c1 / c2[-1], c1[:1] * 0
544
+ else:
545
+ quo = np.empty(lc1 - lc2 + 1, dtype=c1.dtype)
546
+ rem = c1
547
+ for i in range(lc1 - lc2, - 1, -1):
548
+ p = mul_f([0] * i + [1], c2)
549
+ q = rem[-1] / p[-1]
550
+ rem = rem[:-1] - q * p[:-1]
551
+ quo[i] = q
552
+ return quo, trimseq(rem)
553
+
554
+
555
+ def _add(c1, c2):
556
+ """ Helper function used to implement the ``<type>add`` functions. """
557
+ # c1, c2 are trimmed copies
558
+ [c1, c2] = as_series([c1, c2])
559
+ if len(c1) > len(c2):
560
+ c1[:c2.size] += c2
561
+ ret = c1
562
+ else:
563
+ c2[:c1.size] += c1
564
+ ret = c2
565
+ return trimseq(ret)
566
+
567
+
568
+ def _sub(c1, c2):
569
+ """ Helper function used to implement the ``<type>sub`` functions. """
570
+ # c1, c2 are trimmed copies
571
+ [c1, c2] = as_series([c1, c2])
572
+ if len(c1) > len(c2):
573
+ c1[:c2.size] -= c2
574
+ ret = c1
575
+ else:
576
+ c2 = -c2
577
+ c2[:c1.size] += c1
578
+ ret = c2
579
+ return trimseq(ret)
580
+
581
+
582
+ def _fit(vander_f, x, y, deg, rcond=None, full=False, w=None):
583
+ """
584
+ Helper function used to implement the ``<type>fit`` functions.
585
+
586
+ Parameters
587
+ ----------
588
+ vander_f : function(array_like, int) -> ndarray
589
+ The 1d vander function, such as ``polyvander``
590
+ c1, c2
591
+ See the ``<type>fit`` functions for more detail
592
+ """
593
+ x = np.asarray(x) + 0.0
594
+ y = np.asarray(y) + 0.0
595
+ deg = np.asarray(deg)
596
+
597
+ # check arguments.
598
+ if deg.ndim > 1 or deg.dtype.kind not in 'iu' or deg.size == 0:
599
+ raise TypeError("deg must be an int or non-empty 1-D array of int")
600
+ if deg.min() < 0:
601
+ raise ValueError("expected deg >= 0")
602
+ if x.ndim != 1:
603
+ raise TypeError("expected 1D vector for x")
604
+ if x.size == 0:
605
+ raise TypeError("expected non-empty vector for x")
606
+ if y.ndim < 1 or y.ndim > 2:
607
+ raise TypeError("expected 1D or 2D array for y")
608
+ if len(x) != len(y):
609
+ raise TypeError("expected x and y to have same length")
610
+
611
+ if deg.ndim == 0:
612
+ lmax = deg
613
+ order = lmax + 1
614
+ van = vander_f(x, lmax)
615
+ else:
616
+ deg = np.sort(deg)
617
+ lmax = deg[-1]
618
+ order = len(deg)
619
+ van = vander_f(x, lmax)[:, deg]
620
+
621
+ # set up the least squares matrices in transposed form
622
+ lhs = van.T
623
+ rhs = y.T
624
+ if w is not None:
625
+ w = np.asarray(w) + 0.0
626
+ if w.ndim != 1:
627
+ raise TypeError("expected 1D vector for w")
628
+ if len(x) != len(w):
629
+ raise TypeError("expected x and w to have same length")
630
+ # apply weights. Don't use inplace operations as they
631
+ # can cause problems with NA.
632
+ lhs = lhs * w
633
+ rhs = rhs * w
634
+
635
+ # set rcond
636
+ if rcond is None:
637
+ rcond = len(x) * np.finfo(x.dtype).eps
638
+
639
+ # Determine the norms of the design matrix columns.
640
+ if issubclass(lhs.dtype.type, np.complexfloating):
641
+ scl = np.sqrt((np.square(lhs.real) + np.square(lhs.imag)).sum(1))
642
+ else:
643
+ scl = np.sqrt(np.square(lhs).sum(1))
644
+ scl[scl == 0] = 1
645
+
646
+ # Solve the least squares problem.
647
+ c, resids, rank, s = np.linalg.lstsq(lhs.T / scl, rhs.T, rcond)
648
+ c = (c.T / scl).T
649
+
650
+ # Expand c to include non-fitted coefficients which are set to zero
651
+ if deg.ndim > 0:
652
+ if c.ndim == 2:
653
+ cc = np.zeros((lmax + 1, c.shape[1]), dtype=c.dtype)
654
+ else:
655
+ cc = np.zeros(lmax + 1, dtype=c.dtype)
656
+ cc[deg] = c
657
+ c = cc
658
+
659
+ # warn on rank reduction
660
+ if rank != order and not full:
661
+ msg = "The fit may be poorly conditioned"
662
+ warnings.warn(msg, np.exceptions.RankWarning, stacklevel=2)
663
+
664
+ if full:
665
+ return c, [resids, rank, s, rcond]
666
+ else:
667
+ return c
668
+
669
+
670
+ def _pow(mul_f, c, pow, maxpower):
671
+ """
672
+ Helper function used to implement the ``<type>pow`` functions.
673
+
674
+ Parameters
675
+ ----------
676
+ mul_f : function(array_like, array_like) -> ndarray
677
+ The ``<type>mul`` function, such as ``polymul``
678
+ c : array_like
679
+ 1-D array of array of series coefficients
680
+ pow, maxpower
681
+ See the ``<type>pow`` functions for more detail
682
+ """
683
+ # c is a trimmed copy
684
+ [c] = as_series([c])
685
+ power = int(pow)
686
+ if power != pow or power < 0:
687
+ raise ValueError("Power must be a non-negative integer.")
688
+ elif maxpower is not None and power > maxpower:
689
+ raise ValueError("Power is too large")
690
+ elif power == 0:
691
+ return np.array([1], dtype=c.dtype)
692
+ elif power == 1:
693
+ return c
694
+ else:
695
+ # This can be made more efficient by using powers of two
696
+ # in the usual way.
697
+ prd = c
698
+ for i in range(2, power + 1):
699
+ prd = mul_f(prd, c)
700
+ return prd
701
+
702
+
703
+ def _as_int(x, desc):
704
+ """
705
+ Like `operator.index`, but emits a custom exception when passed an
706
+ incorrect type
707
+
708
+ Parameters
709
+ ----------
710
+ x : int-like
711
+ Value to interpret as an integer
712
+ desc : str
713
+ description to include in any error message
714
+
715
+ Raises
716
+ ------
717
+ TypeError : if x is a float or non-numeric
718
+ """
719
+ try:
720
+ return operator.index(x)
721
+ except TypeError as e:
722
+ raise TypeError(f"{desc} must be an integer, received {x}") from e
723
+
724
+
725
+ def format_float(x, parens=False):
726
+ from numpy._core.multiarray import dragon4_positional, dragon4_scientific
727
+
728
+ if not np.issubdtype(type(x), np.floating):
729
+ return str(x)
730
+
731
+ opts = np.get_printoptions()
732
+
733
+ if np.isnan(x):
734
+ return opts['nanstr']
735
+ elif np.isinf(x):
736
+ return opts['infstr']
737
+
738
+ exp_format = False
739
+ if x != 0:
740
+ a = np.abs(x)
741
+ if a >= 1.e8 or a < 10**min(0, -(opts['precision'] - 1) // 2):
742
+ exp_format = True
743
+
744
+ trim, unique = '0', True
745
+ if opts['floatmode'] == 'fixed':
746
+ trim, unique = 'k', False
747
+
748
+ if exp_format:
749
+ s = dragon4_scientific(x, precision=opts['precision'],
750
+ unique=unique, trim=trim,
751
+ sign=opts['sign'] == '+')
752
+ if parens:
753
+ s = '(' + s + ')'
754
+ else:
755
+ s = dragon4_positional(x, precision=opts['precision'],
756
+ fractional=True,
757
+ unique=unique, trim=trim,
758
+ sign=opts['sign'] == '+')
759
+ return s
physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy/polynomial/polyutils.pyi ADDED
@@ -0,0 +1,307 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from collections.abc import Callable, Iterable, Sequence
2
+ from typing import (
3
+ Final,
4
+ Literal,
5
+ Protocol,
6
+ SupportsIndex,
7
+ TypeAlias,
8
+ TypeVar,
9
+ overload,
10
+ type_check_only,
11
+ )
12
+
13
+ import numpy as np
14
+ import numpy.typing as npt
15
+ from numpy._typing import (
16
+ _ArrayLikeComplex_co,
17
+ _ArrayLikeFloat_co,
18
+ _ArrayLikeObject_co,
19
+ _FloatLike_co,
20
+ _NumberLike_co,
21
+ )
22
+
23
+ from ._polytypes import (
24
+ _AnyInt,
25
+ _Array2,
26
+ _ArrayLikeCoef_co,
27
+ _CoefArray,
28
+ _CoefLike_co,
29
+ _CoefSeries,
30
+ _ComplexArray,
31
+ _ComplexSeries,
32
+ _FloatArray,
33
+ _FloatSeries,
34
+ _FuncBinOp,
35
+ _ObjectArray,
36
+ _ObjectSeries,
37
+ _SeriesLikeCoef_co,
38
+ _SeriesLikeComplex_co,
39
+ _SeriesLikeFloat_co,
40
+ _SeriesLikeInt_co,
41
+ _SeriesLikeObject_co,
42
+ _Tuple2,
43
+ )
44
+
45
+ __all__ = ["as_series", "format_float", "getdomain", "mapdomain", "mapparms", "trimcoef", "trimseq"]
46
+
47
+ _T = TypeVar("_T")
48
+ _SeqT = TypeVar("_SeqT", bound=_CoefArray | Sequence[_CoefLike_co])
49
+
50
+ _AnyLineF: TypeAlias = Callable[[float, float], _CoefArray]
51
+ _AnyMulF: TypeAlias = Callable[[np.ndarray | list[int], np.ndarray], _CoefArray]
52
+ _AnyVanderF: TypeAlias = Callable[[np.ndarray, int], _CoefArray]
53
+
54
+ @type_check_only
55
+ class _ValFunc(Protocol[_T]):
56
+ def __call__(self, x: np.ndarray, c: _T, /, *, tensor: bool = True) -> _T: ...
57
+
58
+ ###
59
+
60
+ @overload
61
+ def as_series(alist: npt.NDArray[np.integer] | _FloatArray, trim: bool = True) -> list[_FloatSeries]: ...
62
+ @overload
63
+ def as_series(alist: _ComplexArray, trim: bool = True) -> list[_ComplexSeries]: ...
64
+ @overload
65
+ def as_series(alist: _ObjectArray, trim: bool = True) -> list[_ObjectSeries]: ...
66
+ @overload
67
+ def as_series(alist: Iterable[_FloatArray | npt.NDArray[np.integer]], trim: bool = True) -> list[_FloatSeries]: ...
68
+ @overload
69
+ def as_series(alist: Iterable[_ComplexArray], trim: bool = True) -> list[_ComplexSeries]: ...
70
+ @overload
71
+ def as_series(alist: Iterable[_ObjectArray], trim: bool = True) -> list[_ObjectSeries]: ...
72
+ @overload
73
+ def as_series(alist: Iterable[_SeriesLikeFloat_co | float], trim: bool = True) -> list[_FloatSeries]: ...
74
+ @overload
75
+ def as_series(alist: Iterable[_SeriesLikeComplex_co | complex], trim: bool = True) -> list[_ComplexSeries]: ...
76
+ @overload
77
+ def as_series(alist: Iterable[_SeriesLikeCoef_co | object], trim: bool = True) -> list[_ObjectSeries]: ...
78
+
79
+ #
80
+ def trimseq(seq: _SeqT) -> _SeqT: ...
81
+
82
+ #
83
+ @overload
84
+ def trimcoef(c: npt.NDArray[np.integer] | _FloatArray, tol: _FloatLike_co = 0) -> _FloatSeries: ...
85
+ @overload
86
+ def trimcoef(c: _ComplexArray, tol: _FloatLike_co = 0) -> _ComplexSeries: ...
87
+ @overload
88
+ def trimcoef(c: _ObjectArray, tol: _FloatLike_co = 0) -> _ObjectSeries: ...
89
+ @overload
90
+ def trimcoef(c: _SeriesLikeFloat_co | float, tol: _FloatLike_co = 0) -> _FloatSeries: ...
91
+ @overload
92
+ def trimcoef(c: _SeriesLikeComplex_co | complex, tol: _FloatLike_co = 0) -> _ComplexSeries: ...
93
+ @overload
94
+ def trimcoef(c: _SeriesLikeCoef_co | object, tol: _FloatLike_co = 0) -> _ObjectSeries: ...
95
+
96
+ #
97
+ @overload
98
+ def getdomain(x: _FloatArray | npt.NDArray[np.integer]) -> _Array2[np.float64]: ...
99
+ @overload
100
+ def getdomain(x: _ComplexArray) -> _Array2[np.complex128]: ...
101
+ @overload
102
+ def getdomain(x: _ObjectArray) -> _Array2[np.object_]: ...
103
+ @overload
104
+ def getdomain(x: _SeriesLikeFloat_co | float) -> _Array2[np.float64]: ...
105
+ @overload
106
+ def getdomain(x: _SeriesLikeComplex_co | complex) -> _Array2[np.complex128]: ...
107
+ @overload
108
+ def getdomain(x: _SeriesLikeCoef_co | object) -> _Array2[np.object_]: ...
109
+
110
+ #
111
+ @overload
112
+ def mapparms(old: npt.NDArray[np.floating | np.integer], new: npt.NDArray[np.floating | np.integer]) -> _Tuple2[np.floating]: ...
113
+ @overload
114
+ def mapparms(old: npt.NDArray[np.number], new: npt.NDArray[np.number]) -> _Tuple2[np.complexfloating]: ...
115
+ @overload
116
+ def mapparms(old: npt.NDArray[np.object_ | np.number], new: npt.NDArray[np.object_ | np.number]) -> _Tuple2[object]: ...
117
+ @overload
118
+ def mapparms(old: Sequence[float], new: Sequence[float]) -> _Tuple2[float]: ...
119
+ @overload
120
+ def mapparms(old: Sequence[complex], new: Sequence[complex]) -> _Tuple2[complex]: ...
121
+ @overload
122
+ def mapparms(old: _SeriesLikeFloat_co, new: _SeriesLikeFloat_co) -> _Tuple2[np.floating]: ...
123
+ @overload
124
+ def mapparms(old: _SeriesLikeComplex_co, new: _SeriesLikeComplex_co) -> _Tuple2[np.complexfloating]: ...
125
+ @overload
126
+ def mapparms(old: _SeriesLikeCoef_co, new: _SeriesLikeCoef_co) -> _Tuple2[object]: ...
127
+
128
+ #
129
+ @overload
130
+ def mapdomain(x: _FloatLike_co, old: _SeriesLikeFloat_co, new: _SeriesLikeFloat_co) -> np.floating: ...
131
+ @overload
132
+ def mapdomain(x: _NumberLike_co, old: _SeriesLikeComplex_co, new: _SeriesLikeComplex_co) -> np.complexfloating: ...
133
+ @overload
134
+ def mapdomain(
135
+ x: npt.NDArray[np.floating | np.integer],
136
+ old: npt.NDArray[np.floating | np.integer],
137
+ new: npt.NDArray[np.floating | np.integer],
138
+ ) -> _FloatSeries: ...
139
+ @overload
140
+ def mapdomain(x: npt.NDArray[np.number], old: npt.NDArray[np.number], new: npt.NDArray[np.number]) -> _ComplexSeries: ...
141
+ @overload
142
+ def mapdomain(
143
+ x: npt.NDArray[np.object_ | np.number],
144
+ old: npt.NDArray[np.object_ | np.number],
145
+ new: npt.NDArray[np.object_ | np.number],
146
+ ) -> _ObjectSeries: ...
147
+ @overload
148
+ def mapdomain(x: _SeriesLikeFloat_co, old: _SeriesLikeFloat_co, new: _SeriesLikeFloat_co) -> _FloatSeries: ...
149
+ @overload
150
+ def mapdomain(x: _SeriesLikeComplex_co, old: _SeriesLikeComplex_co, new: _SeriesLikeComplex_co) -> _ComplexSeries: ...
151
+ @overload
152
+ def mapdomain(x: _SeriesLikeCoef_co, old: _SeriesLikeCoef_co, new: _SeriesLikeCoef_co) -> _ObjectSeries: ...
153
+ @overload
154
+ def mapdomain(x: _CoefLike_co, old: _SeriesLikeCoef_co, new: _SeriesLikeCoef_co) -> object: ...
155
+
156
+ #
157
+ def _nth_slice(i: SupportsIndex, ndim: SupportsIndex) -> tuple[slice | None, ...]: ...
158
+
159
+ # keep in sync with `vander_nd_flat`
160
+ @overload
161
+ def _vander_nd(
162
+ vander_fs: Sequence[_AnyVanderF],
163
+ points: Sequence[_ArrayLikeFloat_co],
164
+ degrees: Sequence[SupportsIndex],
165
+ ) -> _FloatArray: ...
166
+ @overload
167
+ def _vander_nd(
168
+ vander_fs: Sequence[_AnyVanderF],
169
+ points: Sequence[_ArrayLikeComplex_co],
170
+ degrees: Sequence[SupportsIndex],
171
+ ) -> _ComplexArray: ...
172
+ @overload
173
+ def _vander_nd(
174
+ vander_fs: Sequence[_AnyVanderF],
175
+ points: Sequence[_ArrayLikeObject_co | _ArrayLikeComplex_co],
176
+ degrees: Sequence[SupportsIndex],
177
+ ) -> _ObjectArray: ...
178
+ @overload
179
+ def _vander_nd(
180
+ vander_fs: Sequence[_AnyVanderF],
181
+ points: Sequence[npt.ArrayLike],
182
+ degrees: Sequence[SupportsIndex],
183
+ ) -> _CoefArray: ...
184
+
185
+ # keep in sync with `vander_nd`
186
+ @overload
187
+ def _vander_nd_flat(
188
+ vander_fs: Sequence[_AnyVanderF],
189
+ points: Sequence[_ArrayLikeFloat_co],
190
+ degrees: Sequence[SupportsIndex],
191
+ ) -> _FloatArray: ...
192
+ @overload
193
+ def _vander_nd_flat(
194
+ vander_fs: Sequence[_AnyVanderF],
195
+ points: Sequence[_ArrayLikeComplex_co],
196
+ degrees: Sequence[SupportsIndex],
197
+ ) -> _ComplexArray: ...
198
+ @overload
199
+ def _vander_nd_flat(
200
+ vander_fs: Sequence[_AnyVanderF],
201
+ points: Sequence[_ArrayLikeObject_co | _ArrayLikeComplex_co],
202
+ degrees: Sequence[SupportsIndex],
203
+ ) -> _ObjectArray: ...
204
+ @overload
205
+ def _vander_nd_flat(
206
+ vander_fs: Sequence[_AnyVanderF],
207
+ points: Sequence[npt.ArrayLike],
208
+ degrees: Sequence[SupportsIndex],
209
+ ) -> _CoefArray: ...
210
+
211
+ # keep in sync with `._polytypes._FuncFromRoots`
212
+ @overload
213
+ def _fromroots(line_f: _AnyLineF, mul_f: _AnyMulF, roots: _SeriesLikeFloat_co) -> _FloatSeries: ...
214
+ @overload
215
+ def _fromroots(line_f: _AnyLineF, mul_f: _AnyMulF, roots: _SeriesLikeComplex_co) -> _ComplexSeries: ...
216
+ @overload
217
+ def _fromroots(line_f: _AnyLineF, mul_f: _AnyMulF, roots: _SeriesLikeObject_co) -> _ObjectSeries: ...
218
+ @overload
219
+ def _fromroots(line_f: _AnyLineF, mul_f: _AnyMulF, roots: _SeriesLikeCoef_co) -> _CoefSeries: ...
220
+
221
+ # keep in sync with `_gridnd`
222
+ def _valnd(val_f: _ValFunc[_T], c: _T, *args: npt.ArrayLike) -> _T: ...
223
+
224
+ # keep in sync with `_valnd`
225
+ def _gridnd(val_f: _ValFunc[_T], c: _T, *args: npt.ArrayLike) -> _T: ...
226
+
227
+ # keep in sync with `_polytypes._FuncBinOp`
228
+ @overload
229
+ def _div(mul_f: _AnyMulF, c1: _SeriesLikeFloat_co, c2: _SeriesLikeFloat_co) -> _Tuple2[_FloatSeries]: ...
230
+ @overload
231
+ def _div(mul_f: _AnyMulF, c1: _SeriesLikeComplex_co, c2: _SeriesLikeComplex_co) -> _Tuple2[_ComplexSeries]: ...
232
+ @overload
233
+ def _div(mul_f: _AnyMulF, c1: _SeriesLikeObject_co, c2: _SeriesLikeObject_co) -> _Tuple2[_ObjectSeries]: ...
234
+ @overload
235
+ def _div(mul_f: _AnyMulF, c1: _SeriesLikeCoef_co, c2: _SeriesLikeCoef_co) -> _Tuple2[_CoefSeries]: ...
236
+
237
+ _add: Final[_FuncBinOp] = ...
238
+ _sub: Final[_FuncBinOp] = ...
239
+
240
+ # keep in sync with `_polytypes._FuncPow`
241
+ @overload
242
+ def _pow(mul_f: _AnyMulF, c: _SeriesLikeFloat_co, pow: _AnyInt, maxpower: _AnyInt | None) -> _FloatSeries: ...
243
+ @overload
244
+ def _pow(mul_f: _AnyMulF, c: _SeriesLikeComplex_co, pow: _AnyInt, maxpower: _AnyInt | None) -> _ComplexSeries: ...
245
+ @overload
246
+ def _pow(mul_f: _AnyMulF, c: _SeriesLikeObject_co, pow: _AnyInt, maxpower: _AnyInt | None) -> _ObjectSeries: ...
247
+ @overload
248
+ def _pow(mul_f: _AnyMulF, c: _SeriesLikeCoef_co, pow: _AnyInt, maxpower: _AnyInt | None) -> _CoefSeries: ...
249
+
250
+ # keep in sync with `_polytypes._FuncFit`
251
+ @overload
252
+ def _fit(
253
+ vander_f: _AnyVanderF,
254
+ x: _SeriesLikeFloat_co,
255
+ y: _ArrayLikeFloat_co,
256
+ deg: _SeriesLikeInt_co,
257
+ rcond: _FloatLike_co | None = None,
258
+ full: Literal[False] = False,
259
+ w: _SeriesLikeFloat_co | None = None,
260
+ ) -> _FloatArray: ...
261
+ @overload
262
+ def _fit(
263
+ vander_f: _AnyVanderF,
264
+ x: _SeriesLikeComplex_co,
265
+ y: _ArrayLikeComplex_co,
266
+ deg: _SeriesLikeInt_co,
267
+ rcond: _FloatLike_co | None = None,
268
+ full: Literal[False] = False,
269
+ w: _SeriesLikeComplex_co | None = None,
270
+ ) -> _ComplexArray: ...
271
+ @overload
272
+ def _fit(
273
+ vander_f: _AnyVanderF,
274
+ x: _SeriesLikeCoef_co,
275
+ y: _ArrayLikeCoef_co,
276
+ deg: _SeriesLikeInt_co,
277
+ rcond: _FloatLike_co | None = None,
278
+ full: Literal[False] = False,
279
+ w: _SeriesLikeCoef_co | None = None,
280
+ ) -> _CoefArray: ...
281
+ @overload
282
+ def _fit(
283
+ vander_f: _AnyVanderF,
284
+ x: _SeriesLikeCoef_co,
285
+ y: _SeriesLikeCoef_co,
286
+ deg: _SeriesLikeInt_co,
287
+ rcond: _FloatLike_co | None,
288
+ full: Literal[True],
289
+ w: _SeriesLikeCoef_co | None = None,
290
+ ) -> tuple[_CoefSeries, Sequence[np.inexact | np.int32]]: ...
291
+ @overload
292
+ def _fit(
293
+ vander_f: _AnyVanderF,
294
+ x: _SeriesLikeCoef_co,
295
+ y: _SeriesLikeCoef_co,
296
+ deg: _SeriesLikeInt_co,
297
+ rcond: _FloatLike_co | None = None,
298
+ *,
299
+ full: Literal[True],
300
+ w: _SeriesLikeCoef_co | None = None,
301
+ ) -> tuple[_CoefSeries, Sequence[np.inexact | np.int32]]: ...
302
+
303
+ #
304
+ def _as_int(x: SupportsIndex, desc: str) -> int: ...
305
+
306
+ #
307
+ def format_float(x: _FloatLike_co, parens: bool = False) -> str: ...
physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy/polynomial/tests/__init__.py ADDED
File without changes
physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy/polynomial/tests/__pycache__/__init__.cpython-311.pyc ADDED
Binary file (262 Bytes). View file
 
physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy/polynomial/tests/__pycache__/test_chebyshev.cpython-311.pyc ADDED
Binary file (43.2 kB). View file
 
physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy/polynomial/tests/__pycache__/test_classes.cpython-311.pyc ADDED
Binary file (39.1 kB). View file
 
physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy/polynomial/tests/__pycache__/test_hermite.cpython-311.pyc ADDED
Binary file (38.5 kB). View file
 
physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy/polynomial/tests/__pycache__/test_hermite_e.cpython-311.pyc ADDED
Binary file (38.7 kB). View file
 
physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy/polynomial/tests/__pycache__/test_laguerre.cpython-311.pyc ADDED
Binary file (37.1 kB). View file
 
physworld_p1_20261018/envs/p1/lib/python3.11/site-packages/numpy/polynomial/tests/__pycache__/test_legendre.cpython-311.pyc ADDED
Binary file (39.6 kB). View file