Instructions to use godlykmathews/BERT-Sentiment_Classifier with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use godlykmathews/BERT-Sentiment_Classifier with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="godlykmathews/BERT-Sentiment_Classifier")# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("godlykmathews/BERT-Sentiment_Classifier", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Upload folder using huggingface_hub (part 15)
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- .gitattributes +1 -0
- venv/lib/python3.14/site-packages/sympy-1.14.0.dist-info/INSTALLER +1 -0
- venv/lib/python3.14/site-packages/sympy-1.14.0.dist-info/METADATA +319 -0
- venv/lib/python3.14/site-packages/sympy-1.14.0.dist-info/RECORD +0 -0
- venv/lib/python3.14/site-packages/sympy-1.14.0.dist-info/WHEEL +5 -0
- venv/lib/python3.14/site-packages/sympy-1.14.0.dist-info/entry_points.txt +2 -0
- venv/lib/python3.14/site-packages/sympy-1.14.0.dist-info/licenses/AUTHORS +1379 -0
- venv/lib/python3.14/site-packages/sympy-1.14.0.dist-info/licenses/LICENSE +153 -0
- venv/lib/python3.14/site-packages/sympy-1.14.0.dist-info/top_level.txt +2 -0
- venv/lib/python3.14/site-packages/sympy/plotting/plot_implicit.py +233 -0
- venv/lib/python3.14/site-packages/sympy/plotting/plotgrid.py +188 -0
- venv/lib/python3.14/site-packages/sympy/plotting/pygletplot/__init__.py +138 -0
- venv/lib/python3.14/site-packages/sympy/plotting/pygletplot/color_scheme.py +336 -0
- venv/lib/python3.14/site-packages/sympy/plotting/pygletplot/managed_window.py +106 -0
- venv/lib/python3.14/site-packages/sympy/plotting/pygletplot/plot.py +464 -0
- venv/lib/python3.14/site-packages/sympy/plotting/pygletplot/plot_axes.py +251 -0
- venv/lib/python3.14/site-packages/sympy/plotting/pygletplot/plot_camera.py +124 -0
- venv/lib/python3.14/site-packages/sympy/plotting/pygletplot/plot_controller.py +218 -0
- venv/lib/python3.14/site-packages/sympy/plotting/pygletplot/plot_curve.py +82 -0
- venv/lib/python3.14/site-packages/sympy/plotting/pygletplot/plot_interval.py +181 -0
- venv/lib/python3.14/site-packages/sympy/plotting/pygletplot/plot_mode.py +400 -0
- venv/lib/python3.14/site-packages/sympy/plotting/pygletplot/plot_mode_base.py +378 -0
- venv/lib/python3.14/site-packages/sympy/plotting/pygletplot/plot_modes.py +209 -0
- venv/lib/python3.14/site-packages/sympy/plotting/pygletplot/plot_object.py +17 -0
- venv/lib/python3.14/site-packages/sympy/plotting/pygletplot/plot_rotation.py +68 -0
- venv/lib/python3.14/site-packages/sympy/plotting/pygletplot/plot_surface.py +102 -0
- venv/lib/python3.14/site-packages/sympy/plotting/pygletplot/plot_window.py +144 -0
- venv/lib/python3.14/site-packages/sympy/plotting/pygletplot/tests/__init__.py +0 -0
- venv/lib/python3.14/site-packages/sympy/plotting/pygletplot/tests/test_plotting.py +88 -0
- venv/lib/python3.14/site-packages/sympy/plotting/pygletplot/util.py +188 -0
- venv/lib/python3.14/site-packages/sympy/plotting/series.py +2591 -0
- venv/lib/python3.14/site-packages/sympy/plotting/tests/__init__.py +0 -0
- venv/lib/python3.14/site-packages/sympy/plotting/tests/test_experimental_lambdify.py +77 -0
- venv/lib/python3.14/site-packages/sympy/plotting/tests/test_plot.py +1344 -0
- venv/lib/python3.14/site-packages/sympy/plotting/tests/test_plot_implicit.py +146 -0
- venv/lib/python3.14/site-packages/sympy/plotting/tests/test_region_and.png +0 -0
- venv/lib/python3.14/site-packages/sympy/plotting/tests/test_region_not.png +0 -0
- venv/lib/python3.14/site-packages/sympy/plotting/tests/test_region_or.png +0 -0
- venv/lib/python3.14/site-packages/sympy/plotting/tests/test_region_xor.png +0 -0
- venv/lib/python3.14/site-packages/sympy/plotting/tests/test_series.py +1771 -0
- venv/lib/python3.14/site-packages/sympy/plotting/tests/test_textplot.py +203 -0
- venv/lib/python3.14/site-packages/sympy/plotting/tests/test_utils.py +110 -0
- venv/lib/python3.14/site-packages/sympy/plotting/textplot.py +168 -0
- venv/lib/python3.14/site-packages/sympy/plotting/utils.py +323 -0
- venv/lib/python3.14/site-packages/sympy/polys/__init__.py +130 -0
- venv/lib/python3.14/site-packages/sympy/polys/agca/__init__.py +5 -0
- venv/lib/python3.14/site-packages/sympy/polys/agca/extensions.py +356 -0
- venv/lib/python3.14/site-packages/sympy/polys/agca/homomorphisms.py +691 -0
- venv/lib/python3.14/site-packages/sympy/polys/agca/ideals.py +395 -0
- venv/lib/python3.14/site-packages/sympy/polys/agca/modules.py +1488 -0
.gitattributes
CHANGED
|
@@ -160,3 +160,4 @@ venv/lib/python3.14/site-packages/streamlit/static/static/media/SourceSansVF-Upr
|
|
| 160 |
venv/lib/python3.14/site-packages/streamlit/static/static/media/SourceSerifVariable-Italic.ttf.CVdzAtxO.woff2 filter=lfs diff=lfs merge=lfs -text
|
| 161 |
venv/lib/python3.14/site-packages/streamlit/static/static/media/SourceSerifVariable-Roman.ttf.mdpVL9bi.woff2 filter=lfs diff=lfs merge=lfs -text
|
| 162 |
venv/lib/python3.14/site-packages/streamlit/static/static/media/fireworks.B4d-_KUe.gif filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 160 |
venv/lib/python3.14/site-packages/streamlit/static/static/media/SourceSerifVariable-Italic.ttf.CVdzAtxO.woff2 filter=lfs diff=lfs merge=lfs -text
|
| 161 |
venv/lib/python3.14/site-packages/streamlit/static/static/media/SourceSerifVariable-Roman.ttf.mdpVL9bi.woff2 filter=lfs diff=lfs merge=lfs -text
|
| 162 |
venv/lib/python3.14/site-packages/streamlit/static/static/media/fireworks.B4d-_KUe.gif filter=lfs diff=lfs merge=lfs -text
|
| 163 |
+
venv/lib/python3.14/site-packages/tokenizers/tokenizers.abi3.so filter=lfs diff=lfs merge=lfs -text
|
venv/lib/python3.14/site-packages/sympy-1.14.0.dist-info/INSTALLER
ADDED
|
@@ -0,0 +1 @@
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| 3 |
+
Version: 1.14.0
|
| 4 |
+
Summary: Computer algebra system (CAS) in Python
|
| 5 |
+
Home-page: https://sympy.org
|
| 6 |
+
Author: SymPy development team
|
| 7 |
+
Author-email: sympy@googlegroups.com
|
| 8 |
+
License: BSD
|
| 9 |
+
Project-URL: Source, https://github.com/sympy/sympy
|
| 10 |
+
Keywords: Math CAS
|
| 11 |
+
Classifier: License :: OSI Approved :: BSD License
|
| 12 |
+
Classifier: Operating System :: OS Independent
|
| 13 |
+
Classifier: Programming Language :: Python
|
| 14 |
+
Classifier: Topic :: Scientific/Engineering
|
| 15 |
+
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
| 16 |
+
Classifier: Topic :: Scientific/Engineering :: Physics
|
| 17 |
+
Classifier: Programming Language :: Python :: 3
|
| 18 |
+
Classifier: Programming Language :: Python :: 3.9
|
| 19 |
+
Classifier: Programming Language :: Python :: 3.10
|
| 20 |
+
Classifier: Programming Language :: Python :: 3.11
|
| 21 |
+
Classifier: Programming Language :: Python :: 3.12
|
| 22 |
+
Classifier: Programming Language :: Python :: 3.13
|
| 23 |
+
Classifier: Programming Language :: Python :: 3 :: Only
|
| 24 |
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
| 25 |
+
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
| 26 |
+
Requires-Python: >=3.9
|
| 27 |
+
Description-Content-Type: text/markdown
|
| 28 |
+
License-File: LICENSE
|
| 29 |
+
License-File: AUTHORS
|
| 30 |
+
Requires-Dist: mpmath<1.4,>=1.1.0
|
| 31 |
+
Provides-Extra: dev
|
| 32 |
+
Requires-Dist: pytest>=7.1.0; extra == "dev"
|
| 33 |
+
Requires-Dist: hypothesis>=6.70.0; extra == "dev"
|
| 34 |
+
Dynamic: author
|
| 35 |
+
Dynamic: author-email
|
| 36 |
+
Dynamic: classifier
|
| 37 |
+
Dynamic: description
|
| 38 |
+
Dynamic: description-content-type
|
| 39 |
+
Dynamic: home-page
|
| 40 |
+
Dynamic: keywords
|
| 41 |
+
Dynamic: license
|
| 42 |
+
Dynamic: license-file
|
| 43 |
+
Dynamic: project-url
|
| 44 |
+
Dynamic: provides-extra
|
| 45 |
+
Dynamic: requires-dist
|
| 46 |
+
Dynamic: requires-python
|
| 47 |
+
Dynamic: summary
|
| 48 |
+
|
| 49 |
+
# SymPy
|
| 50 |
+
|
| 51 |
+
[](https://pypi.python.org/pypi/sympy)
|
| 52 |
+
[](https://gitter.im/sympy/sympy?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
| 53 |
+
[](https://zenodo.org/badge/latestdoi/18918/sympy/sympy)
|
| 54 |
+
[](https://pepy.tech/project/sympy)
|
| 55 |
+
[](https://github.com/sympy/sympy/issues)
|
| 56 |
+
[](https://git-scm.com/book/en/v2/GitHub-Contributing-to-a-Project)
|
| 57 |
+
[](https://numfocus.org)
|
| 58 |
+
[](https://github.com/sympy/sympy/releases)
|
| 59 |
+
|
| 60 |
+
[](https://sympy.org/)
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
See the [AUTHORS](AUTHORS) file for the list of authors.
|
| 64 |
+
|
| 65 |
+
And many more people helped on the SymPy mailing list, reported bugs,
|
| 66 |
+
helped organize SymPy's participation in the Google Summer of Code, the
|
| 67 |
+
Google Highly Open Participation Contest, Google Code-In, wrote and
|
| 68 |
+
blogged about SymPy...
|
| 69 |
+
|
| 70 |
+
License: New BSD License (see the [LICENSE](LICENSE) file for details) covers all
|
| 71 |
+
files in the sympy repository unless stated otherwise.
|
| 72 |
+
|
| 73 |
+
Our mailing list is at
|
| 74 |
+
<https://groups.google.com/forum/?fromgroups#!forum/sympy>.
|
| 75 |
+
|
| 76 |
+
We have a community chat at [Gitter](https://gitter.im/sympy/sympy). Feel
|
| 77 |
+
free to ask us anything there. We have a very welcoming and helpful
|
| 78 |
+
community.
|
| 79 |
+
|
| 80 |
+
## Download
|
| 81 |
+
|
| 82 |
+
The recommended installation method is through Anaconda,
|
| 83 |
+
<https://www.anaconda.com/products/distribution>
|
| 84 |
+
|
| 85 |
+
You can also get the latest version of SymPy from
|
| 86 |
+
<https://pypi.python.org/pypi/sympy/>
|
| 87 |
+
|
| 88 |
+
To get the git version do
|
| 89 |
+
|
| 90 |
+
$ git clone https://github.com/sympy/sympy.git
|
| 91 |
+
|
| 92 |
+
For other options (tarballs, debs, etc.), see
|
| 93 |
+
<https://docs.sympy.org/dev/install.html>.
|
| 94 |
+
|
| 95 |
+
## Documentation and Usage
|
| 96 |
+
|
| 97 |
+
For in-depth instructions on installation and building the
|
| 98 |
+
documentation, see the [SymPy Documentation Style Guide](https://docs.sympy.org/dev/documentation-style-guide.html).
|
| 99 |
+
|
| 100 |
+
Everything is at:
|
| 101 |
+
|
| 102 |
+
<https://docs.sympy.org/>
|
| 103 |
+
|
| 104 |
+
You can generate everything at the above site in your local copy of
|
| 105 |
+
SymPy by:
|
| 106 |
+
|
| 107 |
+
$ cd doc
|
| 108 |
+
$ make html
|
| 109 |
+
|
| 110 |
+
Then the docs will be in <span class="title-ref">\_build/html</span>. If
|
| 111 |
+
you don't want to read that, here is a short usage:
|
| 112 |
+
|
| 113 |
+
From this directory, start Python and:
|
| 114 |
+
|
| 115 |
+
``` python
|
| 116 |
+
>>> from sympy import Symbol, cos
|
| 117 |
+
>>> x = Symbol('x')
|
| 118 |
+
>>> e = 1/cos(x)
|
| 119 |
+
>>> print(e.series(x, 0, 10))
|
| 120 |
+
1 + x**2/2 + 5*x**4/24 + 61*x**6/720 + 277*x**8/8064 + O(x**10)
|
| 121 |
+
```
|
| 122 |
+
|
| 123 |
+
SymPy also comes with a console that is a simple wrapper around the
|
| 124 |
+
classic python console (or IPython when available) that loads the SymPy
|
| 125 |
+
namespace and executes some common commands for you.
|
| 126 |
+
|
| 127 |
+
To start it, issue:
|
| 128 |
+
|
| 129 |
+
$ bin/isympy
|
| 130 |
+
|
| 131 |
+
from this directory, if SymPy is not installed or simply:
|
| 132 |
+
|
| 133 |
+
$ isympy
|
| 134 |
+
|
| 135 |
+
if SymPy is installed.
|
| 136 |
+
|
| 137 |
+
## Installation
|
| 138 |
+
|
| 139 |
+
To install SymPy using PyPI, run the following command:
|
| 140 |
+
|
| 141 |
+
$ pip install sympy
|
| 142 |
+
|
| 143 |
+
To install SymPy using Anaconda, run the following command:
|
| 144 |
+
|
| 145 |
+
$ conda install -c anaconda sympy
|
| 146 |
+
|
| 147 |
+
To install SymPy from GitHub source, first clone SymPy using `git`:
|
| 148 |
+
|
| 149 |
+
$ git clone https://github.com/sympy/sympy.git
|
| 150 |
+
|
| 151 |
+
Then, in the `sympy` repository that you cloned, simply run:
|
| 152 |
+
|
| 153 |
+
$ pip install .
|
| 154 |
+
|
| 155 |
+
See <https://docs.sympy.org/dev/install.html> for more information.
|
| 156 |
+
|
| 157 |
+
## Contributing
|
| 158 |
+
|
| 159 |
+
We welcome contributions from anyone, even if you are new to open
|
| 160 |
+
source. Please read our [Introduction to Contributing](https://docs.sympy.org/dev/contributing/introduction-to-contributing.html)
|
| 161 |
+
page and the [SymPy Documentation Style Guide](https://docs.sympy.org/dev/documentation-style-guide.html). If you
|
| 162 |
+
are new and looking for some way to contribute, a good place to start is
|
| 163 |
+
to look at the issues tagged [Easy to Fix](https://github.com/sympy/sympy/issues?q=is%3Aopen+is%3Aissue+label%3A%22Easy+to+Fix%22).
|
| 164 |
+
|
| 165 |
+
Please note that all participants in this project are expected to follow
|
| 166 |
+
our Code of Conduct. By participating in this project you agree to abide
|
| 167 |
+
by its terms. See [CODE\_OF\_CONDUCT.md](CODE_OF_CONDUCT.md).
|
| 168 |
+
|
| 169 |
+
## Tests
|
| 170 |
+
|
| 171 |
+
To execute all tests, run:
|
| 172 |
+
|
| 173 |
+
$./setup.py test
|
| 174 |
+
|
| 175 |
+
in the current directory.
|
| 176 |
+
|
| 177 |
+
For the more fine-grained running of tests or doctests, use `bin/test`
|
| 178 |
+
or respectively `bin/doctest`. The master branch is automatically tested
|
| 179 |
+
by GitHub Actions.
|
| 180 |
+
|
| 181 |
+
To test pull requests, use
|
| 182 |
+
[sympy-bot](https://github.com/sympy/sympy-bot).
|
| 183 |
+
|
| 184 |
+
## Regenerate Experimental <span class="title-ref">LaTeX</span> Parser/Lexer
|
| 185 |
+
|
| 186 |
+
The parser and lexer were generated with the [ANTLR4](http://antlr4.org)
|
| 187 |
+
toolchain in `sympy/parsing/latex/_antlr` and checked into the repo.
|
| 188 |
+
Presently, most users should not need to regenerate these files, but
|
| 189 |
+
if you plan to work on this feature, you will need the `antlr4`
|
| 190 |
+
command-line tool (and you must ensure that it is in your `PATH`).
|
| 191 |
+
One way to get it is:
|
| 192 |
+
|
| 193 |
+
$ conda install -c conda-forge antlr=4.11.1
|
| 194 |
+
|
| 195 |
+
Alternatively, follow the instructions on the ANTLR website and download
|
| 196 |
+
the `antlr-4.11.1-complete.jar`. Then export the `CLASSPATH` as instructed
|
| 197 |
+
and instead of creating `antlr4` as an alias, make it an executable file
|
| 198 |
+
with the following contents:
|
| 199 |
+
``` bash
|
| 200 |
+
#!/bin/bash
|
| 201 |
+
java -jar /usr/local/lib/antlr-4.11.1-complete.jar "$@"
|
| 202 |
+
```
|
| 203 |
+
|
| 204 |
+
After making changes to `sympy/parsing/latex/LaTeX.g4`, run:
|
| 205 |
+
|
| 206 |
+
$ ./setup.py antlr
|
| 207 |
+
|
| 208 |
+
## Clean
|
| 209 |
+
|
| 210 |
+
To clean everything (thus getting the same tree as in the repository):
|
| 211 |
+
|
| 212 |
+
$ git clean -Xdf
|
| 213 |
+
|
| 214 |
+
which will clear everything ignored by `.gitignore`, and:
|
| 215 |
+
|
| 216 |
+
$ git clean -df
|
| 217 |
+
|
| 218 |
+
to clear all untracked files. You can revert the most recent changes in
|
| 219 |
+
git with:
|
| 220 |
+
|
| 221 |
+
$ git reset --hard
|
| 222 |
+
|
| 223 |
+
WARNING: The above commands will all clear changes you may have made,
|
| 224 |
+
and you will lose them forever. Be sure to check things with `git
|
| 225 |
+
status`, `git diff`, `git clean -Xn`, and `git clean -n` before doing any
|
| 226 |
+
of those.
|
| 227 |
+
|
| 228 |
+
## Bugs
|
| 229 |
+
|
| 230 |
+
Our issue tracker is at <https://github.com/sympy/sympy/issues>. Please
|
| 231 |
+
report any bugs that you find. Or, even better, fork the repository on
|
| 232 |
+
GitHub and create a pull request. We welcome all changes, big or small,
|
| 233 |
+
and we will help you make the pull request if you are new to git (just
|
| 234 |
+
ask on our mailing list or Gitter Channel). If you further have any queries, you can find answers
|
| 235 |
+
on Stack Overflow using the [sympy](https://stackoverflow.com/questions/tagged/sympy) tag.
|
| 236 |
+
|
| 237 |
+
## Brief History
|
| 238 |
+
|
| 239 |
+
SymPy was started by Ondřej Čertík in 2005, he wrote some code during
|
| 240 |
+
the summer, then he wrote some more code during summer 2006. In February
|
| 241 |
+
2007, Fabian Pedregosa joined the project and helped fix many things,
|
| 242 |
+
contributed documentation, and made it alive again. 5 students (Mateusz
|
| 243 |
+
Paprocki, Brian Jorgensen, Jason Gedge, Robert Schwarz, and Chris Wu)
|
| 244 |
+
improved SymPy incredibly during summer 2007 as part of the Google
|
| 245 |
+
Summer of Code. Pearu Peterson joined the development during the summer
|
| 246 |
+
2007 and he has made SymPy much more competitive by rewriting the core
|
| 247 |
+
from scratch, which has made it from 10x to 100x faster. Jurjen N.E. Bos
|
| 248 |
+
has contributed pretty-printing and other patches. Fredrik Johansson has
|
| 249 |
+
written mpmath and contributed a lot of patches.
|
| 250 |
+
|
| 251 |
+
SymPy has participated in every Google Summer of Code since 2007. You
|
| 252 |
+
can see <https://github.com/sympy/sympy/wiki#google-summer-of-code> for
|
| 253 |
+
full details. Each year has improved SymPy by bounds. Most of SymPy's
|
| 254 |
+
development has come from Google Summer of Code students.
|
| 255 |
+
|
| 256 |
+
In 2011, Ondřej Čertík stepped down as lead developer, with Aaron
|
| 257 |
+
Meurer, who also started as a Google Summer of Code student, taking his
|
| 258 |
+
place. Ondřej Čertík is still active in the community but is too busy
|
| 259 |
+
with work and family to play a lead development role.
|
| 260 |
+
|
| 261 |
+
Since then, a lot more people have joined the development and some
|
| 262 |
+
people have also left. You can see the full list in doc/src/aboutus.rst,
|
| 263 |
+
or online at:
|
| 264 |
+
|
| 265 |
+
<https://docs.sympy.org/dev/aboutus.html#sympy-development-team>
|
| 266 |
+
|
| 267 |
+
The git history goes back to 2007 when development moved from svn to hg.
|
| 268 |
+
To see the history before that point, look at
|
| 269 |
+
<https://github.com/sympy/sympy-old>.
|
| 270 |
+
|
| 271 |
+
You can use git to see the biggest developers. The command:
|
| 272 |
+
|
| 273 |
+
$ git shortlog -ns
|
| 274 |
+
|
| 275 |
+
will show each developer, sorted by commits to the project. The command:
|
| 276 |
+
|
| 277 |
+
$ git shortlog -ns --since="1 year"
|
| 278 |
+
|
| 279 |
+
will show the top developers from the last year.
|
| 280 |
+
|
| 281 |
+
## Citation
|
| 282 |
+
|
| 283 |
+
To cite SymPy in publications use
|
| 284 |
+
|
| 285 |
+
> Meurer A, Smith CP, Paprocki M, Čertík O, Kirpichev SB, Rocklin M,
|
| 286 |
+
> Kumar A, Ivanov S, Moore JK, Singh S, Rathnayake T, Vig S, Granger BE,
|
| 287 |
+
> Muller RP, Bonazzi F, Gupta H, Vats S, Johansson F, Pedregosa F, Curry
|
| 288 |
+
> MJ, Terrel AR, Roučka Š, Saboo A, Fernando I, Kulal S, Cimrman R,
|
| 289 |
+
> Scopatz A. (2017) SymPy: symbolic computing in Python. *PeerJ Computer
|
| 290 |
+
> Science* 3:e103 <https://doi.org/10.7717/peerj-cs.103>
|
| 291 |
+
|
| 292 |
+
A BibTeX entry for LaTeX users is
|
| 293 |
+
|
| 294 |
+
``` bibtex
|
| 295 |
+
@article{10.7717/peerj-cs.103,
|
| 296 |
+
title = {SymPy: symbolic computing in Python},
|
| 297 |
+
author = {Meurer, Aaron and Smith, Christopher P. and Paprocki, Mateusz and \v{C}ert\'{i}k, Ond\v{r}ej and Kirpichev, Sergey B. and Rocklin, Matthew and Kumar, Amit and Ivanov, Sergiu and Moore, Jason K. and Singh, Sartaj and Rathnayake, Thilina and Vig, Sean and Granger, Brian E. and Muller, Richard P. and Bonazzi, Francesco and Gupta, Harsh and Vats, Shivam and Johansson, Fredrik and Pedregosa, Fabian and Curry, Matthew J. and Terrel, Andy R. and Rou\v{c}ka, \v{S}t\v{e}p\'{a}n and Saboo, Ashutosh and Fernando, Isuru and Kulal, Sumith and Cimrman, Robert and Scopatz, Anthony},
|
| 298 |
+
year = 2017,
|
| 299 |
+
month = Jan,
|
| 300 |
+
keywords = {Python, Computer algebra system, Symbolics},
|
| 301 |
+
abstract = {
|
| 302 |
+
SymPy is an open-source computer algebra system written in pure Python. It is built with a focus on extensibility and ease of use, through both interactive and programmatic applications. These characteristics have led SymPy to become a popular symbolic library for the scientific Python ecosystem. This paper presents the architecture of SymPy, a description of its features, and a discussion of select submodules. The supplementary material provides additional examples and further outlines details of the architecture and features of SymPy.
|
| 303 |
+
},
|
| 304 |
+
volume = 3,
|
| 305 |
+
pages = {e103},
|
| 306 |
+
journal = {PeerJ Computer Science},
|
| 307 |
+
issn = {2376-5992},
|
| 308 |
+
url = {https://doi.org/10.7717/peerj-cs.103},
|
| 309 |
+
doi = {10.7717/peerj-cs.103}
|
| 310 |
+
}
|
| 311 |
+
```
|
| 312 |
+
|
| 313 |
+
SymPy is BSD licensed, so you are free to use it whatever you like, be
|
| 314 |
+
it academic, commercial, creating forks or derivatives, as long as you
|
| 315 |
+
copy the BSD statement if you redistribute it (see the LICENSE file for
|
| 316 |
+
details). That said, although not required by the SymPy license, if it
|
| 317 |
+
is convenient for you, please cite SymPy when using it in your work and
|
| 318 |
+
also consider contributing all your changes back, so that we can
|
| 319 |
+
incorporate it and all of us will benefit in the end.
|
venv/lib/python3.14/site-packages/sympy-1.14.0.dist-info/RECORD
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
venv/lib/python3.14/site-packages/sympy-1.14.0.dist-info/WHEEL
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Wheel-Version: 1.0
|
| 2 |
+
Generator: setuptools (79.0.1)
|
| 3 |
+
Root-Is-Purelib: true
|
| 4 |
+
Tag: py3-none-any
|
| 5 |
+
|
venv/lib/python3.14/site-packages/sympy-1.14.0.dist-info/entry_points.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[console_scripts]
|
| 2 |
+
isympy = isympy:main
|
venv/lib/python3.14/site-packages/sympy-1.14.0.dist-info/licenses/AUTHORS
ADDED
|
@@ -0,0 +1,1379 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
All people who contributed to SymPy by sending at least a patch or
|
| 2 |
+
more (in the order of the date of their first contribution), except
|
| 3 |
+
those who explicitly didn't want to be mentioned. People with a * next
|
| 4 |
+
to their names are not found in the metadata of the git history. This
|
| 5 |
+
file is generated automatically by running `./bin/authors_update.py`.
|
| 6 |
+
|
| 7 |
+
There are a total of 1371 authors.
|
| 8 |
+
|
| 9 |
+
Ondřej Čertík <ondrej@certik.cz>
|
| 10 |
+
Fabian Pedregosa <fabian@fseoane.net>
|
| 11 |
+
Jurjen N.E. Bos <jnebos@gmail.com>
|
| 12 |
+
Mateusz Paprocki <mattpap@gmail.com>
|
| 13 |
+
*Marc-Etienne M.Leveille <protonyc@gmail.com>
|
| 14 |
+
Brian Jorgensen <brian.jorgensen@gmail.com>
|
| 15 |
+
Jason Gedge <inferno1386@gmail.com>
|
| 16 |
+
Robert Schwarz <lethargo@googlemail.com>
|
| 17 |
+
Pearu Peterson <pearu.peterson@gmail.com>
|
| 18 |
+
Fredrik Johansson <fredrik.johansson@gmail.com>
|
| 19 |
+
Chris Wu <chris.wu@gmail.com>
|
| 20 |
+
*Ulrich Hecht <ulrich.hecht@gmail.com>
|
| 21 |
+
Goutham Lakshminarayan <dl.goutham@gmail.com>
|
| 22 |
+
David Lawrence <dmlawrence@gmail.com>
|
| 23 |
+
Jaroslaw Tworek <dev.jrx@gmail.com>
|
| 24 |
+
David Marek <h4wk.cz@gmail.com>
|
| 25 |
+
Bernhard R. Link <brlink@debian.org>
|
| 26 |
+
Andrej Tokarčík <androsis@gmail.com>
|
| 27 |
+
Or Dvory <gidesa@gmail.com>
|
| 28 |
+
Saroj Adhikari <adh.saroj@gmail.com>
|
| 29 |
+
Pauli Virtanen <pav@iki.fi>
|
| 30 |
+
Robert Kern <robert.kern@gmail.com>
|
| 31 |
+
James Aspnes <aspnes@cs.yale.edu>
|
| 32 |
+
Nimish Telang <ntelang@gmail.com>
|
| 33 |
+
Abderrahim Kitouni <a.kitouni@gmail.com>
|
| 34 |
+
Pan Peng <pengpanster@gmail.com>
|
| 35 |
+
Friedrich Hagedorn <friedrich_h@gmx.de>
|
| 36 |
+
Elrond der Elbenfuerst <elrond+sympy.org@samba-tng.org>
|
| 37 |
+
Rizgar Mella <rizgar.mella@gmail.com>
|
| 38 |
+
Felix Kaiser <felix.kaiser@fxkr.net>
|
| 39 |
+
Roberto Nobrega <rwnobrega@gmail.com>
|
| 40 |
+
David Roberts <dvdr18@gmail.com>
|
| 41 |
+
Sebastian Krämer <basti.kr@gmail.com>
|
| 42 |
+
Vinzent Steinberg <vinzent.steinberg@gmail.com>
|
| 43 |
+
Riccardo Gori <goriccardo@gmail.com>
|
| 44 |
+
Case Van Horsen <casevh@gmail.com>
|
| 45 |
+
Stepan Roucka <stepan@roucka.eu>
|
| 46 |
+
Ali Raza Syed <arsyed@gmail.com>
|
| 47 |
+
Stefano Maggiolo <s.maggiolo@gmail.com>
|
| 48 |
+
Robert Cimrman <cimrman3@ntc.zcu.cz>
|
| 49 |
+
Bastian Weber <bastian.weber@gmx-topmail.de>
|
| 50 |
+
Sebastian Krause <sebastian.krause@gmx.de>
|
| 51 |
+
Sebastian Kreft <skreft@gmail.com>
|
| 52 |
+
*Dan <coolg49964@gmail.com>
|
| 53 |
+
Alan Bromborsky <abrombo@verizon.net>
|
| 54 |
+
Boris Timokhin <qoqenator@gmail.com>
|
| 55 |
+
Robert <average.programmer@gmail.com>
|
| 56 |
+
Andy R. Terrel <aterrel@uchicago.edu>
|
| 57 |
+
Hubert Tsang <intsangity@gmail.com>
|
| 58 |
+
Konrad Meyer <konrad.meyer@gmail.com>
|
| 59 |
+
Henrik Johansson <henjo2006@gmail.com>
|
| 60 |
+
Priit Laes <plaes@plaes.org>
|
| 61 |
+
Freddie Witherden <freddie@witherden.org>
|
| 62 |
+
Brian E. Granger <ellisonbg@gmail.com>
|
| 63 |
+
Andrew Straw <strawman@astraw.com>
|
| 64 |
+
Kaifeng Zhu <cafeeee@gmail.com>
|
| 65 |
+
Ted Horst <ted.horst@earthlink.net>
|
| 66 |
+
Andrew Docherty <andrewd@maths.usyd.edu.au>
|
| 67 |
+
Akshay Srinivasan <akshaysrinivasan@gmail.com>
|
| 68 |
+
Aaron Meurer <asmeurer@gmail.com>
|
| 69 |
+
Barry Wardell <barry.wardell@gmail.com>
|
| 70 |
+
Tomasz Buchert <thinred@gmail.com>
|
| 71 |
+
Vinay Kumar <gnulinooks@gmail.com>
|
| 72 |
+
Johann Cohen-Tanugi <johann.cohentanugi@gmail.com>
|
| 73 |
+
Jochen Voss <voss@seehuhn.de>
|
| 74 |
+
Luke Peterson <hazelnusse@gmail.com>
|
| 75 |
+
Chris Smith <smichr@gmail.com>
|
| 76 |
+
Thomas Sidoti <TSidoti@gmail.com>
|
| 77 |
+
Florian Mickler <florian@mickler.org>
|
| 78 |
+
Nicolas Pourcelot <nicolas.pourcelot@gmail.com>
|
| 79 |
+
Ben Goodrich <goodrich.ben@gmail.com>
|
| 80 |
+
Toon Verstraelen <Toon.Verstraelen@UGent.be>
|
| 81 |
+
Ronan Lamy <ronan.lamy@gmail.com>
|
| 82 |
+
James Abbatiello <abbeyj@gmail.com>
|
| 83 |
+
Ryan Krauss <ryanlists@gmail.com>
|
| 84 |
+
Bill Flynn <wflynny@gmail.com>
|
| 85 |
+
Kevin Goodsell <kevin-opensource@omegacrash.net>
|
| 86 |
+
Jorn Baayen <jorn.baayen@gmail.com>
|
| 87 |
+
Eh Tan <tan2tan2@gmail.com>
|
| 88 |
+
Renato Coutinho <renato.coutinho@gmail.com>
|
| 89 |
+
Oscar Benjamin <oscar.j.benjamin@gmail.com>
|
| 90 |
+
Øyvind Jensen <jensen.oyvind@gmail.com>
|
| 91 |
+
Julio Idichekop Filho <idichekop@yahoo.com.br>
|
| 92 |
+
Łukasz Pankowski <lukpank@o2.pl>
|
| 93 |
+
*Chu-Ching Huang <cchuang@mail.cgu.edu.tw>
|
| 94 |
+
Fernando Perez <Fernando.Perez@berkeley.edu>
|
| 95 |
+
Raffaele De Feo <alberthilbert@gmail.com>
|
| 96 |
+
Christian Muise <christian.muise@gmail.com>
|
| 97 |
+
Matt Curry <mattjcurry@gmail.com>
|
| 98 |
+
Kazuo Thow <kazuo.thow@gmail.com>
|
| 99 |
+
Christian Schubert <chr.schubert@gmx.de>
|
| 100 |
+
Jezreel Ng <jezreel@gmail.com>
|
| 101 |
+
James Pearson <xiong.chiamiov@gmail.com>
|
| 102 |
+
Matthew Brett <matthew.brett@gmail.com>
|
| 103 |
+
Addison Cugini <ajcugini@gmail.com>
|
| 104 |
+
Nicholas J.S. Kinar <n.kinar@usask.ca>
|
| 105 |
+
Harold Erbin <harold.erbin@gmail.com>
|
| 106 |
+
Thomas Dixon <thom@thomdixon.org>
|
| 107 |
+
Cristóvão Sousa <crisjss@gmail.com>
|
| 108 |
+
Andre de Fortier Smit <freevryheid@gmail.com>
|
| 109 |
+
Mark Dewing <markdewing@gmail.com>
|
| 110 |
+
Alexey U. Gudchenko <proga@goodok.ru>
|
| 111 |
+
Gary Kerr <gary.kerr@blueyonder.co.uk>
|
| 112 |
+
Sherjil Ozair <sherjilozair@gmail.com>
|
| 113 |
+
Oleksandr Gituliar <gituliar@gmail.com>
|
| 114 |
+
Sean Vig <sean.v.775@gmail.com>
|
| 115 |
+
Prafullkumar P. Tale <hector1618@gmail.com>
|
| 116 |
+
Vladimir Perić <vlada.peric@gmail.com>
|
| 117 |
+
Tom Bachmann <e_mc_h2@web.de>
|
| 118 |
+
Yuri Karadzhov <yuri.karadzhov@gmail.com>
|
| 119 |
+
Vladimir Lagunov <werehuman@gmail.com>
|
| 120 |
+
Matthew Rocklin <mrocklin@cs.uchicago.edu>
|
| 121 |
+
Saptarshi Mandal <sapta.iitkgp@gmail.com>
|
| 122 |
+
Gilbert Gede <gilbertgede@gmail.com>
|
| 123 |
+
Anatolii Koval <weralwolf@gmail.com>
|
| 124 |
+
Tomo Lazovich <lazovich@gmail.com>
|
| 125 |
+
Pavel Fedotov <fedotovp@gmail.com>
|
| 126 |
+
Jack McCaffery <jpmccaffery@gmail.com>
|
| 127 |
+
Jeremias Yehdegho <j.yehdegho@gmail.com>
|
| 128 |
+
Kibeom Kim <kk1674@nyu.edu>
|
| 129 |
+
Gregory Ksionda <ksiondag846@gmail.com>
|
| 130 |
+
Tomáš Bambas <tomas.bambas@gmail.com>
|
| 131 |
+
Raymond Wong <rayman_407@yahoo.com>
|
| 132 |
+
Luca Weihs <astronomicalcuriosity@gmail.com>
|
| 133 |
+
Shai 'Deshe' Wyborski <shaide@cs.huji.ac.il>
|
| 134 |
+
Thomas Wiecki <thomas.wiecki@gmail.com>
|
| 135 |
+
Óscar Nájera <najera.oscar@gmail.com>
|
| 136 |
+
Mario Pernici <mario.pernici@gmail.com>
|
| 137 |
+
Benjamin McDonald <mcdonald.ben@gmail.com>
|
| 138 |
+
Sam Magura <samtheman132@gmail.com>
|
| 139 |
+
Stefan Krastanov <krastanov.stefan@gmail.com>
|
| 140 |
+
Bradley Froehle <brad.froehle@gmail.com>
|
| 141 |
+
Min Ragan-Kelley <benjaminrk@gmail.com>
|
| 142 |
+
Emma Hogan <ehogan@gemini.edu>
|
| 143 |
+
Nikhil Sarda <diff.operator@gmail.com>
|
| 144 |
+
Julien Rioux <julien.rioux@gmail.com>
|
| 145 |
+
Roberto Colistete, Jr. <roberto.colistete@gmail.com>
|
| 146 |
+
Raoul Bourquin <raoulb@bluewin.ch>
|
| 147 |
+
Gert-Ludwig Ingold <gert.ingold@physik.uni-augsburg.de>
|
| 148 |
+
Srinivas Vasudevan <srvasude@gmail.com>
|
| 149 |
+
Jason Moore <moorepants@gmail.com>
|
| 150 |
+
Miha Marolt <tloramus@gmail.com>
|
| 151 |
+
Tim Lahey <tim.lahey@gmail.com>
|
| 152 |
+
Luis Garcia <ppn.online@me.com>
|
| 153 |
+
Matt Rajca <matt.rajca@me.com>
|
| 154 |
+
David Li <l33tnerd.li@gmail.com>
|
| 155 |
+
Alexandr Gudulin <alexandr.gudulin@gmail.com>
|
| 156 |
+
Bilal Akhtar <bilalakhtar@ubuntu.com>
|
| 157 |
+
Grzegorz Świrski <sognat@gmail.com>
|
| 158 |
+
Matt Habel <habelinc@gmail.com>
|
| 159 |
+
David Ju <Sgtmook314@gmail.com>
|
| 160 |
+
Nichita Utiu <nikita.utiu+github@gmail.com>
|
| 161 |
+
Nikolay Lazarov <qwerqwerqwer@abv.bg>
|
| 162 |
+
Steve Anton <anxuiz.nx@gmail.com>
|
| 163 |
+
Imran Ahmed Manzoor <imran.manzoor31@gmail.com>
|
| 164 |
+
Ljubiša Moćić <3rdslasher@gmail.com>
|
| 165 |
+
Piotr Korgul <p.korgul@gmail.com>
|
| 166 |
+
Jim Zhang <Hyriodula@gmail.com>
|
| 167 |
+
Sam Sleight <samuel.sleight@gmail.com>
|
| 168 |
+
tborisova <ts.borisova3@gmail.com>
|
| 169 |
+
Chancellor Arkantos <Chancellor_Arkantos@hotmail.co.uk>
|
| 170 |
+
Stepan Simsa <simsa.st@gmail.com>
|
| 171 |
+
Tobias Lenz <t_lenz94@web.de>
|
| 172 |
+
Siddhanathan Shanmugam <siddhanathan@gmail.com>
|
| 173 |
+
Tiffany Zhu <bubble.wubble.303@gmail.com>
|
| 174 |
+
Tristan Hume <tris.hume@gmail.com>
|
| 175 |
+
Alexey Subach <alexey.subach@gmail.com>
|
| 176 |
+
Joan Creus <joan.creus.c@gmail.com>
|
| 177 |
+
Geoffry Song <goffrie@gmail.com>
|
| 178 |
+
Puneeth Chaganti <punchagan@gmail.com>
|
| 179 |
+
Marcin Kostrzewa <>
|
| 180 |
+
Natalia Nawara <fankalemura@gmail.com>
|
| 181 |
+
vishal <vishal.panjwani15@gmail.com>
|
| 182 |
+
Shruti Mangipudi <shruti2395@gmail.com>
|
| 183 |
+
Davy Mao <e_equals_mass_speed_light_squared@hotmail.com>
|
| 184 |
+
Swapnil Agarwal <swapnilag29@gmail.com>
|
| 185 |
+
Dhia Kennouche <kendhia@gmail.com>
|
| 186 |
+
jerryma1121 <jerryma1121@gmail.com>
|
| 187 |
+
Joachim Durchholz <jo@durchholz.org>
|
| 188 |
+
Martin Povišer <martin.povik@gmail.com>
|
| 189 |
+
Siddhant Jain <getsiddhant@gmail.com>
|
| 190 |
+
Kevin Hunter <hunteke@earlham.edu>
|
| 191 |
+
Michael Mayorov <marchael@kb.csu.ru>
|
| 192 |
+
Nathan Alison <nathan.f.alison@gmail.com>
|
| 193 |
+
Christian Bühler <christian@cbuehler.de>
|
| 194 |
+
Carsten Knoll <CarstenKnoll@gmx.de>
|
| 195 |
+
Bharath M R <catchmrbharath@gmail.com>
|
| 196 |
+
Matthias Toews <mat.toews@googlemail.com>
|
| 197 |
+
Sergiu Ivanov <unlimitedscolobb@gmail.com>
|
| 198 |
+
Jorge E. Cardona <jorgeecardona@gmail.com>
|
| 199 |
+
Sanket Agarwal <sanket@sanketagarwal.com>
|
| 200 |
+
Manoj Babu K. <manoj.babu2378@gmail.com>
|
| 201 |
+
Sai Nikhil <tsnlegend@gmail.com>
|
| 202 |
+
Aleksandar Makelov <amakelov@college.harvard.edu>
|
| 203 |
+
Sachin Irukula <sachin.irukula@gmail.com>
|
| 204 |
+
Raphael Michel <webmaster@raphaelmichel.de>
|
| 205 |
+
Ashwini Oruganti <ashwini.oruganti@gmail.com>
|
| 206 |
+
Andreas Klöckner <inform@tiker.net>
|
| 207 |
+
Prateek Papriwal <papriwalprateek@gmail.com>
|
| 208 |
+
Arpit Goyal <agmps18@gmail.com>
|
| 209 |
+
Angadh Nanjangud <angadh.n@gmail.com>
|
| 210 |
+
Comer Duncan <comer.duncan@gmail.com>
|
| 211 |
+
Jens H. Nielsen <jenshnielsen@gmail.com>
|
| 212 |
+
Joseph Dougherty <Github@JWDougherty.com>
|
| 213 |
+
Elliot Marshall <Marshall2389@gmail.com>
|
| 214 |
+
Guru Devanla <grdvnl@gmail.com>
|
| 215 |
+
George Waksman <waksman@gwax.com>
|
| 216 |
+
Alexandr Popov <alexandr.s.popov@gmail.com>
|
| 217 |
+
Tarun Gaba <tarun.gaba7@gmail.com>
|
| 218 |
+
Takafumi Arakaki <aka.tkf@gmail.com>
|
| 219 |
+
Saurabh Jha <saurabh.jhaa@gmail.com>
|
| 220 |
+
Rom le Clair <jacen.guardian@gmail.com>
|
| 221 |
+
Angus Griffith <16sn6uv@gmail.com>
|
| 222 |
+
Timothy Reluga <treluga@math.psu.edu>
|
| 223 |
+
Brian Stephanik <xoedusk@gmail.com>
|
| 224 |
+
Alexander Eberspächer <alex.eberspaecher@gmail.com>
|
| 225 |
+
Sachin Joglekar <srjoglekar246@gmail.com>
|
| 226 |
+
Tyler Pirtle <teeler@gmail.com>
|
| 227 |
+
Vasily Povalyaev <vapovalyaev@gmail.com>
|
| 228 |
+
Colleen Lee <colleenclee@gmail.com>
|
| 229 |
+
Matthew Hoff <mhoff14@gmail.com>
|
| 230 |
+
Niklas Thörne <notrupertthorne@gmail.com>
|
| 231 |
+
Huijun Mai <m.maihuijun@gmail.com>
|
| 232 |
+
Marek Šuppa <mr@shu.io>
|
| 233 |
+
Ramana Venkata <idlike2dream@gmail.com>
|
| 234 |
+
Prasoon Shukla <prasoon92.iitr@gmail.com>
|
| 235 |
+
Stefen Yin <zqyin@ucdavis.edu>
|
| 236 |
+
Thomas Hisch <t.hisch@gmail.com>
|
| 237 |
+
Madeleine Ball <mpball@gmail.com>
|
| 238 |
+
Mary Clark <mary.spriteling@gmail.com>
|
| 239 |
+
Rishabh Dixit <rishabhdixit11@gmail.com>
|
| 240 |
+
Manoj Kumar <manojkumarsivaraj334@gmail.com>
|
| 241 |
+
Akshit Agarwal <akshit.jiit@gmail.com>
|
| 242 |
+
CJ Carey <perimosocordiae@gmail.com>
|
| 243 |
+
Patrick Lacasse <patrick.m.lacasse@gmail.com>
|
| 244 |
+
Ananya H <ananyaha93@gmail.com>
|
| 245 |
+
Tarang Patel <tarangrockr@gmail.com>
|
| 246 |
+
Christopher Dembia <cld72@cornell.edu>
|
| 247 |
+
Benjamin Fishbein <fishbeinb@gmail.com>
|
| 248 |
+
Sean Ge <seange727@gmail.com>
|
| 249 |
+
Amit Jamadagni <bitsjamadagni@gmail.com>
|
| 250 |
+
Ankit Agrawal <aaaagrawal@iitb.ac.in>
|
| 251 |
+
Björn Dahlgren <bjodah@gmail.com>
|
| 252 |
+
Christophe Saint-Jean <christophe.saint-jean@univ-lr.fr>
|
| 253 |
+
Demian Wassermann <demian@bwh.harvard.edu>
|
| 254 |
+
Khagesh Patel <khageshpatel93@gmail.com>
|
| 255 |
+
Stephen Loo <shikil@yahoo.com>
|
| 256 |
+
hm <hacman0@gmail.com>
|
| 257 |
+
Patrick Poitras <acebulf@gmail.com>
|
| 258 |
+
Katja Sophie Hotz <katja.sophie.hotz@student.tuwien.ac.at>
|
| 259 |
+
Varun Joshi <joshi.142@osu.edu>
|
| 260 |
+
Chetna Gupta <cheta.gup@gmail.com>
|
| 261 |
+
Thilina Rathnayake <thilinarmtb@gmail.com>
|
| 262 |
+
Max Hutchinson <maxhutch@gmail.com>
|
| 263 |
+
Shravas K Rao <shravas@gmail.com>
|
| 264 |
+
Matthew Tadd <matt.tadd@gmail.com>
|
| 265 |
+
Alexander Hirzel <alex@hirzel.us>
|
| 266 |
+
Randy Heydon <randy.heydon@clockworklab.net>
|
| 267 |
+
Oliver Lee <oliverzlee@gmail.com>
|
| 268 |
+
Seshagiri Prabhu <seshagiriprabhu@gmail.com>
|
| 269 |
+
Pradyumna <pradyu1993@gmail.com>
|
| 270 |
+
Erik Welch <erik.n.welch@gmail.com>
|
| 271 |
+
Eric Nelson <eric.the.red.XLII@gmail.com>
|
| 272 |
+
Roland Puntaier <roland.puntaier@chello.at>
|
| 273 |
+
Chris Conley <chrisconley15@gmail.com>
|
| 274 |
+
Tim Swast <tswast@gmail.com>
|
| 275 |
+
Dmitry Batkovich <batya239@gmail.com>
|
| 276 |
+
Francesco Bonazzi <franz.bonazzi@gmail.com>
|
| 277 |
+
Yuriy Demidov <iurii.demidov@gmail.com>
|
| 278 |
+
Rick Muller <rpmuller@gmail.com>
|
| 279 |
+
Manish Gill <gill.manish90@gmail.com>
|
| 280 |
+
Markus Müller <markus.mueller.1.g@googlemail.com>
|
| 281 |
+
Amit Saha <amitsaha.in@gmail.com>
|
| 282 |
+
Jeremy <twobitlogic@gmail.com>
|
| 283 |
+
QuaBoo <kisonchristian@gmail.com>
|
| 284 |
+
Stefan van der Walt <stefan@sun.ac.za>
|
| 285 |
+
David Joyner <wdjoyner@gmail.com>
|
| 286 |
+
Lars Buitinck <larsmans@gmail.com>
|
| 287 |
+
Alkiviadis G. Akritas <akritas@uth.gr>
|
| 288 |
+
Vinit Ravishankar <vinit.ravishankar@gmail.com>
|
| 289 |
+
Michael Boyle <michael.oliver.boyle@gmail.com>
|
| 290 |
+
Heiner Kirchhoffer <Heiner.Kirchhoffer@gmail.com>
|
| 291 |
+
Pablo Puente <ppuedom@gmail.com>
|
| 292 |
+
James Fiedler <jrfiedler@gmail.com>
|
| 293 |
+
Harsh Gupta <mail@hargup.in>
|
| 294 |
+
Tuomas Airaksinen <tuomas.airaksinen@gmail.com>
|
| 295 |
+
Paul Strickland <p.e.strickland@gmail.com>
|
| 296 |
+
James Goppert <james.goppert@gmail.com>
|
| 297 |
+
rathmann <rathmann.os@gmail.com>
|
| 298 |
+
Avichal Dayal <avichal.dayal@gmail.com>
|
| 299 |
+
Paul Scott <paul.scott@nicta.com.au>
|
| 300 |
+
Shipra Banga <bangashipra@gmail.com>
|
| 301 |
+
Pramod Ch <pramodch14@gmail.com>
|
| 302 |
+
Akshay <akshaynukala95@gmail.com>
|
| 303 |
+
Buck Shlegeris <buck2@bruceh15.anu.edu.au>
|
| 304 |
+
Jonathan Miller <jdmiller93@gmail.com>
|
| 305 |
+
Edward Schembor <eschemb1@jhu.edu>
|
| 306 |
+
Rajath Shashidhara <rajaths.rajaths@gmail.com>
|
| 307 |
+
Zamrath Nizam <zamiguy_ni@yahoo.com>
|
| 308 |
+
Aditya Shah <adityashah30@gmail.com>
|
| 309 |
+
Rajat Aggarwal <rajataggarwal1975@gmail.com>
|
| 310 |
+
Sambuddha Basu <sammygamer@live.com>
|
| 311 |
+
Zeel Shah <kshah215@gmail.com>
|
| 312 |
+
Abhinav Chanda <abhinavchanda01@gmail.com>
|
| 313 |
+
Jim Crist <crist042@umn.edu>
|
| 314 |
+
Sudhanshu Mishra <mrsud94@gmail.com>
|
| 315 |
+
Anurag Sharma <anurags92@gmail.com>
|
| 316 |
+
Soumya Dipta Biswas <sdb1323@gmail.com>
|
| 317 |
+
Sushant Hiray <hiraysushant@gmail.com>
|
| 318 |
+
Ben Lucato <ben.lucato@gmail.com>
|
| 319 |
+
Kunal Arora <kunalarora.135@gmail.com>
|
| 320 |
+
Henry Gebhardt <hsggebhardt@gmail.com>
|
| 321 |
+
Dammina Sahabandu <dmsahabandu@gmail.com>
|
| 322 |
+
Manish Shukla <manish.shukla393@gmail>
|
| 323 |
+
Ralph Bean <rbean@redhat.com>
|
| 324 |
+
richierichrawr <richierichrawr@users.noreply.github.com>
|
| 325 |
+
John Connor <john.theman.connor@gmail.com>
|
| 326 |
+
Juan Luis Cano Rodríguez <juanlu001@gmail.com>
|
| 327 |
+
Sahil Shekhawat <sahilshekhawat01@gmail.com>
|
| 328 |
+
Kundan Kumar <kundankumar18581@gmail.com>
|
| 329 |
+
Stas Kelvich <stanconn@gmail.com>
|
| 330 |
+
sevaader <sevaader@gmail.com>
|
| 331 |
+
Dhruvesh Vijay Parikh <parikhdhruvesh1@gmail.com>
|
| 332 |
+
Venkatesh Halli <venkatesh.fatality@gmail.com>
|
| 333 |
+
Lennart Fricke <lennart@die-frickes.eu>
|
| 334 |
+
Vlad Seghete <vlad.seghete@gmail.com>
|
| 335 |
+
Shashank Agarwal <shashank.agarwal94@gmail.com>
|
| 336 |
+
carstimon <carstimon@gmail.com>
|
| 337 |
+
Pierre Haessig <pierre.haessig@crans.org>
|
| 338 |
+
Maciej Baranski <getrox.sc@gmail.com>
|
| 339 |
+
Benjamin Gudehus <hastebrot@gmail.com>
|
| 340 |
+
Faisal Anees <faisal.iiit@gmail.com>
|
| 341 |
+
Mark Shoulson <mark@kli.org>
|
| 342 |
+
Robert Johansson <jrjohansson@gmail.com>
|
| 343 |
+
Kalevi Suominen <jksuom@gmail.com>
|
| 344 |
+
Kaushik Varanasi <kaushik.varanasi1@gmail.com>
|
| 345 |
+
Fawaz Alazemi <Mba7eth@gmail.com>
|
| 346 |
+
Ambar Mehrotra <mehrotraambar@gmail.com>
|
| 347 |
+
David P. Sanders <dpsanders@gmail.com>
|
| 348 |
+
Peter Brady <petertbrady@gmail.com>
|
| 349 |
+
John V. Siratt <jvsiratt@gmail.com>
|
| 350 |
+
Sarwar Chahal <chahal.sarwar98@gmail.com>
|
| 351 |
+
Nathan Woods <charlesnwoods@gmail.com>
|
| 352 |
+
Colin B. Macdonald <cbm@m.fsf.org>
|
| 353 |
+
Marcus Näslund <naslundx@gmail.com>
|
| 354 |
+
Clemens Novak <clemens@familie-novak.net>
|
| 355 |
+
Mridul Seth <seth.mridul@gmail.com>
|
| 356 |
+
Craig A. Stoudt <craig.stoudt@gmail.com>
|
| 357 |
+
Raj <raj454raj@gmail.com>
|
| 358 |
+
Mihai A. Ionescu <ionescu.a.mihai@gmail.com>
|
| 359 |
+
immerrr <immerrr@gmail.com>
|
| 360 |
+
Chai Wah Wu <cwwuieee@gmail.com>
|
| 361 |
+
Leonid Blouvshtein <leonidbl91@gmail.com>
|
| 362 |
+
Peleg Michaeli <freepeleg@gmail.com>
|
| 363 |
+
ck Lux <lux.r.ck@gmail.com>
|
| 364 |
+
zsc347 <zsc347@gmail.com>
|
| 365 |
+
Hamish Dickson <hamish.dickson@gmail.com>
|
| 366 |
+
Michael Gallaspy <gallaspy.michael@gmail.com>
|
| 367 |
+
Roman Inflianskas <infroma@gmail.com>
|
| 368 |
+
Duane Nykamp <nykamp@umn.edu>
|
| 369 |
+
Ted Dokos <tdokos@gmail.com>
|
| 370 |
+
Sunny Aggarwal <sunnyaggarwal1994@gmail.com>
|
| 371 |
+
Victor Brebenar <v.brebenar@gmail.com>
|
| 372 |
+
Akshat Jain <akshat.jain@students.iiit.ac.in>
|
| 373 |
+
Shivam Vats <shivamvats.iitkgp@gmail.com>
|
| 374 |
+
Longqi Wang <iqgnol@gmail.com>
|
| 375 |
+
Juan Felipe Osorio <jfosorio@gmail.com>
|
| 376 |
+
Ray Cathcart <github@cathcart.us>
|
| 377 |
+
Lukas Zorich <lukas.zorich@gmail.com>
|
| 378 |
+
Eric Miller <emiller42@gmail.com>
|
| 379 |
+
Cody Herbst <cyherbst@gmail.com>
|
| 380 |
+
Nishith Shah <nishithshah.2211@gmail.com>
|
| 381 |
+
Amit Kumar <dtu.amit@gmail.com>
|
| 382 |
+
Yury G. Kudryashov <urkud.urkud@gmail.com>
|
| 383 |
+
Guillaume Gay <contact@damcb.com>
|
| 384 |
+
Mihir Wadwekar <m.mihirw@gmail.com>
|
| 385 |
+
Tuan Manh Lai <laituan245@gmail.com>
|
| 386 |
+
Asish Panda <asishrocks95@gmail.com>
|
| 387 |
+
Darshan Chaudhary <deathbullet@gmail.com>
|
| 388 |
+
Alec Kalinin <alec.kalinin@gmail.com>
|
| 389 |
+
Ralf Stephan <ralf@ark.in-berlin.de>
|
| 390 |
+
Aaditya Nair <aadityanair6494@gmail.com>
|
| 391 |
+
Jayesh Lahori <jlahori92@gmail.com>
|
| 392 |
+
Harshil Goel <harshil158@gmail.com>
|
| 393 |
+
Luv Agarwal <agarwal.iiit@gmail.com>
|
| 394 |
+
Jason Ly <jason.ly@gmail.com>
|
| 395 |
+
Lokesh Sharma <lokeshhsharma@gmail.com>
|
| 396 |
+
Sartaj Singh <singhsartaj94@gmail.com>
|
| 397 |
+
Chris Swierczewski <cswiercz@gmail.com>
|
| 398 |
+
Konstantin Togoi <konstantin.togoi@gmail.com>
|
| 399 |
+
Param Singh <paramsingh258@gmail.com>
|
| 400 |
+
Sumith Kulal <sumith1896@gmail.com>
|
| 401 |
+
Juha Remes <jremes@outlook.com>
|
| 402 |
+
Philippe Bouafia <philippe.bouafia@ensea.fr>
|
| 403 |
+
Peter Schmidt <peter@peterjs.com>
|
| 404 |
+
Jiaxing Liang <liangjiaxing57@gmail.com>
|
| 405 |
+
Lucas Jones <lucas@lucasjones.co.uk>
|
| 406 |
+
Gregory Ashton <gash789@gmail.com>
|
| 407 |
+
Jennifer White <jcrw122@googlemail.com>
|
| 408 |
+
Renato Orsino <renato.orsino@gmail.com>
|
| 409 |
+
Alistair Lynn <arplynn@gmail.com>
|
| 410 |
+
Govind Sahai <gsiitbhu@gmail.com>
|
| 411 |
+
Adam Bloomston <adam@glitterfram.es>
|
| 412 |
+
Kyle McDaniel <mcdanie5@illinois.edu>
|
| 413 |
+
Nguyen Truong Duy <truongduy134@yahoo.com>
|
| 414 |
+
Alex Lindsay <adlinds3@ncsu.edu>
|
| 415 |
+
Mathew Chong <mathewchong.dev@gmail.com>
|
| 416 |
+
Jason Siefken <siefkenj@gmail.com>
|
| 417 |
+
Gaurav Dhingra <gauravdhingra.gxyd@gmail.com>
|
| 418 |
+
Gao, Xiang <qasdfgtyuiop@gmail.com>
|
| 419 |
+
Kevin Ventullo <kevin.ventullo@gmail.com>
|
| 420 |
+
mao8 <thisisma08@gmail.com>
|
| 421 |
+
Isuru Fernando <isuruf@gmail.com>
|
| 422 |
+
Shivam Tyagi <shivam.tyagi.apm13@itbhu.ac.in>
|
| 423 |
+
Richard Otis <richard.otis@outlook.com>
|
| 424 |
+
Rich LaSota <rjlasota@gmail.com>
|
| 425 |
+
dustyrockpyle <dustyrockpyle@gmail.com>
|
| 426 |
+
Anton Akhmerov <anton.akhmerov@gmail.com>
|
| 427 |
+
Michael Zingale <michael.zingale@stonybrook.edu>
|
| 428 |
+
Chak-Pong Chung <chakpongchung@gmail.com>
|
| 429 |
+
David T <derDavidT@users.noreply.github.com>
|
| 430 |
+
Phil Ruffwind <rf@rufflewind.com>
|
| 431 |
+
Sebastian Koslowski <koslowski@kit.edu>
|
| 432 |
+
Kumar Krishna Agrawal <kumar.1994.14@gmail.com>
|
| 433 |
+
Dustin Gadal <Dustin.Gadal@gmail.com>
|
| 434 |
+
João Moura <operte@gmail.com>
|
| 435 |
+
Yu Kobayashi <yukoba@accelart.jp>
|
| 436 |
+
Shashank Kumar <shashank.kumar.apc13@iitbhu.ac.in>
|
| 437 |
+
Timothy Cyrus <tcyrus@users.noreply.github.com>
|
| 438 |
+
Devyani Kota <devyanikota@gmail.com>
|
| 439 |
+
Keval Shah <kevalshah_96@yahoo.co.in>
|
| 440 |
+
Dzhelil Rufat <drufat@caltech.edu>
|
| 441 |
+
Pastafarianist <mr.pastafarianist@gmail.com>
|
| 442 |
+
Sourav Singh <souravsingh@users.noreply.github.com>
|
| 443 |
+
Jacob Garber <jgarber1@ualberta.ca>
|
| 444 |
+
Vinay Singh <csvinay.d@gmail.com>
|
| 445 |
+
GolimarOurHero <metalera94@hotmail.com>
|
| 446 |
+
Prashant Tyagi <prashanttyagi221295@gmail.com>
|
| 447 |
+
Matthew Davis <davisml.md@gmail.com>
|
| 448 |
+
Tschijnmo TSCHAU <tschijnmotschau@gmail.com>
|
| 449 |
+
Alexander Bentkamp <bentkamp@gmail.com>
|
| 450 |
+
Jack Kemp <metaknightdrake-git@yahoo.co.uk>
|
| 451 |
+
Kshitij Saraogi <KshitijSaraogi@gmail.com>
|
| 452 |
+
Thomas Baruchel <baruchel@gmx.com>
|
| 453 |
+
Nicolás Guarín-Zapata <nicoguarin@gmail.com>
|
| 454 |
+
Jens Jørgen Mortensen <jj@smoerhul.dk>
|
| 455 |
+
Sampad Kumar Saha <sampadsaha5@gmail.com>
|
| 456 |
+
Eva Charlotte Mayer <eva-charlotte.mayer@posteo.de>
|
| 457 |
+
Laura Domine <temigo@gmx.com>
|
| 458 |
+
Justin Blythe <jblythe29@gmail.com>
|
| 459 |
+
Meghana Madhyastha <meghana.madhyastha@gmail.com>
|
| 460 |
+
Tanu Hari Dixit <tokencolour@gmail.com>
|
| 461 |
+
Shekhar Prasad Rajak <shekharrajak@live.com>
|
| 462 |
+
Aqnouch Mohammed <aqnouch.mohammed@gmail.com>
|
| 463 |
+
Arafat Dad Khan <arafat.da.khan@gmail.com>
|
| 464 |
+
Boris Atamanovskiy <shaomoron@gmail.com>
|
| 465 |
+
Sam Tygier <sam.tygier@hep.manchester.ac.uk>
|
| 466 |
+
Jai Luthra <me@jailuthra.in>
|
| 467 |
+
Guo Xingjian <Seeker1995@gmail.com>
|
| 468 |
+
Sandeep Veethu <sandeep.veethu@gmail.com>
|
| 469 |
+
Archit Verma <architv07@gmail.com>
|
| 470 |
+
Shubham Tibra <shubh.tibra@gmail.com>
|
| 471 |
+
Ashutosh Saboo <ashutosh.saboo96@gmail.com>
|
| 472 |
+
Michael S. Hansen <michael.hansen@nih.gov>
|
| 473 |
+
Anish Shah <shah.anish07@gmail.com>
|
| 474 |
+
Guillaume Jacquenot <guillaume.jacquenot@gmail.com>
|
| 475 |
+
Bhautik Mavani <mavanibhautik@gmail.com>
|
| 476 |
+
Michał Radwański <enedil.isildur@gmail.com>
|
| 477 |
+
Jerry Li <jerry@jerryli.ca>
|
| 478 |
+
Pablo Zubieta <pabloferz@yahoo.com.mx>
|
| 479 |
+
Shivam Agarwal <knowthyself2503@gmail.com>
|
| 480 |
+
Chaitanya Sai Alaparthi <achaitanyasai@gmail.com>
|
| 481 |
+
Arihant Parsoya <parsoyaarihant@gmail.com>
|
| 482 |
+
Ruslan Pisarev <rpisarev@cloudlinux.com>
|
| 483 |
+
Akash Trehan <akash.trehan123@gmail.com>
|
| 484 |
+
Nishant Nikhil <nishantiam@gmail.com>
|
| 485 |
+
Vladimir Poluhsin <vovapolu@gmail.com>
|
| 486 |
+
Akshay Nagar <awesomeay13@yahoo.com>
|
| 487 |
+
James Brandon Milam <jmilam343@gmail.com>
|
| 488 |
+
Abhinav Agarwal <abhinavagarwal1996@gmail.com>
|
| 489 |
+
Rishabh Daal <rishabhdaal@gmail.com>
|
| 490 |
+
Sanya Khurana <sanya@monica.in>
|
| 491 |
+
Aman Deep <amandeep1024@gmail.com>
|
| 492 |
+
Aravind Reddy <aravindreddy255@gmail.com>
|
| 493 |
+
Abhishek Verma <iamvermaabhishek@gmail.com>
|
| 494 |
+
Matthew Parnell <matt@parnmatt.co.uk>
|
| 495 |
+
Thomas Hickman <Thomas.Hickman42@gmail.com>
|
| 496 |
+
Akshay Siramdas <akshaysiramdas@gmail.com>
|
| 497 |
+
YiDing Jiang <yidinggjiangg@gmail.com>
|
| 498 |
+
Jatin Yadav <jatinyadav25@gmail.com>
|
| 499 |
+
Matthew Thomas <mnmt@users.noreply.github.com>
|
| 500 |
+
Rehas Sachdeva <aquannie@gmail.com>
|
| 501 |
+
Michael Mueller <michaeldmueller7@gmail.com>
|
| 502 |
+
Srajan Garg <srajan.garg@gmail.com>
|
| 503 |
+
Prabhjot Singh <prabhjot.nith@gmail.com>
|
| 504 |
+
Haruki Moriguchi <harukimoriguchi@gmail.com>
|
| 505 |
+
Tom Gijselinck <tomgijselinck@gmail.com>
|
| 506 |
+
Nitin Chaudhary <nitinmax1000@gmail.com>
|
| 507 |
+
Alex Argunov <sajkoooo@gmail.com>
|
| 508 |
+
Nathan Musoke <nathan.musoke@gmail.com>
|
| 509 |
+
Abhishek Garg <abhishekgarg119@gmail.com>
|
| 510 |
+
Dana Jacobsen <dana@acm.org>
|
| 511 |
+
Vasiliy Dommes <vasdommes@gmail.com>
|
| 512 |
+
Phillip Berndt <phillip.berndt@googlemail.com>
|
| 513 |
+
Haimo Zhang <zh.hammer.dev@gmail.com>
|
| 514 |
+
Anthony Scopatz <scopatz@gmail.com>
|
| 515 |
+
bluebrook <perl4logic@gmail.com>
|
| 516 |
+
Leonid Kovalev <leonidvkovalev@gmail.com>
|
| 517 |
+
Josh Burkart <jburkart@gmail.com>
|
| 518 |
+
Dimitra Konomi <t8130064@dias.aueb.gr>
|
| 519 |
+
Christina Zografou <t8130048@dias.aueb.gr>
|
| 520 |
+
Fiach Antaw <fiach.antaw+github@gmail.com>
|
| 521 |
+
Langston Barrett <langston.barrett@gmail.com>
|
| 522 |
+
Krit Karan <kritkaran.b13@iiits.in>
|
| 523 |
+
G. D. McBain <gdmcbain@protonmail.com>
|
| 524 |
+
Prempal Singh <prempal.42@gmail.com>
|
| 525 |
+
Gabriel Orisaka <orisaka@gmail.com>
|
| 526 |
+
Matthias Bussonnier <bussonniermatthias@gmail.com>
|
| 527 |
+
rahuldan <rahul02013@gmail.com>
|
| 528 |
+
Colin Marquardt <github@marquardt-home.de>
|
| 529 |
+
Andrew Taber <andrew.e.taber@gmail.com>
|
| 530 |
+
Yash Reddy <write2yashreddy@gmail.com>
|
| 531 |
+
Peter Stangl <peter.stangl@ph.tum.de>
|
| 532 |
+
elvis-sik <e.sikora@grad.ufsc.br>
|
| 533 |
+
Nikos Karagiannakis <nikoskaragiannakis@gmail.com>
|
| 534 |
+
Jainul Vaghasia <jainulvaghasia@gmail.com>
|
| 535 |
+
Dennis Meckel <meckel@datenschuppen.de>
|
| 536 |
+
Harshil Meena <harshil.7535@gmail.com>
|
| 537 |
+
Micky <mickydroch@gmail.com>
|
| 538 |
+
Nick Curtis <nicholas.curtis@uconn.edu>
|
| 539 |
+
Michele Zaffalon <michele.zaffalon@gmail.com>
|
| 540 |
+
Martha Giannoudovardi <maapxa@gmail.com>
|
| 541 |
+
Devang Kulshreshtha <devang.kulshreshtha.cse14@itbhu.ac.in>
|
| 542 |
+
Steph Papanik <spapanik21@gmail.com>
|
| 543 |
+
Mohammad Sadeq Dousti <msdousti@gmail.com>
|
| 544 |
+
Arif Ahmed <arif.ahmed.5.10.1995@gmail.com>
|
| 545 |
+
Abdullah Javed Nesar <abduljaved1994@gmail.com>
|
| 546 |
+
Lakshya Agrawal <zeeshan.lakshya@gmail.com>
|
| 547 |
+
shruti <shrutishrm512@gmail.com>
|
| 548 |
+
Rohit Rango <rohit.rango@gmail.com>
|
| 549 |
+
Hong Xu <hong@topbug.net>
|
| 550 |
+
Ivan Petuhov <ivan@ostrovok.ru>
|
| 551 |
+
Alsheh <alsheh@rpi.edu>
|
| 552 |
+
Marcel Stimberg <marcel.stimberg@ens.fr>
|
| 553 |
+
Alexey Pakhocmhik <cool.Bakov@yandex.ru>
|
| 554 |
+
Tommy Olofsson <tommy.olofsson.90@gmail.com>
|
| 555 |
+
Zulfikar <zulfikar97@gmail.com>
|
| 556 |
+
Blair Azzopardi <blairuk@gmail.com>
|
| 557 |
+
Danny Hermes <daniel.j.hermes@gmail.com>
|
| 558 |
+
Sergey Pestov <pestov-sa@yandex.ru>
|
| 559 |
+
Mohit Chandra <mohit.chandra@research.iiit.ac.in>
|
| 560 |
+
Karthik Chintapalli <karthik.chintapalli@students.iiit.ac.in>
|
| 561 |
+
Marcin Briański <marcin.brianski@student.uj.edu.pl>
|
| 562 |
+
andreo <andrey.torba@gmail.com>
|
| 563 |
+
Flamy Owl <flamyowl@protonmail.ch>
|
| 564 |
+
Yicong Guo <guoyicong100@gmail.com>
|
| 565 |
+
Varun Garg <varun.garg03@gmail.com>
|
| 566 |
+
Rishabh Madan <rishabhmadan96@gmail.com>
|
| 567 |
+
Aditya Kapoor <aditya.kapoor.apm12@itbhu.ac.in>
|
| 568 |
+
Karan Sharma <karan1276@gmail.com>
|
| 569 |
+
Vedant Rathore <vedantr1998@gmail.com>
|
| 570 |
+
Johan Blåbäck <johan_bluecreek@riseup.net>
|
| 571 |
+
Pranjal Tale <pranjaltale16@gmail.com>
|
| 572 |
+
Jason Tokayer <jason.tokayer@gmail.com>
|
| 573 |
+
Raghav Jajodia <jajodia.raghav@gmail.com>
|
| 574 |
+
Rajat Thakur <rajatthakur1997@gmail.com>
|
| 575 |
+
Dhruv Bhanushali <dhruv_b@live.com>
|
| 576 |
+
Anjul Kumar Tyagi <anjul.ten@gmail.com>
|
| 577 |
+
Barun Parruck <barun.parruck@gmail.com>
|
| 578 |
+
Bao Chau <chauquocbao0907@gmail.com>
|
| 579 |
+
Tanay Agrawal <tanay_agrawal@hotmail.com>
|
| 580 |
+
Ranjith Kumar <ranjith.dakshana2015@gmail.com>
|
| 581 |
+
Shikhar Makhija <shikharmakhija2@gmail.com>
|
| 582 |
+
Yathartha Joshi <yathartha32@gmail.com>
|
| 583 |
+
Valeriia Gladkova <valeriia.gladkova@gmail.com>
|
| 584 |
+
Sagar Bharadwaj <sagarbharadwaj50@gmail.com>
|
| 585 |
+
Daniel Mahler <dmahler@gmail.com>
|
| 586 |
+
Ka Yi <chua.kayi@yahoo.com.sg>
|
| 587 |
+
Rishat Iskhakov <iskhakov@frtk.ru>
|
| 588 |
+
Szymon Mieszczak <szymon.mieszczak@gmail.com>
|
| 589 |
+
Sachin Agarwal <sachinagarwal0499@gmail.com>
|
| 590 |
+
Priyank Patel <pspbot7@gmail.com>
|
| 591 |
+
Satya Prakash Dwibedi <akash581050@gmail.com>
|
| 592 |
+
tools4origins <tools4origins@gmail.com>
|
| 593 |
+
Nico Schlömer <nico.schloemer@gmail.com>
|
| 594 |
+
Fermi Paradox <FermiParadox@users.noreply.github.com>
|
| 595 |
+
Ekansh Purohit <purohit.e15@gmail.com>
|
| 596 |
+
Vedarth Sharma <vedarth.sharma@gmail.com>
|
| 597 |
+
Peeyush Kushwaha <peeyush.p97@gmail.com>
|
| 598 |
+
Jayjayyy <vfhsln8s3l4b87t4c3@byom.de>
|
| 599 |
+
Christopher J. Wright <cjwright4242gh@gmail.com>
|
| 600 |
+
Jakub Wilk <jwilk@jwilk.net>
|
| 601 |
+
Mauro Garavello <mauro.garavello@unimib.it>
|
| 602 |
+
Chris Tefer <ctefer@gmail.com>
|
| 603 |
+
Shikhar Jaiswal <jaiswalshikhar87@gmail.com>
|
| 604 |
+
Chiu-Hsiang Hsu <wdv4758h@gmail.com>
|
| 605 |
+
Carlos Cordoba <ccordoba12@gmail.com>
|
| 606 |
+
Fabian Ball <fabian.ball@kit.edu>
|
| 607 |
+
Yerniyaz <yerniyaz.nurgabylov@nu.edu.kz>
|
| 608 |
+
Christiano Anderson <canderson@riseup.net>
|
| 609 |
+
Robin Neatherway <robin.neatherway@gmail.com>
|
| 610 |
+
Thomas Hunt <thomashunt13@gmail.com>
|
| 611 |
+
Theodore Han <theodorehan@hotmail.com>
|
| 612 |
+
Duc-Minh Phan <alephvn@gmail.com>
|
| 613 |
+
Lejla Metohajrova <l.metohajrova@gmail.com>
|
| 614 |
+
Samyak Jain <samyak.jain2016a@vitstudent.ac.in>
|
| 615 |
+
Aditya Rohan <riyuzakiiitk@gmail.com>
|
| 616 |
+
Vincent Delecroix <vincent.delecroix@labri.fr>
|
| 617 |
+
Michael Sparapany <msparapa@purdue.edu>
|
| 618 |
+
Harsh Jain <harshjniitr@gmail.com>
|
| 619 |
+
Nathan Goldbaum <ngoldbau@illinois.edu>
|
| 620 |
+
latot <felipematas@yahoo.com>
|
| 621 |
+
Kenneth Lyons <ixjlyons@gmail.com>
|
| 622 |
+
Stan Schymanski <stan.schymanski@env.ethz.ch>
|
| 623 |
+
David Daly <david.daly12@kzoo.edu>
|
| 624 |
+
Ayush Shridhar <ayush.shridhar1999@gmail.com>
|
| 625 |
+
Javed Nissar <javednissar@gmail.com>
|
| 626 |
+
Jiri Kuncar <jiri.kuncar@gmail.com>
|
| 627 |
+
vedantc98 <vedantc98@gmail.com>
|
| 628 |
+
Rupesh Harode <rupeshharode@gmail.com>
|
| 629 |
+
Rob Zinkov <rob@zinkov.com>
|
| 630 |
+
James Harrop <ebc121@gmail.com>
|
| 631 |
+
James Taylor <user234683@tutanota.com>
|
| 632 |
+
Ishan Joshi <ishanaj98@gmail.com>
|
| 633 |
+
Marco Mancini <marco.mancini@obspm.fr>
|
| 634 |
+
Boris Ettinger <ettinger.boris@gmail.com>
|
| 635 |
+
Micah Fitch <micahscopes@gmail.com>
|
| 636 |
+
Daniel Wennberg <daniel.wennberg@gmail.com>
|
| 637 |
+
ylemkimon <ylemkimon@naver.com>
|
| 638 |
+
Akash Vaish <akash.9712@gmail.com>
|
| 639 |
+
Peter Enenkel <peter.enenkel+git@gmail.com>
|
| 640 |
+
Waldir Pimenta <waldyrious@gmail.com>
|
| 641 |
+
Jithin D. George <jithindgeorge93@gmail.com>
|
| 642 |
+
Lev Chelyadinov <leva181777@gmail.com>
|
| 643 |
+
Lucas Wiman <lucas.wiman@gmail.com>
|
| 644 |
+
Rhea Parekh <rheaparekh12@gmail.com>
|
| 645 |
+
James Cotton <peabody124@gmail.com>
|
| 646 |
+
Robert Pollak <robert.pollak@posteo.net>
|
| 647 |
+
anca-mc <anca-mc@users.noreply.github.com>
|
| 648 |
+
Sourav Ghosh <souravghosh2197@gmail.com>
|
| 649 |
+
Jonathan Allan <jjallan@users.noreply.github.com>
|
| 650 |
+
Nikhil Pappu <nkhlpappu@gmail.com>
|
| 651 |
+
Ethan Ward <etkewa@gmail.com>
|
| 652 |
+
Cezary Marczak <zeddq1@gmail.com>
|
| 653 |
+
dps7ud <dps7ud@virginia.edu>
|
| 654 |
+
Nilabja Bhattacharya <nilabja10201992@gmail.com>
|
| 655 |
+
Itay4 <31018228+Itay4@users.noreply.github.com>
|
| 656 |
+
Poom Chiarawongse <eight1911@gmail.com>
|
| 657 |
+
Yang Yang <wdscxsj@gmail.com>
|
| 658 |
+
Cavendish McKay <cmckay@tachycline.com>
|
| 659 |
+
Bradley Gannon <bradley.m.gannon@gmail.com>
|
| 660 |
+
B McG <bmcg0890@gmail.com>
|
| 661 |
+
Rob Drynkin <rob.drynkin@gmail.com>
|
| 662 |
+
Seth Ebner <murgrehk@gmail.com>
|
| 663 |
+
Akash Kundu <sk.sayakkundu1997@gmail.com>
|
| 664 |
+
Mark Jeromin <mark.jeromin@sysfrog.net>
|
| 665 |
+
Roberto Díaz Pérez <r.r.1994a@gmail.com>
|
| 666 |
+
Gleb Siroki <g.shiroki@gmail.com>
|
| 667 |
+
Segev Finer <segev208@gmail.com>
|
| 668 |
+
Alex Lubbock <code@alexlubbock.com>
|
| 669 |
+
Ayodeji Ige <ayodeji18@outlook.com>
|
| 670 |
+
Matthew Wardrop <matthew.wardrop@airbnb.com>
|
| 671 |
+
Hugo van Kemenade <hugovk@users.noreply.github.com>
|
| 672 |
+
Austin Palmer <ap4000@nyu.edu>
|
| 673 |
+
der-blaue-elefant <github@kklein.de>
|
| 674 |
+
Filip Gokstorp <filip@gokstorp.se>
|
| 675 |
+
Yuki Matsuda <yuki.matsuda.w@gmail.com>
|
| 676 |
+
Aaron Miller <acmiller273@gmail.com>
|
| 677 |
+
Salil Vishnu Kapur <salilvishnukapur@gmail.com>
|
| 678 |
+
Atharva Khare <khareatharva@gmail.com>
|
| 679 |
+
Shubham Maheshwari <rmaheshwari05@gmail.com>
|
| 680 |
+
Pavel Tkachenko <paveltkachenko@email.com>
|
| 681 |
+
Ashish Kumar Gaurav <ashishkg0022@gmail.com>
|
| 682 |
+
Rajeev Singh <rajs2010@gmail.com>
|
| 683 |
+
Keno Goertz <keno@goertz-berlin.com>
|
| 684 |
+
Lucas Gallindo <lgallindo@gmail.com>
|
| 685 |
+
Himanshu <hs80941@gmail.com>
|
| 686 |
+
David Menéndez Hurtado <david.menendez.hurtado@scilifelab.se>
|
| 687 |
+
Amit Manchanda <amitdelhi1995@gmail.com>
|
| 688 |
+
Rohit Jain <rohitjain3241@gmail.com>
|
| 689 |
+
Jonathan A. Gross <jarthurgross@gmail.com>
|
| 690 |
+
Unknown <kunda@scribus.net>
|
| 691 |
+
Sayan Goswami <Sayan98@users.noreply.github.com>
|
| 692 |
+
Subhash Saurabh <subhashsaurabh419@gmail.com>
|
| 693 |
+
Rastislav Rabatin <rastislav.rabatin@gmail.com>
|
| 694 |
+
Vishal <vishalg2235@gmail.com>
|
| 695 |
+
Jeremey Gluck <jeremygluck@yahoo.com>
|
| 696 |
+
Akshat Maheshwari <akshat14714@gmail.com>
|
| 697 |
+
symbolique <symbolique@users.noreply.github.com>
|
| 698 |
+
Saloni Jain <tosalonijain@gmail.com>
|
| 699 |
+
Arighna Chakrabarty <arighna.chakrabarty100@gmail.com>
|
| 700 |
+
Abhigyan Khaund <mail@abhigyan.xyz>
|
| 701 |
+
Jashanpreet Singh <jashansingh.4398@gmail.com>
|
| 702 |
+
Saurabh Agarwal <shourabh.agarwal@gmail.com>
|
| 703 |
+
luzpaz <luzpaz@users.noreply.github.com>
|
| 704 |
+
P. Sai Prasanth <psai.prasanth.min16@itbhu.ac.in>
|
| 705 |
+
Nirmal Sarswat <nirmalsarswat400@gmail.com>
|
| 706 |
+
Cristian Di Pietrantonio <cristiandipietrantonio@gmail.com>
|
| 707 |
+
Ravi charan <ravicharan.vsp@gmail.com>
|
| 708 |
+
Nityananda Gohain <nityanandagohain@gmail.com>
|
| 709 |
+
Cédric Travelletti <cedrictravelletti@gmail.com>
|
| 710 |
+
Nicholas Bollweg <nick.bollweg@gmail.com>
|
| 711 |
+
Himanshu Ladia <hladia199811@gmail.com>
|
| 712 |
+
Adwait Baokar <adwaitbaokar18@gmail.com>
|
| 713 |
+
Mihail Tarigradschi <m.tarigradschi@gmail.com>
|
| 714 |
+
Saketh <alurusaisaketh@gmail.com>
|
| 715 |
+
rushyam <rushyamsonu@gmail.com>
|
| 716 |
+
sfoo <sfoohei@gmail.com>
|
| 717 |
+
Rahil Hastu <rahilhastu@gmail.com>
|
| 718 |
+
Zach Raines <raineszm@gmail.com>
|
| 719 |
+
Sidhant Nagpal <sidhantnagpal97@gmail.com>
|
| 720 |
+
Gagandeep Singh <singh.23@iitj.ac.in>
|
| 721 |
+
Rishav Chakraborty <annonymousxyz@outlook.com>
|
| 722 |
+
Malkhan Singh <malkhansinghrathaur@gmail.com>
|
| 723 |
+
Joaquim Monserrat <qmonserrat@mailoo.org>
|
| 724 |
+
Mayank Singh <mayank.singh081997@gmail.com>
|
| 725 |
+
Rémy Léone <rleone@online.net>
|
| 726 |
+
Maxence Mayrand <35958639+maxencemayrand@users.noreply.github.com>
|
| 727 |
+
Nikoleta Glynatsi <GlynatsiNE@cardiff.ac.uk>
|
| 728 |
+
helo9 <helo9@users.noreply.github.com>
|
| 729 |
+
Ken Wakita <wakita@is.titech.ac.jp>
|
| 730 |
+
Carl Sandrock <carl.sandrock@up.ac.za>
|
| 731 |
+
Fredrik Eriksson <freeriks@student.chalmers.se>
|
| 732 |
+
Ian Swire <oversizedpenguin@gmail.com>
|
| 733 |
+
Bulat <daianovich@mail.ru>
|
| 734 |
+
Ehren Metcalfe <ehren.m@gmail.com>
|
| 735 |
+
Dmitry Savransky <dsavransky@gmail.com>
|
| 736 |
+
Kiyohito Yamazaki <kyamaz@openql.org>
|
| 737 |
+
Caley Finn <caleyreuben@gmail.com>
|
| 738 |
+
Zhi-Qiang Zhou <zzq_890709@hotmail.com>
|
| 739 |
+
Alexander Pozdneev <pozdneev@users.noreply.github.com>
|
| 740 |
+
Wes Turner <50891+westurner@users.noreply.github.com>
|
| 741 |
+
JMSS-Unknown <31131631+JMSS-Unknown@users.noreply.github.com>
|
| 742 |
+
Arshdeep Singh <singh.arshdeep1999@gmail.com>
|
| 743 |
+
cym1 <16437732+cym1@users.noreply.github.com>
|
| 744 |
+
Stewart Wadsworth <stewart.wadsworth@gmail.com>
|
| 745 |
+
Jared Lumpe <mjlumpe@gmail.com>
|
| 746 |
+
Avi Shrivastava <shrivastavaavi123@gmail.com>
|
| 747 |
+
ramvenkat98 <ramvenkat98@gmail.com>
|
| 748 |
+
Bilal Ahmed <b.ahmed0918@gmail.com>
|
| 749 |
+
Dimas Abreu Archanjo Dutra <dimasad@ufmg.br>
|
| 750 |
+
Yatna Verma <yatnavermaa@gmail.com>
|
| 751 |
+
S.Y. Lee <sylee957@gmail.com>
|
| 752 |
+
Miro Hrončok <miro@hroncok.cz>
|
| 753 |
+
Sudarshan Kamath <sudarshan.kamath97@gmail.com>
|
| 754 |
+
Ayushman Koul <ayushmankoul4570@gmail.com>
|
| 755 |
+
Robert Dougherty-Bliss <robert.w.bliss@gmail.com>
|
| 756 |
+
Andrey Grozin <A.G.Grozin@inp.nsk.su>
|
| 757 |
+
Bavish Kulur <bavishkulur@gmail.com>
|
| 758 |
+
Arun Singh <arunsin997@gmail.com>
|
| 759 |
+
sirnicolaf <43586954+sirnicolaf@users.noreply.github.com>
|
| 760 |
+
Zachariah Etienne <zachetie@gmail.com>
|
| 761 |
+
Prayush Dawda <35144226+iamprayush@users.noreply.github.com>
|
| 762 |
+
2torus <boris.ettinger@gmail.com>
|
| 763 |
+
Faisal Riyaz <faisalriyaz011@gmail.com>
|
| 764 |
+
Martin Roelfs <u0114255@kuleuven.be>
|
| 765 |
+
SirJohnFranklin <sirjfu@googlemail.com>
|
| 766 |
+
Anthony Sottile <asottile@umich.edu>
|
| 767 |
+
ViacheslavP <public.viacheslav@gmail.com>
|
| 768 |
+
Safiya03 <safiyanesar@gmail.com>
|
| 769 |
+
Alexander Dunlap <alexander.dunlap@gmail.com>
|
| 770 |
+
Rohit Sharma <31184621+rohitx007@users.noreply.github.com>
|
| 771 |
+
Jonathan Warner <warnerjon12@gmail.com>
|
| 772 |
+
Mohit Balwani <mohitbalwani.ict17@gmail.com>
|
| 773 |
+
Marduk Bolaños <mardukbp@mac.com>
|
| 774 |
+
amsuhane <ayushsuhane99@iitkgp.ac.in>
|
| 775 |
+
Matthias Geier <Matthias.Geier@gmail.com>
|
| 776 |
+
klaasvanaarsen <44929042+klaasvanaarsen@users.noreply.github.com>
|
| 777 |
+
Shubham Kumar Jha <skjha832@gmail.com>
|
| 778 |
+
rationa-kunal <kunalgk1999@gmail.com>
|
| 779 |
+
Animesh Sinha <animeshsinha1309@gmail.com>
|
| 780 |
+
Gaurang Tandon <1gaurangtandon@gmail.com>
|
| 781 |
+
Matthew Craven <clyring@users.noreply.github.com>
|
| 782 |
+
Daniel Ingram <ingramds@appstate.edu>
|
| 783 |
+
Jogi Miglani <jmig5776@gmail.com>
|
| 784 |
+
Takumasa Nakamura <n.takumasa@gmail.com>
|
| 785 |
+
Ritu Raj Singh <RituRajSingh878@gmail.com>
|
| 786 |
+
Rajiv Ranjan Singh <rajivperfect007@gmail.com>
|
| 787 |
+
Vera Lozhkina <veralozhkina@gmail.com>
|
| 788 |
+
adhoc-king <46354827+adhoc-king@users.noreply.github.com>
|
| 789 |
+
Mikel Rouco <mikel.mrm@gmail.com>
|
| 790 |
+
Oscar Gustafsson <oscar.gustafsson@gmail.com>
|
| 791 |
+
damianos <damianos@semmle.com>
|
| 792 |
+
Supreet Agrawal <supreet11agrawal@gmail.com>
|
| 793 |
+
shiksha11 <shiksharawat01@gmail.com>
|
| 794 |
+
Martin Ueding <dev@martin-ueding.de>
|
| 795 |
+
sharma-kunal <kunalsharma6914@gmail.com>
|
| 796 |
+
Divyanshu Thakur <divyanshu@iiitmanipur.ac.in>
|
| 797 |
+
Susumu Ishizuka <susumu.ishizuka@kii.com>
|
| 798 |
+
Samnan Rahee <namanush.rsr.16@gmail.com>
|
| 799 |
+
Fredrik Andersson <fredrik.andersson@fcc.chalmers.se>
|
| 800 |
+
Bhavya Srivastava <bhavya17037@iiitd.ac.in>
|
| 801 |
+
Alpesh Jamgade <alpeshjamgade21@gmail.com>
|
| 802 |
+
Shubham Abhang <shubhamabhang77@gmail.com>
|
| 803 |
+
Vishesh Mangla <manglavishesh64@gmail.com>
|
| 804 |
+
Nicko van Someren <nicko@nicko.org>
|
| 805 |
+
dandiez <47832466+dandiez@users.noreply.github.com>
|
| 806 |
+
Frédéric Chapoton <fchapoton2@gmail.com>
|
| 807 |
+
jhanwar <f2015463@pilani.bits-pilani.ac.in>
|
| 808 |
+
Noumbissi valere Gille Geovan <noumbissivalere@gmail.com>
|
| 809 |
+
Salmista-94 <alejandrogroso@hotmail.com>
|
| 810 |
+
Shivani Kohli <shivanikohli.09@gmail.com>
|
| 811 |
+
Parker Berry <parkereberry@gmail.com>
|
| 812 |
+
Pragyan Mehrotra <pragyan18168@iiitd.ac.in>
|
| 813 |
+
Nabanita Dash <dashnabanita@gmail.com>
|
| 814 |
+
Gaetano Guerriero <x.guerriero@tin.it>
|
| 815 |
+
Ankit Raj Pandey <pandeyan@grinnell.edu>
|
| 816 |
+
Ritesh Kumar <ritesh99rakesh@gmail.com>
|
| 817 |
+
kangzhiq <709563092@qq.com>
|
| 818 |
+
Jun Lin <junlin0604@gmail.com>
|
| 819 |
+
Petr Kungurtsev <corwinat@gmail.com>
|
| 820 |
+
Anway De <anway1756@gmail.com>
|
| 821 |
+
znxftw <vishnu2101@gmail.com>
|
| 822 |
+
Denis Ivanenko <ivanenko@ucu.edu.ua>
|
| 823 |
+
Orestis Vaggelis <orestisvaggelis@mail.com>
|
| 824 |
+
Nikhil Maan <nikhilmaan22@gmail.com>
|
| 825 |
+
Abhinav Anand <abhinav.anand2807@gmail.com>
|
| 826 |
+
Qingsha Shi <googol.sqs@gmail.com>
|
| 827 |
+
Juan Barbosa <js.barbosa10@uniandes.edu.co>
|
| 828 |
+
Prionti Nasir <pdn3628@rit.edu>
|
| 829 |
+
Bharat Raghunathan <bharatraghunthan9767@gmail.com>
|
| 830 |
+
arooshiverma <av22@iitbbs.ac.in>
|
| 831 |
+
Christoph Gohle <ctg@mpq.mpg.de>
|
| 832 |
+
Charalampos Tsiagkalis <ctsiagkalis@uth.gr>
|
| 833 |
+
Daniel Sears <highpost@users.noreply.github.com>
|
| 834 |
+
Megan Ly <megan.ly@learnosity.com>
|
| 835 |
+
Sean P. Cornelius <spcornelius@gmail.com>
|
| 836 |
+
Erik R. Gomez <gomez@kth.se>
|
| 837 |
+
Riccardo Magliocchetti <riccardo.magliocchetti@gmail.com>
|
| 838 |
+
Henry Metlov <genrih.metlov@gmail.com>
|
| 839 |
+
pekochun <hamburg_hamburger2000@yahoo.co.jp>
|
| 840 |
+
Bendik Samseth <b.samseth@gmail.com>
|
| 841 |
+
Vighnesh Shenoy <vighneshq@gmail.com>
|
| 842 |
+
Versus Void <versusvoid@gmail.com>
|
| 843 |
+
Denys Rybalka <rybalka.denis@gmail.com>
|
| 844 |
+
Mark Dickinson <dickinsm@gmail.com>
|
| 845 |
+
Rimi <rimibis@umich.edu>
|
| 846 |
+
rimibis <33387803+rimibis@users.noreply.github.com>
|
| 847 |
+
Steven Lee <stevenlee123@protonmail.com>
|
| 848 |
+
Gilles Schintgen <gschintgen@hambier.lu>
|
| 849 |
+
Abhi58 <abhijithbharadwaj58@gmail.com>
|
| 850 |
+
Tomasz Pytel <tompytel@gmail.com>
|
| 851 |
+
Aadit Kamat <aadit.k12@gmail.com>
|
| 852 |
+
Samesh <samesh.lakhotia@gmail.com>
|
| 853 |
+
Velibor Zeli <velibor@mech.kth.se>
|
| 854 |
+
Gabriel Bernardino <gabriel.bernardino@upf.edu>
|
| 855 |
+
Joseph Redfern <joseph@redfern.me>
|
| 856 |
+
Evelyn King <evelyn.cameron.king@gmail.com>
|
| 857 |
+
Miguel Marco <mmarco@unizar.es>
|
| 858 |
+
David Hagen <david@drhagen.com>
|
| 859 |
+
Hannah Kari <hannah.kari@marquette.edu>
|
| 860 |
+
Soniya Nayak <soniyanayak51@gmail.com>
|
| 861 |
+
Harsh Agarwal <hagarwal9200@gmail.com>
|
| 862 |
+
Enric Florit <efz1005@gmail.com>
|
| 863 |
+
Yogesh Mishra <ymishra013@gmail.com>
|
| 864 |
+
Denis Rykov <rykovd@gmail.com>
|
| 865 |
+
Ivan Tkachenko <me@ratijas.tk>
|
| 866 |
+
Kenneth Emeka Odoh <kenneth.odoh@gmail.com>
|
| 867 |
+
Stephan Seitz <stephan.seitz@fau.de>
|
| 868 |
+
Yeshwanth N <yeshsurya@gmail.com>
|
| 869 |
+
Oscar Gerardo Lazo Arjona <oscar.lazoarjona@physics.ox.ac.uk>
|
| 870 |
+
Srinivasa Arun Yeragudipati <ysarun1999@gmail.com>
|
| 871 |
+
Kirtan Mali <kirtanmali555@gmail.com>
|
| 872 |
+
TitanSnow <sweeto@live.cn>
|
| 873 |
+
Pengning Chao <8857165+PengningChao@users.noreply.github.com>
|
| 874 |
+
Louis Abraham <louis.abraham@yahoo.fr>
|
| 875 |
+
Morten Olsen Lysgaard <morten@lysgaard.no>
|
| 876 |
+
Akash Nagaraj (akasnaga) <akasnaga@cisco.com>
|
| 877 |
+
Akash Nagaraj <grassknoted@gmail.com>
|
| 878 |
+
Lauren Glattly <laurenglattly@gmail.com>
|
| 879 |
+
Hou-Rui <houruinus@gmail.com>
|
| 880 |
+
George Korepanov <gkorepanov.gk@gmail.com>
|
| 881 |
+
dranknight09 <cbhaavan@gmail.com>
|
| 882 |
+
aditisingh2362 <aditisingh2362@gmail.com>
|
| 883 |
+
Gina <Dr-G@users.noreply.github.com>
|
| 884 |
+
gregmedlock <gmedlo@gmail.com>
|
| 885 |
+
Georgios Giapitzakis Tzintanos <giorgosgiapis@mail.com>
|
| 886 |
+
Eric Wieser <wieser.eric@gmail.com>
|
| 887 |
+
Bradley Dowling <34559056+btdow@users.noreply.github.com>
|
| 888 |
+
Maria Marginean <33810762+mmargin@users.noreply.github.com>
|
| 889 |
+
Akash Agrawall <akash.wanted@gmail.com>
|
| 890 |
+
jgulian <josephdgulian@gmail.com>
|
| 891 |
+
Sourav Goyal <souravgl0@gmail.com>
|
| 892 |
+
Zlatan Vasović <zlatanvasovic@gmail.com>
|
| 893 |
+
Alex Meiburg <timeroot.alex@gmail.com>
|
| 894 |
+
Smit Lunagariya <smitlunagariya.mat18@itbhu.ac.in>
|
| 895 |
+
Naman Gera <namangera15@gmail.com>
|
| 896 |
+
Julien Palard <julien@palard.fr>
|
| 897 |
+
Dhruv Mendiratta <dhruvmendiratta6@gmail.com>
|
| 898 |
+
erdOne <36414270+erdOne@users.noreply.github.com>
|
| 899 |
+
risubaba <risubhjain1010@gmail.com>
|
| 900 |
+
abhinav28071999 <41710346+abhinav28071999@users.noreply.github.com>
|
| 901 |
+
Jisoo Song <jeesoo9595@snu.ac.kr>
|
| 902 |
+
Jaime R <38530589+Jaime02@users.noreply.github.com>
|
| 903 |
+
Vikrant Malik <vikrantmalik051@gmail.com>
|
| 904 |
+
Hardik Saini <43683678+Guardianofgotham@users.noreply.github.com>
|
| 905 |
+
Abhishek <uchiha@pop-os.localdomain>
|
| 906 |
+
Johannes Hartung <joha2@gmx.net>
|
| 907 |
+
Milan Jolly <milan.cs16@iitp.ac.in>
|
| 908 |
+
faizan2700 <syedfaizan824@gmail.com>
|
| 909 |
+
mohit <39158356+mohitacecode@users.noreply.github.com>
|
| 910 |
+
Mohit Gupta <mohitgupta@gmail.com>
|
| 911 |
+
Psycho-Pirate <prakharsaxena.civ18@iitbhu.ac.in>
|
| 912 |
+
Chanakya-Ekbote <ca10@iitbbs.ac.in>
|
| 913 |
+
Rashmi Shehana <rashmi.watagedara@syscolabs.com>
|
| 914 |
+
Jonty16117 <jonty@DESKTOP-J1O6ANP.localdomain>
|
| 915 |
+
Anubhav Gupta <anubhav.gupta.cse19@itbhu.ac.in>
|
| 916 |
+
Michal Grňo <m93a.cz@gmail.com>
|
| 917 |
+
vezeli <37907135+vezeli@users.noreply.github.com>
|
| 918 |
+
Tim Gates <tim.gates@iress.com>
|
| 919 |
+
Sandeep Murthy <smurthy@protonmail.ch>
|
| 920 |
+
Neil <mistersheik@gmail.com>
|
| 921 |
+
V1krant <46847915+V1krant@users.noreply.github.com>
|
| 922 |
+
alejandro <amartinhernan@gmail.com>
|
| 923 |
+
Riyan Dhiman <Riyandhiman14@gmail.com>
|
| 924 |
+
sbt4104 <sthorat661@gmail.com>
|
| 925 |
+
Seth Troisi <sethtroisi@google.com>
|
| 926 |
+
Bhaskar Gupta <guptabhanu1999@gmail.com>
|
| 927 |
+
Smit Gajjar <smitgajjar.gs@gmail.com>
|
| 928 |
+
rbl <rlee@grove.co>
|
| 929 |
+
Ilya Pchelintsev <ilya.pchelintsev@outlook.com>
|
| 930 |
+
Omar Wagih <o.wagih.ow@gmail.com>
|
| 931 |
+
prshnt19 <prashant.rawat216@gmail.com>
|
| 932 |
+
Johan Guzman <jguzm022@ucr.edu>
|
| 933 |
+
Vasileios Kalos <kalosbasileios@gmail.com>
|
| 934 |
+
BasileiosKal <61801875+BasileiosKal@users.noreply.github.com>
|
| 935 |
+
Shubham Thorat <37049710+sbt4104@users.noreply.github.com>
|
| 936 |
+
Arpan Chattopadhyay <f20180319@pilani.bits-pilani.ac.in>
|
| 937 |
+
Ashutosh Hathidara <ashutoshhathidara98@gmail.com>
|
| 938 |
+
Moses Paul R <iammosespaulr@gmail.com>
|
| 939 |
+
Saanidhya vats <saanidhyavats@gmail.com>
|
| 940 |
+
tnzl <you@example.com>
|
| 941 |
+
Vatsal Srivastava <alstav.trivas.sava@gmail.com>
|
| 942 |
+
Jean-Luc Herren <jlh@gmx.ch>
|
| 943 |
+
Dhruv Kothari <dhruvkothari22@gmail.com>
|
| 944 |
+
seadavis <45022599+seadavis@users.noreply.github.com>
|
| 945 |
+
kamimura <kamimura@live.jp>
|
| 946 |
+
slacker404 <pchantza@gmail.com>
|
| 947 |
+
Jaime Resano <gemailpersonal02@gmail.com>
|
| 948 |
+
Ebrahim Byagowi <ebrahim@gnu.org>
|
| 949 |
+
wuyudi <wuyudi119@163.com>
|
| 950 |
+
Akira Kyle <ak@akirakyle.com>
|
| 951 |
+
Calvin Jay Ross <calvinjayross@gmail.com>
|
| 952 |
+
Martin Thoma <info@martin-thoma.de>
|
| 953 |
+
Thomas A Caswell <tcaswell@gmail.com>
|
| 954 |
+
Lagaras Stelios <stel.lag@hotmail.com>
|
| 955 |
+
Jerry James <loganjerry@gmail.com>
|
| 956 |
+
Jan Kruse <janckruse@t-online.de>
|
| 957 |
+
Nathan Taylor <pecan.pine@gmail.com>
|
| 958 |
+
Vaishnav Damani <vaishnavdamani3496@gmail.com>
|
| 959 |
+
Mohit Shah <mohitshah3111999@gmail.com>
|
| 960 |
+
Mathias Louboutin <mathias.louboutin@gmail.com>
|
| 961 |
+
Marijan Smetko <marijansmetko123@gmail.com>
|
| 962 |
+
Dave Witte Morris <Dave.Morris@uleth.ca>
|
| 963 |
+
soumi7 <soumibardhan10@gmail.com>
|
| 964 |
+
Zhongshi <zj495@nyu.edu>
|
| 965 |
+
Wes Galbraith <galbwe92@gmail.com>
|
| 966 |
+
KaustubhDamania <kaustubh.damania@gmail.com>
|
| 967 |
+
w495 <w495@yandex-team.ru>
|
| 968 |
+
Akhil Rajput <akh1lrjput@gmail.com>
|
| 969 |
+
Markus Mohrhard <markus.mohrhard@googlemail.com>
|
| 970 |
+
Benjamin Wolba <mail@benjaminwolba.com>
|
| 971 |
+
彭于斌 <1931127624@qq.com>
|
| 972 |
+
Rudr Tiwari <rudrtiwari@gmail.com>
|
| 973 |
+
Aaryan Dewan <aaryandewan@yahoo.com>
|
| 974 |
+
Benedikt Placke <benedikt.placke@outlook.com>
|
| 975 |
+
Sneha Goddu <s.goddu@wustl.edu>
|
| 976 |
+
goddus <39923708+goddus@users.noreply.github.com>
|
| 977 |
+
Shivang Dubey <shivangdubey8@gmail.com>
|
| 978 |
+
Michael Greminger <michael.greminger@gmail.com>
|
| 979 |
+
Peter Cock <p.j.a.cock@googlemail.com>
|
| 980 |
+
Willem Melching <willem.melching@gmail.com>
|
| 981 |
+
Elias Basler <e.e.basler@protonmail.com>
|
| 982 |
+
Brandon David <brandon.david@zoho.com>
|
| 983 |
+
Abhay_Dhiman <abhaysdhimans@gmail.com>
|
| 984 |
+
Tasha Kim <jae_young_kim@brown.edu>
|
| 985 |
+
Ayush Malik <ayushmalik779@gmail.com>
|
| 986 |
+
Devesh Sawant <devesh47cool@gmail.com>
|
| 987 |
+
Wolfgang Stöcher <wolfgang@stoecher.com>
|
| 988 |
+
Sudeep Sidhu <sudeepmanilsidhu@gmail.com>
|
| 989 |
+
foice <foice.news@gmail.com>
|
| 990 |
+
Ben Payne <ben.is.located@gmail.com>
|
| 991 |
+
Muskan Kumar <31043527+muskanvk@users.noreply.github.com>
|
| 992 |
+
noam simcha finkelstein <noam.finkelstein@protonmail.com>
|
| 993 |
+
Garrett Folbe <gmfolbe@yahoo.com>
|
| 994 |
+
Islam Mansour <is3mansour@gmail.com>
|
| 995 |
+
Sayandip Halder <sayandiph4@gmail.com>
|
| 996 |
+
Shubham Agrawal <shubham.ag6845@gmail.com>
|
| 997 |
+
numbermaniac <5206120+numbermaniac@users.noreply.github.com>
|
| 998 |
+
Sakirul Alam <binarysakir@gmail.com>
|
| 999 |
+
Mohammed Bilal <r.mohammedbilal@gmail.com>
|
| 1000 |
+
Chris du Plessis <christopherjonduplessis@gmail.com>
|
| 1001 |
+
Coder-RG <rgoel1999@gmail.com>
|
| 1002 |
+
Ansh Mishra <anshmishra471@gmail.com>
|
| 1003 |
+
Alex Malins <github@alexmalins.com>
|
| 1004 |
+
Lorenzo Contento <lorenzo.contento@gmail.com>
|
| 1005 |
+
Naveen Sai <naveensaisreenivas@gmail.com>
|
| 1006 |
+
Shital Mule <shitalmule04@gmail.com>
|
| 1007 |
+
Amanda Dsouza <meezamanda@yahoo.com>
|
| 1008 |
+
Nijso Beishuizen <nijso@koolmees.numerically-related.com>
|
| 1009 |
+
Harry Zheng <harry@harryzheng.com>
|
| 1010 |
+
Felix Yan <felixonmars@archlinux.org>
|
| 1011 |
+
Constantin Mateescu <costica1234@me.com>
|
| 1012 |
+
Eva Tiwari <eva.tiwari@gmail.com>
|
| 1013 |
+
Aditya Kumar Sinha <adityakumar113141@gmail.com>
|
| 1014 |
+
Soumi Bardhan <51290447+Soumi7@users.noreply.github.com>
|
| 1015 |
+
Kaustubh Chaudhari <ckaustubhm06@gmail.com>
|
| 1016 |
+
Kristian Brünn <hello@kristianbrunn.com>
|
| 1017 |
+
Neel Gorasiya <mgorasiya1974@gmail.com>
|
| 1018 |
+
Akshat Sood <68052998+akshatsood2249@users.noreply.github.com>
|
| 1019 |
+
Jose M. Gomez <chemoki@gmail.com>
|
| 1020 |
+
Stefan Petrea <stefan@garage-coding.com>
|
| 1021 |
+
Praveen Sahu <povinsahu@gmail.com>
|
| 1022 |
+
Mark Bell <mark00bell@googlemail.com>
|
| 1023 |
+
AlexCQY <alex_chua@u.nus.edu>
|
| 1024 |
+
Fabian Froehlich <fabian@schaluck.com>
|
| 1025 |
+
Nikhil Gopalam <gopalamn@umich.edu>
|
| 1026 |
+
Kartik Sethi <kartiks31416@gmail.com>
|
| 1027 |
+
Muhammed Abdul Quadir Owais <quadirowais200@gmail.com>
|
| 1028 |
+
Harshit Yadav <harshityadav2k@gmail.com>
|
| 1029 |
+
Sidharth Mundhra <sidharthmundhra16@gmail.com>
|
| 1030 |
+
Suryam Arnav Kalra <suryamkalra35@gmail.com>
|
| 1031 |
+
Prince Gupta <codemastercpp@gmail.com>
|
| 1032 |
+
Kunal Singh <ksingh19136@gmail.com>
|
| 1033 |
+
Mayank Raj <mayank_1901cs35@iitp.ac.in>
|
| 1034 |
+
Achal Jain <2achaljain@gmail.com>
|
| 1035 |
+
Mario Maio <mario.maio@aruba.it>
|
| 1036 |
+
Aaron Stiff <69512633+AaronStiff@users.noreply.github.com>
|
| 1037 |
+
Wyatt Peak <wyattpeak@gmail.com>
|
| 1038 |
+
Bhaskar Joshi <bhaskar.joshi@research.iiit.ac.in>
|
| 1039 |
+
Aditya Jindal <jaditya8889@gmail.com>
|
| 1040 |
+
Vaibhav Bhat <vaibhav.bhat2097@gmail.com>
|
| 1041 |
+
Priyansh Rathi <techiepriyansh@gmail.com>
|
| 1042 |
+
Saket Kumar Singh <saketkumar1202@gmail.com>
|
| 1043 |
+
Yukai Chou <muzimuzhi@gmail.com>
|
| 1044 |
+
Qijia Liu <liumeo@pku.edu.cn>
|
| 1045 |
+
Paul Mandel <paulmandel@google.com>
|
| 1046 |
+
Nisarg Chaudhari <54911392+Nisarg-Chaudhari@users.noreply.github.com>
|
| 1047 |
+
Dominik Stańczak <stanczakdominik@gmail.com>
|
| 1048 |
+
Rodrigo Luger <rodluger@gmail.com>
|
| 1049 |
+
Marco Antônio Habitzreuter <mahabitzreuter@gmail.com>
|
| 1050 |
+
Ayush Bisht <bisht.ayush2001@gmail.com>
|
| 1051 |
+
Akshansh Bhatt <akshansh@tuta.io>
|
| 1052 |
+
Brandon T. Willard <brandonwillard@users.noreply.github.com>
|
| 1053 |
+
Thomas Aarholt <thomasaarholt@gmail.com>
|
| 1054 |
+
Hiren Chalodiya <hirenchalodiya99@gmail.com>
|
| 1055 |
+
Roland Dixon <rols121@gmail.com>
|
| 1056 |
+
dimasvq <dimas.vq.2020@bristol.ac.uk>
|
| 1057 |
+
Sagar231 <sagarfeb298@gmail.com>
|
| 1058 |
+
Michael Chu <michael02chu@gmail.com>
|
| 1059 |
+
Abby Ng <abigailjng@gmail.com>
|
| 1060 |
+
Angad Sandhu <55819847+angadsinghsandhu@users.noreply.github.com>
|
| 1061 |
+
Alexander Cockburn <alexander_cockburn12@hotmail.com>
|
| 1062 |
+
Yaser AlOsh <yaseralosh@outlook.com>
|
| 1063 |
+
Davide Sandonà <sandona.davide@gmail.com>
|
| 1064 |
+
Jonathan Gutow <gutow@uwosh.edu>
|
| 1065 |
+
Nihir Agarwal <f20180701@pilani.bits-pilani.ac.in>
|
| 1066 |
+
Lee Johnston <lee.johnston.100@gmail.com>
|
| 1067 |
+
Zach Carmichael <20629897+craymichael@users.noreply.github.com>
|
| 1068 |
+
Vijairam Ganesh Moorthy <vijairamg@gmail.com>
|
| 1069 |
+
Hanspeter Schmid <hanspeter.schmid@fhnw.ch>
|
| 1070 |
+
Ben Oostendorp <oostben@umich.edu>
|
| 1071 |
+
Nikita <nikita.student.cse19@itbhu.ac.in>
|
| 1072 |
+
Aman <amanmourya295@gmail.com>
|
| 1073 |
+
Shashank KS <shashankks0987@gmail.com>
|
| 1074 |
+
Aman Sharma <amansharma110603@gmail.com>
|
| 1075 |
+
Anup Parikh <parikhanupk@gmail.com>
|
| 1076 |
+
Lucy Mountain <lucymountain1@icloud.com>
|
| 1077 |
+
Miguel Torres Costa <miguelptcosta1995@gmail.com>
|
| 1078 |
+
Rikard Nordgren <rikard.nordgren@farmaci.uu.se>
|
| 1079 |
+
Arun sanganal <74652697+ArunSanganal@users.noreply.github.com>
|
| 1080 |
+
Kamlesh Joshi <72374645+kamleshjoshi8102@users.noreply.github.com>
|
| 1081 |
+
Joseph Rance <56409230+Joseph-Rance@users.noreply.github.com>
|
| 1082 |
+
Huangduirong <huangduirong@huawei.com>
|
| 1083 |
+
Nils Schulte <47043622+Schnilz@users.noreply.github.com>
|
| 1084 |
+
Matt Bogosian <matt@bogosian.net>
|
| 1085 |
+
Elisha Hollander <just4now666666@gmail.com>
|
| 1086 |
+
Aditya Ravuri <infprobscix@gmail.com>
|
| 1087 |
+
Mamidi Ratna Praneeth <praneethratna@gmail.com>
|
| 1088 |
+
Jeffrey Ryan <jeffaryan7@gmail.com>
|
| 1089 |
+
Jonathan Daniel <36337649+jond01@users.noreply.github.com>
|
| 1090 |
+
Robin Richard <raisin@ecomail.fr>
|
| 1091 |
+
Gautam Menghani <gum3ng@protonmail.com>
|
| 1092 |
+
Remco de Boer <29308176+redeboer@users.noreply.github.com>
|
| 1093 |
+
Sebastian East <sebastianeast@ymail.com>
|
| 1094 |
+
Evani Balasubramanyam <balasubramanyam.evani@gmail.com>
|
| 1095 |
+
Rahil Parikh <r.parikh@somaiya.edu>
|
| 1096 |
+
Jason Ross <jasonross1024@gmail.com>
|
| 1097 |
+
Joannah Nanjekye <joannah.nanjekye@ibm.com>
|
| 1098 |
+
Ayush Kumar <ayushk7102@gmail.com>
|
| 1099 |
+
Kshitij <kshitijparwani.mat18@itbhu.ac.in>
|
| 1100 |
+
Daniel Hyams <dhyams@gmail.com>
|
| 1101 |
+
alijosephine <alijosephine@gmail.com>
|
| 1102 |
+
Matthias Köppe <mkoeppe@math.ucdavis.edu>
|
| 1103 |
+
mohajain <mohajain99@gmail.com>
|
| 1104 |
+
Anibal M. Medina-Mardones <ammedmar@gmail.com>
|
| 1105 |
+
Travis Ens <ens.travis@gmail.com>
|
| 1106 |
+
Evgenia Karunus <lakesare@gmail.com>
|
| 1107 |
+
Risiraj Dey <risirajdey@gmail.com>
|
| 1108 |
+
lastcodestanding <rohang71604@gmail.com>
|
| 1109 |
+
Andrey Lekar <andrey_lekar@adoriasoft.com>
|
| 1110 |
+
Abbas Mohammed <42001049+iam-abbas@users.noreply.github.com>
|
| 1111 |
+
Anutosh Bhat <andersonbhat491@gmail.com>
|
| 1112 |
+
Steve Kieffer <sk@skieffer.info>
|
| 1113 |
+
Paul Spiering <paul@spiering.org>
|
| 1114 |
+
Pieter Gijsbers <p.gijsbers@tue.nl>
|
| 1115 |
+
Wang Ran (汪然) <wangr@smail.nju.edu.cn>
|
| 1116 |
+
naelsondouglas <naelson17@gmail.com>
|
| 1117 |
+
Aman Thakur <thakuraman22july@gmail.com>
|
| 1118 |
+
S. Hanko <suzy.hanko@gmail.com>
|
| 1119 |
+
Dennis Sweeney <sweeney.427@osu.edu>
|
| 1120 |
+
Gurpartap Singh <dhaliwal.gurpartap@gmail.com>
|
| 1121 |
+
Hampus Malmberg <hampus.malmberg88@gmail.com>
|
| 1122 |
+
scimax <max.kellermeier@hotmail.de>
|
| 1123 |
+
Nikhil Date <nikhil.s.date@gmail.com>
|
| 1124 |
+
Kuldeep Borkar Jr <kuldeepborkarjr765@gmail.com>
|
| 1125 |
+
AkuBrain <76952313+Franck2111@users.noreply.github.com>
|
| 1126 |
+
Leo Battle <leowbattle@gmail.com>
|
| 1127 |
+
Advait Pote <apote2050@gmail.com>
|
| 1128 |
+
Anurag Bhat <bhat.1@iitj.ac.in>
|
| 1129 |
+
Jeremy Monat <jemonat@calalum.org>
|
| 1130 |
+
Diane Tchuindjo <dtchuindjo@gmail.com>
|
| 1131 |
+
Tom Fryers <61272761+TomFryers@users.noreply.github.com>
|
| 1132 |
+
Zouhair <zouhair.mahboubi@gmail.com>
|
| 1133 |
+
zzj <29055749+zjzh@users.noreply.github.com>
|
| 1134 |
+
shubhayu09 <guptashubhayu601@gmail.com>
|
| 1135 |
+
Siddhant Jain <siddhantashoknagar@gmail.com>
|
| 1136 |
+
Tirthankar Mazumder <63574588+wermos@users.noreply.github.com>
|
| 1137 |
+
Sumit Kumar <mr.sumitkrr@gmail.com>
|
| 1138 |
+
Shivam Sagar <technoshivam12@gmail.com>
|
| 1139 |
+
Gaurav Jain <gjain369@gmail.com>
|
| 1140 |
+
Andrii Oriekhov <andriyorehov@gmail.com>
|
| 1141 |
+
Luis Talavera <luisfertalavera15@gmail.com>
|
| 1142 |
+
Arie Bovenberg <a.c.bovenberg@gmail.com>
|
| 1143 |
+
Carson McManus <carson.mcmanus1@gmail.com>
|
| 1144 |
+
Jack Schmidt <1107865+jackschmidt@users.noreply.github.com>
|
| 1145 |
+
Riley Britten <nrb1324@hotmail.com>
|
| 1146 |
+
Georges Khaznadar <georgesk@debian.org>
|
| 1147 |
+
Donald Wilson <donwilson1029@gmail.com>
|
| 1148 |
+
Timo Stienstra <timostienstra00@gmail.com>
|
| 1149 |
+
dispasha <dispasha@users.noreply.github.com>
|
| 1150 |
+
Saksham Alok <sakshamalok13@gmail.com>
|
| 1151 |
+
Varenyam Bhardwaj <varenyambhardwaj123@gmail.com>
|
| 1152 |
+
oittaa <8972248+oittaa@users.noreply.github.com>
|
| 1153 |
+
Omkaar <79257339+Pysics@users.noreply.github.com>
|
| 1154 |
+
Islem BOUZENIA <fi_bouzenia@esi.dz>
|
| 1155 |
+
extraymond <extraymond@gmail.com>
|
| 1156 |
+
Alexander Behrens <alex.git@gmx.net>
|
| 1157 |
+
user202729 <25191436+user202729@users.noreply.github.com>
|
| 1158 |
+
Pieter Eendebak <pieter.eendebak@gmail.com>
|
| 1159 |
+
Zaz Brown <zazbrown@zazbrown.com>
|
| 1160 |
+
ritikBhandari <ritikbhandari68@gmail.com>
|
| 1161 |
+
viocha <66580331+viocha@users.noreply.github.com>
|
| 1162 |
+
Arthur Ryman <arthur.ryman@gmail.com>
|
| 1163 |
+
Xiang Wu <hsiangwu@fb.com>
|
| 1164 |
+
tttc3 <T.Coxon2@lboro.ac.uk>
|
| 1165 |
+
Seth Poulsen <poulsenseth@yahoo.com>
|
| 1166 |
+
cocolato <haiizhu@outlook.com>
|
| 1167 |
+
Anton Golovanov <agolovanov256@gmail.com>
|
| 1168 |
+
Gareth Ma <grhkm21@gmail.com>
|
| 1169 |
+
Clément M.T. Robert <cr52@protonmail.com>
|
| 1170 |
+
Glenn Horton-Smith <glenn.hortonsmith@gmail.com>
|
| 1171 |
+
Karan <grgkaran03@gmail.com>
|
| 1172 |
+
Stefan Behnle <84378403+behnle@users.noreply.github.com>
|
| 1173 |
+
Shreyash Mishra <72146041+Shreyash-cyber@users.noreply.github.com>
|
| 1174 |
+
Arthur Milchior <arthur@milchior.fr>
|
| 1175 |
+
NotWearingPants <26556598+NotWearingPants@users.noreply.github.com>
|
| 1176 |
+
Ishan Pandhare <ishan9096137017@gmail.com>
|
| 1177 |
+
Carlos García Montoro <TrilceAC@gmail.com>
|
| 1178 |
+
Parcly Taxel <reddeloostw@gmail.com>
|
| 1179 |
+
Saicharan <saicharanhahaha@gmail.com>
|
| 1180 |
+
Kunal Sheth <kunal@kunalsheth.info>
|
| 1181 |
+
Biswadeep Purkayastha <98874428+metabiswadeep@users.noreply.github.com>
|
| 1182 |
+
Jyn Spring 琴春 <me@vx.st>
|
| 1183 |
+
Phil LeMaitre <phil_lemaitre@live.ca>
|
| 1184 |
+
Chris Kerr <chris.kerr@mykolab.ch>
|
| 1185 |
+
José Senart <jose.senart@gmail.com>
|
| 1186 |
+
Uwe L. Korn <uwelk@xhochy.com>
|
| 1187 |
+
ForeverHaibara <69423537+ForeverHaibara@users.noreply.github.com>
|
| 1188 |
+
Yves Tumushimire <yvestumushimire@gmail.com>
|
| 1189 |
+
wookie184 <wookie1840@gmail.com>
|
| 1190 |
+
Costor <pcs2009@web.de>
|
| 1191 |
+
Klaus Rettinghaus <klaus.rettinghaus@enote.com>
|
| 1192 |
+
Sam Brockie <sambrockie@icloud.com>
|
| 1193 |
+
Abhishek Patidar <1e9abhi1e10@gmail.com>
|
| 1194 |
+
Eric Demer <demer@mailbox.org>
|
| 1195 |
+
Pontus von Brömssen <pontus.vonbromssen+github@gmail.com>
|
| 1196 |
+
Victor Immanuel <chrollolucilfer1402@gmail.com>
|
| 1197 |
+
Evandro Bernardes <evbernardes@gmail.com>
|
| 1198 |
+
Michele Ceccacci <michelececcacci1@gmail.com>
|
| 1199 |
+
Ayush Aryan <ayush.aryan71@gmail.com>
|
| 1200 |
+
Kishore Gopalakrishnan <kishore96@gmail.com>
|
| 1201 |
+
Jan-Philipp Hoffmann <sonntagsgesicht@icloud.com>
|
| 1202 |
+
Daiki Takahashi <haru.td@gmail.com>
|
| 1203 |
+
Sayan Mitra <ee18b156@smail.iitm.ac.in>
|
| 1204 |
+
Aman Kumar Shukla <theprofessionalaman@gmail.com>
|
| 1205 |
+
Zoufiné Lauer-Baré <raszoufine@gmail.com>
|
| 1206 |
+
Charles Harris <erdos4d@gmail.com>
|
| 1207 |
+
Tejaswini Sanapathi <sastejaswini2002@gmail.com>
|
| 1208 |
+
Devansh <be19b002@smail.iitm.ac.in>
|
| 1209 |
+
Aaron Gokaslan <aaronGokaslan@gmail.com>
|
| 1210 |
+
Daan Koning (he/him) <daanolivierkoning@gmail.com>
|
| 1211 |
+
Steven Burns <royalstream@hotmail.com>
|
| 1212 |
+
Jay Patankar <patankarjays@gmail.com>
|
| 1213 |
+
Vivek Soni <sonisheela1977@gmail.com>
|
| 1214 |
+
Le Cong Minh Hieu <hieu.lecongminh@gmail.com>
|
| 1215 |
+
Sam Ritchie <sam@mentat.org>
|
| 1216 |
+
Maciej Skórski <maciej.skorski@gmail.com>
|
| 1217 |
+
Tilo Reneau-Cardoso <tiloreneau@gmail.com>
|
| 1218 |
+
Laurence Warne <laurencewarne@gmail.com>
|
| 1219 |
+
Lukas Molleman <Lukas.Molleman@gmail.com>
|
| 1220 |
+
Konstantinos Riganas <kostasriganas24@gmail.com>
|
| 1221 |
+
Grace Su <grace.duansu@gmail.com>
|
| 1222 |
+
Pedro Rosa <pedro_sxbr@usp.br>
|
| 1223 |
+
Abhinav Cillanki <abhinavcillanki@kgpian.iitkgp.ac.in>
|
| 1224 |
+
Baiyuan Qiu <1061688677@qq.com>
|
| 1225 |
+
Liwei Cai <cai.lw123@gmail.com>
|
| 1226 |
+
Daniel Weindl <daniel.weindl@helmholtz-muenchen.de>
|
| 1227 |
+
Isidora Araya <iarayaday@gmail.com>
|
| 1228 |
+
Seb Tiburzio <sebtiburzio@gmail.com>
|
| 1229 |
+
Victory Omole <vtomole2@gmail.com>
|
| 1230 |
+
Abhishek Chaudhary <ac5003@columbia.edu>
|
| 1231 |
+
Alexander Zhura <nice.zhura@list.ru>
|
| 1232 |
+
Shuai Zhou <shuaivzhou@berkeley.edu>
|
| 1233 |
+
Martin Manns <mmanns@gmx.net>
|
| 1234 |
+
John Möller <john.moller@outlook.com>
|
| 1235 |
+
zzc <1378113190@qq.com>
|
| 1236 |
+
Pablo Galindo Salgado <pablogsal@gmail.com>
|
| 1237 |
+
Johannes Kasimir <johannes.kasimir@math.lu.se>
|
| 1238 |
+
Theodore Dias <theodore.dias@hotmail.co.uk>
|
| 1239 |
+
Kaustubh <90597818+kaustubh-765@users.noreply.github.com>
|
| 1240 |
+
Idan Pazi <idan.kp@gmail.com>
|
| 1241 |
+
Bobby Palmer <bobbyp@umich.edu>
|
| 1242 |
+
Saikat Das <saikatdchhe@gmail.com>
|
| 1243 |
+
Suman mondal <smondal.qwerty@gmail.com>
|
| 1244 |
+
Taylan Sahin <info@taylansahin.net>
|
| 1245 |
+
Fabio Luporini <fabio@devitocodes.com>
|
| 1246 |
+
Oriel Malihi <orielmalihi1@gmail.com>
|
| 1247 |
+
Geetika Vadali <geetika.vadali4@gmail.com>
|
| 1248 |
+
Matthias Rettl <matthias.rettl@stud.unileoben.ac.at>
|
| 1249 |
+
Mikhail Remnev <maremnev@gmail.com>
|
| 1250 |
+
philwillnyc <56197213+philwillnyc@users.noreply.github.com>
|
| 1251 |
+
Raphael Lehner <raphael.lehner@gmail.com>
|
| 1252 |
+
Harry Mountain <harrymountain1@icloud.com>
|
| 1253 |
+
Bhavik Sachdev <b.sachdev1904@gmail.com>
|
| 1254 |
+
袁野 (Yuan Ye) <yuanyelele@tutanota.com>
|
| 1255 |
+
fazledyn-or <ataf@openrefactory.com>
|
| 1256 |
+
mohammedouahman <simofun85@gmail.com>
|
| 1257 |
+
K. Kraus <laqueray@googlemail.com>
|
| 1258 |
+
Zac Hatfield-Dodds <zac.hatfield.dodds@gmail.com>
|
| 1259 |
+
platypus <platypus.computerchip@gmail.com>
|
| 1260 |
+
codecruisader <nnisarg55@gmail.com>
|
| 1261 |
+
James Whitehead <whiteheadj@gmail.com>
|
| 1262 |
+
atharvParlikar <atharvparlikar@gmail.com>
|
| 1263 |
+
Ivan Petukhov <satels@gmail.com>
|
| 1264 |
+
Augusto Borges <borges.augustoar@gmail.com>
|
| 1265 |
+
Han Wei Ang <ang.h.w@u.nus.edu>
|
| 1266 |
+
Congxu Yang <u7189828@anu.edu.au>
|
| 1267 |
+
Saicharan <62512681+saicharan2804@users.noreply.github.com>
|
| 1268 |
+
Arnab Nandi <arnabnandi2002@gmail.com>
|
| 1269 |
+
Harrison Oates <48871176+HarrisonOates@users.noreply.github.com>
|
| 1270 |
+
Corey Cerovsek <corey@cerovsek.com>
|
| 1271 |
+
Harsh Kasat <hkasat@waymore.io>
|
| 1272 |
+
omahs <73983677+omahs@users.noreply.github.com>
|
| 1273 |
+
Pascal Gitz <pascal.gitz@hotmail.ch>
|
| 1274 |
+
Ravindu-Hirimuthugoda <ravindu.18@cse.mrt.ac.lk>
|
| 1275 |
+
Sophia Pustova <tripplezzed@gmail.com>
|
| 1276 |
+
George Pittock <gpittock4@gmail.com>
|
| 1277 |
+
Warren Jacinto <warrenjacinto@gmail.com>
|
| 1278 |
+
Sachin Singh <sachinishu02@gmail.com>
|
| 1279 |
+
Zedmat <104870914+harshkasat@users.noreply.github.com>
|
| 1280 |
+
Soumendra Ganguly <soumendraganguly@gmail.com>
|
| 1281 |
+
Samith Karunathilake <55777141+samithkavishke@users.noreply.github.com>
|
| 1282 |
+
Viraj Vekaria <virajv5593@gmail.com>
|
| 1283 |
+
Shishir Kushwaha <kushwahashishir1112@gmail.com>
|
| 1284 |
+
Ankit Kumar Singh <ankitdiswar10@gmail.com>
|
| 1285 |
+
Abhishek Kumar <abhishek.nitdelhi@gmail.com>
|
| 1286 |
+
Mohak Malviya <mohakmalviya2000@gmail.com>
|
| 1287 |
+
Matthias Liesenfeld <116307294+maliesen@users.noreply.github.com>
|
| 1288 |
+
dodo <palumbododo@gmail.com>
|
| 1289 |
+
Mohamed Rezk <mohrizq895@gmail.com>
|
| 1290 |
+
Tommaso Vaccari <05-gesto-follemente@icloud.com>
|
| 1291 |
+
Alexis Schotte <alexis.schotte@gmail.com>
|
| 1292 |
+
Lauren Yim <31467609+cherryblossom000@users.noreply.github.com>
|
| 1293 |
+
Prey Patel <patel.prey@iitgn.ac.in>
|
| 1294 |
+
Riccardo Di Girolamo <riccardodigirolamo01@gmail.com>
|
| 1295 |
+
Abhishek kumar <kumar325571@gmail.com>
|
| 1296 |
+
Sam Lubelsky <sammy56lt@gmail.com>
|
| 1297 |
+
Henrique Soares <henrique.c.soares@tecnico.ulisboa.pt>
|
| 1298 |
+
Vladimir Sereda <voffch@gmail.com>
|
| 1299 |
+
Hwayeon Kang <hwayeonniii@gmail.com>
|
| 1300 |
+
Raj Sapale <raj4sapale4@gmail.com>
|
| 1301 |
+
Gerald Teschl <gerald.teschl@univie.ac.at>
|
| 1302 |
+
Richard Samuel <98638849+samuelard7@users.noreply.github.com>
|
| 1303 |
+
HeeJae Chang <hechang@microsoft.com>
|
| 1304 |
+
Nick Harder <nharder@umich.edu>
|
| 1305 |
+
Ethan DeGuire <ethandeguire@gmail.com>
|
| 1306 |
+
Lorenz Winkler <lorenz.winkler@tuwien.ac.at>
|
| 1307 |
+
Richard Rodenbusch <rrodenbusch@gmail.com>
|
| 1308 |
+
Zhenxu Zhu <xzdlj@outlook.com>
|
| 1309 |
+
Mark van Gelder <m.j.vangelder@student.tudelft.nl>
|
| 1310 |
+
Mark van Gelder <mvgmvgmvg@live.com>
|
| 1311 |
+
Ishan Pandhare <91841626+Ishanned@users.noreply.github.com>
|
| 1312 |
+
James A. Preiss <jamesalanpreiss@gmail.com>
|
| 1313 |
+
Emile Fourcini <emile.fourcin1@gmail.com>
|
| 1314 |
+
Alberto Jiménez Ruiz <Alberto.Jimenez@uclm.es>
|
| 1315 |
+
João Bravo <joaocgbravo@tecnico.ulisboa.pt>
|
| 1316 |
+
Dean Price <dean1357price1357@gmail.com>
|
| 1317 |
+
Edward Z. Yang <ezyang@mit.edu>
|
| 1318 |
+
James Titus <titusjames299@gmail.com>
|
| 1319 |
+
Zhuoyuan Li <zy.li@stu.pku.edu.cn>
|
| 1320 |
+
Hugo Kerstens <hugo@kerstens.me>
|
| 1321 |
+
Jan Jancar <johny@neuromancer.sk>
|
| 1322 |
+
Andrew Mosson <amosson@yahoo.com>
|
| 1323 |
+
Marek Madejski <marekmadejski@yandex.com>
|
| 1324 |
+
Gonzalo Tornaría <tornaria@cmat.edu.uy>
|
| 1325 |
+
Peter Stahlecker <peter.stahlecker@gmail.com>
|
| 1326 |
+
Jean-François B <2589111+jfbu@users.noreply.github.com>
|
| 1327 |
+
Zexuan Zhou (Bruce) <zzx498636727@gmail.com>
|
| 1328 |
+
George Frolov <gosha@fro.lv>
|
| 1329 |
+
Corbet Elkins <corbet286@gmail.com>
|
| 1330 |
+
Håkon Kvernmoen <haakon.kvernmoen@gmail.com>
|
| 1331 |
+
Muhammad Maaz <mmaaz6004@gmail.com>
|
| 1332 |
+
Shishir Kushwaha <138311586+shishir-11@users.noreply.github.com>
|
| 1333 |
+
Matt Wang <mattwang44@gmail.com>
|
| 1334 |
+
bharatAmeria <21001019007@jcboseust.ac.in>
|
| 1335 |
+
Amir Ebrahimi <github@aebrahimi.com>
|
| 1336 |
+
Steven Esquea <steven.esquea@irreverente.net>
|
| 1337 |
+
Rishabh Kamboj <111004091+VectorNd@users.noreply.github.com>
|
| 1338 |
+
Aasim Ali <aasim250205@gmail.com>
|
| 1339 |
+
Ivan A. Melnikov <iv@altlinux.org>
|
| 1340 |
+
Borek Saheli <boreksaheli@gmail.com>
|
| 1341 |
+
Guido Roncarolo <guido.roncarolo@gmail.com>
|
| 1342 |
+
Quek Zi Yao <ziyaoqzy2001@gmail.com>
|
| 1343 |
+
Roelof Rietbroek <r.rietbroek@utwente.nl>
|
| 1344 |
+
MostafaGalal1 <mostafag649.mg@gmail.com>
|
| 1345 |
+
Au Huishan <huishan_au@outlook.com>
|
| 1346 |
+
Kris Katterjohn <katterjohn@gmail.com>
|
| 1347 |
+
Shiyao Guo <mivikq@gmail.com>
|
| 1348 |
+
Rushabh Mehta <mehtarushabh2005@gmail.com>
|
| 1349 |
+
Temiloluwa Yusuf ytemiloluwa@gmail.com ytemiloluwa <ytemiloluwa@gmail.com>
|
| 1350 |
+
Davi Laerte <davilae011@gmail.com>
|
| 1351 |
+
Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com>
|
| 1352 |
+
Harshit Gupta <harshithigh2001@gmail.com>
|
| 1353 |
+
Praveen Perumal <ppraveen98841@gmail.com>
|
| 1354 |
+
Kevin McWhirter <klmcw@yahoo.com>
|
| 1355 |
+
Prayag V <v.prayag2005@gmail.com>
|
| 1356 |
+
Lucas Kletzander <lucas.kletzander@gmail.com>
|
| 1357 |
+
Pratyksh Gupta <pratykshgupta9999@gmail.com>
|
| 1358 |
+
Leonardo Mangani <leomangani4@gmail.com>
|
| 1359 |
+
Karan Anand <anandkarancompsci@gmail.com>
|
| 1360 |
+
Gagan Mishra <simonsimple305@gmail.com>
|
| 1361 |
+
Krishnav Bajoria <bajoriakrishnav@gmail.com>
|
| 1362 |
+
Matt Ord <matthew.ord1@gmail.com>
|
| 1363 |
+
Jatin Bhardwaj <bhardwajjatin093@gmail.com>
|
| 1364 |
+
Prashant Tandon <tandonprashant101@gmail.com>
|
| 1365 |
+
Paramjit Singh <paramjit1071@gmail.com>
|
| 1366 |
+
João Rodrigues <abcjoao@hotmail.com>
|
| 1367 |
+
Alejandro García Prada <114813960+AlexGarciaPrada@users.noreply.github.com>
|
| 1368 |
+
Matthew Treinish <mtreinish@kortar.org>
|
| 1369 |
+
Clayton Rabideau <claytonrabideau@gmail.com>
|
| 1370 |
+
Victoria Koval <bictoriakoval16@gmail.com>
|
| 1371 |
+
Voaides Negustor Robert <134785947+voaidesr@users.noreply.github.com>
|
| 1372 |
+
Ovsk Mendov <bbb23exposed@gmail.com>
|
| 1373 |
+
David Brooks <dave@bcs.co.nz>
|
| 1374 |
+
Nicholas Laustrup <124007393+nicklaustrup@users.noreply.github.com>
|
| 1375 |
+
Harikrishna Srinivasan <harikrishnasri3@gmail.com>
|
| 1376 |
+
Mathis Cros <mathis.cros@telecom-paris.fr>
|
| 1377 |
+
Arnav Mummineni <45217840+RCoder01@users.noreply.github.com>
|
| 1378 |
+
Thangaraju Sibiraj <85477603+t-sibiraj@users.noreply.github.com>
|
| 1379 |
+
KJaybhaye <krushnajaybhaye01@gmail.com>
|
venv/lib/python3.14/site-packages/sympy-1.14.0.dist-info/licenses/LICENSE
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Copyright (c) 2006-2023 SymPy Development Team
|
| 2 |
+
|
| 3 |
+
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 |
+
a. Redistributions of source code must retain the above copyright notice,
|
| 9 |
+
this list of conditions and the following disclaimer.
|
| 10 |
+
b. Redistributions in binary form must reproduce the above copyright
|
| 11 |
+
notice, this list of conditions and the following disclaimer in the
|
| 12 |
+
documentation and/or other materials provided with the distribution.
|
| 13 |
+
c. Neither the name of SymPy nor the names of its contributors
|
| 14 |
+
may be used to endorse or promote products derived from this software
|
| 15 |
+
without specific prior written permission.
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
| 19 |
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
| 20 |
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
| 21 |
+
ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
|
| 22 |
+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
| 23 |
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
| 24 |
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
| 25 |
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
| 26 |
+
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
| 27 |
+
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
|
| 28 |
+
DAMAGE.
|
| 29 |
+
|
| 30 |
+
--------------------------------------------------------------------------------
|
| 31 |
+
|
| 32 |
+
Patches that were taken from the Diofant project (https://github.com/diofant/diofant)
|
| 33 |
+
are licensed as:
|
| 34 |
+
|
| 35 |
+
Copyright (c) 2006-2018 SymPy Development Team,
|
| 36 |
+
2013-2023 Sergey B Kirpichev
|
| 37 |
+
|
| 38 |
+
All rights reserved.
|
| 39 |
+
|
| 40 |
+
Redistribution and use in source and binary forms, with or without
|
| 41 |
+
modification, are permitted provided that the following conditions are met:
|
| 42 |
+
|
| 43 |
+
a. Redistributions of source code must retain the above copyright notice,
|
| 44 |
+
this list of conditions and the following disclaimer.
|
| 45 |
+
b. Redistributions in binary form must reproduce the above copyright
|
| 46 |
+
notice, this list of conditions and the following disclaimer in the
|
| 47 |
+
documentation and/or other materials provided with the distribution.
|
| 48 |
+
c. Neither the name of Diofant or SymPy nor the names of its contributors
|
| 49 |
+
may be used to endorse or promote products derived from this software
|
| 50 |
+
without specific prior written permission.
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
| 54 |
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
| 55 |
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
| 56 |
+
ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
|
| 57 |
+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
| 58 |
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
| 59 |
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
| 60 |
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
| 61 |
+
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
| 62 |
+
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
|
| 63 |
+
DAMAGE.
|
| 64 |
+
|
| 65 |
+
--------------------------------------------------------------------------------
|
| 66 |
+
|
| 67 |
+
Submodules taken from the multipledispatch project (https://github.com/mrocklin/multipledispatch)
|
| 68 |
+
are licensed as:
|
| 69 |
+
|
| 70 |
+
Copyright (c) 2014 Matthew Rocklin
|
| 71 |
+
|
| 72 |
+
All rights reserved.
|
| 73 |
+
|
| 74 |
+
Redistribution and use in source and binary forms, with or without
|
| 75 |
+
modification, are permitted provided that the following conditions are met:
|
| 76 |
+
|
| 77 |
+
a. Redistributions of source code must retain the above copyright notice,
|
| 78 |
+
this list of conditions and the following disclaimer.
|
| 79 |
+
b. Redistributions in binary form must reproduce the above copyright
|
| 80 |
+
notice, this list of conditions and the following disclaimer in the
|
| 81 |
+
documentation and/or other materials provided with the distribution.
|
| 82 |
+
c. Neither the name of multipledispatch nor the names of its contributors
|
| 83 |
+
may be used to endorse or promote products derived from this software
|
| 84 |
+
without specific prior written permission.
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
| 88 |
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
| 89 |
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
| 90 |
+
ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
|
| 91 |
+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
| 92 |
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
| 93 |
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
| 94 |
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
| 95 |
+
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
| 96 |
+
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
|
| 97 |
+
DAMAGE.
|
| 98 |
+
|
| 99 |
+
--------------------------------------------------------------------------------
|
| 100 |
+
|
| 101 |
+
The files under the directory sympy/parsing/autolev/tests/pydy-example-repo
|
| 102 |
+
are directly copied from PyDy project and are licensed as:
|
| 103 |
+
|
| 104 |
+
Copyright (c) 2009-2023, PyDy Authors
|
| 105 |
+
All rights reserved.
|
| 106 |
+
|
| 107 |
+
Redistribution and use in source and binary forms, with or without
|
| 108 |
+
modification, are permitted provided that the following conditions are met:
|
| 109 |
+
|
| 110 |
+
* Redistributions of source code must retain the above copyright
|
| 111 |
+
notice, this list of conditions and the following disclaimer.
|
| 112 |
+
* Redistributions in binary form must reproduce the above copyright
|
| 113 |
+
notice, this list of conditions and the following disclaimer in the
|
| 114 |
+
documentation and/or other materials provided with the distribution.
|
| 115 |
+
* Neither the name of this project nor the names of its contributors may be
|
| 116 |
+
used to endorse or promote products derived from this software without
|
| 117 |
+
specific prior written permission.
|
| 118 |
+
|
| 119 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
| 120 |
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
| 121 |
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
| 122 |
+
DISCLAIMED. IN NO EVENT SHALL PYDY AUTHORS BE LIABLE FOR ANY DIRECT,
|
| 123 |
+
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
| 124 |
+
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
| 125 |
+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
| 126 |
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
| 127 |
+
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
| 128 |
+
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 129 |
+
|
| 130 |
+
--------------------------------------------------------------------------------
|
| 131 |
+
|
| 132 |
+
The files under the directory sympy/parsing/latex
|
| 133 |
+
are directly copied from latex2sympy project and are licensed as:
|
| 134 |
+
|
| 135 |
+
Copyright 2016, latex2sympy
|
| 136 |
+
|
| 137 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 138 |
+
of this software and associated documentation files (the "Software"), to deal
|
| 139 |
+
in the Software without restriction, including without limitation the rights
|
| 140 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 141 |
+
copies of the Software, and to permit persons to whom the Software is
|
| 142 |
+
furnished to do so, subject to the following conditions:
|
| 143 |
+
|
| 144 |
+
The above copyright notice and this permission notice shall be included in all
|
| 145 |
+
copies or substantial portions of the Software.
|
| 146 |
+
|
| 147 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 148 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 149 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 150 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 151 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 152 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| 153 |
+
SOFTWARE.
|
venv/lib/python3.14/site-packages/sympy-1.14.0.dist-info/top_level.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
isympy
|
| 2 |
+
sympy
|
venv/lib/python3.14/site-packages/sympy/plotting/plot_implicit.py
ADDED
|
@@ -0,0 +1,233 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Implicit plotting module for SymPy.
|
| 2 |
+
|
| 3 |
+
Explanation
|
| 4 |
+
===========
|
| 5 |
+
|
| 6 |
+
The module implements a data series called ImplicitSeries which is used by
|
| 7 |
+
``Plot`` class to plot implicit plots for different backends. The module,
|
| 8 |
+
by default, implements plotting using interval arithmetic. It switches to a
|
| 9 |
+
fall back algorithm if the expression cannot be plotted using interval arithmetic.
|
| 10 |
+
It is also possible to specify to use the fall back algorithm for all plots.
|
| 11 |
+
|
| 12 |
+
Boolean combinations of expressions cannot be plotted by the fall back
|
| 13 |
+
algorithm.
|
| 14 |
+
|
| 15 |
+
See Also
|
| 16 |
+
========
|
| 17 |
+
|
| 18 |
+
sympy.plotting.plot
|
| 19 |
+
|
| 20 |
+
References
|
| 21 |
+
==========
|
| 22 |
+
|
| 23 |
+
.. [1] Jeffrey Allen Tupper. Reliable Two-Dimensional Graphing Methods for
|
| 24 |
+
Mathematical Formulae with Two Free Variables.
|
| 25 |
+
|
| 26 |
+
.. [2] Jeffrey Allen Tupper. Graphing Equations with Generalized Interval
|
| 27 |
+
Arithmetic. Master's thesis. University of Toronto, 1996
|
| 28 |
+
|
| 29 |
+
"""
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
from sympy.core.containers import Tuple
|
| 33 |
+
from sympy.core.symbol import (Dummy, Symbol)
|
| 34 |
+
from sympy.polys.polyutils import _sort_gens
|
| 35 |
+
from sympy.plotting.series import ImplicitSeries, _set_discretization_points
|
| 36 |
+
from sympy.plotting.plot import plot_factory
|
| 37 |
+
from sympy.utilities.decorator import doctest_depends_on
|
| 38 |
+
from sympy.utilities.iterables import flatten
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
__doctest_requires__ = {'plot_implicit': ['matplotlib']}
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
@doctest_depends_on(modules=('matplotlib',))
|
| 45 |
+
def plot_implicit(expr, x_var=None, y_var=None, adaptive=True, depth=0,
|
| 46 |
+
n=300, line_color="blue", show=True, **kwargs):
|
| 47 |
+
"""A plot function to plot implicit equations / inequalities.
|
| 48 |
+
|
| 49 |
+
Arguments
|
| 50 |
+
=========
|
| 51 |
+
|
| 52 |
+
- expr : The equation / inequality that is to be plotted.
|
| 53 |
+
- x_var (optional) : symbol to plot on x-axis or tuple giving symbol
|
| 54 |
+
and range as ``(symbol, xmin, xmax)``
|
| 55 |
+
- y_var (optional) : symbol to plot on y-axis or tuple giving symbol
|
| 56 |
+
and range as ``(symbol, ymin, ymax)``
|
| 57 |
+
|
| 58 |
+
If neither ``x_var`` nor ``y_var`` are given then the free symbols in the
|
| 59 |
+
expression will be assigned in the order they are sorted.
|
| 60 |
+
|
| 61 |
+
The following keyword arguments can also be used:
|
| 62 |
+
|
| 63 |
+
- ``adaptive`` Boolean. The default value is set to True. It has to be
|
| 64 |
+
set to False if you want to use a mesh grid.
|
| 65 |
+
|
| 66 |
+
- ``depth`` integer. The depth of recursion for adaptive mesh grid.
|
| 67 |
+
Default value is 0. Takes value in the range (0, 4).
|
| 68 |
+
|
| 69 |
+
- ``n`` integer. The number of points if adaptive mesh grid is not
|
| 70 |
+
used. Default value is 300. This keyword argument replaces ``points``,
|
| 71 |
+
which should be considered deprecated.
|
| 72 |
+
|
| 73 |
+
- ``show`` Boolean. Default value is True. If set to False, the plot will
|
| 74 |
+
not be shown. See ``Plot`` for further information.
|
| 75 |
+
|
| 76 |
+
- ``title`` string. The title for the plot.
|
| 77 |
+
|
| 78 |
+
- ``xlabel`` string. The label for the x-axis
|
| 79 |
+
|
| 80 |
+
- ``ylabel`` string. The label for the y-axis
|
| 81 |
+
|
| 82 |
+
Aesthetics options:
|
| 83 |
+
|
| 84 |
+
- ``line_color``: float or string. Specifies the color for the plot.
|
| 85 |
+
See ``Plot`` to see how to set color for the plots.
|
| 86 |
+
Default value is "Blue"
|
| 87 |
+
|
| 88 |
+
plot_implicit, by default, uses interval arithmetic to plot functions. If
|
| 89 |
+
the expression cannot be plotted using interval arithmetic, it defaults to
|
| 90 |
+
a generating a contour using a mesh grid of fixed number of points. By
|
| 91 |
+
setting adaptive to False, you can force plot_implicit to use the mesh
|
| 92 |
+
grid. The mesh grid method can be effective when adaptive plotting using
|
| 93 |
+
interval arithmetic, fails to plot with small line width.
|
| 94 |
+
|
| 95 |
+
Examples
|
| 96 |
+
========
|
| 97 |
+
|
| 98 |
+
Plot expressions:
|
| 99 |
+
|
| 100 |
+
.. plot::
|
| 101 |
+
:context: reset
|
| 102 |
+
:format: doctest
|
| 103 |
+
:include-source: True
|
| 104 |
+
|
| 105 |
+
>>> from sympy import plot_implicit, symbols, Eq, And
|
| 106 |
+
>>> x, y = symbols('x y')
|
| 107 |
+
|
| 108 |
+
Without any ranges for the symbols in the expression:
|
| 109 |
+
|
| 110 |
+
.. plot::
|
| 111 |
+
:context: close-figs
|
| 112 |
+
:format: doctest
|
| 113 |
+
:include-source: True
|
| 114 |
+
|
| 115 |
+
>>> p1 = plot_implicit(Eq(x**2 + y**2, 5))
|
| 116 |
+
|
| 117 |
+
With the range for the symbols:
|
| 118 |
+
|
| 119 |
+
.. plot::
|
| 120 |
+
:context: close-figs
|
| 121 |
+
:format: doctest
|
| 122 |
+
:include-source: True
|
| 123 |
+
|
| 124 |
+
>>> p2 = plot_implicit(
|
| 125 |
+
... Eq(x**2 + y**2, 3), (x, -3, 3), (y, -3, 3))
|
| 126 |
+
|
| 127 |
+
With depth of recursion as argument:
|
| 128 |
+
|
| 129 |
+
.. plot::
|
| 130 |
+
:context: close-figs
|
| 131 |
+
:format: doctest
|
| 132 |
+
:include-source: True
|
| 133 |
+
|
| 134 |
+
>>> p3 = plot_implicit(
|
| 135 |
+
... Eq(x**2 + y**2, 5), (x, -4, 4), (y, -4, 4), depth = 2)
|
| 136 |
+
|
| 137 |
+
Using mesh grid and not using adaptive meshing:
|
| 138 |
+
|
| 139 |
+
.. plot::
|
| 140 |
+
:context: close-figs
|
| 141 |
+
:format: doctest
|
| 142 |
+
:include-source: True
|
| 143 |
+
|
| 144 |
+
>>> p4 = plot_implicit(
|
| 145 |
+
... Eq(x**2 + y**2, 5), (x, -5, 5), (y, -2, 2),
|
| 146 |
+
... adaptive=False)
|
| 147 |
+
|
| 148 |
+
Using mesh grid without using adaptive meshing with number of points
|
| 149 |
+
specified:
|
| 150 |
+
|
| 151 |
+
.. plot::
|
| 152 |
+
:context: close-figs
|
| 153 |
+
:format: doctest
|
| 154 |
+
:include-source: True
|
| 155 |
+
|
| 156 |
+
>>> p5 = plot_implicit(
|
| 157 |
+
... Eq(x**2 + y**2, 5), (x, -5, 5), (y, -2, 2),
|
| 158 |
+
... adaptive=False, n=400)
|
| 159 |
+
|
| 160 |
+
Plotting regions:
|
| 161 |
+
|
| 162 |
+
.. plot::
|
| 163 |
+
:context: close-figs
|
| 164 |
+
:format: doctest
|
| 165 |
+
:include-source: True
|
| 166 |
+
|
| 167 |
+
>>> p6 = plot_implicit(y > x**2)
|
| 168 |
+
|
| 169 |
+
Plotting Using boolean conjunctions:
|
| 170 |
+
|
| 171 |
+
.. plot::
|
| 172 |
+
:context: close-figs
|
| 173 |
+
:format: doctest
|
| 174 |
+
:include-source: True
|
| 175 |
+
|
| 176 |
+
>>> p7 = plot_implicit(And(y > x, y > -x))
|
| 177 |
+
|
| 178 |
+
When plotting an expression with a single variable (y - 1, for example),
|
| 179 |
+
specify the x or the y variable explicitly:
|
| 180 |
+
|
| 181 |
+
.. plot::
|
| 182 |
+
:context: close-figs
|
| 183 |
+
:format: doctest
|
| 184 |
+
:include-source: True
|
| 185 |
+
|
| 186 |
+
>>> p8 = plot_implicit(y - 1, y_var=y)
|
| 187 |
+
>>> p9 = plot_implicit(x - 1, x_var=x)
|
| 188 |
+
"""
|
| 189 |
+
|
| 190 |
+
xyvar = [i for i in (x_var, y_var) if i is not None]
|
| 191 |
+
free_symbols = expr.free_symbols
|
| 192 |
+
range_symbols = Tuple(*flatten(xyvar)).free_symbols
|
| 193 |
+
undeclared = free_symbols - range_symbols
|
| 194 |
+
if len(free_symbols & range_symbols) > 2:
|
| 195 |
+
raise NotImplementedError("Implicit plotting is not implemented for "
|
| 196 |
+
"more than 2 variables")
|
| 197 |
+
|
| 198 |
+
#Create default ranges if the range is not provided.
|
| 199 |
+
default_range = Tuple(-5, 5)
|
| 200 |
+
def _range_tuple(s):
|
| 201 |
+
if isinstance(s, Symbol):
|
| 202 |
+
return Tuple(s) + default_range
|
| 203 |
+
if len(s) == 3:
|
| 204 |
+
return Tuple(*s)
|
| 205 |
+
raise ValueError('symbol or `(symbol, min, max)` expected but got %s' % s)
|
| 206 |
+
|
| 207 |
+
if len(xyvar) == 0:
|
| 208 |
+
xyvar = list(_sort_gens(free_symbols))
|
| 209 |
+
var_start_end_x = _range_tuple(xyvar[0])
|
| 210 |
+
x = var_start_end_x[0]
|
| 211 |
+
if len(xyvar) != 2:
|
| 212 |
+
if x in undeclared or not undeclared:
|
| 213 |
+
xyvar.append(Dummy('f(%s)' % x.name))
|
| 214 |
+
else:
|
| 215 |
+
xyvar.append(undeclared.pop())
|
| 216 |
+
var_start_end_y = _range_tuple(xyvar[1])
|
| 217 |
+
|
| 218 |
+
kwargs = _set_discretization_points(kwargs, ImplicitSeries)
|
| 219 |
+
series_argument = ImplicitSeries(
|
| 220 |
+
expr, var_start_end_x, var_start_end_y,
|
| 221 |
+
adaptive=adaptive, depth=depth,
|
| 222 |
+
n=n, line_color=line_color)
|
| 223 |
+
|
| 224 |
+
#set the x and y limits
|
| 225 |
+
kwargs['xlim'] = tuple(float(x) for x in var_start_end_x[1:])
|
| 226 |
+
kwargs['ylim'] = tuple(float(y) for y in var_start_end_y[1:])
|
| 227 |
+
# set the x and y labels
|
| 228 |
+
kwargs.setdefault('xlabel', var_start_end_x[0])
|
| 229 |
+
kwargs.setdefault('ylabel', var_start_end_y[0])
|
| 230 |
+
p = plot_factory(series_argument, **kwargs)
|
| 231 |
+
if show:
|
| 232 |
+
p.show()
|
| 233 |
+
return p
|
venv/lib/python3.14/site-packages/sympy/plotting/plotgrid.py
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
from sympy.external import import_module
|
| 3 |
+
import sympy.plotting.backends.base_backend as base_backend
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
# N.B.
|
| 7 |
+
# When changing the minimum module version for matplotlib, please change
|
| 8 |
+
# the same in the `SymPyDocTestFinder`` in `sympy/testing/runtests.py`
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
__doctest_requires__ = {
|
| 12 |
+
("PlotGrid",): ["matplotlib"],
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
class PlotGrid:
|
| 17 |
+
"""This class helps to plot subplots from already created SymPy plots
|
| 18 |
+
in a single figure.
|
| 19 |
+
|
| 20 |
+
Examples
|
| 21 |
+
========
|
| 22 |
+
|
| 23 |
+
.. plot::
|
| 24 |
+
:context: close-figs
|
| 25 |
+
:format: doctest
|
| 26 |
+
:include-source: True
|
| 27 |
+
|
| 28 |
+
>>> from sympy import symbols
|
| 29 |
+
>>> from sympy.plotting import plot, plot3d, PlotGrid
|
| 30 |
+
>>> x, y = symbols('x, y')
|
| 31 |
+
>>> p1 = plot(x, x**2, x**3, (x, -5, 5))
|
| 32 |
+
>>> p2 = plot((x**2, (x, -6, 6)), (x, (x, -5, 5)))
|
| 33 |
+
>>> p3 = plot(x**3, (x, -5, 5))
|
| 34 |
+
>>> p4 = plot3d(x*y, (x, -5, 5), (y, -5, 5))
|
| 35 |
+
|
| 36 |
+
Plotting vertically in a single line:
|
| 37 |
+
|
| 38 |
+
.. plot::
|
| 39 |
+
:context: close-figs
|
| 40 |
+
:format: doctest
|
| 41 |
+
:include-source: True
|
| 42 |
+
|
| 43 |
+
>>> PlotGrid(2, 1, p1, p2)
|
| 44 |
+
PlotGrid object containing:
|
| 45 |
+
Plot[0]:Plot object containing:
|
| 46 |
+
[0]: cartesian line: x for x over (-5.0, 5.0)
|
| 47 |
+
[1]: cartesian line: x**2 for x over (-5.0, 5.0)
|
| 48 |
+
[2]: cartesian line: x**3 for x over (-5.0, 5.0)
|
| 49 |
+
Plot[1]:Plot object containing:
|
| 50 |
+
[0]: cartesian line: x**2 for x over (-6.0, 6.0)
|
| 51 |
+
[1]: cartesian line: x for x over (-5.0, 5.0)
|
| 52 |
+
|
| 53 |
+
Plotting horizontally in a single line:
|
| 54 |
+
|
| 55 |
+
.. plot::
|
| 56 |
+
:context: close-figs
|
| 57 |
+
:format: doctest
|
| 58 |
+
:include-source: True
|
| 59 |
+
|
| 60 |
+
>>> PlotGrid(1, 3, p2, p3, p4)
|
| 61 |
+
PlotGrid object containing:
|
| 62 |
+
Plot[0]:Plot object containing:
|
| 63 |
+
[0]: cartesian line: x**2 for x over (-6.0, 6.0)
|
| 64 |
+
[1]: cartesian line: x for x over (-5.0, 5.0)
|
| 65 |
+
Plot[1]:Plot object containing:
|
| 66 |
+
[0]: cartesian line: x**3 for x over (-5.0, 5.0)
|
| 67 |
+
Plot[2]:Plot object containing:
|
| 68 |
+
[0]: cartesian surface: x*y for x over (-5.0, 5.0) and y over (-5.0, 5.0)
|
| 69 |
+
|
| 70 |
+
Plotting in a grid form:
|
| 71 |
+
|
| 72 |
+
.. plot::
|
| 73 |
+
:context: close-figs
|
| 74 |
+
:format: doctest
|
| 75 |
+
:include-source: True
|
| 76 |
+
|
| 77 |
+
>>> PlotGrid(2, 2, p1, p2, p3, p4)
|
| 78 |
+
PlotGrid object containing:
|
| 79 |
+
Plot[0]:Plot object containing:
|
| 80 |
+
[0]: cartesian line: x for x over (-5.0, 5.0)
|
| 81 |
+
[1]: cartesian line: x**2 for x over (-5.0, 5.0)
|
| 82 |
+
[2]: cartesian line: x**3 for x over (-5.0, 5.0)
|
| 83 |
+
Plot[1]:Plot object containing:
|
| 84 |
+
[0]: cartesian line: x**2 for x over (-6.0, 6.0)
|
| 85 |
+
[1]: cartesian line: x for x over (-5.0, 5.0)
|
| 86 |
+
Plot[2]:Plot object containing:
|
| 87 |
+
[0]: cartesian line: x**3 for x over (-5.0, 5.0)
|
| 88 |
+
Plot[3]:Plot object containing:
|
| 89 |
+
[0]: cartesian surface: x*y for x over (-5.0, 5.0) and y over (-5.0, 5.0)
|
| 90 |
+
|
| 91 |
+
"""
|
| 92 |
+
def __init__(self, nrows, ncolumns, *args, show=True, size=None, **kwargs):
|
| 93 |
+
"""
|
| 94 |
+
Parameters
|
| 95 |
+
==========
|
| 96 |
+
|
| 97 |
+
nrows :
|
| 98 |
+
The number of rows that should be in the grid of the
|
| 99 |
+
required subplot.
|
| 100 |
+
ncolumns :
|
| 101 |
+
The number of columns that should be in the grid
|
| 102 |
+
of the required subplot.
|
| 103 |
+
|
| 104 |
+
nrows and ncolumns together define the required grid.
|
| 105 |
+
|
| 106 |
+
Arguments
|
| 107 |
+
=========
|
| 108 |
+
|
| 109 |
+
A list of predefined plot objects entered in a row-wise sequence
|
| 110 |
+
i.e. plot objects which are to be in the top row of the required
|
| 111 |
+
grid are written first, then the second row objects and so on
|
| 112 |
+
|
| 113 |
+
Keyword arguments
|
| 114 |
+
=================
|
| 115 |
+
|
| 116 |
+
show : Boolean
|
| 117 |
+
The default value is set to ``True``. Set show to ``False`` and
|
| 118 |
+
the function will not display the subplot. The returned instance
|
| 119 |
+
of the ``PlotGrid`` class can then be used to save or display the
|
| 120 |
+
plot by calling the ``save()`` and ``show()`` methods
|
| 121 |
+
respectively.
|
| 122 |
+
size : (float, float), optional
|
| 123 |
+
A tuple in the form (width, height) in inches to specify the size of
|
| 124 |
+
the overall figure. The default value is set to ``None``, meaning
|
| 125 |
+
the size will be set by the default backend.
|
| 126 |
+
"""
|
| 127 |
+
self.matplotlib = import_module('matplotlib',
|
| 128 |
+
import_kwargs={'fromlist': ['pyplot', 'cm', 'collections']},
|
| 129 |
+
min_module_version='1.1.0', catch=(RuntimeError,))
|
| 130 |
+
self.nrows = nrows
|
| 131 |
+
self.ncolumns = ncolumns
|
| 132 |
+
self._series = []
|
| 133 |
+
self._fig = None
|
| 134 |
+
self.args = args
|
| 135 |
+
for arg in args:
|
| 136 |
+
self._series.append(arg._series)
|
| 137 |
+
self.size = size
|
| 138 |
+
if show and self.matplotlib:
|
| 139 |
+
self.show()
|
| 140 |
+
|
| 141 |
+
def _create_figure(self):
|
| 142 |
+
gs = self.matplotlib.gridspec.GridSpec(self.nrows, self.ncolumns)
|
| 143 |
+
mapping = {}
|
| 144 |
+
c = 0
|
| 145 |
+
for i in range(self.nrows):
|
| 146 |
+
for j in range(self.ncolumns):
|
| 147 |
+
if c < len(self.args):
|
| 148 |
+
mapping[gs[i, j]] = self.args[c]
|
| 149 |
+
c += 1
|
| 150 |
+
|
| 151 |
+
kw = {} if not self.size else {"figsize": self.size}
|
| 152 |
+
self._fig = self.matplotlib.pyplot.figure(**kw)
|
| 153 |
+
for spec, p in mapping.items():
|
| 154 |
+
kw = ({"projection": "3d"} if (len(p._series) > 0 and
|
| 155 |
+
p._series[0].is_3D) else {})
|
| 156 |
+
cur_ax = self._fig.add_subplot(spec, **kw)
|
| 157 |
+
p._plotgrid_fig = self._fig
|
| 158 |
+
p._plotgrid_ax = cur_ax
|
| 159 |
+
p.process_series()
|
| 160 |
+
|
| 161 |
+
@property
|
| 162 |
+
def fig(self):
|
| 163 |
+
if not self._fig:
|
| 164 |
+
self._create_figure()
|
| 165 |
+
return self._fig
|
| 166 |
+
|
| 167 |
+
@property
|
| 168 |
+
def _backend(self):
|
| 169 |
+
return self
|
| 170 |
+
|
| 171 |
+
def close(self):
|
| 172 |
+
self.matplotlib.pyplot.close(self.fig)
|
| 173 |
+
|
| 174 |
+
def show(self):
|
| 175 |
+
if base_backend._show:
|
| 176 |
+
self.fig.tight_layout()
|
| 177 |
+
self.matplotlib.pyplot.show()
|
| 178 |
+
else:
|
| 179 |
+
self.close()
|
| 180 |
+
|
| 181 |
+
def save(self, path):
|
| 182 |
+
self.fig.savefig(path)
|
| 183 |
+
|
| 184 |
+
def __str__(self):
|
| 185 |
+
plot_strs = [('Plot[%d]:' % i) + str(plot)
|
| 186 |
+
for i, plot in enumerate(self.args)]
|
| 187 |
+
|
| 188 |
+
return 'PlotGrid object containing:\n' + '\n'.join(plot_strs)
|
venv/lib/python3.14/site-packages/sympy/plotting/pygletplot/__init__.py
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Plotting module that can plot 2D and 3D functions
|
| 2 |
+
"""
|
| 3 |
+
|
| 4 |
+
from sympy.utilities.decorator import doctest_depends_on
|
| 5 |
+
|
| 6 |
+
@doctest_depends_on(modules=('pyglet',))
|
| 7 |
+
def PygletPlot(*args, **kwargs):
|
| 8 |
+
"""
|
| 9 |
+
|
| 10 |
+
Plot Examples
|
| 11 |
+
=============
|
| 12 |
+
|
| 13 |
+
See examples/advanced/pyglet_plotting.py for many more examples.
|
| 14 |
+
|
| 15 |
+
>>> from sympy.plotting.pygletplot import PygletPlot as Plot
|
| 16 |
+
>>> from sympy.abc import x, y, z
|
| 17 |
+
|
| 18 |
+
>>> Plot(x*y**3-y*x**3)
|
| 19 |
+
[0]: -x**3*y + x*y**3, 'mode=cartesian'
|
| 20 |
+
|
| 21 |
+
>>> p = Plot()
|
| 22 |
+
>>> p[1] = x*y
|
| 23 |
+
>>> p[1].color = z, (0.4,0.4,0.9), (0.9,0.4,0.4)
|
| 24 |
+
|
| 25 |
+
>>> p = Plot()
|
| 26 |
+
>>> p[1] = x**2+y**2
|
| 27 |
+
>>> p[2] = -x**2-y**2
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
Variable Intervals
|
| 31 |
+
==================
|
| 32 |
+
|
| 33 |
+
The basic format is [var, min, max, steps], but the
|
| 34 |
+
syntax is flexible and arguments left out are taken
|
| 35 |
+
from the defaults for the current coordinate mode:
|
| 36 |
+
|
| 37 |
+
>>> Plot(x**2) # implies [x,-5,5,100]
|
| 38 |
+
[0]: x**2, 'mode=cartesian'
|
| 39 |
+
|
| 40 |
+
>>> Plot(x**2, [], []) # [x,-1,1,40], [y,-1,1,40]
|
| 41 |
+
[0]: x**2, 'mode=cartesian'
|
| 42 |
+
>>> Plot(x**2-y**2, [100], [100]) # [x,-1,1,100], [y,-1,1,100]
|
| 43 |
+
[0]: x**2 - y**2, 'mode=cartesian'
|
| 44 |
+
>>> Plot(x**2, [x,-13,13,100])
|
| 45 |
+
[0]: x**2, 'mode=cartesian'
|
| 46 |
+
>>> Plot(x**2, [-13,13]) # [x,-13,13,100]
|
| 47 |
+
[0]: x**2, 'mode=cartesian'
|
| 48 |
+
>>> Plot(x**2, [x,-13,13]) # [x,-13,13,100]
|
| 49 |
+
[0]: x**2, 'mode=cartesian'
|
| 50 |
+
>>> Plot(1*x, [], [x], mode='cylindrical')
|
| 51 |
+
... # [unbound_theta,0,2*Pi,40], [x,-1,1,20]
|
| 52 |
+
[0]: x, 'mode=cartesian'
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
Coordinate Modes
|
| 56 |
+
================
|
| 57 |
+
|
| 58 |
+
Plot supports several curvilinear coordinate modes, and
|
| 59 |
+
they independent for each plotted function. You can specify
|
| 60 |
+
a coordinate mode explicitly with the 'mode' named argument,
|
| 61 |
+
but it can be automatically determined for Cartesian or
|
| 62 |
+
parametric plots, and therefore must only be specified for
|
| 63 |
+
polar, cylindrical, and spherical modes.
|
| 64 |
+
|
| 65 |
+
Specifically, Plot(function arguments) and Plot[n] =
|
| 66 |
+
(function arguments) will interpret your arguments as a
|
| 67 |
+
Cartesian plot if you provide one function and a parametric
|
| 68 |
+
plot if you provide two or three functions. Similarly, the
|
| 69 |
+
arguments will be interpreted as a curve if one variable is
|
| 70 |
+
used, and a surface if two are used.
|
| 71 |
+
|
| 72 |
+
Supported mode names by number of variables:
|
| 73 |
+
|
| 74 |
+
1: parametric, cartesian, polar
|
| 75 |
+
2: parametric, cartesian, cylindrical = polar, spherical
|
| 76 |
+
|
| 77 |
+
>>> Plot(1, mode='spherical')
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
Calculator-like Interface
|
| 81 |
+
=========================
|
| 82 |
+
|
| 83 |
+
>>> p = Plot(visible=False)
|
| 84 |
+
>>> f = x**2
|
| 85 |
+
>>> p[1] = f
|
| 86 |
+
>>> p[2] = f.diff(x)
|
| 87 |
+
>>> p[3] = f.diff(x).diff(x)
|
| 88 |
+
>>> p
|
| 89 |
+
[1]: x**2, 'mode=cartesian'
|
| 90 |
+
[2]: 2*x, 'mode=cartesian'
|
| 91 |
+
[3]: 2, 'mode=cartesian'
|
| 92 |
+
>>> p.show()
|
| 93 |
+
>>> p.clear()
|
| 94 |
+
>>> p
|
| 95 |
+
<blank plot>
|
| 96 |
+
>>> p[1] = x**2+y**2
|
| 97 |
+
>>> p[1].style = 'solid'
|
| 98 |
+
>>> p[2] = -x**2-y**2
|
| 99 |
+
>>> p[2].style = 'wireframe'
|
| 100 |
+
>>> p[1].color = z, (0.4,0.4,0.9), (0.9,0.4,0.4)
|
| 101 |
+
>>> p[1].style = 'both'
|
| 102 |
+
>>> p[2].style = 'both'
|
| 103 |
+
>>> p.close()
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
Plot Window Keyboard Controls
|
| 107 |
+
=============================
|
| 108 |
+
|
| 109 |
+
Screen Rotation:
|
| 110 |
+
X,Y axis Arrow Keys, A,S,D,W, Numpad 4,6,8,2
|
| 111 |
+
Z axis Q,E, Numpad 7,9
|
| 112 |
+
|
| 113 |
+
Model Rotation:
|
| 114 |
+
Z axis Z,C, Numpad 1,3
|
| 115 |
+
|
| 116 |
+
Zoom: R,F, PgUp,PgDn, Numpad +,-
|
| 117 |
+
|
| 118 |
+
Reset Camera: X, Numpad 5
|
| 119 |
+
|
| 120 |
+
Camera Presets:
|
| 121 |
+
XY F1
|
| 122 |
+
XZ F2
|
| 123 |
+
YZ F3
|
| 124 |
+
Perspective F4
|
| 125 |
+
|
| 126 |
+
Sensitivity Modifier: SHIFT
|
| 127 |
+
|
| 128 |
+
Axes Toggle:
|
| 129 |
+
Visible F5
|
| 130 |
+
Colors F6
|
| 131 |
+
|
| 132 |
+
Close Window: ESCAPE
|
| 133 |
+
|
| 134 |
+
=============================
|
| 135 |
+
"""
|
| 136 |
+
|
| 137 |
+
from sympy.plotting.pygletplot.plot import PygletPlot
|
| 138 |
+
return PygletPlot(*args, **kwargs)
|
venv/lib/python3.14/site-packages/sympy/plotting/pygletplot/color_scheme.py
ADDED
|
@@ -0,0 +1,336 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from sympy.core.basic import Basic
|
| 2 |
+
from sympy.core.symbol import (Symbol, symbols)
|
| 3 |
+
from sympy.utilities.lambdify import lambdify
|
| 4 |
+
from .util import interpolate, rinterpolate, create_bounds, update_bounds
|
| 5 |
+
from sympy.utilities.iterables import sift
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
class ColorGradient:
|
| 9 |
+
colors = [0.4, 0.4, 0.4], [0.9, 0.9, 0.9]
|
| 10 |
+
intervals = 0.0, 1.0
|
| 11 |
+
|
| 12 |
+
def __init__(self, *args):
|
| 13 |
+
if len(args) == 2:
|
| 14 |
+
self.colors = list(args)
|
| 15 |
+
self.intervals = [0.0, 1.0]
|
| 16 |
+
elif len(args) > 0:
|
| 17 |
+
if len(args) % 2 != 0:
|
| 18 |
+
raise ValueError("len(args) should be even")
|
| 19 |
+
self.colors = [args[i] for i in range(1, len(args), 2)]
|
| 20 |
+
self.intervals = [args[i] for i in range(0, len(args), 2)]
|
| 21 |
+
assert len(self.colors) == len(self.intervals)
|
| 22 |
+
|
| 23 |
+
def copy(self):
|
| 24 |
+
c = ColorGradient()
|
| 25 |
+
c.colors = [e[::] for e in self.colors]
|
| 26 |
+
c.intervals = self.intervals[::]
|
| 27 |
+
return c
|
| 28 |
+
|
| 29 |
+
def _find_interval(self, v):
|
| 30 |
+
m = len(self.intervals)
|
| 31 |
+
i = 0
|
| 32 |
+
while i < m - 1 and self.intervals[i] <= v:
|
| 33 |
+
i += 1
|
| 34 |
+
return i
|
| 35 |
+
|
| 36 |
+
def _interpolate_axis(self, axis, v):
|
| 37 |
+
i = self._find_interval(v)
|
| 38 |
+
v = rinterpolate(self.intervals[i - 1], self.intervals[i], v)
|
| 39 |
+
return interpolate(self.colors[i - 1][axis], self.colors[i][axis], v)
|
| 40 |
+
|
| 41 |
+
def __call__(self, r, g, b):
|
| 42 |
+
c = self._interpolate_axis
|
| 43 |
+
return c(0, r), c(1, g), c(2, b)
|
| 44 |
+
|
| 45 |
+
default_color_schemes = {} # defined at the bottom of this file
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
class ColorScheme:
|
| 49 |
+
|
| 50 |
+
def __init__(self, *args, **kwargs):
|
| 51 |
+
self.args = args
|
| 52 |
+
self.f, self.gradient = None, ColorGradient()
|
| 53 |
+
|
| 54 |
+
if len(args) == 1 and not isinstance(args[0], Basic) and callable(args[0]):
|
| 55 |
+
self.f = args[0]
|
| 56 |
+
elif len(args) == 1 and isinstance(args[0], str):
|
| 57 |
+
if args[0] in default_color_schemes:
|
| 58 |
+
cs = default_color_schemes[args[0]]
|
| 59 |
+
self.f, self.gradient = cs.f, cs.gradient.copy()
|
| 60 |
+
else:
|
| 61 |
+
self.f = lambdify('x,y,z,u,v', args[0])
|
| 62 |
+
else:
|
| 63 |
+
self.f, self.gradient = self._interpret_args(args)
|
| 64 |
+
self._test_color_function()
|
| 65 |
+
if not isinstance(self.gradient, ColorGradient):
|
| 66 |
+
raise ValueError("Color gradient not properly initialized. "
|
| 67 |
+
"(Not a ColorGradient instance.)")
|
| 68 |
+
|
| 69 |
+
def _interpret_args(self, args):
|
| 70 |
+
f, gradient = None, self.gradient
|
| 71 |
+
atoms, lists = self._sort_args(args)
|
| 72 |
+
s = self._pop_symbol_list(lists)
|
| 73 |
+
s = self._fill_in_vars(s)
|
| 74 |
+
|
| 75 |
+
# prepare the error message for lambdification failure
|
| 76 |
+
f_str = ', '.join(str(fa) for fa in atoms)
|
| 77 |
+
s_str = (str(sa) for sa in s)
|
| 78 |
+
s_str = ', '.join(sa for sa in s_str if sa.find('unbound') < 0)
|
| 79 |
+
f_error = ValueError("Could not interpret arguments "
|
| 80 |
+
"%s as functions of %s." % (f_str, s_str))
|
| 81 |
+
|
| 82 |
+
# try to lambdify args
|
| 83 |
+
if len(atoms) == 1:
|
| 84 |
+
fv = atoms[0]
|
| 85 |
+
try:
|
| 86 |
+
f = lambdify(s, [fv, fv, fv])
|
| 87 |
+
except TypeError:
|
| 88 |
+
raise f_error
|
| 89 |
+
|
| 90 |
+
elif len(atoms) == 3:
|
| 91 |
+
fr, fg, fb = atoms
|
| 92 |
+
try:
|
| 93 |
+
f = lambdify(s, [fr, fg, fb])
|
| 94 |
+
except TypeError:
|
| 95 |
+
raise f_error
|
| 96 |
+
|
| 97 |
+
else:
|
| 98 |
+
raise ValueError("A ColorScheme must provide 1 or 3 "
|
| 99 |
+
"functions in x, y, z, u, and/or v.")
|
| 100 |
+
|
| 101 |
+
# try to intrepret any given color information
|
| 102 |
+
if len(lists) == 0:
|
| 103 |
+
gargs = []
|
| 104 |
+
|
| 105 |
+
elif len(lists) == 1:
|
| 106 |
+
gargs = lists[0]
|
| 107 |
+
|
| 108 |
+
elif len(lists) == 2:
|
| 109 |
+
try:
|
| 110 |
+
(r1, g1, b1), (r2, g2, b2) = lists
|
| 111 |
+
except TypeError:
|
| 112 |
+
raise ValueError("If two color arguments are given, "
|
| 113 |
+
"they must be given in the format "
|
| 114 |
+
"(r1, g1, b1), (r2, g2, b2).")
|
| 115 |
+
gargs = lists
|
| 116 |
+
|
| 117 |
+
elif len(lists) == 3:
|
| 118 |
+
try:
|
| 119 |
+
(r1, r2), (g1, g2), (b1, b2) = lists
|
| 120 |
+
except Exception:
|
| 121 |
+
raise ValueError("If three color arguments are given, "
|
| 122 |
+
"they must be given in the format "
|
| 123 |
+
"(r1, r2), (g1, g2), (b1, b2). To create "
|
| 124 |
+
"a multi-step gradient, use the syntax "
|
| 125 |
+
"[0, colorStart, step1, color1, ..., 1, "
|
| 126 |
+
"colorEnd].")
|
| 127 |
+
gargs = [[r1, g1, b1], [r2, g2, b2]]
|
| 128 |
+
|
| 129 |
+
else:
|
| 130 |
+
raise ValueError("Don't know what to do with collection "
|
| 131 |
+
"arguments %s." % (', '.join(str(l) for l in lists)))
|
| 132 |
+
|
| 133 |
+
if gargs:
|
| 134 |
+
try:
|
| 135 |
+
gradient = ColorGradient(*gargs)
|
| 136 |
+
except Exception as ex:
|
| 137 |
+
raise ValueError(("Could not initialize a gradient "
|
| 138 |
+
"with arguments %s. Inner "
|
| 139 |
+
"exception: %s") % (gargs, str(ex)))
|
| 140 |
+
|
| 141 |
+
return f, gradient
|
| 142 |
+
|
| 143 |
+
def _pop_symbol_list(self, lists):
|
| 144 |
+
symbol_lists = []
|
| 145 |
+
for l in lists:
|
| 146 |
+
mark = True
|
| 147 |
+
for s in l:
|
| 148 |
+
if s is not None and not isinstance(s, Symbol):
|
| 149 |
+
mark = False
|
| 150 |
+
break
|
| 151 |
+
if mark:
|
| 152 |
+
lists.remove(l)
|
| 153 |
+
symbol_lists.append(l)
|
| 154 |
+
if len(symbol_lists) == 1:
|
| 155 |
+
return symbol_lists[0]
|
| 156 |
+
elif len(symbol_lists) == 0:
|
| 157 |
+
return []
|
| 158 |
+
else:
|
| 159 |
+
raise ValueError("Only one list of Symbols "
|
| 160 |
+
"can be given for a color scheme.")
|
| 161 |
+
|
| 162 |
+
def _fill_in_vars(self, args):
|
| 163 |
+
defaults = symbols('x,y,z,u,v')
|
| 164 |
+
v_error = ValueError("Could not find what to plot.")
|
| 165 |
+
if len(args) == 0:
|
| 166 |
+
return defaults
|
| 167 |
+
if not isinstance(args, (tuple, list)):
|
| 168 |
+
raise v_error
|
| 169 |
+
if len(args) == 0:
|
| 170 |
+
return defaults
|
| 171 |
+
for s in args:
|
| 172 |
+
if s is not None and not isinstance(s, Symbol):
|
| 173 |
+
raise v_error
|
| 174 |
+
# when vars are given explicitly, any vars
|
| 175 |
+
# not given are marked 'unbound' as to not
|
| 176 |
+
# be accidentally used in an expression
|
| 177 |
+
vars = [Symbol('unbound%i' % (i)) for i in range(1, 6)]
|
| 178 |
+
# interpret as t
|
| 179 |
+
if len(args) == 1:
|
| 180 |
+
vars[3] = args[0]
|
| 181 |
+
# interpret as u,v
|
| 182 |
+
elif len(args) == 2:
|
| 183 |
+
if args[0] is not None:
|
| 184 |
+
vars[3] = args[0]
|
| 185 |
+
if args[1] is not None:
|
| 186 |
+
vars[4] = args[1]
|
| 187 |
+
# interpret as x,y,z
|
| 188 |
+
elif len(args) >= 3:
|
| 189 |
+
# allow some of x,y,z to be
|
| 190 |
+
# left unbound if not given
|
| 191 |
+
if args[0] is not None:
|
| 192 |
+
vars[0] = args[0]
|
| 193 |
+
if args[1] is not None:
|
| 194 |
+
vars[1] = args[1]
|
| 195 |
+
if args[2] is not None:
|
| 196 |
+
vars[2] = args[2]
|
| 197 |
+
# interpret the rest as t
|
| 198 |
+
if len(args) >= 4:
|
| 199 |
+
vars[3] = args[3]
|
| 200 |
+
# ...or u,v
|
| 201 |
+
if len(args) >= 5:
|
| 202 |
+
vars[4] = args[4]
|
| 203 |
+
return vars
|
| 204 |
+
|
| 205 |
+
def _sort_args(self, args):
|
| 206 |
+
lists, atoms = sift(args,
|
| 207 |
+
lambda a: isinstance(a, (tuple, list)), binary=True)
|
| 208 |
+
return atoms, lists
|
| 209 |
+
|
| 210 |
+
def _test_color_function(self):
|
| 211 |
+
if not callable(self.f):
|
| 212 |
+
raise ValueError("Color function is not callable.")
|
| 213 |
+
try:
|
| 214 |
+
result = self.f(0, 0, 0, 0, 0)
|
| 215 |
+
if len(result) != 3:
|
| 216 |
+
raise ValueError("length should be equal to 3")
|
| 217 |
+
except TypeError:
|
| 218 |
+
raise ValueError("Color function needs to accept x,y,z,u,v, "
|
| 219 |
+
"as arguments even if it doesn't use all of them.")
|
| 220 |
+
except AssertionError:
|
| 221 |
+
raise ValueError("Color function needs to return 3-tuple r,g,b.")
|
| 222 |
+
except Exception:
|
| 223 |
+
pass # color function probably not valid at 0,0,0,0,0
|
| 224 |
+
|
| 225 |
+
def __call__(self, x, y, z, u, v):
|
| 226 |
+
try:
|
| 227 |
+
return self.f(x, y, z, u, v)
|
| 228 |
+
except Exception:
|
| 229 |
+
return None
|
| 230 |
+
|
| 231 |
+
def apply_to_curve(self, verts, u_set, set_len=None, inc_pos=None):
|
| 232 |
+
"""
|
| 233 |
+
Apply this color scheme to a
|
| 234 |
+
set of vertices over a single
|
| 235 |
+
independent variable u.
|
| 236 |
+
"""
|
| 237 |
+
bounds = create_bounds()
|
| 238 |
+
cverts = []
|
| 239 |
+
if callable(set_len):
|
| 240 |
+
set_len(len(u_set)*2)
|
| 241 |
+
# calculate f() = r,g,b for each vert
|
| 242 |
+
# and find the min and max for r,g,b
|
| 243 |
+
for _u in range(len(u_set)):
|
| 244 |
+
if verts[_u] is None:
|
| 245 |
+
cverts.append(None)
|
| 246 |
+
else:
|
| 247 |
+
x, y, z = verts[_u]
|
| 248 |
+
u, v = u_set[_u], None
|
| 249 |
+
c = self(x, y, z, u, v)
|
| 250 |
+
if c is not None:
|
| 251 |
+
c = list(c)
|
| 252 |
+
update_bounds(bounds, c)
|
| 253 |
+
cverts.append(c)
|
| 254 |
+
if callable(inc_pos):
|
| 255 |
+
inc_pos()
|
| 256 |
+
# scale and apply gradient
|
| 257 |
+
for _u in range(len(u_set)):
|
| 258 |
+
if cverts[_u] is not None:
|
| 259 |
+
for _c in range(3):
|
| 260 |
+
# scale from [f_min, f_max] to [0,1]
|
| 261 |
+
cverts[_u][_c] = rinterpolate(bounds[_c][0], bounds[_c][1],
|
| 262 |
+
cverts[_u][_c])
|
| 263 |
+
# apply gradient
|
| 264 |
+
cverts[_u] = self.gradient(*cverts[_u])
|
| 265 |
+
if callable(inc_pos):
|
| 266 |
+
inc_pos()
|
| 267 |
+
return cverts
|
| 268 |
+
|
| 269 |
+
def apply_to_surface(self, verts, u_set, v_set, set_len=None, inc_pos=None):
|
| 270 |
+
"""
|
| 271 |
+
Apply this color scheme to a
|
| 272 |
+
set of vertices over two
|
| 273 |
+
independent variables u and v.
|
| 274 |
+
"""
|
| 275 |
+
bounds = create_bounds()
|
| 276 |
+
cverts = []
|
| 277 |
+
if callable(set_len):
|
| 278 |
+
set_len(len(u_set)*len(v_set)*2)
|
| 279 |
+
# calculate f() = r,g,b for each vert
|
| 280 |
+
# and find the min and max for r,g,b
|
| 281 |
+
for _u in range(len(u_set)):
|
| 282 |
+
column = []
|
| 283 |
+
for _v in range(len(v_set)):
|
| 284 |
+
if verts[_u][_v] is None:
|
| 285 |
+
column.append(None)
|
| 286 |
+
else:
|
| 287 |
+
x, y, z = verts[_u][_v]
|
| 288 |
+
u, v = u_set[_u], v_set[_v]
|
| 289 |
+
c = self(x, y, z, u, v)
|
| 290 |
+
if c is not None:
|
| 291 |
+
c = list(c)
|
| 292 |
+
update_bounds(bounds, c)
|
| 293 |
+
column.append(c)
|
| 294 |
+
if callable(inc_pos):
|
| 295 |
+
inc_pos()
|
| 296 |
+
cverts.append(column)
|
| 297 |
+
# scale and apply gradient
|
| 298 |
+
for _u in range(len(u_set)):
|
| 299 |
+
for _v in range(len(v_set)):
|
| 300 |
+
if cverts[_u][_v] is not None:
|
| 301 |
+
# scale from [f_min, f_max] to [0,1]
|
| 302 |
+
for _c in range(3):
|
| 303 |
+
cverts[_u][_v][_c] = rinterpolate(bounds[_c][0],
|
| 304 |
+
bounds[_c][1], cverts[_u][_v][_c])
|
| 305 |
+
# apply gradient
|
| 306 |
+
cverts[_u][_v] = self.gradient(*cverts[_u][_v])
|
| 307 |
+
if callable(inc_pos):
|
| 308 |
+
inc_pos()
|
| 309 |
+
return cverts
|
| 310 |
+
|
| 311 |
+
def str_base(self):
|
| 312 |
+
return ", ".join(str(a) for a in self.args)
|
| 313 |
+
|
| 314 |
+
def __repr__(self):
|
| 315 |
+
return "%s" % (self.str_base())
|
| 316 |
+
|
| 317 |
+
|
| 318 |
+
x, y, z, t, u, v = symbols('x,y,z,t,u,v')
|
| 319 |
+
|
| 320 |
+
default_color_schemes['rainbow'] = ColorScheme(z, y, x)
|
| 321 |
+
default_color_schemes['zfade'] = ColorScheme(z, (0.4, 0.4, 0.97),
|
| 322 |
+
(0.97, 0.4, 0.4), (None, None, z))
|
| 323 |
+
default_color_schemes['zfade3'] = ColorScheme(z, (None, None, z),
|
| 324 |
+
[0.00, (0.2, 0.2, 1.0),
|
| 325 |
+
0.35, (0.2, 0.8, 0.4),
|
| 326 |
+
0.50, (0.3, 0.9, 0.3),
|
| 327 |
+
0.65, (0.4, 0.8, 0.2),
|
| 328 |
+
1.00, (1.0, 0.2, 0.2)])
|
| 329 |
+
|
| 330 |
+
default_color_schemes['zfade4'] = ColorScheme(z, (None, None, z),
|
| 331 |
+
[0.0, (0.3, 0.3, 1.0),
|
| 332 |
+
0.30, (0.3, 1.0, 0.3),
|
| 333 |
+
0.55, (0.95, 1.0, 0.2),
|
| 334 |
+
0.65, (1.0, 0.95, 0.2),
|
| 335 |
+
0.85, (1.0, 0.7, 0.2),
|
| 336 |
+
1.0, (1.0, 0.3, 0.2)])
|
venv/lib/python3.14/site-packages/sympy/plotting/pygletplot/managed_window.py
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from pyglet.window import Window
|
| 2 |
+
from pyglet.clock import Clock
|
| 3 |
+
|
| 4 |
+
from threading import Thread, Lock
|
| 5 |
+
|
| 6 |
+
gl_lock = Lock()
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
class ManagedWindow(Window):
|
| 10 |
+
"""
|
| 11 |
+
A pyglet window with an event loop which executes automatically
|
| 12 |
+
in a separate thread. Behavior is added by creating a subclass
|
| 13 |
+
which overrides setup, update, and/or draw.
|
| 14 |
+
"""
|
| 15 |
+
fps_limit = 30
|
| 16 |
+
default_win_args = {"width": 600,
|
| 17 |
+
"height": 500,
|
| 18 |
+
"vsync": False,
|
| 19 |
+
"resizable": True}
|
| 20 |
+
|
| 21 |
+
def __init__(self, **win_args):
|
| 22 |
+
"""
|
| 23 |
+
It is best not to override this function in the child
|
| 24 |
+
class, unless you need to take additional arguments.
|
| 25 |
+
Do any OpenGL initialization calls in setup().
|
| 26 |
+
"""
|
| 27 |
+
|
| 28 |
+
# check if this is run from the doctester
|
| 29 |
+
if win_args.get('runfromdoctester', False):
|
| 30 |
+
return
|
| 31 |
+
|
| 32 |
+
self.win_args = dict(self.default_win_args, **win_args)
|
| 33 |
+
self.Thread = Thread(target=self.__event_loop__)
|
| 34 |
+
self.Thread.start()
|
| 35 |
+
|
| 36 |
+
def __event_loop__(self, **win_args):
|
| 37 |
+
"""
|
| 38 |
+
The event loop thread function. Do not override or call
|
| 39 |
+
directly (it is called by __init__).
|
| 40 |
+
"""
|
| 41 |
+
gl_lock.acquire()
|
| 42 |
+
try:
|
| 43 |
+
try:
|
| 44 |
+
super().__init__(**self.win_args)
|
| 45 |
+
self.switch_to()
|
| 46 |
+
self.setup()
|
| 47 |
+
except Exception as e:
|
| 48 |
+
print("Window initialization failed: %s" % (str(e)))
|
| 49 |
+
self.has_exit = True
|
| 50 |
+
finally:
|
| 51 |
+
gl_lock.release()
|
| 52 |
+
|
| 53 |
+
clock = Clock()
|
| 54 |
+
clock.fps_limit = self.fps_limit
|
| 55 |
+
while not self.has_exit:
|
| 56 |
+
dt = clock.tick()
|
| 57 |
+
gl_lock.acquire()
|
| 58 |
+
try:
|
| 59 |
+
try:
|
| 60 |
+
self.switch_to()
|
| 61 |
+
self.dispatch_events()
|
| 62 |
+
self.clear()
|
| 63 |
+
self.update(dt)
|
| 64 |
+
self.draw()
|
| 65 |
+
self.flip()
|
| 66 |
+
except Exception as e:
|
| 67 |
+
print("Uncaught exception in event loop: %s" % str(e))
|
| 68 |
+
self.has_exit = True
|
| 69 |
+
finally:
|
| 70 |
+
gl_lock.release()
|
| 71 |
+
super().close()
|
| 72 |
+
|
| 73 |
+
def close(self):
|
| 74 |
+
"""
|
| 75 |
+
Closes the window.
|
| 76 |
+
"""
|
| 77 |
+
self.has_exit = True
|
| 78 |
+
|
| 79 |
+
def setup(self):
|
| 80 |
+
"""
|
| 81 |
+
Called once before the event loop begins.
|
| 82 |
+
Override this method in a child class. This
|
| 83 |
+
is the best place to put things like OpenGL
|
| 84 |
+
initialization calls.
|
| 85 |
+
"""
|
| 86 |
+
pass
|
| 87 |
+
|
| 88 |
+
def update(self, dt):
|
| 89 |
+
"""
|
| 90 |
+
Called before draw during each iteration of
|
| 91 |
+
the event loop. dt is the elapsed time in
|
| 92 |
+
seconds since the last update. OpenGL rendering
|
| 93 |
+
calls are best put in draw() rather than here.
|
| 94 |
+
"""
|
| 95 |
+
pass
|
| 96 |
+
|
| 97 |
+
def draw(self):
|
| 98 |
+
"""
|
| 99 |
+
Called after update during each iteration of
|
| 100 |
+
the event loop. Put OpenGL rendering calls
|
| 101 |
+
here.
|
| 102 |
+
"""
|
| 103 |
+
pass
|
| 104 |
+
|
| 105 |
+
if __name__ == '__main__':
|
| 106 |
+
ManagedWindow()
|
venv/lib/python3.14/site-packages/sympy/plotting/pygletplot/plot.py
ADDED
|
@@ -0,0 +1,464 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
| 1 |
+
from threading import RLock
|
| 2 |
+
|
| 3 |
+
# it is sufficient to import "pyglet" here once
|
| 4 |
+
try:
|
| 5 |
+
import pyglet.gl as pgl
|
| 6 |
+
except ImportError:
|
| 7 |
+
raise ImportError("pyglet is required for plotting.\n "
|
| 8 |
+
"visit https://pyglet.org/")
|
| 9 |
+
|
| 10 |
+
from sympy.core.numbers import Integer
|
| 11 |
+
from sympy.external.gmpy import SYMPY_INTS
|
| 12 |
+
from sympy.geometry.entity import GeometryEntity
|
| 13 |
+
from sympy.plotting.pygletplot.plot_axes import PlotAxes
|
| 14 |
+
from sympy.plotting.pygletplot.plot_mode import PlotMode
|
| 15 |
+
from sympy.plotting.pygletplot.plot_object import PlotObject
|
| 16 |
+
from sympy.plotting.pygletplot.plot_window import PlotWindow
|
| 17 |
+
from sympy.plotting.pygletplot.util import parse_option_string
|
| 18 |
+
from sympy.utilities.decorator import doctest_depends_on
|
| 19 |
+
from sympy.utilities.iterables import is_sequence
|
| 20 |
+
|
| 21 |
+
from time import sleep
|
| 22 |
+
from os import getcwd, listdir
|
| 23 |
+
|
| 24 |
+
import ctypes
|
| 25 |
+
|
| 26 |
+
@doctest_depends_on(modules=('pyglet',))
|
| 27 |
+
class PygletPlot:
|
| 28 |
+
"""
|
| 29 |
+
Plot Examples
|
| 30 |
+
=============
|
| 31 |
+
|
| 32 |
+
See examples/advanced/pyglet_plotting.py for many more examples.
|
| 33 |
+
|
| 34 |
+
>>> from sympy.plotting.pygletplot import PygletPlot as Plot
|
| 35 |
+
>>> from sympy.abc import x, y, z
|
| 36 |
+
|
| 37 |
+
>>> Plot(x*y**3-y*x**3)
|
| 38 |
+
[0]: -x**3*y + x*y**3, 'mode=cartesian'
|
| 39 |
+
|
| 40 |
+
>>> p = Plot()
|
| 41 |
+
>>> p[1] = x*y
|
| 42 |
+
>>> p[1].color = z, (0.4,0.4,0.9), (0.9,0.4,0.4)
|
| 43 |
+
|
| 44 |
+
>>> p = Plot()
|
| 45 |
+
>>> p[1] = x**2+y**2
|
| 46 |
+
>>> p[2] = -x**2-y**2
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
Variable Intervals
|
| 50 |
+
==================
|
| 51 |
+
|
| 52 |
+
The basic format is [var, min, max, steps], but the
|
| 53 |
+
syntax is flexible and arguments left out are taken
|
| 54 |
+
from the defaults for the current coordinate mode:
|
| 55 |
+
|
| 56 |
+
>>> Plot(x**2) # implies [x,-5,5,100]
|
| 57 |
+
[0]: x**2, 'mode=cartesian'
|
| 58 |
+
>>> Plot(x**2, [], []) # [x,-1,1,40], [y,-1,1,40]
|
| 59 |
+
[0]: x**2, 'mode=cartesian'
|
| 60 |
+
>>> Plot(x**2-y**2, [100], [100]) # [x,-1,1,100], [y,-1,1,100]
|
| 61 |
+
[0]: x**2 - y**2, 'mode=cartesian'
|
| 62 |
+
>>> Plot(x**2, [x,-13,13,100])
|
| 63 |
+
[0]: x**2, 'mode=cartesian'
|
| 64 |
+
>>> Plot(x**2, [-13,13]) # [x,-13,13,100]
|
| 65 |
+
[0]: x**2, 'mode=cartesian'
|
| 66 |
+
>>> Plot(x**2, [x,-13,13]) # [x,-13,13,10]
|
| 67 |
+
[0]: x**2, 'mode=cartesian'
|
| 68 |
+
>>> Plot(1*x, [], [x], mode='cylindrical')
|
| 69 |
+
... # [unbound_theta,0,2*Pi,40], [x,-1,1,20]
|
| 70 |
+
[0]: x, 'mode=cartesian'
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
Coordinate Modes
|
| 74 |
+
================
|
| 75 |
+
|
| 76 |
+
Plot supports several curvilinear coordinate modes, and
|
| 77 |
+
they independent for each plotted function. You can specify
|
| 78 |
+
a coordinate mode explicitly with the 'mode' named argument,
|
| 79 |
+
but it can be automatically determined for Cartesian or
|
| 80 |
+
parametric plots, and therefore must only be specified for
|
| 81 |
+
polar, cylindrical, and spherical modes.
|
| 82 |
+
|
| 83 |
+
Specifically, Plot(function arguments) and Plot[n] =
|
| 84 |
+
(function arguments) will interpret your arguments as a
|
| 85 |
+
Cartesian plot if you provide one function and a parametric
|
| 86 |
+
plot if you provide two or three functions. Similarly, the
|
| 87 |
+
arguments will be interpreted as a curve if one variable is
|
| 88 |
+
used, and a surface if two are used.
|
| 89 |
+
|
| 90 |
+
Supported mode names by number of variables:
|
| 91 |
+
|
| 92 |
+
1: parametric, cartesian, polar
|
| 93 |
+
2: parametric, cartesian, cylindrical = polar, spherical
|
| 94 |
+
|
| 95 |
+
>>> Plot(1, mode='spherical')
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
Calculator-like Interface
|
| 99 |
+
=========================
|
| 100 |
+
|
| 101 |
+
>>> p = Plot(visible=False)
|
| 102 |
+
>>> f = x**2
|
| 103 |
+
>>> p[1] = f
|
| 104 |
+
>>> p[2] = f.diff(x)
|
| 105 |
+
>>> p[3] = f.diff(x).diff(x)
|
| 106 |
+
>>> p
|
| 107 |
+
[1]: x**2, 'mode=cartesian'
|
| 108 |
+
[2]: 2*x, 'mode=cartesian'
|
| 109 |
+
[3]: 2, 'mode=cartesian'
|
| 110 |
+
>>> p.show()
|
| 111 |
+
>>> p.clear()
|
| 112 |
+
>>> p
|
| 113 |
+
<blank plot>
|
| 114 |
+
>>> p[1] = x**2+y**2
|
| 115 |
+
>>> p[1].style = 'solid'
|
| 116 |
+
>>> p[2] = -x**2-y**2
|
| 117 |
+
>>> p[2].style = 'wireframe'
|
| 118 |
+
>>> p[1].color = z, (0.4,0.4,0.9), (0.9,0.4,0.4)
|
| 119 |
+
>>> p[1].style = 'both'
|
| 120 |
+
>>> p[2].style = 'both'
|
| 121 |
+
>>> p.close()
|
| 122 |
+
|
| 123 |
+
|
| 124 |
+
Plot Window Keyboard Controls
|
| 125 |
+
=============================
|
| 126 |
+
|
| 127 |
+
Screen Rotation:
|
| 128 |
+
X,Y axis Arrow Keys, A,S,D,W, Numpad 4,6,8,2
|
| 129 |
+
Z axis Q,E, Numpad 7,9
|
| 130 |
+
|
| 131 |
+
Model Rotation:
|
| 132 |
+
Z axis Z,C, Numpad 1,3
|
| 133 |
+
|
| 134 |
+
Zoom: R,F, PgUp,PgDn, Numpad +,-
|
| 135 |
+
|
| 136 |
+
Reset Camera: X, Numpad 5
|
| 137 |
+
|
| 138 |
+
Camera Presets:
|
| 139 |
+
XY F1
|
| 140 |
+
XZ F2
|
| 141 |
+
YZ F3
|
| 142 |
+
Perspective F4
|
| 143 |
+
|
| 144 |
+
Sensitivity Modifier: SHIFT
|
| 145 |
+
|
| 146 |
+
Axes Toggle:
|
| 147 |
+
Visible F5
|
| 148 |
+
Colors F6
|
| 149 |
+
|
| 150 |
+
Close Window: ESCAPE
|
| 151 |
+
|
| 152 |
+
=============================
|
| 153 |
+
|
| 154 |
+
"""
|
| 155 |
+
|
| 156 |
+
@doctest_depends_on(modules=('pyglet',))
|
| 157 |
+
def __init__(self, *fargs, **win_args):
|
| 158 |
+
"""
|
| 159 |
+
Positional Arguments
|
| 160 |
+
====================
|
| 161 |
+
|
| 162 |
+
Any given positional arguments are used to
|
| 163 |
+
initialize a plot function at index 1. In
|
| 164 |
+
other words...
|
| 165 |
+
|
| 166 |
+
>>> from sympy.plotting.pygletplot import PygletPlot as Plot
|
| 167 |
+
>>> from sympy.abc import x
|
| 168 |
+
>>> p = Plot(x**2, visible=False)
|
| 169 |
+
|
| 170 |
+
...is equivalent to...
|
| 171 |
+
|
| 172 |
+
>>> p = Plot(visible=False)
|
| 173 |
+
>>> p[1] = x**2
|
| 174 |
+
|
| 175 |
+
Note that in earlier versions of the plotting
|
| 176 |
+
module, you were able to specify multiple
|
| 177 |
+
functions in the initializer. This functionality
|
| 178 |
+
has been dropped in favor of better automatic
|
| 179 |
+
plot plot_mode detection.
|
| 180 |
+
|
| 181 |
+
|
| 182 |
+
Named Arguments
|
| 183 |
+
===============
|
| 184 |
+
|
| 185 |
+
axes
|
| 186 |
+
An option string of the form
|
| 187 |
+
"key1=value1; key2 = value2" which
|
| 188 |
+
can use the following options:
|
| 189 |
+
|
| 190 |
+
style = ordinate
|
| 191 |
+
none OR frame OR box OR ordinate
|
| 192 |
+
|
| 193 |
+
stride = 0.25
|
| 194 |
+
val OR (val_x, val_y, val_z)
|
| 195 |
+
|
| 196 |
+
overlay = True (draw on top of plot)
|
| 197 |
+
True OR False
|
| 198 |
+
|
| 199 |
+
colored = False (False uses Black,
|
| 200 |
+
True uses colors
|
| 201 |
+
R,G,B = X,Y,Z)
|
| 202 |
+
True OR False
|
| 203 |
+
|
| 204 |
+
label_axes = False (display axis names
|
| 205 |
+
at endpoints)
|
| 206 |
+
True OR False
|
| 207 |
+
|
| 208 |
+
visible = True (show immediately
|
| 209 |
+
True OR False
|
| 210 |
+
|
| 211 |
+
|
| 212 |
+
The following named arguments are passed as
|
| 213 |
+
arguments to window initialization:
|
| 214 |
+
|
| 215 |
+
antialiasing = True
|
| 216 |
+
True OR False
|
| 217 |
+
|
| 218 |
+
ortho = False
|
| 219 |
+
True OR False
|
| 220 |
+
|
| 221 |
+
invert_mouse_zoom = False
|
| 222 |
+
True OR False
|
| 223 |
+
|
| 224 |
+
"""
|
| 225 |
+
# Register the plot modes
|
| 226 |
+
from . import plot_modes # noqa
|
| 227 |
+
|
| 228 |
+
self._win_args = win_args
|
| 229 |
+
self._window = None
|
| 230 |
+
|
| 231 |
+
self._render_lock = RLock()
|
| 232 |
+
|
| 233 |
+
self._functions = {}
|
| 234 |
+
self._pobjects = []
|
| 235 |
+
self._screenshot = ScreenShot(self)
|
| 236 |
+
|
| 237 |
+
axe_options = parse_option_string(win_args.pop('axes', ''))
|
| 238 |
+
self.axes = PlotAxes(**axe_options)
|
| 239 |
+
self._pobjects.append(self.axes)
|
| 240 |
+
|
| 241 |
+
self[0] = fargs
|
| 242 |
+
if win_args.get('visible', True):
|
| 243 |
+
self.show()
|
| 244 |
+
|
| 245 |
+
## Window Interfaces
|
| 246 |
+
|
| 247 |
+
def show(self):
|
| 248 |
+
"""
|
| 249 |
+
Creates and displays a plot window, or activates it
|
| 250 |
+
(gives it focus) if it has already been created.
|
| 251 |
+
"""
|
| 252 |
+
if self._window and not self._window.has_exit:
|
| 253 |
+
self._window.activate()
|
| 254 |
+
else:
|
| 255 |
+
self._win_args['visible'] = True
|
| 256 |
+
self.axes.reset_resources()
|
| 257 |
+
|
| 258 |
+
#if hasattr(self, '_doctest_depends_on'):
|
| 259 |
+
# self._win_args['runfromdoctester'] = True
|
| 260 |
+
|
| 261 |
+
self._window = PlotWindow(self, **self._win_args)
|
| 262 |
+
|
| 263 |
+
def close(self):
|
| 264 |
+
"""
|
| 265 |
+
Closes the plot window.
|
| 266 |
+
"""
|
| 267 |
+
if self._window:
|
| 268 |
+
self._window.close()
|
| 269 |
+
|
| 270 |
+
def saveimage(self, outfile=None, format='', size=(600, 500)):
|
| 271 |
+
"""
|
| 272 |
+
Saves a screen capture of the plot window to an
|
| 273 |
+
image file.
|
| 274 |
+
|
| 275 |
+
If outfile is given, it can either be a path
|
| 276 |
+
or a file object. Otherwise a png image will
|
| 277 |
+
be saved to the current working directory.
|
| 278 |
+
If the format is omitted, it is determined from
|
| 279 |
+
the filename extension.
|
| 280 |
+
"""
|
| 281 |
+
self._screenshot.save(outfile, format, size)
|
| 282 |
+
|
| 283 |
+
## Function List Interfaces
|
| 284 |
+
|
| 285 |
+
def clear(self):
|
| 286 |
+
"""
|
| 287 |
+
Clears the function list of this plot.
|
| 288 |
+
"""
|
| 289 |
+
self._render_lock.acquire()
|
| 290 |
+
self._functions = {}
|
| 291 |
+
self.adjust_all_bounds()
|
| 292 |
+
self._render_lock.release()
|
| 293 |
+
|
| 294 |
+
def __getitem__(self, i):
|
| 295 |
+
"""
|
| 296 |
+
Returns the function at position i in the
|
| 297 |
+
function list.
|
| 298 |
+
"""
|
| 299 |
+
return self._functions[i]
|
| 300 |
+
|
| 301 |
+
def __setitem__(self, i, args):
|
| 302 |
+
"""
|
| 303 |
+
Parses and adds a PlotMode to the function
|
| 304 |
+
list.
|
| 305 |
+
"""
|
| 306 |
+
if not (isinstance(i, (SYMPY_INTS, Integer)) and i >= 0):
|
| 307 |
+
raise ValueError("Function index must "
|
| 308 |
+
"be an integer >= 0.")
|
| 309 |
+
|
| 310 |
+
if isinstance(args, PlotObject):
|
| 311 |
+
f = args
|
| 312 |
+
else:
|
| 313 |
+
if (not is_sequence(args)) or isinstance(args, GeometryEntity):
|
| 314 |
+
args = [args]
|
| 315 |
+
if len(args) == 0:
|
| 316 |
+
return # no arguments given
|
| 317 |
+
kwargs = {"bounds_callback": self.adjust_all_bounds}
|
| 318 |
+
f = PlotMode(*args, **kwargs)
|
| 319 |
+
|
| 320 |
+
if f:
|
| 321 |
+
self._render_lock.acquire()
|
| 322 |
+
self._functions[i] = f
|
| 323 |
+
self._render_lock.release()
|
| 324 |
+
else:
|
| 325 |
+
raise ValueError("Failed to parse '%s'."
|
| 326 |
+
% ', '.join(str(a) for a in args))
|
| 327 |
+
|
| 328 |
+
def __delitem__(self, i):
|
| 329 |
+
"""
|
| 330 |
+
Removes the function in the function list at
|
| 331 |
+
position i.
|
| 332 |
+
"""
|
| 333 |
+
self._render_lock.acquire()
|
| 334 |
+
del self._functions[i]
|
| 335 |
+
self.adjust_all_bounds()
|
| 336 |
+
self._render_lock.release()
|
| 337 |
+
|
| 338 |
+
def firstavailableindex(self):
|
| 339 |
+
"""
|
| 340 |
+
Returns the first unused index in the function list.
|
| 341 |
+
"""
|
| 342 |
+
i = 0
|
| 343 |
+
self._render_lock.acquire()
|
| 344 |
+
while i in self._functions:
|
| 345 |
+
i += 1
|
| 346 |
+
self._render_lock.release()
|
| 347 |
+
return i
|
| 348 |
+
|
| 349 |
+
def append(self, *args):
|
| 350 |
+
"""
|
| 351 |
+
Parses and adds a PlotMode to the function
|
| 352 |
+
list at the first available index.
|
| 353 |
+
"""
|
| 354 |
+
self.__setitem__(self.firstavailableindex(), args)
|
| 355 |
+
|
| 356 |
+
def __len__(self):
|
| 357 |
+
"""
|
| 358 |
+
Returns the number of functions in the function list.
|
| 359 |
+
"""
|
| 360 |
+
return len(self._functions)
|
| 361 |
+
|
| 362 |
+
def __iter__(self):
|
| 363 |
+
"""
|
| 364 |
+
Allows iteration of the function list.
|
| 365 |
+
"""
|
| 366 |
+
return self._functions.itervalues()
|
| 367 |
+
|
| 368 |
+
def __repr__(self):
|
| 369 |
+
return str(self)
|
| 370 |
+
|
| 371 |
+
def __str__(self):
|
| 372 |
+
"""
|
| 373 |
+
Returns a string containing a new-line separated
|
| 374 |
+
list of the functions in the function list.
|
| 375 |
+
"""
|
| 376 |
+
s = ""
|
| 377 |
+
if len(self._functions) == 0:
|
| 378 |
+
s += "<blank plot>"
|
| 379 |
+
else:
|
| 380 |
+
self._render_lock.acquire()
|
| 381 |
+
s += "\n".join(["%s[%i]: %s" % ("", i, str(self._functions[i]))
|
| 382 |
+
for i in self._functions])
|
| 383 |
+
self._render_lock.release()
|
| 384 |
+
return s
|
| 385 |
+
|
| 386 |
+
def adjust_all_bounds(self):
|
| 387 |
+
self._render_lock.acquire()
|
| 388 |
+
self.axes.reset_bounding_box()
|
| 389 |
+
for f in self._functions:
|
| 390 |
+
self.axes.adjust_bounds(self._functions[f].bounds)
|
| 391 |
+
self._render_lock.release()
|
| 392 |
+
|
| 393 |
+
def wait_for_calculations(self):
|
| 394 |
+
sleep(0)
|
| 395 |
+
self._render_lock.acquire()
|
| 396 |
+
for f in self._functions:
|
| 397 |
+
a = self._functions[f]._get_calculating_verts
|
| 398 |
+
b = self._functions[f]._get_calculating_cverts
|
| 399 |
+
while a() or b():
|
| 400 |
+
sleep(0)
|
| 401 |
+
self._render_lock.release()
|
| 402 |
+
|
| 403 |
+
class ScreenShot:
|
| 404 |
+
def __init__(self, plot):
|
| 405 |
+
self._plot = plot
|
| 406 |
+
self.screenshot_requested = False
|
| 407 |
+
self.outfile = None
|
| 408 |
+
self.format = ''
|
| 409 |
+
self.invisibleMode = False
|
| 410 |
+
self.flag = 0
|
| 411 |
+
|
| 412 |
+
def __bool__(self):
|
| 413 |
+
return self.screenshot_requested
|
| 414 |
+
|
| 415 |
+
def _execute_saving(self):
|
| 416 |
+
if self.flag < 3:
|
| 417 |
+
self.flag += 1
|
| 418 |
+
return
|
| 419 |
+
|
| 420 |
+
size_x, size_y = self._plot._window.get_size()
|
| 421 |
+
size = size_x*size_y*4*ctypes.sizeof(ctypes.c_ubyte)
|
| 422 |
+
image = ctypes.create_string_buffer(size)
|
| 423 |
+
pgl.glReadPixels(0, 0, size_x, size_y, pgl.GL_RGBA, pgl.GL_UNSIGNED_BYTE, image)
|
| 424 |
+
from PIL import Image
|
| 425 |
+
im = Image.frombuffer('RGBA', (size_x, size_y),
|
| 426 |
+
image.raw, 'raw', 'RGBA', 0, 1)
|
| 427 |
+
im.transpose(Image.FLIP_TOP_BOTTOM).save(self.outfile, self.format)
|
| 428 |
+
|
| 429 |
+
self.flag = 0
|
| 430 |
+
self.screenshot_requested = False
|
| 431 |
+
if self.invisibleMode:
|
| 432 |
+
self._plot._window.close()
|
| 433 |
+
|
| 434 |
+
def save(self, outfile=None, format='', size=(600, 500)):
|
| 435 |
+
self.outfile = outfile
|
| 436 |
+
self.format = format
|
| 437 |
+
self.size = size
|
| 438 |
+
self.screenshot_requested = True
|
| 439 |
+
|
| 440 |
+
if not self._plot._window or self._plot._window.has_exit:
|
| 441 |
+
self._plot._win_args['visible'] = False
|
| 442 |
+
|
| 443 |
+
self._plot._win_args['width'] = size[0]
|
| 444 |
+
self._plot._win_args['height'] = size[1]
|
| 445 |
+
|
| 446 |
+
self._plot.axes.reset_resources()
|
| 447 |
+
self._plot._window = PlotWindow(self._plot, **self._plot._win_args)
|
| 448 |
+
self.invisibleMode = True
|
| 449 |
+
|
| 450 |
+
if self.outfile is None:
|
| 451 |
+
self.outfile = self._create_unique_path()
|
| 452 |
+
print(self.outfile)
|
| 453 |
+
|
| 454 |
+
def _create_unique_path(self):
|
| 455 |
+
cwd = getcwd()
|
| 456 |
+
l = listdir(cwd)
|
| 457 |
+
path = ''
|
| 458 |
+
i = 0
|
| 459 |
+
while True:
|
| 460 |
+
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pyglet.gl as pgl
|
| 2 |
+
from pyglet import font
|
| 3 |
+
|
| 4 |
+
from sympy.core import S
|
| 5 |
+
from sympy.plotting.pygletplot.plot_object import PlotObject
|
| 6 |
+
from sympy.plotting.pygletplot.util import billboard_matrix, dot_product, \
|
| 7 |
+
get_direction_vectors, strided_range, vec_mag, vec_sub
|
| 8 |
+
from sympy.utilities.iterables import is_sequence
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
class PlotAxes(PlotObject):
|
| 12 |
+
|
| 13 |
+
def __init__(self, *args,
|
| 14 |
+
style='', none=None, frame=None, box=None, ordinate=None,
|
| 15 |
+
stride=0.25,
|
| 16 |
+
visible='', overlay='', colored='', label_axes='', label_ticks='',
|
| 17 |
+
tick_length=0.1,
|
| 18 |
+
font_face='Arial', font_size=28,
|
| 19 |
+
**kwargs):
|
| 20 |
+
# initialize style parameter
|
| 21 |
+
style = style.lower()
|
| 22 |
+
|
| 23 |
+
# allow alias kwargs to override style kwarg
|
| 24 |
+
if none is not None:
|
| 25 |
+
style = 'none'
|
| 26 |
+
if frame is not None:
|
| 27 |
+
style = 'frame'
|
| 28 |
+
if box is not None:
|
| 29 |
+
style = 'box'
|
| 30 |
+
if ordinate is not None:
|
| 31 |
+
style = 'ordinate'
|
| 32 |
+
|
| 33 |
+
if style in ['', 'ordinate']:
|
| 34 |
+
self._render_object = PlotAxesOrdinate(self)
|
| 35 |
+
elif style in ['frame', 'box']:
|
| 36 |
+
self._render_object = PlotAxesFrame(self)
|
| 37 |
+
elif style in ['none']:
|
| 38 |
+
self._render_object = None
|
| 39 |
+
else:
|
| 40 |
+
raise ValueError(("Unrecognized axes style %s.") % (style))
|
| 41 |
+
|
| 42 |
+
# initialize stride parameter
|
| 43 |
+
try:
|
| 44 |
+
stride = eval(stride)
|
| 45 |
+
except TypeError:
|
| 46 |
+
pass
|
| 47 |
+
if is_sequence(stride):
|
| 48 |
+
if len(stride) != 3:
|
| 49 |
+
raise ValueError("length should be equal to 3")
|
| 50 |
+
self._stride = stride
|
| 51 |
+
else:
|
| 52 |
+
self._stride = [stride, stride, stride]
|
| 53 |
+
self._tick_length = float(tick_length)
|
| 54 |
+
|
| 55 |
+
# setup bounding box and ticks
|
| 56 |
+
self._origin = [0, 0, 0]
|
| 57 |
+
self.reset_bounding_box()
|
| 58 |
+
|
| 59 |
+
def flexible_boolean(input, default):
|
| 60 |
+
if input in [True, False]:
|
| 61 |
+
return input
|
| 62 |
+
if input in ('f', 'F', 'false', 'False'):
|
| 63 |
+
return False
|
| 64 |
+
if input in ('t', 'T', 'true', 'True'):
|
| 65 |
+
return True
|
| 66 |
+
return default
|
| 67 |
+
|
| 68 |
+
# initialize remaining parameters
|
| 69 |
+
self.visible = flexible_boolean(kwargs, True)
|
| 70 |
+
self._overlay = flexible_boolean(overlay, True)
|
| 71 |
+
self._colored = flexible_boolean(colored, False)
|
| 72 |
+
self._label_axes = flexible_boolean(label_axes, False)
|
| 73 |
+
self._label_ticks = flexible_boolean(label_ticks, True)
|
| 74 |
+
|
| 75 |
+
# setup label font
|
| 76 |
+
self.font_face = font_face
|
| 77 |
+
self.font_size = font_size
|
| 78 |
+
|
| 79 |
+
# this is also used to reinit the
|
| 80 |
+
# font on window close/reopen
|
| 81 |
+
self.reset_resources()
|
| 82 |
+
|
| 83 |
+
def reset_resources(self):
|
| 84 |
+
self.label_font = None
|
| 85 |
+
|
| 86 |
+
def reset_bounding_box(self):
|
| 87 |
+
self._bounding_box = [[None, None], [None, None], [None, None]]
|
| 88 |
+
self._axis_ticks = [[], [], []]
|
| 89 |
+
|
| 90 |
+
def draw(self):
|
| 91 |
+
if self._render_object:
|
| 92 |
+
pgl.glPushAttrib(pgl.GL_ENABLE_BIT | pgl.GL_POLYGON_BIT | pgl.GL_DEPTH_BUFFER_BIT)
|
| 93 |
+
if self._overlay:
|
| 94 |
+
pgl.glDisable(pgl.GL_DEPTH_TEST)
|
| 95 |
+
self._render_object.draw()
|
| 96 |
+
pgl.glPopAttrib()
|
| 97 |
+
|
| 98 |
+
def adjust_bounds(self, child_bounds):
|
| 99 |
+
b = self._bounding_box
|
| 100 |
+
c = child_bounds
|
| 101 |
+
for i in range(3):
|
| 102 |
+
if abs(c[i][0]) is S.Infinity or abs(c[i][1]) is S.Infinity:
|
| 103 |
+
continue
|
| 104 |
+
b[i][0] = c[i][0] if b[i][0] is None else min([b[i][0], c[i][0]])
|
| 105 |
+
b[i][1] = c[i][1] if b[i][1] is None else max([b[i][1], c[i][1]])
|
| 106 |
+
self._bounding_box = b
|
| 107 |
+
self._recalculate_axis_ticks(i)
|
| 108 |
+
|
| 109 |
+
def _recalculate_axis_ticks(self, axis):
|
| 110 |
+
b = self._bounding_box
|
| 111 |
+
if b[axis][0] is None or b[axis][1] is None:
|
| 112 |
+
self._axis_ticks[axis] = []
|
| 113 |
+
else:
|
| 114 |
+
self._axis_ticks[axis] = strided_range(b[axis][0], b[axis][1],
|
| 115 |
+
self._stride[axis])
|
| 116 |
+
|
| 117 |
+
def toggle_visible(self):
|
| 118 |
+
self.visible = not self.visible
|
| 119 |
+
|
| 120 |
+
def toggle_colors(self):
|
| 121 |
+
self._colored = not self._colored
|
| 122 |
+
|
| 123 |
+
|
| 124 |
+
class PlotAxesBase(PlotObject):
|
| 125 |
+
|
| 126 |
+
def __init__(self, parent_axes):
|
| 127 |
+
self._p = parent_axes
|
| 128 |
+
|
| 129 |
+
def draw(self):
|
| 130 |
+
color = [([0.2, 0.1, 0.3], [0.2, 0.1, 0.3], [0.2, 0.1, 0.3]),
|
| 131 |
+
([0.9, 0.3, 0.5], [0.5, 1.0, 0.5], [0.3, 0.3, 0.9])][self._p._colored]
|
| 132 |
+
self.draw_background(color)
|
| 133 |
+
self.draw_axis(2, color[2])
|
| 134 |
+
self.draw_axis(1, color[1])
|
| 135 |
+
self.draw_axis(0, color[0])
|
| 136 |
+
|
| 137 |
+
def draw_background(self, color):
|
| 138 |
+
pass # optional
|
| 139 |
+
|
| 140 |
+
def draw_axis(self, axis, color):
|
| 141 |
+
raise NotImplementedError()
|
| 142 |
+
|
| 143 |
+
def draw_text(self, text, position, color, scale=1.0):
|
| 144 |
+
if len(color) == 3:
|
| 145 |
+
color = (color[0], color[1], color[2], 1.0)
|
| 146 |
+
|
| 147 |
+
if self._p.label_font is None:
|
| 148 |
+
self._p.label_font = font.load(self._p.font_face,
|
| 149 |
+
self._p.font_size,
|
| 150 |
+
bold=True, italic=False)
|
| 151 |
+
|
| 152 |
+
label = font.Text(self._p.label_font, text,
|
| 153 |
+
color=color,
|
| 154 |
+
valign=font.Text.BASELINE,
|
| 155 |
+
halign=font.Text.CENTER)
|
| 156 |
+
|
| 157 |
+
pgl.glPushMatrix()
|
| 158 |
+
pgl.glTranslatef(*position)
|
| 159 |
+
billboard_matrix()
|
| 160 |
+
scale_factor = 0.005 * scale
|
| 161 |
+
pgl.glScalef(scale_factor, scale_factor, scale_factor)
|
| 162 |
+
pgl.glColor4f(0, 0, 0, 0)
|
| 163 |
+
label.draw()
|
| 164 |
+
pgl.glPopMatrix()
|
| 165 |
+
|
| 166 |
+
def draw_line(self, v, color):
|
| 167 |
+
o = self._p._origin
|
| 168 |
+
pgl.glBegin(pgl.GL_LINES)
|
| 169 |
+
pgl.glColor3f(*color)
|
| 170 |
+
pgl.glVertex3f(v[0][0] + o[0], v[0][1] + o[1], v[0][2] + o[2])
|
| 171 |
+
pgl.glVertex3f(v[1][0] + o[0], v[1][1] + o[1], v[1][2] + o[2])
|
| 172 |
+
pgl.glEnd()
|
| 173 |
+
|
| 174 |
+
|
| 175 |
+
class PlotAxesOrdinate(PlotAxesBase):
|
| 176 |
+
|
| 177 |
+
def __init__(self, parent_axes):
|
| 178 |
+
super().__init__(parent_axes)
|
| 179 |
+
|
| 180 |
+
def draw_axis(self, axis, color):
|
| 181 |
+
ticks = self._p._axis_ticks[axis]
|
| 182 |
+
radius = self._p._tick_length / 2.0
|
| 183 |
+
if len(ticks) < 2:
|
| 184 |
+
return
|
| 185 |
+
|
| 186 |
+
# calculate the vector for this axis
|
| 187 |
+
axis_lines = [[0, 0, 0], [0, 0, 0]]
|
| 188 |
+
axis_lines[0][axis], axis_lines[1][axis] = ticks[0], ticks[-1]
|
| 189 |
+
axis_vector = vec_sub(axis_lines[1], axis_lines[0])
|
| 190 |
+
|
| 191 |
+
# calculate angle to the z direction vector
|
| 192 |
+
pos_z = get_direction_vectors()[2]
|
| 193 |
+
d = abs(dot_product(axis_vector, pos_z))
|
| 194 |
+
d = d / vec_mag(axis_vector)
|
| 195 |
+
|
| 196 |
+
# don't draw labels if we're looking down the axis
|
| 197 |
+
labels_visible = abs(d - 1.0) > 0.02
|
| 198 |
+
|
| 199 |
+
# draw the ticks and labels
|
| 200 |
+
for tick in ticks:
|
| 201 |
+
self.draw_tick_line(axis, color, radius, tick, labels_visible)
|
| 202 |
+
|
| 203 |
+
# draw the axis line and labels
|
| 204 |
+
self.draw_axis_line(axis, color, ticks[0], ticks[-1], labels_visible)
|
| 205 |
+
|
| 206 |
+
def draw_axis_line(self, axis, color, a_min, a_max, labels_visible):
|
| 207 |
+
axis_line = [[0, 0, 0], [0, 0, 0]]
|
| 208 |
+
axis_line[0][axis], axis_line[1][axis] = a_min, a_max
|
| 209 |
+
self.draw_line(axis_line, color)
|
| 210 |
+
if labels_visible:
|
| 211 |
+
self.draw_axis_line_labels(axis, color, axis_line)
|
| 212 |
+
|
| 213 |
+
def draw_axis_line_labels(self, axis, color, axis_line):
|
| 214 |
+
if not self._p._label_axes:
|
| 215 |
+
return
|
| 216 |
+
axis_labels = [axis_line[0][::], axis_line[1][::]]
|
| 217 |
+
axis_labels[0][axis] -= 0.3
|
| 218 |
+
axis_labels[1][axis] += 0.3
|
| 219 |
+
a_str = ['X', 'Y', 'Z'][axis]
|
| 220 |
+
self.draw_text("-" + a_str, axis_labels[0], color)
|
| 221 |
+
self.draw_text("+" + a_str, axis_labels[1], color)
|
| 222 |
+
|
| 223 |
+
def draw_tick_line(self, axis, color, radius, tick, labels_visible):
|
| 224 |
+
tick_axis = {0: 1, 1: 0, 2: 1}[axis]
|
| 225 |
+
tick_line = [[0, 0, 0], [0, 0, 0]]
|
| 226 |
+
tick_line[0][axis] = tick_line[1][axis] = tick
|
| 227 |
+
tick_line[0][tick_axis], tick_line[1][tick_axis] = -radius, radius
|
| 228 |
+
self.draw_line(tick_line, color)
|
| 229 |
+
if labels_visible:
|
| 230 |
+
self.draw_tick_line_label(axis, color, radius, tick)
|
| 231 |
+
|
| 232 |
+
def draw_tick_line_label(self, axis, color, radius, tick):
|
| 233 |
+
if not self._p._label_axes:
|
| 234 |
+
return
|
| 235 |
+
tick_label_vector = [0, 0, 0]
|
| 236 |
+
tick_label_vector[axis] = tick
|
| 237 |
+
tick_label_vector[{0: 1, 1: 0, 2: 1}[axis]] = [-1, 1, 1][
|
| 238 |
+
axis] * radius * 3.5
|
| 239 |
+
self.draw_text(str(tick), tick_label_vector, color, scale=0.5)
|
| 240 |
+
|
| 241 |
+
|
| 242 |
+
class PlotAxesFrame(PlotAxesBase):
|
| 243 |
+
|
| 244 |
+
def __init__(self, parent_axes):
|
| 245 |
+
super().__init__(parent_axes)
|
| 246 |
+
|
| 247 |
+
def draw_background(self, color):
|
| 248 |
+
pass
|
| 249 |
+
|
| 250 |
+
def draw_axis(self, axis, color):
|
| 251 |
+
raise NotImplementedError()
|
venv/lib/python3.14/site-packages/sympy/plotting/pygletplot/plot_camera.py
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pyglet.gl as pgl
|
| 2 |
+
from sympy.plotting.pygletplot.plot_rotation import get_spherical_rotatation
|
| 3 |
+
from sympy.plotting.pygletplot.util import get_model_matrix, model_to_screen, \
|
| 4 |
+
screen_to_model, vec_subs
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
class PlotCamera:
|
| 8 |
+
|
| 9 |
+
min_dist = 0.05
|
| 10 |
+
max_dist = 500.0
|
| 11 |
+
|
| 12 |
+
min_ortho_dist = 100.0
|
| 13 |
+
max_ortho_dist = 10000.0
|
| 14 |
+
|
| 15 |
+
_default_dist = 6.0
|
| 16 |
+
_default_ortho_dist = 600.0
|
| 17 |
+
|
| 18 |
+
rot_presets = {
|
| 19 |
+
'xy': (0, 0, 0),
|
| 20 |
+
'xz': (-90, 0, 0),
|
| 21 |
+
'yz': (0, 90, 0),
|
| 22 |
+
'perspective': (-45, 0, -45)
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
def __init__(self, window, ortho=False):
|
| 26 |
+
self.window = window
|
| 27 |
+
self.axes = self.window.plot.axes
|
| 28 |
+
self.ortho = ortho
|
| 29 |
+
self.reset()
|
| 30 |
+
|
| 31 |
+
def init_rot_matrix(self):
|
| 32 |
+
pgl.glPushMatrix()
|
| 33 |
+
pgl.glLoadIdentity()
|
| 34 |
+
self._rot = get_model_matrix()
|
| 35 |
+
pgl.glPopMatrix()
|
| 36 |
+
|
| 37 |
+
def set_rot_preset(self, preset_name):
|
| 38 |
+
self.init_rot_matrix()
|
| 39 |
+
if preset_name not in self.rot_presets:
|
| 40 |
+
raise ValueError(
|
| 41 |
+
"%s is not a valid rotation preset." % preset_name)
|
| 42 |
+
r = self.rot_presets[preset_name]
|
| 43 |
+
self.euler_rotate(r[0], 1, 0, 0)
|
| 44 |
+
self.euler_rotate(r[1], 0, 1, 0)
|
| 45 |
+
self.euler_rotate(r[2], 0, 0, 1)
|
| 46 |
+
|
| 47 |
+
def reset(self):
|
| 48 |
+
self._dist = 0.0
|
| 49 |
+
self._x, self._y = 0.0, 0.0
|
| 50 |
+
self._rot = None
|
| 51 |
+
if self.ortho:
|
| 52 |
+
self._dist = self._default_ortho_dist
|
| 53 |
+
else:
|
| 54 |
+
self._dist = self._default_dist
|
| 55 |
+
self.init_rot_matrix()
|
| 56 |
+
|
| 57 |
+
def mult_rot_matrix(self, rot):
|
| 58 |
+
pgl.glPushMatrix()
|
| 59 |
+
pgl.glLoadMatrixf(rot)
|
| 60 |
+
pgl.glMultMatrixf(self._rot)
|
| 61 |
+
self._rot = get_model_matrix()
|
| 62 |
+
pgl.glPopMatrix()
|
| 63 |
+
|
| 64 |
+
def setup_projection(self):
|
| 65 |
+
pgl.glMatrixMode(pgl.GL_PROJECTION)
|
| 66 |
+
pgl.glLoadIdentity()
|
| 67 |
+
if self.ortho:
|
| 68 |
+
# yep, this is pseudo ortho (don't tell anyone)
|
| 69 |
+
pgl.gluPerspective(
|
| 70 |
+
0.3, float(self.window.width)/float(self.window.height),
|
| 71 |
+
self.min_ortho_dist - 0.01, self.max_ortho_dist + 0.01)
|
| 72 |
+
else:
|
| 73 |
+
pgl.gluPerspective(
|
| 74 |
+
30.0, float(self.window.width)/float(self.window.height),
|
| 75 |
+
self.min_dist - 0.01, self.max_dist + 0.01)
|
| 76 |
+
pgl.glMatrixMode(pgl.GL_MODELVIEW)
|
| 77 |
+
|
| 78 |
+
def _get_scale(self):
|
| 79 |
+
return 1.0, 1.0, 1.0
|
| 80 |
+
|
| 81 |
+
def apply_transformation(self):
|
| 82 |
+
pgl.glLoadIdentity()
|
| 83 |
+
pgl.glTranslatef(self._x, self._y, -self._dist)
|
| 84 |
+
if self._rot is not None:
|
| 85 |
+
pgl.glMultMatrixf(self._rot)
|
| 86 |
+
pgl.glScalef(*self._get_scale())
|
| 87 |
+
|
| 88 |
+
def spherical_rotate(self, p1, p2, sensitivity=1.0):
|
| 89 |
+
mat = get_spherical_rotatation(p1, p2, self.window.width,
|
| 90 |
+
self.window.height, sensitivity)
|
| 91 |
+
if mat is not None:
|
| 92 |
+
self.mult_rot_matrix(mat)
|
| 93 |
+
|
| 94 |
+
def euler_rotate(self, angle, x, y, z):
|
| 95 |
+
pgl.glPushMatrix()
|
| 96 |
+
pgl.glLoadMatrixf(self._rot)
|
| 97 |
+
pgl.glRotatef(angle, x, y, z)
|
| 98 |
+
self._rot = get_model_matrix()
|
| 99 |
+
pgl.glPopMatrix()
|
| 100 |
+
|
| 101 |
+
def zoom_relative(self, clicks, sensitivity):
|
| 102 |
+
|
| 103 |
+
if self.ortho:
|
| 104 |
+
dist_d = clicks * sensitivity * 50.0
|
| 105 |
+
min_dist = self.min_ortho_dist
|
| 106 |
+
max_dist = self.max_ortho_dist
|
| 107 |
+
else:
|
| 108 |
+
dist_d = clicks * sensitivity
|
| 109 |
+
min_dist = self.min_dist
|
| 110 |
+
max_dist = self.max_dist
|
| 111 |
+
|
| 112 |
+
new_dist = (self._dist - dist_d)
|
| 113 |
+
if (clicks < 0 and new_dist < max_dist) or new_dist > min_dist:
|
| 114 |
+
self._dist = new_dist
|
| 115 |
+
|
| 116 |
+
def mouse_translate(self, x, y, dx, dy):
|
| 117 |
+
pgl.glPushMatrix()
|
| 118 |
+
pgl.glLoadIdentity()
|
| 119 |
+
pgl.glTranslatef(0, 0, -self._dist)
|
| 120 |
+
z = model_to_screen(0, 0, 0)[2]
|
| 121 |
+
d = vec_subs(screen_to_model(x, y, z), screen_to_model(x - dx, y - dy, z))
|
| 122 |
+
pgl.glPopMatrix()
|
| 123 |
+
self._x += d[0]
|
| 124 |
+
self._y += d[1]
|
venv/lib/python3.14/site-packages/sympy/plotting/pygletplot/plot_controller.py
ADDED
|
@@ -0,0 +1,218 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from pyglet.window import key
|
| 2 |
+
from pyglet.window.mouse import LEFT, RIGHT, MIDDLE
|
| 3 |
+
from sympy.plotting.pygletplot.util import get_direction_vectors, get_basis_vectors
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
class PlotController:
|
| 7 |
+
|
| 8 |
+
normal_mouse_sensitivity = 4.0
|
| 9 |
+
modified_mouse_sensitivity = 1.0
|
| 10 |
+
|
| 11 |
+
normal_key_sensitivity = 160.0
|
| 12 |
+
modified_key_sensitivity = 40.0
|
| 13 |
+
|
| 14 |
+
keymap = {
|
| 15 |
+
key.LEFT: 'left',
|
| 16 |
+
key.A: 'left',
|
| 17 |
+
key.NUM_4: 'left',
|
| 18 |
+
|
| 19 |
+
key.RIGHT: 'right',
|
| 20 |
+
key.D: 'right',
|
| 21 |
+
key.NUM_6: 'right',
|
| 22 |
+
|
| 23 |
+
key.UP: 'up',
|
| 24 |
+
key.W: 'up',
|
| 25 |
+
key.NUM_8: 'up',
|
| 26 |
+
|
| 27 |
+
key.DOWN: 'down',
|
| 28 |
+
key.S: 'down',
|
| 29 |
+
key.NUM_2: 'down',
|
| 30 |
+
|
| 31 |
+
key.Z: 'rotate_z_neg',
|
| 32 |
+
key.NUM_1: 'rotate_z_neg',
|
| 33 |
+
|
| 34 |
+
key.C: 'rotate_z_pos',
|
| 35 |
+
key.NUM_3: 'rotate_z_pos',
|
| 36 |
+
|
| 37 |
+
key.Q: 'spin_left',
|
| 38 |
+
key.NUM_7: 'spin_left',
|
| 39 |
+
key.E: 'spin_right',
|
| 40 |
+
key.NUM_9: 'spin_right',
|
| 41 |
+
|
| 42 |
+
key.X: 'reset_camera',
|
| 43 |
+
key.NUM_5: 'reset_camera',
|
| 44 |
+
|
| 45 |
+
key.NUM_ADD: 'zoom_in',
|
| 46 |
+
key.PAGEUP: 'zoom_in',
|
| 47 |
+
key.R: 'zoom_in',
|
| 48 |
+
|
| 49 |
+
key.NUM_SUBTRACT: 'zoom_out',
|
| 50 |
+
key.PAGEDOWN: 'zoom_out',
|
| 51 |
+
key.F: 'zoom_out',
|
| 52 |
+
|
| 53 |
+
key.RSHIFT: 'modify_sensitivity',
|
| 54 |
+
key.LSHIFT: 'modify_sensitivity',
|
| 55 |
+
|
| 56 |
+
key.F1: 'rot_preset_xy',
|
| 57 |
+
key.F2: 'rot_preset_xz',
|
| 58 |
+
key.F3: 'rot_preset_yz',
|
| 59 |
+
key.F4: 'rot_preset_perspective',
|
| 60 |
+
|
| 61 |
+
key.F5: 'toggle_axes',
|
| 62 |
+
key.F6: 'toggle_axe_colors',
|
| 63 |
+
|
| 64 |
+
key.F8: 'save_image'
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
def __init__(self, window, *, invert_mouse_zoom=False, **kwargs):
|
| 68 |
+
self.invert_mouse_zoom = invert_mouse_zoom
|
| 69 |
+
self.window = window
|
| 70 |
+
self.camera = window.camera
|
| 71 |
+
self.action = {
|
| 72 |
+
# Rotation around the view Y (up) vector
|
| 73 |
+
'left': False,
|
| 74 |
+
'right': False,
|
| 75 |
+
# Rotation around the view X vector
|
| 76 |
+
'up': False,
|
| 77 |
+
'down': False,
|
| 78 |
+
# Rotation around the view Z vector
|
| 79 |
+
'spin_left': False,
|
| 80 |
+
'spin_right': False,
|
| 81 |
+
# Rotation around the model Z vector
|
| 82 |
+
'rotate_z_neg': False,
|
| 83 |
+
'rotate_z_pos': False,
|
| 84 |
+
# Reset to the default rotation
|
| 85 |
+
'reset_camera': False,
|
| 86 |
+
# Performs camera z-translation
|
| 87 |
+
'zoom_in': False,
|
| 88 |
+
'zoom_out': False,
|
| 89 |
+
# Use alternative sensitivity (speed)
|
| 90 |
+
'modify_sensitivity': False,
|
| 91 |
+
# Rotation presets
|
| 92 |
+
'rot_preset_xy': False,
|
| 93 |
+
'rot_preset_xz': False,
|
| 94 |
+
'rot_preset_yz': False,
|
| 95 |
+
'rot_preset_perspective': False,
|
| 96 |
+
# axes
|
| 97 |
+
'toggle_axes': False,
|
| 98 |
+
'toggle_axe_colors': False,
|
| 99 |
+
# screenshot
|
| 100 |
+
'save_image': False
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
def update(self, dt):
|
| 104 |
+
z = 0
|
| 105 |
+
if self.action['zoom_out']:
|
| 106 |
+
z -= 1
|
| 107 |
+
if self.action['zoom_in']:
|
| 108 |
+
z += 1
|
| 109 |
+
if z != 0:
|
| 110 |
+
self.camera.zoom_relative(z/10.0, self.get_key_sensitivity()/10.0)
|
| 111 |
+
|
| 112 |
+
dx, dy, dz = 0, 0, 0
|
| 113 |
+
if self.action['left']:
|
| 114 |
+
dx -= 1
|
| 115 |
+
if self.action['right']:
|
| 116 |
+
dx += 1
|
| 117 |
+
if self.action['up']:
|
| 118 |
+
dy -= 1
|
| 119 |
+
if self.action['down']:
|
| 120 |
+
dy += 1
|
| 121 |
+
if self.action['spin_left']:
|
| 122 |
+
dz += 1
|
| 123 |
+
if self.action['spin_right']:
|
| 124 |
+
dz -= 1
|
| 125 |
+
|
| 126 |
+
if not self.is_2D():
|
| 127 |
+
if dx != 0:
|
| 128 |
+
self.camera.euler_rotate(dx*dt*self.get_key_sensitivity(),
|
| 129 |
+
*(get_direction_vectors()[1]))
|
| 130 |
+
if dy != 0:
|
| 131 |
+
self.camera.euler_rotate(dy*dt*self.get_key_sensitivity(),
|
| 132 |
+
*(get_direction_vectors()[0]))
|
| 133 |
+
if dz != 0:
|
| 134 |
+
self.camera.euler_rotate(dz*dt*self.get_key_sensitivity(),
|
| 135 |
+
*(get_direction_vectors()[2]))
|
| 136 |
+
else:
|
| 137 |
+
self.camera.mouse_translate(0, 0, dx*dt*self.get_key_sensitivity(),
|
| 138 |
+
-dy*dt*self.get_key_sensitivity())
|
| 139 |
+
|
| 140 |
+
rz = 0
|
| 141 |
+
if self.action['rotate_z_neg'] and not self.is_2D():
|
| 142 |
+
rz -= 1
|
| 143 |
+
if self.action['rotate_z_pos'] and not self.is_2D():
|
| 144 |
+
rz += 1
|
| 145 |
+
|
| 146 |
+
if rz != 0:
|
| 147 |
+
self.camera.euler_rotate(rz*dt*self.get_key_sensitivity(),
|
| 148 |
+
*(get_basis_vectors()[2]))
|
| 149 |
+
|
| 150 |
+
if self.action['reset_camera']:
|
| 151 |
+
self.camera.reset()
|
| 152 |
+
|
| 153 |
+
if self.action['rot_preset_xy']:
|
| 154 |
+
self.camera.set_rot_preset('xy')
|
| 155 |
+
if self.action['rot_preset_xz']:
|
| 156 |
+
self.camera.set_rot_preset('xz')
|
| 157 |
+
if self.action['rot_preset_yz']:
|
| 158 |
+
self.camera.set_rot_preset('yz')
|
| 159 |
+
if self.action['rot_preset_perspective']:
|
| 160 |
+
self.camera.set_rot_preset('perspective')
|
| 161 |
+
|
| 162 |
+
if self.action['toggle_axes']:
|
| 163 |
+
self.action['toggle_axes'] = False
|
| 164 |
+
self.camera.axes.toggle_visible()
|
| 165 |
+
|
| 166 |
+
if self.action['toggle_axe_colors']:
|
| 167 |
+
self.action['toggle_axe_colors'] = False
|
| 168 |
+
self.camera.axes.toggle_colors()
|
| 169 |
+
|
| 170 |
+
if self.action['save_image']:
|
| 171 |
+
self.action['save_image'] = False
|
| 172 |
+
self.window.plot.saveimage()
|
| 173 |
+
|
| 174 |
+
return True
|
| 175 |
+
|
| 176 |
+
def get_mouse_sensitivity(self):
|
| 177 |
+
if self.action['modify_sensitivity']:
|
| 178 |
+
return self.modified_mouse_sensitivity
|
| 179 |
+
else:
|
| 180 |
+
return self.normal_mouse_sensitivity
|
| 181 |
+
|
| 182 |
+
def get_key_sensitivity(self):
|
| 183 |
+
if self.action['modify_sensitivity']:
|
| 184 |
+
return self.modified_key_sensitivity
|
| 185 |
+
else:
|
| 186 |
+
return self.normal_key_sensitivity
|
| 187 |
+
|
| 188 |
+
def on_key_press(self, symbol, modifiers):
|
| 189 |
+
if symbol in self.keymap:
|
| 190 |
+
self.action[self.keymap[symbol]] = True
|
| 191 |
+
|
| 192 |
+
def on_key_release(self, symbol, modifiers):
|
| 193 |
+
if symbol in self.keymap:
|
| 194 |
+
self.action[self.keymap[symbol]] = False
|
| 195 |
+
|
| 196 |
+
def on_mouse_drag(self, x, y, dx, dy, buttons, modifiers):
|
| 197 |
+
if buttons & LEFT:
|
| 198 |
+
if self.is_2D():
|
| 199 |
+
self.camera.mouse_translate(x, y, dx, dy)
|
| 200 |
+
else:
|
| 201 |
+
self.camera.spherical_rotate((x - dx, y - dy), (x, y),
|
| 202 |
+
self.get_mouse_sensitivity())
|
| 203 |
+
if buttons & MIDDLE:
|
| 204 |
+
self.camera.zoom_relative([1, -1][self.invert_mouse_zoom]*dy,
|
| 205 |
+
self.get_mouse_sensitivity()/20.0)
|
| 206 |
+
if buttons & RIGHT:
|
| 207 |
+
self.camera.mouse_translate(x, y, dx, dy)
|
| 208 |
+
|
| 209 |
+
def on_mouse_scroll(self, x, y, dx, dy):
|
| 210 |
+
self.camera.zoom_relative([1, -1][self.invert_mouse_zoom]*dy,
|
| 211 |
+
self.get_mouse_sensitivity())
|
| 212 |
+
|
| 213 |
+
def is_2D(self):
|
| 214 |
+
functions = self.window.plot._functions
|
| 215 |
+
for i in functions:
|
| 216 |
+
if len(functions[i].i_vars) > 1 or len(functions[i].d_vars) > 2:
|
| 217 |
+
return False
|
| 218 |
+
return True
|
venv/lib/python3.14/site-packages/sympy/plotting/pygletplot/plot_curve.py
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pyglet.gl as pgl
|
| 2 |
+
from sympy.core import S
|
| 3 |
+
from sympy.plotting.pygletplot.plot_mode_base import PlotModeBase
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
class PlotCurve(PlotModeBase):
|
| 7 |
+
|
| 8 |
+
style_override = 'wireframe'
|
| 9 |
+
|
| 10 |
+
def _on_calculate_verts(self):
|
| 11 |
+
self.t_interval = self.intervals[0]
|
| 12 |
+
self.t_set = list(self.t_interval.frange())
|
| 13 |
+
self.bounds = [[S.Infinity, S.NegativeInfinity, 0],
|
| 14 |
+
[S.Infinity, S.NegativeInfinity, 0],
|
| 15 |
+
[S.Infinity, S.NegativeInfinity, 0]]
|
| 16 |
+
evaluate = self._get_evaluator()
|
| 17 |
+
|
| 18 |
+
self._calculating_verts_pos = 0.0
|
| 19 |
+
self._calculating_verts_len = float(self.t_interval.v_len)
|
| 20 |
+
|
| 21 |
+
self.verts = []
|
| 22 |
+
b = self.bounds
|
| 23 |
+
for t in self.t_set:
|
| 24 |
+
try:
|
| 25 |
+
_e = evaluate(t) # calculate vertex
|
| 26 |
+
except (NameError, ZeroDivisionError):
|
| 27 |
+
_e = None
|
| 28 |
+
if _e is not None: # update bounding box
|
| 29 |
+
for axis in range(3):
|
| 30 |
+
b[axis][0] = min([b[axis][0], _e[axis]])
|
| 31 |
+
b[axis][1] = max([b[axis][1], _e[axis]])
|
| 32 |
+
self.verts.append(_e)
|
| 33 |
+
self._calculating_verts_pos += 1.0
|
| 34 |
+
|
| 35 |
+
for axis in range(3):
|
| 36 |
+
b[axis][2] = b[axis][1] - b[axis][0]
|
| 37 |
+
if b[axis][2] == 0.0:
|
| 38 |
+
b[axis][2] = 1.0
|
| 39 |
+
|
| 40 |
+
self.push_wireframe(self.draw_verts(False))
|
| 41 |
+
|
| 42 |
+
def _on_calculate_cverts(self):
|
| 43 |
+
if not self.verts or not self.color:
|
| 44 |
+
return
|
| 45 |
+
|
| 46 |
+
def set_work_len(n):
|
| 47 |
+
self._calculating_cverts_len = float(n)
|
| 48 |
+
|
| 49 |
+
def inc_work_pos():
|
| 50 |
+
self._calculating_cverts_pos += 1.0
|
| 51 |
+
set_work_len(1)
|
| 52 |
+
self._calculating_cverts_pos = 0
|
| 53 |
+
self.cverts = self.color.apply_to_curve(self.verts,
|
| 54 |
+
self.t_set,
|
| 55 |
+
set_len=set_work_len,
|
| 56 |
+
inc_pos=inc_work_pos)
|
| 57 |
+
self.push_wireframe(self.draw_verts(True))
|
| 58 |
+
|
| 59 |
+
def calculate_one_cvert(self, t):
|
| 60 |
+
vert = self.verts[t]
|
| 61 |
+
return self.color(vert[0], vert[1], vert[2],
|
| 62 |
+
self.t_set[t], None)
|
| 63 |
+
|
| 64 |
+
def draw_verts(self, use_cverts):
|
| 65 |
+
def f():
|
| 66 |
+
pgl.glBegin(pgl.GL_LINE_STRIP)
|
| 67 |
+
for t in range(len(self.t_set)):
|
| 68 |
+
p = self.verts[t]
|
| 69 |
+
if p is None:
|
| 70 |
+
pgl.glEnd()
|
| 71 |
+
pgl.glBegin(pgl.GL_LINE_STRIP)
|
| 72 |
+
continue
|
| 73 |
+
if use_cverts:
|
| 74 |
+
c = self.cverts[t]
|
| 75 |
+
if c is None:
|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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from sympy.core.singleton import S
|
| 2 |
+
from sympy.core.symbol import Symbol
|
| 3 |
+
from sympy.core.sympify import sympify
|
| 4 |
+
from sympy.core.numbers import Integer
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
class PlotInterval:
|
| 8 |
+
"""
|
| 9 |
+
"""
|
| 10 |
+
_v, _v_min, _v_max, _v_steps = None, None, None, None
|
| 11 |
+
|
| 12 |
+
def require_all_args(f):
|
| 13 |
+
def check(self, *args, **kwargs):
|
| 14 |
+
for g in [self._v, self._v_min, self._v_max, self._v_steps]:
|
| 15 |
+
if g is None:
|
| 16 |
+
raise ValueError("PlotInterval is incomplete.")
|
| 17 |
+
return f(self, *args, **kwargs)
|
| 18 |
+
return check
|
| 19 |
+
|
| 20 |
+
def __init__(self, *args):
|
| 21 |
+
if len(args) == 1:
|
| 22 |
+
if isinstance(args[0], PlotInterval):
|
| 23 |
+
self.fill_from(args[0])
|
| 24 |
+
return
|
| 25 |
+
elif isinstance(args[0], str):
|
| 26 |
+
try:
|
| 27 |
+
args = eval(args[0])
|
| 28 |
+
except TypeError:
|
| 29 |
+
s_eval_error = "Could not interpret string %s."
|
| 30 |
+
raise ValueError(s_eval_error % (args[0]))
|
| 31 |
+
elif isinstance(args[0], (tuple, list)):
|
| 32 |
+
args = args[0]
|
| 33 |
+
else:
|
| 34 |
+
raise ValueError("Not an interval.")
|
| 35 |
+
if not isinstance(args, (tuple, list)) or len(args) > 4:
|
| 36 |
+
f_error = "PlotInterval must be a tuple or list of length 4 or less."
|
| 37 |
+
raise ValueError(f_error)
|
| 38 |
+
|
| 39 |
+
args = list(args)
|
| 40 |
+
if len(args) > 0 and (args[0] is None or isinstance(args[0], Symbol)):
|
| 41 |
+
self.v = args.pop(0)
|
| 42 |
+
if len(args) in [2, 3]:
|
| 43 |
+
self.v_min = args.pop(0)
|
| 44 |
+
self.v_max = args.pop(0)
|
| 45 |
+
if len(args) == 1:
|
| 46 |
+
self.v_steps = args.pop(0)
|
| 47 |
+
elif len(args) == 1:
|
| 48 |
+
self.v_steps = args.pop(0)
|
| 49 |
+
|
| 50 |
+
def get_v(self):
|
| 51 |
+
return self._v
|
| 52 |
+
|
| 53 |
+
def set_v(self, v):
|
| 54 |
+
if v is None:
|
| 55 |
+
self._v = None
|
| 56 |
+
return
|
| 57 |
+
if not isinstance(v, Symbol):
|
| 58 |
+
raise ValueError("v must be a SymPy Symbol.")
|
| 59 |
+
self._v = v
|
| 60 |
+
|
| 61 |
+
def get_v_min(self):
|
| 62 |
+
return self._v_min
|
| 63 |
+
|
| 64 |
+
def set_v_min(self, v_min):
|
| 65 |
+
if v_min is None:
|
| 66 |
+
self._v_min = None
|
| 67 |
+
return
|
| 68 |
+
try:
|
| 69 |
+
self._v_min = sympify(v_min)
|
| 70 |
+
float(self._v_min.evalf())
|
| 71 |
+
except TypeError:
|
| 72 |
+
raise ValueError("v_min could not be interpreted as a number.")
|
| 73 |
+
|
| 74 |
+
def get_v_max(self):
|
| 75 |
+
return self._v_max
|
| 76 |
+
|
| 77 |
+
def set_v_max(self, v_max):
|
| 78 |
+
if v_max is None:
|
| 79 |
+
self._v_max = None
|
| 80 |
+
return
|
| 81 |
+
try:
|
| 82 |
+
self._v_max = sympify(v_max)
|
| 83 |
+
float(self._v_max.evalf())
|
| 84 |
+
except TypeError:
|
| 85 |
+
raise ValueError("v_max could not be interpreted as a number.")
|
| 86 |
+
|
| 87 |
+
def get_v_steps(self):
|
| 88 |
+
return self._v_steps
|
| 89 |
+
|
| 90 |
+
def set_v_steps(self, v_steps):
|
| 91 |
+
if v_steps is None:
|
| 92 |
+
self._v_steps = None
|
| 93 |
+
return
|
| 94 |
+
if isinstance(v_steps, int):
|
| 95 |
+
v_steps = Integer(v_steps)
|
| 96 |
+
elif not isinstance(v_steps, Integer):
|
| 97 |
+
raise ValueError("v_steps must be an int or SymPy Integer.")
|
| 98 |
+
if v_steps <= S.Zero:
|
| 99 |
+
raise ValueError("v_steps must be positive.")
|
| 100 |
+
self._v_steps = v_steps
|
| 101 |
+
|
| 102 |
+
@require_all_args
|
| 103 |
+
def get_v_len(self):
|
| 104 |
+
return self.v_steps + 1
|
| 105 |
+
|
| 106 |
+
v = property(get_v, set_v)
|
| 107 |
+
v_min = property(get_v_min, set_v_min)
|
| 108 |
+
v_max = property(get_v_max, set_v_max)
|
| 109 |
+
v_steps = property(get_v_steps, set_v_steps)
|
| 110 |
+
v_len = property(get_v_len)
|
| 111 |
+
|
| 112 |
+
def fill_from(self, b):
|
| 113 |
+
if b.v is not None:
|
| 114 |
+
self.v = b.v
|
| 115 |
+
if b.v_min is not None:
|
| 116 |
+
self.v_min = b.v_min
|
| 117 |
+
if b.v_max is not None:
|
| 118 |
+
self.v_max = b.v_max
|
| 119 |
+
if b.v_steps is not None:
|
| 120 |
+
self.v_steps = b.v_steps
|
| 121 |
+
|
| 122 |
+
@staticmethod
|
| 123 |
+
def try_parse(*args):
|
| 124 |
+
"""
|
| 125 |
+
Returns a PlotInterval if args can be interpreted
|
| 126 |
+
as such, otherwise None.
|
| 127 |
+
"""
|
| 128 |
+
if len(args) == 1 and isinstance(args[0], PlotInterval):
|
| 129 |
+
return args[0]
|
| 130 |
+
try:
|
| 131 |
+
return PlotInterval(*args)
|
| 132 |
+
except ValueError:
|
| 133 |
+
return None
|
| 134 |
+
|
| 135 |
+
def _str_base(self):
|
| 136 |
+
return ",".join([str(self.v), str(self.v_min),
|
| 137 |
+
str(self.v_max), str(self.v_steps)])
|
| 138 |
+
|
| 139 |
+
def __repr__(self):
|
| 140 |
+
"""
|
| 141 |
+
A string representing the interval in class constructor form.
|
| 142 |
+
"""
|
| 143 |
+
return "PlotInterval(%s)" % (self._str_base())
|
| 144 |
+
|
| 145 |
+
def __str__(self):
|
| 146 |
+
"""
|
| 147 |
+
A string representing the interval in list form.
|
| 148 |
+
"""
|
| 149 |
+
return "[%s]" % (self._str_base())
|
| 150 |
+
|
| 151 |
+
@require_all_args
|
| 152 |
+
def assert_complete(self):
|
| 153 |
+
pass
|
| 154 |
+
|
| 155 |
+
@require_all_args
|
| 156 |
+
def vrange(self):
|
| 157 |
+
"""
|
| 158 |
+
Yields v_steps+1 SymPy numbers ranging from
|
| 159 |
+
v_min to v_max.
|
| 160 |
+
"""
|
| 161 |
+
d = (self.v_max - self.v_min) / self.v_steps
|
| 162 |
+
for i in range(self.v_steps + 1):
|
| 163 |
+
a = self.v_min + (d * Integer(i))
|
| 164 |
+
yield a
|
| 165 |
+
|
| 166 |
+
@require_all_args
|
| 167 |
+
def vrange2(self):
|
| 168 |
+
"""
|
| 169 |
+
Yields v_steps pairs of SymPy numbers ranging from
|
| 170 |
+
(v_min, v_min + step) to (v_max - step, v_max).
|
| 171 |
+
"""
|
| 172 |
+
d = (self.v_max - self.v_min) / self.v_steps
|
| 173 |
+
a = self.v_min + (d * S.Zero)
|
| 174 |
+
for i in range(self.v_steps):
|
| 175 |
+
b = self.v_min + (d * Integer(i + 1))
|
| 176 |
+
yield a, b
|
| 177 |
+
a = b
|
| 178 |
+
|
| 179 |
+
def frange(self):
|
| 180 |
+
for i in self.vrange():
|
| 181 |
+
yield float(i.evalf())
|
venv/lib/python3.14/site-packages/sympy/plotting/pygletplot/plot_mode.py
ADDED
|
@@ -0,0 +1,400 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from .plot_interval import PlotInterval
|
| 2 |
+
from .plot_object import PlotObject
|
| 3 |
+
from .util import parse_option_string
|
| 4 |
+
from sympy.core.symbol import Symbol
|
| 5 |
+
from sympy.core.sympify import sympify
|
| 6 |
+
from sympy.geometry.entity import GeometryEntity
|
| 7 |
+
from sympy.utilities.iterables import is_sequence
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
class PlotMode(PlotObject):
|
| 11 |
+
"""
|
| 12 |
+
Grandparent class for plotting
|
| 13 |
+
modes. Serves as interface for
|
| 14 |
+
registration, lookup, and init
|
| 15 |
+
of modes.
|
| 16 |
+
|
| 17 |
+
To create a new plot mode,
|
| 18 |
+
inherit from PlotModeBase
|
| 19 |
+
or one of its children, such
|
| 20 |
+
as PlotSurface or PlotCurve.
|
| 21 |
+
"""
|
| 22 |
+
|
| 23 |
+
## Class-level attributes
|
| 24 |
+
## used to register and lookup
|
| 25 |
+
## plot modes. See PlotModeBase
|
| 26 |
+
## for descriptions and usage.
|
| 27 |
+
|
| 28 |
+
i_vars, d_vars = '', ''
|
| 29 |
+
intervals = []
|
| 30 |
+
aliases = []
|
| 31 |
+
is_default = False
|
| 32 |
+
|
| 33 |
+
## Draw is the only method here which
|
| 34 |
+
## is meant to be overridden in child
|
| 35 |
+
## classes, and PlotModeBase provides
|
| 36 |
+
## a base implementation.
|
| 37 |
+
def draw(self):
|
| 38 |
+
raise NotImplementedError()
|
| 39 |
+
|
| 40 |
+
## Everything else in this file has to
|
| 41 |
+
## do with registration and retrieval
|
| 42 |
+
## of plot modes. This is where I've
|
| 43 |
+
## hidden much of the ugliness of automatic
|
| 44 |
+
## plot mode divination...
|
| 45 |
+
|
| 46 |
+
## Plot mode registry data structures
|
| 47 |
+
_mode_alias_list = []
|
| 48 |
+
_mode_map = {
|
| 49 |
+
1: {1: {}, 2: {}},
|
| 50 |
+
2: {1: {}, 2: {}},
|
| 51 |
+
3: {1: {}, 2: {}},
|
| 52 |
+
} # [d][i][alias_str]: class
|
| 53 |
+
_mode_default_map = {
|
| 54 |
+
1: {},
|
| 55 |
+
2: {},
|
| 56 |
+
3: {},
|
| 57 |
+
} # [d][i]: class
|
| 58 |
+
_i_var_max, _d_var_max = 2, 3
|
| 59 |
+
|
| 60 |
+
def __new__(cls, *args, **kwargs):
|
| 61 |
+
"""
|
| 62 |
+
This is the function which interprets
|
| 63 |
+
arguments given to Plot.__init__ and
|
| 64 |
+
Plot.__setattr__. Returns an initialized
|
| 65 |
+
instance of the appropriate child class.
|
| 66 |
+
"""
|
| 67 |
+
|
| 68 |
+
newargs, newkwargs = PlotMode._extract_options(args, kwargs)
|
| 69 |
+
mode_arg = newkwargs.get('mode', '')
|
| 70 |
+
|
| 71 |
+
# Interpret the arguments
|
| 72 |
+
d_vars, intervals = PlotMode._interpret_args(newargs)
|
| 73 |
+
i_vars = PlotMode._find_i_vars(d_vars, intervals)
|
| 74 |
+
i, d = max([len(i_vars), len(intervals)]), len(d_vars)
|
| 75 |
+
|
| 76 |
+
# Find the appropriate mode
|
| 77 |
+
subcls = PlotMode._get_mode(mode_arg, i, d)
|
| 78 |
+
|
| 79 |
+
# Create the object
|
| 80 |
+
o = object.__new__(subcls)
|
| 81 |
+
|
| 82 |
+
# Do some setup for the mode instance
|
| 83 |
+
o.d_vars = d_vars
|
| 84 |
+
o._fill_i_vars(i_vars)
|
| 85 |
+
o._fill_intervals(intervals)
|
| 86 |
+
o.options = newkwargs
|
| 87 |
+
|
| 88 |
+
return o
|
| 89 |
+
|
| 90 |
+
@staticmethod
|
| 91 |
+
def _get_mode(mode_arg, i_var_count, d_var_count):
|
| 92 |
+
"""
|
| 93 |
+
Tries to return an appropriate mode class.
|
| 94 |
+
Intended to be called only by __new__.
|
| 95 |
+
|
| 96 |
+
mode_arg
|
| 97 |
+
Can be a string or a class. If it is a
|
| 98 |
+
PlotMode subclass, it is simply returned.
|
| 99 |
+
If it is a string, it can an alias for
|
| 100 |
+
a mode or an empty string. In the latter
|
| 101 |
+
case, we try to find a default mode for
|
| 102 |
+
the i_var_count and d_var_count.
|
| 103 |
+
|
| 104 |
+
i_var_count
|
| 105 |
+
The number of independent variables
|
| 106 |
+
needed to evaluate the d_vars.
|
| 107 |
+
|
| 108 |
+
d_var_count
|
| 109 |
+
The number of dependent variables;
|
| 110 |
+
usually the number of functions to
|
| 111 |
+
be evaluated in plotting.
|
| 112 |
+
|
| 113 |
+
For example, a Cartesian function y = f(x) has
|
| 114 |
+
one i_var (x) and one d_var (y). A parametric
|
| 115 |
+
form x,y,z = f(u,v), f(u,v), f(u,v) has two
|
| 116 |
+
two i_vars (u,v) and three d_vars (x,y,z).
|
| 117 |
+
"""
|
| 118 |
+
# if the mode_arg is simply a PlotMode class,
|
| 119 |
+
# check that the mode supports the numbers
|
| 120 |
+
# of independent and dependent vars, then
|
| 121 |
+
# return it
|
| 122 |
+
try:
|
| 123 |
+
m = None
|
| 124 |
+
if issubclass(mode_arg, PlotMode):
|
| 125 |
+
m = mode_arg
|
| 126 |
+
except TypeError:
|
| 127 |
+
pass
|
| 128 |
+
if m:
|
| 129 |
+
if not m._was_initialized:
|
| 130 |
+
raise ValueError(("To use unregistered plot mode %s "
|
| 131 |
+
"you must first call %s._init_mode().")
|
| 132 |
+
% (m.__name__, m.__name__))
|
| 133 |
+
if d_var_count != m.d_var_count:
|
| 134 |
+
raise ValueError(("%s can only plot functions "
|
| 135 |
+
"with %i dependent variables.")
|
| 136 |
+
% (m.__name__,
|
| 137 |
+
m.d_var_count))
|
| 138 |
+
if i_var_count > m.i_var_count:
|
| 139 |
+
raise ValueError(("%s cannot plot functions "
|
| 140 |
+
"with more than %i independent "
|
| 141 |
+
"variables.")
|
| 142 |
+
% (m.__name__,
|
| 143 |
+
m.i_var_count))
|
| 144 |
+
return m
|
| 145 |
+
# If it is a string, there are two possibilities.
|
| 146 |
+
if isinstance(mode_arg, str):
|
| 147 |
+
i, d = i_var_count, d_var_count
|
| 148 |
+
if i > PlotMode._i_var_max:
|
| 149 |
+
raise ValueError(var_count_error(True, True))
|
| 150 |
+
if d > PlotMode._d_var_max:
|
| 151 |
+
raise ValueError(var_count_error(False, True))
|
| 152 |
+
# If the string is '', try to find a suitable
|
| 153 |
+
# default mode
|
| 154 |
+
if not mode_arg:
|
| 155 |
+
return PlotMode._get_default_mode(i, d)
|
| 156 |
+
# Otherwise, interpret the string as a mode
|
| 157 |
+
# alias (e.g. 'cartesian', 'parametric', etc)
|
| 158 |
+
else:
|
| 159 |
+
return PlotMode._get_aliased_mode(mode_arg, i, d)
|
| 160 |
+
else:
|
| 161 |
+
raise ValueError("PlotMode argument must be "
|
| 162 |
+
"a class or a string")
|
| 163 |
+
|
| 164 |
+
@staticmethod
|
| 165 |
+
def _get_default_mode(i, d, i_vars=-1):
|
| 166 |
+
if i_vars == -1:
|
| 167 |
+
i_vars = i
|
| 168 |
+
try:
|
| 169 |
+
return PlotMode._mode_default_map[d][i]
|
| 170 |
+
except KeyError:
|
| 171 |
+
# Keep looking for modes in higher i var counts
|
| 172 |
+
# which support the given d var count until we
|
| 173 |
+
# reach the max i_var count.
|
| 174 |
+
if i < PlotMode._i_var_max:
|
| 175 |
+
return PlotMode._get_default_mode(i + 1, d, i_vars)
|
| 176 |
+
else:
|
| 177 |
+
raise ValueError(("Couldn't find a default mode "
|
| 178 |
+
"for %i independent and %i "
|
| 179 |
+
"dependent variables.") % (i_vars, d))
|
| 180 |
+
|
| 181 |
+
@staticmethod
|
| 182 |
+
def _get_aliased_mode(alias, i, d, i_vars=-1):
|
| 183 |
+
if i_vars == -1:
|
| 184 |
+
i_vars = i
|
| 185 |
+
if alias not in PlotMode._mode_alias_list:
|
| 186 |
+
raise ValueError(("Couldn't find a mode called"
|
| 187 |
+
" %s. Known modes: %s.")
|
| 188 |
+
% (alias, ", ".join(PlotMode._mode_alias_list)))
|
| 189 |
+
try:
|
| 190 |
+
return PlotMode._mode_map[d][i][alias]
|
| 191 |
+
except TypeError:
|
| 192 |
+
# Keep looking for modes in higher i var counts
|
| 193 |
+
# which support the given d var count and alias
|
| 194 |
+
# until we reach the max i_var count.
|
| 195 |
+
if i < PlotMode._i_var_max:
|
| 196 |
+
return PlotMode._get_aliased_mode(alias, i + 1, d, i_vars)
|
| 197 |
+
else:
|
| 198 |
+
raise ValueError(("Couldn't find a %s mode "
|
| 199 |
+
"for %i independent and %i "
|
| 200 |
+
"dependent variables.")
|
| 201 |
+
% (alias, i_vars, d))
|
| 202 |
+
|
| 203 |
+
@classmethod
|
| 204 |
+
def _register(cls):
|
| 205 |
+
"""
|
| 206 |
+
Called once for each user-usable plot mode.
|
| 207 |
+
For Cartesian2D, it is invoked after the
|
| 208 |
+
class definition: Cartesian2D._register()
|
| 209 |
+
"""
|
| 210 |
+
name = cls.__name__
|
| 211 |
+
cls._init_mode()
|
| 212 |
+
|
| 213 |
+
try:
|
| 214 |
+
i, d = cls.i_var_count, cls.d_var_count
|
| 215 |
+
# Add the mode to _mode_map under all
|
| 216 |
+
# given aliases
|
| 217 |
+
for a in cls.aliases:
|
| 218 |
+
if a not in PlotMode._mode_alias_list:
|
| 219 |
+
# Also track valid aliases, so
|
| 220 |
+
# we can quickly know when given
|
| 221 |
+
# an invalid one in _get_mode.
|
| 222 |
+
PlotMode._mode_alias_list.append(a)
|
| 223 |
+
PlotMode._mode_map[d][i][a] = cls
|
| 224 |
+
if cls.is_default:
|
| 225 |
+
# If this mode was marked as the
|
| 226 |
+
# default for this d,i combination,
|
| 227 |
+
# also set that.
|
| 228 |
+
PlotMode._mode_default_map[d][i] = cls
|
| 229 |
+
|
| 230 |
+
except Exception as e:
|
| 231 |
+
raise RuntimeError(("Failed to register "
|
| 232 |
+
"plot mode %s. Reason: %s")
|
| 233 |
+
% (name, (str(e))))
|
| 234 |
+
|
| 235 |
+
@classmethod
|
| 236 |
+
def _init_mode(cls):
|
| 237 |
+
"""
|
| 238 |
+
Initializes the plot mode based on
|
| 239 |
+
the 'mode-specific parameters' above.
|
| 240 |
+
Only intended to be called by
|
| 241 |
+
PlotMode._register(). To use a mode without
|
| 242 |
+
registering it, you can directly call
|
| 243 |
+
ModeSubclass._init_mode().
|
| 244 |
+
"""
|
| 245 |
+
def symbols_list(symbol_str):
|
| 246 |
+
return [Symbol(s) for s in symbol_str]
|
| 247 |
+
|
| 248 |
+
# Convert the vars strs into
|
| 249 |
+
# lists of symbols.
|
| 250 |
+
cls.i_vars = symbols_list(cls.i_vars)
|
| 251 |
+
cls.d_vars = symbols_list(cls.d_vars)
|
| 252 |
+
|
| 253 |
+
# Var count is used often, calculate
|
| 254 |
+
# it once here
|
| 255 |
+
cls.i_var_count = len(cls.i_vars)
|
| 256 |
+
cls.d_var_count = len(cls.d_vars)
|
| 257 |
+
|
| 258 |
+
if cls.i_var_count > PlotMode._i_var_max:
|
| 259 |
+
raise ValueError(var_count_error(True, False))
|
| 260 |
+
if cls.d_var_count > PlotMode._d_var_max:
|
| 261 |
+
raise ValueError(var_count_error(False, False))
|
| 262 |
+
|
| 263 |
+
# Try to use first alias as primary_alias
|
| 264 |
+
if len(cls.aliases) > 0:
|
| 265 |
+
cls.primary_alias = cls.aliases[0]
|
| 266 |
+
else:
|
| 267 |
+
cls.primary_alias = cls.__name__
|
| 268 |
+
|
| 269 |
+
di = cls.intervals
|
| 270 |
+
if len(di) != cls.i_var_count:
|
| 271 |
+
raise ValueError("Plot mode must provide a "
|
| 272 |
+
"default interval for each i_var.")
|
| 273 |
+
for i in range(cls.i_var_count):
|
| 274 |
+
# default intervals must be given [min,max,steps]
|
| 275 |
+
# (no var, but they must be in the same order as i_vars)
|
| 276 |
+
if len(di[i]) != 3:
|
| 277 |
+
raise ValueError("length should be equal to 3")
|
| 278 |
+
|
| 279 |
+
# Initialize an incomplete interval,
|
| 280 |
+
# to later be filled with a var when
|
| 281 |
+
# the mode is instantiated.
|
| 282 |
+
di[i] = PlotInterval(None, *di[i])
|
| 283 |
+
|
| 284 |
+
# To prevent people from using modes
|
| 285 |
+
# without these required fields set up.
|
| 286 |
+
cls._was_initialized = True
|
| 287 |
+
|
| 288 |
+
_was_initialized = False
|
| 289 |
+
|
| 290 |
+
## Initializer Helper Methods
|
| 291 |
+
|
| 292 |
+
@staticmethod
|
| 293 |
+
def _find_i_vars(functions, intervals):
|
| 294 |
+
i_vars = []
|
| 295 |
+
|
| 296 |
+
# First, collect i_vars in the
|
| 297 |
+
# order they are given in any
|
| 298 |
+
# intervals.
|
| 299 |
+
for i in intervals:
|
| 300 |
+
if i.v is None:
|
| 301 |
+
continue
|
| 302 |
+
elif i.v in i_vars:
|
| 303 |
+
raise ValueError(("Multiple intervals given "
|
| 304 |
+
"for %s.") % (str(i.v)))
|
| 305 |
+
i_vars.append(i.v)
|
| 306 |
+
|
| 307 |
+
# Then, find any remaining
|
| 308 |
+
# i_vars in given functions
|
| 309 |
+
# (aka d_vars)
|
| 310 |
+
for f in functions:
|
| 311 |
+
for a in f.free_symbols:
|
| 312 |
+
if a not in i_vars:
|
| 313 |
+
i_vars.append(a)
|
| 314 |
+
|
| 315 |
+
return i_vars
|
| 316 |
+
|
| 317 |
+
def _fill_i_vars(self, i_vars):
|
| 318 |
+
# copy default i_vars
|
| 319 |
+
self.i_vars = [Symbol(str(i)) for i in self.i_vars]
|
| 320 |
+
# replace with given i_vars
|
| 321 |
+
for i in range(len(i_vars)):
|
| 322 |
+
self.i_vars[i] = i_vars[i]
|
| 323 |
+
|
| 324 |
+
def _fill_intervals(self, intervals):
|
| 325 |
+
# copy default intervals
|
| 326 |
+
self.intervals = [PlotInterval(i) for i in self.intervals]
|
| 327 |
+
# track i_vars used so far
|
| 328 |
+
v_used = []
|
| 329 |
+
# fill copy of default
|
| 330 |
+
# intervals with given info
|
| 331 |
+
for i in range(len(intervals)):
|
| 332 |
+
self.intervals[i].fill_from(intervals[i])
|
| 333 |
+
if self.intervals[i].v is not None:
|
| 334 |
+
v_used.append(self.intervals[i].v)
|
| 335 |
+
# Find any orphan intervals and
|
| 336 |
+
# assign them i_vars
|
| 337 |
+
for i in range(len(self.intervals)):
|
| 338 |
+
if self.intervals[i].v is None:
|
| 339 |
+
u = [v for v in self.i_vars if v not in v_used]
|
| 340 |
+
if len(u) == 0:
|
| 341 |
+
raise ValueError("length should not be equal to 0")
|
| 342 |
+
self.intervals[i].v = u[0]
|
| 343 |
+
v_used.append(u[0])
|
| 344 |
+
|
| 345 |
+
@staticmethod
|
| 346 |
+
def _interpret_args(args):
|
| 347 |
+
interval_wrong_order = "PlotInterval %s was given before any function(s)."
|
| 348 |
+
interpret_error = "Could not interpret %s as a function or interval."
|
| 349 |
+
|
| 350 |
+
functions, intervals = [], []
|
| 351 |
+
if isinstance(args[0], GeometryEntity):
|
| 352 |
+
for coords in list(args[0].arbitrary_point()):
|
| 353 |
+
functions.append(coords)
|
| 354 |
+
intervals.append(PlotInterval.try_parse(args[0].plot_interval()))
|
| 355 |
+
else:
|
| 356 |
+
for a in args:
|
| 357 |
+
i = PlotInterval.try_parse(a)
|
| 358 |
+
if i is not None:
|
| 359 |
+
if len(functions) == 0:
|
| 360 |
+
raise ValueError(interval_wrong_order % (str(i)))
|
| 361 |
+
else:
|
| 362 |
+
intervals.append(i)
|
| 363 |
+
else:
|
| 364 |
+
if is_sequence(a, include=str):
|
| 365 |
+
raise ValueError(interpret_error % (str(a)))
|
| 366 |
+
try:
|
| 367 |
+
f = sympify(a)
|
| 368 |
+
functions.append(f)
|
| 369 |
+
except TypeError:
|
| 370 |
+
raise ValueError(interpret_error % str(a))
|
| 371 |
+
|
| 372 |
+
return functions, intervals
|
| 373 |
+
|
| 374 |
+
@staticmethod
|
| 375 |
+
def _extract_options(args, kwargs):
|
| 376 |
+
newkwargs, newargs = {}, []
|
| 377 |
+
for a in args:
|
| 378 |
+
if isinstance(a, str):
|
| 379 |
+
newkwargs = dict(newkwargs, **parse_option_string(a))
|
| 380 |
+
else:
|
| 381 |
+
newargs.append(a)
|
| 382 |
+
newkwargs = dict(newkwargs, **kwargs)
|
| 383 |
+
return newargs, newkwargs
|
| 384 |
+
|
| 385 |
+
|
| 386 |
+
def var_count_error(is_independent, is_plotting):
|
| 387 |
+
"""
|
| 388 |
+
Used to format an error message which differs
|
| 389 |
+
slightly in 4 places.
|
| 390 |
+
"""
|
| 391 |
+
if is_plotting:
|
| 392 |
+
v = "Plotting"
|
| 393 |
+
else:
|
| 394 |
+
v = "Registering plot modes"
|
| 395 |
+
if is_independent:
|
| 396 |
+
n, s = PlotMode._i_var_max, "independent"
|
| 397 |
+
else:
|
| 398 |
+
n, s = PlotMode._d_var_max, "dependent"
|
| 399 |
+
return ("%s with more than %i %s variables "
|
| 400 |
+
"is not supported.") % (v, n, s)
|
venv/lib/python3.14/site-packages/sympy/plotting/pygletplot/plot_mode_base.py
ADDED
|
@@ -0,0 +1,378 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pyglet.gl as pgl
|
| 2 |
+
from sympy.core import S
|
| 3 |
+
from sympy.plotting.pygletplot.color_scheme import ColorScheme
|
| 4 |
+
from sympy.plotting.pygletplot.plot_mode import PlotMode
|
| 5 |
+
from sympy.utilities.iterables import is_sequence
|
| 6 |
+
from time import sleep
|
| 7 |
+
from threading import Thread, Event, RLock
|
| 8 |
+
import warnings
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
class PlotModeBase(PlotMode):
|
| 12 |
+
"""
|
| 13 |
+
Intended parent class for plotting
|
| 14 |
+
modes. Provides base functionality
|
| 15 |
+
in conjunction with its parent,
|
| 16 |
+
PlotMode.
|
| 17 |
+
"""
|
| 18 |
+
|
| 19 |
+
##
|
| 20 |
+
## Class-Level Attributes
|
| 21 |
+
##
|
| 22 |
+
|
| 23 |
+
"""
|
| 24 |
+
The following attributes are meant
|
| 25 |
+
to be set at the class level, and serve
|
| 26 |
+
as parameters to the plot mode registry
|
| 27 |
+
(in PlotMode). See plot_modes.py for
|
| 28 |
+
concrete examples.
|
| 29 |
+
"""
|
| 30 |
+
|
| 31 |
+
"""
|
| 32 |
+
i_vars
|
| 33 |
+
'x' for Cartesian2D
|
| 34 |
+
'xy' for Cartesian3D
|
| 35 |
+
etc.
|
| 36 |
+
|
| 37 |
+
d_vars
|
| 38 |
+
'y' for Cartesian2D
|
| 39 |
+
'r' for Polar
|
| 40 |
+
etc.
|
| 41 |
+
"""
|
| 42 |
+
i_vars, d_vars = '', ''
|
| 43 |
+
|
| 44 |
+
"""
|
| 45 |
+
intervals
|
| 46 |
+
Default intervals for each i_var, and in the
|
| 47 |
+
same order. Specified [min, max, steps].
|
| 48 |
+
No variable can be given (it is bound later).
|
| 49 |
+
"""
|
| 50 |
+
intervals = []
|
| 51 |
+
|
| 52 |
+
"""
|
| 53 |
+
aliases
|
| 54 |
+
A list of strings which can be used to
|
| 55 |
+
access this mode.
|
| 56 |
+
'cartesian' for Cartesian2D and Cartesian3D
|
| 57 |
+
'polar' for Polar
|
| 58 |
+
'cylindrical', 'polar' for Cylindrical
|
| 59 |
+
|
| 60 |
+
Note that _init_mode chooses the first alias
|
| 61 |
+
in the list as the mode's primary_alias, which
|
| 62 |
+
will be displayed to the end user in certain
|
| 63 |
+
contexts.
|
| 64 |
+
"""
|
| 65 |
+
aliases = []
|
| 66 |
+
|
| 67 |
+
"""
|
| 68 |
+
is_default
|
| 69 |
+
Whether to set this mode as the default
|
| 70 |
+
for arguments passed to PlotMode() containing
|
| 71 |
+
the same number of d_vars as this mode and
|
| 72 |
+
at most the same number of i_vars.
|
| 73 |
+
"""
|
| 74 |
+
is_default = False
|
| 75 |
+
|
| 76 |
+
"""
|
| 77 |
+
All of the above attributes are defined in PlotMode.
|
| 78 |
+
The following ones are specific to PlotModeBase.
|
| 79 |
+
"""
|
| 80 |
+
|
| 81 |
+
"""
|
| 82 |
+
A list of the render styles. Do not modify.
|
| 83 |
+
"""
|
| 84 |
+
styles = {'wireframe': 1, 'solid': 2, 'both': 3}
|
| 85 |
+
|
| 86 |
+
"""
|
| 87 |
+
style_override
|
| 88 |
+
Always use this style if not blank.
|
| 89 |
+
"""
|
| 90 |
+
style_override = ''
|
| 91 |
+
|
| 92 |
+
"""
|
| 93 |
+
default_wireframe_color
|
| 94 |
+
default_solid_color
|
| 95 |
+
Can be used when color is None or being calculated.
|
| 96 |
+
Used by PlotCurve and PlotSurface, but not anywhere
|
| 97 |
+
in PlotModeBase.
|
| 98 |
+
"""
|
| 99 |
+
|
| 100 |
+
default_wireframe_color = (0.85, 0.85, 0.85)
|
| 101 |
+
default_solid_color = (0.6, 0.6, 0.9)
|
| 102 |
+
default_rot_preset = 'xy'
|
| 103 |
+
|
| 104 |
+
##
|
| 105 |
+
## Instance-Level Attributes
|
| 106 |
+
##
|
| 107 |
+
|
| 108 |
+
## 'Abstract' member functions
|
| 109 |
+
def _get_evaluator(self):
|
| 110 |
+
if self.use_lambda_eval:
|
| 111 |
+
try:
|
| 112 |
+
e = self._get_lambda_evaluator()
|
| 113 |
+
return e
|
| 114 |
+
except Exception:
|
| 115 |
+
warnings.warn("\nWarning: creating lambda evaluator failed. "
|
| 116 |
+
"Falling back on SymPy subs evaluator.")
|
| 117 |
+
return self._get_sympy_evaluator()
|
| 118 |
+
|
| 119 |
+
def _get_sympy_evaluator(self):
|
| 120 |
+
raise NotImplementedError()
|
| 121 |
+
|
| 122 |
+
def _get_lambda_evaluator(self):
|
| 123 |
+
raise NotImplementedError()
|
| 124 |
+
|
| 125 |
+
def _on_calculate_verts(self):
|
| 126 |
+
raise NotImplementedError()
|
| 127 |
+
|
| 128 |
+
def _on_calculate_cverts(self):
|
| 129 |
+
raise NotImplementedError()
|
| 130 |
+
|
| 131 |
+
## Base member functions
|
| 132 |
+
def __init__(self, *args, bounds_callback=None, **kwargs):
|
| 133 |
+
self.verts = []
|
| 134 |
+
self.cverts = []
|
| 135 |
+
self.bounds = [[S.Infinity, S.NegativeInfinity, 0],
|
| 136 |
+
[S.Infinity, S.NegativeInfinity, 0],
|
| 137 |
+
[S.Infinity, S.NegativeInfinity, 0]]
|
| 138 |
+
self.cbounds = [[S.Infinity, S.NegativeInfinity, 0],
|
| 139 |
+
[S.Infinity, S.NegativeInfinity, 0],
|
| 140 |
+
[S.Infinity, S.NegativeInfinity, 0]]
|
| 141 |
+
|
| 142 |
+
self._draw_lock = RLock()
|
| 143 |
+
|
| 144 |
+
self._calculating_verts = Event()
|
| 145 |
+
self._calculating_cverts = Event()
|
| 146 |
+
self._calculating_verts_pos = 0.0
|
| 147 |
+
self._calculating_verts_len = 0.0
|
| 148 |
+
self._calculating_cverts_pos = 0.0
|
| 149 |
+
self._calculating_cverts_len = 0.0
|
| 150 |
+
|
| 151 |
+
self._max_render_stack_size = 3
|
| 152 |
+
self._draw_wireframe = [-1]
|
| 153 |
+
self._draw_solid = [-1]
|
| 154 |
+
|
| 155 |
+
self._style = None
|
| 156 |
+
self._color = None
|
| 157 |
+
|
| 158 |
+
self.predraw = []
|
| 159 |
+
self.postdraw = []
|
| 160 |
+
|
| 161 |
+
self.use_lambda_eval = self.options.pop('use_sympy_eval', None) is None
|
| 162 |
+
self.style = self.options.pop('style', '')
|
| 163 |
+
self.color = self.options.pop('color', 'rainbow')
|
| 164 |
+
self.bounds_callback = bounds_callback
|
| 165 |
+
|
| 166 |
+
self._on_calculate()
|
| 167 |
+
|
| 168 |
+
def synchronized(f):
|
| 169 |
+
def w(self, *args, **kwargs):
|
| 170 |
+
self._draw_lock.acquire()
|
| 171 |
+
try:
|
| 172 |
+
r = f(self, *args, **kwargs)
|
| 173 |
+
return r
|
| 174 |
+
finally:
|
| 175 |
+
self._draw_lock.release()
|
| 176 |
+
return w
|
| 177 |
+
|
| 178 |
+
@synchronized
|
| 179 |
+
def push_wireframe(self, function):
|
| 180 |
+
"""
|
| 181 |
+
Push a function which performs gl commands
|
| 182 |
+
used to build a display list. (The list is
|
| 183 |
+
built outside of the function)
|
| 184 |
+
"""
|
| 185 |
+
assert callable(function)
|
| 186 |
+
self._draw_wireframe.append(function)
|
| 187 |
+
if len(self._draw_wireframe) > self._max_render_stack_size:
|
| 188 |
+
del self._draw_wireframe[1] # leave marker element
|
| 189 |
+
|
| 190 |
+
@synchronized
|
| 191 |
+
def push_solid(self, function):
|
| 192 |
+
"""
|
| 193 |
+
Push a function which performs gl commands
|
| 194 |
+
used to build a display list. (The list is
|
| 195 |
+
built outside of the function)
|
| 196 |
+
"""
|
| 197 |
+
assert callable(function)
|
| 198 |
+
self._draw_solid.append(function)
|
| 199 |
+
if len(self._draw_solid) > self._max_render_stack_size:
|
| 200 |
+
del self._draw_solid[1] # leave marker element
|
| 201 |
+
|
| 202 |
+
def _create_display_list(self, function):
|
| 203 |
+
dl = pgl.glGenLists(1)
|
| 204 |
+
pgl.glNewList(dl, pgl.GL_COMPILE)
|
| 205 |
+
function()
|
| 206 |
+
pgl.glEndList()
|
| 207 |
+
return dl
|
| 208 |
+
|
| 209 |
+
def _render_stack_top(self, render_stack):
|
| 210 |
+
top = render_stack[-1]
|
| 211 |
+
if top == -1:
|
| 212 |
+
return -1 # nothing to display
|
| 213 |
+
elif callable(top):
|
| 214 |
+
dl = self._create_display_list(top)
|
| 215 |
+
render_stack[-1] = (dl, top)
|
| 216 |
+
return dl # display newly added list
|
| 217 |
+
elif len(top) == 2:
|
| 218 |
+
if pgl.GL_TRUE == pgl.glIsList(top[0]):
|
| 219 |
+
return top[0] # display stored list
|
| 220 |
+
dl = self._create_display_list(top[1])
|
| 221 |
+
render_stack[-1] = (dl, top[1])
|
| 222 |
+
return dl # display regenerated list
|
| 223 |
+
|
| 224 |
+
def _draw_solid_display_list(self, dl):
|
| 225 |
+
pgl.glPushAttrib(pgl.GL_ENABLE_BIT | pgl.GL_POLYGON_BIT)
|
| 226 |
+
pgl.glPolygonMode(pgl.GL_FRONT_AND_BACK, pgl.GL_FILL)
|
| 227 |
+
pgl.glCallList(dl)
|
| 228 |
+
pgl.glPopAttrib()
|
| 229 |
+
|
| 230 |
+
def _draw_wireframe_display_list(self, dl):
|
| 231 |
+
pgl.glPushAttrib(pgl.GL_ENABLE_BIT | pgl.GL_POLYGON_BIT)
|
| 232 |
+
pgl.glPolygonMode(pgl.GL_FRONT_AND_BACK, pgl.GL_LINE)
|
| 233 |
+
pgl.glEnable(pgl.GL_POLYGON_OFFSET_LINE)
|
| 234 |
+
pgl.glPolygonOffset(-0.005, -50.0)
|
| 235 |
+
pgl.glCallList(dl)
|
| 236 |
+
pgl.glPopAttrib()
|
| 237 |
+
|
| 238 |
+
@synchronized
|
| 239 |
+
def draw(self):
|
| 240 |
+
for f in self.predraw:
|
| 241 |
+
if callable(f):
|
| 242 |
+
f()
|
| 243 |
+
if self.style_override:
|
| 244 |
+
style = self.styles[self.style_override]
|
| 245 |
+
else:
|
| 246 |
+
style = self.styles[self._style]
|
| 247 |
+
# Draw solid component if style includes solid
|
| 248 |
+
if style & 2:
|
| 249 |
+
dl = self._render_stack_top(self._draw_solid)
|
| 250 |
+
if dl > 0 and pgl.GL_TRUE == pgl.glIsList(dl):
|
| 251 |
+
self._draw_solid_display_list(dl)
|
| 252 |
+
# Draw wireframe component if style includes wireframe
|
| 253 |
+
if style & 1:
|
| 254 |
+
dl = self._render_stack_top(self._draw_wireframe)
|
| 255 |
+
if dl > 0 and pgl.GL_TRUE == pgl.glIsList(dl):
|
| 256 |
+
self._draw_wireframe_display_list(dl)
|
| 257 |
+
for f in self.postdraw:
|
| 258 |
+
if callable(f):
|
| 259 |
+
f()
|
| 260 |
+
|
| 261 |
+
def _on_change_color(self, color):
|
| 262 |
+
Thread(target=self._calculate_cverts).start()
|
| 263 |
+
|
| 264 |
+
def _on_calculate(self):
|
| 265 |
+
Thread(target=self._calculate_all).start()
|
| 266 |
+
|
| 267 |
+
def _calculate_all(self):
|
| 268 |
+
self._calculate_verts()
|
| 269 |
+
self._calculate_cverts()
|
| 270 |
+
|
| 271 |
+
def _calculate_verts(self):
|
| 272 |
+
if self._calculating_verts.is_set():
|
| 273 |
+
return
|
| 274 |
+
self._calculating_verts.set()
|
| 275 |
+
try:
|
| 276 |
+
self._on_calculate_verts()
|
| 277 |
+
finally:
|
| 278 |
+
self._calculating_verts.clear()
|
| 279 |
+
if callable(self.bounds_callback):
|
| 280 |
+
self.bounds_callback()
|
| 281 |
+
|
| 282 |
+
def _calculate_cverts(self):
|
| 283 |
+
if self._calculating_verts.is_set():
|
| 284 |
+
return
|
| 285 |
+
while self._calculating_cverts.is_set():
|
| 286 |
+
sleep(0) # wait for previous calculation
|
| 287 |
+
self._calculating_cverts.set()
|
| 288 |
+
try:
|
| 289 |
+
self._on_calculate_cverts()
|
| 290 |
+
finally:
|
| 291 |
+
self._calculating_cverts.clear()
|
| 292 |
+
|
| 293 |
+
def _get_calculating_verts(self):
|
| 294 |
+
return self._calculating_verts.is_set()
|
| 295 |
+
|
| 296 |
+
def _get_calculating_verts_pos(self):
|
| 297 |
+
return self._calculating_verts_pos
|
| 298 |
+
|
| 299 |
+
def _get_calculating_verts_len(self):
|
| 300 |
+
return self._calculating_verts_len
|
| 301 |
+
|
| 302 |
+
def _get_calculating_cverts(self):
|
| 303 |
+
return self._calculating_cverts.is_set()
|
| 304 |
+
|
| 305 |
+
def _get_calculating_cverts_pos(self):
|
| 306 |
+
return self._calculating_cverts_pos
|
| 307 |
+
|
| 308 |
+
def _get_calculating_cverts_len(self):
|
| 309 |
+
return self._calculating_cverts_len
|
| 310 |
+
|
| 311 |
+
## Property handlers
|
| 312 |
+
def _get_style(self):
|
| 313 |
+
return self._style
|
| 314 |
+
|
| 315 |
+
@synchronized
|
| 316 |
+
def _set_style(self, v):
|
| 317 |
+
if v is None:
|
| 318 |
+
return
|
| 319 |
+
if v == '':
|
| 320 |
+
step_max = 0
|
| 321 |
+
for i in self.intervals:
|
| 322 |
+
if i.v_steps is None:
|
| 323 |
+
continue
|
| 324 |
+
step_max = max([step_max, int(i.v_steps)])
|
| 325 |
+
v = ['both', 'solid'][step_max > 40]
|
| 326 |
+
if v not in self.styles:
|
| 327 |
+
raise ValueError("v should be there in self.styles")
|
| 328 |
+
if v == self._style:
|
| 329 |
+
return
|
| 330 |
+
self._style = v
|
| 331 |
+
|
| 332 |
+
def _get_color(self):
|
| 333 |
+
return self._color
|
| 334 |
+
|
| 335 |
+
@synchronized
|
| 336 |
+
def _set_color(self, v):
|
| 337 |
+
try:
|
| 338 |
+
if v is not None:
|
| 339 |
+
if is_sequence(v):
|
| 340 |
+
v = ColorScheme(*v)
|
| 341 |
+
else:
|
| 342 |
+
v = ColorScheme(v)
|
| 343 |
+
if repr(v) == repr(self._color):
|
| 344 |
+
return
|
| 345 |
+
self._on_change_color(v)
|
| 346 |
+
self._color = v
|
| 347 |
+
except Exception as e:
|
| 348 |
+
raise RuntimeError("Color change failed. "
|
| 349 |
+
"Reason: %s" % (str(e)))
|
| 350 |
+
|
| 351 |
+
style = property(_get_style, _set_style)
|
| 352 |
+
color = property(_get_color, _set_color)
|
| 353 |
+
|
| 354 |
+
calculating_verts = property(_get_calculating_verts)
|
| 355 |
+
calculating_verts_pos = property(_get_calculating_verts_pos)
|
| 356 |
+
calculating_verts_len = property(_get_calculating_verts_len)
|
| 357 |
+
|
| 358 |
+
calculating_cverts = property(_get_calculating_cverts)
|
| 359 |
+
calculating_cverts_pos = property(_get_calculating_cverts_pos)
|
| 360 |
+
calculating_cverts_len = property(_get_calculating_cverts_len)
|
| 361 |
+
|
| 362 |
+
## String representations
|
| 363 |
+
|
| 364 |
+
def __str__(self):
|
| 365 |
+
f = ", ".join(str(d) for d in self.d_vars)
|
| 366 |
+
o = "'mode=%s'" % (self.primary_alias)
|
| 367 |
+
return ", ".join([f, o])
|
| 368 |
+
|
| 369 |
+
def __repr__(self):
|
| 370 |
+
f = ", ".join(str(d) for d in self.d_vars)
|
| 371 |
+
i = ", ".join(str(i) for i in self.intervals)
|
| 372 |
+
d = [('mode', self.primary_alias),
|
| 373 |
+
('color', str(self.color)),
|
| 374 |
+
('style', str(self.style))]
|
| 375 |
+
|
| 376 |
+
o = "'%s'" % ("; ".join("%s=%s" % (k, v)
|
| 377 |
+
for k, v in d if v != 'None'))
|
| 378 |
+
return ", ".join([f, i, o])
|
venv/lib/python3.14/site-packages/sympy/plotting/pygletplot/plot_modes.py
ADDED
|
@@ -0,0 +1,209 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from sympy.utilities.lambdify import lambdify
|
| 2 |
+
from sympy.core.numbers import pi
|
| 3 |
+
from sympy.functions import sin, cos
|
| 4 |
+
from sympy.plotting.pygletplot.plot_curve import PlotCurve
|
| 5 |
+
from sympy.plotting.pygletplot.plot_surface import PlotSurface
|
| 6 |
+
|
| 7 |
+
from math import sin as p_sin
|
| 8 |
+
from math import cos as p_cos
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def float_vec3(f):
|
| 12 |
+
def inner(*args):
|
| 13 |
+
v = f(*args)
|
| 14 |
+
return float(v[0]), float(v[1]), float(v[2])
|
| 15 |
+
return inner
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
class Cartesian2D(PlotCurve):
|
| 19 |
+
i_vars, d_vars = 'x', 'y'
|
| 20 |
+
intervals = [[-5, 5, 100]]
|
| 21 |
+
aliases = ['cartesian']
|
| 22 |
+
is_default = True
|
| 23 |
+
|
| 24 |
+
def _get_sympy_evaluator(self):
|
| 25 |
+
fy = self.d_vars[0]
|
| 26 |
+
x = self.t_interval.v
|
| 27 |
+
|
| 28 |
+
@float_vec3
|
| 29 |
+
def e(_x):
|
| 30 |
+
return (_x, fy.subs(x, _x), 0.0)
|
| 31 |
+
return e
|
| 32 |
+
|
| 33 |
+
def _get_lambda_evaluator(self):
|
| 34 |
+
fy = self.d_vars[0]
|
| 35 |
+
x = self.t_interval.v
|
| 36 |
+
return lambdify([x], [x, fy, 0.0])
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
class Cartesian3D(PlotSurface):
|
| 40 |
+
i_vars, d_vars = 'xy', 'z'
|
| 41 |
+
intervals = [[-1, 1, 40], [-1, 1, 40]]
|
| 42 |
+
aliases = ['cartesian', 'monge']
|
| 43 |
+
is_default = True
|
| 44 |
+
|
| 45 |
+
def _get_sympy_evaluator(self):
|
| 46 |
+
fz = self.d_vars[0]
|
| 47 |
+
x = self.u_interval.v
|
| 48 |
+
y = self.v_interval.v
|
| 49 |
+
|
| 50 |
+
@float_vec3
|
| 51 |
+
def e(_x, _y):
|
| 52 |
+
return (_x, _y, fz.subs(x, _x).subs(y, _y))
|
| 53 |
+
return e
|
| 54 |
+
|
| 55 |
+
def _get_lambda_evaluator(self):
|
| 56 |
+
fz = self.d_vars[0]
|
| 57 |
+
x = self.u_interval.v
|
| 58 |
+
y = self.v_interval.v
|
| 59 |
+
return lambdify([x, y], [x, y, fz])
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
class ParametricCurve2D(PlotCurve):
|
| 63 |
+
i_vars, d_vars = 't', 'xy'
|
| 64 |
+
intervals = [[0, 2*pi, 100]]
|
| 65 |
+
aliases = ['parametric']
|
| 66 |
+
is_default = True
|
| 67 |
+
|
| 68 |
+
def _get_sympy_evaluator(self):
|
| 69 |
+
fx, fy = self.d_vars
|
| 70 |
+
t = self.t_interval.v
|
| 71 |
+
|
| 72 |
+
@float_vec3
|
| 73 |
+
def e(_t):
|
| 74 |
+
return (fx.subs(t, _t), fy.subs(t, _t), 0.0)
|
| 75 |
+
return e
|
| 76 |
+
|
| 77 |
+
def _get_lambda_evaluator(self):
|
| 78 |
+
fx, fy = self.d_vars
|
| 79 |
+
t = self.t_interval.v
|
| 80 |
+
return lambdify([t], [fx, fy, 0.0])
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
class ParametricCurve3D(PlotCurve):
|
| 84 |
+
i_vars, d_vars = 't', 'xyz'
|
| 85 |
+
intervals = [[0, 2*pi, 100]]
|
| 86 |
+
aliases = ['parametric']
|
| 87 |
+
is_default = True
|
| 88 |
+
|
| 89 |
+
def _get_sympy_evaluator(self):
|
| 90 |
+
fx, fy, fz = self.d_vars
|
| 91 |
+
t = self.t_interval.v
|
| 92 |
+
|
| 93 |
+
@float_vec3
|
| 94 |
+
def e(_t):
|
| 95 |
+
return (fx.subs(t, _t), fy.subs(t, _t), fz.subs(t, _t))
|
| 96 |
+
return e
|
| 97 |
+
|
| 98 |
+
def _get_lambda_evaluator(self):
|
| 99 |
+
fx, fy, fz = self.d_vars
|
| 100 |
+
t = self.t_interval.v
|
| 101 |
+
return lambdify([t], [fx, fy, fz])
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
class ParametricSurface(PlotSurface):
|
| 105 |
+
i_vars, d_vars = 'uv', 'xyz'
|
| 106 |
+
intervals = [[-1, 1, 40], [-1, 1, 40]]
|
| 107 |
+
aliases = ['parametric']
|
| 108 |
+
is_default = True
|
| 109 |
+
|
| 110 |
+
def _get_sympy_evaluator(self):
|
| 111 |
+
fx, fy, fz = self.d_vars
|
| 112 |
+
u = self.u_interval.v
|
| 113 |
+
v = self.v_interval.v
|
| 114 |
+
|
| 115 |
+
@float_vec3
|
| 116 |
+
def e(_u, _v):
|
| 117 |
+
return (fx.subs(u, _u).subs(v, _v),
|
| 118 |
+
fy.subs(u, _u).subs(v, _v),
|
| 119 |
+
fz.subs(u, _u).subs(v, _v))
|
| 120 |
+
return e
|
| 121 |
+
|
| 122 |
+
def _get_lambda_evaluator(self):
|
| 123 |
+
fx, fy, fz = self.d_vars
|
| 124 |
+
u = self.u_interval.v
|
| 125 |
+
v = self.v_interval.v
|
| 126 |
+
return lambdify([u, v], [fx, fy, fz])
|
| 127 |
+
|
| 128 |
+
|
| 129 |
+
class Polar(PlotCurve):
|
| 130 |
+
i_vars, d_vars = 't', 'r'
|
| 131 |
+
intervals = [[0, 2*pi, 100]]
|
| 132 |
+
aliases = ['polar']
|
| 133 |
+
is_default = False
|
| 134 |
+
|
| 135 |
+
def _get_sympy_evaluator(self):
|
| 136 |
+
fr = self.d_vars[0]
|
| 137 |
+
t = self.t_interval.v
|
| 138 |
+
|
| 139 |
+
def e(_t):
|
| 140 |
+
_r = float(fr.subs(t, _t))
|
| 141 |
+
return (_r*p_cos(_t), _r*p_sin(_t), 0.0)
|
| 142 |
+
return e
|
| 143 |
+
|
| 144 |
+
def _get_lambda_evaluator(self):
|
| 145 |
+
fr = self.d_vars[0]
|
| 146 |
+
t = self.t_interval.v
|
| 147 |
+
fx, fy = fr*cos(t), fr*sin(t)
|
| 148 |
+
return lambdify([t], [fx, fy, 0.0])
|
| 149 |
+
|
| 150 |
+
|
| 151 |
+
class Cylindrical(PlotSurface):
|
| 152 |
+
i_vars, d_vars = 'th', 'r'
|
| 153 |
+
intervals = [[0, 2*pi, 40], [-1, 1, 20]]
|
| 154 |
+
aliases = ['cylindrical', 'polar']
|
| 155 |
+
is_default = False
|
| 156 |
+
|
| 157 |
+
def _get_sympy_evaluator(self):
|
| 158 |
+
fr = self.d_vars[0]
|
| 159 |
+
t = self.u_interval.v
|
| 160 |
+
h = self.v_interval.v
|
| 161 |
+
|
| 162 |
+
def e(_t, _h):
|
| 163 |
+
_r = float(fr.subs(t, _t).subs(h, _h))
|
| 164 |
+
return (_r*p_cos(_t), _r*p_sin(_t), _h)
|
| 165 |
+
return e
|
| 166 |
+
|
| 167 |
+
def _get_lambda_evaluator(self):
|
| 168 |
+
fr = self.d_vars[0]
|
| 169 |
+
t = self.u_interval.v
|
| 170 |
+
h = self.v_interval.v
|
| 171 |
+
fx, fy = fr*cos(t), fr*sin(t)
|
| 172 |
+
return lambdify([t, h], [fx, fy, h])
|
| 173 |
+
|
| 174 |
+
|
| 175 |
+
class Spherical(PlotSurface):
|
| 176 |
+
i_vars, d_vars = 'tp', 'r'
|
| 177 |
+
intervals = [[0, 2*pi, 40], [0, pi, 20]]
|
| 178 |
+
aliases = ['spherical']
|
| 179 |
+
is_default = False
|
| 180 |
+
|
| 181 |
+
def _get_sympy_evaluator(self):
|
| 182 |
+
fr = self.d_vars[0]
|
| 183 |
+
t = self.u_interval.v
|
| 184 |
+
p = self.v_interval.v
|
| 185 |
+
|
| 186 |
+
def e(_t, _p):
|
| 187 |
+
_r = float(fr.subs(t, _t).subs(p, _p))
|
| 188 |
+
return (_r*p_cos(_t)*p_sin(_p),
|
| 189 |
+
_r*p_sin(_t)*p_sin(_p),
|
| 190 |
+
_r*p_cos(_p))
|
| 191 |
+
return e
|
| 192 |
+
|
| 193 |
+
def _get_lambda_evaluator(self):
|
| 194 |
+
fr = self.d_vars[0]
|
| 195 |
+
t = self.u_interval.v
|
| 196 |
+
p = self.v_interval.v
|
| 197 |
+
fx = fr * cos(t) * sin(p)
|
| 198 |
+
fy = fr * sin(t) * sin(p)
|
| 199 |
+
fz = fr * cos(p)
|
| 200 |
+
return lambdify([t, p], [fx, fy, fz])
|
| 201 |
+
|
| 202 |
+
Cartesian2D._register()
|
| 203 |
+
Cartesian3D._register()
|
| 204 |
+
ParametricCurve2D._register()
|
| 205 |
+
ParametricCurve3D._register()
|
| 206 |
+
ParametricSurface._register()
|
| 207 |
+
Polar._register()
|
| 208 |
+
Cylindrical._register()
|
| 209 |
+
Spherical._register()
|
venv/lib/python3.14/site-packages/sympy/plotting/pygletplot/plot_object.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
class PlotObject:
|
| 2 |
+
"""
|
| 3 |
+
Base class for objects which can be displayed in
|
| 4 |
+
a Plot.
|
| 5 |
+
"""
|
| 6 |
+
visible = True
|
| 7 |
+
|
| 8 |
+
def _draw(self):
|
| 9 |
+
if self.visible:
|
| 10 |
+
self.draw()
|
| 11 |
+
|
| 12 |
+
def draw(self):
|
| 13 |
+
"""
|
| 14 |
+
OpenGL rendering code for the plot object.
|
| 15 |
+
Override in base class.
|
| 16 |
+
"""
|
| 17 |
+
pass
|
venv/lib/python3.14/site-packages/sympy/plotting/pygletplot/plot_rotation.py
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
try:
|
| 2 |
+
from ctypes import c_float
|
| 3 |
+
except ImportError:
|
| 4 |
+
pass
|
| 5 |
+
|
| 6 |
+
import pyglet.gl as pgl
|
| 7 |
+
from math import sqrt as _sqrt, acos as _acos, pi
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def cross(a, b):
|
| 11 |
+
return (a[1] * b[2] - a[2] * b[1],
|
| 12 |
+
a[2] * b[0] - a[0] * b[2],
|
| 13 |
+
a[0] * b[1] - a[1] * b[0])
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
def dot(a, b):
|
| 17 |
+
return a[0] * b[0] + a[1] * b[1] + a[2] * b[2]
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def mag(a):
|
| 21 |
+
return _sqrt(a[0]**2 + a[1]**2 + a[2]**2)
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def norm(a):
|
| 25 |
+
m = mag(a)
|
| 26 |
+
return (a[0] / m, a[1] / m, a[2] / m)
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def get_sphere_mapping(x, y, width, height):
|
| 30 |
+
x = min([max([x, 0]), width])
|
| 31 |
+
y = min([max([y, 0]), height])
|
| 32 |
+
|
| 33 |
+
sr = _sqrt((width/2)**2 + (height/2)**2)
|
| 34 |
+
sx = ((x - width / 2) / sr)
|
| 35 |
+
sy = ((y - height / 2) / sr)
|
| 36 |
+
|
| 37 |
+
sz = 1.0 - sx**2 - sy**2
|
| 38 |
+
|
| 39 |
+
if sz > 0.0:
|
| 40 |
+
sz = _sqrt(sz)
|
| 41 |
+
return (sx, sy, sz)
|
| 42 |
+
else:
|
| 43 |
+
sz = 0
|
| 44 |
+
return norm((sx, sy, sz))
|
| 45 |
+
|
| 46 |
+
rad2deg = 180.0 / pi
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
def get_spherical_rotatation(p1, p2, width, height, theta_multiplier):
|
| 50 |
+
v1 = get_sphere_mapping(p1[0], p1[1], width, height)
|
| 51 |
+
v2 = get_sphere_mapping(p2[0], p2[1], width, height)
|
| 52 |
+
|
| 53 |
+
d = min(max([dot(v1, v2), -1]), 1)
|
| 54 |
+
|
| 55 |
+
if abs(d - 1.0) < 0.000001:
|
| 56 |
+
return None
|
| 57 |
+
|
| 58 |
+
raxis = norm( cross(v1, v2) )
|
| 59 |
+
rtheta = theta_multiplier * rad2deg * _acos(d)
|
| 60 |
+
|
| 61 |
+
pgl.glPushMatrix()
|
| 62 |
+
pgl.glLoadIdentity()
|
| 63 |
+
pgl.glRotatef(rtheta, *raxis)
|
| 64 |
+
mat = (c_float*16)()
|
| 65 |
+
pgl.glGetFloatv(pgl.GL_MODELVIEW_MATRIX, mat)
|
| 66 |
+
pgl.glPopMatrix()
|
| 67 |
+
|
| 68 |
+
return mat
|
venv/lib/python3.14/site-packages/sympy/plotting/pygletplot/plot_surface.py
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pyglet.gl as pgl
|
| 2 |
+
|
| 3 |
+
from sympy.core import S
|
| 4 |
+
from sympy.plotting.pygletplot.plot_mode_base import PlotModeBase
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
class PlotSurface(PlotModeBase):
|
| 8 |
+
|
| 9 |
+
default_rot_preset = 'perspective'
|
| 10 |
+
|
| 11 |
+
def _on_calculate_verts(self):
|
| 12 |
+
self.u_interval = self.intervals[0]
|
| 13 |
+
self.u_set = list(self.u_interval.frange())
|
| 14 |
+
self.v_interval = self.intervals[1]
|
| 15 |
+
self.v_set = list(self.v_interval.frange())
|
| 16 |
+
self.bounds = [[S.Infinity, S.NegativeInfinity, 0],
|
| 17 |
+
[S.Infinity, S.NegativeInfinity, 0],
|
| 18 |
+
[S.Infinity, S.NegativeInfinity, 0]]
|
| 19 |
+
evaluate = self._get_evaluator()
|
| 20 |
+
|
| 21 |
+
self._calculating_verts_pos = 0.0
|
| 22 |
+
self._calculating_verts_len = float(
|
| 23 |
+
self.u_interval.v_len*self.v_interval.v_len)
|
| 24 |
+
|
| 25 |
+
verts = []
|
| 26 |
+
b = self.bounds
|
| 27 |
+
for u in self.u_set:
|
| 28 |
+
column = []
|
| 29 |
+
for v in self.v_set:
|
| 30 |
+
try:
|
| 31 |
+
_e = evaluate(u, v) # calculate vertex
|
| 32 |
+
except ZeroDivisionError:
|
| 33 |
+
_e = None
|
| 34 |
+
if _e is not None: # update bounding box
|
| 35 |
+
for axis in range(3):
|
| 36 |
+
b[axis][0] = min([b[axis][0], _e[axis]])
|
| 37 |
+
b[axis][1] = max([b[axis][1], _e[axis]])
|
| 38 |
+
column.append(_e)
|
| 39 |
+
self._calculating_verts_pos += 1.0
|
| 40 |
+
|
| 41 |
+
verts.append(column)
|
| 42 |
+
for axis in range(3):
|
| 43 |
+
b[axis][2] = b[axis][1] - b[axis][0]
|
| 44 |
+
if b[axis][2] == 0.0:
|
| 45 |
+
b[axis][2] = 1.0
|
| 46 |
+
|
| 47 |
+
self.verts = verts
|
| 48 |
+
self.push_wireframe(self.draw_verts(False, False))
|
| 49 |
+
self.push_solid(self.draw_verts(False, True))
|
| 50 |
+
|
| 51 |
+
def _on_calculate_cverts(self):
|
| 52 |
+
if not self.verts or not self.color:
|
| 53 |
+
return
|
| 54 |
+
|
| 55 |
+
def set_work_len(n):
|
| 56 |
+
self._calculating_cverts_len = float(n)
|
| 57 |
+
|
| 58 |
+
def inc_work_pos():
|
| 59 |
+
self._calculating_cverts_pos += 1.0
|
| 60 |
+
set_work_len(1)
|
| 61 |
+
self._calculating_cverts_pos = 0
|
| 62 |
+
self.cverts = self.color.apply_to_surface(self.verts,
|
| 63 |
+
self.u_set,
|
| 64 |
+
self.v_set,
|
| 65 |
+
set_len=set_work_len,
|
| 66 |
+
inc_pos=inc_work_pos)
|
| 67 |
+
self.push_solid(self.draw_verts(True, True))
|
| 68 |
+
|
| 69 |
+
def calculate_one_cvert(self, u, v):
|
| 70 |
+
vert = self.verts[u][v]
|
| 71 |
+
return self.color(vert[0], vert[1], vert[2],
|
| 72 |
+
self.u_set[u], self.v_set[v])
|
| 73 |
+
|
| 74 |
+
def draw_verts(self, use_cverts, use_solid_color):
|
| 75 |
+
def f():
|
| 76 |
+
for u in range(1, len(self.u_set)):
|
| 77 |
+
pgl.glBegin(pgl.GL_QUAD_STRIP)
|
| 78 |
+
for v in range(len(self.v_set)):
|
| 79 |
+
pa = self.verts[u - 1][v]
|
| 80 |
+
pb = self.verts[u][v]
|
| 81 |
+
if pa is None or pb is None:
|
| 82 |
+
pgl.glEnd()
|
| 83 |
+
pgl.glBegin(pgl.GL_QUAD_STRIP)
|
| 84 |
+
continue
|
| 85 |
+
if use_cverts:
|
| 86 |
+
ca = self.cverts[u - 1][v]
|
| 87 |
+
cb = self.cverts[u][v]
|
| 88 |
+
if ca is None:
|
| 89 |
+
ca = (0, 0, 0)
|
| 90 |
+
if cb is None:
|
| 91 |
+
cb = (0, 0, 0)
|
| 92 |
+
else:
|
| 93 |
+
if use_solid_color:
|
| 94 |
+
ca = cb = self.default_solid_color
|
| 95 |
+
else:
|
| 96 |
+
ca = cb = self.default_wireframe_color
|
| 97 |
+
pgl.glColor3f(*ca)
|
| 98 |
+
pgl.glVertex3f(*pa)
|
| 99 |
+
pgl.glColor3f(*cb)
|
| 100 |
+
pgl.glVertex3f(*pb)
|
| 101 |
+
pgl.glEnd()
|
| 102 |
+
return f
|
venv/lib/python3.14/site-packages/sympy/plotting/pygletplot/plot_window.py
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from time import perf_counter
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
import pyglet.gl as pgl
|
| 5 |
+
|
| 6 |
+
from sympy.plotting.pygletplot.managed_window import ManagedWindow
|
| 7 |
+
from sympy.plotting.pygletplot.plot_camera import PlotCamera
|
| 8 |
+
from sympy.plotting.pygletplot.plot_controller import PlotController
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
class PlotWindow(ManagedWindow):
|
| 12 |
+
|
| 13 |
+
def __init__(self, plot, antialiasing=True, ortho=False,
|
| 14 |
+
invert_mouse_zoom=False, linewidth=1.5, caption="SymPy Plot",
|
| 15 |
+
**kwargs):
|
| 16 |
+
"""
|
| 17 |
+
Named Arguments
|
| 18 |
+
===============
|
| 19 |
+
|
| 20 |
+
antialiasing = True
|
| 21 |
+
True OR False
|
| 22 |
+
ortho = False
|
| 23 |
+
True OR False
|
| 24 |
+
invert_mouse_zoom = False
|
| 25 |
+
True OR False
|
| 26 |
+
"""
|
| 27 |
+
self.plot = plot
|
| 28 |
+
|
| 29 |
+
self.camera = None
|
| 30 |
+
self._calculating = False
|
| 31 |
+
|
| 32 |
+
self.antialiasing = antialiasing
|
| 33 |
+
self.ortho = ortho
|
| 34 |
+
self.invert_mouse_zoom = invert_mouse_zoom
|
| 35 |
+
self.linewidth = linewidth
|
| 36 |
+
self.title = caption
|
| 37 |
+
self.last_caption_update = 0
|
| 38 |
+
self.caption_update_interval = 0.2
|
| 39 |
+
self.drawing_first_object = True
|
| 40 |
+
|
| 41 |
+
super().__init__(**kwargs)
|
| 42 |
+
|
| 43 |
+
def setup(self):
|
| 44 |
+
self.camera = PlotCamera(self, ortho=self.ortho)
|
| 45 |
+
self.controller = PlotController(self,
|
| 46 |
+
invert_mouse_zoom=self.invert_mouse_zoom)
|
| 47 |
+
self.push_handlers(self.controller)
|
| 48 |
+
|
| 49 |
+
pgl.glClearColor(1.0, 1.0, 1.0, 0.0)
|
| 50 |
+
pgl.glClearDepth(1.0)
|
| 51 |
+
|
| 52 |
+
pgl.glDepthFunc(pgl.GL_LESS)
|
| 53 |
+
pgl.glEnable(pgl.GL_DEPTH_TEST)
|
| 54 |
+
|
| 55 |
+
pgl.glEnable(pgl.GL_LINE_SMOOTH)
|
| 56 |
+
pgl.glShadeModel(pgl.GL_SMOOTH)
|
| 57 |
+
pgl.glLineWidth(self.linewidth)
|
| 58 |
+
|
| 59 |
+
pgl.glEnable(pgl.GL_BLEND)
|
| 60 |
+
pgl.glBlendFunc(pgl.GL_SRC_ALPHA, pgl.GL_ONE_MINUS_SRC_ALPHA)
|
| 61 |
+
|
| 62 |
+
if self.antialiasing:
|
| 63 |
+
pgl.glHint(pgl.GL_LINE_SMOOTH_HINT, pgl.GL_NICEST)
|
| 64 |
+
pgl.glHint(pgl.GL_POLYGON_SMOOTH_HINT, pgl.GL_NICEST)
|
| 65 |
+
|
| 66 |
+
self.camera.setup_projection()
|
| 67 |
+
|
| 68 |
+
def on_resize(self, w, h):
|
| 69 |
+
super().on_resize(w, h)
|
| 70 |
+
if self.camera is not None:
|
| 71 |
+
self.camera.setup_projection()
|
| 72 |
+
|
| 73 |
+
def update(self, dt):
|
| 74 |
+
self.controller.update(dt)
|
| 75 |
+
|
| 76 |
+
def draw(self):
|
| 77 |
+
self.plot._render_lock.acquire()
|
| 78 |
+
self.camera.apply_transformation()
|
| 79 |
+
|
| 80 |
+
calc_verts_pos, calc_verts_len = 0, 0
|
| 81 |
+
calc_cverts_pos, calc_cverts_len = 0, 0
|
| 82 |
+
|
| 83 |
+
should_update_caption = (perf_counter() - self.last_caption_update >
|
| 84 |
+
self.caption_update_interval)
|
| 85 |
+
|
| 86 |
+
if len(self.plot._functions.values()) == 0:
|
| 87 |
+
self.drawing_first_object = True
|
| 88 |
+
|
| 89 |
+
iterfunctions = iter(self.plot._functions.values())
|
| 90 |
+
|
| 91 |
+
for r in iterfunctions:
|
| 92 |
+
if self.drawing_first_object:
|
| 93 |
+
self.camera.set_rot_preset(r.default_rot_preset)
|
| 94 |
+
self.drawing_first_object = False
|
| 95 |
+
|
| 96 |
+
pgl.glPushMatrix()
|
| 97 |
+
r._draw()
|
| 98 |
+
pgl.glPopMatrix()
|
| 99 |
+
|
| 100 |
+
# might as well do this while we are
|
| 101 |
+
# iterating and have the lock rather
|
| 102 |
+
# than locking and iterating twice
|
| 103 |
+
# per frame:
|
| 104 |
+
|
| 105 |
+
if should_update_caption:
|
| 106 |
+
try:
|
| 107 |
+
if r.calculating_verts:
|
| 108 |
+
calc_verts_pos += r.calculating_verts_pos
|
| 109 |
+
calc_verts_len += r.calculating_verts_len
|
| 110 |
+
if r.calculating_cverts:
|
| 111 |
+
calc_cverts_pos += r.calculating_cverts_pos
|
| 112 |
+
calc_cverts_len += r.calculating_cverts_len
|
| 113 |
+
except ValueError:
|
| 114 |
+
pass
|
| 115 |
+
|
| 116 |
+
for r in self.plot._pobjects:
|
| 117 |
+
pgl.glPushMatrix()
|
| 118 |
+
r._draw()
|
| 119 |
+
pgl.glPopMatrix()
|
| 120 |
+
|
| 121 |
+
if should_update_caption:
|
| 122 |
+
self.update_caption(calc_verts_pos, calc_verts_len,
|
| 123 |
+
calc_cverts_pos, calc_cverts_len)
|
| 124 |
+
self.last_caption_update = perf_counter()
|
| 125 |
+
|
| 126 |
+
if self.plot._screenshot:
|
| 127 |
+
self.plot._screenshot._execute_saving()
|
| 128 |
+
|
| 129 |
+
self.plot._render_lock.release()
|
| 130 |
+
|
| 131 |
+
def update_caption(self, calc_verts_pos, calc_verts_len,
|
| 132 |
+
calc_cverts_pos, calc_cverts_len):
|
| 133 |
+
caption = self.title
|
| 134 |
+
if calc_verts_len or calc_cverts_len:
|
| 135 |
+
caption += " (calculating"
|
| 136 |
+
if calc_verts_len > 0:
|
| 137 |
+
p = (calc_verts_pos / calc_verts_len) * 100
|
| 138 |
+
caption += " vertices %i%%" % (p)
|
| 139 |
+
if calc_cverts_len > 0:
|
| 140 |
+
p = (calc_cverts_pos / calc_cverts_len) * 100
|
| 141 |
+
caption += " colors %i%%" % (p)
|
| 142 |
+
caption += ")"
|
| 143 |
+
if self.caption != caption:
|
| 144 |
+
self.set_caption(caption)
|
venv/lib/python3.14/site-packages/sympy/plotting/pygletplot/tests/__init__.py
ADDED
|
File without changes
|
venv/lib/python3.14/site-packages/sympy/plotting/pygletplot/tests/test_plotting.py
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from sympy.external.importtools import import_module
|
| 2 |
+
|
| 3 |
+
disabled = False
|
| 4 |
+
|
| 5 |
+
# if pyglet.gl fails to import, e.g. opengl is missing, we disable the tests
|
| 6 |
+
pyglet_gl = import_module("pyglet.gl", catch=(OSError,))
|
| 7 |
+
pyglet_window = import_module("pyglet.window", catch=(OSError,))
|
| 8 |
+
if not pyglet_gl or not pyglet_window:
|
| 9 |
+
disabled = True
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
from sympy.core.symbol import symbols
|
| 13 |
+
from sympy.functions.elementary.exponential import log
|
| 14 |
+
from sympy.functions.elementary.trigonometric import (cos, sin)
|
| 15 |
+
x, y, z = symbols('x, y, z')
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def test_plot_2d():
|
| 19 |
+
from sympy.plotting.pygletplot import PygletPlot
|
| 20 |
+
p = PygletPlot(x, [x, -5, 5, 4], visible=False)
|
| 21 |
+
p.wait_for_calculations()
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def test_plot_2d_discontinuous():
|
| 25 |
+
from sympy.plotting.pygletplot import PygletPlot
|
| 26 |
+
p = PygletPlot(1/x, [x, -1, 1, 2], visible=False)
|
| 27 |
+
p.wait_for_calculations()
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def test_plot_3d():
|
| 31 |
+
from sympy.plotting.pygletplot import PygletPlot
|
| 32 |
+
p = PygletPlot(x*y, [x, -5, 5, 5], [y, -5, 5, 5], visible=False)
|
| 33 |
+
p.wait_for_calculations()
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
def test_plot_3d_discontinuous():
|
| 37 |
+
from sympy.plotting.pygletplot import PygletPlot
|
| 38 |
+
p = PygletPlot(1/x, [x, -3, 3, 6], [y, -1, 1, 1], visible=False)
|
| 39 |
+
p.wait_for_calculations()
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
def test_plot_2d_polar():
|
| 43 |
+
from sympy.plotting.pygletplot import PygletPlot
|
| 44 |
+
p = PygletPlot(1/x, [x, -1, 1, 4], 'mode=polar', visible=False)
|
| 45 |
+
p.wait_for_calculations()
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
def test_plot_3d_cylinder():
|
| 49 |
+
from sympy.plotting.pygletplot import PygletPlot
|
| 50 |
+
p = PygletPlot(
|
| 51 |
+
1/y, [x, 0, 6.282, 4], [y, -1, 1, 4], 'mode=polar;style=solid',
|
| 52 |
+
visible=False)
|
| 53 |
+
p.wait_for_calculations()
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
def test_plot_3d_spherical():
|
| 57 |
+
from sympy.plotting.pygletplot import PygletPlot
|
| 58 |
+
p = PygletPlot(
|
| 59 |
+
1, [x, 0, 6.282, 4], [y, 0, 3.141,
|
| 60 |
+
4], 'mode=spherical;style=wireframe',
|
| 61 |
+
visible=False)
|
| 62 |
+
p.wait_for_calculations()
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
def test_plot_2d_parametric():
|
| 66 |
+
from sympy.plotting.pygletplot import PygletPlot
|
| 67 |
+
p = PygletPlot(sin(x), cos(x), [x, 0, 6.282, 4], visible=False)
|
| 68 |
+
p.wait_for_calculations()
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
def test_plot_3d_parametric():
|
| 72 |
+
from sympy.plotting.pygletplot import PygletPlot
|
| 73 |
+
p = PygletPlot(sin(x), cos(x), x/5.0, [x, 0, 6.282, 4], visible=False)
|
| 74 |
+
p.wait_for_calculations()
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
def _test_plot_log():
|
| 78 |
+
from sympy.plotting.pygletplot import PygletPlot
|
| 79 |
+
p = PygletPlot(log(x), [x, 0, 6.282, 4], 'mode=polar', visible=False)
|
| 80 |
+
p.wait_for_calculations()
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
def test_plot_integral():
|
| 84 |
+
# Make sure it doesn't treat x as an independent variable
|
| 85 |
+
from sympy.plotting.pygletplot import PygletPlot
|
| 86 |
+
from sympy.integrals.integrals import Integral
|
| 87 |
+
p = PygletPlot(Integral(z*x, (x, 1, z), (z, 1, y)), visible=False)
|
| 88 |
+
p.wait_for_calculations()
|
venv/lib/python3.14/site-packages/sympy/plotting/pygletplot/util.py
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
try:
|
| 2 |
+
from ctypes import c_float, c_int, c_double
|
| 3 |
+
except ImportError:
|
| 4 |
+
pass
|
| 5 |
+
|
| 6 |
+
import pyglet.gl as pgl
|
| 7 |
+
from sympy.core import S
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def get_model_matrix(array_type=c_float, glGetMethod=pgl.glGetFloatv):
|
| 11 |
+
"""
|
| 12 |
+
Returns the current modelview matrix.
|
| 13 |
+
"""
|
| 14 |
+
m = (array_type*16)()
|
| 15 |
+
glGetMethod(pgl.GL_MODELVIEW_MATRIX, m)
|
| 16 |
+
return m
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def get_projection_matrix(array_type=c_float, glGetMethod=pgl.glGetFloatv):
|
| 20 |
+
"""
|
| 21 |
+
Returns the current modelview matrix.
|
| 22 |
+
"""
|
| 23 |
+
m = (array_type*16)()
|
| 24 |
+
glGetMethod(pgl.GL_PROJECTION_MATRIX, m)
|
| 25 |
+
return m
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def get_viewport():
|
| 29 |
+
"""
|
| 30 |
+
Returns the current viewport.
|
| 31 |
+
"""
|
| 32 |
+
m = (c_int*4)()
|
| 33 |
+
pgl.glGetIntegerv(pgl.GL_VIEWPORT, m)
|
| 34 |
+
return m
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
def get_direction_vectors():
|
| 38 |
+
m = get_model_matrix()
|
| 39 |
+
return ((m[0], m[4], m[8]),
|
| 40 |
+
(m[1], m[5], m[9]),
|
| 41 |
+
(m[2], m[6], m[10]))
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
def get_view_direction_vectors():
|
| 45 |
+
m = get_model_matrix()
|
| 46 |
+
return ((m[0], m[1], m[2]),
|
| 47 |
+
(m[4], m[5], m[6]),
|
| 48 |
+
(m[8], m[9], m[10]))
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
def get_basis_vectors():
|
| 52 |
+
return ((1, 0, 0), (0, 1, 0), (0, 0, 1))
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
def screen_to_model(x, y, z):
|
| 56 |
+
m = get_model_matrix(c_double, pgl.glGetDoublev)
|
| 57 |
+
p = get_projection_matrix(c_double, pgl.glGetDoublev)
|
| 58 |
+
w = get_viewport()
|
| 59 |
+
mx, my, mz = c_double(), c_double(), c_double()
|
| 60 |
+
pgl.gluUnProject(x, y, z, m, p, w, mx, my, mz)
|
| 61 |
+
return float(mx.value), float(my.value), float(mz.value)
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
def model_to_screen(x, y, z):
|
| 65 |
+
m = get_model_matrix(c_double, pgl.glGetDoublev)
|
| 66 |
+
p = get_projection_matrix(c_double, pgl.glGetDoublev)
|
| 67 |
+
w = get_viewport()
|
| 68 |
+
mx, my, mz = c_double(), c_double(), c_double()
|
| 69 |
+
pgl.gluProject(x, y, z, m, p, w, mx, my, mz)
|
| 70 |
+
return float(mx.value), float(my.value), float(mz.value)
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
def vec_subs(a, b):
|
| 74 |
+
return tuple(a[i] - b[i] for i in range(len(a)))
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
def billboard_matrix():
|
| 78 |
+
"""
|
| 79 |
+
Removes rotational components of
|
| 80 |
+
current matrix so that primitives
|
| 81 |
+
are always drawn facing the viewer.
|
| 82 |
+
|
| 83 |
+
|1|0|0|x|
|
| 84 |
+
|0|1|0|x|
|
| 85 |
+
|0|0|1|x| (x means left unchanged)
|
| 86 |
+
|x|x|x|x|
|
| 87 |
+
"""
|
| 88 |
+
m = get_model_matrix()
|
| 89 |
+
# XXX: for i in range(11): m[i] = i ?
|
| 90 |
+
m[0] = 1
|
| 91 |
+
m[1] = 0
|
| 92 |
+
m[2] = 0
|
| 93 |
+
m[4] = 0
|
| 94 |
+
m[5] = 1
|
| 95 |
+
m[6] = 0
|
| 96 |
+
m[8] = 0
|
| 97 |
+
m[9] = 0
|
| 98 |
+
m[10] = 1
|
| 99 |
+
pgl.glLoadMatrixf(m)
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
def create_bounds():
|
| 103 |
+
return [[S.Infinity, S.NegativeInfinity, 0],
|
| 104 |
+
[S.Infinity, S.NegativeInfinity, 0],
|
| 105 |
+
[S.Infinity, S.NegativeInfinity, 0]]
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
def update_bounds(b, v):
|
| 109 |
+
if v is None:
|
| 110 |
+
return
|
| 111 |
+
for axis in range(3):
|
| 112 |
+
b[axis][0] = min([b[axis][0], v[axis]])
|
| 113 |
+
b[axis][1] = max([b[axis][1], v[axis]])
|
| 114 |
+
|
| 115 |
+
|
| 116 |
+
def interpolate(a_min, a_max, a_ratio):
|
| 117 |
+
return a_min + a_ratio * (a_max - a_min)
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
def rinterpolate(a_min, a_max, a_value):
|
| 121 |
+
a_range = a_max - a_min
|
| 122 |
+
if a_max == a_min:
|
| 123 |
+
a_range = 1.0
|
| 124 |
+
return (a_value - a_min) / float(a_range)
|
| 125 |
+
|
| 126 |
+
|
| 127 |
+
def interpolate_color(color1, color2, ratio):
|
| 128 |
+
return tuple(interpolate(color1[i], color2[i], ratio) for i in range(3))
|
| 129 |
+
|
| 130 |
+
|
| 131 |
+
def scale_value(v, v_min, v_len):
|
| 132 |
+
return (v - v_min) / v_len
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
def scale_value_list(flist):
|
| 136 |
+
v_min, v_max = min(flist), max(flist)
|
| 137 |
+
v_len = v_max - v_min
|
| 138 |
+
return [scale_value(f, v_min, v_len) for f in flist]
|
| 139 |
+
|
| 140 |
+
|
| 141 |
+
def strided_range(r_min, r_max, stride, max_steps=50):
|
| 142 |
+
o_min, o_max = r_min, r_max
|
| 143 |
+
if abs(r_min - r_max) < 0.001:
|
| 144 |
+
return []
|
| 145 |
+
try:
|
| 146 |
+
range(int(r_min - r_max))
|
| 147 |
+
except (TypeError, OverflowError):
|
| 148 |
+
return []
|
| 149 |
+
if r_min > r_max:
|
| 150 |
+
raise ValueError("r_min cannot be greater than r_max")
|
| 151 |
+
r_min_s = (r_min % stride)
|
| 152 |
+
r_max_s = stride - (r_max % stride)
|
| 153 |
+
if abs(r_max_s - stride) < 0.001:
|
| 154 |
+
r_max_s = 0.0
|
| 155 |
+
r_min -= r_min_s
|
| 156 |
+
r_max += r_max_s
|
| 157 |
+
r_steps = int((r_max - r_min)/stride)
|
| 158 |
+
if max_steps and r_steps > max_steps:
|
| 159 |
+
return strided_range(o_min, o_max, stride*2)
|
| 160 |
+
return [r_min] + [r_min + e*stride for e in range(1, r_steps + 1)] + [r_max]
|
| 161 |
+
|
| 162 |
+
|
| 163 |
+
def parse_option_string(s):
|
| 164 |
+
if not isinstance(s, str):
|
| 165 |
+
return None
|
| 166 |
+
options = {}
|
| 167 |
+
for token in s.split(';'):
|
| 168 |
+
pieces = token.split('=')
|
| 169 |
+
if len(pieces) == 1:
|
| 170 |
+
option, value = pieces[0], ""
|
| 171 |
+
elif len(pieces) == 2:
|
| 172 |
+
option, value = pieces
|
| 173 |
+
else:
|
| 174 |
+
raise ValueError("Plot option string '%s' is malformed." % (s))
|
| 175 |
+
options[option.strip()] = value.strip()
|
| 176 |
+
return options
|
| 177 |
+
|
| 178 |
+
|
| 179 |
+
def dot_product(v1, v2):
|
| 180 |
+
return sum(v1[i]*v2[i] for i in range(3))
|
| 181 |
+
|
| 182 |
+
|
| 183 |
+
def vec_sub(v1, v2):
|
| 184 |
+
return tuple(v1[i] - v2[i] for i in range(3))
|
| 185 |
+
|
| 186 |
+
|
| 187 |
+
def vec_mag(v):
|
| 188 |
+
return sum(v[i]**2 for i in range(3))**(0.5)
|
venv/lib/python3.14/site-packages/sympy/plotting/series.py
ADDED
|
@@ -0,0 +1,2591 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
### The base class for all series
|
| 2 |
+
from collections.abc import Callable
|
| 3 |
+
from sympy.calculus.util import continuous_domain
|
| 4 |
+
from sympy.concrete import Sum, Product
|
| 5 |
+
from sympy.core.containers import Tuple
|
| 6 |
+
from sympy.core.expr import Expr
|
| 7 |
+
from sympy.core.function import arity
|
| 8 |
+
from sympy.core.sorting import default_sort_key
|
| 9 |
+
from sympy.core.symbol import Symbol
|
| 10 |
+
from sympy.functions import atan2, zeta, frac, ceiling, floor, im
|
| 11 |
+
from sympy.core.relational import (Equality, GreaterThan,
|
| 12 |
+
LessThan, Relational, Ne)
|
| 13 |
+
from sympy.core.sympify import sympify
|
| 14 |
+
from sympy.external import import_module
|
| 15 |
+
from sympy.logic.boolalg import BooleanFunction
|
| 16 |
+
from sympy.plotting.utils import _get_free_symbols, extract_solution
|
| 17 |
+
from sympy.printing.latex import latex
|
| 18 |
+
from sympy.printing.pycode import PythonCodePrinter
|
| 19 |
+
from sympy.printing.precedence import precedence
|
| 20 |
+
from sympy.sets.sets import Set, Interval, Union
|
| 21 |
+
from sympy.simplify.simplify import nsimplify
|
| 22 |
+
from sympy.utilities.exceptions import sympy_deprecation_warning
|
| 23 |
+
from sympy.utilities.lambdify import lambdify
|
| 24 |
+
from .intervalmath import interval
|
| 25 |
+
import warnings
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
class IntervalMathPrinter(PythonCodePrinter):
|
| 29 |
+
"""A printer to be used inside `plot_implicit` when `adaptive=True`,
|
| 30 |
+
in which case the interval arithmetic module is going to be used, which
|
| 31 |
+
requires the following edits.
|
| 32 |
+
"""
|
| 33 |
+
def _print_And(self, expr):
|
| 34 |
+
PREC = precedence(expr)
|
| 35 |
+
return " & ".join(self.parenthesize(a, PREC)
|
| 36 |
+
for a in sorted(expr.args, key=default_sort_key))
|
| 37 |
+
|
| 38 |
+
def _print_Or(self, expr):
|
| 39 |
+
PREC = precedence(expr)
|
| 40 |
+
return " | ".join(self.parenthesize(a, PREC)
|
| 41 |
+
for a in sorted(expr.args, key=default_sort_key))
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
def _uniform_eval(f1, f2, *args, modules=None,
|
| 45 |
+
force_real_eval=False, has_sum=False):
|
| 46 |
+
"""
|
| 47 |
+
Note: this is an experimental function, as such it is prone to changes.
|
| 48 |
+
Please, do not use it in your code.
|
| 49 |
+
"""
|
| 50 |
+
np = import_module('numpy')
|
| 51 |
+
|
| 52 |
+
def wrapper_func(func, *args):
|
| 53 |
+
try:
|
| 54 |
+
return complex(func(*args))
|
| 55 |
+
except (ZeroDivisionError, OverflowError):
|
| 56 |
+
return complex(np.nan, np.nan)
|
| 57 |
+
|
| 58 |
+
# NOTE: np.vectorize is much slower than numpy vectorized operations.
|
| 59 |
+
# However, this modules must be able to evaluate functions also with
|
| 60 |
+
# mpmath or sympy.
|
| 61 |
+
wrapper_func = np.vectorize(wrapper_func, otypes=[complex])
|
| 62 |
+
|
| 63 |
+
def _eval_with_sympy(err=None):
|
| 64 |
+
if f2 is None:
|
| 65 |
+
msg = "Impossible to evaluate the provided numerical function"
|
| 66 |
+
if err is None:
|
| 67 |
+
msg += "."
|
| 68 |
+
else:
|
| 69 |
+
msg += "because the following exception was raised:\n"
|
| 70 |
+
"{}: {}".format(type(err).__name__, err)
|
| 71 |
+
raise RuntimeError(msg)
|
| 72 |
+
if err:
|
| 73 |
+
warnings.warn(
|
| 74 |
+
"The evaluation with %s failed.\n" % (
|
| 75 |
+
"NumPy/SciPy" if not modules else modules) +
|
| 76 |
+
"{}: {}\n".format(type(err).__name__, err) +
|
| 77 |
+
"Trying to evaluate the expression with Sympy, but it might "
|
| 78 |
+
"be a slow operation."
|
| 79 |
+
)
|
| 80 |
+
return wrapper_func(f2, *args)
|
| 81 |
+
|
| 82 |
+
if modules == "sympy":
|
| 83 |
+
return _eval_with_sympy()
|
| 84 |
+
|
| 85 |
+
try:
|
| 86 |
+
return wrapper_func(f1, *args)
|
| 87 |
+
except Exception as err:
|
| 88 |
+
return _eval_with_sympy(err)
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
def _adaptive_eval(f, x):
|
| 92 |
+
"""Evaluate f(x) with an adaptive algorithm. Post-process the result.
|
| 93 |
+
If a symbolic expression is evaluated with SymPy, it might returns
|
| 94 |
+
another symbolic expression, containing additions, ...
|
| 95 |
+
Force evaluation to a float.
|
| 96 |
+
|
| 97 |
+
Parameters
|
| 98 |
+
==========
|
| 99 |
+
f : callable
|
| 100 |
+
x : float
|
| 101 |
+
"""
|
| 102 |
+
np = import_module('numpy')
|
| 103 |
+
|
| 104 |
+
y = f(x)
|
| 105 |
+
if isinstance(y, Expr) and (not y.is_Number):
|
| 106 |
+
y = y.evalf()
|
| 107 |
+
y = complex(y)
|
| 108 |
+
if y.imag > 1e-08:
|
| 109 |
+
return np.nan
|
| 110 |
+
return y.real
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
def _get_wrapper_for_expr(ret):
|
| 114 |
+
wrapper = "%s"
|
| 115 |
+
if ret == "real":
|
| 116 |
+
wrapper = "re(%s)"
|
| 117 |
+
elif ret == "imag":
|
| 118 |
+
wrapper = "im(%s)"
|
| 119 |
+
elif ret == "abs":
|
| 120 |
+
wrapper = "abs(%s)"
|
| 121 |
+
elif ret == "arg":
|
| 122 |
+
wrapper = "arg(%s)"
|
| 123 |
+
return wrapper
|
| 124 |
+
|
| 125 |
+
|
| 126 |
+
class BaseSeries:
|
| 127 |
+
"""Base class for the data objects containing stuff to be plotted.
|
| 128 |
+
|
| 129 |
+
Notes
|
| 130 |
+
=====
|
| 131 |
+
|
| 132 |
+
The backend should check if it supports the data series that is given.
|
| 133 |
+
(e.g. TextBackend supports only LineOver1DRangeSeries).
|
| 134 |
+
It is the backend responsibility to know how to use the class of
|
| 135 |
+
data series that is given.
|
| 136 |
+
|
| 137 |
+
Some data series classes are grouped (using a class attribute like is_2Dline)
|
| 138 |
+
according to the api they present (based only on convention). The backend is
|
| 139 |
+
not obliged to use that api (e.g. LineOver1DRangeSeries belongs to the
|
| 140 |
+
is_2Dline group and presents the get_points method, but the
|
| 141 |
+
TextBackend does not use the get_points method).
|
| 142 |
+
|
| 143 |
+
BaseSeries
|
| 144 |
+
"""
|
| 145 |
+
|
| 146 |
+
# Some flags follow. The rationale for using flags instead of checking base
|
| 147 |
+
# classes is that setting multiple flags is simpler than multiple
|
| 148 |
+
# inheritance.
|
| 149 |
+
|
| 150 |
+
is_2Dline = False
|
| 151 |
+
# Some of the backends expect:
|
| 152 |
+
# - get_points returning 1D np.arrays list_x, list_y
|
| 153 |
+
# - get_color_array returning 1D np.array (done in Line2DBaseSeries)
|
| 154 |
+
# with the colors calculated at the points from get_points
|
| 155 |
+
|
| 156 |
+
is_3Dline = False
|
| 157 |
+
# Some of the backends expect:
|
| 158 |
+
# - get_points returning 1D np.arrays list_x, list_y, list_y
|
| 159 |
+
# - get_color_array returning 1D np.array (done in Line2DBaseSeries)
|
| 160 |
+
# with the colors calculated at the points from get_points
|
| 161 |
+
|
| 162 |
+
is_3Dsurface = False
|
| 163 |
+
# Some of the backends expect:
|
| 164 |
+
# - get_meshes returning mesh_x, mesh_y, mesh_z (2D np.arrays)
|
| 165 |
+
# - get_points an alias for get_meshes
|
| 166 |
+
|
| 167 |
+
is_contour = False
|
| 168 |
+
# Some of the backends expect:
|
| 169 |
+
# - get_meshes returning mesh_x, mesh_y, mesh_z (2D np.arrays)
|
| 170 |
+
# - get_points an alias for get_meshes
|
| 171 |
+
|
| 172 |
+
is_implicit = False
|
| 173 |
+
# Some of the backends expect:
|
| 174 |
+
# - get_meshes returning mesh_x (1D array), mesh_y(1D array,
|
| 175 |
+
# mesh_z (2D np.arrays)
|
| 176 |
+
# - get_points an alias for get_meshes
|
| 177 |
+
# Different from is_contour as the colormap in backend will be
|
| 178 |
+
# different
|
| 179 |
+
|
| 180 |
+
is_interactive = False
|
| 181 |
+
# An interactive series can update its data.
|
| 182 |
+
|
| 183 |
+
is_parametric = False
|
| 184 |
+
# The calculation of aesthetics expects:
|
| 185 |
+
# - get_parameter_points returning one or two np.arrays (1D or 2D)
|
| 186 |
+
# used for calculation aesthetics
|
| 187 |
+
|
| 188 |
+
is_generic = False
|
| 189 |
+
# Represent generic user-provided numerical data
|
| 190 |
+
|
| 191 |
+
is_vector = False
|
| 192 |
+
is_2Dvector = False
|
| 193 |
+
is_3Dvector = False
|
| 194 |
+
# Represents a 2D or 3D vector data series
|
| 195 |
+
|
| 196 |
+
_N = 100
|
| 197 |
+
# default number of discretization points for uniform sampling. Each
|
| 198 |
+
# subclass can set its number.
|
| 199 |
+
|
| 200 |
+
def __init__(self, *args, **kwargs):
|
| 201 |
+
kwargs = _set_discretization_points(kwargs.copy(), type(self))
|
| 202 |
+
# discretize the domain using only integer numbers
|
| 203 |
+
self.only_integers = kwargs.get("only_integers", False)
|
| 204 |
+
# represents the evaluation modules to be used by lambdify
|
| 205 |
+
self.modules = kwargs.get("modules", None)
|
| 206 |
+
# plot functions might create data series that might not be useful to
|
| 207 |
+
# be shown on the legend, for example wireframe lines on 3D plots.
|
| 208 |
+
self.show_in_legend = kwargs.get("show_in_legend", True)
|
| 209 |
+
# line and surface series can show data with a colormap, hence a
|
| 210 |
+
# colorbar is essential to understand the data. However, sometime it
|
| 211 |
+
# is useful to hide it on series-by-series base. The following keyword
|
| 212 |
+
# controls whether the series should show a colorbar or not.
|
| 213 |
+
self.colorbar = kwargs.get("colorbar", True)
|
| 214 |
+
# Some series might use a colormap as default coloring. Setting this
|
| 215 |
+
# attribute to False will inform the backends to use solid color.
|
| 216 |
+
self.use_cm = kwargs.get("use_cm", False)
|
| 217 |
+
# If True, the backend will attempt to render it on a polar-projection
|
| 218 |
+
# axis, or using a polar discretization if a 3D plot is requested
|
| 219 |
+
self.is_polar = kwargs.get("is_polar", kwargs.get("polar", False))
|
| 220 |
+
# If True, the rendering will use points, not lines.
|
| 221 |
+
self.is_point = kwargs.get("is_point", kwargs.get("point", False))
|
| 222 |
+
# some backend is able to render latex, other needs standard text
|
| 223 |
+
self._label = self._latex_label = ""
|
| 224 |
+
|
| 225 |
+
self._ranges = []
|
| 226 |
+
self._n = [
|
| 227 |
+
int(kwargs.get("n1", self._N)),
|
| 228 |
+
int(kwargs.get("n2", self._N)),
|
| 229 |
+
int(kwargs.get("n3", self._N))
|
| 230 |
+
]
|
| 231 |
+
self._scales = [
|
| 232 |
+
kwargs.get("xscale", "linear"),
|
| 233 |
+
kwargs.get("yscale", "linear"),
|
| 234 |
+
kwargs.get("zscale", "linear")
|
| 235 |
+
]
|
| 236 |
+
|
| 237 |
+
# enable interactive widget plots
|
| 238 |
+
self._params = kwargs.get("params", {})
|
| 239 |
+
if not isinstance(self._params, dict):
|
| 240 |
+
raise TypeError("`params` must be a dictionary mapping symbols "
|
| 241 |
+
"to numeric values.")
|
| 242 |
+
if len(self._params) > 0:
|
| 243 |
+
self.is_interactive = True
|
| 244 |
+
|
| 245 |
+
# contains keyword arguments that will be passed to the rendering
|
| 246 |
+
# function of the chosen plotting library
|
| 247 |
+
self.rendering_kw = kwargs.get("rendering_kw", {})
|
| 248 |
+
|
| 249 |
+
# numerical transformation functions to be applied to the output data:
|
| 250 |
+
# x, y, z (coordinates), p (parameter on parametric plots)
|
| 251 |
+
self._tx = kwargs.get("tx", None)
|
| 252 |
+
self._ty = kwargs.get("ty", None)
|
| 253 |
+
self._tz = kwargs.get("tz", None)
|
| 254 |
+
self._tp = kwargs.get("tp", None)
|
| 255 |
+
if not all(callable(t) or (t is None) for t in
|
| 256 |
+
[self._tx, self._ty, self._tz, self._tp]):
|
| 257 |
+
raise TypeError("`tx`, `ty`, `tz`, `tp` must be functions.")
|
| 258 |
+
|
| 259 |
+
# list of numerical functions representing the expressions to evaluate
|
| 260 |
+
self._functions = []
|
| 261 |
+
# signature for the numerical functions
|
| 262 |
+
self._signature = []
|
| 263 |
+
# some expressions don't like to be evaluated over complex data.
|
| 264 |
+
# if that's the case, set this to True
|
| 265 |
+
self._force_real_eval = kwargs.get("force_real_eval", None)
|
| 266 |
+
# this attribute will eventually contain a dictionary with the
|
| 267 |
+
# discretized ranges
|
| 268 |
+
self._discretized_domain = None
|
| 269 |
+
# whether the series contains any interactive range, which is a range
|
| 270 |
+
# where the minimum and maximum values can be changed with an
|
| 271 |
+
# interactive widget
|
| 272 |
+
self._interactive_ranges = False
|
| 273 |
+
# NOTE: consider a generic summation, for example:
|
| 274 |
+
# s = Sum(cos(pi * x), (x, 1, y))
|
| 275 |
+
# This gets lambdified to something:
|
| 276 |
+
# sum(cos(pi*x) for x in range(1, y+1))
|
| 277 |
+
# Hence, y needs to be an integer, otherwise it raises:
|
| 278 |
+
# TypeError: 'complex' object cannot be interpreted as an integer
|
| 279 |
+
# This list will contains symbols that are upper bound to summations
|
| 280 |
+
# or products
|
| 281 |
+
self._needs_to_be_int = []
|
| 282 |
+
# a color function will be responsible to set the line/surface color
|
| 283 |
+
# according to some logic. Each data series will et an appropriate
|
| 284 |
+
# default value.
|
| 285 |
+
self.color_func = None
|
| 286 |
+
# NOTE: color_func usually receives numerical functions that are going
|
| 287 |
+
# to be evaluated over the coordinates of the computed points (or the
|
| 288 |
+
# discretized meshes).
|
| 289 |
+
# However, if an expression is given to color_func, then it will be
|
| 290 |
+
# lambdified with symbols in self._signature, and it will be evaluated
|
| 291 |
+
# with the same data used to evaluate the plotted expression.
|
| 292 |
+
self._eval_color_func_with_signature = False
|
| 293 |
+
|
| 294 |
+
def _block_lambda_functions(self, *exprs):
|
| 295 |
+
"""Some data series can be used to plot numerical functions, others
|
| 296 |
+
cannot. Execute this method inside the `__init__` to prevent the
|
| 297 |
+
processing of numerical functions.
|
| 298 |
+
"""
|
| 299 |
+
if any(callable(e) for e in exprs):
|
| 300 |
+
raise TypeError(type(self).__name__ + " requires a symbolic "
|
| 301 |
+
"expression.")
|
| 302 |
+
|
| 303 |
+
def _check_fs(self):
|
| 304 |
+
""" Checks if there are enough parameters and free symbols.
|
| 305 |
+
"""
|
| 306 |
+
exprs, ranges = self.expr, self.ranges
|
| 307 |
+
params, label = self.params, self.label
|
| 308 |
+
exprs = exprs if hasattr(exprs, "__iter__") else [exprs]
|
| 309 |
+
if any(callable(e) for e in exprs):
|
| 310 |
+
return
|
| 311 |
+
|
| 312 |
+
# from the expression's free symbols, remove the ones used in
|
| 313 |
+
# the parameters and the ranges
|
| 314 |
+
fs = _get_free_symbols(exprs)
|
| 315 |
+
fs = fs.difference(params.keys())
|
| 316 |
+
if ranges is not None:
|
| 317 |
+
fs = fs.difference([r[0] for r in ranges])
|
| 318 |
+
|
| 319 |
+
if len(fs) > 0:
|
| 320 |
+
raise ValueError(
|
| 321 |
+
"Incompatible expression and parameters.\n"
|
| 322 |
+
+ "Expression: {}\n".format(
|
| 323 |
+
(exprs, ranges, label) if ranges is not None else (exprs, label))
|
| 324 |
+
+ "params: {}\n".format(params)
|
| 325 |
+
+ "Specify what these symbols represent: {}\n".format(fs)
|
| 326 |
+
+ "Are they ranges or parameters?"
|
| 327 |
+
)
|
| 328 |
+
|
| 329 |
+
# verify that all symbols are known (they either represent plotting
|
| 330 |
+
# ranges or parameters)
|
| 331 |
+
range_symbols = [r[0] for r in ranges]
|
| 332 |
+
for r in ranges:
|
| 333 |
+
fs = set().union(*[e.free_symbols for e in r[1:]])
|
| 334 |
+
if any(t in fs for t in range_symbols):
|
| 335 |
+
# ranges can't depend on each other, for example this are
|
| 336 |
+
# not allowed:
|
| 337 |
+
# (x, 0, y), (y, 0, 3)
|
| 338 |
+
# (x, 0, y), (y, x + 2, 3)
|
| 339 |
+
raise ValueError("Range symbols can't be included into "
|
| 340 |
+
"minimum and maximum of a range. "
|
| 341 |
+
"Received range: %s" % str(r))
|
| 342 |
+
if len(fs) > 0:
|
| 343 |
+
self._interactive_ranges = True
|
| 344 |
+
remaining_fs = fs.difference(params.keys())
|
| 345 |
+
if len(remaining_fs) > 0:
|
| 346 |
+
raise ValueError(
|
| 347 |
+
"Unknown symbols found in plotting range: %s. " % (r,) +
|
| 348 |
+
"Are the following parameters? %s" % remaining_fs)
|
| 349 |
+
|
| 350 |
+
def _create_lambda_func(self):
|
| 351 |
+
"""Create the lambda functions to be used by the uniform meshing
|
| 352 |
+
strategy.
|
| 353 |
+
|
| 354 |
+
Notes
|
| 355 |
+
=====
|
| 356 |
+
The old sympy.plotting used experimental_lambdify. It created one
|
| 357 |
+
lambda function each time an evaluation was requested. If that failed,
|
| 358 |
+
it went on to create a different lambda function and evaluated it,
|
| 359 |
+
and so on.
|
| 360 |
+
|
| 361 |
+
This new module changes strategy: it creates right away the default
|
| 362 |
+
lambda function as well as the backup one. The reason is that the
|
| 363 |
+
series could be interactive, hence the numerical function will be
|
| 364 |
+
evaluated multiple times. So, let's create the functions just once.
|
| 365 |
+
|
| 366 |
+
This approach works fine for the majority of cases, in which the
|
| 367 |
+
symbolic expression is relatively short, hence the lambdification
|
| 368 |
+
is fast. If the expression is very long, this approach takes twice
|
| 369 |
+
the time to create the lambda functions. Be aware of that!
|
| 370 |
+
"""
|
| 371 |
+
exprs = self.expr if hasattr(self.expr, "__iter__") else [self.expr]
|
| 372 |
+
if not any(callable(e) for e in exprs):
|
| 373 |
+
fs = _get_free_symbols(exprs)
|
| 374 |
+
self._signature = sorted(fs, key=lambda t: t.name)
|
| 375 |
+
|
| 376 |
+
# Generate a list of lambda functions, two for each expression:
|
| 377 |
+
# 1. the default one.
|
| 378 |
+
# 2. the backup one, in case of failures with the default one.
|
| 379 |
+
self._functions = []
|
| 380 |
+
for e in exprs:
|
| 381 |
+
# TODO: set cse=True once this issue is solved:
|
| 382 |
+
# https://github.com/sympy/sympy/issues/24246
|
| 383 |
+
self._functions.append([
|
| 384 |
+
lambdify(self._signature, e, modules=self.modules),
|
| 385 |
+
lambdify(self._signature, e, modules="sympy", dummify=True),
|
| 386 |
+
])
|
| 387 |
+
else:
|
| 388 |
+
self._signature = sorted([r[0] for r in self.ranges], key=lambda t: t.name)
|
| 389 |
+
self._functions = [(e, None) for e in exprs]
|
| 390 |
+
|
| 391 |
+
# deal with symbolic color_func
|
| 392 |
+
if isinstance(self.color_func, Expr):
|
| 393 |
+
self.color_func = lambdify(self._signature, self.color_func)
|
| 394 |
+
self._eval_color_func_with_signature = True
|
| 395 |
+
|
| 396 |
+
def _update_range_value(self, t):
|
| 397 |
+
"""If the value of a plotting range is a symbolic expression,
|
| 398 |
+
substitute the parameters in order to get a numerical value.
|
| 399 |
+
"""
|
| 400 |
+
if not self._interactive_ranges:
|
| 401 |
+
return complex(t)
|
| 402 |
+
return complex(t.subs(self.params))
|
| 403 |
+
|
| 404 |
+
def _create_discretized_domain(self):
|
| 405 |
+
"""Discretize the ranges for uniform meshing strategy.
|
| 406 |
+
"""
|
| 407 |
+
# NOTE: the goal is to create a dictionary stored in
|
| 408 |
+
# self._discretized_domain, mapping symbols to a numpy array
|
| 409 |
+
# representing the discretization
|
| 410 |
+
discr_symbols = []
|
| 411 |
+
discretizations = []
|
| 412 |
+
|
| 413 |
+
# create a 1D discretization
|
| 414 |
+
for i, r in enumerate(self.ranges):
|
| 415 |
+
discr_symbols.append(r[0])
|
| 416 |
+
c_start = self._update_range_value(r[1])
|
| 417 |
+
c_end = self._update_range_value(r[2])
|
| 418 |
+
start = c_start.real if c_start.imag == c_end.imag == 0 else c_start
|
| 419 |
+
end = c_end.real if c_start.imag == c_end.imag == 0 else c_end
|
| 420 |
+
needs_integer_discr = self.only_integers or (r[0] in self._needs_to_be_int)
|
| 421 |
+
d = BaseSeries._discretize(start, end, self.n[i],
|
| 422 |
+
scale=self.scales[i],
|
| 423 |
+
only_integers=needs_integer_discr)
|
| 424 |
+
|
| 425 |
+
if ((not self._force_real_eval) and (not needs_integer_discr) and
|
| 426 |
+
(d.dtype != "complex")):
|
| 427 |
+
d = d + 1j * c_start.imag
|
| 428 |
+
|
| 429 |
+
if needs_integer_discr:
|
| 430 |
+
d = d.astype(int)
|
| 431 |
+
|
| 432 |
+
discretizations.append(d)
|
| 433 |
+
|
| 434 |
+
# create 2D or 3D
|
| 435 |
+
self._create_discretized_domain_helper(discr_symbols, discretizations)
|
| 436 |
+
|
| 437 |
+
def _create_discretized_domain_helper(self, discr_symbols, discretizations):
|
| 438 |
+
"""Create 2D or 3D discretized grids.
|
| 439 |
+
|
| 440 |
+
Subclasses should override this method in order to implement a
|
| 441 |
+
different behaviour.
|
| 442 |
+
"""
|
| 443 |
+
np = import_module('numpy')
|
| 444 |
+
|
| 445 |
+
# discretization suitable for 2D line plots, 3D surface plots,
|
| 446 |
+
# contours plots, vector plots
|
| 447 |
+
# NOTE: why indexing='ij'? Because it produces consistent results with
|
| 448 |
+
# np.mgrid. This is important as Mayavi requires this indexing
|
| 449 |
+
# to correctly compute 3D streamlines. While VTK is able to compute
|
| 450 |
+
# streamlines regardless of the indexing, with indexing='xy' it
|
| 451 |
+
# produces "strange" results with "voids" into the
|
| 452 |
+
# discretization volume. indexing='ij' solves the problem.
|
| 453 |
+
# Also note that matplotlib 2D streamlines requires indexing='xy'.
|
| 454 |
+
indexing = "xy"
|
| 455 |
+
if self.is_3Dvector or (self.is_3Dsurface and self.is_implicit):
|
| 456 |
+
indexing = "ij"
|
| 457 |
+
meshes = np.meshgrid(*discretizations, indexing=indexing)
|
| 458 |
+
self._discretized_domain = dict(zip(discr_symbols, meshes))
|
| 459 |
+
|
| 460 |
+
def _evaluate(self, cast_to_real=True):
|
| 461 |
+
"""Evaluation of the symbolic expression (or expressions) with the
|
| 462 |
+
uniform meshing strategy, based on current values of the parameters.
|
| 463 |
+
"""
|
| 464 |
+
np = import_module('numpy')
|
| 465 |
+
|
| 466 |
+
# create lambda functions
|
| 467 |
+
if not self._functions:
|
| 468 |
+
self._create_lambda_func()
|
| 469 |
+
# create (or update) the discretized domain
|
| 470 |
+
if (not self._discretized_domain) or self._interactive_ranges:
|
| 471 |
+
self._create_discretized_domain()
|
| 472 |
+
# ensure that discretized domains are returned with the proper order
|
| 473 |
+
discr = [self._discretized_domain[s[0]] for s in self.ranges]
|
| 474 |
+
|
| 475 |
+
args = self._aggregate_args()
|
| 476 |
+
|
| 477 |
+
results = []
|
| 478 |
+
for f in self._functions:
|
| 479 |
+
r = _uniform_eval(*f, *args)
|
| 480 |
+
# the evaluation might produce an int/float. Need this correction.
|
| 481 |
+
r = self._correct_shape(np.array(r), discr[0])
|
| 482 |
+
# sometime the evaluation is performed over arrays of type object.
|
| 483 |
+
# hence, `result` might be of type object, which don't work well
|
| 484 |
+
# with numpy real and imag functions.
|
| 485 |
+
r = r.astype(complex)
|
| 486 |
+
results.append(r)
|
| 487 |
+
|
| 488 |
+
if cast_to_real:
|
| 489 |
+
discr = [np.real(d.astype(complex)) for d in discr]
|
| 490 |
+
return [*discr, *results]
|
| 491 |
+
|
| 492 |
+
def _aggregate_args(self):
|
| 493 |
+
"""Create a list of arguments to be passed to the lambda function,
|
| 494 |
+
sorted according to self._signature.
|
| 495 |
+
"""
|
| 496 |
+
args = []
|
| 497 |
+
for s in self._signature:
|
| 498 |
+
if s in self._params.keys():
|
| 499 |
+
args.append(
|
| 500 |
+
int(self._params[s]) if s in self._needs_to_be_int else
|
| 501 |
+
self._params[s] if self._force_real_eval
|
| 502 |
+
else complex(self._params[s]))
|
| 503 |
+
else:
|
| 504 |
+
args.append(self._discretized_domain[s])
|
| 505 |
+
return args
|
| 506 |
+
|
| 507 |
+
@property
|
| 508 |
+
def expr(self):
|
| 509 |
+
"""Return the expression (or expressions) of the series."""
|
| 510 |
+
return self._expr
|
| 511 |
+
|
| 512 |
+
@expr.setter
|
| 513 |
+
def expr(self, e):
|
| 514 |
+
"""Set the expression (or expressions) of the series."""
|
| 515 |
+
is_iter = hasattr(e, "__iter__")
|
| 516 |
+
is_callable = callable(e) if not is_iter else any(callable(t) for t in e)
|
| 517 |
+
if is_callable:
|
| 518 |
+
self._expr = e
|
| 519 |
+
else:
|
| 520 |
+
self._expr = sympify(e) if not is_iter else Tuple(*e)
|
| 521 |
+
|
| 522 |
+
# look for the upper bound of summations and products
|
| 523 |
+
s = set()
|
| 524 |
+
for e in self._expr.atoms(Sum, Product):
|
| 525 |
+
for a in e.args[1:]:
|
| 526 |
+
if isinstance(a[-1], Symbol):
|
| 527 |
+
s.add(a[-1])
|
| 528 |
+
self._needs_to_be_int = list(s)
|
| 529 |
+
|
| 530 |
+
# list of sympy functions that when lambdified, the corresponding
|
| 531 |
+
# numpy functions don't like complex-type arguments
|
| 532 |
+
pf = [ceiling, floor, atan2, frac, zeta]
|
| 533 |
+
if self._force_real_eval is not True:
|
| 534 |
+
check_res = [self._expr.has(f) for f in pf]
|
| 535 |
+
self._force_real_eval = any(check_res)
|
| 536 |
+
if self._force_real_eval and ((self.modules is None) or
|
| 537 |
+
(isinstance(self.modules, str) and "numpy" in self.modules)):
|
| 538 |
+
funcs = [f for f, c in zip(pf, check_res) if c]
|
| 539 |
+
warnings.warn("NumPy is unable to evaluate with complex "
|
| 540 |
+
"numbers some of the functions included in this "
|
| 541 |
+
"symbolic expression: %s. " % funcs +
|
| 542 |
+
"Hence, the evaluation will use real numbers. "
|
| 543 |
+
"If you believe the resulting plot is incorrect, "
|
| 544 |
+
"change the evaluation module by setting the "
|
| 545 |
+
"`modules` keyword argument.")
|
| 546 |
+
if self._functions:
|
| 547 |
+
# update lambda functions
|
| 548 |
+
self._create_lambda_func()
|
| 549 |
+
|
| 550 |
+
@property
|
| 551 |
+
def is_3D(self):
|
| 552 |
+
flags3D = [self.is_3Dline, self.is_3Dsurface, self.is_3Dvector]
|
| 553 |
+
return any(flags3D)
|
| 554 |
+
|
| 555 |
+
@property
|
| 556 |
+
def is_line(self):
|
| 557 |
+
flagslines = [self.is_2Dline, self.is_3Dline]
|
| 558 |
+
return any(flagslines)
|
| 559 |
+
|
| 560 |
+
def _line_surface_color(self, prop, val):
|
| 561 |
+
"""This method enables back-compatibility with old sympy.plotting"""
|
| 562 |
+
# NOTE: color_func is set inside the init method of the series.
|
| 563 |
+
# If line_color/surface_color is not a callable, then color_func will
|
| 564 |
+
# be set to None.
|
| 565 |
+
setattr(self, prop, val)
|
| 566 |
+
if callable(val) or isinstance(val, Expr):
|
| 567 |
+
self.color_func = val
|
| 568 |
+
setattr(self, prop, None)
|
| 569 |
+
elif val is not None:
|
| 570 |
+
self.color_func = None
|
| 571 |
+
|
| 572 |
+
@property
|
| 573 |
+
def line_color(self):
|
| 574 |
+
return self._line_color
|
| 575 |
+
|
| 576 |
+
@line_color.setter
|
| 577 |
+
def line_color(self, val):
|
| 578 |
+
self._line_surface_color("_line_color", val)
|
| 579 |
+
|
| 580 |
+
@property
|
| 581 |
+
def n(self):
|
| 582 |
+
"""Returns a list [n1, n2, n3] of numbers of discratization points.
|
| 583 |
+
"""
|
| 584 |
+
return self._n
|
| 585 |
+
|
| 586 |
+
@n.setter
|
| 587 |
+
def n(self, v):
|
| 588 |
+
"""Set the numbers of discretization points. ``v`` must be an int or
|
| 589 |
+
a list.
|
| 590 |
+
|
| 591 |
+
Let ``s`` be a series. Then:
|
| 592 |
+
|
| 593 |
+
* to set the number of discretization points along the x direction (or
|
| 594 |
+
first parameter): ``s.n = 10``
|
| 595 |
+
* to set the number of discretization points along the x and y
|
| 596 |
+
directions (or first and second parameters): ``s.n = [10, 15]``
|
| 597 |
+
* to set the number of discretization points along the x, y and z
|
| 598 |
+
directions: ``s.n = [10, 15, 20]``
|
| 599 |
+
|
| 600 |
+
The following is highly unreccomended, because it prevents
|
| 601 |
+
the execution of necessary code in order to keep updated data:
|
| 602 |
+
``s.n[1] = 15``
|
| 603 |
+
"""
|
| 604 |
+
if not hasattr(v, "__iter__"):
|
| 605 |
+
self._n[0] = v
|
| 606 |
+
else:
|
| 607 |
+
self._n[:len(v)] = v
|
| 608 |
+
if self._discretized_domain:
|
| 609 |
+
# update the discretized domain
|
| 610 |
+
self._create_discretized_domain()
|
| 611 |
+
|
| 612 |
+
@property
|
| 613 |
+
def params(self):
|
| 614 |
+
"""Get or set the current parameters dictionary.
|
| 615 |
+
|
| 616 |
+
Parameters
|
| 617 |
+
==========
|
| 618 |
+
|
| 619 |
+
p : dict
|
| 620 |
+
|
| 621 |
+
* key: symbol associated to the parameter
|
| 622 |
+
* val: the numeric value
|
| 623 |
+
"""
|
| 624 |
+
return self._params
|
| 625 |
+
|
| 626 |
+
@params.setter
|
| 627 |
+
def params(self, p):
|
| 628 |
+
self._params = p
|
| 629 |
+
|
| 630 |
+
def _post_init(self):
|
| 631 |
+
exprs = self.expr if hasattr(self.expr, "__iter__") else [self.expr]
|
| 632 |
+
if any(callable(e) for e in exprs) and self.params:
|
| 633 |
+
raise TypeError("`params` was provided, hence an interactive plot "
|
| 634 |
+
"is expected. However, interactive plots do not support "
|
| 635 |
+
"user-provided numerical functions.")
|
| 636 |
+
|
| 637 |
+
# if the expressions is a lambda function and no label has been
|
| 638 |
+
# provided, then its better to do the following in order to avoid
|
| 639 |
+
# surprises on the backend
|
| 640 |
+
if any(callable(e) for e in exprs):
|
| 641 |
+
if self._label == str(self.expr):
|
| 642 |
+
self.label = ""
|
| 643 |
+
|
| 644 |
+
self._check_fs()
|
| 645 |
+
|
| 646 |
+
if hasattr(self, "adaptive") and self.adaptive and self.params:
|
| 647 |
+
warnings.warn("`params` was provided, hence an interactive plot "
|
| 648 |
+
"is expected. However, interactive plots do not support "
|
| 649 |
+
"adaptive evaluation. Automatically switched to "
|
| 650 |
+
"adaptive=False.")
|
| 651 |
+
self.adaptive = False
|
| 652 |
+
|
| 653 |
+
@property
|
| 654 |
+
def scales(self):
|
| 655 |
+
return self._scales
|
| 656 |
+
|
| 657 |
+
@scales.setter
|
| 658 |
+
def scales(self, v):
|
| 659 |
+
if isinstance(v, str):
|
| 660 |
+
self._scales[0] = v
|
| 661 |
+
else:
|
| 662 |
+
self._scales[:len(v)] = v
|
| 663 |
+
|
| 664 |
+
@property
|
| 665 |
+
def surface_color(self):
|
| 666 |
+
return self._surface_color
|
| 667 |
+
|
| 668 |
+
@surface_color.setter
|
| 669 |
+
def surface_color(self, val):
|
| 670 |
+
self._line_surface_color("_surface_color", val)
|
| 671 |
+
|
| 672 |
+
@property
|
| 673 |
+
def rendering_kw(self):
|
| 674 |
+
return self._rendering_kw
|
| 675 |
+
|
| 676 |
+
@rendering_kw.setter
|
| 677 |
+
def rendering_kw(self, kwargs):
|
| 678 |
+
if isinstance(kwargs, dict):
|
| 679 |
+
self._rendering_kw = kwargs
|
| 680 |
+
else:
|
| 681 |
+
self._rendering_kw = {}
|
| 682 |
+
if kwargs is not None:
|
| 683 |
+
warnings.warn(
|
| 684 |
+
"`rendering_kw` must be a dictionary, instead an "
|
| 685 |
+
"object of type %s was received. " % type(kwargs) +
|
| 686 |
+
"Automatically setting `rendering_kw` to an empty "
|
| 687 |
+
"dictionary")
|
| 688 |
+
|
| 689 |
+
@staticmethod
|
| 690 |
+
def _discretize(start, end, N, scale="linear", only_integers=False):
|
| 691 |
+
"""Discretize a 1D domain.
|
| 692 |
+
|
| 693 |
+
Returns
|
| 694 |
+
=======
|
| 695 |
+
|
| 696 |
+
domain : np.ndarray with dtype=float or complex
|
| 697 |
+
The domain's dtype will be float or complex (depending on the
|
| 698 |
+
type of start/end) even if only_integers=True. It is left for
|
| 699 |
+
the downstream code to perform further casting, if necessary.
|
| 700 |
+
"""
|
| 701 |
+
np = import_module('numpy')
|
| 702 |
+
|
| 703 |
+
if only_integers is True:
|
| 704 |
+
start, end = int(start), int(end)
|
| 705 |
+
N = end - start + 1
|
| 706 |
+
|
| 707 |
+
if scale == "linear":
|
| 708 |
+
return np.linspace(start, end, N)
|
| 709 |
+
return np.geomspace(start, end, N)
|
| 710 |
+
|
| 711 |
+
@staticmethod
|
| 712 |
+
def _correct_shape(a, b):
|
| 713 |
+
"""Convert ``a`` to a np.ndarray of the same shape of ``b``.
|
| 714 |
+
|
| 715 |
+
Parameters
|
| 716 |
+
==========
|
| 717 |
+
|
| 718 |
+
a : int, float, complex, np.ndarray
|
| 719 |
+
Usually, this is the result of a numerical evaluation of a
|
| 720 |
+
symbolic expression. Even if a discretized domain was used to
|
| 721 |
+
evaluate the function, the result can be a scalar (int, float,
|
| 722 |
+
complex). Think for example to ``expr = Float(2)`` and
|
| 723 |
+
``f = lambdify(x, expr)``. No matter the shape of the numerical
|
| 724 |
+
array representing x, the result of the evaluation will be
|
| 725 |
+
a single value.
|
| 726 |
+
|
| 727 |
+
b : np.ndarray
|
| 728 |
+
It represents the correct shape that ``a`` should have.
|
| 729 |
+
|
| 730 |
+
Returns
|
| 731 |
+
=======
|
| 732 |
+
new_a : np.ndarray
|
| 733 |
+
An array with the correct shape.
|
| 734 |
+
"""
|
| 735 |
+
np = import_module('numpy')
|
| 736 |
+
|
| 737 |
+
if not isinstance(a, np.ndarray):
|
| 738 |
+
a = np.array(a)
|
| 739 |
+
if a.shape != b.shape:
|
| 740 |
+
if a.shape == ():
|
| 741 |
+
a = a * np.ones_like(b)
|
| 742 |
+
else:
|
| 743 |
+
a = a.reshape(b.shape)
|
| 744 |
+
return a
|
| 745 |
+
|
| 746 |
+
def eval_color_func(self, *args):
|
| 747 |
+
"""Evaluate the color function.
|
| 748 |
+
|
| 749 |
+
Parameters
|
| 750 |
+
==========
|
| 751 |
+
|
| 752 |
+
args : tuple
|
| 753 |
+
Arguments to be passed to the coloring function. Can be coordinates
|
| 754 |
+
or parameters or both.
|
| 755 |
+
|
| 756 |
+
Notes
|
| 757 |
+
=====
|
| 758 |
+
|
| 759 |
+
The backend will request the data series to generate the numerical
|
| 760 |
+
data. Depending on the data series, either the data series itself or
|
| 761 |
+
the backend will eventually execute this function to generate the
|
| 762 |
+
appropriate coloring value.
|
| 763 |
+
"""
|
| 764 |
+
np = import_module('numpy')
|
| 765 |
+
if self.color_func is None:
|
| 766 |
+
# NOTE: with the line_color and surface_color attributes
|
| 767 |
+
# (back-compatibility with the old sympy.plotting module) it is
|
| 768 |
+
# possible to create a plot with a callable line_color (or
|
| 769 |
+
# surface_color). For example:
|
| 770 |
+
# p = plot(sin(x), line_color=lambda x, y: -y)
|
| 771 |
+
# This creates a ColoredLineOver1DRangeSeries with line_color=None
|
| 772 |
+
# and color_func=lambda x, y: -y, which effectively is a
|
| 773 |
+
# parametric series. Later we could change it to a string value:
|
| 774 |
+
# p[0].line_color = "red"
|
| 775 |
+
# However, this sets ine_color="red" and color_func=None, but the
|
| 776 |
+
# series is still ColoredLineOver1DRangeSeries (a parametric
|
| 777 |
+
# series), which will render using a color_func...
|
| 778 |
+
warnings.warn("This is likely not the result you were "
|
| 779 |
+
"looking for. Please, re-execute the plot command, this time "
|
| 780 |
+
"with the appropriate an appropriate value to line_color "
|
| 781 |
+
"or surface_color.")
|
| 782 |
+
return np.ones_like(args[0])
|
| 783 |
+
|
| 784 |
+
if self._eval_color_func_with_signature:
|
| 785 |
+
args = self._aggregate_args()
|
| 786 |
+
color = self.color_func(*args)
|
| 787 |
+
_re, _im = np.real(color), np.imag(color)
|
| 788 |
+
_re[np.invert(np.isclose(_im, np.zeros_like(_im)))] = np.nan
|
| 789 |
+
return _re
|
| 790 |
+
|
| 791 |
+
nargs = arity(self.color_func)
|
| 792 |
+
if nargs == 1:
|
| 793 |
+
if self.is_2Dline and self.is_parametric:
|
| 794 |
+
if len(args) == 2:
|
| 795 |
+
# ColoredLineOver1DRangeSeries
|
| 796 |
+
return self._correct_shape(self.color_func(args[0]), args[0])
|
| 797 |
+
# Parametric2DLineSeries
|
| 798 |
+
return self._correct_shape(self.color_func(args[2]), args[2])
|
| 799 |
+
elif self.is_3Dline and self.is_parametric:
|
| 800 |
+
return self._correct_shape(self.color_func(args[3]), args[3])
|
| 801 |
+
elif self.is_3Dsurface and self.is_parametric:
|
| 802 |
+
return self._correct_shape(self.color_func(args[3]), args[3])
|
| 803 |
+
return self._correct_shape(self.color_func(args[0]), args[0])
|
| 804 |
+
elif nargs == 2:
|
| 805 |
+
if self.is_3Dsurface and self.is_parametric:
|
| 806 |
+
return self._correct_shape(self.color_func(*args[3:]), args[3])
|
| 807 |
+
return self._correct_shape(self.color_func(*args[:2]), args[0])
|
| 808 |
+
return self._correct_shape(self.color_func(*args[:nargs]), args[0])
|
| 809 |
+
|
| 810 |
+
def get_data(self):
|
| 811 |
+
"""Compute and returns the numerical data.
|
| 812 |
+
|
| 813 |
+
The number of parameters returned by this method depends on the
|
| 814 |
+
specific instance. If ``s`` is the series, make sure to read
|
| 815 |
+
``help(s.get_data)`` to understand what it returns.
|
| 816 |
+
"""
|
| 817 |
+
raise NotImplementedError
|
| 818 |
+
|
| 819 |
+
def _get_wrapped_label(self, label, wrapper):
|
| 820 |
+
"""Given a latex representation of an expression, wrap it inside
|
| 821 |
+
some characters. Matplotlib needs "$%s%$", K3D-Jupyter needs "%s".
|
| 822 |
+
"""
|
| 823 |
+
return wrapper % label
|
| 824 |
+
|
| 825 |
+
def get_label(self, use_latex=False, wrapper="$%s$"):
|
| 826 |
+
"""Return the label to be used to display the expression.
|
| 827 |
+
|
| 828 |
+
Parameters
|
| 829 |
+
==========
|
| 830 |
+
use_latex : bool
|
| 831 |
+
If False, the string representation of the expression is returned.
|
| 832 |
+
If True, the latex representation is returned.
|
| 833 |
+
wrapper : str
|
| 834 |
+
The backend might need the latex representation to be wrapped by
|
| 835 |
+
some characters. Default to ``"$%s$"``.
|
| 836 |
+
|
| 837 |
+
Returns
|
| 838 |
+
=======
|
| 839 |
+
label : str
|
| 840 |
+
"""
|
| 841 |
+
if use_latex is False:
|
| 842 |
+
return self._label
|
| 843 |
+
if self._label == str(self.expr):
|
| 844 |
+
# when the backend requests a latex label and user didn't provide
|
| 845 |
+
# any label
|
| 846 |
+
return self._get_wrapped_label(self._latex_label, wrapper)
|
| 847 |
+
return self._latex_label
|
| 848 |
+
|
| 849 |
+
@property
|
| 850 |
+
def label(self):
|
| 851 |
+
return self.get_label()
|
| 852 |
+
|
| 853 |
+
@label.setter
|
| 854 |
+
def label(self, val):
|
| 855 |
+
"""Set the labels associated to this series."""
|
| 856 |
+
# NOTE: the init method of any series requires a label. If the user do
|
| 857 |
+
# not provide it, the preprocessing function will set label=None, which
|
| 858 |
+
# informs the series to initialize two attributes:
|
| 859 |
+
# _label contains the string representation of the expression.
|
| 860 |
+
# _latex_label contains the latex representation of the expression.
|
| 861 |
+
self._label = self._latex_label = val
|
| 862 |
+
|
| 863 |
+
@property
|
| 864 |
+
def ranges(self):
|
| 865 |
+
return self._ranges
|
| 866 |
+
|
| 867 |
+
@ranges.setter
|
| 868 |
+
def ranges(self, val):
|
| 869 |
+
new_vals = []
|
| 870 |
+
for v in val:
|
| 871 |
+
if v is not None:
|
| 872 |
+
new_vals.append(tuple([sympify(t) for t in v]))
|
| 873 |
+
self._ranges = new_vals
|
| 874 |
+
|
| 875 |
+
def _apply_transform(self, *args):
|
| 876 |
+
"""Apply transformations to the results of numerical evaluation.
|
| 877 |
+
|
| 878 |
+
Parameters
|
| 879 |
+
==========
|
| 880 |
+
args : tuple
|
| 881 |
+
Results of numerical evaluation.
|
| 882 |
+
|
| 883 |
+
Returns
|
| 884 |
+
=======
|
| 885 |
+
transformed_args : tuple
|
| 886 |
+
Tuple containing the transformed results.
|
| 887 |
+
"""
|
| 888 |
+
t = lambda x, transform: x if transform is None else transform(x)
|
| 889 |
+
x, y, z = None, None, None
|
| 890 |
+
if len(args) == 2:
|
| 891 |
+
x, y = args
|
| 892 |
+
return t(x, self._tx), t(y, self._ty)
|
| 893 |
+
elif (len(args) == 3) and isinstance(self, Parametric2DLineSeries):
|
| 894 |
+
x, y, u = args
|
| 895 |
+
return (t(x, self._tx), t(y, self._ty), t(u, self._tp))
|
| 896 |
+
elif len(args) == 3:
|
| 897 |
+
x, y, z = args
|
| 898 |
+
return t(x, self._tx), t(y, self._ty), t(z, self._tz)
|
| 899 |
+
elif (len(args) == 4) and isinstance(self, Parametric3DLineSeries):
|
| 900 |
+
x, y, z, u = args
|
| 901 |
+
return (t(x, self._tx), t(y, self._ty), t(z, self._tz), t(u, self._tp))
|
| 902 |
+
elif len(args) == 4: # 2D vector plot
|
| 903 |
+
x, y, u, v = args
|
| 904 |
+
return (
|
| 905 |
+
t(x, self._tx), t(y, self._ty),
|
| 906 |
+
t(u, self._tx), t(v, self._ty)
|
| 907 |
+
)
|
| 908 |
+
elif (len(args) == 5) and isinstance(self, ParametricSurfaceSeries):
|
| 909 |
+
x, y, z, u, v = args
|
| 910 |
+
return (t(x, self._tx), t(y, self._ty), t(z, self._tz), u, v)
|
| 911 |
+
elif (len(args) == 6) and self.is_3Dvector: # 3D vector plot
|
| 912 |
+
x, y, z, u, v, w = args
|
| 913 |
+
return (
|
| 914 |
+
t(x, self._tx), t(y, self._ty), t(z, self._tz),
|
| 915 |
+
t(u, self._tx), t(v, self._ty), t(w, self._tz)
|
| 916 |
+
)
|
| 917 |
+
elif len(args) == 6: # complex plot
|
| 918 |
+
x, y, _abs, _arg, img, colors = args
|
| 919 |
+
return (
|
| 920 |
+
x, y, t(_abs, self._tz), _arg, img, colors)
|
| 921 |
+
return args
|
| 922 |
+
|
| 923 |
+
def _str_helper(self, s):
|
| 924 |
+
pre, post = "", ""
|
| 925 |
+
if self.is_interactive:
|
| 926 |
+
pre = "interactive "
|
| 927 |
+
post = " and parameters " + str(tuple(self.params.keys()))
|
| 928 |
+
return pre + s + post
|
| 929 |
+
|
| 930 |
+
|
| 931 |
+
def _detect_poles_numerical_helper(x, y, eps=0.01, expr=None, symb=None, symbolic=False):
|
| 932 |
+
"""Compute the steepness of each segment. If it's greater than a
|
| 933 |
+
threshold, set the right-point y-value non NaN and record the
|
| 934 |
+
corresponding x-location for further processing.
|
| 935 |
+
|
| 936 |
+
Returns
|
| 937 |
+
=======
|
| 938 |
+
x : np.ndarray
|
| 939 |
+
Unchanged x-data.
|
| 940 |
+
yy : np.ndarray
|
| 941 |
+
Modified y-data with NaN values.
|
| 942 |
+
"""
|
| 943 |
+
np = import_module('numpy')
|
| 944 |
+
|
| 945 |
+
yy = y.copy()
|
| 946 |
+
threshold = np.pi / 2 - eps
|
| 947 |
+
for i in range(len(x) - 1):
|
| 948 |
+
dx = x[i + 1] - x[i]
|
| 949 |
+
dy = abs(y[i + 1] - y[i])
|
| 950 |
+
angle = np.arctan(dy / dx)
|
| 951 |
+
if abs(angle) >= threshold:
|
| 952 |
+
yy[i + 1] = np.nan
|
| 953 |
+
|
| 954 |
+
return x, yy
|
| 955 |
+
|
| 956 |
+
def _detect_poles_symbolic_helper(expr, symb, start, end):
|
| 957 |
+
"""Attempts to compute symbolic discontinuities.
|
| 958 |
+
|
| 959 |
+
Returns
|
| 960 |
+
=======
|
| 961 |
+
pole : list
|
| 962 |
+
List of symbolic poles, possibly empty.
|
| 963 |
+
"""
|
| 964 |
+
poles = []
|
| 965 |
+
interval = Interval(nsimplify(start), nsimplify(end))
|
| 966 |
+
res = continuous_domain(expr, symb, interval)
|
| 967 |
+
res = res.simplify()
|
| 968 |
+
if res == interval:
|
| 969 |
+
pass
|
| 970 |
+
elif (isinstance(res, Union) and
|
| 971 |
+
all(isinstance(t, Interval) for t in res.args)):
|
| 972 |
+
poles = []
|
| 973 |
+
for s in res.args:
|
| 974 |
+
if s.left_open:
|
| 975 |
+
poles.append(s.left)
|
| 976 |
+
if s.right_open:
|
| 977 |
+
poles.append(s.right)
|
| 978 |
+
poles = list(set(poles))
|
| 979 |
+
else:
|
| 980 |
+
raise ValueError(
|
| 981 |
+
f"Could not parse the following object: {res} .\n"
|
| 982 |
+
"Please, submit this as a bug. Consider also to set "
|
| 983 |
+
"`detect_poles=True`."
|
| 984 |
+
)
|
| 985 |
+
return poles
|
| 986 |
+
|
| 987 |
+
|
| 988 |
+
### 2D lines
|
| 989 |
+
class Line2DBaseSeries(BaseSeries):
|
| 990 |
+
"""A base class for 2D lines.
|
| 991 |
+
|
| 992 |
+
- adding the label, steps and only_integers options
|
| 993 |
+
- making is_2Dline true
|
| 994 |
+
- defining get_segments and get_color_array
|
| 995 |
+
"""
|
| 996 |
+
|
| 997 |
+
is_2Dline = True
|
| 998 |
+
_dim = 2
|
| 999 |
+
_N = 1000
|
| 1000 |
+
|
| 1001 |
+
def __init__(self, **kwargs):
|
| 1002 |
+
super().__init__(**kwargs)
|
| 1003 |
+
self.steps = kwargs.get("steps", False)
|
| 1004 |
+
self.is_point = kwargs.get("is_point", kwargs.get("point", False))
|
| 1005 |
+
self.is_filled = kwargs.get("is_filled", kwargs.get("fill", True))
|
| 1006 |
+
self.adaptive = kwargs.get("adaptive", False)
|
| 1007 |
+
self.depth = kwargs.get('depth', 12)
|
| 1008 |
+
self.use_cm = kwargs.get("use_cm", False)
|
| 1009 |
+
self.color_func = kwargs.get("color_func", None)
|
| 1010 |
+
self.line_color = kwargs.get("line_color", None)
|
| 1011 |
+
self.detect_poles = kwargs.get("detect_poles", False)
|
| 1012 |
+
self.eps = kwargs.get("eps", 0.01)
|
| 1013 |
+
self.is_polar = kwargs.get("is_polar", kwargs.get("polar", False))
|
| 1014 |
+
self.unwrap = kwargs.get("unwrap", False)
|
| 1015 |
+
# when detect_poles="symbolic", stores the location of poles so that
|
| 1016 |
+
# they can be appropriately rendered
|
| 1017 |
+
self.poles_locations = []
|
| 1018 |
+
exclude = kwargs.get("exclude", [])
|
| 1019 |
+
if isinstance(exclude, Set):
|
| 1020 |
+
exclude = list(extract_solution(exclude, n=100))
|
| 1021 |
+
if not hasattr(exclude, "__iter__"):
|
| 1022 |
+
exclude = [exclude]
|
| 1023 |
+
exclude = [float(e) for e in exclude]
|
| 1024 |
+
self.exclude = sorted(exclude)
|
| 1025 |
+
|
| 1026 |
+
def get_data(self):
|
| 1027 |
+
"""Return coordinates for plotting the line.
|
| 1028 |
+
|
| 1029 |
+
Returns
|
| 1030 |
+
=======
|
| 1031 |
+
|
| 1032 |
+
x: np.ndarray
|
| 1033 |
+
x-coordinates
|
| 1034 |
+
|
| 1035 |
+
y: np.ndarray
|
| 1036 |
+
y-coordinates
|
| 1037 |
+
|
| 1038 |
+
z: np.ndarray (optional)
|
| 1039 |
+
z-coordinates in case of Parametric3DLineSeries,
|
| 1040 |
+
Parametric3DLineInteractiveSeries
|
| 1041 |
+
|
| 1042 |
+
param : np.ndarray (optional)
|
| 1043 |
+
The parameter in case of Parametric2DLineSeries,
|
| 1044 |
+
Parametric3DLineSeries or AbsArgLineSeries (and their
|
| 1045 |
+
corresponding interactive series).
|
| 1046 |
+
"""
|
| 1047 |
+
np = import_module('numpy')
|
| 1048 |
+
points = self._get_data_helper()
|
| 1049 |
+
|
| 1050 |
+
if (isinstance(self, LineOver1DRangeSeries) and
|
| 1051 |
+
(self.detect_poles == "symbolic")):
|
| 1052 |
+
poles = _detect_poles_symbolic_helper(
|
| 1053 |
+
self.expr.subs(self.params), *self.ranges[0])
|
| 1054 |
+
poles = np.array([float(t) for t in poles])
|
| 1055 |
+
t = lambda x, transform: x if transform is None else transform(x)
|
| 1056 |
+
self.poles_locations = t(np.array(poles), self._tx)
|
| 1057 |
+
|
| 1058 |
+
# postprocessing
|
| 1059 |
+
points = self._apply_transform(*points)
|
| 1060 |
+
|
| 1061 |
+
if self.is_2Dline and self.detect_poles:
|
| 1062 |
+
if len(points) == 2:
|
| 1063 |
+
x, y = points
|
| 1064 |
+
x, y = _detect_poles_numerical_helper(
|
| 1065 |
+
x, y, self.eps)
|
| 1066 |
+
points = (x, y)
|
| 1067 |
+
else:
|
| 1068 |
+
x, y, p = points
|
| 1069 |
+
x, y = _detect_poles_numerical_helper(x, y, self.eps)
|
| 1070 |
+
points = (x, y, p)
|
| 1071 |
+
|
| 1072 |
+
if self.unwrap:
|
| 1073 |
+
kw = {}
|
| 1074 |
+
if self.unwrap is not True:
|
| 1075 |
+
kw = self.unwrap
|
| 1076 |
+
if self.is_2Dline:
|
| 1077 |
+
if len(points) == 2:
|
| 1078 |
+
x, y = points
|
| 1079 |
+
y = np.unwrap(y, **kw)
|
| 1080 |
+
points = (x, y)
|
| 1081 |
+
else:
|
| 1082 |
+
x, y, p = points
|
| 1083 |
+
y = np.unwrap(y, **kw)
|
| 1084 |
+
points = (x, y, p)
|
| 1085 |
+
|
| 1086 |
+
if self.steps is True:
|
| 1087 |
+
if self.is_2Dline:
|
| 1088 |
+
x, y = points[0], points[1]
|
| 1089 |
+
x = np.array((x, x)).T.flatten()[1:]
|
| 1090 |
+
y = np.array((y, y)).T.flatten()[:-1]
|
| 1091 |
+
if self.is_parametric:
|
| 1092 |
+
points = (x, y, points[2])
|
| 1093 |
+
else:
|
| 1094 |
+
points = (x, y)
|
| 1095 |
+
elif self.is_3Dline:
|
| 1096 |
+
x = np.repeat(points[0], 3)[2:]
|
| 1097 |
+
y = np.repeat(points[1], 3)[:-2]
|
| 1098 |
+
z = np.repeat(points[2], 3)[1:-1]
|
| 1099 |
+
if len(points) > 3:
|
| 1100 |
+
points = (x, y, z, points[3])
|
| 1101 |
+
else:
|
| 1102 |
+
points = (x, y, z)
|
| 1103 |
+
|
| 1104 |
+
if len(self.exclude) > 0:
|
| 1105 |
+
points = self._insert_exclusions(points)
|
| 1106 |
+
return points
|
| 1107 |
+
|
| 1108 |
+
def get_segments(self):
|
| 1109 |
+
sympy_deprecation_warning(
|
| 1110 |
+
"""
|
| 1111 |
+
The Line2DBaseSeries.get_segments() method is deprecated.
|
| 1112 |
+
|
| 1113 |
+
Instead, use the MatplotlibBackend.get_segments() method, or use
|
| 1114 |
+
The get_points() or get_data() methods.
|
| 1115 |
+
""",
|
| 1116 |
+
deprecated_since_version="1.9",
|
| 1117 |
+
active_deprecations_target="deprecated-get-segments")
|
| 1118 |
+
|
| 1119 |
+
np = import_module('numpy')
|
| 1120 |
+
points = type(self).get_data(self)
|
| 1121 |
+
points = np.ma.array(points).T.reshape(-1, 1, self._dim)
|
| 1122 |
+
return np.ma.concatenate([points[:-1], points[1:]], axis=1)
|
| 1123 |
+
|
| 1124 |
+
def _insert_exclusions(self, points):
|
| 1125 |
+
"""Add NaN to each of the exclusion point. Practically, this adds a
|
| 1126 |
+
NaN to the exclusion point, plus two other nearby points evaluated with
|
| 1127 |
+
the numerical functions associated to this data series.
|
| 1128 |
+
These nearby points are important when the number of discretization
|
| 1129 |
+
points is low, or the scale is logarithm.
|
| 1130 |
+
|
| 1131 |
+
NOTE: it would be easier to just add exclusion points to the
|
| 1132 |
+
discretized domain before evaluation, then after evaluation add NaN
|
| 1133 |
+
to the exclusion points. But that's only work with adaptive=False.
|
| 1134 |
+
The following approach work even with adaptive=True.
|
| 1135 |
+
"""
|
| 1136 |
+
np = import_module("numpy")
|
| 1137 |
+
points = list(points)
|
| 1138 |
+
n = len(points)
|
| 1139 |
+
# index of the x-coordinate (for 2d plots) or parameter (for 2d/3d
|
| 1140 |
+
# parametric plots)
|
| 1141 |
+
k = n - 1
|
| 1142 |
+
if n == 2:
|
| 1143 |
+
k = 0
|
| 1144 |
+
# indices of the other coordinates
|
| 1145 |
+
j_indeces = sorted(set(range(n)).difference([k]))
|
| 1146 |
+
# TODO: for now, I assume that numpy functions are going to succeed
|
| 1147 |
+
funcs = [f[0] for f in self._functions]
|
| 1148 |
+
|
| 1149 |
+
for e in self.exclude:
|
| 1150 |
+
res = points[k] - e >= 0
|
| 1151 |
+
# if res contains both True and False, ie, if e is found
|
| 1152 |
+
if any(res) and any(~res):
|
| 1153 |
+
idx = np.nanargmax(res)
|
| 1154 |
+
# select the previous point with respect to e
|
| 1155 |
+
idx -= 1
|
| 1156 |
+
# TODO: what if points[k][idx]==e or points[k][idx+1]==e?
|
| 1157 |
+
|
| 1158 |
+
if idx > 0 and idx < len(points[k]) - 1:
|
| 1159 |
+
delta_prev = abs(e - points[k][idx])
|
| 1160 |
+
delta_post = abs(e - points[k][idx + 1])
|
| 1161 |
+
delta = min(delta_prev, delta_post) / 100
|
| 1162 |
+
prev = e - delta
|
| 1163 |
+
post = e + delta
|
| 1164 |
+
|
| 1165 |
+
# add points to the x-coord or the parameter
|
| 1166 |
+
points[k] = np.concatenate(
|
| 1167 |
+
(points[k][:idx], [prev, e, post], points[k][idx+1:]))
|
| 1168 |
+
|
| 1169 |
+
# add points to the other coordinates
|
| 1170 |
+
c = 0
|
| 1171 |
+
for j in j_indeces:
|
| 1172 |
+
values = funcs[c](np.array([prev, post]))
|
| 1173 |
+
c += 1
|
| 1174 |
+
points[j] = np.concatenate(
|
| 1175 |
+
(points[j][:idx], [values[0], np.nan, values[1]], points[j][idx+1:]))
|
| 1176 |
+
return points
|
| 1177 |
+
|
| 1178 |
+
@property
|
| 1179 |
+
def var(self):
|
| 1180 |
+
return None if not self.ranges else self.ranges[0][0]
|
| 1181 |
+
|
| 1182 |
+
@property
|
| 1183 |
+
def start(self):
|
| 1184 |
+
if not self.ranges:
|
| 1185 |
+
return None
|
| 1186 |
+
try:
|
| 1187 |
+
return self._cast(self.ranges[0][1])
|
| 1188 |
+
except TypeError:
|
| 1189 |
+
return self.ranges[0][1]
|
| 1190 |
+
|
| 1191 |
+
@property
|
| 1192 |
+
def end(self):
|
| 1193 |
+
if not self.ranges:
|
| 1194 |
+
return None
|
| 1195 |
+
try:
|
| 1196 |
+
return self._cast(self.ranges[0][2])
|
| 1197 |
+
except TypeError:
|
| 1198 |
+
return self.ranges[0][2]
|
| 1199 |
+
|
| 1200 |
+
@property
|
| 1201 |
+
def xscale(self):
|
| 1202 |
+
return self._scales[0]
|
| 1203 |
+
|
| 1204 |
+
@xscale.setter
|
| 1205 |
+
def xscale(self, v):
|
| 1206 |
+
self.scales = v
|
| 1207 |
+
|
| 1208 |
+
def get_color_array(self):
|
| 1209 |
+
np = import_module('numpy')
|
| 1210 |
+
c = self.line_color
|
| 1211 |
+
if hasattr(c, '__call__'):
|
| 1212 |
+
f = np.vectorize(c)
|
| 1213 |
+
nargs = arity(c)
|
| 1214 |
+
if nargs == 1 and self.is_parametric:
|
| 1215 |
+
x = self.get_parameter_points()
|
| 1216 |
+
return f(centers_of_segments(x))
|
| 1217 |
+
else:
|
| 1218 |
+
variables = list(map(centers_of_segments, self.get_points()))
|
| 1219 |
+
if nargs == 1:
|
| 1220 |
+
return f(variables[0])
|
| 1221 |
+
elif nargs == 2:
|
| 1222 |
+
return f(*variables[:2])
|
| 1223 |
+
else: # only if the line is 3D (otherwise raises an error)
|
| 1224 |
+
return f(*variables)
|
| 1225 |
+
else:
|
| 1226 |
+
return c*np.ones(self.nb_of_points)
|
| 1227 |
+
|
| 1228 |
+
|
| 1229 |
+
class List2DSeries(Line2DBaseSeries):
|
| 1230 |
+
"""Representation for a line consisting of list of points."""
|
| 1231 |
+
|
| 1232 |
+
def __init__(self, list_x, list_y, label="", **kwargs):
|
| 1233 |
+
super().__init__(**kwargs)
|
| 1234 |
+
np = import_module('numpy')
|
| 1235 |
+
if len(list_x) != len(list_y):
|
| 1236 |
+
raise ValueError(
|
| 1237 |
+
"The two lists of coordinates must have the same "
|
| 1238 |
+
"number of elements.\n"
|
| 1239 |
+
"Received: len(list_x) = {} ".format(len(list_x)) +
|
| 1240 |
+
"and len(list_y) = {}".format(len(list_y))
|
| 1241 |
+
)
|
| 1242 |
+
self._block_lambda_functions(list_x, list_y)
|
| 1243 |
+
check = lambda l: [isinstance(t, Expr) and (not t.is_number) for t in l]
|
| 1244 |
+
if any(check(list_x) + check(list_y)) or self.params:
|
| 1245 |
+
if not self.params:
|
| 1246 |
+
raise ValueError("Some or all elements of the provided lists "
|
| 1247 |
+
"are symbolic expressions, but the ``params`` dictionary "
|
| 1248 |
+
"was not provided: those elements can't be evaluated.")
|
| 1249 |
+
self.list_x = Tuple(*list_x)
|
| 1250 |
+
self.list_y = Tuple(*list_y)
|
| 1251 |
+
else:
|
| 1252 |
+
self.list_x = np.array(list_x, dtype=np.float64)
|
| 1253 |
+
self.list_y = np.array(list_y, dtype=np.float64)
|
| 1254 |
+
|
| 1255 |
+
self._expr = (self.list_x, self.list_y)
|
| 1256 |
+
if not any(isinstance(t, np.ndarray) for t in [self.list_x, self.list_y]):
|
| 1257 |
+
self._check_fs()
|
| 1258 |
+
self.is_polar = kwargs.get("is_polar", kwargs.get("polar", False))
|
| 1259 |
+
self.label = label
|
| 1260 |
+
self.rendering_kw = kwargs.get("rendering_kw", {})
|
| 1261 |
+
if self.use_cm and self.color_func:
|
| 1262 |
+
self.is_parametric = True
|
| 1263 |
+
if isinstance(self.color_func, Expr):
|
| 1264 |
+
raise TypeError(
|
| 1265 |
+
"%s don't support symbolic " % self.__class__.__name__ +
|
| 1266 |
+
"expression for `color_func`.")
|
| 1267 |
+
|
| 1268 |
+
def __str__(self):
|
| 1269 |
+
return "2D list plot"
|
| 1270 |
+
|
| 1271 |
+
def _get_data_helper(self):
|
| 1272 |
+
"""Returns coordinates that needs to be postprocessed."""
|
| 1273 |
+
lx, ly = self.list_x, self.list_y
|
| 1274 |
+
|
| 1275 |
+
if not self.is_interactive:
|
| 1276 |
+
return self._eval_color_func_and_return(lx, ly)
|
| 1277 |
+
|
| 1278 |
+
np = import_module('numpy')
|
| 1279 |
+
lx = np.array([t.evalf(subs=self.params) for t in lx], dtype=float)
|
| 1280 |
+
ly = np.array([t.evalf(subs=self.params) for t in ly], dtype=float)
|
| 1281 |
+
return self._eval_color_func_and_return(lx, ly)
|
| 1282 |
+
|
| 1283 |
+
def _eval_color_func_and_return(self, *data):
|
| 1284 |
+
if self.use_cm and callable(self.color_func):
|
| 1285 |
+
return [*data, self.eval_color_func(*data)]
|
| 1286 |
+
return data
|
| 1287 |
+
|
| 1288 |
+
|
| 1289 |
+
class LineOver1DRangeSeries(Line2DBaseSeries):
|
| 1290 |
+
"""Representation for a line consisting of a SymPy expression over a range."""
|
| 1291 |
+
|
| 1292 |
+
def __init__(self, expr, var_start_end, label="", **kwargs):
|
| 1293 |
+
super().__init__(**kwargs)
|
| 1294 |
+
self.expr = expr if callable(expr) else sympify(expr)
|
| 1295 |
+
self._label = str(self.expr) if label is None else label
|
| 1296 |
+
self._latex_label = latex(self.expr) if label is None else label
|
| 1297 |
+
self.ranges = [var_start_end]
|
| 1298 |
+
self._cast = complex
|
| 1299 |
+
# for complex-related data series, this determines what data to return
|
| 1300 |
+
# on the y-axis
|
| 1301 |
+
self._return = kwargs.get("return", None)
|
| 1302 |
+
self._post_init()
|
| 1303 |
+
|
| 1304 |
+
if not self._interactive_ranges:
|
| 1305 |
+
# NOTE: the following check is only possible when the minimum and
|
| 1306 |
+
# maximum values of a plotting range are numeric
|
| 1307 |
+
start, end = [complex(t) for t in self.ranges[0][1:]]
|
| 1308 |
+
if im(start) != im(end):
|
| 1309 |
+
raise ValueError(
|
| 1310 |
+
"%s requires the imaginary " % self.__class__.__name__ +
|
| 1311 |
+
"part of the start and end values of the range "
|
| 1312 |
+
"to be the same.")
|
| 1313 |
+
|
| 1314 |
+
if self.adaptive and self._return:
|
| 1315 |
+
warnings.warn("The adaptive algorithm is unable to deal with "
|
| 1316 |
+
"complex numbers. Automatically switching to uniform meshing.")
|
| 1317 |
+
self.adaptive = False
|
| 1318 |
+
|
| 1319 |
+
@property
|
| 1320 |
+
def nb_of_points(self):
|
| 1321 |
+
return self.n[0]
|
| 1322 |
+
|
| 1323 |
+
@nb_of_points.setter
|
| 1324 |
+
def nb_of_points(self, v):
|
| 1325 |
+
self.n = v
|
| 1326 |
+
|
| 1327 |
+
def __str__(self):
|
| 1328 |
+
def f(t):
|
| 1329 |
+
if isinstance(t, complex):
|
| 1330 |
+
if t.imag != 0:
|
| 1331 |
+
return t
|
| 1332 |
+
return t.real
|
| 1333 |
+
return t
|
| 1334 |
+
pre = "interactive " if self.is_interactive else ""
|
| 1335 |
+
post = ""
|
| 1336 |
+
if self.is_interactive:
|
| 1337 |
+
post = " and parameters " + str(tuple(self.params.keys()))
|
| 1338 |
+
wrapper = _get_wrapper_for_expr(self._return)
|
| 1339 |
+
return pre + "cartesian line: %s for %s over %s" % (
|
| 1340 |
+
wrapper % self.expr,
|
| 1341 |
+
str(self.var),
|
| 1342 |
+
str((f(self.start), f(self.end))),
|
| 1343 |
+
) + post
|
| 1344 |
+
|
| 1345 |
+
def get_points(self):
|
| 1346 |
+
"""Return lists of coordinates for plotting. Depending on the
|
| 1347 |
+
``adaptive`` option, this function will either use an adaptive algorithm
|
| 1348 |
+
or it will uniformly sample the expression over the provided range.
|
| 1349 |
+
|
| 1350 |
+
This function is available for back-compatibility purposes. Consider
|
| 1351 |
+
using ``get_data()`` instead.
|
| 1352 |
+
|
| 1353 |
+
Returns
|
| 1354 |
+
=======
|
| 1355 |
+
x : list
|
| 1356 |
+
List of x-coordinates
|
| 1357 |
+
|
| 1358 |
+
y : list
|
| 1359 |
+
List of y-coordinates
|
| 1360 |
+
"""
|
| 1361 |
+
return self._get_data_helper()
|
| 1362 |
+
|
| 1363 |
+
def _adaptive_sampling(self):
|
| 1364 |
+
try:
|
| 1365 |
+
if callable(self.expr):
|
| 1366 |
+
f = self.expr
|
| 1367 |
+
else:
|
| 1368 |
+
f = lambdify([self.var], self.expr, self.modules)
|
| 1369 |
+
x, y = self._adaptive_sampling_helper(f)
|
| 1370 |
+
except Exception as err:
|
| 1371 |
+
warnings.warn(
|
| 1372 |
+
"The evaluation with %s failed.\n" % (
|
| 1373 |
+
"NumPy/SciPy" if not self.modules else self.modules) +
|
| 1374 |
+
"{}: {}\n".format(type(err).__name__, err) +
|
| 1375 |
+
"Trying to evaluate the expression with Sympy, but it might "
|
| 1376 |
+
"be a slow operation."
|
| 1377 |
+
)
|
| 1378 |
+
f = lambdify([self.var], self.expr, "sympy")
|
| 1379 |
+
x, y = self._adaptive_sampling_helper(f)
|
| 1380 |
+
return x, y
|
| 1381 |
+
|
| 1382 |
+
def _adaptive_sampling_helper(self, f):
|
| 1383 |
+
"""The adaptive sampling is done by recursively checking if three
|
| 1384 |
+
points are almost collinear. If they are not collinear, then more
|
| 1385 |
+
points are added between those points.
|
| 1386 |
+
|
| 1387 |
+
References
|
| 1388 |
+
==========
|
| 1389 |
+
|
| 1390 |
+
.. [1] Adaptive polygonal approximation of parametric curves,
|
| 1391 |
+
Luiz Henrique de Figueiredo.
|
| 1392 |
+
"""
|
| 1393 |
+
np = import_module('numpy')
|
| 1394 |
+
|
| 1395 |
+
x_coords = []
|
| 1396 |
+
y_coords = []
|
| 1397 |
+
def sample(p, q, depth):
|
| 1398 |
+
""" Samples recursively if three points are almost collinear.
|
| 1399 |
+
For depth < 6, points are added irrespective of whether they
|
| 1400 |
+
satisfy the collinearity condition or not. The maximum depth
|
| 1401 |
+
allowed is 12.
|
| 1402 |
+
"""
|
| 1403 |
+
# Randomly sample to avoid aliasing.
|
| 1404 |
+
random = 0.45 + np.random.rand() * 0.1
|
| 1405 |
+
if self.xscale == 'log':
|
| 1406 |
+
xnew = 10**(np.log10(p[0]) + random * (np.log10(q[0]) -
|
| 1407 |
+
np.log10(p[0])))
|
| 1408 |
+
else:
|
| 1409 |
+
xnew = p[0] + random * (q[0] - p[0])
|
| 1410 |
+
ynew = _adaptive_eval(f, xnew)
|
| 1411 |
+
new_point = np.array([xnew, ynew])
|
| 1412 |
+
|
| 1413 |
+
# Maximum depth
|
| 1414 |
+
if depth > self.depth:
|
| 1415 |
+
x_coords.append(q[0])
|
| 1416 |
+
y_coords.append(q[1])
|
| 1417 |
+
|
| 1418 |
+
# Sample to depth of 6 (whether the line is flat or not)
|
| 1419 |
+
# without using linspace (to avoid aliasing).
|
| 1420 |
+
elif depth < 6:
|
| 1421 |
+
sample(p, new_point, depth + 1)
|
| 1422 |
+
sample(new_point, q, depth + 1)
|
| 1423 |
+
|
| 1424 |
+
# Sample ten points if complex values are encountered
|
| 1425 |
+
# at both ends. If there is a real value in between, then
|
| 1426 |
+
# sample those points further.
|
| 1427 |
+
elif p[1] is None and q[1] is None:
|
| 1428 |
+
if self.xscale == 'log':
|
| 1429 |
+
xarray = np.logspace(p[0], q[0], 10)
|
| 1430 |
+
else:
|
| 1431 |
+
xarray = np.linspace(p[0], q[0], 10)
|
| 1432 |
+
yarray = list(map(f, xarray))
|
| 1433 |
+
if not all(y is None for y in yarray):
|
| 1434 |
+
for i in range(len(yarray) - 1):
|
| 1435 |
+
if not (yarray[i] is None and yarray[i + 1] is None):
|
| 1436 |
+
sample([xarray[i], yarray[i]],
|
| 1437 |
+
[xarray[i + 1], yarray[i + 1]], depth + 1)
|
| 1438 |
+
|
| 1439 |
+
# Sample further if one of the end points in None (i.e. a
|
| 1440 |
+
# complex value) or the three points are not almost collinear.
|
| 1441 |
+
elif (p[1] is None or q[1] is None or new_point[1] is None
|
| 1442 |
+
or not flat(p, new_point, q)):
|
| 1443 |
+
sample(p, new_point, depth + 1)
|
| 1444 |
+
sample(new_point, q, depth + 1)
|
| 1445 |
+
else:
|
| 1446 |
+
x_coords.append(q[0])
|
| 1447 |
+
y_coords.append(q[1])
|
| 1448 |
+
|
| 1449 |
+
f_start = _adaptive_eval(f, self.start.real)
|
| 1450 |
+
f_end = _adaptive_eval(f, self.end.real)
|
| 1451 |
+
x_coords.append(self.start.real)
|
| 1452 |
+
y_coords.append(f_start)
|
| 1453 |
+
sample(np.array([self.start.real, f_start]),
|
| 1454 |
+
np.array([self.end.real, f_end]), 0)
|
| 1455 |
+
|
| 1456 |
+
return (x_coords, y_coords)
|
| 1457 |
+
|
| 1458 |
+
def _uniform_sampling(self):
|
| 1459 |
+
np = import_module('numpy')
|
| 1460 |
+
|
| 1461 |
+
x, result = self._evaluate()
|
| 1462 |
+
_re, _im = np.real(result), np.imag(result)
|
| 1463 |
+
_re = self._correct_shape(_re, x)
|
| 1464 |
+
_im = self._correct_shape(_im, x)
|
| 1465 |
+
return x, _re, _im
|
| 1466 |
+
|
| 1467 |
+
def _get_data_helper(self):
|
| 1468 |
+
"""Returns coordinates that needs to be postprocessed.
|
| 1469 |
+
"""
|
| 1470 |
+
np = import_module('numpy')
|
| 1471 |
+
if self.adaptive and (not self.only_integers):
|
| 1472 |
+
x, y = self._adaptive_sampling()
|
| 1473 |
+
return [np.array(t) for t in [x, y]]
|
| 1474 |
+
|
| 1475 |
+
x, _re, _im = self._uniform_sampling()
|
| 1476 |
+
|
| 1477 |
+
if self._return is None:
|
| 1478 |
+
# The evaluation could produce complex numbers. Set real elements
|
| 1479 |
+
# to NaN where there are non-zero imaginary elements
|
| 1480 |
+
_re[np.invert(np.isclose(_im, np.zeros_like(_im)))] = np.nan
|
| 1481 |
+
elif self._return == "real":
|
| 1482 |
+
pass
|
| 1483 |
+
elif self._return == "imag":
|
| 1484 |
+
_re = _im
|
| 1485 |
+
elif self._return == "abs":
|
| 1486 |
+
_re = np.sqrt(_re**2 + _im**2)
|
| 1487 |
+
elif self._return == "arg":
|
| 1488 |
+
_re = np.arctan2(_im, _re)
|
| 1489 |
+
else:
|
| 1490 |
+
raise ValueError("`_return` not recognized. "
|
| 1491 |
+
"Received: %s" % self._return)
|
| 1492 |
+
|
| 1493 |
+
return x, _re
|
| 1494 |
+
|
| 1495 |
+
|
| 1496 |
+
class ParametricLineBaseSeries(Line2DBaseSeries):
|
| 1497 |
+
is_parametric = True
|
| 1498 |
+
|
| 1499 |
+
def _set_parametric_line_label(self, label):
|
| 1500 |
+
"""Logic to set the correct label to be shown on the plot.
|
| 1501 |
+
If `use_cm=True` there will be a colorbar, so we show the parameter.
|
| 1502 |
+
If `use_cm=False`, there might be a legend, so we show the expressions.
|
| 1503 |
+
|
| 1504 |
+
Parameters
|
| 1505 |
+
==========
|
| 1506 |
+
label : str
|
| 1507 |
+
label passed in by the pre-processor or the user
|
| 1508 |
+
"""
|
| 1509 |
+
self._label = str(self.var) if label is None else label
|
| 1510 |
+
self._latex_label = latex(self.var) if label is None else label
|
| 1511 |
+
if (self.use_cm is False) and (self._label == str(self.var)):
|
| 1512 |
+
self._label = str(self.expr)
|
| 1513 |
+
self._latex_label = latex(self.expr)
|
| 1514 |
+
# if the expressions is a lambda function and use_cm=False and no label
|
| 1515 |
+
# has been provided, then its better to do the following in order to
|
| 1516 |
+
# avoid surprises on the backend
|
| 1517 |
+
if any(callable(e) for e in self.expr) and (not self.use_cm):
|
| 1518 |
+
if self._label == str(self.expr):
|
| 1519 |
+
self._label = ""
|
| 1520 |
+
|
| 1521 |
+
def get_label(self, use_latex=False, wrapper="$%s$"):
|
| 1522 |
+
# parametric lines returns the representation of the parameter to be
|
| 1523 |
+
# shown on the colorbar if `use_cm=True`, otherwise it returns the
|
| 1524 |
+
# representation of the expression to be placed on the legend.
|
| 1525 |
+
if self.use_cm:
|
| 1526 |
+
if str(self.var) == self._label:
|
| 1527 |
+
if use_latex:
|
| 1528 |
+
return self._get_wrapped_label(latex(self.var), wrapper)
|
| 1529 |
+
return str(self.var)
|
| 1530 |
+
# here the user has provided a custom label
|
| 1531 |
+
return self._label
|
| 1532 |
+
if use_latex:
|
| 1533 |
+
if self._label != str(self.expr):
|
| 1534 |
+
return self._latex_label
|
| 1535 |
+
return self._get_wrapped_label(self._latex_label, wrapper)
|
| 1536 |
+
return self._label
|
| 1537 |
+
|
| 1538 |
+
def _get_data_helper(self):
|
| 1539 |
+
"""Returns coordinates that needs to be postprocessed.
|
| 1540 |
+
Depending on the `adaptive` option, this function will either use an
|
| 1541 |
+
adaptive algorithm or it will uniformly sample the expression over the
|
| 1542 |
+
provided range.
|
| 1543 |
+
"""
|
| 1544 |
+
if self.adaptive:
|
| 1545 |
+
np = import_module("numpy")
|
| 1546 |
+
coords = self._adaptive_sampling()
|
| 1547 |
+
coords = [np.array(t) for t in coords]
|
| 1548 |
+
else:
|
| 1549 |
+
coords = self._uniform_sampling()
|
| 1550 |
+
|
| 1551 |
+
if self.is_2Dline and self.is_polar:
|
| 1552 |
+
# when plot_polar is executed with polar_axis=True
|
| 1553 |
+
np = import_module('numpy')
|
| 1554 |
+
x, y, _ = coords
|
| 1555 |
+
r = np.sqrt(x**2 + y**2)
|
| 1556 |
+
t = np.arctan2(y, x)
|
| 1557 |
+
coords = [t, r, coords[-1]]
|
| 1558 |
+
|
| 1559 |
+
if callable(self.color_func):
|
| 1560 |
+
coords = list(coords)
|
| 1561 |
+
coords[-1] = self.eval_color_func(*coords)
|
| 1562 |
+
|
| 1563 |
+
return coords
|
| 1564 |
+
|
| 1565 |
+
def _uniform_sampling(self):
|
| 1566 |
+
"""Returns coordinates that needs to be postprocessed."""
|
| 1567 |
+
np = import_module('numpy')
|
| 1568 |
+
|
| 1569 |
+
results = self._evaluate()
|
| 1570 |
+
for i, r in enumerate(results):
|
| 1571 |
+
_re, _im = np.real(r), np.imag(r)
|
| 1572 |
+
_re[np.invert(np.isclose(_im, np.zeros_like(_im)))] = np.nan
|
| 1573 |
+
results[i] = _re
|
| 1574 |
+
|
| 1575 |
+
return [*results[1:], results[0]]
|
| 1576 |
+
|
| 1577 |
+
def get_parameter_points(self):
|
| 1578 |
+
return self.get_data()[-1]
|
| 1579 |
+
|
| 1580 |
+
def get_points(self):
|
| 1581 |
+
""" Return lists of coordinates for plotting. Depending on the
|
| 1582 |
+
``adaptive`` option, this function will either use an adaptive algorithm
|
| 1583 |
+
or it will uniformly sample the expression over the provided range.
|
| 1584 |
+
|
| 1585 |
+
This function is available for back-compatibility purposes. Consider
|
| 1586 |
+
using ``get_data()`` instead.
|
| 1587 |
+
|
| 1588 |
+
Returns
|
| 1589 |
+
=======
|
| 1590 |
+
x : list
|
| 1591 |
+
List of x-coordinates
|
| 1592 |
+
y : list
|
| 1593 |
+
List of y-coordinates
|
| 1594 |
+
z : list
|
| 1595 |
+
List of z-coordinates, only for 3D parametric line plot.
|
| 1596 |
+
"""
|
| 1597 |
+
return self._get_data_helper()[:-1]
|
| 1598 |
+
|
| 1599 |
+
@property
|
| 1600 |
+
def nb_of_points(self):
|
| 1601 |
+
return self.n[0]
|
| 1602 |
+
|
| 1603 |
+
@nb_of_points.setter
|
| 1604 |
+
def nb_of_points(self, v):
|
| 1605 |
+
self.n = v
|
| 1606 |
+
|
| 1607 |
+
|
| 1608 |
+
class Parametric2DLineSeries(ParametricLineBaseSeries):
|
| 1609 |
+
"""Representation for a line consisting of two parametric SymPy expressions
|
| 1610 |
+
over a range."""
|
| 1611 |
+
|
| 1612 |
+
is_2Dline = True
|
| 1613 |
+
|
| 1614 |
+
def __init__(self, expr_x, expr_y, var_start_end, label="", **kwargs):
|
| 1615 |
+
super().__init__(**kwargs)
|
| 1616 |
+
self.expr_x = expr_x if callable(expr_x) else sympify(expr_x)
|
| 1617 |
+
self.expr_y = expr_y if callable(expr_y) else sympify(expr_y)
|
| 1618 |
+
self.expr = (self.expr_x, self.expr_y)
|
| 1619 |
+
self.ranges = [var_start_end]
|
| 1620 |
+
self._cast = float
|
| 1621 |
+
self.use_cm = kwargs.get("use_cm", True)
|
| 1622 |
+
self._set_parametric_line_label(label)
|
| 1623 |
+
self._post_init()
|
| 1624 |
+
|
| 1625 |
+
def __str__(self):
|
| 1626 |
+
return self._str_helper(
|
| 1627 |
+
"parametric cartesian line: (%s, %s) for %s over %s" % (
|
| 1628 |
+
str(self.expr_x),
|
| 1629 |
+
str(self.expr_y),
|
| 1630 |
+
str(self.var),
|
| 1631 |
+
str((self.start, self.end))
|
| 1632 |
+
))
|
| 1633 |
+
|
| 1634 |
+
def _adaptive_sampling(self):
|
| 1635 |
+
try:
|
| 1636 |
+
if callable(self.expr_x) and callable(self.expr_y):
|
| 1637 |
+
f_x = self.expr_x
|
| 1638 |
+
f_y = self.expr_y
|
| 1639 |
+
else:
|
| 1640 |
+
f_x = lambdify([self.var], self.expr_x)
|
| 1641 |
+
f_y = lambdify([self.var], self.expr_y)
|
| 1642 |
+
x, y, p = self._adaptive_sampling_helper(f_x, f_y)
|
| 1643 |
+
except Exception as err:
|
| 1644 |
+
warnings.warn(
|
| 1645 |
+
"The evaluation with %s failed.\n" % (
|
| 1646 |
+
"NumPy/SciPy" if not self.modules else self.modules) +
|
| 1647 |
+
"{}: {}\n".format(type(err).__name__, err) +
|
| 1648 |
+
"Trying to evaluate the expression with Sympy, but it might "
|
| 1649 |
+
"be a slow operation."
|
| 1650 |
+
)
|
| 1651 |
+
f_x = lambdify([self.var], self.expr_x, "sympy")
|
| 1652 |
+
f_y = lambdify([self.var], self.expr_y, "sympy")
|
| 1653 |
+
x, y, p = self._adaptive_sampling_helper(f_x, f_y)
|
| 1654 |
+
return x, y, p
|
| 1655 |
+
|
| 1656 |
+
def _adaptive_sampling_helper(self, f_x, f_y):
|
| 1657 |
+
"""The adaptive sampling is done by recursively checking if three
|
| 1658 |
+
points are almost collinear. If they are not collinear, then more
|
| 1659 |
+
points are added between those points.
|
| 1660 |
+
|
| 1661 |
+
References
|
| 1662 |
+
==========
|
| 1663 |
+
|
| 1664 |
+
.. [1] Adaptive polygonal approximation of parametric curves,
|
| 1665 |
+
Luiz Henrique de Figueiredo.
|
| 1666 |
+
"""
|
| 1667 |
+
x_coords = []
|
| 1668 |
+
y_coords = []
|
| 1669 |
+
param = []
|
| 1670 |
+
|
| 1671 |
+
def sample(param_p, param_q, p, q, depth):
|
| 1672 |
+
""" Samples recursively if three points are almost collinear.
|
| 1673 |
+
For depth < 6, points are added irrespective of whether they
|
| 1674 |
+
satisfy the collinearity condition or not. The maximum depth
|
| 1675 |
+
allowed is 12.
|
| 1676 |
+
"""
|
| 1677 |
+
# Randomly sample to avoid aliasing.
|
| 1678 |
+
np = import_module('numpy')
|
| 1679 |
+
random = 0.45 + np.random.rand() * 0.1
|
| 1680 |
+
param_new = param_p + random * (param_q - param_p)
|
| 1681 |
+
xnew = _adaptive_eval(f_x, param_new)
|
| 1682 |
+
ynew = _adaptive_eval(f_y, param_new)
|
| 1683 |
+
new_point = np.array([xnew, ynew])
|
| 1684 |
+
|
| 1685 |
+
# Maximum depth
|
| 1686 |
+
if depth > self.depth:
|
| 1687 |
+
x_coords.append(q[0])
|
| 1688 |
+
y_coords.append(q[1])
|
| 1689 |
+
param.append(param_p)
|
| 1690 |
+
|
| 1691 |
+
# Sample irrespective of whether the line is flat till the
|
| 1692 |
+
# depth of 6. We are not using linspace to avoid aliasing.
|
| 1693 |
+
elif depth < 6:
|
| 1694 |
+
sample(param_p, param_new, p, new_point, depth + 1)
|
| 1695 |
+
sample(param_new, param_q, new_point, q, depth + 1)
|
| 1696 |
+
|
| 1697 |
+
# Sample ten points if complex values are encountered
|
| 1698 |
+
# at both ends. If there is a real value in between, then
|
| 1699 |
+
# sample those points further.
|
| 1700 |
+
elif ((p[0] is None and q[1] is None) or
|
| 1701 |
+
(p[1] is None and q[1] is None)):
|
| 1702 |
+
param_array = np.linspace(param_p, param_q, 10)
|
| 1703 |
+
x_array = [_adaptive_eval(f_x, t) for t in param_array]
|
| 1704 |
+
y_array = [_adaptive_eval(f_y, t) for t in param_array]
|
| 1705 |
+
if not all(x is None and y is None
|
| 1706 |
+
for x, y in zip(x_array, y_array)):
|
| 1707 |
+
for i in range(len(y_array) - 1):
|
| 1708 |
+
if ((x_array[i] is not None and y_array[i] is not None) or
|
| 1709 |
+
(x_array[i + 1] is not None and y_array[i + 1] is not None)):
|
| 1710 |
+
point_a = [x_array[i], y_array[i]]
|
| 1711 |
+
point_b = [x_array[i + 1], y_array[i + 1]]
|
| 1712 |
+
sample(param_array[i], param_array[i], point_a,
|
| 1713 |
+
point_b, depth + 1)
|
| 1714 |
+
|
| 1715 |
+
# Sample further if one of the end points in None (i.e. a complex
|
| 1716 |
+
# value) or the three points are not almost collinear.
|
| 1717 |
+
elif (p[0] is None or p[1] is None
|
| 1718 |
+
or q[1] is None or q[0] is None
|
| 1719 |
+
or not flat(p, new_point, q)):
|
| 1720 |
+
sample(param_p, param_new, p, new_point, depth + 1)
|
| 1721 |
+
sample(param_new, param_q, new_point, q, depth + 1)
|
| 1722 |
+
else:
|
| 1723 |
+
x_coords.append(q[0])
|
| 1724 |
+
y_coords.append(q[1])
|
| 1725 |
+
param.append(param_p)
|
| 1726 |
+
|
| 1727 |
+
f_start_x = _adaptive_eval(f_x, self.start)
|
| 1728 |
+
f_start_y = _adaptive_eval(f_y, self.start)
|
| 1729 |
+
start = [f_start_x, f_start_y]
|
| 1730 |
+
f_end_x = _adaptive_eval(f_x, self.end)
|
| 1731 |
+
f_end_y = _adaptive_eval(f_y, self.end)
|
| 1732 |
+
end = [f_end_x, f_end_y]
|
| 1733 |
+
x_coords.append(f_start_x)
|
| 1734 |
+
y_coords.append(f_start_y)
|
| 1735 |
+
param.append(self.start)
|
| 1736 |
+
sample(self.start, self.end, start, end, 0)
|
| 1737 |
+
|
| 1738 |
+
return x_coords, y_coords, param
|
| 1739 |
+
|
| 1740 |
+
|
| 1741 |
+
### 3D lines
|
| 1742 |
+
class Line3DBaseSeries(Line2DBaseSeries):
|
| 1743 |
+
"""A base class for 3D lines.
|
| 1744 |
+
|
| 1745 |
+
Most of the stuff is derived from Line2DBaseSeries."""
|
| 1746 |
+
|
| 1747 |
+
is_2Dline = False
|
| 1748 |
+
is_3Dline = True
|
| 1749 |
+
_dim = 3
|
| 1750 |
+
|
| 1751 |
+
def __init__(self):
|
| 1752 |
+
super().__init__()
|
| 1753 |
+
|
| 1754 |
+
|
| 1755 |
+
class Parametric3DLineSeries(ParametricLineBaseSeries):
|
| 1756 |
+
"""Representation for a 3D line consisting of three parametric SymPy
|
| 1757 |
+
expressions and a range."""
|
| 1758 |
+
|
| 1759 |
+
is_2Dline = False
|
| 1760 |
+
is_3Dline = True
|
| 1761 |
+
|
| 1762 |
+
def __init__(self, expr_x, expr_y, expr_z, var_start_end, label="", **kwargs):
|
| 1763 |
+
super().__init__(**kwargs)
|
| 1764 |
+
self.expr_x = expr_x if callable(expr_x) else sympify(expr_x)
|
| 1765 |
+
self.expr_y = expr_y if callable(expr_y) else sympify(expr_y)
|
| 1766 |
+
self.expr_z = expr_z if callable(expr_z) else sympify(expr_z)
|
| 1767 |
+
self.expr = (self.expr_x, self.expr_y, self.expr_z)
|
| 1768 |
+
self.ranges = [var_start_end]
|
| 1769 |
+
self._cast = float
|
| 1770 |
+
self.adaptive = False
|
| 1771 |
+
self.use_cm = kwargs.get("use_cm", True)
|
| 1772 |
+
self._set_parametric_line_label(label)
|
| 1773 |
+
self._post_init()
|
| 1774 |
+
# TODO: remove this
|
| 1775 |
+
self._xlim = None
|
| 1776 |
+
self._ylim = None
|
| 1777 |
+
self._zlim = None
|
| 1778 |
+
|
| 1779 |
+
def __str__(self):
|
| 1780 |
+
return self._str_helper(
|
| 1781 |
+
"3D parametric cartesian line: (%s, %s, %s) for %s over %s" % (
|
| 1782 |
+
str(self.expr_x),
|
| 1783 |
+
str(self.expr_y),
|
| 1784 |
+
str(self.expr_z),
|
| 1785 |
+
str(self.var),
|
| 1786 |
+
str((self.start, self.end))
|
| 1787 |
+
))
|
| 1788 |
+
|
| 1789 |
+
def get_data(self):
|
| 1790 |
+
# TODO: remove this
|
| 1791 |
+
np = import_module("numpy")
|
| 1792 |
+
x, y, z, p = super().get_data()
|
| 1793 |
+
self._xlim = (np.amin(x), np.amax(x))
|
| 1794 |
+
self._ylim = (np.amin(y), np.amax(y))
|
| 1795 |
+
self._zlim = (np.amin(z), np.amax(z))
|
| 1796 |
+
return x, y, z, p
|
| 1797 |
+
|
| 1798 |
+
|
| 1799 |
+
### Surfaces
|
| 1800 |
+
class SurfaceBaseSeries(BaseSeries):
|
| 1801 |
+
"""A base class for 3D surfaces."""
|
| 1802 |
+
|
| 1803 |
+
is_3Dsurface = True
|
| 1804 |
+
|
| 1805 |
+
def __init__(self, *args, **kwargs):
|
| 1806 |
+
super().__init__(**kwargs)
|
| 1807 |
+
self.use_cm = kwargs.get("use_cm", False)
|
| 1808 |
+
# NOTE: why should SurfaceOver2DRangeSeries support is polar?
|
| 1809 |
+
# After all, the same result can be achieve with
|
| 1810 |
+
# ParametricSurfaceSeries. For example:
|
| 1811 |
+
# sin(r) for (r, 0, 2 * pi) and (theta, 0, pi/2) can be parameterized
|
| 1812 |
+
# as (r * cos(theta), r * sin(theta), sin(t)) for (r, 0, 2 * pi) and
|
| 1813 |
+
# (theta, 0, pi/2).
|
| 1814 |
+
# Because it is faster to evaluate (important for interactive plots).
|
| 1815 |
+
self.is_polar = kwargs.get("is_polar", kwargs.get("polar", False))
|
| 1816 |
+
self.surface_color = kwargs.get("surface_color", None)
|
| 1817 |
+
self.color_func = kwargs.get("color_func", lambda x, y, z: z)
|
| 1818 |
+
if callable(self.surface_color):
|
| 1819 |
+
self.color_func = self.surface_color
|
| 1820 |
+
self.surface_color = None
|
| 1821 |
+
|
| 1822 |
+
def _set_surface_label(self, label):
|
| 1823 |
+
exprs = self.expr
|
| 1824 |
+
self._label = str(exprs) if label is None else label
|
| 1825 |
+
self._latex_label = latex(exprs) if label is None else label
|
| 1826 |
+
# if the expressions is a lambda function and no label
|
| 1827 |
+
# has been provided, then its better to do the following to avoid
|
| 1828 |
+
# surprises on the backend
|
| 1829 |
+
is_lambda = (callable(exprs) if not hasattr(exprs, "__iter__")
|
| 1830 |
+
else any(callable(e) for e in exprs))
|
| 1831 |
+
if is_lambda and (self._label == str(exprs)):
|
| 1832 |
+
self._label = ""
|
| 1833 |
+
self._latex_label = ""
|
| 1834 |
+
|
| 1835 |
+
def get_color_array(self):
|
| 1836 |
+
np = import_module('numpy')
|
| 1837 |
+
c = self.surface_color
|
| 1838 |
+
if isinstance(c, Callable):
|
| 1839 |
+
f = np.vectorize(c)
|
| 1840 |
+
nargs = arity(c)
|
| 1841 |
+
if self.is_parametric:
|
| 1842 |
+
variables = list(map(centers_of_faces, self.get_parameter_meshes()))
|
| 1843 |
+
if nargs == 1:
|
| 1844 |
+
return f(variables[0])
|
| 1845 |
+
elif nargs == 2:
|
| 1846 |
+
return f(*variables)
|
| 1847 |
+
variables = list(map(centers_of_faces, self.get_meshes()))
|
| 1848 |
+
if nargs == 1:
|
| 1849 |
+
return f(variables[0])
|
| 1850 |
+
elif nargs == 2:
|
| 1851 |
+
return f(*variables[:2])
|
| 1852 |
+
else:
|
| 1853 |
+
return f(*variables)
|
| 1854 |
+
else:
|
| 1855 |
+
if isinstance(self, SurfaceOver2DRangeSeries):
|
| 1856 |
+
return c*np.ones(min(self.nb_of_points_x, self.nb_of_points_y))
|
| 1857 |
+
else:
|
| 1858 |
+
return c*np.ones(min(self.nb_of_points_u, self.nb_of_points_v))
|
| 1859 |
+
|
| 1860 |
+
|
| 1861 |
+
class SurfaceOver2DRangeSeries(SurfaceBaseSeries):
|
| 1862 |
+
"""Representation for a 3D surface consisting of a SymPy expression and 2D
|
| 1863 |
+
range."""
|
| 1864 |
+
|
| 1865 |
+
def __init__(self, expr, var_start_end_x, var_start_end_y, label="", **kwargs):
|
| 1866 |
+
super().__init__(**kwargs)
|
| 1867 |
+
self.expr = expr if callable(expr) else sympify(expr)
|
| 1868 |
+
self.ranges = [var_start_end_x, var_start_end_y]
|
| 1869 |
+
self._set_surface_label(label)
|
| 1870 |
+
self._post_init()
|
| 1871 |
+
# TODO: remove this
|
| 1872 |
+
self._xlim = (self.start_x, self.end_x)
|
| 1873 |
+
self._ylim = (self.start_y, self.end_y)
|
| 1874 |
+
|
| 1875 |
+
@property
|
| 1876 |
+
def var_x(self):
|
| 1877 |
+
return self.ranges[0][0]
|
| 1878 |
+
|
| 1879 |
+
@property
|
| 1880 |
+
def var_y(self):
|
| 1881 |
+
return self.ranges[1][0]
|
| 1882 |
+
|
| 1883 |
+
@property
|
| 1884 |
+
def start_x(self):
|
| 1885 |
+
try:
|
| 1886 |
+
return float(self.ranges[0][1])
|
| 1887 |
+
except TypeError:
|
| 1888 |
+
return self.ranges[0][1]
|
| 1889 |
+
|
| 1890 |
+
@property
|
| 1891 |
+
def end_x(self):
|
| 1892 |
+
try:
|
| 1893 |
+
return float(self.ranges[0][2])
|
| 1894 |
+
except TypeError:
|
| 1895 |
+
return self.ranges[0][2]
|
| 1896 |
+
|
| 1897 |
+
@property
|
| 1898 |
+
def start_y(self):
|
| 1899 |
+
try:
|
| 1900 |
+
return float(self.ranges[1][1])
|
| 1901 |
+
except TypeError:
|
| 1902 |
+
return self.ranges[1][1]
|
| 1903 |
+
|
| 1904 |
+
@property
|
| 1905 |
+
def end_y(self):
|
| 1906 |
+
try:
|
| 1907 |
+
return float(self.ranges[1][2])
|
| 1908 |
+
except TypeError:
|
| 1909 |
+
return self.ranges[1][2]
|
| 1910 |
+
|
| 1911 |
+
@property
|
| 1912 |
+
def nb_of_points_x(self):
|
| 1913 |
+
return self.n[0]
|
| 1914 |
+
|
| 1915 |
+
@nb_of_points_x.setter
|
| 1916 |
+
def nb_of_points_x(self, v):
|
| 1917 |
+
n = self.n
|
| 1918 |
+
self.n = [v, n[1:]]
|
| 1919 |
+
|
| 1920 |
+
@property
|
| 1921 |
+
def nb_of_points_y(self):
|
| 1922 |
+
return self.n[1]
|
| 1923 |
+
|
| 1924 |
+
@nb_of_points_y.setter
|
| 1925 |
+
def nb_of_points_y(self, v):
|
| 1926 |
+
n = self.n
|
| 1927 |
+
self.n = [n[0], v, n[2]]
|
| 1928 |
+
|
| 1929 |
+
def __str__(self):
|
| 1930 |
+
series_type = "cartesian surface" if self.is_3Dsurface else "contour"
|
| 1931 |
+
return self._str_helper(
|
| 1932 |
+
series_type + ": %s for" " %s over %s and %s over %s" % (
|
| 1933 |
+
str(self.expr),
|
| 1934 |
+
str(self.var_x), str((self.start_x, self.end_x)),
|
| 1935 |
+
str(self.var_y), str((self.start_y, self.end_y)),
|
| 1936 |
+
))
|
| 1937 |
+
|
| 1938 |
+
def get_meshes(self):
|
| 1939 |
+
"""Return the x,y,z coordinates for plotting the surface.
|
| 1940 |
+
This function is available for back-compatibility purposes. Consider
|
| 1941 |
+
using ``get_data()`` instead.
|
| 1942 |
+
"""
|
| 1943 |
+
return self.get_data()
|
| 1944 |
+
|
| 1945 |
+
def get_data(self):
|
| 1946 |
+
"""Return arrays of coordinates for plotting.
|
| 1947 |
+
|
| 1948 |
+
Returns
|
| 1949 |
+
=======
|
| 1950 |
+
mesh_x : np.ndarray
|
| 1951 |
+
Discretized x-domain.
|
| 1952 |
+
mesh_y : np.ndarray
|
| 1953 |
+
Discretized y-domain.
|
| 1954 |
+
mesh_z : np.ndarray
|
| 1955 |
+
Results of the evaluation.
|
| 1956 |
+
"""
|
| 1957 |
+
np = import_module('numpy')
|
| 1958 |
+
|
| 1959 |
+
results = self._evaluate()
|
| 1960 |
+
# mask out complex values
|
| 1961 |
+
for i, r in enumerate(results):
|
| 1962 |
+
_re, _im = np.real(r), np.imag(r)
|
| 1963 |
+
_re[np.invert(np.isclose(_im, np.zeros_like(_im)))] = np.nan
|
| 1964 |
+
results[i] = _re
|
| 1965 |
+
|
| 1966 |
+
x, y, z = results
|
| 1967 |
+
if self.is_polar and self.is_3Dsurface:
|
| 1968 |
+
r = x.copy()
|
| 1969 |
+
x = r * np.cos(y)
|
| 1970 |
+
y = r * np.sin(y)
|
| 1971 |
+
|
| 1972 |
+
# TODO: remove this
|
| 1973 |
+
self._zlim = (np.amin(z), np.amax(z))
|
| 1974 |
+
|
| 1975 |
+
return self._apply_transform(x, y, z)
|
| 1976 |
+
|
| 1977 |
+
|
| 1978 |
+
class ParametricSurfaceSeries(SurfaceBaseSeries):
|
| 1979 |
+
"""Representation for a 3D surface consisting of three parametric SymPy
|
| 1980 |
+
expressions and a range."""
|
| 1981 |
+
|
| 1982 |
+
is_parametric = True
|
| 1983 |
+
|
| 1984 |
+
def __init__(self, expr_x, expr_y, expr_z,
|
| 1985 |
+
var_start_end_u, var_start_end_v, label="", **kwargs):
|
| 1986 |
+
super().__init__(**kwargs)
|
| 1987 |
+
self.expr_x = expr_x if callable(expr_x) else sympify(expr_x)
|
| 1988 |
+
self.expr_y = expr_y if callable(expr_y) else sympify(expr_y)
|
| 1989 |
+
self.expr_z = expr_z if callable(expr_z) else sympify(expr_z)
|
| 1990 |
+
self.expr = (self.expr_x, self.expr_y, self.expr_z)
|
| 1991 |
+
self.ranges = [var_start_end_u, var_start_end_v]
|
| 1992 |
+
self.color_func = kwargs.get("color_func", lambda x, y, z, u, v: z)
|
| 1993 |
+
self._set_surface_label(label)
|
| 1994 |
+
self._post_init()
|
| 1995 |
+
|
| 1996 |
+
@property
|
| 1997 |
+
def var_u(self):
|
| 1998 |
+
return self.ranges[0][0]
|
| 1999 |
+
|
| 2000 |
+
@property
|
| 2001 |
+
def var_v(self):
|
| 2002 |
+
return self.ranges[1][0]
|
| 2003 |
+
|
| 2004 |
+
@property
|
| 2005 |
+
def start_u(self):
|
| 2006 |
+
try:
|
| 2007 |
+
return float(self.ranges[0][1])
|
| 2008 |
+
except TypeError:
|
| 2009 |
+
return self.ranges[0][1]
|
| 2010 |
+
|
| 2011 |
+
@property
|
| 2012 |
+
def end_u(self):
|
| 2013 |
+
try:
|
| 2014 |
+
return float(self.ranges[0][2])
|
| 2015 |
+
except TypeError:
|
| 2016 |
+
return self.ranges[0][2]
|
| 2017 |
+
|
| 2018 |
+
@property
|
| 2019 |
+
def start_v(self):
|
| 2020 |
+
try:
|
| 2021 |
+
return float(self.ranges[1][1])
|
| 2022 |
+
except TypeError:
|
| 2023 |
+
return self.ranges[1][1]
|
| 2024 |
+
|
| 2025 |
+
@property
|
| 2026 |
+
def end_v(self):
|
| 2027 |
+
try:
|
| 2028 |
+
return float(self.ranges[1][2])
|
| 2029 |
+
except TypeError:
|
| 2030 |
+
return self.ranges[1][2]
|
| 2031 |
+
|
| 2032 |
+
@property
|
| 2033 |
+
def nb_of_points_u(self):
|
| 2034 |
+
return self.n[0]
|
| 2035 |
+
|
| 2036 |
+
@nb_of_points_u.setter
|
| 2037 |
+
def nb_of_points_u(self, v):
|
| 2038 |
+
n = self.n
|
| 2039 |
+
self.n = [v, n[1:]]
|
| 2040 |
+
|
| 2041 |
+
@property
|
| 2042 |
+
def nb_of_points_v(self):
|
| 2043 |
+
return self.n[1]
|
| 2044 |
+
|
| 2045 |
+
@nb_of_points_v.setter
|
| 2046 |
+
def nb_of_points_v(self, v):
|
| 2047 |
+
n = self.n
|
| 2048 |
+
self.n = [n[0], v, n[2]]
|
| 2049 |
+
|
| 2050 |
+
def __str__(self):
|
| 2051 |
+
return self._str_helper(
|
| 2052 |
+
"parametric cartesian surface: (%s, %s, %s) for"
|
| 2053 |
+
" %s over %s and %s over %s" % (
|
| 2054 |
+
str(self.expr_x), str(self.expr_y), str(self.expr_z),
|
| 2055 |
+
str(self.var_u), str((self.start_u, self.end_u)),
|
| 2056 |
+
str(self.var_v), str((self.start_v, self.end_v)),
|
| 2057 |
+
))
|
| 2058 |
+
|
| 2059 |
+
def get_parameter_meshes(self):
|
| 2060 |
+
return self.get_data()[3:]
|
| 2061 |
+
|
| 2062 |
+
def get_meshes(self):
|
| 2063 |
+
"""Return the x,y,z coordinates for plotting the surface.
|
| 2064 |
+
This function is available for back-compatibility purposes. Consider
|
| 2065 |
+
using ``get_data()`` instead.
|
| 2066 |
+
"""
|
| 2067 |
+
return self.get_data()[:3]
|
| 2068 |
+
|
| 2069 |
+
def get_data(self):
|
| 2070 |
+
"""Return arrays of coordinates for plotting.
|
| 2071 |
+
|
| 2072 |
+
Returns
|
| 2073 |
+
=======
|
| 2074 |
+
x : np.ndarray [n2 x n1]
|
| 2075 |
+
x-coordinates.
|
| 2076 |
+
y : np.ndarray [n2 x n1]
|
| 2077 |
+
y-coordinates.
|
| 2078 |
+
z : np.ndarray [n2 x n1]
|
| 2079 |
+
z-coordinates.
|
| 2080 |
+
mesh_u : np.ndarray [n2 x n1]
|
| 2081 |
+
Discretized u range.
|
| 2082 |
+
mesh_v : np.ndarray [n2 x n1]
|
| 2083 |
+
Discretized v range.
|
| 2084 |
+
"""
|
| 2085 |
+
np = import_module('numpy')
|
| 2086 |
+
|
| 2087 |
+
results = self._evaluate()
|
| 2088 |
+
# mask out complex values
|
| 2089 |
+
for i, r in enumerate(results):
|
| 2090 |
+
_re, _im = np.real(r), np.imag(r)
|
| 2091 |
+
_re[np.invert(np.isclose(_im, np.zeros_like(_im)))] = np.nan
|
| 2092 |
+
results[i] = _re
|
| 2093 |
+
|
| 2094 |
+
# TODO: remove this
|
| 2095 |
+
x, y, z = results[2:]
|
| 2096 |
+
self._xlim = (np.amin(x), np.amax(x))
|
| 2097 |
+
self._ylim = (np.amin(y), np.amax(y))
|
| 2098 |
+
self._zlim = (np.amin(z), np.amax(z))
|
| 2099 |
+
|
| 2100 |
+
return self._apply_transform(*results[2:], *results[:2])
|
| 2101 |
+
|
| 2102 |
+
|
| 2103 |
+
### Contours
|
| 2104 |
+
class ContourSeries(SurfaceOver2DRangeSeries):
|
| 2105 |
+
"""Representation for a contour plot."""
|
| 2106 |
+
|
| 2107 |
+
is_3Dsurface = False
|
| 2108 |
+
is_contour = True
|
| 2109 |
+
|
| 2110 |
+
def __init__(self, *args, **kwargs):
|
| 2111 |
+
super().__init__(*args, **kwargs)
|
| 2112 |
+
self.is_filled = kwargs.get("is_filled", kwargs.get("fill", True))
|
| 2113 |
+
self.show_clabels = kwargs.get("clabels", True)
|
| 2114 |
+
|
| 2115 |
+
# NOTE: contour plots are used by plot_contour, plot_vector and
|
| 2116 |
+
# plot_complex_vector. By implementing contour_kw we are able to
|
| 2117 |
+
# quickly target the contour plot.
|
| 2118 |
+
self.rendering_kw = kwargs.get("contour_kw",
|
| 2119 |
+
kwargs.get("rendering_kw", {}))
|
| 2120 |
+
|
| 2121 |
+
|
| 2122 |
+
class GenericDataSeries(BaseSeries):
|
| 2123 |
+
"""Represents generic numerical data.
|
| 2124 |
+
|
| 2125 |
+
Notes
|
| 2126 |
+
=====
|
| 2127 |
+
This class serves the purpose of back-compatibility with the "markers,
|
| 2128 |
+
annotations, fill, rectangles" keyword arguments that represent
|
| 2129 |
+
user-provided numerical data. In particular, it solves the problem of
|
| 2130 |
+
combining together two or more plot-objects with the ``extend`` or
|
| 2131 |
+
``append`` methods: user-provided numerical data is also taken into
|
| 2132 |
+
consideration because it is stored in this series class.
|
| 2133 |
+
|
| 2134 |
+
Also note that the current implementation is far from optimal, as each
|
| 2135 |
+
keyword argument is stored into an attribute in the ``Plot`` class, which
|
| 2136 |
+
requires a hard-coded if-statement in the ``MatplotlibBackend`` class.
|
| 2137 |
+
The implementation suggests that it is ok to add attributes and
|
| 2138 |
+
if-statements to provide more and more functionalities for user-provided
|
| 2139 |
+
numerical data (e.g. adding horizontal lines, or vertical lines, or bar
|
| 2140 |
+
plots, etc). However, in doing so one would reinvent the wheel: plotting
|
| 2141 |
+
libraries (like Matplotlib) already implements the necessary API.
|
| 2142 |
+
|
| 2143 |
+
Instead of adding more keyword arguments and attributes, users interested
|
| 2144 |
+
in adding custom numerical data to a plot should retrieve the figure
|
| 2145 |
+
created by this plotting module. For example, this code:
|
| 2146 |
+
|
| 2147 |
+
.. plot::
|
| 2148 |
+
:context: close-figs
|
| 2149 |
+
:include-source: True
|
| 2150 |
+
|
| 2151 |
+
from sympy import Symbol, plot, cos
|
| 2152 |
+
x = Symbol("x")
|
| 2153 |
+
p = plot(cos(x), markers=[{"args": [[0, 1, 2], [0, 1, -1], "*"]}])
|
| 2154 |
+
|
| 2155 |
+
Becomes:
|
| 2156 |
+
|
| 2157 |
+
.. plot::
|
| 2158 |
+
:context: close-figs
|
| 2159 |
+
:include-source: True
|
| 2160 |
+
|
| 2161 |
+
p = plot(cos(x), backend="matplotlib")
|
| 2162 |
+
fig, ax = p._backend.fig, p._backend.ax
|
| 2163 |
+
ax.plot([0, 1, 2], [0, 1, -1], "*")
|
| 2164 |
+
fig
|
| 2165 |
+
|
| 2166 |
+
Which is far better in terms of readability. Also, it gives access to the
|
| 2167 |
+
full plotting library capabilities, without the need to reinvent the wheel.
|
| 2168 |
+
"""
|
| 2169 |
+
is_generic = True
|
| 2170 |
+
|
| 2171 |
+
def __init__(self, tp, *args, **kwargs):
|
| 2172 |
+
self.type = tp
|
| 2173 |
+
self.args = args
|
| 2174 |
+
self.rendering_kw = kwargs
|
| 2175 |
+
|
| 2176 |
+
def get_data(self):
|
| 2177 |
+
return self.args
|
| 2178 |
+
|
| 2179 |
+
|
| 2180 |
+
class ImplicitSeries(BaseSeries):
|
| 2181 |
+
"""Representation for 2D Implicit plot."""
|
| 2182 |
+
|
| 2183 |
+
is_implicit = True
|
| 2184 |
+
use_cm = False
|
| 2185 |
+
_N = 100
|
| 2186 |
+
|
| 2187 |
+
def __init__(self, expr, var_start_end_x, var_start_end_y, label="", **kwargs):
|
| 2188 |
+
super().__init__(**kwargs)
|
| 2189 |
+
self.adaptive = kwargs.get("adaptive", False)
|
| 2190 |
+
self.expr = expr
|
| 2191 |
+
self._label = str(expr) if label is None else label
|
| 2192 |
+
self._latex_label = latex(expr) if label is None else label
|
| 2193 |
+
self.ranges = [var_start_end_x, var_start_end_y]
|
| 2194 |
+
self.var_x, self.start_x, self.end_x = self.ranges[0]
|
| 2195 |
+
self.var_y, self.start_y, self.end_y = self.ranges[1]
|
| 2196 |
+
self._color = kwargs.get("color", kwargs.get("line_color", None))
|
| 2197 |
+
|
| 2198 |
+
if self.is_interactive and self.adaptive:
|
| 2199 |
+
raise NotImplementedError("Interactive plot with `adaptive=True` "
|
| 2200 |
+
"is not supported.")
|
| 2201 |
+
|
| 2202 |
+
# Check whether the depth is greater than 4 or less than 0.
|
| 2203 |
+
depth = kwargs.get("depth", 0)
|
| 2204 |
+
if depth > 4:
|
| 2205 |
+
depth = 4
|
| 2206 |
+
elif depth < 0:
|
| 2207 |
+
depth = 0
|
| 2208 |
+
self.depth = 4 + depth
|
| 2209 |
+
self._post_init()
|
| 2210 |
+
|
| 2211 |
+
@property
|
| 2212 |
+
def expr(self):
|
| 2213 |
+
if self.adaptive:
|
| 2214 |
+
return self._adaptive_expr
|
| 2215 |
+
return self._non_adaptive_expr
|
| 2216 |
+
|
| 2217 |
+
@expr.setter
|
| 2218 |
+
def expr(self, expr):
|
| 2219 |
+
self._block_lambda_functions(expr)
|
| 2220 |
+
# these are needed for adaptive evaluation
|
| 2221 |
+
expr, has_equality = self._has_equality(sympify(expr))
|
| 2222 |
+
self._adaptive_expr = expr
|
| 2223 |
+
self.has_equality = has_equality
|
| 2224 |
+
self._label = str(expr)
|
| 2225 |
+
self._latex_label = latex(expr)
|
| 2226 |
+
|
| 2227 |
+
if isinstance(expr, (BooleanFunction, Ne)) and (not self.adaptive):
|
| 2228 |
+
self.adaptive = True
|
| 2229 |
+
msg = "contains Boolean functions. "
|
| 2230 |
+
if isinstance(expr, Ne):
|
| 2231 |
+
msg = "is an unequality. "
|
| 2232 |
+
warnings.warn(
|
| 2233 |
+
"The provided expression " + msg
|
| 2234 |
+
+ "In order to plot the expression, the algorithm "
|
| 2235 |
+
+ "automatically switched to an adaptive sampling."
|
| 2236 |
+
)
|
| 2237 |
+
|
| 2238 |
+
if isinstance(expr, BooleanFunction):
|
| 2239 |
+
self._non_adaptive_expr = None
|
| 2240 |
+
self._is_equality = False
|
| 2241 |
+
else:
|
| 2242 |
+
# these are needed for uniform meshing evaluation
|
| 2243 |
+
expr, is_equality = self._preprocess_meshgrid_expression(expr, self.adaptive)
|
| 2244 |
+
self._non_adaptive_expr = expr
|
| 2245 |
+
self._is_equality = is_equality
|
| 2246 |
+
|
| 2247 |
+
@property
|
| 2248 |
+
def line_color(self):
|
| 2249 |
+
return self._color
|
| 2250 |
+
|
| 2251 |
+
@line_color.setter
|
| 2252 |
+
def line_color(self, v):
|
| 2253 |
+
self._color = v
|
| 2254 |
+
|
| 2255 |
+
color = line_color
|
| 2256 |
+
|
| 2257 |
+
def _has_equality(self, expr):
|
| 2258 |
+
# Represents whether the expression contains an Equality, GreaterThan
|
| 2259 |
+
# or LessThan
|
| 2260 |
+
has_equality = False
|
| 2261 |
+
|
| 2262 |
+
def arg_expand(bool_expr):
|
| 2263 |
+
"""Recursively expands the arguments of an Boolean Function"""
|
| 2264 |
+
for arg in bool_expr.args:
|
| 2265 |
+
if isinstance(arg, BooleanFunction):
|
| 2266 |
+
arg_expand(arg)
|
| 2267 |
+
elif isinstance(arg, Relational):
|
| 2268 |
+
arg_list.append(arg)
|
| 2269 |
+
|
| 2270 |
+
arg_list = []
|
| 2271 |
+
if isinstance(expr, BooleanFunction):
|
| 2272 |
+
arg_expand(expr)
|
| 2273 |
+
# Check whether there is an equality in the expression provided.
|
| 2274 |
+
if any(isinstance(e, (Equality, GreaterThan, LessThan)) for e in arg_list):
|
| 2275 |
+
has_equality = True
|
| 2276 |
+
elif not isinstance(expr, Relational):
|
| 2277 |
+
expr = Equality(expr, 0)
|
| 2278 |
+
has_equality = True
|
| 2279 |
+
elif isinstance(expr, (Equality, GreaterThan, LessThan)):
|
| 2280 |
+
has_equality = True
|
| 2281 |
+
|
| 2282 |
+
return expr, has_equality
|
| 2283 |
+
|
| 2284 |
+
def __str__(self):
|
| 2285 |
+
f = lambda t: float(t) if len(t.free_symbols) == 0 else t
|
| 2286 |
+
|
| 2287 |
+
return self._str_helper(
|
| 2288 |
+
"Implicit expression: %s for %s over %s and %s over %s") % (
|
| 2289 |
+
str(self._adaptive_expr),
|
| 2290 |
+
str(self.var_x),
|
| 2291 |
+
str((f(self.start_x), f(self.end_x))),
|
| 2292 |
+
str(self.var_y),
|
| 2293 |
+
str((f(self.start_y), f(self.end_y))),
|
| 2294 |
+
)
|
| 2295 |
+
|
| 2296 |
+
def get_data(self):
|
| 2297 |
+
"""Returns numerical data.
|
| 2298 |
+
|
| 2299 |
+
Returns
|
| 2300 |
+
=======
|
| 2301 |
+
|
| 2302 |
+
If the series is evaluated with the `adaptive=True` it returns:
|
| 2303 |
+
|
| 2304 |
+
interval_list : list
|
| 2305 |
+
List of bounding rectangular intervals to be postprocessed and
|
| 2306 |
+
eventually used with Matplotlib's ``fill`` command.
|
| 2307 |
+
dummy : str
|
| 2308 |
+
A string containing ``"fill"``.
|
| 2309 |
+
|
| 2310 |
+
Otherwise, it returns 2D numpy arrays to be used with Matplotlib's
|
| 2311 |
+
``contour`` or ``contourf`` commands:
|
| 2312 |
+
|
| 2313 |
+
x_array : np.ndarray
|
| 2314 |
+
y_array : np.ndarray
|
| 2315 |
+
z_array : np.ndarray
|
| 2316 |
+
plot_type : str
|
| 2317 |
+
A string specifying which plot command to use, ``"contour"``
|
| 2318 |
+
or ``"contourf"``.
|
| 2319 |
+
"""
|
| 2320 |
+
if self.adaptive:
|
| 2321 |
+
data = self._adaptive_eval()
|
| 2322 |
+
if data is not None:
|
| 2323 |
+
return data
|
| 2324 |
+
|
| 2325 |
+
return self._get_meshes_grid()
|
| 2326 |
+
|
| 2327 |
+
def _adaptive_eval(self):
|
| 2328 |
+
"""
|
| 2329 |
+
References
|
| 2330 |
+
==========
|
| 2331 |
+
|
| 2332 |
+
.. [1] Jeffrey Allen Tupper. Reliable Two-Dimensional Graphing Methods for
|
| 2333 |
+
Mathematical Formulae with Two Free Variables.
|
| 2334 |
+
|
| 2335 |
+
.. [2] Jeffrey Allen Tupper. Graphing Equations with Generalized Interval
|
| 2336 |
+
Arithmetic. Master's thesis. University of Toronto, 1996
|
| 2337 |
+
"""
|
| 2338 |
+
import sympy.plotting.intervalmath.lib_interval as li
|
| 2339 |
+
|
| 2340 |
+
user_functions = {}
|
| 2341 |
+
printer = IntervalMathPrinter({
|
| 2342 |
+
'fully_qualified_modules': False, 'inline': True,
|
| 2343 |
+
'allow_unknown_functions': True,
|
| 2344 |
+
'user_functions': user_functions})
|
| 2345 |
+
|
| 2346 |
+
keys = [t for t in dir(li) if ("__" not in t) and (t not in ["import_module", "interval"])]
|
| 2347 |
+
vals = [getattr(li, k) for k in keys]
|
| 2348 |
+
d = dict(zip(keys, vals))
|
| 2349 |
+
func = lambdify((self.var_x, self.var_y), self.expr, modules=[d], printer=printer)
|
| 2350 |
+
data = None
|
| 2351 |
+
|
| 2352 |
+
try:
|
| 2353 |
+
data = self._get_raster_interval(func)
|
| 2354 |
+
except NameError as err:
|
| 2355 |
+
warnings.warn(
|
| 2356 |
+
"Adaptive meshing could not be applied to the"
|
| 2357 |
+
" expression, as some functions are not yet implemented"
|
| 2358 |
+
" in the interval math module:\n\n"
|
| 2359 |
+
"NameError: %s\n\n" % err +
|
| 2360 |
+
"Proceeding with uniform meshing."
|
| 2361 |
+
)
|
| 2362 |
+
self.adaptive = False
|
| 2363 |
+
except TypeError:
|
| 2364 |
+
warnings.warn(
|
| 2365 |
+
"Adaptive meshing could not be applied to the"
|
| 2366 |
+
" expression. Using uniform meshing.")
|
| 2367 |
+
self.adaptive = False
|
| 2368 |
+
|
| 2369 |
+
return data
|
| 2370 |
+
|
| 2371 |
+
def _get_raster_interval(self, func):
|
| 2372 |
+
"""Uses interval math to adaptively mesh and obtain the plot"""
|
| 2373 |
+
np = import_module('numpy')
|
| 2374 |
+
|
| 2375 |
+
k = self.depth
|
| 2376 |
+
interval_list = []
|
| 2377 |
+
sx, sy = [float(t) for t in [self.start_x, self.start_y]]
|
| 2378 |
+
ex, ey = [float(t) for t in [self.end_x, self.end_y]]
|
| 2379 |
+
# Create initial 32 divisions
|
| 2380 |
+
xsample = np.linspace(sx, ex, 33)
|
| 2381 |
+
ysample = np.linspace(sy, ey, 33)
|
| 2382 |
+
|
| 2383 |
+
# Add a small jitter so that there are no false positives for equality.
|
| 2384 |
+
# Ex: y==x becomes True for x interval(1, 2) and y interval(1, 2)
|
| 2385 |
+
# which will draw a rectangle.
|
| 2386 |
+
jitterx = (
|
| 2387 |
+
(np.random.rand(len(xsample)) * 2 - 1)
|
| 2388 |
+
* (ex - sx)
|
| 2389 |
+
/ 2 ** 20
|
| 2390 |
+
)
|
| 2391 |
+
jittery = (
|
| 2392 |
+
(np.random.rand(len(ysample)) * 2 - 1)
|
| 2393 |
+
* (ey - sy)
|
| 2394 |
+
/ 2 ** 20
|
| 2395 |
+
)
|
| 2396 |
+
xsample += jitterx
|
| 2397 |
+
ysample += jittery
|
| 2398 |
+
|
| 2399 |
+
xinter = [interval(x1, x2) for x1, x2 in zip(xsample[:-1], xsample[1:])]
|
| 2400 |
+
yinter = [interval(y1, y2) for y1, y2 in zip(ysample[:-1], ysample[1:])]
|
| 2401 |
+
interval_list = [[x, y] for x in xinter for y in yinter]
|
| 2402 |
+
plot_list = []
|
| 2403 |
+
|
| 2404 |
+
# recursive call refinepixels which subdivides the intervals which are
|
| 2405 |
+
# neither True nor False according to the expression.
|
| 2406 |
+
def refine_pixels(interval_list):
|
| 2407 |
+
"""Evaluates the intervals and subdivides the interval if the
|
| 2408 |
+
expression is partially satisfied."""
|
| 2409 |
+
temp_interval_list = []
|
| 2410 |
+
plot_list = []
|
| 2411 |
+
for intervals in interval_list:
|
| 2412 |
+
|
| 2413 |
+
# Convert the array indices to x and y values
|
| 2414 |
+
intervalx = intervals[0]
|
| 2415 |
+
intervaly = intervals[1]
|
| 2416 |
+
func_eval = func(intervalx, intervaly)
|
| 2417 |
+
# The expression is valid in the interval. Change the contour
|
| 2418 |
+
# array values to 1.
|
| 2419 |
+
if func_eval[1] is False or func_eval[0] is False:
|
| 2420 |
+
pass
|
| 2421 |
+
elif func_eval == (True, True):
|
| 2422 |
+
plot_list.append([intervalx, intervaly])
|
| 2423 |
+
elif func_eval[1] is None or func_eval[0] is None:
|
| 2424 |
+
# Subdivide
|
| 2425 |
+
avgx = intervalx.mid
|
| 2426 |
+
avgy = intervaly.mid
|
| 2427 |
+
a = interval(intervalx.start, avgx)
|
| 2428 |
+
b = interval(avgx, intervalx.end)
|
| 2429 |
+
c = interval(intervaly.start, avgy)
|
| 2430 |
+
d = interval(avgy, intervaly.end)
|
| 2431 |
+
temp_interval_list.append([a, c])
|
| 2432 |
+
temp_interval_list.append([a, d])
|
| 2433 |
+
temp_interval_list.append([b, c])
|
| 2434 |
+
temp_interval_list.append([b, d])
|
| 2435 |
+
return temp_interval_list, plot_list
|
| 2436 |
+
|
| 2437 |
+
while k >= 0 and len(interval_list):
|
| 2438 |
+
interval_list, plot_list_temp = refine_pixels(interval_list)
|
| 2439 |
+
plot_list.extend(plot_list_temp)
|
| 2440 |
+
k = k - 1
|
| 2441 |
+
# Check whether the expression represents an equality
|
| 2442 |
+
# If it represents an equality, then none of the intervals
|
| 2443 |
+
# would have satisfied the expression due to floating point
|
| 2444 |
+
# differences. Add all the undecided values to the plot.
|
| 2445 |
+
if self.has_equality:
|
| 2446 |
+
for intervals in interval_list:
|
| 2447 |
+
intervalx = intervals[0]
|
| 2448 |
+
intervaly = intervals[1]
|
| 2449 |
+
func_eval = func(intervalx, intervaly)
|
| 2450 |
+
if func_eval[1] and func_eval[0] is not False:
|
| 2451 |
+
plot_list.append([intervalx, intervaly])
|
| 2452 |
+
return plot_list, "fill"
|
| 2453 |
+
|
| 2454 |
+
def _get_meshes_grid(self):
|
| 2455 |
+
"""Generates the mesh for generating a contour.
|
| 2456 |
+
|
| 2457 |
+
In the case of equality, ``contour`` function of matplotlib can
|
| 2458 |
+
be used. In other cases, matplotlib's ``contourf`` is used.
|
| 2459 |
+
"""
|
| 2460 |
+
np = import_module('numpy')
|
| 2461 |
+
|
| 2462 |
+
xarray, yarray, z_grid = self._evaluate()
|
| 2463 |
+
_re, _im = np.real(z_grid), np.imag(z_grid)
|
| 2464 |
+
_re[np.invert(np.isclose(_im, np.zeros_like(_im)))] = np.nan
|
| 2465 |
+
if self._is_equality:
|
| 2466 |
+
return xarray, yarray, _re, 'contour'
|
| 2467 |
+
return xarray, yarray, _re, 'contourf'
|
| 2468 |
+
|
| 2469 |
+
@staticmethod
|
| 2470 |
+
def _preprocess_meshgrid_expression(expr, adaptive):
|
| 2471 |
+
"""If the expression is a Relational, rewrite it as a single
|
| 2472 |
+
expression.
|
| 2473 |
+
|
| 2474 |
+
Returns
|
| 2475 |
+
=======
|
| 2476 |
+
|
| 2477 |
+
expr : Expr
|
| 2478 |
+
The rewritten expression
|
| 2479 |
+
|
| 2480 |
+
equality : Boolean
|
| 2481 |
+
Whether the original expression was an Equality or not.
|
| 2482 |
+
"""
|
| 2483 |
+
equality = False
|
| 2484 |
+
if isinstance(expr, Equality):
|
| 2485 |
+
expr = expr.lhs - expr.rhs
|
| 2486 |
+
equality = True
|
| 2487 |
+
elif isinstance(expr, Relational):
|
| 2488 |
+
expr = expr.gts - expr.lts
|
| 2489 |
+
elif not adaptive:
|
| 2490 |
+
raise NotImplementedError(
|
| 2491 |
+
"The expression is not supported for "
|
| 2492 |
+
"plotting in uniform meshed plot."
|
| 2493 |
+
)
|
| 2494 |
+
return expr, equality
|
| 2495 |
+
|
| 2496 |
+
def get_label(self, use_latex=False, wrapper="$%s$"):
|
| 2497 |
+
"""Return the label to be used to display the expression.
|
| 2498 |
+
|
| 2499 |
+
Parameters
|
| 2500 |
+
==========
|
| 2501 |
+
use_latex : bool
|
| 2502 |
+
If False, the string representation of the expression is returned.
|
| 2503 |
+
If True, the latex representation is returned.
|
| 2504 |
+
wrapper : str
|
| 2505 |
+
The backend might need the latex representation to be wrapped by
|
| 2506 |
+
some characters. Default to ``"$%s$"``.
|
| 2507 |
+
|
| 2508 |
+
Returns
|
| 2509 |
+
=======
|
| 2510 |
+
label : str
|
| 2511 |
+
"""
|
| 2512 |
+
if use_latex is False:
|
| 2513 |
+
return self._label
|
| 2514 |
+
if self._label == str(self._adaptive_expr):
|
| 2515 |
+
return self._get_wrapped_label(self._latex_label, wrapper)
|
| 2516 |
+
return self._latex_label
|
| 2517 |
+
|
| 2518 |
+
|
| 2519 |
+
##############################################################################
|
| 2520 |
+
# Finding the centers of line segments or mesh faces
|
| 2521 |
+
##############################################################################
|
| 2522 |
+
|
| 2523 |
+
def centers_of_segments(array):
|
| 2524 |
+
np = import_module('numpy')
|
| 2525 |
+
return np.mean(np.vstack((array[:-1], array[1:])), 0)
|
| 2526 |
+
|
| 2527 |
+
|
| 2528 |
+
def centers_of_faces(array):
|
| 2529 |
+
np = import_module('numpy')
|
| 2530 |
+
return np.mean(np.dstack((array[:-1, :-1],
|
| 2531 |
+
array[1:, :-1],
|
| 2532 |
+
array[:-1, 1:],
|
| 2533 |
+
array[:-1, :-1],
|
| 2534 |
+
)), 2)
|
| 2535 |
+
|
| 2536 |
+
|
| 2537 |
+
def flat(x, y, z, eps=1e-3):
|
| 2538 |
+
"""Checks whether three points are almost collinear"""
|
| 2539 |
+
np = import_module('numpy')
|
| 2540 |
+
# Workaround plotting piecewise (#8577)
|
| 2541 |
+
vector_a = (x - y).astype(float)
|
| 2542 |
+
vector_b = (z - y).astype(float)
|
| 2543 |
+
dot_product = np.dot(vector_a, vector_b)
|
| 2544 |
+
vector_a_norm = np.linalg.norm(vector_a)
|
| 2545 |
+
vector_b_norm = np.linalg.norm(vector_b)
|
| 2546 |
+
cos_theta = dot_product / (vector_a_norm * vector_b_norm)
|
| 2547 |
+
return abs(cos_theta + 1) < eps
|
| 2548 |
+
|
| 2549 |
+
|
| 2550 |
+
def _set_discretization_points(kwargs, pt):
|
| 2551 |
+
"""Allow the use of the keyword arguments ``n, n1, n2`` to
|
| 2552 |
+
specify the number of discretization points in one and two
|
| 2553 |
+
directions, while keeping back-compatibility with older keyword arguments
|
| 2554 |
+
like, ``nb_of_points, nb_of_points_*, points``.
|
| 2555 |
+
|
| 2556 |
+
Parameters
|
| 2557 |
+
==========
|
| 2558 |
+
|
| 2559 |
+
kwargs : dict
|
| 2560 |
+
Dictionary of keyword arguments passed into a plotting function.
|
| 2561 |
+
pt : type
|
| 2562 |
+
The type of the series, which indicates the kind of plot we are
|
| 2563 |
+
trying to create.
|
| 2564 |
+
"""
|
| 2565 |
+
replace_old_keywords = {
|
| 2566 |
+
"nb_of_points": "n",
|
| 2567 |
+
"nb_of_points_x": "n1",
|
| 2568 |
+
"nb_of_points_y": "n2",
|
| 2569 |
+
"nb_of_points_u": "n1",
|
| 2570 |
+
"nb_of_points_v": "n2",
|
| 2571 |
+
"points": "n"
|
| 2572 |
+
}
|
| 2573 |
+
for k, v in replace_old_keywords.items():
|
| 2574 |
+
if k in kwargs.keys():
|
| 2575 |
+
kwargs[v] = kwargs.pop(k)
|
| 2576 |
+
|
| 2577 |
+
if pt in [LineOver1DRangeSeries, Parametric2DLineSeries,
|
| 2578 |
+
Parametric3DLineSeries]:
|
| 2579 |
+
if "n" in kwargs.keys():
|
| 2580 |
+
kwargs["n1"] = kwargs["n"]
|
| 2581 |
+
if hasattr(kwargs["n"], "__iter__") and (len(kwargs["n"]) > 0):
|
| 2582 |
+
kwargs["n1"] = kwargs["n"][0]
|
| 2583 |
+
elif pt in [SurfaceOver2DRangeSeries, ContourSeries,
|
| 2584 |
+
ParametricSurfaceSeries, ImplicitSeries]:
|
| 2585 |
+
if "n" in kwargs.keys():
|
| 2586 |
+
if hasattr(kwargs["n"], "__iter__") and (len(kwargs["n"]) > 1):
|
| 2587 |
+
kwargs["n1"] = kwargs["n"][0]
|
| 2588 |
+
kwargs["n2"] = kwargs["n"][1]
|
| 2589 |
+
else:
|
| 2590 |
+
kwargs["n1"] = kwargs["n2"] = kwargs["n"]
|
| 2591 |
+
return kwargs
|
venv/lib/python3.14/site-packages/sympy/plotting/tests/__init__.py
ADDED
|
File without changes
|
venv/lib/python3.14/site-packages/sympy/plotting/tests/test_experimental_lambdify.py
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from sympy.core.symbol import symbols, Symbol
|
| 2 |
+
from sympy.functions import Max
|
| 3 |
+
from sympy.plotting.experimental_lambdify import experimental_lambdify
|
| 4 |
+
from sympy.plotting.intervalmath.interval_arithmetic import \
|
| 5 |
+
interval, intervalMembership
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
# Tests for exception handling in experimental_lambdify
|
| 9 |
+
def test_experimental_lambify():
|
| 10 |
+
x = Symbol('x')
|
| 11 |
+
f = experimental_lambdify([x], Max(x, 5))
|
| 12 |
+
# XXX should f be tested? If f(2) is attempted, an
|
| 13 |
+
# error is raised because a complex produced during wrapping of the arg
|
| 14 |
+
# is being compared with an int.
|
| 15 |
+
assert Max(2, 5) == 5
|
| 16 |
+
assert Max(5, 7) == 7
|
| 17 |
+
|
| 18 |
+
x = Symbol('x-3')
|
| 19 |
+
f = experimental_lambdify([x], x + 1)
|
| 20 |
+
assert f(1) == 2
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def test_composite_boolean_region():
|
| 24 |
+
x, y = symbols('x y')
|
| 25 |
+
|
| 26 |
+
r1 = (x - 1)**2 + y**2 < 2
|
| 27 |
+
r2 = (x + 1)**2 + y**2 < 2
|
| 28 |
+
|
| 29 |
+
f = experimental_lambdify((x, y), r1 & r2)
|
| 30 |
+
a = (interval(-0.1, 0.1), interval(-0.1, 0.1))
|
| 31 |
+
assert f(*a) == intervalMembership(True, True)
|
| 32 |
+
a = (interval(-1.1, -0.9), interval(-0.1, 0.1))
|
| 33 |
+
assert f(*a) == intervalMembership(False, True)
|
| 34 |
+
a = (interval(0.9, 1.1), interval(-0.1, 0.1))
|
| 35 |
+
assert f(*a) == intervalMembership(False, True)
|
| 36 |
+
a = (interval(-0.1, 0.1), interval(1.9, 2.1))
|
| 37 |
+
assert f(*a) == intervalMembership(False, True)
|
| 38 |
+
|
| 39 |
+
f = experimental_lambdify((x, y), r1 | r2)
|
| 40 |
+
a = (interval(-0.1, 0.1), interval(-0.1, 0.1))
|
| 41 |
+
assert f(*a) == intervalMembership(True, True)
|
| 42 |
+
a = (interval(-1.1, -0.9), interval(-0.1, 0.1))
|
| 43 |
+
assert f(*a) == intervalMembership(True, True)
|
| 44 |
+
a = (interval(0.9, 1.1), interval(-0.1, 0.1))
|
| 45 |
+
assert f(*a) == intervalMembership(True, True)
|
| 46 |
+
a = (interval(-0.1, 0.1), interval(1.9, 2.1))
|
| 47 |
+
assert f(*a) == intervalMembership(False, True)
|
| 48 |
+
|
| 49 |
+
f = experimental_lambdify((x, y), r1 & ~r2)
|
| 50 |
+
a = (interval(-0.1, 0.1), interval(-0.1, 0.1))
|
| 51 |
+
assert f(*a) == intervalMembership(False, True)
|
| 52 |
+
a = (interval(-1.1, -0.9), interval(-0.1, 0.1))
|
| 53 |
+
assert f(*a) == intervalMembership(False, True)
|
| 54 |
+
a = (interval(0.9, 1.1), interval(-0.1, 0.1))
|
| 55 |
+
assert f(*a) == intervalMembership(True, True)
|
| 56 |
+
a = (interval(-0.1, 0.1), interval(1.9, 2.1))
|
| 57 |
+
assert f(*a) == intervalMembership(False, True)
|
| 58 |
+
|
| 59 |
+
f = experimental_lambdify((x, y), ~r1 & r2)
|
| 60 |
+
a = (interval(-0.1, 0.1), interval(-0.1, 0.1))
|
| 61 |
+
assert f(*a) == intervalMembership(False, True)
|
| 62 |
+
a = (interval(-1.1, -0.9), interval(-0.1, 0.1))
|
| 63 |
+
assert f(*a) == intervalMembership(True, True)
|
| 64 |
+
a = (interval(0.9, 1.1), interval(-0.1, 0.1))
|
| 65 |
+
assert f(*a) == intervalMembership(False, True)
|
| 66 |
+
a = (interval(-0.1, 0.1), interval(1.9, 2.1))
|
| 67 |
+
assert f(*a) == intervalMembership(False, True)
|
| 68 |
+
|
| 69 |
+
f = experimental_lambdify((x, y), ~r1 & ~r2)
|
| 70 |
+
a = (interval(-0.1, 0.1), interval(-0.1, 0.1))
|
| 71 |
+
assert f(*a) == intervalMembership(False, True)
|
| 72 |
+
a = (interval(-1.1, -0.9), interval(-0.1, 0.1))
|
| 73 |
+
assert f(*a) == intervalMembership(False, True)
|
| 74 |
+
a = (interval(0.9, 1.1), interval(-0.1, 0.1))
|
| 75 |
+
assert f(*a) == intervalMembership(False, True)
|
| 76 |
+
a = (interval(-0.1, 0.1), interval(1.9, 2.1))
|
| 77 |
+
assert f(*a) == intervalMembership(True, True)
|
venv/lib/python3.14/site-packages/sympy/plotting/tests/test_plot.py
ADDED
|
@@ -0,0 +1,1344 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
from tempfile import TemporaryDirectory
|
| 3 |
+
import pytest
|
| 4 |
+
from sympy.concrete.summations import Sum
|
| 5 |
+
from sympy.core.numbers import (I, oo, pi)
|
| 6 |
+
from sympy.core.relational import Ne
|
| 7 |
+
from sympy.core.symbol import Symbol, symbols
|
| 8 |
+
from sympy.functions.elementary.exponential import (LambertW, exp, exp_polar, log)
|
| 9 |
+
from sympy.functions.elementary.miscellaneous import (real_root, sqrt)
|
| 10 |
+
from sympy.functions.elementary.piecewise import Piecewise
|
| 11 |
+
from sympy.functions.elementary.trigonometric import (cos, sin)
|
| 12 |
+
from sympy.functions.elementary.miscellaneous import Min
|
| 13 |
+
from sympy.functions.special.hyper import meijerg
|
| 14 |
+
from sympy.integrals.integrals import Integral
|
| 15 |
+
from sympy.logic.boolalg import And
|
| 16 |
+
from sympy.core.singleton import S
|
| 17 |
+
from sympy.core.sympify import sympify
|
| 18 |
+
from sympy.external import import_module
|
| 19 |
+
from sympy.plotting.plot import (
|
| 20 |
+
Plot, plot, plot_parametric, plot3d_parametric_line, plot3d,
|
| 21 |
+
plot3d_parametric_surface)
|
| 22 |
+
from sympy.plotting.plot import (
|
| 23 |
+
unset_show, plot_contour, PlotGrid, MatplotlibBackend, TextBackend)
|
| 24 |
+
from sympy.plotting.series import (
|
| 25 |
+
LineOver1DRangeSeries, Parametric2DLineSeries, Parametric3DLineSeries,
|
| 26 |
+
ParametricSurfaceSeries, SurfaceOver2DRangeSeries)
|
| 27 |
+
from sympy.testing.pytest import skip, skip_under_pyodide, warns, raises, warns_deprecated_sympy
|
| 28 |
+
from sympy.utilities import lambdify as lambdify_
|
| 29 |
+
from sympy.utilities.exceptions import ignore_warnings
|
| 30 |
+
|
| 31 |
+
unset_show()
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
matplotlib = import_module(
|
| 35 |
+
'matplotlib', min_module_version='1.1.0', catch=(RuntimeError,))
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
class DummyBackendNotOk(Plot):
|
| 39 |
+
""" Used to verify if users can create their own backends.
|
| 40 |
+
This backend is meant to raise NotImplementedError for methods `show`,
|
| 41 |
+
`save`, `close`.
|
| 42 |
+
"""
|
| 43 |
+
def __new__(cls, *args, **kwargs):
|
| 44 |
+
return object.__new__(cls)
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
class DummyBackendOk(Plot):
|
| 48 |
+
""" Used to verify if users can create their own backends.
|
| 49 |
+
This backend is meant to pass all tests.
|
| 50 |
+
"""
|
| 51 |
+
def __new__(cls, *args, **kwargs):
|
| 52 |
+
return object.__new__(cls)
|
| 53 |
+
|
| 54 |
+
def show(self):
|
| 55 |
+
pass
|
| 56 |
+
|
| 57 |
+
def save(self):
|
| 58 |
+
pass
|
| 59 |
+
|
| 60 |
+
def close(self):
|
| 61 |
+
pass
|
| 62 |
+
|
| 63 |
+
def test_basic_plotting_backend():
|
| 64 |
+
x = Symbol('x')
|
| 65 |
+
plot(x, (x, 0, 3), backend='text')
|
| 66 |
+
plot(x**2 + 1, (x, 0, 3), backend='text')
|
| 67 |
+
|
| 68 |
+
@pytest.mark.parametrize("adaptive", [True, False])
|
| 69 |
+
def test_plot_and_save_1(adaptive):
|
| 70 |
+
if not matplotlib:
|
| 71 |
+
skip("Matplotlib not the default backend")
|
| 72 |
+
|
| 73 |
+
x = Symbol('x')
|
| 74 |
+
y = Symbol('y')
|
| 75 |
+
|
| 76 |
+
with TemporaryDirectory(prefix='sympy_') as tmpdir:
|
| 77 |
+
###
|
| 78 |
+
# Examples from the 'introduction' notebook
|
| 79 |
+
###
|
| 80 |
+
p = plot(x, legend=True, label='f1', adaptive=adaptive, n=10)
|
| 81 |
+
p = plot(x*sin(x), x*cos(x), label='f2', adaptive=adaptive, n=10)
|
| 82 |
+
p.extend(p)
|
| 83 |
+
p[0].line_color = lambda a: a
|
| 84 |
+
p[1].line_color = 'b'
|
| 85 |
+
p.title = 'Big title'
|
| 86 |
+
p.xlabel = 'the x axis'
|
| 87 |
+
p[1].label = 'straight line'
|
| 88 |
+
p.legend = True
|
| 89 |
+
p.aspect_ratio = (1, 1)
|
| 90 |
+
p.xlim = (-15, 20)
|
| 91 |
+
filename = 'test_basic_options_and_colors.png'
|
| 92 |
+
p.save(os.path.join(tmpdir, filename))
|
| 93 |
+
p._backend.close()
|
| 94 |
+
|
| 95 |
+
p.extend(plot(x + 1, adaptive=adaptive, n=10))
|
| 96 |
+
p.append(plot(x + 3, x**2, adaptive=adaptive, n=10)[1])
|
| 97 |
+
filename = 'test_plot_extend_append.png'
|
| 98 |
+
p.save(os.path.join(tmpdir, filename))
|
| 99 |
+
|
| 100 |
+
p[2] = plot(x**2, (x, -2, 3), adaptive=adaptive, n=10)
|
| 101 |
+
filename = 'test_plot_setitem.png'
|
| 102 |
+
p.save(os.path.join(tmpdir, filename))
|
| 103 |
+
p._backend.close()
|
| 104 |
+
|
| 105 |
+
p = plot(sin(x), (x, -2*pi, 4*pi), adaptive=adaptive, n=10)
|
| 106 |
+
filename = 'test_line_explicit.png'
|
| 107 |
+
p.save(os.path.join(tmpdir, filename))
|
| 108 |
+
p._backend.close()
|
| 109 |
+
|
| 110 |
+
p = plot(sin(x), adaptive=adaptive, n=10)
|
| 111 |
+
filename = 'test_line_default_range.png'
|
| 112 |
+
p.save(os.path.join(tmpdir, filename))
|
| 113 |
+
p._backend.close()
|
| 114 |
+
|
| 115 |
+
p = plot((x**2, (x, -5, 5)), (x**3, (x, -3, 3)), adaptive=adaptive, n=10)
|
| 116 |
+
filename = 'test_line_multiple_range.png'
|
| 117 |
+
p.save(os.path.join(tmpdir, filename))
|
| 118 |
+
p._backend.close()
|
| 119 |
+
|
| 120 |
+
raises(ValueError, lambda: plot(x, y))
|
| 121 |
+
|
| 122 |
+
#Piecewise plots
|
| 123 |
+
p = plot(Piecewise((1, x > 0), (0, True)), (x, -1, 1), adaptive=adaptive, n=10)
|
| 124 |
+
filename = 'test_plot_piecewise.png'
|
| 125 |
+
p.save(os.path.join(tmpdir, filename))
|
| 126 |
+
p._backend.close()
|
| 127 |
+
|
| 128 |
+
p = plot(Piecewise((x, x < 1), (x**2, True)), (x, -3, 3), adaptive=adaptive, n=10)
|
| 129 |
+
filename = 'test_plot_piecewise_2.png'
|
| 130 |
+
p.save(os.path.join(tmpdir, filename))
|
| 131 |
+
p._backend.close()
|
| 132 |
+
|
| 133 |
+
# test issue 7471
|
| 134 |
+
p1 = plot(x, adaptive=adaptive, n=10)
|
| 135 |
+
p2 = plot(3, adaptive=adaptive, n=10)
|
| 136 |
+
p1.extend(p2)
|
| 137 |
+
filename = 'test_horizontal_line.png'
|
| 138 |
+
p.save(os.path.join(tmpdir, filename))
|
| 139 |
+
p._backend.close()
|
| 140 |
+
|
| 141 |
+
# test issue 10925
|
| 142 |
+
f = Piecewise((-1, x < -1), (x, And(-1 <= x, x < 0)), \
|
| 143 |
+
(x**2, And(0 <= x, x < 1)), (x**3, x >= 1))
|
| 144 |
+
p = plot(f, (x, -3, 3), adaptive=adaptive, n=10)
|
| 145 |
+
filename = 'test_plot_piecewise_3.png'
|
| 146 |
+
p.save(os.path.join(tmpdir, filename))
|
| 147 |
+
p._backend.close()
|
| 148 |
+
|
| 149 |
+
|
| 150 |
+
@pytest.mark.parametrize("adaptive", [True, False])
|
| 151 |
+
def test_plot_and_save_2(adaptive):
|
| 152 |
+
if not matplotlib:
|
| 153 |
+
skip("Matplotlib not the default backend")
|
| 154 |
+
|
| 155 |
+
x = Symbol('x')
|
| 156 |
+
y = Symbol('y')
|
| 157 |
+
z = Symbol('z')
|
| 158 |
+
|
| 159 |
+
with TemporaryDirectory(prefix='sympy_') as tmpdir:
|
| 160 |
+
#parametric 2d plots.
|
| 161 |
+
#Single plot with default range.
|
| 162 |
+
p = plot_parametric(sin(x), cos(x), adaptive=adaptive, n=10)
|
| 163 |
+
filename = 'test_parametric.png'
|
| 164 |
+
p.save(os.path.join(tmpdir, filename))
|
| 165 |
+
p._backend.close()
|
| 166 |
+
|
| 167 |
+
#Single plot with range.
|
| 168 |
+
p = plot_parametric(
|
| 169 |
+
sin(x), cos(x), (x, -5, 5), legend=True, label='parametric_plot',
|
| 170 |
+
adaptive=adaptive, n=10)
|
| 171 |
+
filename = 'test_parametric_range.png'
|
| 172 |
+
p.save(os.path.join(tmpdir, filename))
|
| 173 |
+
p._backend.close()
|
| 174 |
+
|
| 175 |
+
#Multiple plots with same range.
|
| 176 |
+
p = plot_parametric((sin(x), cos(x)), (x, sin(x)),
|
| 177 |
+
adaptive=adaptive, n=10)
|
| 178 |
+
filename = 'test_parametric_multiple.png'
|
| 179 |
+
p.save(os.path.join(tmpdir, filename))
|
| 180 |
+
p._backend.close()
|
| 181 |
+
|
| 182 |
+
#Multiple plots with different ranges.
|
| 183 |
+
p = plot_parametric(
|
| 184 |
+
(sin(x), cos(x), (x, -3, 3)), (x, sin(x), (x, -5, 5)),
|
| 185 |
+
adaptive=adaptive, n=10)
|
| 186 |
+
filename = 'test_parametric_multiple_ranges.png'
|
| 187 |
+
p.save(os.path.join(tmpdir, filename))
|
| 188 |
+
p._backend.close()
|
| 189 |
+
|
| 190 |
+
#depth of recursion specified.
|
| 191 |
+
p = plot_parametric(x, sin(x), depth=13,
|
| 192 |
+
adaptive=adaptive, n=10)
|
| 193 |
+
filename = 'test_recursion_depth.png'
|
| 194 |
+
p.save(os.path.join(tmpdir, filename))
|
| 195 |
+
p._backend.close()
|
| 196 |
+
|
| 197 |
+
#No adaptive sampling.
|
| 198 |
+
p = plot_parametric(cos(x), sin(x), adaptive=False, n=500)
|
| 199 |
+
filename = 'test_adaptive.png'
|
| 200 |
+
p.save(os.path.join(tmpdir, filename))
|
| 201 |
+
p._backend.close()
|
| 202 |
+
|
| 203 |
+
#3d parametric plots
|
| 204 |
+
p = plot3d_parametric_line(
|
| 205 |
+
sin(x), cos(x), x, legend=True, label='3d_parametric_plot',
|
| 206 |
+
adaptive=adaptive, n=10)
|
| 207 |
+
filename = 'test_3d_line.png'
|
| 208 |
+
p.save(os.path.join(tmpdir, filename))
|
| 209 |
+
p._backend.close()
|
| 210 |
+
|
| 211 |
+
p = plot3d_parametric_line(
|
| 212 |
+
(sin(x), cos(x), x, (x, -5, 5)), (cos(x), sin(x), x, (x, -3, 3)),
|
| 213 |
+
adaptive=adaptive, n=10)
|
| 214 |
+
filename = 'test_3d_line_multiple.png'
|
| 215 |
+
p.save(os.path.join(tmpdir, filename))
|
| 216 |
+
p._backend.close()
|
| 217 |
+
|
| 218 |
+
p = plot3d_parametric_line(sin(x), cos(x), x, n=30,
|
| 219 |
+
adaptive=adaptive)
|
| 220 |
+
filename = 'test_3d_line_points.png'
|
| 221 |
+
p.save(os.path.join(tmpdir, filename))
|
| 222 |
+
p._backend.close()
|
| 223 |
+
|
| 224 |
+
# 3d surface single plot.
|
| 225 |
+
p = plot3d(x * y, adaptive=adaptive, n=10)
|
| 226 |
+
filename = 'test_surface.png'
|
| 227 |
+
p.save(os.path.join(tmpdir, filename))
|
| 228 |
+
p._backend.close()
|
| 229 |
+
|
| 230 |
+
# Multiple 3D plots with same range.
|
| 231 |
+
p = plot3d(-x * y, x * y, (x, -5, 5), adaptive=adaptive, n=10)
|
| 232 |
+
filename = 'test_surface_multiple.png'
|
| 233 |
+
p.save(os.path.join(tmpdir, filename))
|
| 234 |
+
p._backend.close()
|
| 235 |
+
|
| 236 |
+
# Multiple 3D plots with different ranges.
|
| 237 |
+
p = plot3d(
|
| 238 |
+
(x * y, (x, -3, 3), (y, -3, 3)), (-x * y, (x, -3, 3), (y, -3, 3)),
|
| 239 |
+
adaptive=adaptive, n=10)
|
| 240 |
+
filename = 'test_surface_multiple_ranges.png'
|
| 241 |
+
p.save(os.path.join(tmpdir, filename))
|
| 242 |
+
p._backend.close()
|
| 243 |
+
|
| 244 |
+
# Single Parametric 3D plot
|
| 245 |
+
p = plot3d_parametric_surface(sin(x + y), cos(x - y), x - y,
|
| 246 |
+
adaptive=adaptive, n=10)
|
| 247 |
+
filename = 'test_parametric_surface.png'
|
| 248 |
+
p.save(os.path.join(tmpdir, filename))
|
| 249 |
+
p._backend.close()
|
| 250 |
+
|
| 251 |
+
# Multiple Parametric 3D plots.
|
| 252 |
+
p = plot3d_parametric_surface(
|
| 253 |
+
(x*sin(z), x*cos(z), z, (x, -5, 5), (z, -5, 5)),
|
| 254 |
+
(sin(x + y), cos(x - y), x - y, (x, -5, 5), (y, -5, 5)),
|
| 255 |
+
adaptive=adaptive, n=10)
|
| 256 |
+
filename = 'test_parametric_surface.png'
|
| 257 |
+
p.save(os.path.join(tmpdir, filename))
|
| 258 |
+
p._backend.close()
|
| 259 |
+
|
| 260 |
+
# Single Contour plot.
|
| 261 |
+
p = plot_contour(sin(x)*sin(y), (x, -5, 5), (y, -5, 5),
|
| 262 |
+
adaptive=adaptive, n=10)
|
| 263 |
+
filename = 'test_contour_plot.png'
|
| 264 |
+
p.save(os.path.join(tmpdir, filename))
|
| 265 |
+
p._backend.close()
|
| 266 |
+
|
| 267 |
+
# Multiple Contour plots with same range.
|
| 268 |
+
p = plot_contour(x**2 + y**2, x**3 + y**3, (x, -5, 5), (y, -5, 5),
|
| 269 |
+
adaptive=adaptive, n=10)
|
| 270 |
+
filename = 'test_contour_plot.png'
|
| 271 |
+
p.save(os.path.join(tmpdir, filename))
|
| 272 |
+
p._backend.close()
|
| 273 |
+
|
| 274 |
+
# Multiple Contour plots with different range.
|
| 275 |
+
p = plot_contour(
|
| 276 |
+
(x**2 + y**2, (x, -5, 5), (y, -5, 5)),
|
| 277 |
+
(x**3 + y**3, (x, -3, 3), (y, -3, 3)),
|
| 278 |
+
adaptive=adaptive, n=10)
|
| 279 |
+
filename = 'test_contour_plot.png'
|
| 280 |
+
p.save(os.path.join(tmpdir, filename))
|
| 281 |
+
p._backend.close()
|
| 282 |
+
|
| 283 |
+
|
| 284 |
+
@pytest.mark.parametrize("adaptive", [True, False])
|
| 285 |
+
def test_plot_and_save_3(adaptive):
|
| 286 |
+
if not matplotlib:
|
| 287 |
+
skip("Matplotlib not the default backend")
|
| 288 |
+
|
| 289 |
+
x = Symbol('x')
|
| 290 |
+
y = Symbol('y')
|
| 291 |
+
z = Symbol('z')
|
| 292 |
+
|
| 293 |
+
with TemporaryDirectory(prefix='sympy_') as tmpdir:
|
| 294 |
+
###
|
| 295 |
+
# Examples from the 'colors' notebook
|
| 296 |
+
###
|
| 297 |
+
|
| 298 |
+
p = plot(sin(x), adaptive=adaptive, n=10)
|
| 299 |
+
p[0].line_color = lambda a: a
|
| 300 |
+
filename = 'test_colors_line_arity1.png'
|
| 301 |
+
p.save(os.path.join(tmpdir, filename))
|
| 302 |
+
|
| 303 |
+
p[0].line_color = lambda a, b: b
|
| 304 |
+
filename = 'test_colors_line_arity2.png'
|
| 305 |
+
p.save(os.path.join(tmpdir, filename))
|
| 306 |
+
p._backend.close()
|
| 307 |
+
|
| 308 |
+
p = plot(x*sin(x), x*cos(x), (x, 0, 10), adaptive=adaptive, n=10)
|
| 309 |
+
p[0].line_color = lambda a: a
|
| 310 |
+
filename = 'test_colors_param_line_arity1.png'
|
| 311 |
+
p.save(os.path.join(tmpdir, filename))
|
| 312 |
+
|
| 313 |
+
p[0].line_color = lambda a, b: a
|
| 314 |
+
filename = 'test_colors_param_line_arity1.png'
|
| 315 |
+
p.save(os.path.join(tmpdir, filename))
|
| 316 |
+
|
| 317 |
+
p[0].line_color = lambda a, b: b
|
| 318 |
+
filename = 'test_colors_param_line_arity2b.png'
|
| 319 |
+
p.save(os.path.join(tmpdir, filename))
|
| 320 |
+
p._backend.close()
|
| 321 |
+
|
| 322 |
+
p = plot3d_parametric_line(
|
| 323 |
+
sin(x) + 0.1*sin(x)*cos(7*x),
|
| 324 |
+
cos(x) + 0.1*cos(x)*cos(7*x),
|
| 325 |
+
0.1*sin(7*x),
|
| 326 |
+
(x, 0, 2*pi), adaptive=adaptive, n=10)
|
| 327 |
+
p[0].line_color = lambdify_(x, sin(4*x))
|
| 328 |
+
filename = 'test_colors_3d_line_arity1.png'
|
| 329 |
+
p.save(os.path.join(tmpdir, filename))
|
| 330 |
+
p[0].line_color = lambda a, b: b
|
| 331 |
+
filename = 'test_colors_3d_line_arity2.png'
|
| 332 |
+
p.save(os.path.join(tmpdir, filename))
|
| 333 |
+
p[0].line_color = lambda a, b, c: c
|
| 334 |
+
filename = 'test_colors_3d_line_arity3.png'
|
| 335 |
+
p.save(os.path.join(tmpdir, filename))
|
| 336 |
+
p._backend.close()
|
| 337 |
+
|
| 338 |
+
p = plot3d(sin(x)*y, (x, 0, 6*pi), (y, -5, 5), adaptive=adaptive, n=10)
|
| 339 |
+
p[0].surface_color = lambda a: a
|
| 340 |
+
filename = 'test_colors_surface_arity1.png'
|
| 341 |
+
p.save(os.path.join(tmpdir, filename))
|
| 342 |
+
p[0].surface_color = lambda a, b: b
|
| 343 |
+
filename = 'test_colors_surface_arity2.png'
|
| 344 |
+
p.save(os.path.join(tmpdir, filename))
|
| 345 |
+
p[0].surface_color = lambda a, b, c: c
|
| 346 |
+
filename = 'test_colors_surface_arity3a.png'
|
| 347 |
+
p.save(os.path.join(tmpdir, filename))
|
| 348 |
+
p[0].surface_color = lambdify_((x, y, z), sqrt((x - 3*pi)**2 + y**2))
|
| 349 |
+
filename = 'test_colors_surface_arity3b.png'
|
| 350 |
+
p.save(os.path.join(tmpdir, filename))
|
| 351 |
+
p._backend.close()
|
| 352 |
+
|
| 353 |
+
p = plot3d_parametric_surface(x * cos(4 * y), x * sin(4 * y), y,
|
| 354 |
+
(x, -1, 1), (y, -1, 1), adaptive=adaptive, n=10)
|
| 355 |
+
p[0].surface_color = lambda a: a
|
| 356 |
+
filename = 'test_colors_param_surf_arity1.png'
|
| 357 |
+
p.save(os.path.join(tmpdir, filename))
|
| 358 |
+
p[0].surface_color = lambda a, b: a*b
|
| 359 |
+
filename = 'test_colors_param_surf_arity2.png'
|
| 360 |
+
p.save(os.path.join(tmpdir, filename))
|
| 361 |
+
p[0].surface_color = lambdify_((x, y, z), sqrt(x**2 + y**2 + z**2))
|
| 362 |
+
filename = 'test_colors_param_surf_arity3.png'
|
| 363 |
+
p.save(os.path.join(tmpdir, filename))
|
| 364 |
+
p._backend.close()
|
| 365 |
+
|
| 366 |
+
|
| 367 |
+
@pytest.mark.parametrize("adaptive", [True])
|
| 368 |
+
def test_plot_and_save_4(adaptive):
|
| 369 |
+
if not matplotlib:
|
| 370 |
+
skip("Matplotlib not the default backend")
|
| 371 |
+
|
| 372 |
+
x = Symbol('x')
|
| 373 |
+
y = Symbol('y')
|
| 374 |
+
|
| 375 |
+
###
|
| 376 |
+
# Examples from the 'advanced' notebook
|
| 377 |
+
###
|
| 378 |
+
|
| 379 |
+
with TemporaryDirectory(prefix='sympy_') as tmpdir:
|
| 380 |
+
i = Integral(log((sin(x)**2 + 1)*sqrt(x**2 + 1)), (x, 0, y))
|
| 381 |
+
p = plot(i, (y, 1, 5), adaptive=adaptive, n=10, force_real_eval=True)
|
| 382 |
+
filename = 'test_advanced_integral.png'
|
| 383 |
+
p.save(os.path.join(tmpdir, filename))
|
| 384 |
+
p._backend.close()
|
| 385 |
+
|
| 386 |
+
|
| 387 |
+
@pytest.mark.parametrize("adaptive", [True, False])
|
| 388 |
+
def test_plot_and_save_5(adaptive):
|
| 389 |
+
if not matplotlib:
|
| 390 |
+
skip("Matplotlib not the default backend")
|
| 391 |
+
|
| 392 |
+
x = Symbol('x')
|
| 393 |
+
y = Symbol('y')
|
| 394 |
+
|
| 395 |
+
with TemporaryDirectory(prefix='sympy_') as tmpdir:
|
| 396 |
+
s = Sum(1/x**y, (x, 1, oo))
|
| 397 |
+
p = plot(s, (y, 2, 10), adaptive=adaptive, n=10)
|
| 398 |
+
filename = 'test_advanced_inf_sum.png'
|
| 399 |
+
p.save(os.path.join(tmpdir, filename))
|
| 400 |
+
p._backend.close()
|
| 401 |
+
|
| 402 |
+
p = plot(Sum(1/x, (x, 1, y)), (y, 2, 10), show=False,
|
| 403 |
+
adaptive=adaptive, n=10)
|
| 404 |
+
p[0].only_integers = True
|
| 405 |
+
p[0].steps = True
|
| 406 |
+
filename = 'test_advanced_fin_sum.png'
|
| 407 |
+
|
| 408 |
+
# XXX: This should be fixed in experimental_lambdify or by using
|
| 409 |
+
# ordinary lambdify so that it doesn't warn. The error results from
|
| 410 |
+
# passing an array of values as the integration limit.
|
| 411 |
+
#
|
| 412 |
+
# UserWarning: The evaluation of the expression is problematic. We are
|
| 413 |
+
# trying a failback method that may still work. Please report this as a
|
| 414 |
+
# bug.
|
| 415 |
+
with ignore_warnings(UserWarning):
|
| 416 |
+
p.save(os.path.join(tmpdir, filename))
|
| 417 |
+
|
| 418 |
+
p._backend.close()
|
| 419 |
+
|
| 420 |
+
|
| 421 |
+
@pytest.mark.parametrize("adaptive", [True, False])
|
| 422 |
+
def test_plot_and_save_6(adaptive):
|
| 423 |
+
if not matplotlib:
|
| 424 |
+
skip("Matplotlib not the default backend")
|
| 425 |
+
|
| 426 |
+
x = Symbol('x')
|
| 427 |
+
|
| 428 |
+
with TemporaryDirectory(prefix='sympy_') as tmpdir:
|
| 429 |
+
filename = 'test.png'
|
| 430 |
+
###
|
| 431 |
+
# Test expressions that can not be translated to np and generate complex
|
| 432 |
+
# results.
|
| 433 |
+
###
|
| 434 |
+
p = plot(sin(x) + I*cos(x))
|
| 435 |
+
p.save(os.path.join(tmpdir, filename))
|
| 436 |
+
|
| 437 |
+
with ignore_warnings(RuntimeWarning):
|
| 438 |
+
p = plot(sqrt(sqrt(-x)))
|
| 439 |
+
p.save(os.path.join(tmpdir, filename))
|
| 440 |
+
|
| 441 |
+
p = plot(LambertW(x))
|
| 442 |
+
p.save(os.path.join(tmpdir, filename))
|
| 443 |
+
p = plot(sqrt(LambertW(x)))
|
| 444 |
+
p.save(os.path.join(tmpdir, filename))
|
| 445 |
+
|
| 446 |
+
#Characteristic function of a StudentT distribution with nu=10
|
| 447 |
+
x1 = 5 * x**2 * exp_polar(-I*pi)/2
|
| 448 |
+
m1 = meijerg(((1 / 2,), ()), ((5, 0, 1 / 2), ()), x1)
|
| 449 |
+
x2 = 5*x**2 * exp_polar(I*pi)/2
|
| 450 |
+
m2 = meijerg(((1/2,), ()), ((5, 0, 1/2), ()), x2)
|
| 451 |
+
expr = (m1 + m2) / (48 * pi)
|
| 452 |
+
with warns(
|
| 453 |
+
UserWarning,
|
| 454 |
+
match="The evaluation with NumPy/SciPy failed",
|
| 455 |
+
test_stacklevel=False,
|
| 456 |
+
):
|
| 457 |
+
p = plot(expr, (x, 1e-6, 1e-2), adaptive=adaptive, n=10)
|
| 458 |
+
p.save(os.path.join(tmpdir, filename))
|
| 459 |
+
|
| 460 |
+
|
| 461 |
+
@pytest.mark.parametrize("adaptive", [True, False])
|
| 462 |
+
def test_plotgrid_and_save(adaptive):
|
| 463 |
+
if not matplotlib:
|
| 464 |
+
skip("Matplotlib not the default backend")
|
| 465 |
+
|
| 466 |
+
x = Symbol('x')
|
| 467 |
+
y = Symbol('y')
|
| 468 |
+
|
| 469 |
+
with TemporaryDirectory(prefix='sympy_') as tmpdir:
|
| 470 |
+
p1 = plot(x, adaptive=adaptive, n=10)
|
| 471 |
+
p2 = plot_parametric((sin(x), cos(x)), (x, sin(x)), show=False,
|
| 472 |
+
adaptive=adaptive, n=10)
|
| 473 |
+
p3 = plot_parametric(
|
| 474 |
+
cos(x), sin(x), adaptive=adaptive, n=10, show=False)
|
| 475 |
+
p4 = plot3d_parametric_line(sin(x), cos(x), x, show=False,
|
| 476 |
+
adaptive=adaptive, n=10)
|
| 477 |
+
# symmetric grid
|
| 478 |
+
p = PlotGrid(2, 2, p1, p2, p3, p4)
|
| 479 |
+
filename = 'test_grid1.png'
|
| 480 |
+
p.save(os.path.join(tmpdir, filename))
|
| 481 |
+
p._backend.close()
|
| 482 |
+
|
| 483 |
+
# grid size greater than the number of subplots
|
| 484 |
+
p = PlotGrid(3, 4, p1, p2, p3, p4)
|
| 485 |
+
filename = 'test_grid2.png'
|
| 486 |
+
p.save(os.path.join(tmpdir, filename))
|
| 487 |
+
p._backend.close()
|
| 488 |
+
|
| 489 |
+
p5 = plot(cos(x),(x, -pi, pi), show=False, adaptive=adaptive, n=10)
|
| 490 |
+
p5[0].line_color = lambda a: a
|
| 491 |
+
p6 = plot(Piecewise((1, x > 0), (0, True)), (x, -1, 1), show=False,
|
| 492 |
+
adaptive=adaptive, n=10)
|
| 493 |
+
p7 = plot_contour(
|
| 494 |
+
(x**2 + y**2, (x, -5, 5), (y, -5, 5)),
|
| 495 |
+
(x**3 + y**3, (x, -3, 3), (y, -3, 3)), show=False,
|
| 496 |
+
adaptive=adaptive, n=10)
|
| 497 |
+
# unsymmetric grid (subplots in one line)
|
| 498 |
+
p = PlotGrid(1, 3, p5, p6, p7)
|
| 499 |
+
filename = 'test_grid3.png'
|
| 500 |
+
p.save(os.path.join(tmpdir, filename))
|
| 501 |
+
p._backend.close()
|
| 502 |
+
|
| 503 |
+
|
| 504 |
+
@pytest.mark.parametrize("adaptive", [True, False])
|
| 505 |
+
def test_append_issue_7140(adaptive):
|
| 506 |
+
if not matplotlib:
|
| 507 |
+
skip("Matplotlib not the default backend")
|
| 508 |
+
|
| 509 |
+
x = Symbol('x')
|
| 510 |
+
p1 = plot(x, adaptive=adaptive, n=10)
|
| 511 |
+
p2 = plot(x**2, adaptive=adaptive, n=10)
|
| 512 |
+
plot(x + 2, adaptive=adaptive, n=10)
|
| 513 |
+
|
| 514 |
+
# append a series
|
| 515 |
+
p2.append(p1[0])
|
| 516 |
+
assert len(p2._series) == 2
|
| 517 |
+
|
| 518 |
+
with raises(TypeError):
|
| 519 |
+
p1.append(p2)
|
| 520 |
+
|
| 521 |
+
with raises(TypeError):
|
| 522 |
+
p1.append(p2._series)
|
| 523 |
+
|
| 524 |
+
|
| 525 |
+
@pytest.mark.parametrize("adaptive", [True, False])
|
| 526 |
+
def test_issue_15265(adaptive):
|
| 527 |
+
if not matplotlib:
|
| 528 |
+
skip("Matplotlib not the default backend")
|
| 529 |
+
|
| 530 |
+
x = Symbol('x')
|
| 531 |
+
eqn = sin(x)
|
| 532 |
+
|
| 533 |
+
p = plot(eqn, xlim=(-S.Pi, S.Pi), ylim=(-1, 1), adaptive=adaptive, n=10)
|
| 534 |
+
p._backend.close()
|
| 535 |
+
|
| 536 |
+
p = plot(eqn, xlim=(-1, 1), ylim=(-S.Pi, S.Pi), adaptive=adaptive, n=10)
|
| 537 |
+
p._backend.close()
|
| 538 |
+
|
| 539 |
+
p = plot(eqn, xlim=(-1, 1), adaptive=adaptive, n=10,
|
| 540 |
+
ylim=(sympify('-3.14'), sympify('3.14')))
|
| 541 |
+
p._backend.close()
|
| 542 |
+
|
| 543 |
+
p = plot(eqn, adaptive=adaptive, n=10,
|
| 544 |
+
xlim=(sympify('-3.14'), sympify('3.14')), ylim=(-1, 1))
|
| 545 |
+
p._backend.close()
|
| 546 |
+
|
| 547 |
+
raises(ValueError,
|
| 548 |
+
lambda: plot(eqn, adaptive=adaptive, n=10,
|
| 549 |
+
xlim=(-S.ImaginaryUnit, 1), ylim=(-1, 1)))
|
| 550 |
+
|
| 551 |
+
raises(ValueError,
|
| 552 |
+
lambda: plot(eqn, adaptive=adaptive, n=10,
|
| 553 |
+
xlim=(-1, 1), ylim=(-1, S.ImaginaryUnit)))
|
| 554 |
+
|
| 555 |
+
raises(ValueError,
|
| 556 |
+
lambda: plot(eqn, adaptive=adaptive, n=10,
|
| 557 |
+
xlim=(S.NegativeInfinity, 1), ylim=(-1, 1)))
|
| 558 |
+
|
| 559 |
+
raises(ValueError,
|
| 560 |
+
lambda: plot(eqn, adaptive=adaptive, n=10,
|
| 561 |
+
xlim=(-1, 1), ylim=(-1, S.Infinity)))
|
| 562 |
+
|
| 563 |
+
|
| 564 |
+
def test_empty_Plot():
|
| 565 |
+
if not matplotlib:
|
| 566 |
+
skip("Matplotlib not the default backend")
|
| 567 |
+
|
| 568 |
+
# No exception showing an empty plot
|
| 569 |
+
plot()
|
| 570 |
+
# Plot is only a base class: doesn't implement any logic for showing
|
| 571 |
+
# images
|
| 572 |
+
p = Plot()
|
| 573 |
+
raises(NotImplementedError, lambda: p.show())
|
| 574 |
+
|
| 575 |
+
|
| 576 |
+
@pytest.mark.parametrize("adaptive", [True, False])
|
| 577 |
+
def test_issue_17405(adaptive):
|
| 578 |
+
if not matplotlib:
|
| 579 |
+
skip("Matplotlib not the default backend")
|
| 580 |
+
|
| 581 |
+
x = Symbol('x')
|
| 582 |
+
f = x**0.3 - 10*x**3 + x**2
|
| 583 |
+
p = plot(f, (x, -10, 10), adaptive=adaptive, n=30, show=False)
|
| 584 |
+
# Random number of segments, probably more than 100, but we want to see
|
| 585 |
+
# that there are segments generated, as opposed to when the bug was present
|
| 586 |
+
|
| 587 |
+
# RuntimeWarning: invalid value encountered in double_scalars
|
| 588 |
+
with ignore_warnings(RuntimeWarning):
|
| 589 |
+
assert len(p[0].get_data()[0]) >= 30
|
| 590 |
+
|
| 591 |
+
|
| 592 |
+
@pytest.mark.parametrize("adaptive", [True, False])
|
| 593 |
+
def test_logplot_PR_16796(adaptive):
|
| 594 |
+
if not matplotlib:
|
| 595 |
+
skip("Matplotlib not the default backend")
|
| 596 |
+
|
| 597 |
+
x = Symbol('x')
|
| 598 |
+
p = plot(x, (x, .001, 100), adaptive=adaptive, n=30,
|
| 599 |
+
xscale='log', show=False)
|
| 600 |
+
# Random number of segments, probably more than 100, but we want to see
|
| 601 |
+
# that there are segments generated, as opposed to when the bug was present
|
| 602 |
+
assert len(p[0].get_data()[0]) >= 30
|
| 603 |
+
assert p[0].end == 100.0
|
| 604 |
+
assert p[0].start == .001
|
| 605 |
+
|
| 606 |
+
|
| 607 |
+
@pytest.mark.parametrize("adaptive", [True, False])
|
| 608 |
+
def test_issue_16572(adaptive):
|
| 609 |
+
if not matplotlib:
|
| 610 |
+
skip("Matplotlib not the default backend")
|
| 611 |
+
|
| 612 |
+
x = Symbol('x')
|
| 613 |
+
p = plot(LambertW(x), show=False, adaptive=adaptive, n=30)
|
| 614 |
+
# Random number of segments, probably more than 50, but we want to see
|
| 615 |
+
# that there are segments generated, as opposed to when the bug was present
|
| 616 |
+
assert len(p[0].get_data()[0]) >= 30
|
| 617 |
+
|
| 618 |
+
|
| 619 |
+
@pytest.mark.parametrize("adaptive", [True, False])
|
| 620 |
+
def test_issue_11865(adaptive):
|
| 621 |
+
if not matplotlib:
|
| 622 |
+
skip("Matplotlib not the default backend")
|
| 623 |
+
|
| 624 |
+
k = Symbol('k', integer=True)
|
| 625 |
+
f = Piecewise((-I*exp(I*pi*k)/k + I*exp(-I*pi*k)/k, Ne(k, 0)), (2*pi, True))
|
| 626 |
+
p = plot(f, show=False, adaptive=adaptive, n=30)
|
| 627 |
+
# Random number of segments, probably more than 100, but we want to see
|
| 628 |
+
# that there are segments generated, as opposed to when the bug was present
|
| 629 |
+
# and that there are no exceptions.
|
| 630 |
+
assert len(p[0].get_data()[0]) >= 30
|
| 631 |
+
|
| 632 |
+
|
| 633 |
+
@skip_under_pyodide("Warnings not emitted in Pyodide because of lack of WASM fp exception support")
|
| 634 |
+
def test_issue_11461():
|
| 635 |
+
if not matplotlib:
|
| 636 |
+
skip("Matplotlib not the default backend")
|
| 637 |
+
|
| 638 |
+
x = Symbol('x')
|
| 639 |
+
p = plot(real_root((log(x/(x-2))), 3), show=False, adaptive=True)
|
| 640 |
+
with warns(
|
| 641 |
+
RuntimeWarning,
|
| 642 |
+
match="invalid value encountered in",
|
| 643 |
+
test_stacklevel=False,
|
| 644 |
+
):
|
| 645 |
+
# Random number of segments, probably more than 100, but we want to see
|
| 646 |
+
# that there are segments generated, as opposed to when the bug was present
|
| 647 |
+
# and that there are no exceptions.
|
| 648 |
+
assert len(p[0].get_data()[0]) >= 30
|
| 649 |
+
|
| 650 |
+
|
| 651 |
+
@pytest.mark.parametrize("adaptive", [True, False])
|
| 652 |
+
def test_issue_11764(adaptive):
|
| 653 |
+
if not matplotlib:
|
| 654 |
+
skip("Matplotlib not the default backend")
|
| 655 |
+
|
| 656 |
+
x = Symbol('x')
|
| 657 |
+
p = plot_parametric(cos(x), sin(x), (x, 0, 2 * pi),
|
| 658 |
+
aspect_ratio=(1,1), show=False, adaptive=adaptive, n=30)
|
| 659 |
+
assert p.aspect_ratio == (1, 1)
|
| 660 |
+
# Random number of segments, probably more than 100, but we want to see
|
| 661 |
+
# that there are segments generated, as opposed to when the bug was present
|
| 662 |
+
assert len(p[0].get_data()[0]) >= 30
|
| 663 |
+
|
| 664 |
+
|
| 665 |
+
@pytest.mark.parametrize("adaptive", [True, False])
|
| 666 |
+
def test_issue_13516(adaptive):
|
| 667 |
+
if not matplotlib:
|
| 668 |
+
skip("Matplotlib not the default backend")
|
| 669 |
+
|
| 670 |
+
x = Symbol('x')
|
| 671 |
+
|
| 672 |
+
pm = plot(sin(x), backend="matplotlib", show=False, adaptive=adaptive, n=30)
|
| 673 |
+
assert pm.backend == MatplotlibBackend
|
| 674 |
+
assert len(pm[0].get_data()[0]) >= 30
|
| 675 |
+
|
| 676 |
+
pt = plot(sin(x), backend="text", show=False, adaptive=adaptive, n=30)
|
| 677 |
+
assert pt.backend == TextBackend
|
| 678 |
+
assert len(pt[0].get_data()[0]) >= 30
|
| 679 |
+
|
| 680 |
+
pd = plot(sin(x), backend="default", show=False, adaptive=adaptive, n=30)
|
| 681 |
+
assert pd.backend == MatplotlibBackend
|
| 682 |
+
assert len(pd[0].get_data()[0]) >= 30
|
| 683 |
+
|
| 684 |
+
p = plot(sin(x), show=False, adaptive=adaptive, n=30)
|
| 685 |
+
assert p.backend == MatplotlibBackend
|
| 686 |
+
assert len(p[0].get_data()[0]) >= 30
|
| 687 |
+
|
| 688 |
+
|
| 689 |
+
@pytest.mark.parametrize("adaptive", [True, False])
|
| 690 |
+
def test_plot_limits(adaptive):
|
| 691 |
+
if not matplotlib:
|
| 692 |
+
skip("Matplotlib not the default backend")
|
| 693 |
+
|
| 694 |
+
x = Symbol('x')
|
| 695 |
+
p = plot(x, x**2, (x, -10, 10), adaptive=adaptive, n=10)
|
| 696 |
+
backend = p._backend
|
| 697 |
+
|
| 698 |
+
xmin, xmax = backend.ax.get_xlim()
|
| 699 |
+
assert abs(xmin + 10) < 2
|
| 700 |
+
assert abs(xmax - 10) < 2
|
| 701 |
+
ymin, ymax = backend.ax.get_ylim()
|
| 702 |
+
assert abs(ymin + 10) < 10
|
| 703 |
+
assert abs(ymax - 100) < 10
|
| 704 |
+
|
| 705 |
+
|
| 706 |
+
@pytest.mark.parametrize("adaptive", [True, False])
|
| 707 |
+
def test_plot3d_parametric_line_limits(adaptive):
|
| 708 |
+
if not matplotlib:
|
| 709 |
+
skip("Matplotlib not the default backend")
|
| 710 |
+
|
| 711 |
+
x = Symbol('x')
|
| 712 |
+
|
| 713 |
+
v1 = (2*cos(x), 2*sin(x), 2*x, (x, -5, 5))
|
| 714 |
+
v2 = (sin(x), cos(x), x, (x, -5, 5))
|
| 715 |
+
p = plot3d_parametric_line(v1, v2, adaptive=adaptive, n=60)
|
| 716 |
+
backend = p._backend
|
| 717 |
+
|
| 718 |
+
xmin, xmax = backend.ax.get_xlim()
|
| 719 |
+
assert abs(xmin + 2) < 1e-2
|
| 720 |
+
assert abs(xmax - 2) < 1e-2
|
| 721 |
+
ymin, ymax = backend.ax.get_ylim()
|
| 722 |
+
assert abs(ymin + 2) < 1e-2
|
| 723 |
+
assert abs(ymax - 2) < 1e-2
|
| 724 |
+
zmin, zmax = backend.ax.get_zlim()
|
| 725 |
+
assert abs(zmin + 10) < 1e-2
|
| 726 |
+
assert abs(zmax - 10) < 1e-2
|
| 727 |
+
|
| 728 |
+
p = plot3d_parametric_line(v2, v1, adaptive=adaptive, n=60)
|
| 729 |
+
backend = p._backend
|
| 730 |
+
|
| 731 |
+
xmin, xmax = backend.ax.get_xlim()
|
| 732 |
+
assert abs(xmin + 2) < 1e-2
|
| 733 |
+
assert abs(xmax - 2) < 1e-2
|
| 734 |
+
ymin, ymax = backend.ax.get_ylim()
|
| 735 |
+
assert abs(ymin + 2) < 1e-2
|
| 736 |
+
assert abs(ymax - 2) < 1e-2
|
| 737 |
+
zmin, zmax = backend.ax.get_zlim()
|
| 738 |
+
assert abs(zmin + 10) < 1e-2
|
| 739 |
+
assert abs(zmax - 10) < 1e-2
|
| 740 |
+
|
| 741 |
+
|
| 742 |
+
@pytest.mark.parametrize("adaptive", [True, False])
|
| 743 |
+
def test_plot_size(adaptive):
|
| 744 |
+
if not matplotlib:
|
| 745 |
+
skip("Matplotlib not the default backend")
|
| 746 |
+
|
| 747 |
+
x = Symbol('x')
|
| 748 |
+
|
| 749 |
+
p1 = plot(sin(x), backend="matplotlib", size=(8, 4),
|
| 750 |
+
adaptive=adaptive, n=10)
|
| 751 |
+
s1 = p1._backend.fig.get_size_inches()
|
| 752 |
+
assert (s1[0] == 8) and (s1[1] == 4)
|
| 753 |
+
p2 = plot(sin(x), backend="matplotlib", size=(5, 10),
|
| 754 |
+
adaptive=adaptive, n=10)
|
| 755 |
+
s2 = p2._backend.fig.get_size_inches()
|
| 756 |
+
assert (s2[0] == 5) and (s2[1] == 10)
|
| 757 |
+
p3 = PlotGrid(2, 1, p1, p2, size=(6, 2),
|
| 758 |
+
adaptive=adaptive, n=10)
|
| 759 |
+
s3 = p3._backend.fig.get_size_inches()
|
| 760 |
+
assert (s3[0] == 6) and (s3[1] == 2)
|
| 761 |
+
|
| 762 |
+
with raises(ValueError):
|
| 763 |
+
plot(sin(x), backend="matplotlib", size=(-1, 3))
|
| 764 |
+
|
| 765 |
+
|
| 766 |
+
def test_issue_20113():
|
| 767 |
+
if not matplotlib:
|
| 768 |
+
skip("Matplotlib not the default backend")
|
| 769 |
+
|
| 770 |
+
x = Symbol('x')
|
| 771 |
+
|
| 772 |
+
# verify the capability to use custom backends
|
| 773 |
+
plot(sin(x), backend=Plot, show=False)
|
| 774 |
+
p2 = plot(sin(x), backend=MatplotlibBackend, show=False)
|
| 775 |
+
assert p2.backend == MatplotlibBackend
|
| 776 |
+
assert len(p2[0].get_data()[0]) >= 30
|
| 777 |
+
p3 = plot(sin(x), backend=DummyBackendOk, show=False)
|
| 778 |
+
assert p3.backend == DummyBackendOk
|
| 779 |
+
assert len(p3[0].get_data()[0]) >= 30
|
| 780 |
+
|
| 781 |
+
# test for an improper coded backend
|
| 782 |
+
p4 = plot(sin(x), backend=DummyBackendNotOk, show=False)
|
| 783 |
+
assert p4.backend == DummyBackendNotOk
|
| 784 |
+
assert len(p4[0].get_data()[0]) >= 30
|
| 785 |
+
with raises(NotImplementedError):
|
| 786 |
+
p4.show()
|
| 787 |
+
with raises(NotImplementedError):
|
| 788 |
+
p4.save("test/path")
|
| 789 |
+
with raises(NotImplementedError):
|
| 790 |
+
p4._backend.close()
|
| 791 |
+
|
| 792 |
+
|
| 793 |
+
def test_custom_coloring():
|
| 794 |
+
x = Symbol('x')
|
| 795 |
+
y = Symbol('y')
|
| 796 |
+
plot(cos(x), line_color=lambda a: a)
|
| 797 |
+
plot(cos(x), line_color=1)
|
| 798 |
+
plot(cos(x), line_color="r")
|
| 799 |
+
plot_parametric(cos(x), sin(x), line_color=lambda a: a)
|
| 800 |
+
plot_parametric(cos(x), sin(x), line_color=1)
|
| 801 |
+
plot_parametric(cos(x), sin(x), line_color="r")
|
| 802 |
+
plot3d_parametric_line(cos(x), sin(x), x, line_color=lambda a: a)
|
| 803 |
+
plot3d_parametric_line(cos(x), sin(x), x, line_color=1)
|
| 804 |
+
plot3d_parametric_line(cos(x), sin(x), x, line_color="r")
|
| 805 |
+
plot3d_parametric_surface(cos(x + y), sin(x - y), x - y,
|
| 806 |
+
(x, -5, 5), (y, -5, 5),
|
| 807 |
+
surface_color=lambda a, b: a**2 + b**2)
|
| 808 |
+
plot3d_parametric_surface(cos(x + y), sin(x - y), x - y,
|
| 809 |
+
(x, -5, 5), (y, -5, 5),
|
| 810 |
+
surface_color=1)
|
| 811 |
+
plot3d_parametric_surface(cos(x + y), sin(x - y), x - y,
|
| 812 |
+
(x, -5, 5), (y, -5, 5),
|
| 813 |
+
surface_color="r")
|
| 814 |
+
plot3d(x*y, (x, -5, 5), (y, -5, 5),
|
| 815 |
+
surface_color=lambda a, b: a**2 + b**2)
|
| 816 |
+
plot3d(x*y, (x, -5, 5), (y, -5, 5), surface_color=1)
|
| 817 |
+
plot3d(x*y, (x, -5, 5), (y, -5, 5), surface_color="r")
|
| 818 |
+
|
| 819 |
+
|
| 820 |
+
@pytest.mark.parametrize("adaptive", [True, False])
|
| 821 |
+
def test_deprecated_get_segments(adaptive):
|
| 822 |
+
if not matplotlib:
|
| 823 |
+
skip("Matplotlib not the default backend")
|
| 824 |
+
|
| 825 |
+
x = Symbol('x')
|
| 826 |
+
f = sin(x)
|
| 827 |
+
p = plot(f, (x, -10, 10), show=False, adaptive=adaptive, n=10)
|
| 828 |
+
with warns_deprecated_sympy():
|
| 829 |
+
p[0].get_segments()
|
| 830 |
+
|
| 831 |
+
|
| 832 |
+
@pytest.mark.parametrize("adaptive", [True, False])
|
| 833 |
+
def test_generic_data_series(adaptive):
|
| 834 |
+
# verify that no errors are raised when generic data series are used
|
| 835 |
+
if not matplotlib:
|
| 836 |
+
skip("Matplotlib not the default backend")
|
| 837 |
+
|
| 838 |
+
x = Symbol("x")
|
| 839 |
+
p = plot(x,
|
| 840 |
+
markers=[{"args":[[0, 1], [0, 1]], "marker": "*", "linestyle": "none"}],
|
| 841 |
+
annotations=[{"text": "test", "xy": (0, 0)}],
|
| 842 |
+
fill={"x": [0, 1, 2, 3], "y1": [0, 1, 2, 3]},
|
| 843 |
+
rectangles=[{"xy": (0, 0), "width": 5, "height": 1}],
|
| 844 |
+
adaptive=adaptive, n=10)
|
| 845 |
+
assert len(p._backend.ax.collections) == 1
|
| 846 |
+
assert len(p._backend.ax.patches) == 1
|
| 847 |
+
assert len(p._backend.ax.lines) == 2
|
| 848 |
+
assert len(p._backend.ax.texts) == 1
|
| 849 |
+
|
| 850 |
+
|
| 851 |
+
def test_deprecated_markers_annotations_rectangles_fill():
|
| 852 |
+
if not matplotlib:
|
| 853 |
+
skip("Matplotlib not the default backend")
|
| 854 |
+
|
| 855 |
+
x = Symbol('x')
|
| 856 |
+
p = plot(sin(x), (x, -10, 10), show=False)
|
| 857 |
+
with warns_deprecated_sympy():
|
| 858 |
+
p.markers = [{"args":[[0, 1], [0, 1]], "marker": "*", "linestyle": "none"}]
|
| 859 |
+
assert len(p._series) == 2
|
| 860 |
+
with warns_deprecated_sympy():
|
| 861 |
+
p.annotations = [{"text": "test", "xy": (0, 0)}]
|
| 862 |
+
assert len(p._series) == 3
|
| 863 |
+
with warns_deprecated_sympy():
|
| 864 |
+
p.fill = {"x": [0, 1, 2, 3], "y1": [0, 1, 2, 3]}
|
| 865 |
+
assert len(p._series) == 4
|
| 866 |
+
with warns_deprecated_sympy():
|
| 867 |
+
p.rectangles = [{"xy": (0, 0), "width": 5, "height": 1}]
|
| 868 |
+
assert len(p._series) == 5
|
| 869 |
+
|
| 870 |
+
|
| 871 |
+
def test_back_compatibility():
|
| 872 |
+
if not matplotlib:
|
| 873 |
+
skip("Matplotlib not the default backend")
|
| 874 |
+
|
| 875 |
+
x = Symbol('x')
|
| 876 |
+
y = Symbol('y')
|
| 877 |
+
p = plot(sin(x), adaptive=False, n=5)
|
| 878 |
+
assert len(p[0].get_points()) == 2
|
| 879 |
+
assert len(p[0].get_data()) == 2
|
| 880 |
+
p = plot_parametric(cos(x), sin(x), (x, 0, 2), adaptive=False, n=5)
|
| 881 |
+
assert len(p[0].get_points()) == 2
|
| 882 |
+
assert len(p[0].get_data()) == 3
|
| 883 |
+
p = plot3d_parametric_line(cos(x), sin(x), x, (x, 0, 2),
|
| 884 |
+
adaptive=False, n=5)
|
| 885 |
+
assert len(p[0].get_points()) == 3
|
| 886 |
+
assert len(p[0].get_data()) == 4
|
| 887 |
+
p = plot3d(cos(x**2 + y**2), (x, -pi, pi), (y, -pi, pi), n=5)
|
| 888 |
+
assert len(p[0].get_meshes()) == 3
|
| 889 |
+
assert len(p[0].get_data()) == 3
|
| 890 |
+
p = plot_contour(cos(x**2 + y**2), (x, -pi, pi), (y, -pi, pi), n=5)
|
| 891 |
+
assert len(p[0].get_meshes()) == 3
|
| 892 |
+
assert len(p[0].get_data()) == 3
|
| 893 |
+
p = plot3d_parametric_surface(x * cos(y), x * sin(y), x * cos(4 * y) / 2,
|
| 894 |
+
(x, 0, pi), (y, 0, 2*pi), n=5)
|
| 895 |
+
assert len(p[0].get_meshes()) == 3
|
| 896 |
+
assert len(p[0].get_data()) == 5
|
| 897 |
+
|
| 898 |
+
|
| 899 |
+
def test_plot_arguments():
|
| 900 |
+
### Test arguments for plot()
|
| 901 |
+
if not matplotlib:
|
| 902 |
+
skip("Matplotlib not the default backend")
|
| 903 |
+
|
| 904 |
+
x, y = symbols("x, y")
|
| 905 |
+
|
| 906 |
+
# single expressions
|
| 907 |
+
p = plot(x + 1)
|
| 908 |
+
assert isinstance(p[0], LineOver1DRangeSeries)
|
| 909 |
+
assert p[0].expr == x + 1
|
| 910 |
+
assert p[0].ranges == [(x, -10, 10)]
|
| 911 |
+
assert p[0].get_label(False) == "x + 1"
|
| 912 |
+
assert p[0].rendering_kw == {}
|
| 913 |
+
|
| 914 |
+
# single expressions custom label
|
| 915 |
+
p = plot(x + 1, "label")
|
| 916 |
+
assert isinstance(p[0], LineOver1DRangeSeries)
|
| 917 |
+
assert p[0].expr == x + 1
|
| 918 |
+
assert p[0].ranges == [(x, -10, 10)]
|
| 919 |
+
assert p[0].get_label(False) == "label"
|
| 920 |
+
assert p[0].rendering_kw == {}
|
| 921 |
+
|
| 922 |
+
# single expressions with range
|
| 923 |
+
p = plot(x + 1, (x, -2, 2))
|
| 924 |
+
assert p[0].ranges == [(x, -2, 2)]
|
| 925 |
+
|
| 926 |
+
# single expressions with range, label and rendering-kw dictionary
|
| 927 |
+
p = plot(x + 1, (x, -2, 2), "test", {"color": "r"})
|
| 928 |
+
assert p[0].get_label(False) == "test"
|
| 929 |
+
assert p[0].rendering_kw == {"color": "r"}
|
| 930 |
+
|
| 931 |
+
# multiple expressions
|
| 932 |
+
p = plot(x + 1, x**2)
|
| 933 |
+
assert isinstance(p[0], LineOver1DRangeSeries)
|
| 934 |
+
assert p[0].expr == x + 1
|
| 935 |
+
assert p[0].ranges == [(x, -10, 10)]
|
| 936 |
+
assert p[0].get_label(False) == "x + 1"
|
| 937 |
+
assert p[0].rendering_kw == {}
|
| 938 |
+
assert isinstance(p[1], LineOver1DRangeSeries)
|
| 939 |
+
assert p[1].expr == x**2
|
| 940 |
+
assert p[1].ranges == [(x, -10, 10)]
|
| 941 |
+
assert p[1].get_label(False) == "x**2"
|
| 942 |
+
assert p[1].rendering_kw == {}
|
| 943 |
+
|
| 944 |
+
# multiple expressions over the same range
|
| 945 |
+
p = plot(x + 1, x**2, (x, 0, 5))
|
| 946 |
+
assert p[0].ranges == [(x, 0, 5)]
|
| 947 |
+
assert p[1].ranges == [(x, 0, 5)]
|
| 948 |
+
|
| 949 |
+
# multiple expressions over the same range with the same rendering kws
|
| 950 |
+
p = plot(x + 1, x**2, (x, 0, 5), {"color": "r"})
|
| 951 |
+
assert p[0].ranges == [(x, 0, 5)]
|
| 952 |
+
assert p[1].ranges == [(x, 0, 5)]
|
| 953 |
+
assert p[0].rendering_kw == {"color": "r"}
|
| 954 |
+
assert p[1].rendering_kw == {"color": "r"}
|
| 955 |
+
|
| 956 |
+
# multiple expressions with different ranges, labels and rendering kws
|
| 957 |
+
p = plot(
|
| 958 |
+
(x + 1, (x, 0, 5)),
|
| 959 |
+
(x**2, (x, -2, 2), "test", {"color": "r"}))
|
| 960 |
+
assert isinstance(p[0], LineOver1DRangeSeries)
|
| 961 |
+
assert p[0].expr == x + 1
|
| 962 |
+
assert p[0].ranges == [(x, 0, 5)]
|
| 963 |
+
assert p[0].get_label(False) == "x + 1"
|
| 964 |
+
assert p[0].rendering_kw == {}
|
| 965 |
+
assert isinstance(p[1], LineOver1DRangeSeries)
|
| 966 |
+
assert p[1].expr == x**2
|
| 967 |
+
assert p[1].ranges == [(x, -2, 2)]
|
| 968 |
+
assert p[1].get_label(False) == "test"
|
| 969 |
+
assert p[1].rendering_kw == {"color": "r"}
|
| 970 |
+
|
| 971 |
+
# single argument: lambda function
|
| 972 |
+
f = lambda t: t
|
| 973 |
+
p = plot(lambda t: t)
|
| 974 |
+
assert isinstance(p[0], LineOver1DRangeSeries)
|
| 975 |
+
assert callable(p[0].expr)
|
| 976 |
+
assert p[0].ranges[0][1:] == (-10, 10)
|
| 977 |
+
assert p[0].get_label(False) == ""
|
| 978 |
+
assert p[0].rendering_kw == {}
|
| 979 |
+
|
| 980 |
+
# single argument: lambda function + custom range and label
|
| 981 |
+
p = plot(f, ("t", -5, 6), "test")
|
| 982 |
+
assert p[0].ranges[0][1:] == (-5, 6)
|
| 983 |
+
assert p[0].get_label(False) == "test"
|
| 984 |
+
|
| 985 |
+
|
| 986 |
+
def test_plot_parametric_arguments():
|
| 987 |
+
### Test arguments for plot_parametric()
|
| 988 |
+
if not matplotlib:
|
| 989 |
+
skip("Matplotlib not the default backend")
|
| 990 |
+
|
| 991 |
+
x, y = symbols("x, y")
|
| 992 |
+
|
| 993 |
+
# single parametric expression
|
| 994 |
+
p = plot_parametric(x + 1, x)
|
| 995 |
+
assert isinstance(p[0], Parametric2DLineSeries)
|
| 996 |
+
assert p[0].expr == (x + 1, x)
|
| 997 |
+
assert p[0].ranges == [(x, -10, 10)]
|
| 998 |
+
assert p[0].get_label(False) == "x"
|
| 999 |
+
assert p[0].rendering_kw == {}
|
| 1000 |
+
|
| 1001 |
+
# single parametric expression with custom range, label and rendering kws
|
| 1002 |
+
p = plot_parametric(x + 1, x, (x, -2, 2), "test",
|
| 1003 |
+
{"cmap": "Reds"})
|
| 1004 |
+
assert p[0].expr == (x + 1, x)
|
| 1005 |
+
assert p[0].ranges == [(x, -2, 2)]
|
| 1006 |
+
assert p[0].get_label(False) == "test"
|
| 1007 |
+
assert p[0].rendering_kw == {"cmap": "Reds"}
|
| 1008 |
+
|
| 1009 |
+
p = plot_parametric((x + 1, x), (x, -2, 2), "test")
|
| 1010 |
+
assert p[0].expr == (x + 1, x)
|
| 1011 |
+
assert p[0].ranges == [(x, -2, 2)]
|
| 1012 |
+
assert p[0].get_label(False) == "test"
|
| 1013 |
+
assert p[0].rendering_kw == {}
|
| 1014 |
+
|
| 1015 |
+
# multiple parametric expressions same symbol
|
| 1016 |
+
p = plot_parametric((x + 1, x), (x ** 2, x + 1))
|
| 1017 |
+
assert p[0].expr == (x + 1, x)
|
| 1018 |
+
assert p[0].ranges == [(x, -10, 10)]
|
| 1019 |
+
assert p[0].get_label(False) == "x"
|
| 1020 |
+
assert p[0].rendering_kw == {}
|
| 1021 |
+
assert p[1].expr == (x ** 2, x + 1)
|
| 1022 |
+
assert p[1].ranges == [(x, -10, 10)]
|
| 1023 |
+
assert p[1].get_label(False) == "x"
|
| 1024 |
+
assert p[1].rendering_kw == {}
|
| 1025 |
+
|
| 1026 |
+
# multiple parametric expressions different symbols
|
| 1027 |
+
p = plot_parametric((x + 1, x), (y ** 2, y + 1, "test"))
|
| 1028 |
+
assert p[0].expr == (x + 1, x)
|
| 1029 |
+
assert p[0].ranges == [(x, -10, 10)]
|
| 1030 |
+
assert p[0].get_label(False) == "x"
|
| 1031 |
+
assert p[0].rendering_kw == {}
|
| 1032 |
+
assert p[1].expr == (y ** 2, y + 1)
|
| 1033 |
+
assert p[1].ranges == [(y, -10, 10)]
|
| 1034 |
+
assert p[1].get_label(False) == "test"
|
| 1035 |
+
assert p[1].rendering_kw == {}
|
| 1036 |
+
|
| 1037 |
+
# multiple parametric expressions same range
|
| 1038 |
+
p = plot_parametric((x + 1, x), (x ** 2, x + 1), (x, -2, 2))
|
| 1039 |
+
assert p[0].expr == (x + 1, x)
|
| 1040 |
+
assert p[0].ranges == [(x, -2, 2)]
|
| 1041 |
+
assert p[0].get_label(False) == "x"
|
| 1042 |
+
assert p[0].rendering_kw == {}
|
| 1043 |
+
assert p[1].expr == (x ** 2, x + 1)
|
| 1044 |
+
assert p[1].ranges == [(x, -2, 2)]
|
| 1045 |
+
assert p[1].get_label(False) == "x"
|
| 1046 |
+
assert p[1].rendering_kw == {}
|
| 1047 |
+
|
| 1048 |
+
# multiple parametric expressions, custom ranges and labels
|
| 1049 |
+
p = plot_parametric(
|
| 1050 |
+
(x + 1, x, (x, -2, 2), "test1"),
|
| 1051 |
+
(x ** 2, x + 1, (x, -3, 3), "test2", {"cmap": "Reds"}))
|
| 1052 |
+
assert p[0].expr == (x + 1, x)
|
| 1053 |
+
assert p[0].ranges == [(x, -2, 2)]
|
| 1054 |
+
assert p[0].get_label(False) == "test1"
|
| 1055 |
+
assert p[0].rendering_kw == {}
|
| 1056 |
+
assert p[1].expr == (x ** 2, x + 1)
|
| 1057 |
+
assert p[1].ranges == [(x, -3, 3)]
|
| 1058 |
+
assert p[1].get_label(False) == "test2"
|
| 1059 |
+
assert p[1].rendering_kw == {"cmap": "Reds"}
|
| 1060 |
+
|
| 1061 |
+
# single argument: lambda function
|
| 1062 |
+
fx = lambda t: t
|
| 1063 |
+
fy = lambda t: 2 * t
|
| 1064 |
+
p = plot_parametric(fx, fy)
|
| 1065 |
+
assert all(callable(t) for t in p[0].expr)
|
| 1066 |
+
assert p[0].ranges[0][1:] == (-10, 10)
|
| 1067 |
+
assert "Dummy" in p[0].get_label(False)
|
| 1068 |
+
assert p[0].rendering_kw == {}
|
| 1069 |
+
|
| 1070 |
+
# single argument: lambda function + custom range + label
|
| 1071 |
+
p = plot_parametric(fx, fy, ("t", 0, 2), "test")
|
| 1072 |
+
assert all(callable(t) for t in p[0].expr)
|
| 1073 |
+
assert p[0].ranges[0][1:] == (0, 2)
|
| 1074 |
+
assert p[0].get_label(False) == "test"
|
| 1075 |
+
assert p[0].rendering_kw == {}
|
| 1076 |
+
|
| 1077 |
+
|
| 1078 |
+
def test_plot3d_parametric_line_arguments():
|
| 1079 |
+
### Test arguments for plot3d_parametric_line()
|
| 1080 |
+
if not matplotlib:
|
| 1081 |
+
skip("Matplotlib not the default backend")
|
| 1082 |
+
|
| 1083 |
+
x, y = symbols("x, y")
|
| 1084 |
+
|
| 1085 |
+
# single parametric expression
|
| 1086 |
+
p = plot3d_parametric_line(x + 1, x, sin(x))
|
| 1087 |
+
assert isinstance(p[0], Parametric3DLineSeries)
|
| 1088 |
+
assert p[0].expr == (x + 1, x, sin(x))
|
| 1089 |
+
assert p[0].ranges == [(x, -10, 10)]
|
| 1090 |
+
assert p[0].get_label(False) == "x"
|
| 1091 |
+
assert p[0].rendering_kw == {}
|
| 1092 |
+
|
| 1093 |
+
# single parametric expression with custom range, label and rendering kws
|
| 1094 |
+
p = plot3d_parametric_line(x + 1, x, sin(x), (x, -2, 2),
|
| 1095 |
+
"test", {"cmap": "Reds"})
|
| 1096 |
+
assert isinstance(p[0], Parametric3DLineSeries)
|
| 1097 |
+
assert p[0].expr == (x + 1, x, sin(x))
|
| 1098 |
+
assert p[0].ranges == [(x, -2, 2)]
|
| 1099 |
+
assert p[0].get_label(False) == "test"
|
| 1100 |
+
assert p[0].rendering_kw == {"cmap": "Reds"}
|
| 1101 |
+
|
| 1102 |
+
p = plot3d_parametric_line((x + 1, x, sin(x)), (x, -2, 2), "test")
|
| 1103 |
+
assert p[0].expr == (x + 1, x, sin(x))
|
| 1104 |
+
assert p[0].ranges == [(x, -2, 2)]
|
| 1105 |
+
assert p[0].get_label(False) == "test"
|
| 1106 |
+
assert p[0].rendering_kw == {}
|
| 1107 |
+
|
| 1108 |
+
# multiple parametric expression same symbol
|
| 1109 |
+
p = plot3d_parametric_line(
|
| 1110 |
+
(x + 1, x, sin(x)), (x ** 2, 1, cos(x), {"cmap": "Reds"}))
|
| 1111 |
+
assert p[0].expr == (x + 1, x, sin(x))
|
| 1112 |
+
assert p[0].ranges == [(x, -10, 10)]
|
| 1113 |
+
assert p[0].get_label(False) == "x"
|
| 1114 |
+
assert p[0].rendering_kw == {}
|
| 1115 |
+
assert p[1].expr == (x ** 2, 1, cos(x))
|
| 1116 |
+
assert p[1].ranges == [(x, -10, 10)]
|
| 1117 |
+
assert p[1].get_label(False) == "x"
|
| 1118 |
+
assert p[1].rendering_kw == {"cmap": "Reds"}
|
| 1119 |
+
|
| 1120 |
+
# multiple parametric expression different symbols
|
| 1121 |
+
p = plot3d_parametric_line((x + 1, x, sin(x)), (y ** 2, 1, cos(y)))
|
| 1122 |
+
assert p[0].expr == (x + 1, x, sin(x))
|
| 1123 |
+
assert p[0].ranges == [(x, -10, 10)]
|
| 1124 |
+
assert p[0].get_label(False) == "x"
|
| 1125 |
+
assert p[0].rendering_kw == {}
|
| 1126 |
+
assert p[1].expr == (y ** 2, 1, cos(y))
|
| 1127 |
+
assert p[1].ranges == [(y, -10, 10)]
|
| 1128 |
+
assert p[1].get_label(False) == "y"
|
| 1129 |
+
assert p[1].rendering_kw == {}
|
| 1130 |
+
|
| 1131 |
+
# multiple parametric expression, custom ranges and labels
|
| 1132 |
+
p = plot3d_parametric_line(
|
| 1133 |
+
(x + 1, x, sin(x)),
|
| 1134 |
+
(x ** 2, 1, cos(x), (x, -2, 2), "test", {"cmap": "Reds"}))
|
| 1135 |
+
assert p[0].expr == (x + 1, x, sin(x))
|
| 1136 |
+
assert p[0].ranges == [(x, -10, 10)]
|
| 1137 |
+
assert p[0].get_label(False) == "x"
|
| 1138 |
+
assert p[0].rendering_kw == {}
|
| 1139 |
+
assert p[1].expr == (x ** 2, 1, cos(x))
|
| 1140 |
+
assert p[1].ranges == [(x, -2, 2)]
|
| 1141 |
+
assert p[1].get_label(False) == "test"
|
| 1142 |
+
assert p[1].rendering_kw == {"cmap": "Reds"}
|
| 1143 |
+
|
| 1144 |
+
# single argument: lambda function
|
| 1145 |
+
fx = lambda t: t
|
| 1146 |
+
fy = lambda t: 2 * t
|
| 1147 |
+
fz = lambda t: 3 * t
|
| 1148 |
+
p = plot3d_parametric_line(fx, fy, fz)
|
| 1149 |
+
assert all(callable(t) for t in p[0].expr)
|
| 1150 |
+
assert p[0].ranges[0][1:] == (-10, 10)
|
| 1151 |
+
assert "Dummy" in p[0].get_label(False)
|
| 1152 |
+
assert p[0].rendering_kw == {}
|
| 1153 |
+
|
| 1154 |
+
# single argument: lambda function + custom range + label
|
| 1155 |
+
p = plot3d_parametric_line(fx, fy, fz, ("t", 0, 2), "test")
|
| 1156 |
+
assert all(callable(t) for t in p[0].expr)
|
| 1157 |
+
assert p[0].ranges[0][1:] == (0, 2)
|
| 1158 |
+
assert p[0].get_label(False) == "test"
|
| 1159 |
+
assert p[0].rendering_kw == {}
|
| 1160 |
+
|
| 1161 |
+
|
| 1162 |
+
def test_plot3d_plot_contour_arguments():
|
| 1163 |
+
### Test arguments for plot3d() and plot_contour()
|
| 1164 |
+
if not matplotlib:
|
| 1165 |
+
skip("Matplotlib not the default backend")
|
| 1166 |
+
|
| 1167 |
+
x, y = symbols("x, y")
|
| 1168 |
+
|
| 1169 |
+
# single expression
|
| 1170 |
+
p = plot3d(x + y)
|
| 1171 |
+
assert isinstance(p[0], SurfaceOver2DRangeSeries)
|
| 1172 |
+
assert p[0].expr == x + y
|
| 1173 |
+
assert p[0].ranges[0] == (x, -10, 10) or (y, -10, 10)
|
| 1174 |
+
assert p[0].ranges[1] == (x, -10, 10) or (y, -10, 10)
|
| 1175 |
+
assert p[0].get_label(False) == "x + y"
|
| 1176 |
+
assert p[0].rendering_kw == {}
|
| 1177 |
+
|
| 1178 |
+
# single expression, custom range, label and rendering kws
|
| 1179 |
+
p = plot3d(x + y, (x, -2, 2), "test", {"cmap": "Reds"})
|
| 1180 |
+
assert isinstance(p[0], SurfaceOver2DRangeSeries)
|
| 1181 |
+
assert p[0].expr == x + y
|
| 1182 |
+
assert p[0].ranges[0] == (x, -2, 2)
|
| 1183 |
+
assert p[0].ranges[1] == (y, -10, 10)
|
| 1184 |
+
assert p[0].get_label(False) == "test"
|
| 1185 |
+
assert p[0].rendering_kw == {"cmap": "Reds"}
|
| 1186 |
+
|
| 1187 |
+
p = plot3d(x + y, (x, -2, 2), (y, -4, 4), "test")
|
| 1188 |
+
assert p[0].ranges[0] == (x, -2, 2)
|
| 1189 |
+
assert p[0].ranges[1] == (y, -4, 4)
|
| 1190 |
+
|
| 1191 |
+
# multiple expressions
|
| 1192 |
+
p = plot3d(x + y, x * y)
|
| 1193 |
+
assert p[0].expr == x + y
|
| 1194 |
+
assert p[0].ranges[0] == (x, -10, 10) or (y, -10, 10)
|
| 1195 |
+
assert p[0].ranges[1] == (x, -10, 10) or (y, -10, 10)
|
| 1196 |
+
assert p[0].get_label(False) == "x + y"
|
| 1197 |
+
assert p[0].rendering_kw == {}
|
| 1198 |
+
assert p[1].expr == x * y
|
| 1199 |
+
assert p[1].ranges[0] == (x, -10, 10) or (y, -10, 10)
|
| 1200 |
+
assert p[1].ranges[1] == (x, -10, 10) or (y, -10, 10)
|
| 1201 |
+
assert p[1].get_label(False) == "x*y"
|
| 1202 |
+
assert p[1].rendering_kw == {}
|
| 1203 |
+
|
| 1204 |
+
# multiple expressions, same custom ranges
|
| 1205 |
+
p = plot3d(x + y, x * y, (x, -2, 2), (y, -4, 4))
|
| 1206 |
+
assert p[0].expr == x + y
|
| 1207 |
+
assert p[0].ranges[0] == (x, -2, 2)
|
| 1208 |
+
assert p[0].ranges[1] == (y, -4, 4)
|
| 1209 |
+
assert p[0].get_label(False) == "x + y"
|
| 1210 |
+
assert p[0].rendering_kw == {}
|
| 1211 |
+
assert p[1].expr == x * y
|
| 1212 |
+
assert p[1].ranges[0] == (x, -2, 2)
|
| 1213 |
+
assert p[1].ranges[1] == (y, -4, 4)
|
| 1214 |
+
assert p[1].get_label(False) == "x*y"
|
| 1215 |
+
assert p[1].rendering_kw == {}
|
| 1216 |
+
|
| 1217 |
+
# multiple expressions, custom ranges, labels and rendering kws
|
| 1218 |
+
p = plot3d(
|
| 1219 |
+
(x + y, (x, -2, 2), (y, -4, 4)),
|
| 1220 |
+
(x * y, (x, -3, 3), (y, -6, 6), "test", {"cmap": "Reds"}))
|
| 1221 |
+
assert p[0].expr == x + y
|
| 1222 |
+
assert p[0].ranges[0] == (x, -2, 2)
|
| 1223 |
+
assert p[0].ranges[1] == (y, -4, 4)
|
| 1224 |
+
assert p[0].get_label(False) == "x + y"
|
| 1225 |
+
assert p[0].rendering_kw == {}
|
| 1226 |
+
assert p[1].expr == x * y
|
| 1227 |
+
assert p[1].ranges[0] == (x, -3, 3)
|
| 1228 |
+
assert p[1].ranges[1] == (y, -6, 6)
|
| 1229 |
+
assert p[1].get_label(False) == "test"
|
| 1230 |
+
assert p[1].rendering_kw == {"cmap": "Reds"}
|
| 1231 |
+
|
| 1232 |
+
# single expression: lambda function
|
| 1233 |
+
f = lambda x, y: x + y
|
| 1234 |
+
p = plot3d(f)
|
| 1235 |
+
assert callable(p[0].expr)
|
| 1236 |
+
assert p[0].ranges[0][1:] == (-10, 10)
|
| 1237 |
+
assert p[0].ranges[1][1:] == (-10, 10)
|
| 1238 |
+
assert p[0].get_label(False) == ""
|
| 1239 |
+
assert p[0].rendering_kw == {}
|
| 1240 |
+
|
| 1241 |
+
# single expression: lambda function + custom ranges + label
|
| 1242 |
+
p = plot3d(f, ("a", -5, 3), ("b", -2, 1), "test")
|
| 1243 |
+
assert callable(p[0].expr)
|
| 1244 |
+
assert p[0].ranges[0][1:] == (-5, 3)
|
| 1245 |
+
assert p[0].ranges[1][1:] == (-2, 1)
|
| 1246 |
+
assert p[0].get_label(False) == "test"
|
| 1247 |
+
assert p[0].rendering_kw == {}
|
| 1248 |
+
|
| 1249 |
+
# test issue 25818
|
| 1250 |
+
# single expression, custom range, min/max functions
|
| 1251 |
+
p = plot3d(Min(x, y), (x, 0, 10), (y, 0, 10))
|
| 1252 |
+
assert isinstance(p[0], SurfaceOver2DRangeSeries)
|
| 1253 |
+
assert p[0].expr == Min(x, y)
|
| 1254 |
+
assert p[0].ranges[0] == (x, 0, 10)
|
| 1255 |
+
assert p[0].ranges[1] == (y, 0, 10)
|
| 1256 |
+
assert p[0].get_label(False) == "Min(x, y)"
|
| 1257 |
+
assert p[0].rendering_kw == {}
|
| 1258 |
+
|
| 1259 |
+
|
| 1260 |
+
def test_plot3d_parametric_surface_arguments():
|
| 1261 |
+
### Test arguments for plot3d_parametric_surface()
|
| 1262 |
+
if not matplotlib:
|
| 1263 |
+
skip("Matplotlib not the default backend")
|
| 1264 |
+
|
| 1265 |
+
x, y = symbols("x, y")
|
| 1266 |
+
|
| 1267 |
+
# single parametric expression
|
| 1268 |
+
p = plot3d_parametric_surface(x + y, cos(x + y), sin(x + y))
|
| 1269 |
+
assert isinstance(p[0], ParametricSurfaceSeries)
|
| 1270 |
+
assert p[0].expr == (x + y, cos(x + y), sin(x + y))
|
| 1271 |
+
assert p[0].ranges[0] == (x, -10, 10) or (y, -10, 10)
|
| 1272 |
+
assert p[0].ranges[1] == (x, -10, 10) or (y, -10, 10)
|
| 1273 |
+
assert p[0].get_label(False) == "(x + y, cos(x + y), sin(x + y))"
|
| 1274 |
+
assert p[0].rendering_kw == {}
|
| 1275 |
+
|
| 1276 |
+
# single parametric expression, custom ranges, labels and rendering kws
|
| 1277 |
+
p = plot3d_parametric_surface(x + y, cos(x + y), sin(x + y),
|
| 1278 |
+
(x, -2, 2), (y, -4, 4), "test", {"cmap": "Reds"})
|
| 1279 |
+
assert isinstance(p[0], ParametricSurfaceSeries)
|
| 1280 |
+
assert p[0].expr == (x + y, cos(x + y), sin(x + y))
|
| 1281 |
+
assert p[0].ranges[0] == (x, -2, 2)
|
| 1282 |
+
assert p[0].ranges[1] == (y, -4, 4)
|
| 1283 |
+
assert p[0].get_label(False) == "test"
|
| 1284 |
+
assert p[0].rendering_kw == {"cmap": "Reds"}
|
| 1285 |
+
|
| 1286 |
+
# multiple parametric expressions
|
| 1287 |
+
p = plot3d_parametric_surface(
|
| 1288 |
+
(x + y, cos(x + y), sin(x + y)),
|
| 1289 |
+
(x - y, cos(x - y), sin(x - y), "test"))
|
| 1290 |
+
assert p[0].expr == (x + y, cos(x + y), sin(x + y))
|
| 1291 |
+
assert p[0].ranges[0] == (x, -10, 10) or (y, -10, 10)
|
| 1292 |
+
assert p[0].ranges[1] == (x, -10, 10) or (y, -10, 10)
|
| 1293 |
+
assert p[0].get_label(False) == "(x + y, cos(x + y), sin(x + y))"
|
| 1294 |
+
assert p[0].rendering_kw == {}
|
| 1295 |
+
assert p[1].expr == (x - y, cos(x - y), sin(x - y))
|
| 1296 |
+
assert p[1].ranges[0] == (x, -10, 10) or (y, -10, 10)
|
| 1297 |
+
assert p[1].ranges[1] == (x, -10, 10) or (y, -10, 10)
|
| 1298 |
+
assert p[1].get_label(False) == "test"
|
| 1299 |
+
assert p[1].rendering_kw == {}
|
| 1300 |
+
|
| 1301 |
+
# multiple parametric expressions, custom ranges and labels
|
| 1302 |
+
p = plot3d_parametric_surface(
|
| 1303 |
+
(x + y, cos(x + y), sin(x + y), (x, -2, 2), "test"),
|
| 1304 |
+
(x - y, cos(x - y), sin(x - y), (x, -3, 3), (y, -4, 4),
|
| 1305 |
+
"test2", {"cmap": "Reds"}))
|
| 1306 |
+
assert p[0].expr == (x + y, cos(x + y), sin(x + y))
|
| 1307 |
+
assert p[0].ranges[0] == (x, -2, 2)
|
| 1308 |
+
assert p[0].ranges[1] == (y, -10, 10)
|
| 1309 |
+
assert p[0].get_label(False) == "test"
|
| 1310 |
+
assert p[0].rendering_kw == {}
|
| 1311 |
+
assert p[1].expr == (x - y, cos(x - y), sin(x - y))
|
| 1312 |
+
assert p[1].ranges[0] == (x, -3, 3)
|
| 1313 |
+
assert p[1].ranges[1] == (y, -4, 4)
|
| 1314 |
+
assert p[1].get_label(False) == "test2"
|
| 1315 |
+
assert p[1].rendering_kw == {"cmap": "Reds"}
|
| 1316 |
+
|
| 1317 |
+
# lambda functions instead of symbolic expressions for a single 3D
|
| 1318 |
+
# parametric surface
|
| 1319 |
+
p = plot3d_parametric_surface(
|
| 1320 |
+
lambda u, v: u, lambda u, v: v, lambda u, v: u + v,
|
| 1321 |
+
("u", 0, 2), ("v", -3, 4))
|
| 1322 |
+
assert all(callable(t) for t in p[0].expr)
|
| 1323 |
+
assert p[0].ranges[0][1:] == (-0, 2)
|
| 1324 |
+
assert p[0].ranges[1][1:] == (-3, 4)
|
| 1325 |
+
assert p[0].get_label(False) == ""
|
| 1326 |
+
assert p[0].rendering_kw == {}
|
| 1327 |
+
|
| 1328 |
+
# lambda functions instead of symbolic expressions for multiple 3D
|
| 1329 |
+
# parametric surfaces
|
| 1330 |
+
p = plot3d_parametric_surface(
|
| 1331 |
+
(lambda u, v: u, lambda u, v: v, lambda u, v: u + v,
|
| 1332 |
+
("u", 0, 2), ("v", -3, 4)),
|
| 1333 |
+
(lambda u, v: v, lambda u, v: u, lambda u, v: u - v,
|
| 1334 |
+
("u", -2, 3), ("v", -4, 5), "test"))
|
| 1335 |
+
assert all(callable(t) for t in p[0].expr)
|
| 1336 |
+
assert p[0].ranges[0][1:] == (0, 2)
|
| 1337 |
+
assert p[0].ranges[1][1:] == (-3, 4)
|
| 1338 |
+
assert p[0].get_label(False) == ""
|
| 1339 |
+
assert p[0].rendering_kw == {}
|
| 1340 |
+
assert all(callable(t) for t in p[1].expr)
|
| 1341 |
+
assert p[1].ranges[0][1:] == (-2, 3)
|
| 1342 |
+
assert p[1].ranges[1][1:] == (-4, 5)
|
| 1343 |
+
assert p[1].get_label(False) == "test"
|
| 1344 |
+
assert p[1].rendering_kw == {}
|
venv/lib/python3.14/site-packages/sympy/plotting/tests/test_plot_implicit.py
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from sympy.core.numbers import (I, pi)
|
| 2 |
+
from sympy.core.relational import Eq
|
| 3 |
+
from sympy.core.symbol import (Symbol, symbols)
|
| 4 |
+
from sympy.functions.elementary.complexes import re
|
| 5 |
+
from sympy.functions.elementary.exponential import exp
|
| 6 |
+
from sympy.functions.elementary.trigonometric import (cos, sin, tan)
|
| 7 |
+
from sympy.logic.boolalg import (And, Or)
|
| 8 |
+
from sympy.plotting.plot_implicit import plot_implicit
|
| 9 |
+
from sympy.plotting.plot import unset_show
|
| 10 |
+
from tempfile import NamedTemporaryFile, mkdtemp
|
| 11 |
+
from sympy.testing.pytest import skip, warns, XFAIL
|
| 12 |
+
from sympy.external import import_module
|
| 13 |
+
from sympy.testing.tmpfiles import TmpFileManager
|
| 14 |
+
|
| 15 |
+
import os
|
| 16 |
+
|
| 17 |
+
#Set plots not to show
|
| 18 |
+
unset_show()
|
| 19 |
+
|
| 20 |
+
def tmp_file(dir=None, name=''):
|
| 21 |
+
return NamedTemporaryFile(
|
| 22 |
+
suffix='.png', dir=dir, delete=False).name
|
| 23 |
+
|
| 24 |
+
def plot_and_save(expr, *args, name='', dir=None, **kwargs):
|
| 25 |
+
p = plot_implicit(expr, *args, **kwargs)
|
| 26 |
+
p.save(tmp_file(dir=dir, name=name))
|
| 27 |
+
# Close the plot to avoid a warning from matplotlib
|
| 28 |
+
p._backend.close()
|
| 29 |
+
|
| 30 |
+
def plot_implicit_tests(name):
|
| 31 |
+
temp_dir = mkdtemp()
|
| 32 |
+
TmpFileManager.tmp_folder(temp_dir)
|
| 33 |
+
x = Symbol('x')
|
| 34 |
+
y = Symbol('y')
|
| 35 |
+
#implicit plot tests
|
| 36 |
+
plot_and_save(Eq(y, cos(x)), (x, -5, 5), (y, -2, 2), name=name, dir=temp_dir)
|
| 37 |
+
plot_and_save(Eq(y**2, x**3 - x), (x, -5, 5),
|
| 38 |
+
(y, -4, 4), name=name, dir=temp_dir)
|
| 39 |
+
plot_and_save(y > 1 / x, (x, -5, 5),
|
| 40 |
+
(y, -2, 2), name=name, dir=temp_dir)
|
| 41 |
+
plot_and_save(y < 1 / tan(x), (x, -5, 5),
|
| 42 |
+
(y, -2, 2), name=name, dir=temp_dir)
|
| 43 |
+
plot_and_save(y >= 2 * sin(x) * cos(x), (x, -5, 5),
|
| 44 |
+
(y, -2, 2), name=name, dir=temp_dir)
|
| 45 |
+
plot_and_save(y <= x**2, (x, -3, 3),
|
| 46 |
+
(y, -1, 5), name=name, dir=temp_dir)
|
| 47 |
+
|
| 48 |
+
#Test all input args for plot_implicit
|
| 49 |
+
plot_and_save(Eq(y**2, x**3 - x), dir=temp_dir)
|
| 50 |
+
plot_and_save(Eq(y**2, x**3 - x), adaptive=False, dir=temp_dir)
|
| 51 |
+
plot_and_save(Eq(y**2, x**3 - x), adaptive=False, n=500, dir=temp_dir)
|
| 52 |
+
plot_and_save(y > x, (x, -5, 5), dir=temp_dir)
|
| 53 |
+
plot_and_save(And(y > exp(x), y > x + 2), dir=temp_dir)
|
| 54 |
+
plot_and_save(Or(y > x, y > -x), dir=temp_dir)
|
| 55 |
+
plot_and_save(x**2 - 1, (x, -5, 5), dir=temp_dir)
|
| 56 |
+
plot_and_save(x**2 - 1, dir=temp_dir)
|
| 57 |
+
plot_and_save(y > x, depth=-5, dir=temp_dir)
|
| 58 |
+
plot_and_save(y > x, depth=5, dir=temp_dir)
|
| 59 |
+
plot_and_save(y > cos(x), adaptive=False, dir=temp_dir)
|
| 60 |
+
plot_and_save(y < cos(x), adaptive=False, dir=temp_dir)
|
| 61 |
+
plot_and_save(And(y > cos(x), Or(y > x, Eq(y, x))), dir=temp_dir)
|
| 62 |
+
plot_and_save(y - cos(pi / x), dir=temp_dir)
|
| 63 |
+
|
| 64 |
+
plot_and_save(x**2 - 1, title='An implicit plot', dir=temp_dir)
|
| 65 |
+
|
| 66 |
+
@XFAIL
|
| 67 |
+
def test_no_adaptive_meshing():
|
| 68 |
+
matplotlib = import_module('matplotlib', min_module_version='1.1.0', catch=(RuntimeError,))
|
| 69 |
+
if matplotlib:
|
| 70 |
+
try:
|
| 71 |
+
temp_dir = mkdtemp()
|
| 72 |
+
TmpFileManager.tmp_folder(temp_dir)
|
| 73 |
+
x = Symbol('x')
|
| 74 |
+
y = Symbol('y')
|
| 75 |
+
# Test plots which cannot be rendered using the adaptive algorithm
|
| 76 |
+
|
| 77 |
+
# This works, but it triggers a deprecation warning from sympify(). The
|
| 78 |
+
# code needs to be updated to detect if interval math is supported without
|
| 79 |
+
# relying on random AttributeErrors.
|
| 80 |
+
with warns(UserWarning, match="Adaptive meshing could not be applied"):
|
| 81 |
+
plot_and_save(Eq(y, re(cos(x) + I*sin(x))), name='test', dir=temp_dir)
|
| 82 |
+
finally:
|
| 83 |
+
TmpFileManager.cleanup()
|
| 84 |
+
else:
|
| 85 |
+
skip("Matplotlib not the default backend")
|
| 86 |
+
def test_line_color():
|
| 87 |
+
x, y = symbols('x, y')
|
| 88 |
+
p = plot_implicit(x**2 + y**2 - 1, line_color="green", show=False)
|
| 89 |
+
assert p._series[0].line_color == "green"
|
| 90 |
+
p = plot_implicit(x**2 + y**2 - 1, line_color='r', show=False)
|
| 91 |
+
assert p._series[0].line_color == "r"
|
| 92 |
+
|
| 93 |
+
def test_matplotlib():
|
| 94 |
+
matplotlib = import_module('matplotlib', min_module_version='1.1.0', catch=(RuntimeError,))
|
| 95 |
+
if matplotlib:
|
| 96 |
+
try:
|
| 97 |
+
plot_implicit_tests('test')
|
| 98 |
+
test_line_color()
|
| 99 |
+
finally:
|
| 100 |
+
TmpFileManager.cleanup()
|
| 101 |
+
else:
|
| 102 |
+
skip("Matplotlib not the default backend")
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
def test_region_and():
|
| 106 |
+
matplotlib = import_module('matplotlib', min_module_version='1.1.0', catch=(RuntimeError,))
|
| 107 |
+
if not matplotlib:
|
| 108 |
+
skip("Matplotlib not the default backend")
|
| 109 |
+
|
| 110 |
+
from matplotlib.testing.compare import compare_images
|
| 111 |
+
test_directory = os.path.dirname(os.path.abspath(__file__))
|
| 112 |
+
|
| 113 |
+
try:
|
| 114 |
+
temp_dir = mkdtemp()
|
| 115 |
+
TmpFileManager.tmp_folder(temp_dir)
|
| 116 |
+
|
| 117 |
+
x, y = symbols('x y')
|
| 118 |
+
|
| 119 |
+
r1 = (x - 1)**2 + y**2 < 2
|
| 120 |
+
r2 = (x + 1)**2 + y**2 < 2
|
| 121 |
+
|
| 122 |
+
test_filename = tmp_file(dir=temp_dir, name="test_region_and")
|
| 123 |
+
cmp_filename = os.path.join(test_directory, "test_region_and.png")
|
| 124 |
+
p = plot_implicit(r1 & r2, x, y)
|
| 125 |
+
p.save(test_filename)
|
| 126 |
+
compare_images(cmp_filename, test_filename, 0.005)
|
| 127 |
+
|
| 128 |
+
test_filename = tmp_file(dir=temp_dir, name="test_region_or")
|
| 129 |
+
cmp_filename = os.path.join(test_directory, "test_region_or.png")
|
| 130 |
+
p = plot_implicit(r1 | r2, x, y)
|
| 131 |
+
p.save(test_filename)
|
| 132 |
+
compare_images(cmp_filename, test_filename, 0.005)
|
| 133 |
+
|
| 134 |
+
test_filename = tmp_file(dir=temp_dir, name="test_region_not")
|
| 135 |
+
cmp_filename = os.path.join(test_directory, "test_region_not.png")
|
| 136 |
+
p = plot_implicit(~r1, x, y)
|
| 137 |
+
p.save(test_filename)
|
| 138 |
+
compare_images(cmp_filename, test_filename, 0.005)
|
| 139 |
+
|
| 140 |
+
test_filename = tmp_file(dir=temp_dir, name="test_region_xor")
|
| 141 |
+
cmp_filename = os.path.join(test_directory, "test_region_xor.png")
|
| 142 |
+
p = plot_implicit(r1 ^ r2, x, y)
|
| 143 |
+
p.save(test_filename)
|
| 144 |
+
compare_images(cmp_filename, test_filename, 0.005)
|
| 145 |
+
finally:
|
| 146 |
+
TmpFileManager.cleanup()
|
venv/lib/python3.14/site-packages/sympy/plotting/tests/test_region_and.png
ADDED
|
venv/lib/python3.14/site-packages/sympy/plotting/tests/test_region_not.png
ADDED
|
venv/lib/python3.14/site-packages/sympy/plotting/tests/test_region_or.png
ADDED
|
venv/lib/python3.14/site-packages/sympy/plotting/tests/test_region_xor.png
ADDED
|
venv/lib/python3.14/site-packages/sympy/plotting/tests/test_series.py
ADDED
|
@@ -0,0 +1,1771 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from sympy import (
|
| 2 |
+
latex, exp, symbols, I, pi, sin, cos, tan, log, sqrt,
|
| 3 |
+
re, im, arg, frac, Sum, S, Abs, lambdify,
|
| 4 |
+
Function, dsolve, Eq, floor, Tuple
|
| 5 |
+
)
|
| 6 |
+
from sympy.external import import_module
|
| 7 |
+
from sympy.plotting.series import (
|
| 8 |
+
LineOver1DRangeSeries, Parametric2DLineSeries, Parametric3DLineSeries,
|
| 9 |
+
SurfaceOver2DRangeSeries, ContourSeries, ParametricSurfaceSeries,
|
| 10 |
+
ImplicitSeries, _set_discretization_points, List2DSeries
|
| 11 |
+
)
|
| 12 |
+
from sympy.testing.pytest import raises, warns, XFAIL, skip, ignore_warnings
|
| 13 |
+
|
| 14 |
+
np = import_module('numpy')
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def test_adaptive():
|
| 18 |
+
# verify that adaptive-related keywords produces the expected results
|
| 19 |
+
if not np:
|
| 20 |
+
skip("numpy not installed.")
|
| 21 |
+
|
| 22 |
+
x, y = symbols("x, y")
|
| 23 |
+
|
| 24 |
+
s1 = LineOver1DRangeSeries(sin(x), (x, -10, 10), "", adaptive=True,
|
| 25 |
+
depth=2)
|
| 26 |
+
x1, _ = s1.get_data()
|
| 27 |
+
s2 = LineOver1DRangeSeries(sin(x), (x, -10, 10), "", adaptive=True,
|
| 28 |
+
depth=5)
|
| 29 |
+
x2, _ = s2.get_data()
|
| 30 |
+
s3 = LineOver1DRangeSeries(sin(x), (x, -10, 10), "", adaptive=True)
|
| 31 |
+
x3, _ = s3.get_data()
|
| 32 |
+
assert len(x1) < len(x2) < len(x3)
|
| 33 |
+
|
| 34 |
+
s1 = Parametric2DLineSeries(cos(x), sin(x), (x, 0, 2*pi),
|
| 35 |
+
adaptive=True, depth=2)
|
| 36 |
+
x1, _, _, = s1.get_data()
|
| 37 |
+
s2 = Parametric2DLineSeries(cos(x), sin(x), (x, 0, 2*pi),
|
| 38 |
+
adaptive=True, depth=5)
|
| 39 |
+
x2, _, _ = s2.get_data()
|
| 40 |
+
s3 = Parametric2DLineSeries(cos(x), sin(x), (x, 0, 2*pi),
|
| 41 |
+
adaptive=True)
|
| 42 |
+
x3, _, _ = s3.get_data()
|
| 43 |
+
assert len(x1) < len(x2) < len(x3)
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
def test_detect_poles():
|
| 47 |
+
if not np:
|
| 48 |
+
skip("numpy not installed.")
|
| 49 |
+
|
| 50 |
+
x, u = symbols("x, u")
|
| 51 |
+
|
| 52 |
+
s1 = LineOver1DRangeSeries(tan(x), (x, -pi, pi),
|
| 53 |
+
adaptive=False, n=1000, detect_poles=False)
|
| 54 |
+
xx1, yy1 = s1.get_data()
|
| 55 |
+
s2 = LineOver1DRangeSeries(tan(x), (x, -pi, pi),
|
| 56 |
+
adaptive=False, n=1000, detect_poles=True, eps=0.01)
|
| 57 |
+
xx2, yy2 = s2.get_data()
|
| 58 |
+
# eps is too small: doesn't detect any poles
|
| 59 |
+
s3 = LineOver1DRangeSeries(tan(x), (x, -pi, pi),
|
| 60 |
+
adaptive=False, n=1000, detect_poles=True, eps=1e-06)
|
| 61 |
+
xx3, yy3 = s3.get_data()
|
| 62 |
+
s4 = LineOver1DRangeSeries(tan(x), (x, -pi, pi),
|
| 63 |
+
adaptive=False, n=1000, detect_poles="symbolic")
|
| 64 |
+
xx4, yy4 = s4.get_data()
|
| 65 |
+
|
| 66 |
+
assert np.allclose(xx1, xx2) and np.allclose(xx1, xx3) and np.allclose(xx1, xx4)
|
| 67 |
+
assert not np.any(np.isnan(yy1))
|
| 68 |
+
assert not np.any(np.isnan(yy3))
|
| 69 |
+
assert np.any(np.isnan(yy2))
|
| 70 |
+
assert np.any(np.isnan(yy4))
|
| 71 |
+
assert len(s2.poles_locations) == len(s3.poles_locations) == 0
|
| 72 |
+
assert len(s4.poles_locations) == 2
|
| 73 |
+
assert np.allclose(np.abs(s4.poles_locations), np.pi / 2)
|
| 74 |
+
|
| 75 |
+
with warns(
|
| 76 |
+
UserWarning,
|
| 77 |
+
match="NumPy is unable to evaluate with complex numbers some of",
|
| 78 |
+
test_stacklevel=False,
|
| 79 |
+
):
|
| 80 |
+
s1 = LineOver1DRangeSeries(frac(x), (x, -10, 10),
|
| 81 |
+
adaptive=False, n=1000, detect_poles=False)
|
| 82 |
+
s2 = LineOver1DRangeSeries(frac(x), (x, -10, 10),
|
| 83 |
+
adaptive=False, n=1000, detect_poles=True, eps=0.05)
|
| 84 |
+
s3 = LineOver1DRangeSeries(frac(x), (x, -10, 10),
|
| 85 |
+
adaptive=False, n=1000, detect_poles="symbolic")
|
| 86 |
+
xx1, yy1 = s1.get_data()
|
| 87 |
+
xx2, yy2 = s2.get_data()
|
| 88 |
+
xx3, yy3 = s3.get_data()
|
| 89 |
+
assert np.allclose(xx1, xx2) and np.allclose(xx1, xx3)
|
| 90 |
+
assert not np.any(np.isnan(yy1))
|
| 91 |
+
assert np.any(np.isnan(yy2)) and np.any(np.isnan(yy2))
|
| 92 |
+
assert not np.allclose(yy1, yy2, equal_nan=True)
|
| 93 |
+
# The poles below are actually step discontinuities.
|
| 94 |
+
assert len(s3.poles_locations) == 21
|
| 95 |
+
|
| 96 |
+
s1 = LineOver1DRangeSeries(tan(u * x), (x, -pi, pi), params={u: 1},
|
| 97 |
+
adaptive=False, n=1000, detect_poles=False)
|
| 98 |
+
xx1, yy1 = s1.get_data()
|
| 99 |
+
s2 = LineOver1DRangeSeries(tan(u * x), (x, -pi, pi), params={u: 1},
|
| 100 |
+
adaptive=False, n=1000, detect_poles=True, eps=0.01)
|
| 101 |
+
xx2, yy2 = s2.get_data()
|
| 102 |
+
# eps is too small: doesn't detect any poles
|
| 103 |
+
s3 = LineOver1DRangeSeries(tan(u * x), (x, -pi, pi), params={u: 1},
|
| 104 |
+
adaptive=False, n=1000, detect_poles=True, eps=1e-06)
|
| 105 |
+
xx3, yy3 = s3.get_data()
|
| 106 |
+
s4 = LineOver1DRangeSeries(tan(u * x), (x, -pi, pi), params={u: 1},
|
| 107 |
+
adaptive=False, n=1000, detect_poles="symbolic")
|
| 108 |
+
xx4, yy4 = s4.get_data()
|
| 109 |
+
|
| 110 |
+
assert np.allclose(xx1, xx2) and np.allclose(xx1, xx3) and np.allclose(xx1, xx4)
|
| 111 |
+
assert not np.any(np.isnan(yy1))
|
| 112 |
+
assert not np.any(np.isnan(yy3))
|
| 113 |
+
assert np.any(np.isnan(yy2))
|
| 114 |
+
assert np.any(np.isnan(yy4))
|
| 115 |
+
assert len(s2.poles_locations) == len(s3.poles_locations) == 0
|
| 116 |
+
assert len(s4.poles_locations) == 2
|
| 117 |
+
assert np.allclose(np.abs(s4.poles_locations), np.pi / 2)
|
| 118 |
+
|
| 119 |
+
with warns(
|
| 120 |
+
UserWarning,
|
| 121 |
+
match="NumPy is unable to evaluate with complex numbers some of",
|
| 122 |
+
test_stacklevel=False,
|
| 123 |
+
):
|
| 124 |
+
u, v = symbols("u, v", real=True)
|
| 125 |
+
n = S(1) / 3
|
| 126 |
+
f = (u + I * v)**n
|
| 127 |
+
r, i = re(f), im(f)
|
| 128 |
+
s1 = Parametric2DLineSeries(r.subs(u, -2), i.subs(u, -2), (v, -2, 2),
|
| 129 |
+
adaptive=False, n=1000, detect_poles=False)
|
| 130 |
+
s2 = Parametric2DLineSeries(r.subs(u, -2), i.subs(u, -2), (v, -2, 2),
|
| 131 |
+
adaptive=False, n=1000, detect_poles=True)
|
| 132 |
+
with ignore_warnings(RuntimeWarning):
|
| 133 |
+
xx1, yy1, pp1 = s1.get_data()
|
| 134 |
+
assert not np.isnan(yy1).any()
|
| 135 |
+
xx2, yy2, pp2 = s2.get_data()
|
| 136 |
+
assert np.isnan(yy2).any()
|
| 137 |
+
|
| 138 |
+
with warns(
|
| 139 |
+
UserWarning,
|
| 140 |
+
match="NumPy is unable to evaluate with complex numbers some of",
|
| 141 |
+
test_stacklevel=False,
|
| 142 |
+
):
|
| 143 |
+
f = (x * u + x * I * v)**n
|
| 144 |
+
r, i = re(f), im(f)
|
| 145 |
+
s1 = Parametric2DLineSeries(r.subs(u, -2), i.subs(u, -2),
|
| 146 |
+
(v, -2, 2), params={x: 1},
|
| 147 |
+
adaptive=False, n1=1000, detect_poles=False)
|
| 148 |
+
s2 = Parametric2DLineSeries(r.subs(u, -2), i.subs(u, -2),
|
| 149 |
+
(v, -2, 2), params={x: 1},
|
| 150 |
+
adaptive=False, n1=1000, detect_poles=True)
|
| 151 |
+
with ignore_warnings(RuntimeWarning):
|
| 152 |
+
xx1, yy1, pp1 = s1.get_data()
|
| 153 |
+
assert not np.isnan(yy1).any()
|
| 154 |
+
xx2, yy2, pp2 = s2.get_data()
|
| 155 |
+
assert np.isnan(yy2).any()
|
| 156 |
+
|
| 157 |
+
|
| 158 |
+
def test_number_discretization_points():
|
| 159 |
+
# verify that the different ways to set the number of discretization
|
| 160 |
+
# points are consistent with each other.
|
| 161 |
+
if not np:
|
| 162 |
+
skip("numpy not installed.")
|
| 163 |
+
|
| 164 |
+
x, y, z = symbols("x:z")
|
| 165 |
+
|
| 166 |
+
for pt in [LineOver1DRangeSeries, Parametric2DLineSeries,
|
| 167 |
+
Parametric3DLineSeries]:
|
| 168 |
+
kw1 = _set_discretization_points({"n": 10}, pt)
|
| 169 |
+
kw2 = _set_discretization_points({"n": [10, 20, 30]}, pt)
|
| 170 |
+
kw3 = _set_discretization_points({"n1": 10}, pt)
|
| 171 |
+
assert all(("n1" in kw) and kw["n1"] == 10 for kw in [kw1, kw2, kw3])
|
| 172 |
+
|
| 173 |
+
for pt in [SurfaceOver2DRangeSeries, ContourSeries, ParametricSurfaceSeries,
|
| 174 |
+
ImplicitSeries]:
|
| 175 |
+
kw1 = _set_discretization_points({"n": 10}, pt)
|
| 176 |
+
kw2 = _set_discretization_points({"n": [10, 20, 30]}, pt)
|
| 177 |
+
kw3 = _set_discretization_points({"n1": 10, "n2": 20}, pt)
|
| 178 |
+
assert kw1["n1"] == kw1["n2"] == 10
|
| 179 |
+
assert all((kw["n1"] == 10) and (kw["n2"] == 20) for kw in [kw2, kw3])
|
| 180 |
+
|
| 181 |
+
# verify that line-related series can deal with large float number of
|
| 182 |
+
# discretization points
|
| 183 |
+
LineOver1DRangeSeries(cos(x), (x, -5, 5), adaptive=False, n=1e04).get_data()
|
| 184 |
+
|
| 185 |
+
|
| 186 |
+
def test_list2dseries():
|
| 187 |
+
if not np:
|
| 188 |
+
skip("numpy not installed.")
|
| 189 |
+
|
| 190 |
+
xx = np.linspace(-3, 3, 10)
|
| 191 |
+
yy1 = np.cos(xx)
|
| 192 |
+
yy2 = np.linspace(-3, 3, 20)
|
| 193 |
+
|
| 194 |
+
# same number of elements: everything is fine
|
| 195 |
+
s = List2DSeries(xx, yy1)
|
| 196 |
+
assert not s.is_parametric
|
| 197 |
+
# different number of elements: error
|
| 198 |
+
raises(ValueError, lambda: List2DSeries(xx, yy2))
|
| 199 |
+
|
| 200 |
+
# no color func: returns only x, y components and s in not parametric
|
| 201 |
+
s = List2DSeries(xx, yy1)
|
| 202 |
+
xxs, yys = s.get_data()
|
| 203 |
+
assert np.allclose(xx, xxs)
|
| 204 |
+
assert np.allclose(yy1, yys)
|
| 205 |
+
assert not s.is_parametric
|
| 206 |
+
|
| 207 |
+
|
| 208 |
+
def test_interactive_vs_noninteractive():
|
| 209 |
+
# verify that if a *Series class receives a `params` dictionary, it sets
|
| 210 |
+
# is_interactive=True
|
| 211 |
+
x, y, z, u, v = symbols("x, y, z, u, v")
|
| 212 |
+
|
| 213 |
+
s = LineOver1DRangeSeries(cos(x), (x, -5, 5))
|
| 214 |
+
assert not s.is_interactive
|
| 215 |
+
s = LineOver1DRangeSeries(u * cos(x), (x, -5, 5), params={u: 1})
|
| 216 |
+
assert s.is_interactive
|
| 217 |
+
|
| 218 |
+
s = Parametric2DLineSeries(cos(x), sin(x), (x, -5, 5))
|
| 219 |
+
assert not s.is_interactive
|
| 220 |
+
s = Parametric2DLineSeries(u * cos(x), u * sin(x), (x, -5, 5),
|
| 221 |
+
params={u: 1})
|
| 222 |
+
assert s.is_interactive
|
| 223 |
+
|
| 224 |
+
s = Parametric3DLineSeries(cos(x), sin(x), x, (x, -5, 5))
|
| 225 |
+
assert not s.is_interactive
|
| 226 |
+
s = Parametric3DLineSeries(u * cos(x), u * sin(x), x, (x, -5, 5),
|
| 227 |
+
params={u: 1})
|
| 228 |
+
assert s.is_interactive
|
| 229 |
+
|
| 230 |
+
s = SurfaceOver2DRangeSeries(cos(x * y), (x, -5, 5), (y, -5, 5))
|
| 231 |
+
assert not s.is_interactive
|
| 232 |
+
s = SurfaceOver2DRangeSeries(u * cos(x * y), (x, -5, 5), (y, -5, 5),
|
| 233 |
+
params={u: 1})
|
| 234 |
+
assert s.is_interactive
|
| 235 |
+
|
| 236 |
+
s = ContourSeries(cos(x * y), (x, -5, 5), (y, -5, 5))
|
| 237 |
+
assert not s.is_interactive
|
| 238 |
+
s = ContourSeries(u * cos(x * y), (x, -5, 5), (y, -5, 5),
|
| 239 |
+
params={u: 1})
|
| 240 |
+
assert s.is_interactive
|
| 241 |
+
|
| 242 |
+
s = ParametricSurfaceSeries(u * cos(v), v * sin(u), u + v,
|
| 243 |
+
(u, -5, 5), (v, -5, 5))
|
| 244 |
+
assert not s.is_interactive
|
| 245 |
+
s = ParametricSurfaceSeries(u * cos(v * x), v * sin(u), u + v,
|
| 246 |
+
(u, -5, 5), (v, -5, 5), params={x: 1})
|
| 247 |
+
assert s.is_interactive
|
| 248 |
+
|
| 249 |
+
|
| 250 |
+
def test_lin_log_scale():
|
| 251 |
+
# Verify that data series create the correct spacing in the data.
|
| 252 |
+
if not np:
|
| 253 |
+
skip("numpy not installed.")
|
| 254 |
+
|
| 255 |
+
x, y, z = symbols("x, y, z")
|
| 256 |
+
|
| 257 |
+
s = LineOver1DRangeSeries(x, (x, 1, 10), adaptive=False, n=50,
|
| 258 |
+
xscale="linear")
|
| 259 |
+
xx, _ = s.get_data()
|
| 260 |
+
assert np.isclose(xx[1] - xx[0], xx[-1] - xx[-2])
|
| 261 |
+
|
| 262 |
+
s = LineOver1DRangeSeries(x, (x, 1, 10), adaptive=False, n=50,
|
| 263 |
+
xscale="log")
|
| 264 |
+
xx, _ = s.get_data()
|
| 265 |
+
assert not np.isclose(xx[1] - xx[0], xx[-1] - xx[-2])
|
| 266 |
+
|
| 267 |
+
s = Parametric2DLineSeries(
|
| 268 |
+
cos(x), sin(x), (x, pi / 2, 1.5 * pi), adaptive=False, n=50,
|
| 269 |
+
xscale="linear")
|
| 270 |
+
_, _, param = s.get_data()
|
| 271 |
+
assert np.isclose(param[1] - param[0], param[-1] - param[-2])
|
| 272 |
+
|
| 273 |
+
s = Parametric2DLineSeries(
|
| 274 |
+
cos(x), sin(x), (x, pi / 2, 1.5 * pi), adaptive=False, n=50,
|
| 275 |
+
xscale="log")
|
| 276 |
+
_, _, param = s.get_data()
|
| 277 |
+
assert not np.isclose(param[1] - param[0], param[-1] - param[-2])
|
| 278 |
+
|
| 279 |
+
s = Parametric3DLineSeries(
|
| 280 |
+
cos(x), sin(x), x, (x, pi / 2, 1.5 * pi), adaptive=False, n=50,
|
| 281 |
+
xscale="linear")
|
| 282 |
+
_, _, _, param = s.get_data()
|
| 283 |
+
assert np.isclose(param[1] - param[0], param[-1] - param[-2])
|
| 284 |
+
|
| 285 |
+
s = Parametric3DLineSeries(
|
| 286 |
+
cos(x), sin(x), x, (x, pi / 2, 1.5 * pi), adaptive=False, n=50,
|
| 287 |
+
xscale="log")
|
| 288 |
+
_, _, _, param = s.get_data()
|
| 289 |
+
assert not np.isclose(param[1] - param[0], param[-1] - param[-2])
|
| 290 |
+
|
| 291 |
+
s = SurfaceOver2DRangeSeries(
|
| 292 |
+
cos(x ** 2 + y ** 2), (x, 1, 5), (y, 1, 5), n=10,
|
| 293 |
+
xscale="linear", yscale="linear")
|
| 294 |
+
xx, yy, _ = s.get_data()
|
| 295 |
+
assert np.isclose(xx[0, 1] - xx[0, 0], xx[0, -1] - xx[0, -2])
|
| 296 |
+
assert np.isclose(yy[1, 0] - yy[0, 0], yy[-1, 0] - yy[-2, 0])
|
| 297 |
+
|
| 298 |
+
s = SurfaceOver2DRangeSeries(
|
| 299 |
+
cos(x ** 2 + y ** 2), (x, 1, 5), (y, 1, 5), n=10,
|
| 300 |
+
xscale="log", yscale="log")
|
| 301 |
+
xx, yy, _ = s.get_data()
|
| 302 |
+
assert not np.isclose(xx[0, 1] - xx[0, 0], xx[0, -1] - xx[0, -2])
|
| 303 |
+
assert not np.isclose(yy[1, 0] - yy[0, 0], yy[-1, 0] - yy[-2, 0])
|
| 304 |
+
|
| 305 |
+
s = ImplicitSeries(
|
| 306 |
+
cos(x ** 2 + y ** 2) > 0, (x, 1, 5), (y, 1, 5),
|
| 307 |
+
n1=10, n2=10, xscale="linear", yscale="linear", adaptive=False)
|
| 308 |
+
xx, yy, _, _ = s.get_data()
|
| 309 |
+
assert np.isclose(xx[0, 1] - xx[0, 0], xx[0, -1] - xx[0, -2])
|
| 310 |
+
assert np.isclose(yy[1, 0] - yy[0, 0], yy[-1, 0] - yy[-2, 0])
|
| 311 |
+
|
| 312 |
+
s = ImplicitSeries(
|
| 313 |
+
cos(x ** 2 + y ** 2) > 0, (x, 1, 5), (y, 1, 5),
|
| 314 |
+
n=10, xscale="log", yscale="log", adaptive=False)
|
| 315 |
+
xx, yy, _, _ = s.get_data()
|
| 316 |
+
assert not np.isclose(xx[0, 1] - xx[0, 0], xx[0, -1] - xx[0, -2])
|
| 317 |
+
assert not np.isclose(yy[1, 0] - yy[0, 0], yy[-1, 0] - yy[-2, 0])
|
| 318 |
+
|
| 319 |
+
|
| 320 |
+
def test_rendering_kw():
|
| 321 |
+
# verify that each series exposes the `rendering_kw` attribute
|
| 322 |
+
if not np:
|
| 323 |
+
skip("numpy not installed.")
|
| 324 |
+
|
| 325 |
+
u, v, x, y, z = symbols("u, v, x:z")
|
| 326 |
+
|
| 327 |
+
s = List2DSeries([1, 2, 3], [4, 5, 6])
|
| 328 |
+
assert isinstance(s.rendering_kw, dict)
|
| 329 |
+
|
| 330 |
+
s = LineOver1DRangeSeries(1, (x, -5, 5))
|
| 331 |
+
assert isinstance(s.rendering_kw, dict)
|
| 332 |
+
|
| 333 |
+
s = Parametric2DLineSeries(sin(x), cos(x), (x, 0, pi))
|
| 334 |
+
assert isinstance(s.rendering_kw, dict)
|
| 335 |
+
|
| 336 |
+
s = Parametric3DLineSeries(cos(x), sin(x), x, (x, 0, 2 * pi))
|
| 337 |
+
assert isinstance(s.rendering_kw, dict)
|
| 338 |
+
|
| 339 |
+
s = SurfaceOver2DRangeSeries(x + y, (x, -2, 2), (y, -3, 3))
|
| 340 |
+
assert isinstance(s.rendering_kw, dict)
|
| 341 |
+
|
| 342 |
+
s = ContourSeries(x + y, (x, -2, 2), (y, -3, 3))
|
| 343 |
+
assert isinstance(s.rendering_kw, dict)
|
| 344 |
+
|
| 345 |
+
s = ParametricSurfaceSeries(1, x, y, (x, 0, 1), (y, 0, 1))
|
| 346 |
+
assert isinstance(s.rendering_kw, dict)
|
| 347 |
+
|
| 348 |
+
|
| 349 |
+
def test_data_shape():
|
| 350 |
+
# Verify that the series produces the correct data shape when the input
|
| 351 |
+
# expression is a number.
|
| 352 |
+
if not np:
|
| 353 |
+
skip("numpy not installed.")
|
| 354 |
+
|
| 355 |
+
u, x, y, z = symbols("u, x:z")
|
| 356 |
+
|
| 357 |
+
# scalar expression: it should return a numpy ones array
|
| 358 |
+
s = LineOver1DRangeSeries(1, (x, -5, 5))
|
| 359 |
+
xx, yy = s.get_data()
|
| 360 |
+
assert len(xx) == len(yy)
|
| 361 |
+
assert np.all(yy == 1)
|
| 362 |
+
|
| 363 |
+
s = LineOver1DRangeSeries(1, (x, -5, 5), adaptive=False, n=10)
|
| 364 |
+
xx, yy = s.get_data()
|
| 365 |
+
assert len(xx) == len(yy) == 10
|
| 366 |
+
assert np.all(yy == 1)
|
| 367 |
+
|
| 368 |
+
s = Parametric2DLineSeries(sin(x), 1, (x, 0, pi))
|
| 369 |
+
xx, yy, param = s.get_data()
|
| 370 |
+
assert (len(xx) == len(yy)) and (len(xx) == len(param))
|
| 371 |
+
assert np.all(yy == 1)
|
| 372 |
+
|
| 373 |
+
s = Parametric2DLineSeries(1, sin(x), (x, 0, pi))
|
| 374 |
+
xx, yy, param = s.get_data()
|
| 375 |
+
assert (len(xx) == len(yy)) and (len(xx) == len(param))
|
| 376 |
+
assert np.all(xx == 1)
|
| 377 |
+
|
| 378 |
+
s = Parametric2DLineSeries(sin(x), 1, (x, 0, pi), adaptive=False)
|
| 379 |
+
xx, yy, param = s.get_data()
|
| 380 |
+
assert (len(xx) == len(yy)) and (len(xx) == len(param))
|
| 381 |
+
assert np.all(yy == 1)
|
| 382 |
+
|
| 383 |
+
s = Parametric2DLineSeries(1, sin(x), (x, 0, pi), adaptive=False)
|
| 384 |
+
xx, yy, param = s.get_data()
|
| 385 |
+
assert (len(xx) == len(yy)) and (len(xx) == len(param))
|
| 386 |
+
assert np.all(xx == 1)
|
| 387 |
+
|
| 388 |
+
s = Parametric3DLineSeries(cos(x), sin(x), 1, (x, 0, 2 * pi))
|
| 389 |
+
xx, yy, zz, param = s.get_data()
|
| 390 |
+
assert (len(xx) == len(yy)) and (len(xx) == len(zz)) and (len(xx) == len(param))
|
| 391 |
+
assert np.all(zz == 1)
|
| 392 |
+
|
| 393 |
+
s = Parametric3DLineSeries(cos(x), 1, x, (x, 0, 2 * pi))
|
| 394 |
+
xx, yy, zz, param = s.get_data()
|
| 395 |
+
assert (len(xx) == len(yy)) and (len(xx) == len(zz)) and (len(xx) == len(param))
|
| 396 |
+
assert np.all(yy == 1)
|
| 397 |
+
|
| 398 |
+
s = Parametric3DLineSeries(1, sin(x), x, (x, 0, 2 * pi))
|
| 399 |
+
xx, yy, zz, param = s.get_data()
|
| 400 |
+
assert (len(xx) == len(yy)) and (len(xx) == len(zz)) and (len(xx) == len(param))
|
| 401 |
+
assert np.all(xx == 1)
|
| 402 |
+
|
| 403 |
+
s = SurfaceOver2DRangeSeries(1, (x, -2, 2), (y, -3, 3))
|
| 404 |
+
xx, yy, zz = s.get_data()
|
| 405 |
+
assert (xx.shape == yy.shape) and (xx.shape == zz.shape)
|
| 406 |
+
assert np.all(zz == 1)
|
| 407 |
+
|
| 408 |
+
s = ParametricSurfaceSeries(1, x, y, (x, 0, 1), (y, 0, 1))
|
| 409 |
+
xx, yy, zz, uu, vv = s.get_data()
|
| 410 |
+
assert xx.shape == yy.shape == zz.shape == uu.shape == vv.shape
|
| 411 |
+
assert np.all(xx == 1)
|
| 412 |
+
|
| 413 |
+
s = ParametricSurfaceSeries(1, 1, y, (x, 0, 1), (y, 0, 1))
|
| 414 |
+
xx, yy, zz, uu, vv = s.get_data()
|
| 415 |
+
assert xx.shape == yy.shape == zz.shape == uu.shape == vv.shape
|
| 416 |
+
assert np.all(yy == 1)
|
| 417 |
+
|
| 418 |
+
s = ParametricSurfaceSeries(x, 1, 1, (x, 0, 1), (y, 0, 1))
|
| 419 |
+
xx, yy, zz, uu, vv = s.get_data()
|
| 420 |
+
assert xx.shape == yy.shape == zz.shape == uu.shape == vv.shape
|
| 421 |
+
assert np.all(zz == 1)
|
| 422 |
+
|
| 423 |
+
|
| 424 |
+
def test_only_integers():
|
| 425 |
+
if not np:
|
| 426 |
+
skip("numpy not installed.")
|
| 427 |
+
|
| 428 |
+
x, y, u, v = symbols("x, y, u, v")
|
| 429 |
+
|
| 430 |
+
s = LineOver1DRangeSeries(sin(x), (x, -5.5, 4.5), "",
|
| 431 |
+
adaptive=False, only_integers=True)
|
| 432 |
+
xx, _ = s.get_data()
|
| 433 |
+
assert len(xx) == 10
|
| 434 |
+
assert xx[0] == -5 and xx[-1] == 4
|
| 435 |
+
|
| 436 |
+
s = Parametric2DLineSeries(cos(x), sin(x), (x, 0, 2 * pi), "",
|
| 437 |
+
adaptive=False, only_integers=True)
|
| 438 |
+
_, _, p = s.get_data()
|
| 439 |
+
assert len(p) == 7
|
| 440 |
+
assert p[0] == 0 and p[-1] == 6
|
| 441 |
+
|
| 442 |
+
s = Parametric3DLineSeries(cos(x), sin(x), x, (x, 0, 2 * pi), "",
|
| 443 |
+
adaptive=False, only_integers=True)
|
| 444 |
+
_, _, _, p = s.get_data()
|
| 445 |
+
assert len(p) == 7
|
| 446 |
+
assert p[0] == 0 and p[-1] == 6
|
| 447 |
+
|
| 448 |
+
s = SurfaceOver2DRangeSeries(cos(x**2 + y**2), (x, -5.5, 5.5),
|
| 449 |
+
(y, -3.5, 3.5), "",
|
| 450 |
+
adaptive=False, only_integers=True)
|
| 451 |
+
xx, yy, _ = s.get_data()
|
| 452 |
+
assert xx.shape == yy.shape == (7, 11)
|
| 453 |
+
assert np.allclose(xx[:, 0] - (-5) * np.ones(7), 0)
|
| 454 |
+
assert np.allclose(xx[0, :] - np.linspace(-5, 5, 11), 0)
|
| 455 |
+
assert np.allclose(yy[:, 0] - np.linspace(-3, 3, 7), 0)
|
| 456 |
+
assert np.allclose(yy[0, :] - (-3) * np.ones(11), 0)
|
| 457 |
+
|
| 458 |
+
r = 2 + sin(7 * u + 5 * v)
|
| 459 |
+
expr = (
|
| 460 |
+
r * cos(u) * sin(v),
|
| 461 |
+
r * sin(u) * sin(v),
|
| 462 |
+
r * cos(v)
|
| 463 |
+
)
|
| 464 |
+
s = ParametricSurfaceSeries(*expr, (u, 0, 2 * pi), (v, 0, pi), "",
|
| 465 |
+
adaptive=False, only_integers=True)
|
| 466 |
+
xx, yy, zz, uu, vv = s.get_data()
|
| 467 |
+
assert xx.shape == yy.shape == zz.shape == uu.shape == vv.shape == (4, 7)
|
| 468 |
+
|
| 469 |
+
# only_integers also works with scalar expressions
|
| 470 |
+
s = LineOver1DRangeSeries(1, (x, -5.5, 4.5), "",
|
| 471 |
+
adaptive=False, only_integers=True)
|
| 472 |
+
xx, _ = s.get_data()
|
| 473 |
+
assert len(xx) == 10
|
| 474 |
+
assert xx[0] == -5 and xx[-1] == 4
|
| 475 |
+
|
| 476 |
+
s = Parametric2DLineSeries(cos(x), 1, (x, 0, 2 * pi), "",
|
| 477 |
+
adaptive=False, only_integers=True)
|
| 478 |
+
_, _, p = s.get_data()
|
| 479 |
+
assert len(p) == 7
|
| 480 |
+
assert p[0] == 0 and p[-1] == 6
|
| 481 |
+
|
| 482 |
+
s = SurfaceOver2DRangeSeries(1, (x, -5.5, 5.5), (y, -3.5, 3.5), "",
|
| 483 |
+
adaptive=False, only_integers=True)
|
| 484 |
+
xx, yy, _ = s.get_data()
|
| 485 |
+
assert xx.shape == yy.shape == (7, 11)
|
| 486 |
+
assert np.allclose(xx[:, 0] - (-5) * np.ones(7), 0)
|
| 487 |
+
assert np.allclose(xx[0, :] - np.linspace(-5, 5, 11), 0)
|
| 488 |
+
assert np.allclose(yy[:, 0] - np.linspace(-3, 3, 7), 0)
|
| 489 |
+
assert np.allclose(yy[0, :] - (-3) * np.ones(11), 0)
|
| 490 |
+
|
| 491 |
+
r = 2 + sin(7 * u + 5 * v)
|
| 492 |
+
expr = (
|
| 493 |
+
r * cos(u) * sin(v),
|
| 494 |
+
1,
|
| 495 |
+
r * cos(v)
|
| 496 |
+
)
|
| 497 |
+
s = ParametricSurfaceSeries(*expr, (u, 0, 2 * pi), (v, 0, pi), "",
|
| 498 |
+
adaptive=False, only_integers=True)
|
| 499 |
+
xx, yy, zz, uu, vv = s.get_data()
|
| 500 |
+
assert xx.shape == yy.shape == zz.shape == uu.shape == vv.shape == (4, 7)
|
| 501 |
+
|
| 502 |
+
|
| 503 |
+
def test_is_point_is_filled():
|
| 504 |
+
# verify that `is_point` and `is_filled` are attributes and that they
|
| 505 |
+
# they receive the correct values
|
| 506 |
+
if not np:
|
| 507 |
+
skip("numpy not installed.")
|
| 508 |
+
|
| 509 |
+
x, u = symbols("x, u")
|
| 510 |
+
|
| 511 |
+
s = LineOver1DRangeSeries(cos(x), (x, -5, 5), "",
|
| 512 |
+
is_point=False, is_filled=True)
|
| 513 |
+
assert (not s.is_point) and s.is_filled
|
| 514 |
+
s = LineOver1DRangeSeries(cos(x), (x, -5, 5), "",
|
| 515 |
+
is_point=True, is_filled=False)
|
| 516 |
+
assert s.is_point and (not s.is_filled)
|
| 517 |
+
|
| 518 |
+
s = List2DSeries([0, 1, 2], [3, 4, 5],
|
| 519 |
+
is_point=False, is_filled=True)
|
| 520 |
+
assert (not s.is_point) and s.is_filled
|
| 521 |
+
s = List2DSeries([0, 1, 2], [3, 4, 5],
|
| 522 |
+
is_point=True, is_filled=False)
|
| 523 |
+
assert s.is_point and (not s.is_filled)
|
| 524 |
+
|
| 525 |
+
s = Parametric2DLineSeries(cos(x), sin(x), (x, -5, 5),
|
| 526 |
+
is_point=False, is_filled=True)
|
| 527 |
+
assert (not s.is_point) and s.is_filled
|
| 528 |
+
s = Parametric2DLineSeries(cos(x), sin(x), (x, -5, 5),
|
| 529 |
+
is_point=True, is_filled=False)
|
| 530 |
+
assert s.is_point and (not s.is_filled)
|
| 531 |
+
|
| 532 |
+
s = Parametric3DLineSeries(cos(x), sin(x), x, (x, -5, 5),
|
| 533 |
+
is_point=False, is_filled=True)
|
| 534 |
+
assert (not s.is_point) and s.is_filled
|
| 535 |
+
s = Parametric3DLineSeries(cos(x), sin(x), x, (x, -5, 5),
|
| 536 |
+
is_point=True, is_filled=False)
|
| 537 |
+
assert s.is_point and (not s.is_filled)
|
| 538 |
+
|
| 539 |
+
|
| 540 |
+
def test_is_filled_2d():
|
| 541 |
+
# verify that the is_filled attribute is exposed by the following series
|
| 542 |
+
x, y = symbols("x, y")
|
| 543 |
+
|
| 544 |
+
expr = cos(x**2 + y**2)
|
| 545 |
+
ranges = (x, -2, 2), (y, -2, 2)
|
| 546 |
+
|
| 547 |
+
s = ContourSeries(expr, *ranges)
|
| 548 |
+
assert s.is_filled
|
| 549 |
+
s = ContourSeries(expr, *ranges, is_filled=True)
|
| 550 |
+
assert s.is_filled
|
| 551 |
+
s = ContourSeries(expr, *ranges, is_filled=False)
|
| 552 |
+
assert not s.is_filled
|
| 553 |
+
|
| 554 |
+
|
| 555 |
+
def test_steps():
|
| 556 |
+
if not np:
|
| 557 |
+
skip("numpy not installed.")
|
| 558 |
+
|
| 559 |
+
x, u = symbols("x, u")
|
| 560 |
+
|
| 561 |
+
def do_test(s1, s2):
|
| 562 |
+
if (not s1.is_parametric) and s1.is_2Dline:
|
| 563 |
+
xx1, _ = s1.get_data()
|
| 564 |
+
xx2, _ = s2.get_data()
|
| 565 |
+
elif s1.is_parametric and s1.is_2Dline:
|
| 566 |
+
xx1, _, _ = s1.get_data()
|
| 567 |
+
xx2, _, _ = s2.get_data()
|
| 568 |
+
elif (not s1.is_parametric) and s1.is_3Dline:
|
| 569 |
+
xx1, _, _ = s1.get_data()
|
| 570 |
+
xx2, _, _ = s2.get_data()
|
| 571 |
+
else:
|
| 572 |
+
xx1, _, _, _ = s1.get_data()
|
| 573 |
+
xx2, _, _, _ = s2.get_data()
|
| 574 |
+
assert len(xx1) != len(xx2)
|
| 575 |
+
|
| 576 |
+
s1 = LineOver1DRangeSeries(cos(x), (x, -5, 5), "",
|
| 577 |
+
adaptive=False, n=40, steps=False)
|
| 578 |
+
s2 = LineOver1DRangeSeries(cos(x), (x, -5, 5), "",
|
| 579 |
+
adaptive=False, n=40, steps=True)
|
| 580 |
+
do_test(s1, s2)
|
| 581 |
+
|
| 582 |
+
s1 = List2DSeries([0, 1, 2], [3, 4, 5], steps=False)
|
| 583 |
+
s2 = List2DSeries([0, 1, 2], [3, 4, 5], steps=True)
|
| 584 |
+
do_test(s1, s2)
|
| 585 |
+
|
| 586 |
+
s1 = Parametric2DLineSeries(cos(x), sin(x), (x, -5, 5),
|
| 587 |
+
adaptive=False, n=40, steps=False)
|
| 588 |
+
s2 = Parametric2DLineSeries(cos(x), sin(x), (x, -5, 5),
|
| 589 |
+
adaptive=False, n=40, steps=True)
|
| 590 |
+
do_test(s1, s2)
|
| 591 |
+
|
| 592 |
+
s1 = Parametric3DLineSeries(cos(x), sin(x), x, (x, -5, 5),
|
| 593 |
+
adaptive=False, n=40, steps=False)
|
| 594 |
+
s2 = Parametric3DLineSeries(cos(x), sin(x), x, (x, -5, 5),
|
| 595 |
+
adaptive=False, n=40, steps=True)
|
| 596 |
+
do_test(s1, s2)
|
| 597 |
+
|
| 598 |
+
|
| 599 |
+
def test_interactive_data():
|
| 600 |
+
# verify that InteractiveSeries produces the same numerical data as their
|
| 601 |
+
# corresponding non-interactive series.
|
| 602 |
+
if not np:
|
| 603 |
+
skip("numpy not installed.")
|
| 604 |
+
|
| 605 |
+
u, x, y, z = symbols("u, x:z")
|
| 606 |
+
|
| 607 |
+
def do_test(data1, data2):
|
| 608 |
+
assert len(data1) == len(data2)
|
| 609 |
+
for d1, d2 in zip(data1, data2):
|
| 610 |
+
assert np.allclose(d1, d2)
|
| 611 |
+
|
| 612 |
+
s1 = LineOver1DRangeSeries(u * cos(x), (x, -5, 5), params={u: 1}, n=50)
|
| 613 |
+
s2 = LineOver1DRangeSeries(cos(x), (x, -5, 5), adaptive=False, n=50)
|
| 614 |
+
do_test(s1.get_data(), s2.get_data())
|
| 615 |
+
|
| 616 |
+
s1 = Parametric2DLineSeries(
|
| 617 |
+
u * cos(x), u * sin(x), (x, -5, 5), params={u: 1}, n=50)
|
| 618 |
+
s2 = Parametric2DLineSeries(cos(x), sin(x), (x, -5, 5),
|
| 619 |
+
adaptive=False, n=50)
|
| 620 |
+
do_test(s1.get_data(), s2.get_data())
|
| 621 |
+
|
| 622 |
+
s1 = Parametric3DLineSeries(
|
| 623 |
+
u * cos(x), u * sin(x), u * x, (x, -5, 5),
|
| 624 |
+
params={u: 1}, n=50)
|
| 625 |
+
s2 = Parametric3DLineSeries(cos(x), sin(x), x, (x, -5, 5),
|
| 626 |
+
adaptive=False, n=50)
|
| 627 |
+
do_test(s1.get_data(), s2.get_data())
|
| 628 |
+
|
| 629 |
+
s1 = SurfaceOver2DRangeSeries(
|
| 630 |
+
u * cos(x ** 2 + y ** 2), (x, -3, 3), (y, -3, 3),
|
| 631 |
+
params={u: 1}, n1=50, n2=50,)
|
| 632 |
+
s2 = SurfaceOver2DRangeSeries(
|
| 633 |
+
cos(x ** 2 + y ** 2), (x, -3, 3), (y, -3, 3),
|
| 634 |
+
adaptive=False, n1=50, n2=50)
|
| 635 |
+
do_test(s1.get_data(), s2.get_data())
|
| 636 |
+
|
| 637 |
+
s1 = ParametricSurfaceSeries(
|
| 638 |
+
u * cos(x + y), sin(x + y), x - y, (x, -3, 3), (y, -3, 3),
|
| 639 |
+
params={u: 1}, n1=50, n2=50,)
|
| 640 |
+
s2 = ParametricSurfaceSeries(
|
| 641 |
+
cos(x + y), sin(x + y), x - y, (x, -3, 3), (y, -3, 3),
|
| 642 |
+
adaptive=False, n1=50, n2=50,)
|
| 643 |
+
do_test(s1.get_data(), s2.get_data())
|
| 644 |
+
|
| 645 |
+
# real part of a complex function evaluated over a real line with numpy
|
| 646 |
+
expr = re((z ** 2 + 1) / (z ** 2 - 1))
|
| 647 |
+
s1 = LineOver1DRangeSeries(u * expr, (z, -3, 3), adaptive=False, n=50,
|
| 648 |
+
modules=None, params={u: 1})
|
| 649 |
+
s2 = LineOver1DRangeSeries(expr, (z, -3, 3), adaptive=False, n=50,
|
| 650 |
+
modules=None)
|
| 651 |
+
do_test(s1.get_data(), s2.get_data())
|
| 652 |
+
|
| 653 |
+
# real part of a complex function evaluated over a real line with mpmath
|
| 654 |
+
expr = re((z ** 2 + 1) / (z ** 2 - 1))
|
| 655 |
+
s1 = LineOver1DRangeSeries(u * expr, (z, -3, 3), n=50, modules="mpmath",
|
| 656 |
+
params={u: 1})
|
| 657 |
+
s2 = LineOver1DRangeSeries(expr, (z, -3, 3),
|
| 658 |
+
adaptive=False, n=50, modules="mpmath")
|
| 659 |
+
do_test(s1.get_data(), s2.get_data())
|
| 660 |
+
|
| 661 |
+
|
| 662 |
+
def test_list2dseries_interactive():
|
| 663 |
+
if not np:
|
| 664 |
+
skip("numpy not installed.")
|
| 665 |
+
|
| 666 |
+
x, y, u = symbols("x, y, u")
|
| 667 |
+
|
| 668 |
+
s = List2DSeries([1, 2, 3], [1, 2, 3])
|
| 669 |
+
assert not s.is_interactive
|
| 670 |
+
|
| 671 |
+
# symbolic expressions as coordinates, but no ``params``
|
| 672 |
+
raises(ValueError, lambda: List2DSeries([cos(x)], [sin(x)]))
|
| 673 |
+
|
| 674 |
+
# too few parameters
|
| 675 |
+
raises(ValueError,
|
| 676 |
+
lambda: List2DSeries([cos(x), y], [sin(x), 2], params={u: 1}))
|
| 677 |
+
|
| 678 |
+
s = List2DSeries([cos(x)], [sin(x)], params={x: 1})
|
| 679 |
+
assert s.is_interactive
|
| 680 |
+
|
| 681 |
+
s = List2DSeries([x, 2, 3, 4], [4, 3, 2, x], params={x: 3})
|
| 682 |
+
xx, yy = s.get_data()
|
| 683 |
+
assert np.allclose(xx, [3, 2, 3, 4])
|
| 684 |
+
assert np.allclose(yy, [4, 3, 2, 3])
|
| 685 |
+
assert not s.is_parametric
|
| 686 |
+
|
| 687 |
+
# numeric lists + params is present -> interactive series and
|
| 688 |
+
# lists are converted to Tuple.
|
| 689 |
+
s = List2DSeries([1, 2, 3], [1, 2, 3], params={x: 1})
|
| 690 |
+
assert s.is_interactive
|
| 691 |
+
assert isinstance(s.list_x, Tuple)
|
| 692 |
+
assert isinstance(s.list_y, Tuple)
|
| 693 |
+
|
| 694 |
+
|
| 695 |
+
def test_mpmath():
|
| 696 |
+
# test that the argument of complex functions evaluated with mpmath
|
| 697 |
+
# might be different than the one computed with Numpy (different
|
| 698 |
+
# behaviour at branch cuts)
|
| 699 |
+
if not np:
|
| 700 |
+
skip("numpy not installed.")
|
| 701 |
+
|
| 702 |
+
z, u = symbols("z, u")
|
| 703 |
+
|
| 704 |
+
s1 = LineOver1DRangeSeries(im(sqrt(-z)), (z, 1e-03, 5),
|
| 705 |
+
adaptive=True, modules=None, force_real_eval=True)
|
| 706 |
+
s2 = LineOver1DRangeSeries(im(sqrt(-z)), (z, 1e-03, 5),
|
| 707 |
+
adaptive=True, modules="mpmath", force_real_eval=True)
|
| 708 |
+
xx1, yy1 = s1.get_data()
|
| 709 |
+
xx2, yy2 = s2.get_data()
|
| 710 |
+
assert np.all(yy1 < 0)
|
| 711 |
+
assert np.all(yy2 > 0)
|
| 712 |
+
|
| 713 |
+
s1 = LineOver1DRangeSeries(im(sqrt(-z)), (z, -5, 5),
|
| 714 |
+
adaptive=False, n=20, modules=None, force_real_eval=True)
|
| 715 |
+
s2 = LineOver1DRangeSeries(im(sqrt(-z)), (z, -5, 5),
|
| 716 |
+
adaptive=False, n=20, modules="mpmath", force_real_eval=True)
|
| 717 |
+
xx1, yy1 = s1.get_data()
|
| 718 |
+
xx2, yy2 = s2.get_data()
|
| 719 |
+
assert np.allclose(xx1, xx2)
|
| 720 |
+
assert not np.allclose(yy1, yy2)
|
| 721 |
+
|
| 722 |
+
|
| 723 |
+
def test_str():
|
| 724 |
+
u, x, y, z = symbols("u, x:z")
|
| 725 |
+
|
| 726 |
+
s = LineOver1DRangeSeries(cos(x), (x, -4, 3))
|
| 727 |
+
assert str(s) == "cartesian line: cos(x) for x over (-4.0, 3.0)"
|
| 728 |
+
|
| 729 |
+
d = {"return": "real"}
|
| 730 |
+
s = LineOver1DRangeSeries(cos(x), (x, -4, 3), **d)
|
| 731 |
+
assert str(s) == "cartesian line: re(cos(x)) for x over (-4.0, 3.0)"
|
| 732 |
+
|
| 733 |
+
d = {"return": "imag"}
|
| 734 |
+
s = LineOver1DRangeSeries(cos(x), (x, -4, 3), **d)
|
| 735 |
+
assert str(s) == "cartesian line: im(cos(x)) for x over (-4.0, 3.0)"
|
| 736 |
+
|
| 737 |
+
d = {"return": "abs"}
|
| 738 |
+
s = LineOver1DRangeSeries(cos(x), (x, -4, 3), **d)
|
| 739 |
+
assert str(s) == "cartesian line: abs(cos(x)) for x over (-4.0, 3.0)"
|
| 740 |
+
|
| 741 |
+
d = {"return": "arg"}
|
| 742 |
+
s = LineOver1DRangeSeries(cos(x), (x, -4, 3), **d)
|
| 743 |
+
assert str(s) == "cartesian line: arg(cos(x)) for x over (-4.0, 3.0)"
|
| 744 |
+
|
| 745 |
+
s = LineOver1DRangeSeries(cos(u * x), (x, -4, 3), params={u: 1})
|
| 746 |
+
assert str(s) == "interactive cartesian line: cos(u*x) for x over (-4.0, 3.0) and parameters (u,)"
|
| 747 |
+
|
| 748 |
+
s = LineOver1DRangeSeries(cos(u * x), (x, -u, 3*y), params={u: 1, y: 1})
|
| 749 |
+
assert str(s) == "interactive cartesian line: cos(u*x) for x over (-u, 3*y) and parameters (u, y)"
|
| 750 |
+
|
| 751 |
+
s = Parametric2DLineSeries(cos(x), sin(x), (x, -4, 3))
|
| 752 |
+
assert str(s) == "parametric cartesian line: (cos(x), sin(x)) for x over (-4.0, 3.0)"
|
| 753 |
+
|
| 754 |
+
s = Parametric2DLineSeries(cos(u * x), sin(x), (x, -4, 3), params={u: 1})
|
| 755 |
+
assert str(s) == "interactive parametric cartesian line: (cos(u*x), sin(x)) for x over (-4.0, 3.0) and parameters (u,)"
|
| 756 |
+
|
| 757 |
+
s = Parametric2DLineSeries(cos(u * x), sin(x), (x, -u, 3*y), params={u: 1, y:1})
|
| 758 |
+
assert str(s) == "interactive parametric cartesian line: (cos(u*x), sin(x)) for x over (-u, 3*y) and parameters (u, y)"
|
| 759 |
+
|
| 760 |
+
s = Parametric3DLineSeries(cos(x), sin(x), x, (x, -4, 3))
|
| 761 |
+
assert str(s) == "3D parametric cartesian line: (cos(x), sin(x), x) for x over (-4.0, 3.0)"
|
| 762 |
+
|
| 763 |
+
s = Parametric3DLineSeries(cos(u*x), sin(x), x, (x, -4, 3), params={u: 1})
|
| 764 |
+
assert str(s) == "interactive 3D parametric cartesian line: (cos(u*x), sin(x), x) for x over (-4.0, 3.0) and parameters (u,)"
|
| 765 |
+
|
| 766 |
+
s = Parametric3DLineSeries(cos(u*x), sin(x), x, (x, -u, 3*y), params={u: 1, y: 1})
|
| 767 |
+
assert str(s) == "interactive 3D parametric cartesian line: (cos(u*x), sin(x), x) for x over (-u, 3*y) and parameters (u, y)"
|
| 768 |
+
|
| 769 |
+
s = SurfaceOver2DRangeSeries(cos(x * y), (x, -4, 3), (y, -2, 5))
|
| 770 |
+
assert str(s) == "cartesian surface: cos(x*y) for x over (-4.0, 3.0) and y over (-2.0, 5.0)"
|
| 771 |
+
|
| 772 |
+
s = SurfaceOver2DRangeSeries(cos(u * x * y), (x, -4, 3), (y, -2, 5), params={u: 1})
|
| 773 |
+
assert str(s) == "interactive cartesian surface: cos(u*x*y) for x over (-4.0, 3.0) and y over (-2.0, 5.0) and parameters (u,)"
|
| 774 |
+
|
| 775 |
+
s = SurfaceOver2DRangeSeries(cos(u * x * y), (x, -4*u, 3), (y, -2, 5*u), params={u: 1})
|
| 776 |
+
assert str(s) == "interactive cartesian surface: cos(u*x*y) for x over (-4*u, 3.0) and y over (-2.0, 5*u) and parameters (u,)"
|
| 777 |
+
|
| 778 |
+
s = ContourSeries(cos(x * y), (x, -4, 3), (y, -2, 5))
|
| 779 |
+
assert str(s) == "contour: cos(x*y) for x over (-4.0, 3.0) and y over (-2.0, 5.0)"
|
| 780 |
+
|
| 781 |
+
s = ContourSeries(cos(u * x * y), (x, -4, 3), (y, -2, 5), params={u: 1})
|
| 782 |
+
assert str(s) == "interactive contour: cos(u*x*y) for x over (-4.0, 3.0) and y over (-2.0, 5.0) and parameters (u,)"
|
| 783 |
+
|
| 784 |
+
s = ParametricSurfaceSeries(cos(x * y), sin(x * y), x * y,
|
| 785 |
+
(x, -4, 3), (y, -2, 5))
|
| 786 |
+
assert str(s) == "parametric cartesian surface: (cos(x*y), sin(x*y), x*y) for x over (-4.0, 3.0) and y over (-2.0, 5.0)"
|
| 787 |
+
|
| 788 |
+
s = ParametricSurfaceSeries(cos(u * x * y), sin(x * y), x * y,
|
| 789 |
+
(x, -4, 3), (y, -2, 5), params={u: 1})
|
| 790 |
+
assert str(s) == "interactive parametric cartesian surface: (cos(u*x*y), sin(x*y), x*y) for x over (-4.0, 3.0) and y over (-2.0, 5.0) and parameters (u,)"
|
| 791 |
+
|
| 792 |
+
s = ImplicitSeries(x < y, (x, -5, 4), (y, -3, 2))
|
| 793 |
+
assert str(s) == "Implicit expression: x < y for x over (-5.0, 4.0) and y over (-3.0, 2.0)"
|
| 794 |
+
|
| 795 |
+
|
| 796 |
+
def test_use_cm():
|
| 797 |
+
# verify that the `use_cm` attribute is implemented.
|
| 798 |
+
if not np:
|
| 799 |
+
skip("numpy not installed.")
|
| 800 |
+
|
| 801 |
+
u, x, y, z = symbols("u, x:z")
|
| 802 |
+
|
| 803 |
+
s = List2DSeries([1, 2, 3, 4], [5, 6, 7, 8], use_cm=True)
|
| 804 |
+
assert s.use_cm
|
| 805 |
+
s = List2DSeries([1, 2, 3, 4], [5, 6, 7, 8], use_cm=False)
|
| 806 |
+
assert not s.use_cm
|
| 807 |
+
|
| 808 |
+
s = Parametric2DLineSeries(cos(x), sin(x), (x, -4, 3), use_cm=True)
|
| 809 |
+
assert s.use_cm
|
| 810 |
+
s = Parametric2DLineSeries(cos(x), sin(x), (x, -4, 3), use_cm=False)
|
| 811 |
+
assert not s.use_cm
|
| 812 |
+
|
| 813 |
+
s = Parametric3DLineSeries(cos(x), sin(x), x, (x, -4, 3),
|
| 814 |
+
use_cm=True)
|
| 815 |
+
assert s.use_cm
|
| 816 |
+
s = Parametric3DLineSeries(cos(x), sin(x), x, (x, -4, 3),
|
| 817 |
+
use_cm=False)
|
| 818 |
+
assert not s.use_cm
|
| 819 |
+
|
| 820 |
+
s = SurfaceOver2DRangeSeries(cos(x * y), (x, -4, 3), (y, -2, 5),
|
| 821 |
+
use_cm=True)
|
| 822 |
+
assert s.use_cm
|
| 823 |
+
s = SurfaceOver2DRangeSeries(cos(x * y), (x, -4, 3), (y, -2, 5),
|
| 824 |
+
use_cm=False)
|
| 825 |
+
assert not s.use_cm
|
| 826 |
+
|
| 827 |
+
s = ParametricSurfaceSeries(cos(x * y), sin(x * y), x * y,
|
| 828 |
+
(x, -4, 3), (y, -2, 5), use_cm=True)
|
| 829 |
+
assert s.use_cm
|
| 830 |
+
s = ParametricSurfaceSeries(cos(x * y), sin(x * y), x * y,
|
| 831 |
+
(x, -4, 3), (y, -2, 5), use_cm=False)
|
| 832 |
+
assert not s.use_cm
|
| 833 |
+
|
| 834 |
+
|
| 835 |
+
def test_surface_use_cm():
|
| 836 |
+
# verify that SurfaceOver2DRangeSeries and ParametricSurfaceSeries get
|
| 837 |
+
# the same value for use_cm
|
| 838 |
+
|
| 839 |
+
x, y, u, v = symbols("x, y, u, v")
|
| 840 |
+
|
| 841 |
+
# they read the same value from default settings
|
| 842 |
+
s1 = SurfaceOver2DRangeSeries(cos(x**2 + y**2), (x, -2, 2), (y, -2, 2))
|
| 843 |
+
s2 = ParametricSurfaceSeries(u * cos(v), u * sin(v), u,
|
| 844 |
+
(u, 0, 1), (v, 0 , 2*pi))
|
| 845 |
+
assert s1.use_cm == s2.use_cm
|
| 846 |
+
|
| 847 |
+
# they get the same value
|
| 848 |
+
s1 = SurfaceOver2DRangeSeries(cos(x**2 + y**2), (x, -2, 2), (y, -2, 2),
|
| 849 |
+
use_cm=False)
|
| 850 |
+
s2 = ParametricSurfaceSeries(u * cos(v), u * sin(v), u,
|
| 851 |
+
(u, 0, 1), (v, 0 , 2*pi), use_cm=False)
|
| 852 |
+
assert s1.use_cm == s2.use_cm
|
| 853 |
+
|
| 854 |
+
# they get the same value
|
| 855 |
+
s1 = SurfaceOver2DRangeSeries(cos(x**2 + y**2), (x, -2, 2), (y, -2, 2),
|
| 856 |
+
use_cm=True)
|
| 857 |
+
s2 = ParametricSurfaceSeries(u * cos(v), u * sin(v), u,
|
| 858 |
+
(u, 0, 1), (v, 0 , 2*pi), use_cm=True)
|
| 859 |
+
assert s1.use_cm == s2.use_cm
|
| 860 |
+
|
| 861 |
+
|
| 862 |
+
def test_sums():
|
| 863 |
+
# test that data series are able to deal with sums
|
| 864 |
+
if not np:
|
| 865 |
+
skip("numpy not installed.")
|
| 866 |
+
|
| 867 |
+
x, y, u = symbols("x, y, u")
|
| 868 |
+
|
| 869 |
+
def do_test(data1, data2):
|
| 870 |
+
assert len(data1) == len(data2)
|
| 871 |
+
for d1, d2 in zip(data1, data2):
|
| 872 |
+
assert np.allclose(d1, d2)
|
| 873 |
+
|
| 874 |
+
s = LineOver1DRangeSeries(Sum(1 / x ** y, (x, 1, 1000)), (y, 2, 10),
|
| 875 |
+
adaptive=False, only_integers=True)
|
| 876 |
+
xx, yy = s.get_data()
|
| 877 |
+
|
| 878 |
+
s1 = LineOver1DRangeSeries(Sum(1 / x, (x, 1, y)), (y, 2, 10),
|
| 879 |
+
adaptive=False, only_integers=True)
|
| 880 |
+
xx1, yy1 = s1.get_data()
|
| 881 |
+
|
| 882 |
+
s2 = LineOver1DRangeSeries(Sum(u / x, (x, 1, y)), (y, 2, 10),
|
| 883 |
+
params={u: 1}, only_integers=True)
|
| 884 |
+
xx2, yy2 = s2.get_data()
|
| 885 |
+
xx1 = xx1.astype(float)
|
| 886 |
+
xx2 = xx2.astype(float)
|
| 887 |
+
do_test([xx1, yy1], [xx2, yy2])
|
| 888 |
+
|
| 889 |
+
s = LineOver1DRangeSeries(Sum(1 / x, (x, 1, y)), (y, 2, 10),
|
| 890 |
+
adaptive=True)
|
| 891 |
+
with warns(
|
| 892 |
+
UserWarning,
|
| 893 |
+
match="The evaluation with NumPy/SciPy failed",
|
| 894 |
+
test_stacklevel=False,
|
| 895 |
+
):
|
| 896 |
+
raises(TypeError, lambda: s.get_data())
|
| 897 |
+
|
| 898 |
+
|
| 899 |
+
def test_apply_transforms():
|
| 900 |
+
# verify that transformation functions get applied to the output
|
| 901 |
+
# of data series
|
| 902 |
+
if not np:
|
| 903 |
+
skip("numpy not installed.")
|
| 904 |
+
|
| 905 |
+
x, y, z, u, v = symbols("x:z, u, v")
|
| 906 |
+
|
| 907 |
+
s1 = LineOver1DRangeSeries(cos(x), (x, -2*pi, 2*pi), adaptive=False, n=10)
|
| 908 |
+
s2 = LineOver1DRangeSeries(cos(x), (x, -2*pi, 2*pi), adaptive=False, n=10,
|
| 909 |
+
tx=np.rad2deg)
|
| 910 |
+
s3 = LineOver1DRangeSeries(cos(x), (x, -2*pi, 2*pi), adaptive=False, n=10,
|
| 911 |
+
ty=np.rad2deg)
|
| 912 |
+
s4 = LineOver1DRangeSeries(cos(x), (x, -2*pi, 2*pi), adaptive=False, n=10,
|
| 913 |
+
tx=np.rad2deg, ty=np.rad2deg)
|
| 914 |
+
|
| 915 |
+
x1, y1 = s1.get_data()
|
| 916 |
+
x2, y2 = s2.get_data()
|
| 917 |
+
x3, y3 = s3.get_data()
|
| 918 |
+
x4, y4 = s4.get_data()
|
| 919 |
+
assert np.isclose(x1[0], -2*np.pi) and np.isclose(x1[-1], 2*np.pi)
|
| 920 |
+
assert (y1.min() < -0.9) and (y1.max() > 0.9)
|
| 921 |
+
assert np.isclose(x2[0], -360) and np.isclose(x2[-1], 360)
|
| 922 |
+
assert (y2.min() < -0.9) and (y2.max() > 0.9)
|
| 923 |
+
assert np.isclose(x3[0], -2*np.pi) and np.isclose(x3[-1], 2*np.pi)
|
| 924 |
+
assert (y3.min() < -52) and (y3.max() > 52)
|
| 925 |
+
assert np.isclose(x4[0], -360) and np.isclose(x4[-1], 360)
|
| 926 |
+
assert (y4.min() < -52) and (y4.max() > 52)
|
| 927 |
+
|
| 928 |
+
xx = np.linspace(-2*np.pi, 2*np.pi, 10)
|
| 929 |
+
yy = np.cos(xx)
|
| 930 |
+
s1 = List2DSeries(xx, yy)
|
| 931 |
+
s2 = List2DSeries(xx, yy, tx=np.rad2deg, ty=np.rad2deg)
|
| 932 |
+
x1, y1 = s1.get_data()
|
| 933 |
+
x2, y2 = s2.get_data()
|
| 934 |
+
assert np.isclose(x1[0], -2*np.pi) and np.isclose(x1[-1], 2*np.pi)
|
| 935 |
+
assert (y1.min() < -0.9) and (y1.max() > 0.9)
|
| 936 |
+
assert np.isclose(x2[0], -360) and np.isclose(x2[-1], 360)
|
| 937 |
+
assert (y2.min() < -52) and (y2.max() > 52)
|
| 938 |
+
|
| 939 |
+
s1 = Parametric2DLineSeries(
|
| 940 |
+
sin(x), cos(x), (x, -pi, pi), adaptive=False, n=10)
|
| 941 |
+
s2 = Parametric2DLineSeries(
|
| 942 |
+
sin(x), cos(x), (x, -pi, pi), adaptive=False, n=10,
|
| 943 |
+
tx=np.rad2deg, ty=np.rad2deg, tp=np.rad2deg)
|
| 944 |
+
x1, y1, a1 = s1.get_data()
|
| 945 |
+
x2, y2, a2 = s2.get_data()
|
| 946 |
+
assert np.allclose(x1, np.deg2rad(x2))
|
| 947 |
+
assert np.allclose(y1, np.deg2rad(y2))
|
| 948 |
+
assert np.allclose(a1, np.deg2rad(a2))
|
| 949 |
+
|
| 950 |
+
s1 = Parametric3DLineSeries(
|
| 951 |
+
sin(x), cos(x), x, (x, -pi, pi), adaptive=False, n=10)
|
| 952 |
+
s2 = Parametric3DLineSeries(
|
| 953 |
+
sin(x), cos(x), x, (x, -pi, pi), adaptive=False, n=10, tp=np.rad2deg)
|
| 954 |
+
x1, y1, z1, a1 = s1.get_data()
|
| 955 |
+
x2, y2, z2, a2 = s2.get_data()
|
| 956 |
+
assert np.allclose(x1, x2)
|
| 957 |
+
assert np.allclose(y1, y2)
|
| 958 |
+
assert np.allclose(z1, z2)
|
| 959 |
+
assert np.allclose(a1, np.deg2rad(a2))
|
| 960 |
+
|
| 961 |
+
s1 = SurfaceOver2DRangeSeries(
|
| 962 |
+
cos(x**2 + y**2), (x, -2*pi, 2*pi), (y, -2*pi, 2*pi),
|
| 963 |
+
adaptive=False, n1=10, n2=10)
|
| 964 |
+
s2 = SurfaceOver2DRangeSeries(
|
| 965 |
+
cos(x**2 + y**2), (x, -2*pi, 2*pi), (y, -2*pi, 2*pi),
|
| 966 |
+
adaptive=False, n1=10, n2=10,
|
| 967 |
+
tx=np.rad2deg, ty=lambda x: 2*x, tz=lambda x: 3*x)
|
| 968 |
+
x1, y1, z1 = s1.get_data()
|
| 969 |
+
x2, y2, z2 = s2.get_data()
|
| 970 |
+
assert np.allclose(x1, np.deg2rad(x2))
|
| 971 |
+
assert np.allclose(y1, y2 / 2)
|
| 972 |
+
assert np.allclose(z1, z2 / 3)
|
| 973 |
+
|
| 974 |
+
s1 = ParametricSurfaceSeries(
|
| 975 |
+
u + v, u - v, u * v, (u, 0, 2*pi), (v, 0, pi),
|
| 976 |
+
adaptive=False, n1=10, n2=10)
|
| 977 |
+
s2 = ParametricSurfaceSeries(
|
| 978 |
+
u + v, u - v, u * v, (u, 0, 2*pi), (v, 0, pi),
|
| 979 |
+
adaptive=False, n1=10, n2=10,
|
| 980 |
+
tx=np.rad2deg, ty=lambda x: 2*x, tz=lambda x: 3*x)
|
| 981 |
+
x1, y1, z1, u1, v1 = s1.get_data()
|
| 982 |
+
x2, y2, z2, u2, v2 = s2.get_data()
|
| 983 |
+
assert np.allclose(x1, np.deg2rad(x2))
|
| 984 |
+
assert np.allclose(y1, y2 / 2)
|
| 985 |
+
assert np.allclose(z1, z2 / 3)
|
| 986 |
+
assert np.allclose(u1, u2)
|
| 987 |
+
assert np.allclose(v1, v2)
|
| 988 |
+
|
| 989 |
+
|
| 990 |
+
def test_series_labels():
|
| 991 |
+
# verify that series return the correct label, depending on the plot
|
| 992 |
+
# type and input arguments. If the user set custom label on a data series,
|
| 993 |
+
# it should returned un-modified.
|
| 994 |
+
if not np:
|
| 995 |
+
skip("numpy not installed.")
|
| 996 |
+
|
| 997 |
+
x, y, z, u, v = symbols("x, y, z, u, v")
|
| 998 |
+
wrapper = "$%s$"
|
| 999 |
+
|
| 1000 |
+
expr = cos(x)
|
| 1001 |
+
s1 = LineOver1DRangeSeries(expr, (x, -2, 2), None)
|
| 1002 |
+
s2 = LineOver1DRangeSeries(expr, (x, -2, 2), "test")
|
| 1003 |
+
assert s1.get_label(False) == str(expr)
|
| 1004 |
+
assert s1.get_label(True) == wrapper % latex(expr)
|
| 1005 |
+
assert s2.get_label(False) == "test"
|
| 1006 |
+
assert s2.get_label(True) == "test"
|
| 1007 |
+
|
| 1008 |
+
s1 = List2DSeries([0, 1, 2, 3], [0, 1, 2, 3], "test")
|
| 1009 |
+
assert s1.get_label(False) == "test"
|
| 1010 |
+
assert s1.get_label(True) == "test"
|
| 1011 |
+
|
| 1012 |
+
expr = (cos(x), sin(x))
|
| 1013 |
+
s1 = Parametric2DLineSeries(*expr, (x, -2, 2), None, use_cm=True)
|
| 1014 |
+
s2 = Parametric2DLineSeries(*expr, (x, -2, 2), "test", use_cm=True)
|
| 1015 |
+
s3 = Parametric2DLineSeries(*expr, (x, -2, 2), None, use_cm=False)
|
| 1016 |
+
s4 = Parametric2DLineSeries(*expr, (x, -2, 2), "test", use_cm=False)
|
| 1017 |
+
assert s1.get_label(False) == "x"
|
| 1018 |
+
assert s1.get_label(True) == wrapper % "x"
|
| 1019 |
+
assert s2.get_label(False) == "test"
|
| 1020 |
+
assert s2.get_label(True) == "test"
|
| 1021 |
+
assert s3.get_label(False) == str(expr)
|
| 1022 |
+
assert s3.get_label(True) == wrapper % latex(expr)
|
| 1023 |
+
assert s4.get_label(False) == "test"
|
| 1024 |
+
assert s4.get_label(True) == "test"
|
| 1025 |
+
|
| 1026 |
+
expr = (cos(x), sin(x), x)
|
| 1027 |
+
s1 = Parametric3DLineSeries(*expr, (x, -2, 2), None, use_cm=True)
|
| 1028 |
+
s2 = Parametric3DLineSeries(*expr, (x, -2, 2), "test", use_cm=True)
|
| 1029 |
+
s3 = Parametric3DLineSeries(*expr, (x, -2, 2), None, use_cm=False)
|
| 1030 |
+
s4 = Parametric3DLineSeries(*expr, (x, -2, 2), "test", use_cm=False)
|
| 1031 |
+
assert s1.get_label(False) == "x"
|
| 1032 |
+
assert s1.get_label(True) == wrapper % "x"
|
| 1033 |
+
assert s2.get_label(False) == "test"
|
| 1034 |
+
assert s2.get_label(True) == "test"
|
| 1035 |
+
assert s3.get_label(False) == str(expr)
|
| 1036 |
+
assert s3.get_label(True) == wrapper % latex(expr)
|
| 1037 |
+
assert s4.get_label(False) == "test"
|
| 1038 |
+
assert s4.get_label(True) == "test"
|
| 1039 |
+
|
| 1040 |
+
expr = cos(x**2 + y**2)
|
| 1041 |
+
s1 = SurfaceOver2DRangeSeries(expr, (x, -2, 2), (y, -2, 2), None)
|
| 1042 |
+
s2 = SurfaceOver2DRangeSeries(expr, (x, -2, 2), (y, -2, 2), "test")
|
| 1043 |
+
assert s1.get_label(False) == str(expr)
|
| 1044 |
+
assert s1.get_label(True) == wrapper % latex(expr)
|
| 1045 |
+
assert s2.get_label(False) == "test"
|
| 1046 |
+
assert s2.get_label(True) == "test"
|
| 1047 |
+
|
| 1048 |
+
expr = (cos(x - y), sin(x + y), x - y)
|
| 1049 |
+
s1 = ParametricSurfaceSeries(*expr, (x, -2, 2), (y, -2, 2), None)
|
| 1050 |
+
s2 = ParametricSurfaceSeries(*expr, (x, -2, 2), (y, -2, 2), "test")
|
| 1051 |
+
assert s1.get_label(False) == str(expr)
|
| 1052 |
+
assert s1.get_label(True) == wrapper % latex(expr)
|
| 1053 |
+
assert s2.get_label(False) == "test"
|
| 1054 |
+
assert s2.get_label(True) == "test"
|
| 1055 |
+
|
| 1056 |
+
expr = Eq(cos(x - y), 0)
|
| 1057 |
+
s1 = ImplicitSeries(expr, (x, -10, 10), (y, -10, 10), None)
|
| 1058 |
+
s2 = ImplicitSeries(expr, (x, -10, 10), (y, -10, 10), "test")
|
| 1059 |
+
assert s1.get_label(False) == str(expr)
|
| 1060 |
+
assert s1.get_label(True) == wrapper % latex(expr)
|
| 1061 |
+
assert s2.get_label(False) == "test"
|
| 1062 |
+
assert s2.get_label(True) == "test"
|
| 1063 |
+
|
| 1064 |
+
|
| 1065 |
+
def test_is_polar_2d_parametric():
|
| 1066 |
+
# verify that Parametric2DLineSeries isable to apply polar discretization,
|
| 1067 |
+
# which is used when polar_plot is executed with polar_axis=True
|
| 1068 |
+
if not np:
|
| 1069 |
+
skip("numpy not installed.")
|
| 1070 |
+
|
| 1071 |
+
t, u = symbols("t u")
|
| 1072 |
+
|
| 1073 |
+
# NOTE: a sufficiently big n must be provided, or else tests
|
| 1074 |
+
# are going to fail
|
| 1075 |
+
# No colormap
|
| 1076 |
+
f = sin(4 * t)
|
| 1077 |
+
s1 = Parametric2DLineSeries(f * cos(t), f * sin(t), (t, 0, 2*pi),
|
| 1078 |
+
adaptive=False, n=10, is_polar=False, use_cm=False)
|
| 1079 |
+
x1, y1, p1 = s1.get_data()
|
| 1080 |
+
s2 = Parametric2DLineSeries(f * cos(t), f * sin(t), (t, 0, 2*pi),
|
| 1081 |
+
adaptive=False, n=10, is_polar=True, use_cm=False)
|
| 1082 |
+
th, r, p2 = s2.get_data()
|
| 1083 |
+
assert (not np.allclose(x1, th)) and (not np.allclose(y1, r))
|
| 1084 |
+
assert np.allclose(p1, p2)
|
| 1085 |
+
|
| 1086 |
+
# With colormap
|
| 1087 |
+
s3 = Parametric2DLineSeries(f * cos(t), f * sin(t), (t, 0, 2*pi),
|
| 1088 |
+
adaptive=False, n=10, is_polar=False, color_func=lambda t: 2*t)
|
| 1089 |
+
x3, y3, p3 = s3.get_data()
|
| 1090 |
+
s4 = Parametric2DLineSeries(f * cos(t), f * sin(t), (t, 0, 2*pi),
|
| 1091 |
+
adaptive=False, n=10, is_polar=True, color_func=lambda t: 2*t)
|
| 1092 |
+
th4, r4, p4 = s4.get_data()
|
| 1093 |
+
assert np.allclose(p3, p4) and (not np.allclose(p1, p3))
|
| 1094 |
+
assert np.allclose(x3, x1) and np.allclose(y3, y1)
|
| 1095 |
+
assert np.allclose(th4, th) and np.allclose(r4, r)
|
| 1096 |
+
|
| 1097 |
+
|
| 1098 |
+
def test_is_polar_3d():
|
| 1099 |
+
# verify that SurfaceOver2DRangeSeries is able to apply
|
| 1100 |
+
# polar discretization
|
| 1101 |
+
if not np:
|
| 1102 |
+
skip("numpy not installed.")
|
| 1103 |
+
|
| 1104 |
+
x, y, t = symbols("x, y, t")
|
| 1105 |
+
expr = (x**2 - 1)**2
|
| 1106 |
+
s1 = SurfaceOver2DRangeSeries(expr, (x, 0, 1.5), (y, 0, 2 * pi),
|
| 1107 |
+
n=10, adaptive=False, is_polar=False)
|
| 1108 |
+
s2 = SurfaceOver2DRangeSeries(expr, (x, 0, 1.5), (y, 0, 2 * pi),
|
| 1109 |
+
n=10, adaptive=False, is_polar=True)
|
| 1110 |
+
x1, y1, z1 = s1.get_data()
|
| 1111 |
+
x2, y2, z2 = s2.get_data()
|
| 1112 |
+
x22, y22 = x1 * np.cos(y1), x1 * np.sin(y1)
|
| 1113 |
+
assert np.allclose(x2, x22)
|
| 1114 |
+
assert np.allclose(y2, y22)
|
| 1115 |
+
|
| 1116 |
+
|
| 1117 |
+
def test_color_func():
|
| 1118 |
+
# verify that eval_color_func produces the expected results in order to
|
| 1119 |
+
# maintain back compatibility with the old sympy.plotting module
|
| 1120 |
+
if not np:
|
| 1121 |
+
skip("numpy not installed.")
|
| 1122 |
+
|
| 1123 |
+
x, y, z, u, v = symbols("x, y, z, u, v")
|
| 1124 |
+
|
| 1125 |
+
# color func: returns x, y, color and s is parametric
|
| 1126 |
+
xx = np.linspace(-3, 3, 10)
|
| 1127 |
+
yy1 = np.cos(xx)
|
| 1128 |
+
s = List2DSeries(xx, yy1, color_func=lambda x, y: 2 * x, use_cm=True)
|
| 1129 |
+
xxs, yys, col = s.get_data()
|
| 1130 |
+
assert np.allclose(xx, xxs)
|
| 1131 |
+
assert np.allclose(yy1, yys)
|
| 1132 |
+
assert np.allclose(2 * xx, col)
|
| 1133 |
+
assert s.is_parametric
|
| 1134 |
+
|
| 1135 |
+
s = List2DSeries(xx, yy1, color_func=lambda x, y: 2 * x, use_cm=False)
|
| 1136 |
+
assert len(s.get_data()) == 2
|
| 1137 |
+
assert not s.is_parametric
|
| 1138 |
+
|
| 1139 |
+
s = Parametric2DLineSeries(cos(x), sin(x), (x, 0, 2*pi),
|
| 1140 |
+
adaptive=False, n=10, color_func=lambda t: t)
|
| 1141 |
+
xx, yy, col = s.get_data()
|
| 1142 |
+
assert (not np.allclose(xx, col)) and (not np.allclose(yy, col))
|
| 1143 |
+
s = Parametric2DLineSeries(cos(x), sin(x), (x, 0, 2*pi),
|
| 1144 |
+
adaptive=False, n=10, color_func=lambda x, y: x * y)
|
| 1145 |
+
xx, yy, col = s.get_data()
|
| 1146 |
+
assert np.allclose(col, xx * yy)
|
| 1147 |
+
s = Parametric2DLineSeries(cos(x), sin(x), (x, 0, 2*pi),
|
| 1148 |
+
adaptive=False, n=10, color_func=lambda x, y, t: x * y * t)
|
| 1149 |
+
xx, yy, col = s.get_data()
|
| 1150 |
+
assert np.allclose(col, xx * yy * np.linspace(0, 2*np.pi, 10))
|
| 1151 |
+
|
| 1152 |
+
s = Parametric3DLineSeries(cos(x), sin(x), x, (x, 0, 2*pi),
|
| 1153 |
+
adaptive=False, n=10, color_func=lambda t: t)
|
| 1154 |
+
xx, yy, zz, col = s.get_data()
|
| 1155 |
+
assert (not np.allclose(xx, col)) and (not np.allclose(yy, col))
|
| 1156 |
+
s = Parametric3DLineSeries(cos(x), sin(x), x, (x, 0, 2*pi),
|
| 1157 |
+
adaptive=False, n=10, color_func=lambda x, y, z: x * y * z)
|
| 1158 |
+
xx, yy, zz, col = s.get_data()
|
| 1159 |
+
assert np.allclose(col, xx * yy * zz)
|
| 1160 |
+
s = Parametric3DLineSeries(cos(x), sin(x), x, (x, 0, 2*pi),
|
| 1161 |
+
adaptive=False, n=10, color_func=lambda x, y, z, t: x * y * z * t)
|
| 1162 |
+
xx, yy, zz, col = s.get_data()
|
| 1163 |
+
assert np.allclose(col, xx * yy * zz * np.linspace(0, 2*np.pi, 10))
|
| 1164 |
+
|
| 1165 |
+
s = SurfaceOver2DRangeSeries(cos(x**2 + y**2), (x, -2, 2), (y, -2, 2),
|
| 1166 |
+
adaptive=False, n1=10, n2=10, color_func=lambda x: x)
|
| 1167 |
+
xx, yy, zz = s.get_data()
|
| 1168 |
+
col = s.eval_color_func(xx, yy, zz)
|
| 1169 |
+
assert np.allclose(xx, col)
|
| 1170 |
+
s = SurfaceOver2DRangeSeries(cos(x**2 + y**2), (x, -2, 2), (y, -2, 2),
|
| 1171 |
+
adaptive=False, n1=10, n2=10, color_func=lambda x, y: x * y)
|
| 1172 |
+
xx, yy, zz = s.get_data()
|
| 1173 |
+
col = s.eval_color_func(xx, yy, zz)
|
| 1174 |
+
assert np.allclose(xx * yy, col)
|
| 1175 |
+
s = SurfaceOver2DRangeSeries(cos(x**2 + y**2), (x, -2, 2), (y, -2, 2),
|
| 1176 |
+
adaptive=False, n1=10, n2=10, color_func=lambda x, y, z: x * y * z)
|
| 1177 |
+
xx, yy, zz = s.get_data()
|
| 1178 |
+
col = s.eval_color_func(xx, yy, zz)
|
| 1179 |
+
assert np.allclose(xx * yy * zz, col)
|
| 1180 |
+
|
| 1181 |
+
s = ParametricSurfaceSeries(1, x, y, (x, 0, 1), (y, 0, 1), adaptive=False,
|
| 1182 |
+
n1=10, n2=10, color_func=lambda u:u)
|
| 1183 |
+
xx, yy, zz, uu, vv = s.get_data()
|
| 1184 |
+
col = s.eval_color_func(xx, yy, zz, uu, vv)
|
| 1185 |
+
assert np.allclose(uu, col)
|
| 1186 |
+
s = ParametricSurfaceSeries(1, x, y, (x, 0, 1), (y, 0, 1), adaptive=False,
|
| 1187 |
+
n1=10, n2=10, color_func=lambda u, v: u * v)
|
| 1188 |
+
xx, yy, zz, uu, vv = s.get_data()
|
| 1189 |
+
col = s.eval_color_func(xx, yy, zz, uu, vv)
|
| 1190 |
+
assert np.allclose(uu * vv, col)
|
| 1191 |
+
s = ParametricSurfaceSeries(1, x, y, (x, 0, 1), (y, 0, 1), adaptive=False,
|
| 1192 |
+
n1=10, n2=10, color_func=lambda x, y, z: x * y * z)
|
| 1193 |
+
xx, yy, zz, uu, vv = s.get_data()
|
| 1194 |
+
col = s.eval_color_func(xx, yy, zz, uu, vv)
|
| 1195 |
+
assert np.allclose(xx * yy * zz, col)
|
| 1196 |
+
s = ParametricSurfaceSeries(1, x, y, (x, 0, 1), (y, 0, 1), adaptive=False,
|
| 1197 |
+
n1=10, n2=10, color_func=lambda x, y, z, u, v: x * y * z * u * v)
|
| 1198 |
+
xx, yy, zz, uu, vv = s.get_data()
|
| 1199 |
+
col = s.eval_color_func(xx, yy, zz, uu, vv)
|
| 1200 |
+
assert np.allclose(xx * yy * zz * uu * vv, col)
|
| 1201 |
+
|
| 1202 |
+
# Interactive Series
|
| 1203 |
+
s = List2DSeries([0, 1, 2, x], [x, 2, 3, 4],
|
| 1204 |
+
color_func=lambda x, y: 2 * x, params={x: 1}, use_cm=True)
|
| 1205 |
+
xx, yy, col = s.get_data()
|
| 1206 |
+
assert np.allclose(xx, [0, 1, 2, 1])
|
| 1207 |
+
assert np.allclose(yy, [1, 2, 3, 4])
|
| 1208 |
+
assert np.allclose(2 * xx, col)
|
| 1209 |
+
assert s.is_parametric and s.use_cm
|
| 1210 |
+
|
| 1211 |
+
s = List2DSeries([0, 1, 2, x], [x, 2, 3, 4],
|
| 1212 |
+
color_func=lambda x, y: 2 * x, params={x: 1}, use_cm=False)
|
| 1213 |
+
assert len(s.get_data()) == 2
|
| 1214 |
+
assert not s.is_parametric
|
| 1215 |
+
|
| 1216 |
+
|
| 1217 |
+
def test_color_func_scalar_val():
|
| 1218 |
+
# verify that eval_color_func returns a numpy array even when color_func
|
| 1219 |
+
# evaluates to a scalar value
|
| 1220 |
+
if not np:
|
| 1221 |
+
skip("numpy not installed.")
|
| 1222 |
+
|
| 1223 |
+
x, y = symbols("x, y")
|
| 1224 |
+
|
| 1225 |
+
s = Parametric2DLineSeries(cos(x), sin(x), (x, 0, 2*pi),
|
| 1226 |
+
adaptive=False, n=10, color_func=lambda t: 1)
|
| 1227 |
+
xx, yy, col = s.get_data()
|
| 1228 |
+
assert np.allclose(col, np.ones(xx.shape))
|
| 1229 |
+
|
| 1230 |
+
s = Parametric3DLineSeries(cos(x), sin(x), x, (x, 0, 2*pi),
|
| 1231 |
+
adaptive=False, n=10, color_func=lambda t: 1)
|
| 1232 |
+
xx, yy, zz, col = s.get_data()
|
| 1233 |
+
assert np.allclose(col, np.ones(xx.shape))
|
| 1234 |
+
|
| 1235 |
+
s = SurfaceOver2DRangeSeries(cos(x**2 + y**2), (x, -2, 2), (y, -2, 2),
|
| 1236 |
+
adaptive=False, n1=10, n2=10, color_func=lambda x: 1)
|
| 1237 |
+
xx, yy, zz = s.get_data()
|
| 1238 |
+
assert np.allclose(s.eval_color_func(xx), np.ones(xx.shape))
|
| 1239 |
+
|
| 1240 |
+
s = ParametricSurfaceSeries(1, x, y, (x, 0, 1), (y, 0, 1), adaptive=False,
|
| 1241 |
+
n1=10, n2=10, color_func=lambda u: 1)
|
| 1242 |
+
xx, yy, zz, uu, vv = s.get_data()
|
| 1243 |
+
col = s.eval_color_func(xx, yy, zz, uu, vv)
|
| 1244 |
+
assert np.allclose(col, np.ones(xx.shape))
|
| 1245 |
+
|
| 1246 |
+
|
| 1247 |
+
def test_color_func_expression():
|
| 1248 |
+
# verify that color_func is able to deal with instances of Expr: they will
|
| 1249 |
+
# be lambdified with the same signature used for the main expression.
|
| 1250 |
+
if not np:
|
| 1251 |
+
skip("numpy not installed.")
|
| 1252 |
+
|
| 1253 |
+
x, y = symbols("x, y")
|
| 1254 |
+
|
| 1255 |
+
s1 = Parametric2DLineSeries(cos(x), sin(x), (x, 0, 2*pi),
|
| 1256 |
+
color_func=sin(x), adaptive=False, n=10, use_cm=True)
|
| 1257 |
+
s2 = Parametric2DLineSeries(cos(x), sin(x), (x, 0, 2*pi),
|
| 1258 |
+
color_func=lambda x: np.cos(x), adaptive=False, n=10, use_cm=True)
|
| 1259 |
+
# the following statement should not raise errors
|
| 1260 |
+
d1 = s1.get_data()
|
| 1261 |
+
assert callable(s1.color_func)
|
| 1262 |
+
d2 = s2.get_data()
|
| 1263 |
+
assert not np.allclose(d1[-1], d2[-1])
|
| 1264 |
+
|
| 1265 |
+
s = SurfaceOver2DRangeSeries(cos(x**2 + y**2), (x, -pi, pi), (y, -pi, pi),
|
| 1266 |
+
color_func=sin(x**2 + y**2), adaptive=False, n1=5, n2=5)
|
| 1267 |
+
# the following statement should not raise errors
|
| 1268 |
+
s.get_data()
|
| 1269 |
+
assert callable(s.color_func)
|
| 1270 |
+
|
| 1271 |
+
xx = [1, 2, 3, 4, 5]
|
| 1272 |
+
yy = [1, 2, 3, 4, 5]
|
| 1273 |
+
raises(TypeError,
|
| 1274 |
+
lambda : List2DSeries(xx, yy, use_cm=True, color_func=sin(x)))
|
| 1275 |
+
|
| 1276 |
+
|
| 1277 |
+
def test_line_surface_color():
|
| 1278 |
+
# verify the back-compatibility with the old sympy.plotting module.
|
| 1279 |
+
# By setting line_color or surface_color to be a callable, it will set
|
| 1280 |
+
# the color_func attribute.
|
| 1281 |
+
|
| 1282 |
+
x, y, z = symbols("x, y, z")
|
| 1283 |
+
|
| 1284 |
+
s = LineOver1DRangeSeries(sin(x), (x, -5, 5), adaptive=False, n=10,
|
| 1285 |
+
line_color=lambda x: x)
|
| 1286 |
+
assert (s.line_color is None) and callable(s.color_func)
|
| 1287 |
+
|
| 1288 |
+
s = Parametric2DLineSeries(cos(x), sin(x), (x, 0, 2*pi),
|
| 1289 |
+
adaptive=False, n=10, line_color=lambda t: t)
|
| 1290 |
+
assert (s.line_color is None) and callable(s.color_func)
|
| 1291 |
+
|
| 1292 |
+
s = SurfaceOver2DRangeSeries(cos(x**2 + y**2), (x, -2, 2), (y, -2, 2),
|
| 1293 |
+
n1=10, n2=10, surface_color=lambda x: x)
|
| 1294 |
+
assert (s.surface_color is None) and callable(s.color_func)
|
| 1295 |
+
|
| 1296 |
+
|
| 1297 |
+
def test_complex_adaptive_false():
|
| 1298 |
+
# verify that series with adaptive=False is evaluated with discretized
|
| 1299 |
+
# ranges of type complex.
|
| 1300 |
+
if not np:
|
| 1301 |
+
skip("numpy not installed.")
|
| 1302 |
+
|
| 1303 |
+
x, y, u = symbols("x y u")
|
| 1304 |
+
|
| 1305 |
+
def do_test(data1, data2):
|
| 1306 |
+
assert len(data1) == len(data2)
|
| 1307 |
+
for d1, d2 in zip(data1, data2):
|
| 1308 |
+
assert np.allclose(d1, d2)
|
| 1309 |
+
|
| 1310 |
+
expr1 = sqrt(x) * exp(-x**2)
|
| 1311 |
+
expr2 = sqrt(u * x) * exp(-x**2)
|
| 1312 |
+
s1 = LineOver1DRangeSeries(im(expr1), (x, -5, 5), adaptive=False, n=10)
|
| 1313 |
+
s2 = LineOver1DRangeSeries(im(expr2), (x, -5, 5),
|
| 1314 |
+
adaptive=False, n=10, params={u: 1})
|
| 1315 |
+
data1 = s1.get_data()
|
| 1316 |
+
data2 = s2.get_data()
|
| 1317 |
+
|
| 1318 |
+
do_test(data1, data2)
|
| 1319 |
+
assert (not np.allclose(data1[1], 0)) and (not np.allclose(data2[1], 0))
|
| 1320 |
+
|
| 1321 |
+
s1 = Parametric2DLineSeries(re(expr1), im(expr1), (x, -pi, pi),
|
| 1322 |
+
adaptive=False, n=10)
|
| 1323 |
+
s2 = Parametric2DLineSeries(re(expr2), im(expr2), (x, -pi, pi),
|
| 1324 |
+
adaptive=False, n=10, params={u: 1})
|
| 1325 |
+
data1 = s1.get_data()
|
| 1326 |
+
data2 = s2.get_data()
|
| 1327 |
+
do_test(data1, data2)
|
| 1328 |
+
assert (not np.allclose(data1[1], 0)) and (not np.allclose(data2[1], 0))
|
| 1329 |
+
|
| 1330 |
+
s1 = SurfaceOver2DRangeSeries(im(expr1), (x, -5, 5), (y, -10, 10),
|
| 1331 |
+
adaptive=False, n1=30, n2=3)
|
| 1332 |
+
s2 = SurfaceOver2DRangeSeries(im(expr2), (x, -5, 5), (y, -10, 10),
|
| 1333 |
+
adaptive=False, n1=30, n2=3, params={u: 1})
|
| 1334 |
+
data1 = s1.get_data()
|
| 1335 |
+
data2 = s2.get_data()
|
| 1336 |
+
do_test(data1, data2)
|
| 1337 |
+
assert (not np.allclose(data1[1], 0)) and (not np.allclose(data2[1], 0))
|
| 1338 |
+
|
| 1339 |
+
|
| 1340 |
+
def test_expr_is_lambda_function():
|
| 1341 |
+
# verify that when a numpy function is provided, the series will be able
|
| 1342 |
+
# to evaluate it. Also, label should be empty in order to prevent some
|
| 1343 |
+
# backend from crashing.
|
| 1344 |
+
if not np:
|
| 1345 |
+
skip("numpy not installed.")
|
| 1346 |
+
|
| 1347 |
+
f = lambda x: np.cos(x)
|
| 1348 |
+
s1 = LineOver1DRangeSeries(f, ("x", -5, 5), adaptive=True, depth=3)
|
| 1349 |
+
s1.get_data()
|
| 1350 |
+
s2 = LineOver1DRangeSeries(f, ("x", -5, 5), adaptive=False, n=10)
|
| 1351 |
+
s2.get_data()
|
| 1352 |
+
assert s1.label == s2.label == ""
|
| 1353 |
+
|
| 1354 |
+
fx = lambda x: np.cos(x)
|
| 1355 |
+
fy = lambda x: np.sin(x)
|
| 1356 |
+
s1 = Parametric2DLineSeries(fx, fy, ("x", 0, 2*pi),
|
| 1357 |
+
adaptive=True, adaptive_goal=0.1)
|
| 1358 |
+
s1.get_data()
|
| 1359 |
+
s2 = Parametric2DLineSeries(fx, fy, ("x", 0, 2*pi),
|
| 1360 |
+
adaptive=False, n=10)
|
| 1361 |
+
s2.get_data()
|
| 1362 |
+
assert s1.label == s2.label == ""
|
| 1363 |
+
|
| 1364 |
+
fz = lambda x: x
|
| 1365 |
+
s1 = Parametric3DLineSeries(fx, fy, fz, ("x", 0, 2*pi),
|
| 1366 |
+
adaptive=True, adaptive_goal=0.1)
|
| 1367 |
+
s1.get_data()
|
| 1368 |
+
s2 = Parametric3DLineSeries(fx, fy, fz, ("x", 0, 2*pi),
|
| 1369 |
+
adaptive=False, n=10)
|
| 1370 |
+
s2.get_data()
|
| 1371 |
+
assert s1.label == s2.label == ""
|
| 1372 |
+
|
| 1373 |
+
f = lambda x, y: np.cos(x**2 + y**2)
|
| 1374 |
+
s1 = SurfaceOver2DRangeSeries(f, ("a", -2, 2), ("b", -3, 3),
|
| 1375 |
+
adaptive=False, n1=10, n2=10)
|
| 1376 |
+
s1.get_data()
|
| 1377 |
+
s2 = ContourSeries(f, ("a", -2, 2), ("b", -3, 3),
|
| 1378 |
+
adaptive=False, n1=10, n2=10)
|
| 1379 |
+
s2.get_data()
|
| 1380 |
+
assert s1.label == s2.label == ""
|
| 1381 |
+
|
| 1382 |
+
fx = lambda u, v: np.cos(u + v)
|
| 1383 |
+
fy = lambda u, v: np.sin(u - v)
|
| 1384 |
+
fz = lambda u, v: u * v
|
| 1385 |
+
s1 = ParametricSurfaceSeries(fx, fy, fz, ("u", 0, pi), ("v", 0, 2*pi),
|
| 1386 |
+
adaptive=False, n1=10, n2=10)
|
| 1387 |
+
s1.get_data()
|
| 1388 |
+
assert s1.label == ""
|
| 1389 |
+
|
| 1390 |
+
raises(TypeError, lambda: List2DSeries(lambda t: t, lambda t: t))
|
| 1391 |
+
raises(TypeError, lambda : ImplicitSeries(lambda t: np.sin(t),
|
| 1392 |
+
("x", -5, 5), ("y", -6, 6)))
|
| 1393 |
+
|
| 1394 |
+
|
| 1395 |
+
def test_show_in_legend_lines():
|
| 1396 |
+
# verify that lines series correctly set the show_in_legend attribute
|
| 1397 |
+
x, u = symbols("x, u")
|
| 1398 |
+
|
| 1399 |
+
s = LineOver1DRangeSeries(cos(x), (x, -2, 2), "test", show_in_legend=True)
|
| 1400 |
+
assert s.show_in_legend
|
| 1401 |
+
s = LineOver1DRangeSeries(cos(x), (x, -2, 2), "test", show_in_legend=False)
|
| 1402 |
+
assert not s.show_in_legend
|
| 1403 |
+
|
| 1404 |
+
s = Parametric2DLineSeries(cos(x), sin(x), (x, 0, 1), "test",
|
| 1405 |
+
show_in_legend=True)
|
| 1406 |
+
assert s.show_in_legend
|
| 1407 |
+
s = Parametric2DLineSeries(cos(x), sin(x), (x, 0, 1), "test",
|
| 1408 |
+
show_in_legend=False)
|
| 1409 |
+
assert not s.show_in_legend
|
| 1410 |
+
|
| 1411 |
+
s = Parametric3DLineSeries(cos(x), sin(x), x, (x, 0, 1), "test",
|
| 1412 |
+
show_in_legend=True)
|
| 1413 |
+
assert s.show_in_legend
|
| 1414 |
+
s = Parametric3DLineSeries(cos(x), sin(x), x, (x, 0, 1), "test",
|
| 1415 |
+
show_in_legend=False)
|
| 1416 |
+
assert not s.show_in_legend
|
| 1417 |
+
|
| 1418 |
+
|
| 1419 |
+
@XFAIL
|
| 1420 |
+
def test_particular_case_1_with_adaptive_true():
|
| 1421 |
+
# Verify that symbolic expressions and numerical lambda functions are
|
| 1422 |
+
# evaluated with the same algorithm.
|
| 1423 |
+
if not np:
|
| 1424 |
+
skip("numpy not installed.")
|
| 1425 |
+
|
| 1426 |
+
# NOTE: xfail because sympy's adaptive algorithm is not deterministic
|
| 1427 |
+
|
| 1428 |
+
def do_test(a, b):
|
| 1429 |
+
with warns(
|
| 1430 |
+
RuntimeWarning,
|
| 1431 |
+
match="invalid value encountered in scalar power",
|
| 1432 |
+
test_stacklevel=False,
|
| 1433 |
+
):
|
| 1434 |
+
d1 = a.get_data()
|
| 1435 |
+
d2 = b.get_data()
|
| 1436 |
+
for t, v in zip(d1, d2):
|
| 1437 |
+
assert np.allclose(t, v)
|
| 1438 |
+
|
| 1439 |
+
n = symbols("n")
|
| 1440 |
+
a = S(2) / 3
|
| 1441 |
+
epsilon = 0.01
|
| 1442 |
+
xn = (n**3 + n**2)**(S(1)/3) - (n**3 - n**2)**(S(1)/3)
|
| 1443 |
+
expr = Abs(xn - a) - epsilon
|
| 1444 |
+
math_func = lambdify([n], expr)
|
| 1445 |
+
s1 = LineOver1DRangeSeries(expr, (n, -10, 10), "",
|
| 1446 |
+
adaptive=True, depth=3)
|
| 1447 |
+
s2 = LineOver1DRangeSeries(math_func, ("n", -10, 10), "",
|
| 1448 |
+
adaptive=True, depth=3)
|
| 1449 |
+
do_test(s1, s2)
|
| 1450 |
+
|
| 1451 |
+
|
| 1452 |
+
def test_particular_case_1_with_adaptive_false():
|
| 1453 |
+
# Verify that symbolic expressions and numerical lambda functions are
|
| 1454 |
+
# evaluated with the same algorithm. In particular, uniform evaluation
|
| 1455 |
+
# is going to use np.vectorize, which correctly evaluates the following
|
| 1456 |
+
# mathematical function.
|
| 1457 |
+
if not np:
|
| 1458 |
+
skip("numpy not installed.")
|
| 1459 |
+
|
| 1460 |
+
def do_test(a, b):
|
| 1461 |
+
d1 = a.get_data()
|
| 1462 |
+
d2 = b.get_data()
|
| 1463 |
+
for t, v in zip(d1, d2):
|
| 1464 |
+
assert np.allclose(t, v)
|
| 1465 |
+
|
| 1466 |
+
n = symbols("n")
|
| 1467 |
+
a = S(2) / 3
|
| 1468 |
+
epsilon = 0.01
|
| 1469 |
+
xn = (n**3 + n**2)**(S(1)/3) - (n**3 - n**2)**(S(1)/3)
|
| 1470 |
+
expr = Abs(xn - a) - epsilon
|
| 1471 |
+
math_func = lambdify([n], expr)
|
| 1472 |
+
|
| 1473 |
+
s3 = LineOver1DRangeSeries(expr, (n, -10, 10), "",
|
| 1474 |
+
adaptive=False, n=10)
|
| 1475 |
+
s4 = LineOver1DRangeSeries(math_func, ("n", -10, 10), "",
|
| 1476 |
+
adaptive=False, n=10)
|
| 1477 |
+
do_test(s3, s4)
|
| 1478 |
+
|
| 1479 |
+
|
| 1480 |
+
def test_complex_params_number_eval():
|
| 1481 |
+
# The main expression contains terms like sqrt(xi - 1), with
|
| 1482 |
+
# parameter (0 <= xi <= 1).
|
| 1483 |
+
# There shouldn't be any NaN values on the output.
|
| 1484 |
+
if not np:
|
| 1485 |
+
skip("numpy not installed.")
|
| 1486 |
+
|
| 1487 |
+
xi, wn, x0, v0, t = symbols("xi, omega_n, x0, v0, t")
|
| 1488 |
+
x = Function("x")(t)
|
| 1489 |
+
eq = x.diff(t, 2) + 2 * xi * wn * x.diff(t) + wn**2 * x
|
| 1490 |
+
sol = dsolve(eq, x, ics={x.subs(t, 0): x0, x.diff(t).subs(t, 0): v0})
|
| 1491 |
+
params = {
|
| 1492 |
+
wn: 0.5,
|
| 1493 |
+
xi: 0.25,
|
| 1494 |
+
x0: 0.45,
|
| 1495 |
+
v0: 0.0
|
| 1496 |
+
}
|
| 1497 |
+
s = LineOver1DRangeSeries(sol.rhs, (t, 0, 100), adaptive=False, n=5,
|
| 1498 |
+
params=params)
|
| 1499 |
+
x, y = s.get_data()
|
| 1500 |
+
assert not np.isnan(x).any()
|
| 1501 |
+
assert not np.isnan(y).any()
|
| 1502 |
+
|
| 1503 |
+
|
| 1504 |
+
# Fourier Series of a sawtooth wave
|
| 1505 |
+
# The main expression contains a Sum with a symbolic upper range.
|
| 1506 |
+
# The lambdified code looks like:
|
| 1507 |
+
# sum(blablabla for for n in range(1, m+1))
|
| 1508 |
+
# But range requires integer numbers, whereas per above example, the series
|
| 1509 |
+
# casts parameters to complex. Verify that the series is able to detect
|
| 1510 |
+
# upper bounds in summations and cast it to int in order to get successful
|
| 1511 |
+
# evaluation
|
| 1512 |
+
x, T, n, m = symbols("x, T, n, m")
|
| 1513 |
+
fs = S(1) / 2 - (1 / pi) * Sum(sin(2 * n * pi * x / T) / n, (n, 1, m))
|
| 1514 |
+
params = {
|
| 1515 |
+
T: 4.5,
|
| 1516 |
+
m: 5
|
| 1517 |
+
}
|
| 1518 |
+
s = LineOver1DRangeSeries(fs, (x, 0, 10), adaptive=False, n=5,
|
| 1519 |
+
params=params)
|
| 1520 |
+
x, y = s.get_data()
|
| 1521 |
+
assert not np.isnan(x).any()
|
| 1522 |
+
assert not np.isnan(y).any()
|
| 1523 |
+
|
| 1524 |
+
|
| 1525 |
+
def test_complex_range_line_plot_1():
|
| 1526 |
+
# verify that univariate functions are evaluated with a complex
|
| 1527 |
+
# data range (with zero imaginary part). There shouldn't be any
|
| 1528 |
+
# NaN value in the output.
|
| 1529 |
+
if not np:
|
| 1530 |
+
skip("numpy not installed.")
|
| 1531 |
+
|
| 1532 |
+
x, u = symbols("x, u")
|
| 1533 |
+
expr1 = im(sqrt(x) * exp(-x**2))
|
| 1534 |
+
expr2 = im(sqrt(u * x) * exp(-x**2))
|
| 1535 |
+
s1 = LineOver1DRangeSeries(expr1, (x, -10, 10), adaptive=True,
|
| 1536 |
+
adaptive_goal=0.1)
|
| 1537 |
+
s2 = LineOver1DRangeSeries(expr1, (x, -10, 10), adaptive=False, n=30)
|
| 1538 |
+
s3 = LineOver1DRangeSeries(expr2, (x, -10, 10), adaptive=False, n=30,
|
| 1539 |
+
params={u: 1})
|
| 1540 |
+
|
| 1541 |
+
with ignore_warnings(RuntimeWarning):
|
| 1542 |
+
data1 = s1.get_data()
|
| 1543 |
+
data2 = s2.get_data()
|
| 1544 |
+
data3 = s3.get_data()
|
| 1545 |
+
|
| 1546 |
+
assert not np.isnan(data1[1]).any()
|
| 1547 |
+
assert not np.isnan(data2[1]).any()
|
| 1548 |
+
assert not np.isnan(data3[1]).any()
|
| 1549 |
+
assert np.allclose(data2[0], data3[0]) and np.allclose(data2[1], data3[1])
|
| 1550 |
+
|
| 1551 |
+
|
| 1552 |
+
@XFAIL
|
| 1553 |
+
def test_complex_range_line_plot_2():
|
| 1554 |
+
# verify that univariate functions are evaluated with a complex
|
| 1555 |
+
# data range (with non-zero imaginary part). There shouldn't be any
|
| 1556 |
+
# NaN value in the output.
|
| 1557 |
+
if not np:
|
| 1558 |
+
skip("numpy not installed.")
|
| 1559 |
+
|
| 1560 |
+
# NOTE: xfail because sympy's adaptive algorithm is unable to deal with
|
| 1561 |
+
# complex number.
|
| 1562 |
+
|
| 1563 |
+
x, u = symbols("x, u")
|
| 1564 |
+
|
| 1565 |
+
# adaptive and uniform meshing should produce the same data.
|
| 1566 |
+
# because of the adaptive nature, just compare the first and last points
|
| 1567 |
+
# of both series.
|
| 1568 |
+
s1 = LineOver1DRangeSeries(abs(sqrt(x)), (x, -5-2j, 5-2j), adaptive=True)
|
| 1569 |
+
s2 = LineOver1DRangeSeries(abs(sqrt(x)), (x, -5-2j, 5-2j), adaptive=False,
|
| 1570 |
+
n=10)
|
| 1571 |
+
with warns(
|
| 1572 |
+
RuntimeWarning,
|
| 1573 |
+
match="invalid value encountered in sqrt",
|
| 1574 |
+
test_stacklevel=False,
|
| 1575 |
+
):
|
| 1576 |
+
d1 = s1.get_data()
|
| 1577 |
+
d2 = s2.get_data()
|
| 1578 |
+
xx1 = [d1[0][0], d1[0][-1]]
|
| 1579 |
+
xx2 = [d2[0][0], d2[0][-1]]
|
| 1580 |
+
yy1 = [d1[1][0], d1[1][-1]]
|
| 1581 |
+
yy2 = [d2[1][0], d2[1][-1]]
|
| 1582 |
+
assert np.allclose(xx1, xx2)
|
| 1583 |
+
assert np.allclose(yy1, yy2)
|
| 1584 |
+
|
| 1585 |
+
|
| 1586 |
+
def test_force_real_eval():
|
| 1587 |
+
# verify that force_real_eval=True produces inconsistent results when
|
| 1588 |
+
# compared with evaluation of complex domain.
|
| 1589 |
+
if not np:
|
| 1590 |
+
skip("numpy not installed.")
|
| 1591 |
+
|
| 1592 |
+
x = symbols("x")
|
| 1593 |
+
|
| 1594 |
+
expr = im(sqrt(x) * exp(-x**2))
|
| 1595 |
+
s1 = LineOver1DRangeSeries(expr, (x, -10, 10), adaptive=False, n=10,
|
| 1596 |
+
force_real_eval=False)
|
| 1597 |
+
s2 = LineOver1DRangeSeries(expr, (x, -10, 10), adaptive=False, n=10,
|
| 1598 |
+
force_real_eval=True)
|
| 1599 |
+
d1 = s1.get_data()
|
| 1600 |
+
with ignore_warnings(RuntimeWarning):
|
| 1601 |
+
d2 = s2.get_data()
|
| 1602 |
+
assert not np.allclose(d1[1], 0)
|
| 1603 |
+
assert np.allclose(d2[1], 0)
|
| 1604 |
+
|
| 1605 |
+
|
| 1606 |
+
def test_contour_series_show_clabels():
|
| 1607 |
+
# verify that a contour series has the abiliy to set the visibility of
|
| 1608 |
+
# labels to contour lines
|
| 1609 |
+
|
| 1610 |
+
x, y = symbols("x, y")
|
| 1611 |
+
s = ContourSeries(cos(x*y), (x, -2, 2), (y, -2, 2))
|
| 1612 |
+
assert s.show_clabels
|
| 1613 |
+
|
| 1614 |
+
s = ContourSeries(cos(x*y), (x, -2, 2), (y, -2, 2), clabels=True)
|
| 1615 |
+
assert s.show_clabels
|
| 1616 |
+
|
| 1617 |
+
s = ContourSeries(cos(x*y), (x, -2, 2), (y, -2, 2), clabels=False)
|
| 1618 |
+
assert not s.show_clabels
|
| 1619 |
+
|
| 1620 |
+
|
| 1621 |
+
def test_LineOver1DRangeSeries_complex_range():
|
| 1622 |
+
# verify that LineOver1DRangeSeries can accept a complex range
|
| 1623 |
+
# if the imaginary part of the start and end values are the same
|
| 1624 |
+
|
| 1625 |
+
x = symbols("x")
|
| 1626 |
+
|
| 1627 |
+
LineOver1DRangeSeries(sqrt(x), (x, -10, 10))
|
| 1628 |
+
LineOver1DRangeSeries(sqrt(x), (x, -10-2j, 10-2j))
|
| 1629 |
+
raises(ValueError,
|
| 1630 |
+
lambda : LineOver1DRangeSeries(sqrt(x), (x, -10-2j, 10+2j)))
|
| 1631 |
+
|
| 1632 |
+
|
| 1633 |
+
def test_symbolic_plotting_ranges():
|
| 1634 |
+
# verify that data series can use symbolic plotting ranges
|
| 1635 |
+
if not np:
|
| 1636 |
+
skip("numpy not installed.")
|
| 1637 |
+
|
| 1638 |
+
x, y, z, a, b = symbols("x, y, z, a, b")
|
| 1639 |
+
|
| 1640 |
+
def do_test(s1, s2, new_params):
|
| 1641 |
+
d1 = s1.get_data()
|
| 1642 |
+
d2 = s2.get_data()
|
| 1643 |
+
for u, v in zip(d1, d2):
|
| 1644 |
+
assert np.allclose(u, v)
|
| 1645 |
+
s2.params = new_params
|
| 1646 |
+
d2 = s2.get_data()
|
| 1647 |
+
for u, v in zip(d1, d2):
|
| 1648 |
+
assert not np.allclose(u, v)
|
| 1649 |
+
|
| 1650 |
+
s1 = LineOver1DRangeSeries(sin(x), (x, 0, 1), adaptive=False, n=10)
|
| 1651 |
+
s2 = LineOver1DRangeSeries(sin(x), (x, a, b), params={a: 0, b: 1},
|
| 1652 |
+
adaptive=False, n=10)
|
| 1653 |
+
do_test(s1, s2, {a: 0.5, b: 1.5})
|
| 1654 |
+
|
| 1655 |
+
# missing a parameter
|
| 1656 |
+
raises(ValueError,
|
| 1657 |
+
lambda : LineOver1DRangeSeries(sin(x), (x, a, b), params={a: 1}, n=10))
|
| 1658 |
+
|
| 1659 |
+
s1 = Parametric2DLineSeries(cos(x), sin(x), (x, 0, 1), adaptive=False, n=10)
|
| 1660 |
+
s2 = Parametric2DLineSeries(cos(x), sin(x), (x, a, b), params={a: 0, b: 1},
|
| 1661 |
+
adaptive=False, n=10)
|
| 1662 |
+
do_test(s1, s2, {a: 0.5, b: 1.5})
|
| 1663 |
+
|
| 1664 |
+
# missing a parameter
|
| 1665 |
+
raises(ValueError,
|
| 1666 |
+
lambda : Parametric2DLineSeries(cos(x), sin(x), (x, a, b),
|
| 1667 |
+
params={a: 0}, adaptive=False, n=10))
|
| 1668 |
+
|
| 1669 |
+
s1 = Parametric3DLineSeries(cos(x), sin(x), x, (x, 0, 1),
|
| 1670 |
+
adaptive=False, n=10)
|
| 1671 |
+
s2 = Parametric3DLineSeries(cos(x), sin(x), x, (x, a, b),
|
| 1672 |
+
params={a: 0, b: 1}, adaptive=False, n=10)
|
| 1673 |
+
do_test(s1, s2, {a: 0.5, b: 1.5})
|
| 1674 |
+
|
| 1675 |
+
# missing a parameter
|
| 1676 |
+
raises(ValueError,
|
| 1677 |
+
lambda : Parametric3DLineSeries(cos(x), sin(x), x, (x, a, b),
|
| 1678 |
+
params={a: 0}, adaptive=False, n=10))
|
| 1679 |
+
|
| 1680 |
+
s1 = SurfaceOver2DRangeSeries(cos(x**2 + y**2), (x, -pi, pi), (y, -pi, pi),
|
| 1681 |
+
adaptive=False, n1=5, n2=5)
|
| 1682 |
+
s2 = SurfaceOver2DRangeSeries(cos(x**2 + y**2), (x, -pi * a, pi * a),
|
| 1683 |
+
(y, -pi * b, pi * b), params={a: 1, b: 1},
|
| 1684 |
+
adaptive=False, n1=5, n2=5)
|
| 1685 |
+
do_test(s1, s2, {a: 0.5, b: 1.5})
|
| 1686 |
+
|
| 1687 |
+
# missing a parameter
|
| 1688 |
+
raises(ValueError,
|
| 1689 |
+
lambda : SurfaceOver2DRangeSeries(cos(x**2 + y**2),
|
| 1690 |
+
(x, -pi * a, pi * a), (y, -pi * b, pi * b), params={a: 1},
|
| 1691 |
+
adaptive=False, n1=5, n2=5))
|
| 1692 |
+
# one range symbol is included into another range's minimum or maximum val
|
| 1693 |
+
raises(ValueError,
|
| 1694 |
+
lambda : SurfaceOver2DRangeSeries(cos(x**2 + y**2),
|
| 1695 |
+
(x, -pi * a + y, pi * a), (y, -pi * b, pi * b), params={a: 1},
|
| 1696 |
+
adaptive=False, n1=5, n2=5))
|
| 1697 |
+
|
| 1698 |
+
s1 = ParametricSurfaceSeries(
|
| 1699 |
+
cos(x - y), sin(x + y), x - y, (x, -2, 2), (y, -2, 2), n1=5, n2=5)
|
| 1700 |
+
s2 = ParametricSurfaceSeries(
|
| 1701 |
+
cos(x - y), sin(x + y), x - y, (x, -2 * a, 2), (y, -2, 2 * b),
|
| 1702 |
+
params={a: 1, b: 1}, n1=5, n2=5)
|
| 1703 |
+
do_test(s1, s2, {a: 0.5, b: 1.5})
|
| 1704 |
+
|
| 1705 |
+
# missing a parameter
|
| 1706 |
+
raises(ValueError,
|
| 1707 |
+
lambda : ParametricSurfaceSeries(
|
| 1708 |
+
cos(x - y), sin(x + y), x - y, (x, -2 * a, 2), (y, -2, 2 * b),
|
| 1709 |
+
params={a: 1}, n1=5, n2=5))
|
| 1710 |
+
|
| 1711 |
+
|
| 1712 |
+
def test_exclude_points():
|
| 1713 |
+
# verify that exclude works as expected
|
| 1714 |
+
if not np:
|
| 1715 |
+
skip("numpy not installed.")
|
| 1716 |
+
|
| 1717 |
+
x = symbols("x")
|
| 1718 |
+
|
| 1719 |
+
expr = (floor(x) + S.Half) / (1 - (x - S.Half)**2)
|
| 1720 |
+
|
| 1721 |
+
with warns(
|
| 1722 |
+
UserWarning,
|
| 1723 |
+
match="NumPy is unable to evaluate with complex numbers some",
|
| 1724 |
+
test_stacklevel=False,
|
| 1725 |
+
):
|
| 1726 |
+
s = LineOver1DRangeSeries(expr, (x, -3.5, 3.5), adaptive=False, n=100,
|
| 1727 |
+
exclude=list(range(-3, 4)))
|
| 1728 |
+
xx, yy = s.get_data()
|
| 1729 |
+
assert not np.isnan(xx).any()
|
| 1730 |
+
assert np.count_nonzero(np.isnan(yy)) == 7
|
| 1731 |
+
assert len(xx) > 100
|
| 1732 |
+
|
| 1733 |
+
e1 = log(floor(x)) * cos(x)
|
| 1734 |
+
e2 = log(floor(x)) * sin(x)
|
| 1735 |
+
with warns(
|
| 1736 |
+
UserWarning,
|
| 1737 |
+
match="NumPy is unable to evaluate with complex numbers some",
|
| 1738 |
+
test_stacklevel=False,
|
| 1739 |
+
):
|
| 1740 |
+
s = Parametric2DLineSeries(e1, e2, (x, 1, 12), adaptive=False, n=100,
|
| 1741 |
+
exclude=list(range(1, 13)))
|
| 1742 |
+
xx, yy, pp = s.get_data()
|
| 1743 |
+
assert not np.isnan(pp).any()
|
| 1744 |
+
assert np.count_nonzero(np.isnan(xx)) == 11
|
| 1745 |
+
assert np.count_nonzero(np.isnan(yy)) == 11
|
| 1746 |
+
assert len(xx) > 100
|
| 1747 |
+
|
| 1748 |
+
|
| 1749 |
+
def test_unwrap():
|
| 1750 |
+
# verify that unwrap works as expected
|
| 1751 |
+
if not np:
|
| 1752 |
+
skip("numpy not installed.")
|
| 1753 |
+
|
| 1754 |
+
x, y = symbols("x, y")
|
| 1755 |
+
expr = 1 / (x**3 + 2*x**2 + x)
|
| 1756 |
+
expr = arg(expr.subs(x, I*y*2*pi))
|
| 1757 |
+
s1 = LineOver1DRangeSeries(expr, (y, 1e-05, 1e05), xscale="log",
|
| 1758 |
+
adaptive=False, n=10, unwrap=False)
|
| 1759 |
+
s2 = LineOver1DRangeSeries(expr, (y, 1e-05, 1e05), xscale="log",
|
| 1760 |
+
adaptive=False, n=10, unwrap=True)
|
| 1761 |
+
s3 = LineOver1DRangeSeries(expr, (y, 1e-05, 1e05), xscale="log",
|
| 1762 |
+
adaptive=False, n=10, unwrap={"period": 4})
|
| 1763 |
+
x1, y1 = s1.get_data()
|
| 1764 |
+
x2, y2 = s2.get_data()
|
| 1765 |
+
x3, y3 = s3.get_data()
|
| 1766 |
+
assert np.allclose(x1, x2)
|
| 1767 |
+
# there must not be nan values in the results of these evaluations
|
| 1768 |
+
assert all(not np.isnan(t).any() for t in [y1, y2, y3])
|
| 1769 |
+
assert not np.allclose(y1, y2)
|
| 1770 |
+
assert not np.allclose(y1, y3)
|
| 1771 |
+
assert not np.allclose(y2, y3)
|
venv/lib/python3.14/site-packages/sympy/plotting/tests/test_textplot.py
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from sympy.core.singleton import S
|
| 2 |
+
from sympy.core.symbol import Symbol
|
| 3 |
+
from sympy.functions.elementary.exponential import log
|
| 4 |
+
from sympy.functions.elementary.miscellaneous import sqrt
|
| 5 |
+
from sympy.functions.elementary.trigonometric import sin
|
| 6 |
+
from sympy.plotting.textplot import textplot_str
|
| 7 |
+
|
| 8 |
+
from sympy.utilities.exceptions import ignore_warnings
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def test_axes_alignment():
|
| 12 |
+
x = Symbol('x')
|
| 13 |
+
lines = [
|
| 14 |
+
' 1 | ..',
|
| 15 |
+
' | ... ',
|
| 16 |
+
' | .. ',
|
| 17 |
+
' | ... ',
|
| 18 |
+
' | ... ',
|
| 19 |
+
' | .. ',
|
| 20 |
+
' | ... ',
|
| 21 |
+
' | ... ',
|
| 22 |
+
' | .. ',
|
| 23 |
+
' | ... ',
|
| 24 |
+
' 0 |--------------------------...--------------------------',
|
| 25 |
+
' | ... ',
|
| 26 |
+
' | .. ',
|
| 27 |
+
' | ... ',
|
| 28 |
+
' | ... ',
|
| 29 |
+
' | .. ',
|
| 30 |
+
' | ... ',
|
| 31 |
+
' | ... ',
|
| 32 |
+
' | .. ',
|
| 33 |
+
' | ... ',
|
| 34 |
+
' -1 |_______________________________________________________',
|
| 35 |
+
' -1 0 1'
|
| 36 |
+
]
|
| 37 |
+
assert lines == list(textplot_str(x, -1, 1))
|
| 38 |
+
|
| 39 |
+
lines = [
|
| 40 |
+
' 1 | ..',
|
| 41 |
+
' | .... ',
|
| 42 |
+
' | ... ',
|
| 43 |
+
' | ... ',
|
| 44 |
+
' | .... ',
|
| 45 |
+
' | ... ',
|
| 46 |
+
' | ... ',
|
| 47 |
+
' | .... ',
|
| 48 |
+
' 0 |--------------------------...--------------------------',
|
| 49 |
+
' | .... ',
|
| 50 |
+
' | ... ',
|
| 51 |
+
' | ... ',
|
| 52 |
+
' | .... ',
|
| 53 |
+
' | ... ',
|
| 54 |
+
' | ... ',
|
| 55 |
+
' | .... ',
|
| 56 |
+
' -1 |_______________________________________________________',
|
| 57 |
+
' -1 0 1'
|
| 58 |
+
]
|
| 59 |
+
assert lines == list(textplot_str(x, -1, 1, H=17))
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
def test_singularity():
|
| 63 |
+
x = Symbol('x')
|
| 64 |
+
lines = [
|
| 65 |
+
' 54 | . ',
|
| 66 |
+
' | ',
|
| 67 |
+
' | ',
|
| 68 |
+
' | ',
|
| 69 |
+
' | ',' | ',
|
| 70 |
+
' | ',
|
| 71 |
+
' | ',
|
| 72 |
+
' | ',
|
| 73 |
+
' | ',
|
| 74 |
+
' 27.5 |--.----------------------------------------------------',
|
| 75 |
+
' | ',
|
| 76 |
+
' | ',
|
| 77 |
+
' | ',
|
| 78 |
+
' | . ',
|
| 79 |
+
' | \\ ',
|
| 80 |
+
' | \\ ',
|
| 81 |
+
' | .. ',
|
| 82 |
+
' | ... ',
|
| 83 |
+
' | ............. ',
|
| 84 |
+
' 1 |_______________________________________________________',
|
| 85 |
+
' 0 0.5 1'
|
| 86 |
+
]
|
| 87 |
+
assert lines == list(textplot_str(1/x, 0, 1))
|
| 88 |
+
|
| 89 |
+
lines = [
|
| 90 |
+
' 0 | ......',
|
| 91 |
+
' | ........ ',
|
| 92 |
+
' | ........ ',
|
| 93 |
+
' | ...... ',
|
| 94 |
+
' | ..... ',
|
| 95 |
+
' | .... ',
|
| 96 |
+
' | ... ',
|
| 97 |
+
' | .. ',
|
| 98 |
+
' | ... ',
|
| 99 |
+
' | / ',
|
| 100 |
+
' -2 |-------..----------------------------------------------',
|
| 101 |
+
' | / ',
|
| 102 |
+
' | / ',
|
| 103 |
+
' | / ',
|
| 104 |
+
' | . ',
|
| 105 |
+
' | ',
|
| 106 |
+
' | . ',
|
| 107 |
+
' | ',
|
| 108 |
+
' | ',
|
| 109 |
+
' | ',
|
| 110 |
+
' -4 |_______________________________________________________',
|
| 111 |
+
' 0 0.5 1'
|
| 112 |
+
]
|
| 113 |
+
# RuntimeWarning: divide by zero encountered in log
|
| 114 |
+
with ignore_warnings(RuntimeWarning):
|
| 115 |
+
assert lines == list(textplot_str(log(x), 0, 1))
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
def test_sinc():
|
| 119 |
+
x = Symbol('x')
|
| 120 |
+
lines = [
|
| 121 |
+
' 1 | . . ',
|
| 122 |
+
' | . . ',
|
| 123 |
+
' | ',
|
| 124 |
+
' | . . ',
|
| 125 |
+
' | ',
|
| 126 |
+
' | . . ',
|
| 127 |
+
' | ',
|
| 128 |
+
' | ',
|
| 129 |
+
' | . . ',
|
| 130 |
+
' | ',
|
| 131 |
+
' 0.4 |-------------------------------------------------------',
|
| 132 |
+
' | . . ',
|
| 133 |
+
' | ',
|
| 134 |
+
' | . . ',
|
| 135 |
+
' | ',
|
| 136 |
+
' | ..... ..... ',
|
| 137 |
+
' | .. \\ . . / .. ',
|
| 138 |
+
' | / \\ / \\ ',
|
| 139 |
+
' |/ \\ . . / \\',
|
| 140 |
+
' | \\ / \\ / ',
|
| 141 |
+
' -0.2 |_______________________________________________________',
|
| 142 |
+
' -10 0 10'
|
| 143 |
+
]
|
| 144 |
+
# RuntimeWarning: invalid value encountered in double_scalars
|
| 145 |
+
with ignore_warnings(RuntimeWarning):
|
| 146 |
+
assert lines == list(textplot_str(sin(x)/x, -10, 10))
|
| 147 |
+
|
| 148 |
+
|
| 149 |
+
def test_imaginary():
|
| 150 |
+
x = Symbol('x')
|
| 151 |
+
lines = [
|
| 152 |
+
' 1 | ..',
|
| 153 |
+
' | .. ',
|
| 154 |
+
' | ... ',
|
| 155 |
+
' | .. ',
|
| 156 |
+
' | .. ',
|
| 157 |
+
' | .. ',
|
| 158 |
+
' | .. ',
|
| 159 |
+
' | .. ',
|
| 160 |
+
' | .. ',
|
| 161 |
+
' | / ',
|
| 162 |
+
' 0.5 |----------------------------------/--------------------',
|
| 163 |
+
' | .. ',
|
| 164 |
+
' | / ',
|
| 165 |
+
' | . ',
|
| 166 |
+
' | ',
|
| 167 |
+
' | . ',
|
| 168 |
+
' | . ',
|
| 169 |
+
' | ',
|
| 170 |
+
' | ',
|
| 171 |
+
' | ',
|
| 172 |
+
' 0 |_______________________________________________________',
|
| 173 |
+
' -1 0 1'
|
| 174 |
+
]
|
| 175 |
+
# RuntimeWarning: invalid value encountered in sqrt
|
| 176 |
+
with ignore_warnings(RuntimeWarning):
|
| 177 |
+
assert list(textplot_str(sqrt(x), -1, 1)) == lines
|
| 178 |
+
|
| 179 |
+
lines = [
|
| 180 |
+
' 1 | ',
|
| 181 |
+
' | ',
|
| 182 |
+
' | ',
|
| 183 |
+
' | ',
|
| 184 |
+
' | ',
|
| 185 |
+
' | ',
|
| 186 |
+
' | ',
|
| 187 |
+
' | ',
|
| 188 |
+
' | ',
|
| 189 |
+
' | ',
|
| 190 |
+
' 0 |-------------------------------------------------------',
|
| 191 |
+
' | ',
|
| 192 |
+
' | ',
|
| 193 |
+
' | ',
|
| 194 |
+
' | ',
|
| 195 |
+
' | ',
|
| 196 |
+
' | ',
|
| 197 |
+
' | ',
|
| 198 |
+
' | ',
|
| 199 |
+
' | ',
|
| 200 |
+
' -1 |_______________________________________________________',
|
| 201 |
+
' -1 0 1'
|
| 202 |
+
]
|
| 203 |
+
assert list(textplot_str(S.ImaginaryUnit, -1, 1)) == lines
|
venv/lib/python3.14/site-packages/sympy/plotting/tests/test_utils.py
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from pytest import raises
|
| 2 |
+
from sympy import (
|
| 3 |
+
symbols, Expr, Tuple, Integer, cos, solveset, FiniteSet, ImageSet)
|
| 4 |
+
from sympy.plotting.utils import (
|
| 5 |
+
_create_ranges, _plot_sympify, extract_solution)
|
| 6 |
+
from sympy.physics.mechanics import ReferenceFrame, Vector as MechVector
|
| 7 |
+
from sympy.vector import CoordSys3D, Vector
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def test_plot_sympify():
|
| 11 |
+
x, y = symbols("x, y")
|
| 12 |
+
|
| 13 |
+
# argument is already sympified
|
| 14 |
+
args = x + y
|
| 15 |
+
r = _plot_sympify(args)
|
| 16 |
+
assert r == args
|
| 17 |
+
|
| 18 |
+
# one argument needs to be sympified
|
| 19 |
+
args = (x + y, 1)
|
| 20 |
+
r = _plot_sympify(args)
|
| 21 |
+
assert isinstance(r, (list, tuple, Tuple)) and len(r) == 2
|
| 22 |
+
assert isinstance(r[0], Expr)
|
| 23 |
+
assert isinstance(r[1], Integer)
|
| 24 |
+
|
| 25 |
+
# string and dict should not be sympified
|
| 26 |
+
args = (x + y, (x, 0, 1), "str", 1, {1: 1, 2: 2.0})
|
| 27 |
+
r = _plot_sympify(args)
|
| 28 |
+
assert isinstance(r, (list, tuple, Tuple)) and len(r) == 5
|
| 29 |
+
assert isinstance(r[0], Expr)
|
| 30 |
+
assert isinstance(r[1], Tuple)
|
| 31 |
+
assert isinstance(r[2], str)
|
| 32 |
+
assert isinstance(r[3], Integer)
|
| 33 |
+
assert isinstance(r[4], dict) and isinstance(r[4][1], int) and isinstance(r[4][2], float)
|
| 34 |
+
|
| 35 |
+
# nested arguments containing strings
|
| 36 |
+
args = ((x + y, (y, 0, 1), "a"), (x + 1, (x, 0, 1), "$f_{1}$"))
|
| 37 |
+
r = _plot_sympify(args)
|
| 38 |
+
assert isinstance(r, (list, tuple, Tuple)) and len(r) == 2
|
| 39 |
+
assert isinstance(r[0], Tuple)
|
| 40 |
+
assert isinstance(r[0][1], Tuple)
|
| 41 |
+
assert isinstance(r[0][1][1], Integer)
|
| 42 |
+
assert isinstance(r[0][2], str)
|
| 43 |
+
assert isinstance(r[1], Tuple)
|
| 44 |
+
assert isinstance(r[1][1], Tuple)
|
| 45 |
+
assert isinstance(r[1][1][1], Integer)
|
| 46 |
+
assert isinstance(r[1][2], str)
|
| 47 |
+
|
| 48 |
+
# vectors from sympy.physics.vectors module are not sympified
|
| 49 |
+
# vectors from sympy.vectors are sympified
|
| 50 |
+
# in both cases, no error should be raised
|
| 51 |
+
R = ReferenceFrame("R")
|
| 52 |
+
v1 = 2 * R.x + R.y
|
| 53 |
+
C = CoordSys3D("C")
|
| 54 |
+
v2 = 2 * C.i + C.j
|
| 55 |
+
args = (v1, v2)
|
| 56 |
+
r = _plot_sympify(args)
|
| 57 |
+
assert isinstance(r, (list, tuple, Tuple)) and len(r) == 2
|
| 58 |
+
assert isinstance(v1, MechVector)
|
| 59 |
+
assert isinstance(v2, Vector)
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
def test_create_ranges():
|
| 63 |
+
x, y = symbols("x, y")
|
| 64 |
+
|
| 65 |
+
# user don't provide any range -> return a default range
|
| 66 |
+
r = _create_ranges({x}, [], 1)
|
| 67 |
+
assert isinstance(r, (list, tuple, Tuple)) and len(r) == 1
|
| 68 |
+
assert isinstance(r[0], (Tuple, tuple))
|
| 69 |
+
assert r[0] == (x, -10, 10)
|
| 70 |
+
|
| 71 |
+
r = _create_ranges({x, y}, [], 2)
|
| 72 |
+
assert isinstance(r, (list, tuple, Tuple)) and len(r) == 2
|
| 73 |
+
assert isinstance(r[0], (Tuple, tuple))
|
| 74 |
+
assert isinstance(r[1], (Tuple, tuple))
|
| 75 |
+
assert r[0] == (x, -10, 10) or (y, -10, 10)
|
| 76 |
+
assert r[1] == (y, -10, 10) or (x, -10, 10)
|
| 77 |
+
assert r[0] != r[1]
|
| 78 |
+
|
| 79 |
+
# not enough ranges provided by the user -> create default ranges
|
| 80 |
+
r = _create_ranges(
|
| 81 |
+
{x, y},
|
| 82 |
+
[
|
| 83 |
+
(x, 0, 1),
|
| 84 |
+
],
|
| 85 |
+
2,
|
| 86 |
+
)
|
| 87 |
+
assert isinstance(r, (list, tuple, Tuple)) and len(r) == 2
|
| 88 |
+
assert isinstance(r[0], (Tuple, tuple))
|
| 89 |
+
assert isinstance(r[1], (Tuple, tuple))
|
| 90 |
+
assert r[0] == (x, 0, 1) or (y, -10, 10)
|
| 91 |
+
assert r[1] == (y, -10, 10) or (x, 0, 1)
|
| 92 |
+
assert r[0] != r[1]
|
| 93 |
+
|
| 94 |
+
# too many free symbols
|
| 95 |
+
raises(ValueError, lambda: _create_ranges({x, y}, [], 1))
|
| 96 |
+
raises(ValueError, lambda: _create_ranges({x, y}, [(x, 0, 5), (y, 0, 1)], 1))
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
def test_extract_solution():
|
| 100 |
+
x = symbols("x")
|
| 101 |
+
|
| 102 |
+
sol = solveset(cos(10 * x))
|
| 103 |
+
assert sol.has(ImageSet)
|
| 104 |
+
res = extract_solution(sol)
|
| 105 |
+
assert len(res) == 20
|
| 106 |
+
assert isinstance(res, FiniteSet)
|
| 107 |
+
|
| 108 |
+
res = extract_solution(sol, 20)
|
| 109 |
+
assert len(res) == 40
|
| 110 |
+
assert isinstance(res, FiniteSet)
|
venv/lib/python3.14/site-packages/sympy/plotting/textplot.py
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from sympy.core.numbers import Float
|
| 2 |
+
from sympy.core.symbol import Dummy
|
| 3 |
+
from sympy.utilities.lambdify import lambdify
|
| 4 |
+
|
| 5 |
+
import math
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def is_valid(x):
|
| 9 |
+
"""Check if a floating point number is valid"""
|
| 10 |
+
if x is None:
|
| 11 |
+
return False
|
| 12 |
+
if isinstance(x, complex):
|
| 13 |
+
return False
|
| 14 |
+
return not math.isinf(x) and not math.isnan(x)
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def rescale(y, W, H, mi, ma):
|
| 18 |
+
"""Rescale the given array `y` to fit into the integer values
|
| 19 |
+
between `0` and `H-1` for the values between ``mi`` and ``ma``.
|
| 20 |
+
"""
|
| 21 |
+
y_new = []
|
| 22 |
+
|
| 23 |
+
norm = ma - mi
|
| 24 |
+
offset = (ma + mi) / 2
|
| 25 |
+
|
| 26 |
+
for x in range(W):
|
| 27 |
+
if is_valid(y[x]):
|
| 28 |
+
normalized = (y[x] - offset) / norm
|
| 29 |
+
if not is_valid(normalized):
|
| 30 |
+
y_new.append(None)
|
| 31 |
+
else:
|
| 32 |
+
rescaled = Float((normalized*H + H/2) * (H-1)/H).round()
|
| 33 |
+
rescaled = int(rescaled)
|
| 34 |
+
y_new.append(rescaled)
|
| 35 |
+
else:
|
| 36 |
+
y_new.append(None)
|
| 37 |
+
return y_new
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
def linspace(start, stop, num):
|
| 41 |
+
return [start + (stop - start) * x / (num-1) for x in range(num)]
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
def textplot_str(expr, a, b, W=55, H=21):
|
| 45 |
+
"""Generator for the lines of the plot"""
|
| 46 |
+
free = expr.free_symbols
|
| 47 |
+
if len(free) > 1:
|
| 48 |
+
raise ValueError(
|
| 49 |
+
"The expression must have a single variable. (Got {})"
|
| 50 |
+
.format(free))
|
| 51 |
+
x = free.pop() if free else Dummy()
|
| 52 |
+
f = lambdify([x], expr)
|
| 53 |
+
if isinstance(a, complex):
|
| 54 |
+
if a.imag == 0:
|
| 55 |
+
a = a.real
|
| 56 |
+
if isinstance(b, complex):
|
| 57 |
+
if b.imag == 0:
|
| 58 |
+
b = b.real
|
| 59 |
+
a = float(a)
|
| 60 |
+
b = float(b)
|
| 61 |
+
|
| 62 |
+
# Calculate function values
|
| 63 |
+
x = linspace(a, b, W)
|
| 64 |
+
y = []
|
| 65 |
+
for val in x:
|
| 66 |
+
try:
|
| 67 |
+
y.append(f(val))
|
| 68 |
+
# Not sure what exceptions to catch here or why...
|
| 69 |
+
except (ValueError, TypeError, ZeroDivisionError):
|
| 70 |
+
y.append(None)
|
| 71 |
+
|
| 72 |
+
# Normalize height to screen space
|
| 73 |
+
y_valid = list(filter(is_valid, y))
|
| 74 |
+
if y_valid:
|
| 75 |
+
ma = max(y_valid)
|
| 76 |
+
mi = min(y_valid)
|
| 77 |
+
if ma == mi:
|
| 78 |
+
if ma:
|
| 79 |
+
mi, ma = sorted([0, 2*ma])
|
| 80 |
+
else:
|
| 81 |
+
mi, ma = -1, 1
|
| 82 |
+
else:
|
| 83 |
+
mi, ma = -1, 1
|
| 84 |
+
y_range = ma - mi
|
| 85 |
+
precision = math.floor(math.log10(y_range)) - 1
|
| 86 |
+
precision *= -1
|
| 87 |
+
mi = round(mi, precision)
|
| 88 |
+
ma = round(ma, precision)
|
| 89 |
+
y = rescale(y, W, H, mi, ma)
|
| 90 |
+
|
| 91 |
+
y_bins = linspace(mi, ma, H)
|
| 92 |
+
|
| 93 |
+
# Draw plot
|
| 94 |
+
margin = 7
|
| 95 |
+
for h in range(H - 1, -1, -1):
|
| 96 |
+
s = [' '] * W
|
| 97 |
+
for i in range(W):
|
| 98 |
+
if y[i] == h:
|
| 99 |
+
if (i == 0 or y[i - 1] == h - 1) and (i == W - 1 or y[i + 1] == h + 1):
|
| 100 |
+
s[i] = '/'
|
| 101 |
+
elif (i == 0 or y[i - 1] == h + 1) and (i == W - 1 or y[i + 1] == h - 1):
|
| 102 |
+
s[i] = '\\'
|
| 103 |
+
else:
|
| 104 |
+
s[i] = '.'
|
| 105 |
+
|
| 106 |
+
if h == 0:
|
| 107 |
+
for i in range(W):
|
| 108 |
+
s[i] = '_'
|
| 109 |
+
|
| 110 |
+
# Print y values
|
| 111 |
+
if h in (0, H//2, H - 1):
|
| 112 |
+
prefix = ("%g" % y_bins[h]).rjust(margin)[:margin]
|
| 113 |
+
else:
|
| 114 |
+
prefix = " "*margin
|
| 115 |
+
s = "".join(s)
|
| 116 |
+
if h == H//2:
|
| 117 |
+
s = s.replace(" ", "-")
|
| 118 |
+
yield prefix + " |" + s
|
| 119 |
+
|
| 120 |
+
# Print x values
|
| 121 |
+
bottom = " " * (margin + 2)
|
| 122 |
+
bottom += ("%g" % x[0]).ljust(W//2)
|
| 123 |
+
if W % 2 == 1:
|
| 124 |
+
bottom += ("%g" % x[W//2]).ljust(W//2)
|
| 125 |
+
else:
|
| 126 |
+
bottom += ("%g" % x[W//2]).ljust(W//2-1)
|
| 127 |
+
bottom += "%g" % x[-1]
|
| 128 |
+
yield bottom
|
| 129 |
+
|
| 130 |
+
|
| 131 |
+
def textplot(expr, a, b, W=55, H=21):
|
| 132 |
+
r"""
|
| 133 |
+
Print a crude ASCII art plot of the SymPy expression 'expr' (which
|
| 134 |
+
should contain a single symbol, e.g. x or something else) over the
|
| 135 |
+
interval [a, b].
|
| 136 |
+
|
| 137 |
+
Examples
|
| 138 |
+
========
|
| 139 |
+
|
| 140 |
+
>>> from sympy import Symbol, sin
|
| 141 |
+
>>> from sympy.plotting import textplot
|
| 142 |
+
>>> t = Symbol('t')
|
| 143 |
+
>>> textplot(sin(t)*t, 0, 15)
|
| 144 |
+
14 | ...
|
| 145 |
+
| .
|
| 146 |
+
| .
|
| 147 |
+
| .
|
| 148 |
+
| .
|
| 149 |
+
| ...
|
| 150 |
+
| / . .
|
| 151 |
+
| /
|
| 152 |
+
| / .
|
| 153 |
+
| . . .
|
| 154 |
+
1.5 |----.......--------------------------------------------
|
| 155 |
+
|.... \ . .
|
| 156 |
+
| \ / .
|
| 157 |
+
| .. / .
|
| 158 |
+
| \ / .
|
| 159 |
+
| ....
|
| 160 |
+
| .
|
| 161 |
+
| . .
|
| 162 |
+
|
|
| 163 |
+
| . .
|
| 164 |
+
-11 |_______________________________________________________
|
| 165 |
+
0 7.5 15
|
| 166 |
+
"""
|
| 167 |
+
for line in textplot_str(expr, a, b, W, H):
|
| 168 |
+
print(line)
|
venv/lib/python3.14/site-packages/sympy/plotting/utils.py
ADDED
|
@@ -0,0 +1,323 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from sympy.core.containers import Tuple
|
| 2 |
+
from sympy.core.basic import Basic
|
| 3 |
+
from sympy.core.expr import Expr
|
| 4 |
+
from sympy.core.function import AppliedUndef
|
| 5 |
+
from sympy.core.relational import Relational
|
| 6 |
+
from sympy.core.symbol import Dummy
|
| 7 |
+
from sympy.core.sympify import sympify
|
| 8 |
+
from sympy.logic.boolalg import BooleanFunction
|
| 9 |
+
from sympy.sets.fancysets import ImageSet
|
| 10 |
+
from sympy.sets.sets import FiniteSet
|
| 11 |
+
from sympy.tensor.indexed import Indexed
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def _get_free_symbols(exprs):
|
| 15 |
+
"""Returns the free symbols of a symbolic expression.
|
| 16 |
+
|
| 17 |
+
If the expression contains any of these elements, assume that they are
|
| 18 |
+
the "free symbols" of the expression:
|
| 19 |
+
|
| 20 |
+
* indexed objects
|
| 21 |
+
* applied undefined function (useful for sympy.physics.mechanics module)
|
| 22 |
+
"""
|
| 23 |
+
if not isinstance(exprs, (list, tuple, set)):
|
| 24 |
+
exprs = [exprs]
|
| 25 |
+
if all(callable(e) for e in exprs):
|
| 26 |
+
return set()
|
| 27 |
+
|
| 28 |
+
free = set().union(*[e.atoms(Indexed) for e in exprs])
|
| 29 |
+
free = free.union(*[e.atoms(AppliedUndef) for e in exprs])
|
| 30 |
+
return free or set().union(*[e.free_symbols for e in exprs])
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
def extract_solution(set_sol, n=10):
|
| 34 |
+
"""Extract numerical solutions from a set solution (computed by solveset,
|
| 35 |
+
linsolve, nonlinsolve). Often, it is not trivial do get something useful
|
| 36 |
+
out of them.
|
| 37 |
+
|
| 38 |
+
Parameters
|
| 39 |
+
==========
|
| 40 |
+
|
| 41 |
+
n : int, optional
|
| 42 |
+
In order to replace ImageSet with FiniteSet, an iterator is created
|
| 43 |
+
for each ImageSet contained in `set_sol`, starting from 0 up to `n`.
|
| 44 |
+
Default value: 10.
|
| 45 |
+
"""
|
| 46 |
+
images = set_sol.find(ImageSet)
|
| 47 |
+
for im in images:
|
| 48 |
+
it = iter(im)
|
| 49 |
+
s = FiniteSet(*[next(it) for n in range(0, n)])
|
| 50 |
+
set_sol = set_sol.subs(im, s)
|
| 51 |
+
return set_sol
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
def _plot_sympify(args):
|
| 55 |
+
"""This function recursively loop over the arguments passed to the plot
|
| 56 |
+
functions: the sympify function will be applied to all arguments except
|
| 57 |
+
those of type string/dict.
|
| 58 |
+
|
| 59 |
+
Generally, users can provide the following arguments to a plot function:
|
| 60 |
+
|
| 61 |
+
expr, range1 [tuple, opt], ..., label [str, opt], rendering_kw [dict, opt]
|
| 62 |
+
|
| 63 |
+
`expr, range1, ...` can be sympified, whereas `label, rendering_kw` can't.
|
| 64 |
+
In particular, whenever a special character like $, {, }, ... is used in
|
| 65 |
+
the `label`, sympify will raise an error.
|
| 66 |
+
"""
|
| 67 |
+
if isinstance(args, Expr):
|
| 68 |
+
return args
|
| 69 |
+
|
| 70 |
+
args = list(args)
|
| 71 |
+
for i, a in enumerate(args):
|
| 72 |
+
if isinstance(a, (list, tuple)):
|
| 73 |
+
args[i] = Tuple(*_plot_sympify(a), sympify=False)
|
| 74 |
+
elif not (isinstance(a, (str, dict)) or callable(a)
|
| 75 |
+
# NOTE: check if it is a vector from sympy.physics.vector module
|
| 76 |
+
# without importing the module (because it slows down SymPy's
|
| 77 |
+
# import process and triggers SymPy's optional-dependencies
|
| 78 |
+
# tests to fail).
|
| 79 |
+
or ((a.__class__.__name__ == "Vector") and not isinstance(a, Basic))
|
| 80 |
+
):
|
| 81 |
+
args[i] = sympify(a)
|
| 82 |
+
return args
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
def _create_ranges(exprs, ranges, npar, label="", params=None):
|
| 86 |
+
"""This function does two things:
|
| 87 |
+
|
| 88 |
+
1. Check if the number of free symbols is in agreement with the type of
|
| 89 |
+
plot chosen. For example, plot() requires 1 free symbol;
|
| 90 |
+
plot3d() requires 2 free symbols.
|
| 91 |
+
2. Sometime users create plots without providing ranges for the variables.
|
| 92 |
+
Here we create the necessary ranges.
|
| 93 |
+
|
| 94 |
+
Parameters
|
| 95 |
+
==========
|
| 96 |
+
|
| 97 |
+
exprs : iterable
|
| 98 |
+
The expressions from which to extract the free symbols
|
| 99 |
+
ranges : iterable
|
| 100 |
+
The limiting ranges provided by the user
|
| 101 |
+
npar : int
|
| 102 |
+
The number of free symbols required by the plot functions.
|
| 103 |
+
For example,
|
| 104 |
+
npar=1 for plot, npar=2 for plot3d, ...
|
| 105 |
+
params : dict
|
| 106 |
+
A dictionary mapping symbols to parameters for interactive plot.
|
| 107 |
+
"""
|
| 108 |
+
get_default_range = lambda symbol: Tuple(symbol, -10, 10)
|
| 109 |
+
|
| 110 |
+
free_symbols = _get_free_symbols(exprs)
|
| 111 |
+
if params is not None:
|
| 112 |
+
free_symbols = free_symbols.difference(params.keys())
|
| 113 |
+
|
| 114 |
+
if len(free_symbols) > npar:
|
| 115 |
+
raise ValueError(
|
| 116 |
+
"Too many free symbols.\n"
|
| 117 |
+
+ "Expected {} free symbols.\n".format(npar)
|
| 118 |
+
+ "Received {}: {}".format(len(free_symbols), free_symbols)
|
| 119 |
+
)
|
| 120 |
+
|
| 121 |
+
if len(ranges) > npar:
|
| 122 |
+
raise ValueError(
|
| 123 |
+
"Too many ranges. Received %s, expected %s" % (len(ranges), npar))
|
| 124 |
+
|
| 125 |
+
# free symbols in the ranges provided by the user
|
| 126 |
+
rfs = set().union([r[0] for r in ranges])
|
| 127 |
+
if len(rfs) != len(ranges):
|
| 128 |
+
raise ValueError("Multiple ranges with the same symbol")
|
| 129 |
+
|
| 130 |
+
if len(ranges) < npar:
|
| 131 |
+
symbols = free_symbols.difference(rfs)
|
| 132 |
+
if symbols != set():
|
| 133 |
+
# add a range for each missing free symbols
|
| 134 |
+
for s in symbols:
|
| 135 |
+
ranges.append(get_default_range(s))
|
| 136 |
+
# if there is still room, fill them with dummys
|
| 137 |
+
for i in range(npar - len(ranges)):
|
| 138 |
+
ranges.append(get_default_range(Dummy()))
|
| 139 |
+
|
| 140 |
+
if len(free_symbols) == npar:
|
| 141 |
+
# there could be times when this condition is not met, for example
|
| 142 |
+
# plotting the function f(x, y) = x (which is a plane); in this case,
|
| 143 |
+
# free_symbols = {x} whereas rfs = {x, y} (or x and Dummy)
|
| 144 |
+
rfs = set().union([r[0] for r in ranges])
|
| 145 |
+
if len(free_symbols.difference(rfs)) > 0:
|
| 146 |
+
raise ValueError(
|
| 147 |
+
"Incompatible free symbols of the expressions with "
|
| 148 |
+
"the ranges.\n"
|
| 149 |
+
+ "Free symbols in the expressions: {}\n".format(free_symbols)
|
| 150 |
+
+ "Free symbols in the ranges: {}".format(rfs)
|
| 151 |
+
)
|
| 152 |
+
return ranges
|
| 153 |
+
|
| 154 |
+
|
| 155 |
+
def _is_range(r):
|
| 156 |
+
"""A range is defined as (symbol, start, end). start and end should
|
| 157 |
+
be numbers.
|
| 158 |
+
"""
|
| 159 |
+
# TODO: prange check goes here
|
| 160 |
+
return (
|
| 161 |
+
isinstance(r, Tuple)
|
| 162 |
+
and (len(r) == 3)
|
| 163 |
+
and (not isinstance(r.args[1], str)) and r.args[1].is_number
|
| 164 |
+
and (not isinstance(r.args[2], str)) and r.args[2].is_number
|
| 165 |
+
)
|
| 166 |
+
|
| 167 |
+
|
| 168 |
+
def _unpack_args(*args):
|
| 169 |
+
"""Given a list/tuple of arguments previously processed by _plot_sympify()
|
| 170 |
+
and/or _check_arguments(), separates and returns its components:
|
| 171 |
+
expressions, ranges, label and rendering keywords.
|
| 172 |
+
|
| 173 |
+
Examples
|
| 174 |
+
========
|
| 175 |
+
|
| 176 |
+
>>> from sympy import cos, sin, symbols
|
| 177 |
+
>>> from sympy.plotting.utils import _plot_sympify, _unpack_args
|
| 178 |
+
>>> x, y = symbols('x, y')
|
| 179 |
+
>>> args = (sin(x), (x, -10, 10), "f1")
|
| 180 |
+
>>> args = _plot_sympify(args)
|
| 181 |
+
>>> _unpack_args(*args)
|
| 182 |
+
([sin(x)], [(x, -10, 10)], 'f1', None)
|
| 183 |
+
|
| 184 |
+
>>> args = (sin(x**2 + y**2), (x, -2, 2), (y, -3, 3), "f2")
|
| 185 |
+
>>> args = _plot_sympify(args)
|
| 186 |
+
>>> _unpack_args(*args)
|
| 187 |
+
([sin(x**2 + y**2)], [(x, -2, 2), (y, -3, 3)], 'f2', None)
|
| 188 |
+
|
| 189 |
+
>>> args = (sin(x + y), cos(x - y), x + y, (x, -2, 2), (y, -3, 3), "f3")
|
| 190 |
+
>>> args = _plot_sympify(args)
|
| 191 |
+
>>> _unpack_args(*args)
|
| 192 |
+
([sin(x + y), cos(x - y), x + y], [(x, -2, 2), (y, -3, 3)], 'f3', None)
|
| 193 |
+
"""
|
| 194 |
+
ranges = [t for t in args if _is_range(t)]
|
| 195 |
+
labels = [t for t in args if isinstance(t, str)]
|
| 196 |
+
label = None if not labels else labels[0]
|
| 197 |
+
rendering_kw = [t for t in args if isinstance(t, dict)]
|
| 198 |
+
rendering_kw = None if not rendering_kw else rendering_kw[0]
|
| 199 |
+
# NOTE: why None? because args might have been preprocessed by
|
| 200 |
+
# _check_arguments, so None might represent the rendering_kw
|
| 201 |
+
results = [not (_is_range(a) or isinstance(a, (str, dict)) or (a is None)) for a in args]
|
| 202 |
+
exprs = [a for a, b in zip(args, results) if b]
|
| 203 |
+
return exprs, ranges, label, rendering_kw
|
| 204 |
+
|
| 205 |
+
|
| 206 |
+
def _check_arguments(args, nexpr, npar, **kwargs):
|
| 207 |
+
"""Checks the arguments and converts into tuples of the
|
| 208 |
+
form (exprs, ranges, label, rendering_kw).
|
| 209 |
+
|
| 210 |
+
Parameters
|
| 211 |
+
==========
|
| 212 |
+
|
| 213 |
+
args
|
| 214 |
+
The arguments provided to the plot functions
|
| 215 |
+
nexpr
|
| 216 |
+
The number of sub-expression forming an expression to be plotted.
|
| 217 |
+
For example:
|
| 218 |
+
nexpr=1 for plot.
|
| 219 |
+
nexpr=2 for plot_parametric: a curve is represented by a tuple of two
|
| 220 |
+
elements.
|
| 221 |
+
nexpr=1 for plot3d.
|
| 222 |
+
nexpr=3 for plot3d_parametric_line: a curve is represented by a tuple
|
| 223 |
+
of three elements.
|
| 224 |
+
npar
|
| 225 |
+
The number of free symbols required by the plot functions. For example,
|
| 226 |
+
npar=1 for plot, npar=2 for plot3d, ...
|
| 227 |
+
**kwargs :
|
| 228 |
+
keyword arguments passed to the plotting function. It will be used to
|
| 229 |
+
verify if ``params`` has ben provided.
|
| 230 |
+
|
| 231 |
+
Examples
|
| 232 |
+
========
|
| 233 |
+
|
| 234 |
+
.. plot::
|
| 235 |
+
:context: reset
|
| 236 |
+
:format: doctest
|
| 237 |
+
:include-source: True
|
| 238 |
+
|
| 239 |
+
>>> from sympy import cos, sin, symbols
|
| 240 |
+
>>> from sympy.plotting.plot import _check_arguments
|
| 241 |
+
>>> x = symbols('x')
|
| 242 |
+
>>> _check_arguments([cos(x), sin(x)], 2, 1)
|
| 243 |
+
[(cos(x), sin(x), (x, -10, 10), None, None)]
|
| 244 |
+
|
| 245 |
+
>>> _check_arguments([cos(x), sin(x), "test"], 2, 1)
|
| 246 |
+
[(cos(x), sin(x), (x, -10, 10), 'test', None)]
|
| 247 |
+
|
| 248 |
+
>>> _check_arguments([cos(x), sin(x), "test", {"a": 0, "b": 1}], 2, 1)
|
| 249 |
+
[(cos(x), sin(x), (x, -10, 10), 'test', {'a': 0, 'b': 1})]
|
| 250 |
+
|
| 251 |
+
>>> _check_arguments([x, x**2], 1, 1)
|
| 252 |
+
[(x, (x, -10, 10), None, None), (x**2, (x, -10, 10), None, None)]
|
| 253 |
+
"""
|
| 254 |
+
if not args:
|
| 255 |
+
return []
|
| 256 |
+
output = []
|
| 257 |
+
params = kwargs.get("params", None)
|
| 258 |
+
|
| 259 |
+
if all(isinstance(a, (Expr, Relational, BooleanFunction)) for a in args[:nexpr]):
|
| 260 |
+
# In this case, with a single plot command, we are plotting either:
|
| 261 |
+
# 1. one expression
|
| 262 |
+
# 2. multiple expressions over the same range
|
| 263 |
+
|
| 264 |
+
exprs, ranges, label, rendering_kw = _unpack_args(*args)
|
| 265 |
+
free_symbols = set().union(*[e.free_symbols for e in exprs])
|
| 266 |
+
ranges = _create_ranges(exprs, ranges, npar, label, params)
|
| 267 |
+
|
| 268 |
+
if nexpr > 1:
|
| 269 |
+
# in case of plot_parametric or plot3d_parametric_line, there will
|
| 270 |
+
# be 2 or 3 expressions defining a curve. Group them together.
|
| 271 |
+
if len(exprs) == nexpr:
|
| 272 |
+
exprs = (tuple(exprs),)
|
| 273 |
+
for expr in exprs:
|
| 274 |
+
# need this if-else to deal with both plot/plot3d and
|
| 275 |
+
# plot_parametric/plot3d_parametric_line
|
| 276 |
+
is_expr = isinstance(expr, (Expr, Relational, BooleanFunction))
|
| 277 |
+
e = (expr,) if is_expr else expr
|
| 278 |
+
output.append((*e, *ranges, label, rendering_kw))
|
| 279 |
+
|
| 280 |
+
else:
|
| 281 |
+
# In this case, we are plotting multiple expressions, each one with its
|
| 282 |
+
# range. Each "expression" to be plotted has the following form:
|
| 283 |
+
# (expr, range, label) where label is optional
|
| 284 |
+
|
| 285 |
+
_, ranges, labels, rendering_kw = _unpack_args(*args)
|
| 286 |
+
labels = [labels] if labels else []
|
| 287 |
+
|
| 288 |
+
# number of expressions
|
| 289 |
+
n = (len(ranges) + len(labels) +
|
| 290 |
+
(len(rendering_kw) if rendering_kw is not None else 0))
|
| 291 |
+
new_args = args[:-n] if n > 0 else args
|
| 292 |
+
|
| 293 |
+
# at this point, new_args might just be [expr]. But I need it to be
|
| 294 |
+
# [[expr]] in order to be able to loop over
|
| 295 |
+
# [expr, range [opt], label [opt]]
|
| 296 |
+
if not isinstance(new_args[0], (list, tuple, Tuple)):
|
| 297 |
+
new_args = [new_args]
|
| 298 |
+
|
| 299 |
+
# Each arg has the form (expr1, expr2, ..., range1 [optional], ...,
|
| 300 |
+
# label [optional], rendering_kw [optional])
|
| 301 |
+
for arg in new_args:
|
| 302 |
+
# look for "local" range and label. If there is not, use "global".
|
| 303 |
+
l = [a for a in arg if isinstance(a, str)]
|
| 304 |
+
if not l:
|
| 305 |
+
l = labels
|
| 306 |
+
r = [a for a in arg if _is_range(a)]
|
| 307 |
+
if not r:
|
| 308 |
+
r = ranges.copy()
|
| 309 |
+
rend_kw = [a for a in arg if isinstance(a, dict)]
|
| 310 |
+
rend_kw = rendering_kw if len(rend_kw) == 0 else rend_kw[0]
|
| 311 |
+
|
| 312 |
+
# NOTE: arg = arg[:nexpr] may raise an exception if lambda
|
| 313 |
+
# functions are used. Execute the following instead:
|
| 314 |
+
arg = [arg[i] for i in range(nexpr)]
|
| 315 |
+
free_symbols = set()
|
| 316 |
+
if all(not callable(a) for a in arg):
|
| 317 |
+
free_symbols = free_symbols.union(*[a.free_symbols for a in arg])
|
| 318 |
+
if len(r) != npar:
|
| 319 |
+
r = _create_ranges(arg, r, npar, "", params)
|
| 320 |
+
|
| 321 |
+
label = None if not l else l[0]
|
| 322 |
+
output.append((*arg, *r, label, rend_kw))
|
| 323 |
+
return output
|
venv/lib/python3.14/site-packages/sympy/polys/__init__.py
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Polynomial manipulation algorithms and algebraic objects. """
|
| 2 |
+
|
| 3 |
+
__all__ = [
|
| 4 |
+
'Poly', 'PurePoly', 'poly_from_expr', 'parallel_poly_from_expr', 'degree',
|
| 5 |
+
'total_degree', 'degree_list', 'LC', 'LM', 'LT', 'pdiv', 'prem', 'pquo',
|
| 6 |
+
'pexquo', 'div', 'rem', 'quo', 'exquo', 'half_gcdex', 'gcdex', 'invert',
|
| 7 |
+
'subresultants', 'resultant', 'discriminant', 'cofactors', 'gcd_list',
|
| 8 |
+
'gcd', 'lcm_list', 'lcm', 'terms_gcd', 'trunc', 'monic', 'content',
|
| 9 |
+
'primitive', 'compose', 'decompose', 'sturm', 'gff_list', 'gff',
|
| 10 |
+
'sqf_norm', 'sqf_part', 'sqf_list', 'sqf', 'factor_list', 'factor',
|
| 11 |
+
'intervals', 'refine_root', 'count_roots', 'all_roots', 'real_roots',
|
| 12 |
+
'nroots', 'ground_roots', 'nth_power_roots_poly', 'cancel', 'reduced',
|
| 13 |
+
'groebner', 'is_zero_dimensional', 'GroebnerBasis', 'poly',
|
| 14 |
+
|
| 15 |
+
'symmetrize', 'horner', 'interpolate', 'rational_interpolate', 'viete',
|
| 16 |
+
|
| 17 |
+
'together',
|
| 18 |
+
|
| 19 |
+
'BasePolynomialError', 'ExactQuotientFailed', 'PolynomialDivisionFailed',
|
| 20 |
+
'OperationNotSupported', 'HeuristicGCDFailed', 'HomomorphismFailed',
|
| 21 |
+
'IsomorphismFailed', 'ExtraneousFactors', 'EvaluationFailed',
|
| 22 |
+
'RefinementFailed', 'CoercionFailed', 'NotInvertible', 'NotReversible',
|
| 23 |
+
'NotAlgebraic', 'DomainError', 'PolynomialError', 'UnificationFailed',
|
| 24 |
+
'GeneratorsError', 'GeneratorsNeeded', 'ComputationFailed',
|
| 25 |
+
'UnivariatePolynomialError', 'MultivariatePolynomialError',
|
| 26 |
+
'PolificationFailed', 'OptionError', 'FlagError',
|
| 27 |
+
|
| 28 |
+
'minpoly', 'minimal_polynomial', 'primitive_element', 'field_isomorphism',
|
| 29 |
+
'to_number_field', 'isolate', 'round_two', 'prime_decomp',
|
| 30 |
+
'prime_valuation', 'galois_group',
|
| 31 |
+
|
| 32 |
+
'itermonomials', 'Monomial',
|
| 33 |
+
|
| 34 |
+
'lex', 'grlex', 'grevlex', 'ilex', 'igrlex', 'igrevlex',
|
| 35 |
+
|
| 36 |
+
'CRootOf', 'rootof', 'RootOf', 'ComplexRootOf', 'RootSum',
|
| 37 |
+
|
| 38 |
+
'roots',
|
| 39 |
+
|
| 40 |
+
'Domain', 'FiniteField', 'IntegerRing', 'RationalField', 'RealField',
|
| 41 |
+
'ComplexField', 'PythonFiniteField', 'GMPYFiniteField',
|
| 42 |
+
'PythonIntegerRing', 'GMPYIntegerRing', 'PythonRational',
|
| 43 |
+
'GMPYRationalField', 'AlgebraicField', 'PolynomialRing', 'FractionField',
|
| 44 |
+
'ExpressionDomain', 'FF_python', 'FF_gmpy', 'ZZ_python', 'ZZ_gmpy',
|
| 45 |
+
'QQ_python', 'QQ_gmpy', 'GF', 'FF', 'ZZ', 'QQ', 'ZZ_I', 'QQ_I', 'RR',
|
| 46 |
+
'CC', 'EX', 'EXRAW',
|
| 47 |
+
|
| 48 |
+
'construct_domain',
|
| 49 |
+
|
| 50 |
+
'swinnerton_dyer_poly', 'cyclotomic_poly', 'symmetric_poly',
|
| 51 |
+
'random_poly', 'interpolating_poly',
|
| 52 |
+
|
| 53 |
+
'jacobi_poly', 'chebyshevt_poly', 'chebyshevu_poly', 'hermite_poly',
|
| 54 |
+
'hermite_prob_poly', 'legendre_poly', 'laguerre_poly',
|
| 55 |
+
|
| 56 |
+
'bernoulli_poly', 'bernoulli_c_poly', 'genocchi_poly', 'euler_poly',
|
| 57 |
+
'andre_poly',
|
| 58 |
+
|
| 59 |
+
'apart', 'apart_list', 'assemble_partfrac_list',
|
| 60 |
+
|
| 61 |
+
'Options',
|
| 62 |
+
|
| 63 |
+
'ring', 'xring', 'vring', 'sring',
|
| 64 |
+
|
| 65 |
+
'field', 'xfield', 'vfield', 'sfield'
|
| 66 |
+
]
|
| 67 |
+
|
| 68 |
+
from .polytools import (Poly, PurePoly, poly_from_expr,
|
| 69 |
+
parallel_poly_from_expr, degree, total_degree, degree_list, LC, LM,
|
| 70 |
+
LT, pdiv, prem, pquo, pexquo, div, rem, quo, exquo, half_gcdex, gcdex,
|
| 71 |
+
invert, subresultants, resultant, discriminant, cofactors, gcd_list,
|
| 72 |
+
gcd, lcm_list, lcm, terms_gcd, trunc, monic, content, primitive,
|
| 73 |
+
compose, decompose, sturm, gff_list, gff, sqf_norm, sqf_part,
|
| 74 |
+
sqf_list, sqf, factor_list, factor, intervals, refine_root,
|
| 75 |
+
count_roots, all_roots, real_roots, nroots, ground_roots,
|
| 76 |
+
nth_power_roots_poly, cancel, reduced, groebner, is_zero_dimensional,
|
| 77 |
+
GroebnerBasis, poly)
|
| 78 |
+
|
| 79 |
+
from .polyfuncs import (symmetrize, horner, interpolate,
|
| 80 |
+
rational_interpolate, viete)
|
| 81 |
+
|
| 82 |
+
from .rationaltools import together
|
| 83 |
+
|
| 84 |
+
from .polyerrors import (BasePolynomialError, ExactQuotientFailed,
|
| 85 |
+
PolynomialDivisionFailed, OperationNotSupported, HeuristicGCDFailed,
|
| 86 |
+
HomomorphismFailed, IsomorphismFailed, ExtraneousFactors,
|
| 87 |
+
EvaluationFailed, RefinementFailed, CoercionFailed, NotInvertible,
|
| 88 |
+
NotReversible, NotAlgebraic, DomainError, PolynomialError,
|
| 89 |
+
UnificationFailed, GeneratorsError, GeneratorsNeeded,
|
| 90 |
+
ComputationFailed, UnivariatePolynomialError,
|
| 91 |
+
MultivariatePolynomialError, PolificationFailed, OptionError,
|
| 92 |
+
FlagError)
|
| 93 |
+
|
| 94 |
+
from .numberfields import (minpoly, minimal_polynomial, primitive_element,
|
| 95 |
+
field_isomorphism, to_number_field, isolate, round_two, prime_decomp,
|
| 96 |
+
prime_valuation, galois_group)
|
| 97 |
+
|
| 98 |
+
from .monomials import itermonomials, Monomial
|
| 99 |
+
|
| 100 |
+
from .orderings import lex, grlex, grevlex, ilex, igrlex, igrevlex
|
| 101 |
+
|
| 102 |
+
from .rootoftools import CRootOf, rootof, RootOf, ComplexRootOf, RootSum
|
| 103 |
+
|
| 104 |
+
from .polyroots import roots
|
| 105 |
+
|
| 106 |
+
from .domains import (Domain, FiniteField, IntegerRing, RationalField,
|
| 107 |
+
RealField, ComplexField, PythonFiniteField, GMPYFiniteField,
|
| 108 |
+
PythonIntegerRing, GMPYIntegerRing, PythonRational, GMPYRationalField,
|
| 109 |
+
AlgebraicField, PolynomialRing, FractionField, ExpressionDomain,
|
| 110 |
+
FF_python, FF_gmpy, ZZ_python, ZZ_gmpy, QQ_python, QQ_gmpy, GF, FF,
|
| 111 |
+
ZZ, QQ, ZZ_I, QQ_I, RR, CC, EX, EXRAW)
|
| 112 |
+
|
| 113 |
+
from .constructor import construct_domain
|
| 114 |
+
|
| 115 |
+
from .specialpolys import (swinnerton_dyer_poly, cyclotomic_poly,
|
| 116 |
+
symmetric_poly, random_poly, interpolating_poly)
|
| 117 |
+
|
| 118 |
+
from .orthopolys import (jacobi_poly, chebyshevt_poly, chebyshevu_poly,
|
| 119 |
+
hermite_poly, hermite_prob_poly, legendre_poly, laguerre_poly)
|
| 120 |
+
|
| 121 |
+
from .appellseqs import (bernoulli_poly, bernoulli_c_poly, genocchi_poly,
|
| 122 |
+
euler_poly, andre_poly)
|
| 123 |
+
|
| 124 |
+
from .partfrac import apart, apart_list, assemble_partfrac_list
|
| 125 |
+
|
| 126 |
+
from .polyoptions import Options
|
| 127 |
+
|
| 128 |
+
from .rings import ring, xring, vring, sring
|
| 129 |
+
|
| 130 |
+
from .fields import field, xfield, vfield, sfield
|
venv/lib/python3.14/site-packages/sympy/polys/agca/__init__.py
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Module for algebraic geometry and commutative algebra."""
|
| 2 |
+
|
| 3 |
+
from .homomorphisms import homomorphism
|
| 4 |
+
|
| 5 |
+
__all__ = ['homomorphism']
|
venv/lib/python3.14/site-packages/sympy/polys/agca/extensions.py
ADDED
|
@@ -0,0 +1,356 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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 3 |
+
from sympy.polys.domains.domain import Domain
|
| 4 |
+
from sympy.polys.domains.domainelement import DomainElement
|
| 5 |
+
from sympy.polys.polyerrors import (CoercionFailed, NotInvertible,
|
| 6 |
+
GeneratorsError)
|
| 7 |
+
from sympy.polys.polytools import Poly
|
| 8 |
+
from sympy.printing.defaults import DefaultPrinting
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
class ExtensionElement(DomainElement, DefaultPrinting):
|
| 12 |
+
"""
|
| 13 |
+
Element of a finite extension.
|
| 14 |
+
|
| 15 |
+
A class of univariate polynomials modulo the ``modulus``
|
| 16 |
+
of the extension ``ext``. It is represented by the
|
| 17 |
+
unique polynomial ``rep`` of lowest degree. Both
|
| 18 |
+
``rep`` and the representation ``mod`` of ``modulus``
|
| 19 |
+
are of class DMP.
|
| 20 |
+
|
| 21 |
+
"""
|
| 22 |
+
__slots__ = ('rep', 'ext')
|
| 23 |
+
|
| 24 |
+
def __init__(self, rep, ext):
|
| 25 |
+
self.rep = rep
|
| 26 |
+
self.ext = ext
|
| 27 |
+
|
| 28 |
+
def parent(f):
|
| 29 |
+
return f.ext
|
| 30 |
+
|
| 31 |
+
def as_expr(f):
|
| 32 |
+
return f.ext.to_sympy(f)
|
| 33 |
+
|
| 34 |
+
def __bool__(f):
|
| 35 |
+
return bool(f.rep)
|
| 36 |
+
|
| 37 |
+
def __pos__(f):
|
| 38 |
+
return f
|
| 39 |
+
|
| 40 |
+
def __neg__(f):
|
| 41 |
+
return ExtElem(-f.rep, f.ext)
|
| 42 |
+
|
| 43 |
+
def _get_rep(f, g):
|
| 44 |
+
if isinstance(g, ExtElem):
|
| 45 |
+
if g.ext == f.ext:
|
| 46 |
+
return g.rep
|
| 47 |
+
else:
|
| 48 |
+
return None
|
| 49 |
+
else:
|
| 50 |
+
try:
|
| 51 |
+
g = f.ext.convert(g)
|
| 52 |
+
return g.rep
|
| 53 |
+
except CoercionFailed:
|
| 54 |
+
return None
|
| 55 |
+
|
| 56 |
+
def __add__(f, g):
|
| 57 |
+
rep = f._get_rep(g)
|
| 58 |
+
if rep is not None:
|
| 59 |
+
return ExtElem(f.rep + rep, f.ext)
|
| 60 |
+
else:
|
| 61 |
+
return NotImplemented
|
| 62 |
+
|
| 63 |
+
__radd__ = __add__
|
| 64 |
+
|
| 65 |
+
def __sub__(f, g):
|
| 66 |
+
rep = f._get_rep(g)
|
| 67 |
+
if rep is not None:
|
| 68 |
+
return ExtElem(f.rep - rep, f.ext)
|
| 69 |
+
else:
|
| 70 |
+
return NotImplemented
|
| 71 |
+
|
| 72 |
+
def __rsub__(f, g):
|
| 73 |
+
rep = f._get_rep(g)
|
| 74 |
+
if rep is not None:
|
| 75 |
+
return ExtElem(rep - f.rep, f.ext)
|
| 76 |
+
else:
|
| 77 |
+
return NotImplemented
|
| 78 |
+
|
| 79 |
+
def __mul__(f, g):
|
| 80 |
+
rep = f._get_rep(g)
|
| 81 |
+
if rep is not None:
|
| 82 |
+
return ExtElem((f.rep * rep) % f.ext.mod, f.ext)
|
| 83 |
+
else:
|
| 84 |
+
return NotImplemented
|
| 85 |
+
|
| 86 |
+
__rmul__ = __mul__
|
| 87 |
+
|
| 88 |
+
def _divcheck(f):
|
| 89 |
+
"""Raise if division is not implemented for this divisor"""
|
| 90 |
+
if not f:
|
| 91 |
+
raise NotInvertible('Zero divisor')
|
| 92 |
+
elif f.ext.is_Field:
|
| 93 |
+
return True
|
| 94 |
+
elif f.rep.is_ground and f.ext.domain.is_unit(f.rep.LC()):
|
| 95 |
+
return True
|
| 96 |
+
else:
|
| 97 |
+
# Some cases like (2*x + 2)/2 over ZZ will fail here. It is
|
| 98 |
+
# unclear how to implement division in general if the ground
|
| 99 |
+
# domain is not a field so for now it was decided to restrict the
|
| 100 |
+
# implementation to division by invertible constants.
|
| 101 |
+
msg = (f"Can not invert {f} in {f.ext}. "
|
| 102 |
+
"Only division by invertible constants is implemented.")
|
| 103 |
+
raise NotImplementedError(msg)
|
| 104 |
+
|
| 105 |
+
def inverse(f):
|
| 106 |
+
"""Multiplicative inverse.
|
| 107 |
+
|
| 108 |
+
Raises
|
| 109 |
+
======
|
| 110 |
+
|
| 111 |
+
NotInvertible
|
| 112 |
+
If the element is a zero divisor.
|
| 113 |
+
|
| 114 |
+
"""
|
| 115 |
+
f._divcheck()
|
| 116 |
+
|
| 117 |
+
if f.ext.is_Field:
|
| 118 |
+
invrep = f.rep.invert(f.ext.mod)
|
| 119 |
+
else:
|
| 120 |
+
R = f.ext.ring
|
| 121 |
+
invrep = R.exquo(R.one, f.rep)
|
| 122 |
+
|
| 123 |
+
return ExtElem(invrep, f.ext)
|
| 124 |
+
|
| 125 |
+
def __truediv__(f, g):
|
| 126 |
+
rep = f._get_rep(g)
|
| 127 |
+
if rep is None:
|
| 128 |
+
return NotImplemented
|
| 129 |
+
g = ExtElem(rep, f.ext)
|
| 130 |
+
|
| 131 |
+
try:
|
| 132 |
+
ginv = g.inverse()
|
| 133 |
+
except NotInvertible:
|
| 134 |
+
raise ZeroDivisionError(f"{f} / {g}")
|
| 135 |
+
|
| 136 |
+
return f * ginv
|
| 137 |
+
|
| 138 |
+
__floordiv__ = __truediv__
|
| 139 |
+
|
| 140 |
+
def __rtruediv__(f, g):
|
| 141 |
+
try:
|
| 142 |
+
g = f.ext.convert(g)
|
| 143 |
+
except CoercionFailed:
|
| 144 |
+
return NotImplemented
|
| 145 |
+
return g / f
|
| 146 |
+
|
| 147 |
+
__rfloordiv__ = __rtruediv__
|
| 148 |
+
|
| 149 |
+
def __mod__(f, g):
|
| 150 |
+
rep = f._get_rep(g)
|
| 151 |
+
if rep is None:
|
| 152 |
+
return NotImplemented
|
| 153 |
+
g = ExtElem(rep, f.ext)
|
| 154 |
+
|
| 155 |
+
try:
|
| 156 |
+
g._divcheck()
|
| 157 |
+
except NotInvertible:
|
| 158 |
+
raise ZeroDivisionError(f"{f} % {g}")
|
| 159 |
+
|
| 160 |
+
# Division where defined is always exact so there is no remainder
|
| 161 |
+
return f.ext.zero
|
| 162 |
+
|
| 163 |
+
def __rmod__(f, g):
|
| 164 |
+
try:
|
| 165 |
+
g = f.ext.convert(g)
|
| 166 |
+
except CoercionFailed:
|
| 167 |
+
return NotImplemented
|
| 168 |
+
return g % f
|
| 169 |
+
|
| 170 |
+
def __pow__(f, n):
|
| 171 |
+
if not isinstance(n, int):
|
| 172 |
+
raise TypeError("exponent of type 'int' expected")
|
| 173 |
+
if n < 0:
|
| 174 |
+
try:
|
| 175 |
+
f, n = f.inverse(), -n
|
| 176 |
+
except NotImplementedError:
|
| 177 |
+
raise ValueError("negative powers are not defined")
|
| 178 |
+
|
| 179 |
+
b = f.rep
|
| 180 |
+
m = f.ext.mod
|
| 181 |
+
r = f.ext.one.rep
|
| 182 |
+
while n > 0:
|
| 183 |
+
if n % 2:
|
| 184 |
+
r = (r*b) % m
|
| 185 |
+
b = (b*b) % m
|
| 186 |
+
n //= 2
|
| 187 |
+
|
| 188 |
+
return ExtElem(r, f.ext)
|
| 189 |
+
|
| 190 |
+
def __eq__(f, g):
|
| 191 |
+
if isinstance(g, ExtElem):
|
| 192 |
+
return f.rep == g.rep and f.ext == g.ext
|
| 193 |
+
else:
|
| 194 |
+
return NotImplemented
|
| 195 |
+
|
| 196 |
+
def __ne__(f, g):
|
| 197 |
+
return not f == g
|
| 198 |
+
|
| 199 |
+
def __hash__(f):
|
| 200 |
+
return hash((f.rep, f.ext))
|
| 201 |
+
|
| 202 |
+
def __str__(f):
|
| 203 |
+
from sympy.printing.str import sstr
|
| 204 |
+
return sstr(f.as_expr())
|
| 205 |
+
|
| 206 |
+
__repr__ = __str__
|
| 207 |
+
|
| 208 |
+
@property
|
| 209 |
+
def is_ground(f):
|
| 210 |
+
return f.rep.is_ground
|
| 211 |
+
|
| 212 |
+
def to_ground(f):
|
| 213 |
+
[c] = f.rep.to_list()
|
| 214 |
+
return c
|
| 215 |
+
|
| 216 |
+
ExtElem = ExtensionElement
|
| 217 |
+
|
| 218 |
+
|
| 219 |
+
class MonogenicFiniteExtension(Domain):
|
| 220 |
+
r"""
|
| 221 |
+
Finite extension generated by an integral element.
|
| 222 |
+
|
| 223 |
+
The generator is defined by a monic univariate
|
| 224 |
+
polynomial derived from the argument ``mod``.
|
| 225 |
+
|
| 226 |
+
A shorter alias is ``FiniteExtension``.
|
| 227 |
+
|
| 228 |
+
Examples
|
| 229 |
+
========
|
| 230 |
+
|
| 231 |
+
Quadratic integer ring $\mathbb{Z}[\sqrt2]$:
|
| 232 |
+
|
| 233 |
+
>>> from sympy import Symbol, Poly
|
| 234 |
+
>>> from sympy.polys.agca.extensions import FiniteExtension
|
| 235 |
+
>>> x = Symbol('x')
|
| 236 |
+
>>> R = FiniteExtension(Poly(x**2 - 2)); R
|
| 237 |
+
ZZ[x]/(x**2 - 2)
|
| 238 |
+
>>> R.rank
|
| 239 |
+
2
|
| 240 |
+
>>> R(1 + x)*(3 - 2*x)
|
| 241 |
+
x - 1
|
| 242 |
+
|
| 243 |
+
Finite field $GF(5^3)$ defined by the primitive
|
| 244 |
+
polynomial $x^3 + x^2 + 2$ (over $\mathbb{Z}_5$).
|
| 245 |
+
|
| 246 |
+
>>> F = FiniteExtension(Poly(x**3 + x**2 + 2, modulus=5)); F
|
| 247 |
+
GF(5)[x]/(x**3 + x**2 + 2)
|
| 248 |
+
>>> F.basis
|
| 249 |
+
(1, x, x**2)
|
| 250 |
+
>>> F(x + 3)/(x**2 + 2)
|
| 251 |
+
-2*x**2 + x + 2
|
| 252 |
+
|
| 253 |
+
Function field of an elliptic curve:
|
| 254 |
+
|
| 255 |
+
>>> t = Symbol('t')
|
| 256 |
+
>>> FiniteExtension(Poly(t**2 - x**3 - x + 1, t, field=True))
|
| 257 |
+
ZZ(x)[t]/(t**2 - x**3 - x + 1)
|
| 258 |
+
|
| 259 |
+
"""
|
| 260 |
+
is_FiniteExtension = True
|
| 261 |
+
|
| 262 |
+
dtype = ExtensionElement
|
| 263 |
+
|
| 264 |
+
def __init__(self, mod):
|
| 265 |
+
if not (isinstance(mod, Poly) and mod.is_univariate):
|
| 266 |
+
raise TypeError("modulus must be a univariate Poly")
|
| 267 |
+
|
| 268 |
+
# Using auto=True (default) potentially changes the ground domain to a
|
| 269 |
+
# field whereas auto=False raises if division is not exact. We'll let
|
| 270 |
+
# the caller decide whether or not they want to put the ground domain
|
| 271 |
+
# over a field. In most uses mod is already monic.
|
| 272 |
+
mod = mod.monic(auto=False)
|
| 273 |
+
|
| 274 |
+
self.rank = mod.degree()
|
| 275 |
+
self.modulus = mod
|
| 276 |
+
self.mod = mod.rep # DMP representation
|
| 277 |
+
|
| 278 |
+
self.domain = dom = mod.domain
|
| 279 |
+
self.ring = dom.old_poly_ring(*mod.gens)
|
| 280 |
+
|
| 281 |
+
self.zero = self.convert(self.ring.zero)
|
| 282 |
+
self.one = self.convert(self.ring.one)
|
| 283 |
+
|
| 284 |
+
gen = self.ring.gens[0]
|
| 285 |
+
self.symbol = self.ring.symbols[0]
|
| 286 |
+
self.generator = self.convert(gen)
|
| 287 |
+
self.basis = tuple(self.convert(gen**i) for i in range(self.rank))
|
| 288 |
+
|
| 289 |
+
# XXX: It might be necessary to check mod.is_irreducible here
|
| 290 |
+
self.is_Field = self.domain.is_Field
|
| 291 |
+
|
| 292 |
+
def new(self, arg):
|
| 293 |
+
rep = self.ring.convert(arg)
|
| 294 |
+
return ExtElem(rep % self.mod, self)
|
| 295 |
+
|
| 296 |
+
def __eq__(self, other):
|
| 297 |
+
if not isinstance(other, FiniteExtension):
|
| 298 |
+
return False
|
| 299 |
+
return self.modulus == other.modulus
|
| 300 |
+
|
| 301 |
+
def __hash__(self):
|
| 302 |
+
return hash((self.__class__.__name__, self.modulus))
|
| 303 |
+
|
| 304 |
+
def __str__(self):
|
| 305 |
+
return "%s/(%s)" % (self.ring, self.modulus.as_expr())
|
| 306 |
+
|
| 307 |
+
__repr__ = __str__
|
| 308 |
+
|
| 309 |
+
@property
|
| 310 |
+
def has_CharacteristicZero(self):
|
| 311 |
+
return self.domain.has_CharacteristicZero
|
| 312 |
+
|
| 313 |
+
def characteristic(self):
|
| 314 |
+
return self.domain.characteristic()
|
| 315 |
+
|
| 316 |
+
def convert(self, f, base=None):
|
| 317 |
+
rep = self.ring.convert(f, base)
|
| 318 |
+
return ExtElem(rep % self.mod, self)
|
| 319 |
+
|
| 320 |
+
def convert_from(self, f, base):
|
| 321 |
+
rep = self.ring.convert(f, base)
|
| 322 |
+
return ExtElem(rep % self.mod, self)
|
| 323 |
+
|
| 324 |
+
def to_sympy(self, f):
|
| 325 |
+
return self.ring.to_sympy(f.rep)
|
| 326 |
+
|
| 327 |
+
def from_sympy(self, f):
|
| 328 |
+
return self.convert(f)
|
| 329 |
+
|
| 330 |
+
def set_domain(self, K):
|
| 331 |
+
mod = self.modulus.set_domain(K)
|
| 332 |
+
return self.__class__(mod)
|
| 333 |
+
|
| 334 |
+
def drop(self, *symbols):
|
| 335 |
+
if self.symbol in symbols:
|
| 336 |
+
raise GeneratorsError('Can not drop generator from FiniteExtension')
|
| 337 |
+
K = self.domain.drop(*symbols)
|
| 338 |
+
return self.set_domain(K)
|
| 339 |
+
|
| 340 |
+
def quo(self, f, g):
|
| 341 |
+
return self.exquo(f, g)
|
| 342 |
+
|
| 343 |
+
def exquo(self, f, g):
|
| 344 |
+
rep = self.ring.exquo(f.rep, g.rep)
|
| 345 |
+
return ExtElem(rep % self.mod, self)
|
| 346 |
+
|
| 347 |
+
def is_negative(self, a):
|
| 348 |
+
return False
|
| 349 |
+
|
| 350 |
+
def is_unit(self, a):
|
| 351 |
+
if self.is_Field:
|
| 352 |
+
return bool(a)
|
| 353 |
+
elif a.is_ground:
|
| 354 |
+
return self.domain.is_unit(a.to_ground())
|
| 355 |
+
|
| 356 |
+
FiniteExtension = MonogenicFiniteExtension
|
venv/lib/python3.14/site-packages/sympy/polys/agca/homomorphisms.py
ADDED
|
@@ -0,0 +1,691 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
+
Computations with homomorphisms of modules and rings.
|
| 3 |
+
|
| 4 |
+
This module implements classes for representing homomorphisms of rings and
|
| 5 |
+
their modules. Instead of instantiating the classes directly, you should use
|
| 6 |
+
the function ``homomorphism(from, to, matrix)`` to create homomorphism objects.
|
| 7 |
+
"""
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
from sympy.polys.agca.modules import (Module, FreeModule, QuotientModule,
|
| 11 |
+
SubModule, SubQuotientModule)
|
| 12 |
+
from sympy.polys.polyerrors import CoercionFailed
|
| 13 |
+
|
| 14 |
+
# The main computational task for module homomorphisms is kernels.
|
| 15 |
+
# For this reason, the concrete classes are organised by domain module type.
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
class ModuleHomomorphism:
|
| 19 |
+
"""
|
| 20 |
+
Abstract base class for module homomoprhisms. Do not instantiate.
|
| 21 |
+
|
| 22 |
+
Instead, use the ``homomorphism`` function:
|
| 23 |
+
|
| 24 |
+
>>> from sympy import QQ
|
| 25 |
+
>>> from sympy.abc import x
|
| 26 |
+
>>> from sympy.polys.agca import homomorphism
|
| 27 |
+
|
| 28 |
+
>>> F = QQ.old_poly_ring(x).free_module(2)
|
| 29 |
+
>>> homomorphism(F, F, [[1, 0], [0, 1]])
|
| 30 |
+
Matrix([
|
| 31 |
+
[1, 0], : QQ[x]**2 -> QQ[x]**2
|
| 32 |
+
[0, 1]])
|
| 33 |
+
|
| 34 |
+
Attributes:
|
| 35 |
+
|
| 36 |
+
- ring - the ring over which we are considering modules
|
| 37 |
+
- domain - the domain module
|
| 38 |
+
- codomain - the codomain module
|
| 39 |
+
- _ker - cached kernel
|
| 40 |
+
- _img - cached image
|
| 41 |
+
|
| 42 |
+
Non-implemented methods:
|
| 43 |
+
|
| 44 |
+
- _kernel
|
| 45 |
+
- _image
|
| 46 |
+
- _restrict_domain
|
| 47 |
+
- _restrict_codomain
|
| 48 |
+
- _quotient_domain
|
| 49 |
+
- _quotient_codomain
|
| 50 |
+
- _apply
|
| 51 |
+
- _mul_scalar
|
| 52 |
+
- _compose
|
| 53 |
+
- _add
|
| 54 |
+
"""
|
| 55 |
+
|
| 56 |
+
def __init__(self, domain, codomain):
|
| 57 |
+
if not isinstance(domain, Module):
|
| 58 |
+
raise TypeError('Source must be a module, got %s' % domain)
|
| 59 |
+
if not isinstance(codomain, Module):
|
| 60 |
+
raise TypeError('Target must be a module, got %s' % codomain)
|
| 61 |
+
if domain.ring != codomain.ring:
|
| 62 |
+
raise ValueError('Source and codomain must be over same ring, '
|
| 63 |
+
'got %s != %s' % (domain, codomain))
|
| 64 |
+
self.domain = domain
|
| 65 |
+
self.codomain = codomain
|
| 66 |
+
self.ring = domain.ring
|
| 67 |
+
self._ker = None
|
| 68 |
+
self._img = None
|
| 69 |
+
|
| 70 |
+
def kernel(self):
|
| 71 |
+
r"""
|
| 72 |
+
Compute the kernel of ``self``.
|
| 73 |
+
|
| 74 |
+
That is, if ``self`` is the homomorphism `\phi: M \to N`, then compute
|
| 75 |
+
`ker(\phi) = \{x \in M | \phi(x) = 0\}`. This is a submodule of `M`.
|
| 76 |
+
|
| 77 |
+
Examples
|
| 78 |
+
========
|
| 79 |
+
|
| 80 |
+
>>> from sympy import QQ
|
| 81 |
+
>>> from sympy.abc import x
|
| 82 |
+
>>> from sympy.polys.agca import homomorphism
|
| 83 |
+
|
| 84 |
+
>>> F = QQ.old_poly_ring(x).free_module(2)
|
| 85 |
+
>>> homomorphism(F, F, [[1, 0], [x, 0]]).kernel()
|
| 86 |
+
<[x, -1]>
|
| 87 |
+
"""
|
| 88 |
+
if self._ker is None:
|
| 89 |
+
self._ker = self._kernel()
|
| 90 |
+
return self._ker
|
| 91 |
+
|
| 92 |
+
def image(self):
|
| 93 |
+
r"""
|
| 94 |
+
Compute the image of ``self``.
|
| 95 |
+
|
| 96 |
+
That is, if ``self`` is the homomorphism `\phi: M \to N`, then compute
|
| 97 |
+
`im(\phi) = \{\phi(x) | x \in M \}`. This is a submodule of `N`.
|
| 98 |
+
|
| 99 |
+
Examples
|
| 100 |
+
========
|
| 101 |
+
|
| 102 |
+
>>> from sympy import QQ
|
| 103 |
+
>>> from sympy.abc import x
|
| 104 |
+
>>> from sympy.polys.agca import homomorphism
|
| 105 |
+
|
| 106 |
+
>>> F = QQ.old_poly_ring(x).free_module(2)
|
| 107 |
+
>>> homomorphism(F, F, [[1, 0], [x, 0]]).image() == F.submodule([1, 0])
|
| 108 |
+
True
|
| 109 |
+
"""
|
| 110 |
+
if self._img is None:
|
| 111 |
+
self._img = self._image()
|
| 112 |
+
return self._img
|
| 113 |
+
|
| 114 |
+
def _kernel(self):
|
| 115 |
+
"""Compute the kernel of ``self``."""
|
| 116 |
+
raise NotImplementedError
|
| 117 |
+
|
| 118 |
+
def _image(self):
|
| 119 |
+
"""Compute the image of ``self``."""
|
| 120 |
+
raise NotImplementedError
|
| 121 |
+
|
| 122 |
+
def _restrict_domain(self, sm):
|
| 123 |
+
"""Implementation of domain restriction."""
|
| 124 |
+
raise NotImplementedError
|
| 125 |
+
|
| 126 |
+
def _restrict_codomain(self, sm):
|
| 127 |
+
"""Implementation of codomain restriction."""
|
| 128 |
+
raise NotImplementedError
|
| 129 |
+
|
| 130 |
+
def _quotient_domain(self, sm):
|
| 131 |
+
"""Implementation of domain quotient."""
|
| 132 |
+
raise NotImplementedError
|
| 133 |
+
|
| 134 |
+
def _quotient_codomain(self, sm):
|
| 135 |
+
"""Implementation of codomain quotient."""
|
| 136 |
+
raise NotImplementedError
|
| 137 |
+
|
| 138 |
+
def restrict_domain(self, sm):
|
| 139 |
+
"""
|
| 140 |
+
Return ``self``, with the domain restricted to ``sm``.
|
| 141 |
+
|
| 142 |
+
Here ``sm`` has to be a submodule of ``self.domain``.
|
| 143 |
+
|
| 144 |
+
Examples
|
| 145 |
+
========
|
| 146 |
+
|
| 147 |
+
>>> from sympy import QQ
|
| 148 |
+
>>> from sympy.abc import x
|
| 149 |
+
>>> from sympy.polys.agca import homomorphism
|
| 150 |
+
|
| 151 |
+
>>> F = QQ.old_poly_ring(x).free_module(2)
|
| 152 |
+
>>> h = homomorphism(F, F, [[1, 0], [x, 0]])
|
| 153 |
+
>>> h
|
| 154 |
+
Matrix([
|
| 155 |
+
[1, x], : QQ[x]**2 -> QQ[x]**2
|
| 156 |
+
[0, 0]])
|
| 157 |
+
>>> h.restrict_domain(F.submodule([1, 0]))
|
| 158 |
+
Matrix([
|
| 159 |
+
[1, x], : <[1, 0]> -> QQ[x]**2
|
| 160 |
+
[0, 0]])
|
| 161 |
+
|
| 162 |
+
This is the same as just composing on the right with the submodule
|
| 163 |
+
inclusion:
|
| 164 |
+
|
| 165 |
+
>>> h * F.submodule([1, 0]).inclusion_hom()
|
| 166 |
+
Matrix([
|
| 167 |
+
[1, x], : <[1, 0]> -> QQ[x]**2
|
| 168 |
+
[0, 0]])
|
| 169 |
+
"""
|
| 170 |
+
if not self.domain.is_submodule(sm):
|
| 171 |
+
raise ValueError('sm must be a submodule of %s, got %s'
|
| 172 |
+
% (self.domain, sm))
|
| 173 |
+
if sm == self.domain:
|
| 174 |
+
return self
|
| 175 |
+
return self._restrict_domain(sm)
|
| 176 |
+
|
| 177 |
+
def restrict_codomain(self, sm):
|
| 178 |
+
"""
|
| 179 |
+
Return ``self``, with codomain restricted to to ``sm``.
|
| 180 |
+
|
| 181 |
+
Here ``sm`` has to be a submodule of ``self.codomain`` containing the
|
| 182 |
+
image.
|
| 183 |
+
|
| 184 |
+
Examples
|
| 185 |
+
========
|
| 186 |
+
|
| 187 |
+
>>> from sympy import QQ
|
| 188 |
+
>>> from sympy.abc import x
|
| 189 |
+
>>> from sympy.polys.agca import homomorphism
|
| 190 |
+
|
| 191 |
+
>>> F = QQ.old_poly_ring(x).free_module(2)
|
| 192 |
+
>>> h = homomorphism(F, F, [[1, 0], [x, 0]])
|
| 193 |
+
>>> h
|
| 194 |
+
Matrix([
|
| 195 |
+
[1, x], : QQ[x]**2 -> QQ[x]**2
|
| 196 |
+
[0, 0]])
|
| 197 |
+
>>> h.restrict_codomain(F.submodule([1, 0]))
|
| 198 |
+
Matrix([
|
| 199 |
+
[1, x], : QQ[x]**2 -> <[1, 0]>
|
| 200 |
+
[0, 0]])
|
| 201 |
+
"""
|
| 202 |
+
if not sm.is_submodule(self.image()):
|
| 203 |
+
raise ValueError('the image %s must contain sm, got %s'
|
| 204 |
+
% (self.image(), sm))
|
| 205 |
+
if sm == self.codomain:
|
| 206 |
+
return self
|
| 207 |
+
return self._restrict_codomain(sm)
|
| 208 |
+
|
| 209 |
+
def quotient_domain(self, sm):
|
| 210 |
+
"""
|
| 211 |
+
Return ``self`` with domain replaced by ``domain/sm``.
|
| 212 |
+
|
| 213 |
+
Here ``sm`` must be a submodule of ``self.kernel()``.
|
| 214 |
+
|
| 215 |
+
Examples
|
| 216 |
+
========
|
| 217 |
+
|
| 218 |
+
>>> from sympy import QQ
|
| 219 |
+
>>> from sympy.abc import x
|
| 220 |
+
>>> from sympy.polys.agca import homomorphism
|
| 221 |
+
|
| 222 |
+
>>> F = QQ.old_poly_ring(x).free_module(2)
|
| 223 |
+
>>> h = homomorphism(F, F, [[1, 0], [x, 0]])
|
| 224 |
+
>>> h
|
| 225 |
+
Matrix([
|
| 226 |
+
[1, x], : QQ[x]**2 -> QQ[x]**2
|
| 227 |
+
[0, 0]])
|
| 228 |
+
>>> h.quotient_domain(F.submodule([-x, 1]))
|
| 229 |
+
Matrix([
|
| 230 |
+
[1, x], : QQ[x]**2/<[-x, 1]> -> QQ[x]**2
|
| 231 |
+
[0, 0]])
|
| 232 |
+
"""
|
| 233 |
+
if not self.kernel().is_submodule(sm):
|
| 234 |
+
raise ValueError('kernel %s must contain sm, got %s' %
|
| 235 |
+
(self.kernel(), sm))
|
| 236 |
+
if sm.is_zero():
|
| 237 |
+
return self
|
| 238 |
+
return self._quotient_domain(sm)
|
| 239 |
+
|
| 240 |
+
def quotient_codomain(self, sm):
|
| 241 |
+
"""
|
| 242 |
+
Return ``self`` with codomain replaced by ``codomain/sm``.
|
| 243 |
+
|
| 244 |
+
Here ``sm`` must be a submodule of ``self.codomain``.
|
| 245 |
+
|
| 246 |
+
Examples
|
| 247 |
+
========
|
| 248 |
+
|
| 249 |
+
>>> from sympy import QQ
|
| 250 |
+
>>> from sympy.abc import x
|
| 251 |
+
>>> from sympy.polys.agca import homomorphism
|
| 252 |
+
|
| 253 |
+
>>> F = QQ.old_poly_ring(x).free_module(2)
|
| 254 |
+
>>> h = homomorphism(F, F, [[1, 0], [x, 0]])
|
| 255 |
+
>>> h
|
| 256 |
+
Matrix([
|
| 257 |
+
[1, x], : QQ[x]**2 -> QQ[x]**2
|
| 258 |
+
[0, 0]])
|
| 259 |
+
>>> h.quotient_codomain(F.submodule([1, 1]))
|
| 260 |
+
Matrix([
|
| 261 |
+
[1, x], : QQ[x]**2 -> QQ[x]**2/<[1, 1]>
|
| 262 |
+
[0, 0]])
|
| 263 |
+
|
| 264 |
+
This is the same as composing with the quotient map on the left:
|
| 265 |
+
|
| 266 |
+
>>> (F/[(1, 1)]).quotient_hom() * h
|
| 267 |
+
Matrix([
|
| 268 |
+
[1, x], : QQ[x]**2 -> QQ[x]**2/<[1, 1]>
|
| 269 |
+
[0, 0]])
|
| 270 |
+
"""
|
| 271 |
+
if not self.codomain.is_submodule(sm):
|
| 272 |
+
raise ValueError('sm must be a submodule of codomain %s, got %s'
|
| 273 |
+
% (self.codomain, sm))
|
| 274 |
+
if sm.is_zero():
|
| 275 |
+
return self
|
| 276 |
+
return self._quotient_codomain(sm)
|
| 277 |
+
|
| 278 |
+
def _apply(self, elem):
|
| 279 |
+
"""Apply ``self`` to ``elem``."""
|
| 280 |
+
raise NotImplementedError
|
| 281 |
+
|
| 282 |
+
def __call__(self, elem):
|
| 283 |
+
return self.codomain.convert(self._apply(self.domain.convert(elem)))
|
| 284 |
+
|
| 285 |
+
def _compose(self, oth):
|
| 286 |
+
"""
|
| 287 |
+
Compose ``self`` with ``oth``, that is, return the homomorphism
|
| 288 |
+
obtained by first applying then ``self``, then ``oth``.
|
| 289 |
+
|
| 290 |
+
(This method is private since in this syntax, it is non-obvious which
|
| 291 |
+
homomorphism is executed first.)
|
| 292 |
+
"""
|
| 293 |
+
raise NotImplementedError
|
| 294 |
+
|
| 295 |
+
def _mul_scalar(self, c):
|
| 296 |
+
"""Scalar multiplication. ``c`` is guaranteed in self.ring."""
|
| 297 |
+
raise NotImplementedError
|
| 298 |
+
|
| 299 |
+
def _add(self, oth):
|
| 300 |
+
"""
|
| 301 |
+
Homomorphism addition.
|
| 302 |
+
``oth`` is guaranteed to be a homomorphism with same domain/codomain.
|
| 303 |
+
"""
|
| 304 |
+
raise NotImplementedError
|
| 305 |
+
|
| 306 |
+
def _check_hom(self, oth):
|
| 307 |
+
"""Helper to check that oth is a homomorphism with same domain/codomain."""
|
| 308 |
+
if not isinstance(oth, ModuleHomomorphism):
|
| 309 |
+
return False
|
| 310 |
+
return oth.domain == self.domain and oth.codomain == self.codomain
|
| 311 |
+
|
| 312 |
+
def __mul__(self, oth):
|
| 313 |
+
if isinstance(oth, ModuleHomomorphism) and self.domain == oth.codomain:
|
| 314 |
+
return oth._compose(self)
|
| 315 |
+
try:
|
| 316 |
+
return self._mul_scalar(self.ring.convert(oth))
|
| 317 |
+
except CoercionFailed:
|
| 318 |
+
return NotImplemented
|
| 319 |
+
|
| 320 |
+
# NOTE: _compose will never be called from rmul
|
| 321 |
+
__rmul__ = __mul__
|
| 322 |
+
|
| 323 |
+
def __truediv__(self, oth):
|
| 324 |
+
try:
|
| 325 |
+
return self._mul_scalar(1/self.ring.convert(oth))
|
| 326 |
+
except CoercionFailed:
|
| 327 |
+
return NotImplemented
|
| 328 |
+
|
| 329 |
+
def __add__(self, oth):
|
| 330 |
+
if self._check_hom(oth):
|
| 331 |
+
return self._add(oth)
|
| 332 |
+
return NotImplemented
|
| 333 |
+
|
| 334 |
+
def __sub__(self, oth):
|
| 335 |
+
if self._check_hom(oth):
|
| 336 |
+
return self._add(oth._mul_scalar(self.ring.convert(-1)))
|
| 337 |
+
return NotImplemented
|
| 338 |
+
|
| 339 |
+
def is_injective(self):
|
| 340 |
+
"""
|
| 341 |
+
Return True if ``self`` is injective.
|
| 342 |
+
|
| 343 |
+
That is, check if the elements of the domain are mapped to the same
|
| 344 |
+
codomain element.
|
| 345 |
+
|
| 346 |
+
Examples
|
| 347 |
+
========
|
| 348 |
+
|
| 349 |
+
>>> from sympy import QQ
|
| 350 |
+
>>> from sympy.abc import x
|
| 351 |
+
>>> from sympy.polys.agca import homomorphism
|
| 352 |
+
|
| 353 |
+
>>> F = QQ.old_poly_ring(x).free_module(2)
|
| 354 |
+
>>> h = homomorphism(F, F, [[1, 0], [x, 0]])
|
| 355 |
+
>>> h.is_injective()
|
| 356 |
+
False
|
| 357 |
+
>>> h.quotient_domain(h.kernel()).is_injective()
|
| 358 |
+
True
|
| 359 |
+
"""
|
| 360 |
+
return self.kernel().is_zero()
|
| 361 |
+
|
| 362 |
+
def is_surjective(self):
|
| 363 |
+
"""
|
| 364 |
+
Return True if ``self`` is surjective.
|
| 365 |
+
|
| 366 |
+
That is, check if every element of the codomain has at least one
|
| 367 |
+
preimage.
|
| 368 |
+
|
| 369 |
+
Examples
|
| 370 |
+
========
|
| 371 |
+
|
| 372 |
+
>>> from sympy import QQ
|
| 373 |
+
>>> from sympy.abc import x
|
| 374 |
+
>>> from sympy.polys.agca import homomorphism
|
| 375 |
+
|
| 376 |
+
>>> F = QQ.old_poly_ring(x).free_module(2)
|
| 377 |
+
>>> h = homomorphism(F, F, [[1, 0], [x, 0]])
|
| 378 |
+
>>> h.is_surjective()
|
| 379 |
+
False
|
| 380 |
+
>>> h.restrict_codomain(h.image()).is_surjective()
|
| 381 |
+
True
|
| 382 |
+
"""
|
| 383 |
+
return self.image() == self.codomain
|
| 384 |
+
|
| 385 |
+
def is_isomorphism(self):
|
| 386 |
+
"""
|
| 387 |
+
Return True if ``self`` is an isomorphism.
|
| 388 |
+
|
| 389 |
+
That is, check if every element of the codomain has precisely one
|
| 390 |
+
preimage. Equivalently, ``self`` is both injective and surjective.
|
| 391 |
+
|
| 392 |
+
Examples
|
| 393 |
+
========
|
| 394 |
+
|
| 395 |
+
>>> from sympy import QQ
|
| 396 |
+
>>> from sympy.abc import x
|
| 397 |
+
>>> from sympy.polys.agca import homomorphism
|
| 398 |
+
|
| 399 |
+
>>> F = QQ.old_poly_ring(x).free_module(2)
|
| 400 |
+
>>> h = homomorphism(F, F, [[1, 0], [x, 0]])
|
| 401 |
+
>>> h = h.restrict_codomain(h.image())
|
| 402 |
+
>>> h.is_isomorphism()
|
| 403 |
+
False
|
| 404 |
+
>>> h.quotient_domain(h.kernel()).is_isomorphism()
|
| 405 |
+
True
|
| 406 |
+
"""
|
| 407 |
+
return self.is_injective() and self.is_surjective()
|
| 408 |
+
|
| 409 |
+
def is_zero(self):
|
| 410 |
+
"""
|
| 411 |
+
Return True if ``self`` is a zero morphism.
|
| 412 |
+
|
| 413 |
+
That is, check if every element of the domain is mapped to zero
|
| 414 |
+
under self.
|
| 415 |
+
|
| 416 |
+
Examples
|
| 417 |
+
========
|
| 418 |
+
|
| 419 |
+
>>> from sympy import QQ
|
| 420 |
+
>>> from sympy.abc import x
|
| 421 |
+
>>> from sympy.polys.agca import homomorphism
|
| 422 |
+
|
| 423 |
+
>>> F = QQ.old_poly_ring(x).free_module(2)
|
| 424 |
+
>>> h = homomorphism(F, F, [[1, 0], [x, 0]])
|
| 425 |
+
>>> h.is_zero()
|
| 426 |
+
False
|
| 427 |
+
>>> h.restrict_domain(F.submodule()).is_zero()
|
| 428 |
+
True
|
| 429 |
+
>>> h.quotient_codomain(h.image()).is_zero()
|
| 430 |
+
True
|
| 431 |
+
"""
|
| 432 |
+
return self.image().is_zero()
|
| 433 |
+
|
| 434 |
+
def __eq__(self, oth):
|
| 435 |
+
try:
|
| 436 |
+
return (self - oth).is_zero()
|
| 437 |
+
except TypeError:
|
| 438 |
+
return False
|
| 439 |
+
|
| 440 |
+
def __ne__(self, oth):
|
| 441 |
+
return not (self == oth)
|
| 442 |
+
|
| 443 |
+
|
| 444 |
+
class MatrixHomomorphism(ModuleHomomorphism):
|
| 445 |
+
r"""
|
| 446 |
+
Helper class for all homomoprhisms which are expressed via a matrix.
|
| 447 |
+
|
| 448 |
+
That is, for such homomorphisms ``domain`` is contained in a module
|
| 449 |
+
generated by finitely many elements `e_1, \ldots, e_n`, so that the
|
| 450 |
+
homomorphism is determined uniquely by its action on the `e_i`. It
|
| 451 |
+
can thus be represented as a vector of elements of the codomain module,
|
| 452 |
+
or potentially a supermodule of the codomain module
|
| 453 |
+
(and hence conventionally as a matrix, if there is a similar interpretation
|
| 454 |
+
for elements of the codomain module).
|
| 455 |
+
|
| 456 |
+
Note that this class does *not* assume that the `e_i` freely generate a
|
| 457 |
+
submodule, nor that ``domain`` is even all of this submodule. It exists
|
| 458 |
+
only to unify the interface.
|
| 459 |
+
|
| 460 |
+
Do not instantiate.
|
| 461 |
+
|
| 462 |
+
Attributes:
|
| 463 |
+
|
| 464 |
+
- matrix - the list of images determining the homomorphism.
|
| 465 |
+
NOTE: the elements of matrix belong to either self.codomain or
|
| 466 |
+
self.codomain.container
|
| 467 |
+
|
| 468 |
+
Still non-implemented methods:
|
| 469 |
+
|
| 470 |
+
- kernel
|
| 471 |
+
- _apply
|
| 472 |
+
"""
|
| 473 |
+
|
| 474 |
+
def __init__(self, domain, codomain, matrix):
|
| 475 |
+
ModuleHomomorphism.__init__(self, domain, codomain)
|
| 476 |
+
if len(matrix) != domain.rank:
|
| 477 |
+
raise ValueError('Need to provide %s elements, got %s'
|
| 478 |
+
% (domain.rank, len(matrix)))
|
| 479 |
+
|
| 480 |
+
converter = self.codomain.convert
|
| 481 |
+
if isinstance(self.codomain, (SubModule, SubQuotientModule)):
|
| 482 |
+
converter = self.codomain.container.convert
|
| 483 |
+
self.matrix = tuple(converter(x) for x in matrix)
|
| 484 |
+
|
| 485 |
+
def _sympy_matrix(self):
|
| 486 |
+
"""Helper function which returns a SymPy matrix ``self.matrix``."""
|
| 487 |
+
from sympy.matrices import Matrix
|
| 488 |
+
c = lambda x: x
|
| 489 |
+
if isinstance(self.codomain, (QuotientModule, SubQuotientModule)):
|
| 490 |
+
c = lambda x: x.data
|
| 491 |
+
return Matrix([[self.ring.to_sympy(y) for y in c(x)] for x in self.matrix]).T
|
| 492 |
+
|
| 493 |
+
def __repr__(self):
|
| 494 |
+
lines = repr(self._sympy_matrix()).split('\n')
|
| 495 |
+
t = " : %s -> %s" % (self.domain, self.codomain)
|
| 496 |
+
s = ' '*len(t)
|
| 497 |
+
n = len(lines)
|
| 498 |
+
for i in range(n // 2):
|
| 499 |
+
lines[i] += s
|
| 500 |
+
lines[n // 2] += t
|
| 501 |
+
for i in range(n//2 + 1, n):
|
| 502 |
+
lines[i] += s
|
| 503 |
+
return '\n'.join(lines)
|
| 504 |
+
|
| 505 |
+
def _restrict_domain(self, sm):
|
| 506 |
+
"""Implementation of domain restriction."""
|
| 507 |
+
return SubModuleHomomorphism(sm, self.codomain, self.matrix)
|
| 508 |
+
|
| 509 |
+
def _restrict_codomain(self, sm):
|
| 510 |
+
"""Implementation of codomain restriction."""
|
| 511 |
+
return self.__class__(self.domain, sm, self.matrix)
|
| 512 |
+
|
| 513 |
+
def _quotient_domain(self, sm):
|
| 514 |
+
"""Implementation of domain quotient."""
|
| 515 |
+
return self.__class__(self.domain/sm, self.codomain, self.matrix)
|
| 516 |
+
|
| 517 |
+
def _quotient_codomain(self, sm):
|
| 518 |
+
"""Implementation of codomain quotient."""
|
| 519 |
+
Q = self.codomain/sm
|
| 520 |
+
converter = Q.convert
|
| 521 |
+
if isinstance(self.codomain, SubModule):
|
| 522 |
+
converter = Q.container.convert
|
| 523 |
+
return self.__class__(self.domain, self.codomain/sm,
|
| 524 |
+
[converter(x) for x in self.matrix])
|
| 525 |
+
|
| 526 |
+
def _add(self, oth):
|
| 527 |
+
return self.__class__(self.domain, self.codomain,
|
| 528 |
+
[x + y for x, y in zip(self.matrix, oth.matrix)])
|
| 529 |
+
|
| 530 |
+
def _mul_scalar(self, c):
|
| 531 |
+
return self.__class__(self.domain, self.codomain, [c*x for x in self.matrix])
|
| 532 |
+
|
| 533 |
+
def _compose(self, oth):
|
| 534 |
+
return self.__class__(self.domain, oth.codomain, [oth(x) for x in self.matrix])
|
| 535 |
+
|
| 536 |
+
|
| 537 |
+
class FreeModuleHomomorphism(MatrixHomomorphism):
|
| 538 |
+
"""
|
| 539 |
+
Concrete class for homomorphisms with domain a free module or a quotient
|
| 540 |
+
thereof.
|
| 541 |
+
|
| 542 |
+
Do not instantiate; the constructor does not check that your data is well
|
| 543 |
+
defined. Use the ``homomorphism`` function instead:
|
| 544 |
+
|
| 545 |
+
>>> from sympy import QQ
|
| 546 |
+
>>> from sympy.abc import x
|
| 547 |
+
>>> from sympy.polys.agca import homomorphism
|
| 548 |
+
|
| 549 |
+
>>> F = QQ.old_poly_ring(x).free_module(2)
|
| 550 |
+
>>> homomorphism(F, F, [[1, 0], [0, 1]])
|
| 551 |
+
Matrix([
|
| 552 |
+
[1, 0], : QQ[x]**2 -> QQ[x]**2
|
| 553 |
+
[0, 1]])
|
| 554 |
+
"""
|
| 555 |
+
|
| 556 |
+
def _apply(self, elem):
|
| 557 |
+
if isinstance(self.domain, QuotientModule):
|
| 558 |
+
elem = elem.data
|
| 559 |
+
return sum(x * e for x, e in zip(elem, self.matrix))
|
| 560 |
+
|
| 561 |
+
def _image(self):
|
| 562 |
+
return self.codomain.submodule(*self.matrix)
|
| 563 |
+
|
| 564 |
+
def _kernel(self):
|
| 565 |
+
# The domain is either a free module or a quotient thereof.
|
| 566 |
+
# It does not matter if it is a quotient, because that won't increase
|
| 567 |
+
# the kernel.
|
| 568 |
+
# Our generators {e_i} are sent to the matrix entries {b_i}.
|
| 569 |
+
# The kernel is essentially the syzygy module of these {b_i}.
|
| 570 |
+
syz = self.image().syzygy_module()
|
| 571 |
+
return self.domain.submodule(*syz.gens)
|
| 572 |
+
|
| 573 |
+
|
| 574 |
+
class SubModuleHomomorphism(MatrixHomomorphism):
|
| 575 |
+
"""
|
| 576 |
+
Concrete class for homomorphism with domain a submodule of a free module
|
| 577 |
+
or a quotient thereof.
|
| 578 |
+
|
| 579 |
+
Do not instantiate; the constructor does not check that your data is well
|
| 580 |
+
defined. Use the ``homomorphism`` function instead:
|
| 581 |
+
|
| 582 |
+
>>> from sympy import QQ
|
| 583 |
+
>>> from sympy.abc import x
|
| 584 |
+
>>> from sympy.polys.agca import homomorphism
|
| 585 |
+
|
| 586 |
+
>>> M = QQ.old_poly_ring(x).free_module(2)*x
|
| 587 |
+
>>> homomorphism(M, M, [[1, 0], [0, 1]])
|
| 588 |
+
Matrix([
|
| 589 |
+
[1, 0], : <[x, 0], [0, x]> -> <[x, 0], [0, x]>
|
| 590 |
+
[0, 1]])
|
| 591 |
+
"""
|
| 592 |
+
|
| 593 |
+
def _apply(self, elem):
|
| 594 |
+
if isinstance(self.domain, SubQuotientModule):
|
| 595 |
+
elem = elem.data
|
| 596 |
+
return sum(x * e for x, e in zip(elem, self.matrix))
|
| 597 |
+
|
| 598 |
+
def _image(self):
|
| 599 |
+
return self.codomain.submodule(*[self(x) for x in self.domain.gens])
|
| 600 |
+
|
| 601 |
+
def _kernel(self):
|
| 602 |
+
syz = self.image().syzygy_module()
|
| 603 |
+
return self.domain.submodule(
|
| 604 |
+
*[sum(xi*gi for xi, gi in zip(s, self.domain.gens))
|
| 605 |
+
for s in syz.gens])
|
| 606 |
+
|
| 607 |
+
|
| 608 |
+
def homomorphism(domain, codomain, matrix):
|
| 609 |
+
r"""
|
| 610 |
+
Create a homomorphism object.
|
| 611 |
+
|
| 612 |
+
This function tries to build a homomorphism from ``domain`` to ``codomain``
|
| 613 |
+
via the matrix ``matrix``.
|
| 614 |
+
|
| 615 |
+
Examples
|
| 616 |
+
========
|
| 617 |
+
|
| 618 |
+
>>> from sympy import QQ
|
| 619 |
+
>>> from sympy.abc import x
|
| 620 |
+
>>> from sympy.polys.agca import homomorphism
|
| 621 |
+
|
| 622 |
+
>>> R = QQ.old_poly_ring(x)
|
| 623 |
+
>>> T = R.free_module(2)
|
| 624 |
+
|
| 625 |
+
If ``domain`` is a free module generated by `e_1, \ldots, e_n`, then
|
| 626 |
+
``matrix`` should be an n-element iterable `(b_1, \ldots, b_n)` where
|
| 627 |
+
the `b_i` are elements of ``codomain``. The constructed homomorphism is the
|
| 628 |
+
unique homomorphism sending `e_i` to `b_i`.
|
| 629 |
+
|
| 630 |
+
>>> F = R.free_module(2)
|
| 631 |
+
>>> h = homomorphism(F, T, [[1, x], [x**2, 0]])
|
| 632 |
+
>>> h
|
| 633 |
+
Matrix([
|
| 634 |
+
[1, x**2], : QQ[x]**2 -> QQ[x]**2
|
| 635 |
+
[x, 0]])
|
| 636 |
+
>>> h([1, 0])
|
| 637 |
+
[1, x]
|
| 638 |
+
>>> h([0, 1])
|
| 639 |
+
[x**2, 0]
|
| 640 |
+
>>> h([1, 1])
|
| 641 |
+
[x**2 + 1, x]
|
| 642 |
+
|
| 643 |
+
If ``domain`` is a submodule of a free module, them ``matrix`` determines
|
| 644 |
+
a homomoprhism from the containing free module to ``codomain``, and the
|
| 645 |
+
homomorphism returned is obtained by restriction to ``domain``.
|
| 646 |
+
|
| 647 |
+
>>> S = F.submodule([1, 0], [0, x])
|
| 648 |
+
>>> homomorphism(S, T, [[1, x], [x**2, 0]])
|
| 649 |
+
Matrix([
|
| 650 |
+
[1, x**2], : <[1, 0], [0, x]> -> QQ[x]**2
|
| 651 |
+
[x, 0]])
|
| 652 |
+
|
| 653 |
+
If ``domain`` is a (sub)quotient `N/K`, then ``matrix`` determines a
|
| 654 |
+
homomorphism from `N` to ``codomain``. If the kernel contains `K`, this
|
| 655 |
+
homomorphism descends to ``domain`` and is returned; otherwise an exception
|
| 656 |
+
is raised.
|
| 657 |
+
|
| 658 |
+
>>> homomorphism(S/[(1, 0)], T, [0, [x**2, 0]])
|
| 659 |
+
Matrix([
|
| 660 |
+
[0, x**2], : <[1, 0] + <[1, 0]>, [0, x] + <[1, 0]>, [1, 0] + <[1, 0]>> -> QQ[x]**2
|
| 661 |
+
[0, 0]])
|
| 662 |
+
>>> homomorphism(S/[(0, x)], T, [0, [x**2, 0]])
|
| 663 |
+
Traceback (most recent call last):
|
| 664 |
+
...
|
| 665 |
+
ValueError: kernel <[1, 0], [0, 0]> must contain sm, got <[0,x]>
|
| 666 |
+
|
| 667 |
+
"""
|
| 668 |
+
def freepres(module):
|
| 669 |
+
"""
|
| 670 |
+
Return a tuple ``(F, S, Q, c)`` where ``F`` is a free module, ``S`` is a
|
| 671 |
+
submodule of ``F``, and ``Q`` a submodule of ``S``, such that
|
| 672 |
+
``module = S/Q``, and ``c`` is a conversion function.
|
| 673 |
+
"""
|
| 674 |
+
if isinstance(module, FreeModule):
|
| 675 |
+
return module, module, module.submodule(), lambda x: module.convert(x)
|
| 676 |
+
if isinstance(module, QuotientModule):
|
| 677 |
+
return (module.base, module.base, module.killed_module,
|
| 678 |
+
lambda x: module.convert(x).data)
|
| 679 |
+
if isinstance(module, SubQuotientModule):
|
| 680 |
+
return (module.base.container, module.base, module.killed_module,
|
| 681 |
+
lambda x: module.container.convert(x).data)
|
| 682 |
+
# an ordinary submodule
|
| 683 |
+
return (module.container, module, module.submodule(),
|
| 684 |
+
lambda x: module.container.convert(x))
|
| 685 |
+
|
| 686 |
+
SF, SS, SQ, _ = freepres(domain)
|
| 687 |
+
TF, TS, TQ, c = freepres(codomain)
|
| 688 |
+
# NOTE this is probably a bit inefficient (redundant checks)
|
| 689 |
+
return FreeModuleHomomorphism(SF, TF, [c(x) for x in matrix]
|
| 690 |
+
).restrict_domain(SS).restrict_codomain(TS
|
| 691 |
+
).quotient_codomain(TQ).quotient_domain(SQ)
|
venv/lib/python3.14/site-packages/sympy/polys/agca/ideals.py
ADDED
|
@@ -0,0 +1,395 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Computations with ideals of polynomial rings."""
|
| 2 |
+
|
| 3 |
+
from sympy.polys.polyerrors import CoercionFailed
|
| 4 |
+
from sympy.polys.polyutils import IntegerPowerable
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
class Ideal(IntegerPowerable):
|
| 8 |
+
"""
|
| 9 |
+
Abstract base class for ideals.
|
| 10 |
+
|
| 11 |
+
Do not instantiate - use explicit constructors in the ring class instead:
|
| 12 |
+
|
| 13 |
+
>>> from sympy import QQ
|
| 14 |
+
>>> from sympy.abc import x
|
| 15 |
+
>>> QQ.old_poly_ring(x).ideal(x+1)
|
| 16 |
+
<x + 1>
|
| 17 |
+
|
| 18 |
+
Attributes
|
| 19 |
+
|
| 20 |
+
- ring - the ring this ideal belongs to
|
| 21 |
+
|
| 22 |
+
Non-implemented methods:
|
| 23 |
+
|
| 24 |
+
- _contains_elem
|
| 25 |
+
- _contains_ideal
|
| 26 |
+
- _quotient
|
| 27 |
+
- _intersect
|
| 28 |
+
- _union
|
| 29 |
+
- _product
|
| 30 |
+
- is_whole_ring
|
| 31 |
+
- is_zero
|
| 32 |
+
- is_prime, is_maximal, is_primary, is_radical
|
| 33 |
+
- is_principal
|
| 34 |
+
- height, depth
|
| 35 |
+
- radical
|
| 36 |
+
|
| 37 |
+
Methods that likely should be overridden in subclasses:
|
| 38 |
+
|
| 39 |
+
- reduce_element
|
| 40 |
+
"""
|
| 41 |
+
|
| 42 |
+
def _contains_elem(self, x):
|
| 43 |
+
"""Implementation of element containment."""
|
| 44 |
+
raise NotImplementedError
|
| 45 |
+
|
| 46 |
+
def _contains_ideal(self, I):
|
| 47 |
+
"""Implementation of ideal containment."""
|
| 48 |
+
raise NotImplementedError
|
| 49 |
+
|
| 50 |
+
def _quotient(self, J):
|
| 51 |
+
"""Implementation of ideal quotient."""
|
| 52 |
+
raise NotImplementedError
|
| 53 |
+
|
| 54 |
+
def _intersect(self, J):
|
| 55 |
+
"""Implementation of ideal intersection."""
|
| 56 |
+
raise NotImplementedError
|
| 57 |
+
|
| 58 |
+
def is_whole_ring(self):
|
| 59 |
+
"""Return True if ``self`` is the whole ring."""
|
| 60 |
+
raise NotImplementedError
|
| 61 |
+
|
| 62 |
+
def is_zero(self):
|
| 63 |
+
"""Return True if ``self`` is the zero ideal."""
|
| 64 |
+
raise NotImplementedError
|
| 65 |
+
|
| 66 |
+
def _equals(self, J):
|
| 67 |
+
"""Implementation of ideal equality."""
|
| 68 |
+
return self._contains_ideal(J) and J._contains_ideal(self)
|
| 69 |
+
|
| 70 |
+
def is_prime(self):
|
| 71 |
+
"""Return True if ``self`` is a prime ideal."""
|
| 72 |
+
raise NotImplementedError
|
| 73 |
+
|
| 74 |
+
def is_maximal(self):
|
| 75 |
+
"""Return True if ``self`` is a maximal ideal."""
|
| 76 |
+
raise NotImplementedError
|
| 77 |
+
|
| 78 |
+
def is_radical(self):
|
| 79 |
+
"""Return True if ``self`` is a radical ideal."""
|
| 80 |
+
raise NotImplementedError
|
| 81 |
+
|
| 82 |
+
def is_primary(self):
|
| 83 |
+
"""Return True if ``self`` is a primary ideal."""
|
| 84 |
+
raise NotImplementedError
|
| 85 |
+
|
| 86 |
+
def is_principal(self):
|
| 87 |
+
"""Return True if ``self`` is a principal ideal."""
|
| 88 |
+
raise NotImplementedError
|
| 89 |
+
|
| 90 |
+
def radical(self):
|
| 91 |
+
"""Compute the radical of ``self``."""
|
| 92 |
+
raise NotImplementedError
|
| 93 |
+
|
| 94 |
+
def depth(self):
|
| 95 |
+
"""Compute the depth of ``self``."""
|
| 96 |
+
raise NotImplementedError
|
| 97 |
+
|
| 98 |
+
def height(self):
|
| 99 |
+
"""Compute the height of ``self``."""
|
| 100 |
+
raise NotImplementedError
|
| 101 |
+
|
| 102 |
+
# TODO more
|
| 103 |
+
|
| 104 |
+
# non-implemented methods end here
|
| 105 |
+
|
| 106 |
+
def __init__(self, ring):
|
| 107 |
+
self.ring = ring
|
| 108 |
+
|
| 109 |
+
def _check_ideal(self, J):
|
| 110 |
+
"""Helper to check ``J`` is an ideal of our ring."""
|
| 111 |
+
if not isinstance(J, Ideal) or J.ring != self.ring:
|
| 112 |
+
raise ValueError(
|
| 113 |
+
'J must be an ideal of %s, got %s' % (self.ring, J))
|
| 114 |
+
|
| 115 |
+
def contains(self, elem):
|
| 116 |
+
"""
|
| 117 |
+
Return True if ``elem`` is an element of this ideal.
|
| 118 |
+
|
| 119 |
+
Examples
|
| 120 |
+
========
|
| 121 |
+
|
| 122 |
+
>>> from sympy.abc import x
|
| 123 |
+
>>> from sympy import QQ
|
| 124 |
+
>>> QQ.old_poly_ring(x).ideal(x+1, x-1).contains(3)
|
| 125 |
+
True
|
| 126 |
+
>>> QQ.old_poly_ring(x).ideal(x**2, x**3).contains(x)
|
| 127 |
+
False
|
| 128 |
+
"""
|
| 129 |
+
return self._contains_elem(self.ring.convert(elem))
|
| 130 |
+
|
| 131 |
+
def subset(self, other):
|
| 132 |
+
"""
|
| 133 |
+
Returns True if ``other`` is is a subset of ``self``.
|
| 134 |
+
|
| 135 |
+
Here ``other`` may be an ideal.
|
| 136 |
+
|
| 137 |
+
Examples
|
| 138 |
+
========
|
| 139 |
+
|
| 140 |
+
>>> from sympy.abc import x
|
| 141 |
+
>>> from sympy import QQ
|
| 142 |
+
>>> I = QQ.old_poly_ring(x).ideal(x+1)
|
| 143 |
+
>>> I.subset([x**2 - 1, x**2 + 2*x + 1])
|
| 144 |
+
True
|
| 145 |
+
>>> I.subset([x**2 + 1, x + 1])
|
| 146 |
+
False
|
| 147 |
+
>>> I.subset(QQ.old_poly_ring(x).ideal(x**2 - 1))
|
| 148 |
+
True
|
| 149 |
+
"""
|
| 150 |
+
if isinstance(other, Ideal):
|
| 151 |
+
return self._contains_ideal(other)
|
| 152 |
+
return all(self._contains_elem(x) for x in other)
|
| 153 |
+
|
| 154 |
+
def quotient(self, J, **opts):
|
| 155 |
+
r"""
|
| 156 |
+
Compute the ideal quotient of ``self`` by ``J``.
|
| 157 |
+
|
| 158 |
+
That is, if ``self`` is the ideal `I`, compute the set
|
| 159 |
+
`I : J = \{x \in R | xJ \subset I \}`.
|
| 160 |
+
|
| 161 |
+
Examples
|
| 162 |
+
========
|
| 163 |
+
|
| 164 |
+
>>> from sympy.abc import x, y
|
| 165 |
+
>>> from sympy import QQ
|
| 166 |
+
>>> R = QQ.old_poly_ring(x, y)
|
| 167 |
+
>>> R.ideal(x*y).quotient(R.ideal(x))
|
| 168 |
+
<y>
|
| 169 |
+
"""
|
| 170 |
+
self._check_ideal(J)
|
| 171 |
+
return self._quotient(J, **opts)
|
| 172 |
+
|
| 173 |
+
def intersect(self, J):
|
| 174 |
+
"""
|
| 175 |
+
Compute the intersection of self with ideal J.
|
| 176 |
+
|
| 177 |
+
Examples
|
| 178 |
+
========
|
| 179 |
+
|
| 180 |
+
>>> from sympy.abc import x, y
|
| 181 |
+
>>> from sympy import QQ
|
| 182 |
+
>>> R = QQ.old_poly_ring(x, y)
|
| 183 |
+
>>> R.ideal(x).intersect(R.ideal(y))
|
| 184 |
+
<x*y>
|
| 185 |
+
"""
|
| 186 |
+
self._check_ideal(J)
|
| 187 |
+
return self._intersect(J)
|
| 188 |
+
|
| 189 |
+
def saturate(self, J):
|
| 190 |
+
r"""
|
| 191 |
+
Compute the ideal saturation of ``self`` by ``J``.
|
| 192 |
+
|
| 193 |
+
That is, if ``self`` is the ideal `I`, compute the set
|
| 194 |
+
`I : J^\infty = \{x \in R | xJ^n \subset I \text{ for some } n\}`.
|
| 195 |
+
"""
|
| 196 |
+
raise NotImplementedError
|
| 197 |
+
# Note this can be implemented using repeated quotient
|
| 198 |
+
|
| 199 |
+
def union(self, J):
|
| 200 |
+
"""
|
| 201 |
+
Compute the ideal generated by the union of ``self`` and ``J``.
|
| 202 |
+
|
| 203 |
+
Examples
|
| 204 |
+
========
|
| 205 |
+
|
| 206 |
+
>>> from sympy.abc import x
|
| 207 |
+
>>> from sympy import QQ
|
| 208 |
+
>>> QQ.old_poly_ring(x).ideal(x**2 - 1).union(QQ.old_poly_ring(x).ideal((x+1)**2)) == QQ.old_poly_ring(x).ideal(x+1)
|
| 209 |
+
True
|
| 210 |
+
"""
|
| 211 |
+
self._check_ideal(J)
|
| 212 |
+
return self._union(J)
|
| 213 |
+
|
| 214 |
+
def product(self, J):
|
| 215 |
+
r"""
|
| 216 |
+
Compute the ideal product of ``self`` and ``J``.
|
| 217 |
+
|
| 218 |
+
That is, compute the ideal generated by products `xy`, for `x` an element
|
| 219 |
+
of ``self`` and `y \in J`.
|
| 220 |
+
|
| 221 |
+
Examples
|
| 222 |
+
========
|
| 223 |
+
|
| 224 |
+
>>> from sympy.abc import x, y
|
| 225 |
+
>>> from sympy import QQ
|
| 226 |
+
>>> QQ.old_poly_ring(x, y).ideal(x).product(QQ.old_poly_ring(x, y).ideal(y))
|
| 227 |
+
<x*y>
|
| 228 |
+
"""
|
| 229 |
+
self._check_ideal(J)
|
| 230 |
+
return self._product(J)
|
| 231 |
+
|
| 232 |
+
def reduce_element(self, x):
|
| 233 |
+
"""
|
| 234 |
+
Reduce the element ``x`` of our ring modulo the ideal ``self``.
|
| 235 |
+
|
| 236 |
+
Here "reduce" has no specific meaning: it could return a unique normal
|
| 237 |
+
form, simplify the expression a bit, or just do nothing.
|
| 238 |
+
"""
|
| 239 |
+
return x
|
| 240 |
+
|
| 241 |
+
def __add__(self, e):
|
| 242 |
+
if not isinstance(e, Ideal):
|
| 243 |
+
R = self.ring.quotient_ring(self)
|
| 244 |
+
if isinstance(e, R.dtype):
|
| 245 |
+
return e
|
| 246 |
+
if isinstance(e, R.ring.dtype):
|
| 247 |
+
return R(e)
|
| 248 |
+
return R.convert(e)
|
| 249 |
+
self._check_ideal(e)
|
| 250 |
+
return self.union(e)
|
| 251 |
+
|
| 252 |
+
__radd__ = __add__
|
| 253 |
+
|
| 254 |
+
def __mul__(self, e):
|
| 255 |
+
if not isinstance(e, Ideal):
|
| 256 |
+
try:
|
| 257 |
+
e = self.ring.ideal(e)
|
| 258 |
+
except CoercionFailed:
|
| 259 |
+
return NotImplemented
|
| 260 |
+
self._check_ideal(e)
|
| 261 |
+
return self.product(e)
|
| 262 |
+
|
| 263 |
+
__rmul__ = __mul__
|
| 264 |
+
|
| 265 |
+
def _zeroth_power(self):
|
| 266 |
+
return self.ring.ideal(1)
|
| 267 |
+
|
| 268 |
+
def _first_power(self):
|
| 269 |
+
# Raising to any power but 1 returns a new instance. So we mult by 1
|
| 270 |
+
# here so that the first power is no exception.
|
| 271 |
+
return self * 1
|
| 272 |
+
|
| 273 |
+
def __eq__(self, e):
|
| 274 |
+
if not isinstance(e, Ideal) or e.ring != self.ring:
|
| 275 |
+
return False
|
| 276 |
+
return self._equals(e)
|
| 277 |
+
|
| 278 |
+
def __ne__(self, e):
|
| 279 |
+
return not (self == e)
|
| 280 |
+
|
| 281 |
+
|
| 282 |
+
class ModuleImplementedIdeal(Ideal):
|
| 283 |
+
"""
|
| 284 |
+
Ideal implementation relying on the modules code.
|
| 285 |
+
|
| 286 |
+
Attributes:
|
| 287 |
+
|
| 288 |
+
- _module - the underlying module
|
| 289 |
+
"""
|
| 290 |
+
|
| 291 |
+
def __init__(self, ring, module):
|
| 292 |
+
Ideal.__init__(self, ring)
|
| 293 |
+
self._module = module
|
| 294 |
+
|
| 295 |
+
def _contains_elem(self, x):
|
| 296 |
+
return self._module.contains([x])
|
| 297 |
+
|
| 298 |
+
def _contains_ideal(self, J):
|
| 299 |
+
if not isinstance(J, ModuleImplementedIdeal):
|
| 300 |
+
raise NotImplementedError
|
| 301 |
+
return self._module.is_submodule(J._module)
|
| 302 |
+
|
| 303 |
+
def _intersect(self, J):
|
| 304 |
+
if not isinstance(J, ModuleImplementedIdeal):
|
| 305 |
+
raise NotImplementedError
|
| 306 |
+
return self.__class__(self.ring, self._module.intersect(J._module))
|
| 307 |
+
|
| 308 |
+
def _quotient(self, J, **opts):
|
| 309 |
+
if not isinstance(J, ModuleImplementedIdeal):
|
| 310 |
+
raise NotImplementedError
|
| 311 |
+
return self._module.module_quotient(J._module, **opts)
|
| 312 |
+
|
| 313 |
+
def _union(self, J):
|
| 314 |
+
if not isinstance(J, ModuleImplementedIdeal):
|
| 315 |
+
raise NotImplementedError
|
| 316 |
+
return self.__class__(self.ring, self._module.union(J._module))
|
| 317 |
+
|
| 318 |
+
@property
|
| 319 |
+
def gens(self):
|
| 320 |
+
"""
|
| 321 |
+
Return generators for ``self``.
|
| 322 |
+
|
| 323 |
+
Examples
|
| 324 |
+
========
|
| 325 |
+
|
| 326 |
+
>>> from sympy import QQ
|
| 327 |
+
>>> from sympy.abc import x, y
|
| 328 |
+
>>> list(QQ.old_poly_ring(x, y).ideal(x, y, x**2 + y).gens)
|
| 329 |
+
[DMP_Python([[1], []], QQ), DMP_Python([[1, 0]], QQ), DMP_Python([[1], [], [1, 0]], QQ)]
|
| 330 |
+
"""
|
| 331 |
+
return (x[0] for x in self._module.gens)
|
| 332 |
+
|
| 333 |
+
def is_zero(self):
|
| 334 |
+
"""
|
| 335 |
+
Return True if ``self`` is the zero ideal.
|
| 336 |
+
|
| 337 |
+
Examples
|
| 338 |
+
========
|
| 339 |
+
|
| 340 |
+
>>> from sympy.abc import x
|
| 341 |
+
>>> from sympy import QQ
|
| 342 |
+
>>> QQ.old_poly_ring(x).ideal(x).is_zero()
|
| 343 |
+
False
|
| 344 |
+
>>> QQ.old_poly_ring(x).ideal().is_zero()
|
| 345 |
+
True
|
| 346 |
+
"""
|
| 347 |
+
return self._module.is_zero()
|
| 348 |
+
|
| 349 |
+
def is_whole_ring(self):
|
| 350 |
+
"""
|
| 351 |
+
Return True if ``self`` is the whole ring, i.e. one generator is a unit.
|
| 352 |
+
|
| 353 |
+
Examples
|
| 354 |
+
========
|
| 355 |
+
|
| 356 |
+
>>> from sympy.abc import x
|
| 357 |
+
>>> from sympy import QQ, ilex
|
| 358 |
+
>>> QQ.old_poly_ring(x).ideal(x).is_whole_ring()
|
| 359 |
+
False
|
| 360 |
+
>>> QQ.old_poly_ring(x).ideal(3).is_whole_ring()
|
| 361 |
+
True
|
| 362 |
+
>>> QQ.old_poly_ring(x, order=ilex).ideal(2 + x).is_whole_ring()
|
| 363 |
+
True
|
| 364 |
+
"""
|
| 365 |
+
return self._module.is_full_module()
|
| 366 |
+
|
| 367 |
+
def __repr__(self):
|
| 368 |
+
from sympy.printing.str import sstr
|
| 369 |
+
gens = [self.ring.to_sympy(x) for [x] in self._module.gens]
|
| 370 |
+
return '<' + ','.join(sstr(g) for g in gens) + '>'
|
| 371 |
+
|
| 372 |
+
# NOTE this is the only method using the fact that the module is a SubModule
|
| 373 |
+
def _product(self, J):
|
| 374 |
+
if not isinstance(J, ModuleImplementedIdeal):
|
| 375 |
+
raise NotImplementedError
|
| 376 |
+
return self.__class__(self.ring, self._module.submodule(
|
| 377 |
+
*[[x*y] for [x] in self._module.gens for [y] in J._module.gens]))
|
| 378 |
+
|
| 379 |
+
def in_terms_of_generators(self, e):
|
| 380 |
+
"""
|
| 381 |
+
Express ``e`` in terms of the generators of ``self``.
|
| 382 |
+
|
| 383 |
+
Examples
|
| 384 |
+
========
|
| 385 |
+
|
| 386 |
+
>>> from sympy.abc import x
|
| 387 |
+
>>> from sympy import QQ
|
| 388 |
+
>>> I = QQ.old_poly_ring(x).ideal(x**2 + 1, x)
|
| 389 |
+
>>> I.in_terms_of_generators(1) # doctest: +SKIP
|
| 390 |
+
[DMP_Python([1], QQ), DMP_Python([-1, 0], QQ)]
|
| 391 |
+
"""
|
| 392 |
+
return self._module.in_terms_of_generators([e])
|
| 393 |
+
|
| 394 |
+
def reduce_element(self, x, **options):
|
| 395 |
+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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Computations with modules over polynomial rings.
|
| 3 |
+
|
| 4 |
+
This module implements various classes that encapsulate groebner basis
|
| 5 |
+
computations for modules. Most of them should not be instantiated by hand.
|
| 6 |
+
Instead, use the constructing routines on objects you already have.
|
| 7 |
+
|
| 8 |
+
For example, to construct a free module over ``QQ[x, y]``, call
|
| 9 |
+
``QQ[x, y].free_module(rank)`` instead of the ``FreeModule`` constructor.
|
| 10 |
+
In fact ``FreeModule`` is an abstract base class that should not be
|
| 11 |
+
instantiated, the ``free_module`` method instead returns the implementing class
|
| 12 |
+
``FreeModulePolyRing``.
|
| 13 |
+
|
| 14 |
+
In general, the abstract base classes implement most functionality in terms of
|
| 15 |
+
a few non-implemented methods. The concrete base classes supply only these
|
| 16 |
+
non-implemented methods. They may also supply new implementations of the
|
| 17 |
+
convenience methods, for example if there are faster algorithms available.
|
| 18 |
+
"""
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
from copy import copy
|
| 22 |
+
from functools import reduce
|
| 23 |
+
|
| 24 |
+
from sympy.polys.agca.ideals import Ideal
|
| 25 |
+
from sympy.polys.domains.field import Field
|
| 26 |
+
from sympy.polys.orderings import ProductOrder, monomial_key
|
| 27 |
+
from sympy.polys.polyclasses import DMP
|
| 28 |
+
from sympy.polys.polyerrors import CoercionFailed
|
| 29 |
+
from sympy.core.basic import _aresame
|
| 30 |
+
from sympy.utilities.iterables import iterable
|
| 31 |
+
|
| 32 |
+
# TODO
|
| 33 |
+
# - module saturation
|
| 34 |
+
# - module quotient/intersection for quotient rings
|
| 35 |
+
# - free resoltutions / syzygies
|
| 36 |
+
# - finding small/minimal generating sets
|
| 37 |
+
# - ...
|
| 38 |
+
|
| 39 |
+
##########################################################################
|
| 40 |
+
## Abstract base classes #################################################
|
| 41 |
+
##########################################################################
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
class Module:
|
| 45 |
+
"""
|
| 46 |
+
Abstract base class for modules.
|
| 47 |
+
|
| 48 |
+
Do not instantiate - use ring explicit constructors instead:
|
| 49 |
+
|
| 50 |
+
>>> from sympy import QQ
|
| 51 |
+
>>> from sympy.abc import x
|
| 52 |
+
>>> QQ.old_poly_ring(x).free_module(2)
|
| 53 |
+
QQ[x]**2
|
| 54 |
+
|
| 55 |
+
Attributes:
|
| 56 |
+
|
| 57 |
+
- dtype - type of elements
|
| 58 |
+
- ring - containing ring
|
| 59 |
+
|
| 60 |
+
Non-implemented methods:
|
| 61 |
+
|
| 62 |
+
- submodule
|
| 63 |
+
- quotient_module
|
| 64 |
+
- is_zero
|
| 65 |
+
- is_submodule
|
| 66 |
+
- multiply_ideal
|
| 67 |
+
|
| 68 |
+
The method convert likely needs to be changed in subclasses.
|
| 69 |
+
"""
|
| 70 |
+
|
| 71 |
+
def __init__(self, ring):
|
| 72 |
+
self.ring = ring
|
| 73 |
+
|
| 74 |
+
def convert(self, elem, M=None):
|
| 75 |
+
"""
|
| 76 |
+
Convert ``elem`` into internal representation of this module.
|
| 77 |
+
|
| 78 |
+
If ``M`` is not None, it should be a module containing it.
|
| 79 |
+
"""
|
| 80 |
+
if not isinstance(elem, self.dtype):
|
| 81 |
+
raise CoercionFailed
|
| 82 |
+
return elem
|
| 83 |
+
|
| 84 |
+
def submodule(self, *gens):
|
| 85 |
+
"""Generate a submodule."""
|
| 86 |
+
raise NotImplementedError
|
| 87 |
+
|
| 88 |
+
def quotient_module(self, other):
|
| 89 |
+
"""Generate a quotient module."""
|
| 90 |
+
raise NotImplementedError
|
| 91 |
+
|
| 92 |
+
def __truediv__(self, e):
|
| 93 |
+
if not isinstance(e, Module):
|
| 94 |
+
e = self.submodule(*e)
|
| 95 |
+
return self.quotient_module(e)
|
| 96 |
+
|
| 97 |
+
def contains(self, elem):
|
| 98 |
+
"""Return True if ``elem`` is an element of this module."""
|
| 99 |
+
try:
|
| 100 |
+
self.convert(elem)
|
| 101 |
+
return True
|
| 102 |
+
except CoercionFailed:
|
| 103 |
+
return False
|
| 104 |
+
|
| 105 |
+
def __contains__(self, elem):
|
| 106 |
+
return self.contains(elem)
|
| 107 |
+
|
| 108 |
+
def subset(self, other):
|
| 109 |
+
"""
|
| 110 |
+
Returns True if ``other`` is is a subset of ``self``.
|
| 111 |
+
|
| 112 |
+
Examples
|
| 113 |
+
========
|
| 114 |
+
|
| 115 |
+
>>> from sympy.abc import x
|
| 116 |
+
>>> from sympy import QQ
|
| 117 |
+
>>> F = QQ.old_poly_ring(x).free_module(2)
|
| 118 |
+
>>> F.subset([(1, x), (x, 2)])
|
| 119 |
+
True
|
| 120 |
+
>>> F.subset([(1/x, x), (x, 2)])
|
| 121 |
+
False
|
| 122 |
+
"""
|
| 123 |
+
return all(self.contains(x) for x in other)
|
| 124 |
+
|
| 125 |
+
def __eq__(self, other):
|
| 126 |
+
return self.is_submodule(other) and other.is_submodule(self)
|
| 127 |
+
|
| 128 |
+
def __ne__(self, other):
|
| 129 |
+
return not (self == other)
|
| 130 |
+
|
| 131 |
+
def is_zero(self):
|
| 132 |
+
"""Returns True if ``self`` is a zero module."""
|
| 133 |
+
raise NotImplementedError
|
| 134 |
+
|
| 135 |
+
def is_submodule(self, other):
|
| 136 |
+
"""Returns True if ``other`` is a submodule of ``self``."""
|
| 137 |
+
raise NotImplementedError
|
| 138 |
+
|
| 139 |
+
def multiply_ideal(self, other):
|
| 140 |
+
"""
|
| 141 |
+
Multiply ``self`` by the ideal ``other``.
|
| 142 |
+
"""
|
| 143 |
+
raise NotImplementedError
|
| 144 |
+
|
| 145 |
+
def __mul__(self, e):
|
| 146 |
+
if not isinstance(e, Ideal):
|
| 147 |
+
try:
|
| 148 |
+
e = self.ring.ideal(e)
|
| 149 |
+
except (CoercionFailed, NotImplementedError):
|
| 150 |
+
return NotImplemented
|
| 151 |
+
return self.multiply_ideal(e)
|
| 152 |
+
|
| 153 |
+
__rmul__ = __mul__
|
| 154 |
+
|
| 155 |
+
def identity_hom(self):
|
| 156 |
+
"""Return the identity homomorphism on ``self``."""
|
| 157 |
+
raise NotImplementedError
|
| 158 |
+
|
| 159 |
+
|
| 160 |
+
class ModuleElement:
|
| 161 |
+
"""
|
| 162 |
+
Base class for module element wrappers.
|
| 163 |
+
|
| 164 |
+
Use this class to wrap primitive data types as module elements. It stores
|
| 165 |
+
a reference to the containing module, and implements all the arithmetic
|
| 166 |
+
operators.
|
| 167 |
+
|
| 168 |
+
Attributes:
|
| 169 |
+
|
| 170 |
+
- module - containing module
|
| 171 |
+
- data - internal data
|
| 172 |
+
|
| 173 |
+
Methods that likely need change in subclasses:
|
| 174 |
+
|
| 175 |
+
- add
|
| 176 |
+
- mul
|
| 177 |
+
- div
|
| 178 |
+
- eq
|
| 179 |
+
"""
|
| 180 |
+
|
| 181 |
+
def __init__(self, module, data):
|
| 182 |
+
self.module = module
|
| 183 |
+
self.data = data
|
| 184 |
+
|
| 185 |
+
def add(self, d1, d2):
|
| 186 |
+
"""Add data ``d1`` and ``d2``."""
|
| 187 |
+
return d1 + d2
|
| 188 |
+
|
| 189 |
+
def mul(self, m, d):
|
| 190 |
+
"""Multiply module data ``m`` by coefficient d."""
|
| 191 |
+
return m * d
|
| 192 |
+
|
| 193 |
+
def div(self, m, d):
|
| 194 |
+
"""Divide module data ``m`` by coefficient d."""
|
| 195 |
+
return m / d
|
| 196 |
+
|
| 197 |
+
def eq(self, d1, d2):
|
| 198 |
+
"""Return true if d1 and d2 represent the same element."""
|
| 199 |
+
return d1 == d2
|
| 200 |
+
|
| 201 |
+
def __add__(self, om):
|
| 202 |
+
if not isinstance(om, self.__class__) or om.module != self.module:
|
| 203 |
+
try:
|
| 204 |
+
om = self.module.convert(om)
|
| 205 |
+
except CoercionFailed:
|
| 206 |
+
return NotImplemented
|
| 207 |
+
return self.__class__(self.module, self.add(self.data, om.data))
|
| 208 |
+
|
| 209 |
+
__radd__ = __add__
|
| 210 |
+
|
| 211 |
+
def __neg__(self):
|
| 212 |
+
return self.__class__(self.module, self.mul(self.data,
|
| 213 |
+
self.module.ring.convert(-1)))
|
| 214 |
+
|
| 215 |
+
def __sub__(self, om):
|
| 216 |
+
if not isinstance(om, self.__class__) or om.module != self.module:
|
| 217 |
+
try:
|
| 218 |
+
om = self.module.convert(om)
|
| 219 |
+
except CoercionFailed:
|
| 220 |
+
return NotImplemented
|
| 221 |
+
return self.__add__(-om)
|
| 222 |
+
|
| 223 |
+
def __rsub__(self, om):
|
| 224 |
+
return (-self).__add__(om)
|
| 225 |
+
|
| 226 |
+
def __mul__(self, o):
|
| 227 |
+
if not isinstance(o, self.module.ring.dtype):
|
| 228 |
+
try:
|
| 229 |
+
o = self.module.ring.convert(o)
|
| 230 |
+
except CoercionFailed:
|
| 231 |
+
return NotImplemented
|
| 232 |
+
return self.__class__(self.module, self.mul(self.data, o))
|
| 233 |
+
|
| 234 |
+
__rmul__ = __mul__
|
| 235 |
+
|
| 236 |
+
def __truediv__(self, o):
|
| 237 |
+
if not isinstance(o, self.module.ring.dtype):
|
| 238 |
+
try:
|
| 239 |
+
o = self.module.ring.convert(o)
|
| 240 |
+
except CoercionFailed:
|
| 241 |
+
return NotImplemented
|
| 242 |
+
return self.__class__(self.module, self.div(self.data, o))
|
| 243 |
+
|
| 244 |
+
def __eq__(self, om):
|
| 245 |
+
if not isinstance(om, self.__class__) or om.module != self.module:
|
| 246 |
+
try:
|
| 247 |
+
om = self.module.convert(om)
|
| 248 |
+
except CoercionFailed:
|
| 249 |
+
return False
|
| 250 |
+
return self.eq(self.data, om.data)
|
| 251 |
+
|
| 252 |
+
def __ne__(self, om):
|
| 253 |
+
return not self == om
|
| 254 |
+
|
| 255 |
+
##########################################################################
|
| 256 |
+
## Free Modules ##########################################################
|
| 257 |
+
##########################################################################
|
| 258 |
+
|
| 259 |
+
|
| 260 |
+
class FreeModuleElement(ModuleElement):
|
| 261 |
+
"""Element of a free module. Data stored as a tuple."""
|
| 262 |
+
|
| 263 |
+
def add(self, d1, d2):
|
| 264 |
+
return tuple(x + y for x, y in zip(d1, d2))
|
| 265 |
+
|
| 266 |
+
def mul(self, d, p):
|
| 267 |
+
return tuple(x * p for x in d)
|
| 268 |
+
|
| 269 |
+
def div(self, d, p):
|
| 270 |
+
return tuple(x / p for x in d)
|
| 271 |
+
|
| 272 |
+
def __repr__(self):
|
| 273 |
+
from sympy.printing.str import sstr
|
| 274 |
+
data = self.data
|
| 275 |
+
if any(isinstance(x, DMP) for x in data):
|
| 276 |
+
data = [self.module.ring.to_sympy(x) for x in data]
|
| 277 |
+
return '[' + ', '.join(sstr(x) for x in data) + ']'
|
| 278 |
+
|
| 279 |
+
def __iter__(self):
|
| 280 |
+
return self.data.__iter__()
|
| 281 |
+
|
| 282 |
+
def __getitem__(self, idx):
|
| 283 |
+
return self.data[idx]
|
| 284 |
+
|
| 285 |
+
|
| 286 |
+
class FreeModule(Module):
|
| 287 |
+
"""
|
| 288 |
+
Abstract base class for free modules.
|
| 289 |
+
|
| 290 |
+
Additional attributes:
|
| 291 |
+
|
| 292 |
+
- rank - rank of the free module
|
| 293 |
+
|
| 294 |
+
Non-implemented methods:
|
| 295 |
+
|
| 296 |
+
- submodule
|
| 297 |
+
"""
|
| 298 |
+
|
| 299 |
+
dtype = FreeModuleElement
|
| 300 |
+
|
| 301 |
+
def __init__(self, ring, rank):
|
| 302 |
+
Module.__init__(self, ring)
|
| 303 |
+
self.rank = rank
|
| 304 |
+
|
| 305 |
+
def __repr__(self):
|
| 306 |
+
return repr(self.ring) + "**" + repr(self.rank)
|
| 307 |
+
|
| 308 |
+
def is_submodule(self, other):
|
| 309 |
+
"""
|
| 310 |
+
Returns True if ``other`` is a submodule of ``self``.
|
| 311 |
+
|
| 312 |
+
Examples
|
| 313 |
+
========
|
| 314 |
+
|
| 315 |
+
>>> from sympy.abc import x
|
| 316 |
+
>>> from sympy import QQ
|
| 317 |
+
>>> F = QQ.old_poly_ring(x).free_module(2)
|
| 318 |
+
>>> M = F.submodule([2, x])
|
| 319 |
+
>>> F.is_submodule(F)
|
| 320 |
+
True
|
| 321 |
+
>>> F.is_submodule(M)
|
| 322 |
+
True
|
| 323 |
+
>>> M.is_submodule(F)
|
| 324 |
+
False
|
| 325 |
+
"""
|
| 326 |
+
if isinstance(other, SubModule):
|
| 327 |
+
return other.container == self
|
| 328 |
+
if isinstance(other, FreeModule):
|
| 329 |
+
return other.ring == self.ring and other.rank == self.rank
|
| 330 |
+
return False
|
| 331 |
+
|
| 332 |
+
def convert(self, elem, M=None):
|
| 333 |
+
"""
|
| 334 |
+
Convert ``elem`` into the internal representation.
|
| 335 |
+
|
| 336 |
+
This method is called implicitly whenever computations involve elements
|
| 337 |
+
not in the internal representation.
|
| 338 |
+
|
| 339 |
+
Examples
|
| 340 |
+
========
|
| 341 |
+
|
| 342 |
+
>>> from sympy.abc import x
|
| 343 |
+
>>> from sympy import QQ
|
| 344 |
+
>>> F = QQ.old_poly_ring(x).free_module(2)
|
| 345 |
+
>>> F.convert([1, 0])
|
| 346 |
+
[1, 0]
|
| 347 |
+
"""
|
| 348 |
+
if isinstance(elem, FreeModuleElement):
|
| 349 |
+
if elem.module is self:
|
| 350 |
+
return elem
|
| 351 |
+
if elem.module.rank != self.rank:
|
| 352 |
+
raise CoercionFailed
|
| 353 |
+
return FreeModuleElement(self,
|
| 354 |
+
tuple(self.ring.convert(x, elem.module.ring) for x in elem.data))
|
| 355 |
+
elif iterable(elem):
|
| 356 |
+
tpl = tuple(self.ring.convert(x) for x in elem)
|
| 357 |
+
if len(tpl) != self.rank:
|
| 358 |
+
raise CoercionFailed
|
| 359 |
+
return FreeModuleElement(self, tpl)
|
| 360 |
+
elif _aresame(elem, 0):
|
| 361 |
+
return FreeModuleElement(self, (self.ring.convert(0),)*self.rank)
|
| 362 |
+
else:
|
| 363 |
+
raise CoercionFailed
|
| 364 |
+
|
| 365 |
+
def is_zero(self):
|
| 366 |
+
"""
|
| 367 |
+
Returns True if ``self`` is a zero module.
|
| 368 |
+
|
| 369 |
+
(If, as this implementation assumes, the coefficient ring is not the
|
| 370 |
+
zero ring, then this is equivalent to the rank being zero.)
|
| 371 |
+
|
| 372 |
+
Examples
|
| 373 |
+
========
|
| 374 |
+
|
| 375 |
+
>>> from sympy.abc import x
|
| 376 |
+
>>> from sympy import QQ
|
| 377 |
+
>>> QQ.old_poly_ring(x).free_module(0).is_zero()
|
| 378 |
+
True
|
| 379 |
+
>>> QQ.old_poly_ring(x).free_module(1).is_zero()
|
| 380 |
+
False
|
| 381 |
+
"""
|
| 382 |
+
return self.rank == 0
|
| 383 |
+
|
| 384 |
+
def basis(self):
|
| 385 |
+
"""
|
| 386 |
+
Return a set of basis elements.
|
| 387 |
+
|
| 388 |
+
Examples
|
| 389 |
+
========
|
| 390 |
+
|
| 391 |
+
>>> from sympy.abc import x
|
| 392 |
+
>>> from sympy import QQ
|
| 393 |
+
>>> QQ.old_poly_ring(x).free_module(3).basis()
|
| 394 |
+
([1, 0, 0], [0, 1, 0], [0, 0, 1])
|
| 395 |
+
"""
|
| 396 |
+
from sympy.matrices import eye
|
| 397 |
+
M = eye(self.rank)
|
| 398 |
+
return tuple(self.convert(M.row(i)) for i in range(self.rank))
|
| 399 |
+
|
| 400 |
+
def quotient_module(self, submodule):
|
| 401 |
+
"""
|
| 402 |
+
Return a quotient module.
|
| 403 |
+
|
| 404 |
+
Examples
|
| 405 |
+
========
|
| 406 |
+
|
| 407 |
+
>>> from sympy.abc import x
|
| 408 |
+
>>> from sympy import QQ
|
| 409 |
+
>>> M = QQ.old_poly_ring(x).free_module(2)
|
| 410 |
+
>>> M.quotient_module(M.submodule([1, x], [x, 2]))
|
| 411 |
+
QQ[x]**2/<[1, x], [x, 2]>
|
| 412 |
+
|
| 413 |
+
Or more conicisely, using the overloaded division operator:
|
| 414 |
+
|
| 415 |
+
>>> QQ.old_poly_ring(x).free_module(2) / [[1, x], [x, 2]]
|
| 416 |
+
QQ[x]**2/<[1, x], [x, 2]>
|
| 417 |
+
"""
|
| 418 |
+
return QuotientModule(self.ring, self, submodule)
|
| 419 |
+
|
| 420 |
+
def multiply_ideal(self, other):
|
| 421 |
+
"""
|
| 422 |
+
Multiply ``self`` by the ideal ``other``.
|
| 423 |
+
|
| 424 |
+
Examples
|
| 425 |
+
========
|
| 426 |
+
|
| 427 |
+
>>> from sympy.abc import x
|
| 428 |
+
>>> from sympy import QQ
|
| 429 |
+
>>> I = QQ.old_poly_ring(x).ideal(x)
|
| 430 |
+
>>> F = QQ.old_poly_ring(x).free_module(2)
|
| 431 |
+
>>> F.multiply_ideal(I)
|
| 432 |
+
<[x, 0], [0, x]>
|
| 433 |
+
"""
|
| 434 |
+
return self.submodule(*self.basis()).multiply_ideal(other)
|
| 435 |
+
|
| 436 |
+
def identity_hom(self):
|
| 437 |
+
"""
|
| 438 |
+
Return the identity homomorphism on ``self``.
|
| 439 |
+
|
| 440 |
+
Examples
|
| 441 |
+
========
|
| 442 |
+
|
| 443 |
+
>>> from sympy.abc import x
|
| 444 |
+
>>> from sympy import QQ
|
| 445 |
+
>>> QQ.old_poly_ring(x).free_module(2).identity_hom()
|
| 446 |
+
Matrix([
|
| 447 |
+
[1, 0], : QQ[x]**2 -> QQ[x]**2
|
| 448 |
+
[0, 1]])
|
| 449 |
+
"""
|
| 450 |
+
from sympy.polys.agca.homomorphisms import homomorphism
|
| 451 |
+
return homomorphism(self, self, self.basis())
|
| 452 |
+
|
| 453 |
+
|
| 454 |
+
class FreeModulePolyRing(FreeModule):
|
| 455 |
+
"""
|
| 456 |
+
Free module over a generalized polynomial ring.
|
| 457 |
+
|
| 458 |
+
Do not instantiate this, use the constructor method of the ring instead:
|
| 459 |
+
|
| 460 |
+
Examples
|
| 461 |
+
========
|
| 462 |
+
|
| 463 |
+
>>> from sympy.abc import x
|
| 464 |
+
>>> from sympy import QQ
|
| 465 |
+
>>> F = QQ.old_poly_ring(x).free_module(3)
|
| 466 |
+
>>> F
|
| 467 |
+
QQ[x]**3
|
| 468 |
+
>>> F.contains([x, 1, 0])
|
| 469 |
+
True
|
| 470 |
+
>>> F.contains([1/x, 0, 1])
|
| 471 |
+
False
|
| 472 |
+
"""
|
| 473 |
+
|
| 474 |
+
def __init__(self, ring, rank):
|
| 475 |
+
from sympy.polys.domains.old_polynomialring import PolynomialRingBase
|
| 476 |
+
FreeModule.__init__(self, ring, rank)
|
| 477 |
+
if not isinstance(ring, PolynomialRingBase):
|
| 478 |
+
raise NotImplementedError('This implementation only works over '
|
| 479 |
+
+ 'polynomial rings, got %s' % ring)
|
| 480 |
+
if not isinstance(ring.dom, Field):
|
| 481 |
+
raise NotImplementedError('Ground domain must be a field, '
|
| 482 |
+
+ 'got %s' % ring.dom)
|
| 483 |
+
|
| 484 |
+
def submodule(self, *gens, **opts):
|
| 485 |
+
"""
|
| 486 |
+
Generate a submodule.
|
| 487 |
+
|
| 488 |
+
Examples
|
| 489 |
+
========
|
| 490 |
+
|
| 491 |
+
>>> from sympy.abc import x, y
|
| 492 |
+
>>> from sympy import QQ
|
| 493 |
+
>>> M = QQ.old_poly_ring(x, y).free_module(2).submodule([x, x + y])
|
| 494 |
+
>>> M
|
| 495 |
+
<[x, x + y]>
|
| 496 |
+
>>> M.contains([2*x, 2*x + 2*y])
|
| 497 |
+
True
|
| 498 |
+
>>> M.contains([x, y])
|
| 499 |
+
False
|
| 500 |
+
"""
|
| 501 |
+
return SubModulePolyRing(gens, self, **opts)
|
| 502 |
+
|
| 503 |
+
|
| 504 |
+
class FreeModuleQuotientRing(FreeModule):
|
| 505 |
+
"""
|
| 506 |
+
Free module over a quotient ring.
|
| 507 |
+
|
| 508 |
+
Do not instantiate this, use the constructor method of the ring instead:
|
| 509 |
+
|
| 510 |
+
Examples
|
| 511 |
+
========
|
| 512 |
+
|
| 513 |
+
>>> from sympy.abc import x
|
| 514 |
+
>>> from sympy import QQ
|
| 515 |
+
>>> F = (QQ.old_poly_ring(x)/[x**2 + 1]).free_module(3)
|
| 516 |
+
>>> F
|
| 517 |
+
(QQ[x]/<x**2 + 1>)**3
|
| 518 |
+
|
| 519 |
+
Attributes
|
| 520 |
+
|
| 521 |
+
- quot - the quotient module `R^n / IR^n`, where `R/I` is our ring
|
| 522 |
+
"""
|
| 523 |
+
|
| 524 |
+
def __init__(self, ring, rank):
|
| 525 |
+
from sympy.polys.domains.quotientring import QuotientRing
|
| 526 |
+
FreeModule.__init__(self, ring, rank)
|
| 527 |
+
if not isinstance(ring, QuotientRing):
|
| 528 |
+
raise NotImplementedError('This implementation only works over '
|
| 529 |
+
+ 'quotient rings, got %s' % ring)
|
| 530 |
+
F = self.ring.ring.free_module(self.rank)
|
| 531 |
+
self.quot = F / (self.ring.base_ideal*F)
|
| 532 |
+
|
| 533 |
+
def __repr__(self):
|
| 534 |
+
return "(" + repr(self.ring) + ")" + "**" + repr(self.rank)
|
| 535 |
+
|
| 536 |
+
def submodule(self, *gens, **opts):
|
| 537 |
+
"""
|
| 538 |
+
Generate a submodule.
|
| 539 |
+
|
| 540 |
+
Examples
|
| 541 |
+
========
|
| 542 |
+
|
| 543 |
+
>>> from sympy.abc import x, y
|
| 544 |
+
>>> from sympy import QQ
|
| 545 |
+
>>> M = (QQ.old_poly_ring(x, y)/[x**2 - y**2]).free_module(2).submodule([x, x + y])
|
| 546 |
+
>>> M
|
| 547 |
+
<[x + <x**2 - y**2>, x + y + <x**2 - y**2>]>
|
| 548 |
+
>>> M.contains([y**2, x**2 + x*y])
|
| 549 |
+
True
|
| 550 |
+
>>> M.contains([x, y])
|
| 551 |
+
False
|
| 552 |
+
"""
|
| 553 |
+
return SubModuleQuotientRing(gens, self, **opts)
|
| 554 |
+
|
| 555 |
+
def lift(self, elem):
|
| 556 |
+
"""
|
| 557 |
+
Lift the element ``elem`` of self to the module self.quot.
|
| 558 |
+
|
| 559 |
+
Note that self.quot is the same set as self, just as an R-module
|
| 560 |
+
and not as an R/I-module, so this makes sense.
|
| 561 |
+
|
| 562 |
+
Examples
|
| 563 |
+
========
|
| 564 |
+
|
| 565 |
+
>>> from sympy.abc import x
|
| 566 |
+
>>> from sympy import QQ
|
| 567 |
+
>>> F = (QQ.old_poly_ring(x)/[x**2 + 1]).free_module(2)
|
| 568 |
+
>>> e = F.convert([1, 0])
|
| 569 |
+
>>> e
|
| 570 |
+
[1 + <x**2 + 1>, 0 + <x**2 + 1>]
|
| 571 |
+
>>> L = F.quot
|
| 572 |
+
>>> l = F.lift(e)
|
| 573 |
+
>>> l
|
| 574 |
+
[1, 0] + <[x**2 + 1, 0], [0, x**2 + 1]>
|
| 575 |
+
>>> L.contains(l)
|
| 576 |
+
True
|
| 577 |
+
"""
|
| 578 |
+
return self.quot.convert([x.data for x in elem])
|
| 579 |
+
|
| 580 |
+
def unlift(self, elem):
|
| 581 |
+
"""
|
| 582 |
+
Push down an element of self.quot to self.
|
| 583 |
+
|
| 584 |
+
This undoes ``lift``.
|
| 585 |
+
|
| 586 |
+
Examples
|
| 587 |
+
========
|
| 588 |
+
|
| 589 |
+
>>> from sympy.abc import x
|
| 590 |
+
>>> from sympy import QQ
|
| 591 |
+
>>> F = (QQ.old_poly_ring(x)/[x**2 + 1]).free_module(2)
|
| 592 |
+
>>> e = F.convert([1, 0])
|
| 593 |
+
>>> l = F.lift(e)
|
| 594 |
+
>>> e == l
|
| 595 |
+
False
|
| 596 |
+
>>> e == F.unlift(l)
|
| 597 |
+
True
|
| 598 |
+
"""
|
| 599 |
+
return self.convert(elem.data)
|
| 600 |
+
|
| 601 |
+
##########################################################################
|
| 602 |
+
## Submodules and subquotients ###########################################
|
| 603 |
+
##########################################################################
|
| 604 |
+
|
| 605 |
+
|
| 606 |
+
class SubModule(Module):
|
| 607 |
+
"""
|
| 608 |
+
Base class for submodules.
|
| 609 |
+
|
| 610 |
+
Attributes:
|
| 611 |
+
|
| 612 |
+
- container - containing module
|
| 613 |
+
- gens - generators (subset of containing module)
|
| 614 |
+
- rank - rank of containing module
|
| 615 |
+
|
| 616 |
+
Non-implemented methods:
|
| 617 |
+
|
| 618 |
+
- _contains
|
| 619 |
+
- _syzygies
|
| 620 |
+
- _in_terms_of_generators
|
| 621 |
+
- _intersect
|
| 622 |
+
- _module_quotient
|
| 623 |
+
|
| 624 |
+
Methods that likely need change in subclasses:
|
| 625 |
+
|
| 626 |
+
- reduce_element
|
| 627 |
+
"""
|
| 628 |
+
|
| 629 |
+
def __init__(self, gens, container):
|
| 630 |
+
Module.__init__(self, container.ring)
|
| 631 |
+
self.gens = tuple(container.convert(x) for x in gens)
|
| 632 |
+
self.container = container
|
| 633 |
+
self.rank = container.rank
|
| 634 |
+
self.ring = container.ring
|
| 635 |
+
self.dtype = container.dtype
|
| 636 |
+
|
| 637 |
+
def __repr__(self):
|
| 638 |
+
return "<" + ", ".join(repr(x) for x in self.gens) + ">"
|
| 639 |
+
|
| 640 |
+
def _contains(self, other):
|
| 641 |
+
"""Implementation of containment.
|
| 642 |
+
Other is guaranteed to be FreeModuleElement."""
|
| 643 |
+
raise NotImplementedError
|
| 644 |
+
|
| 645 |
+
def _syzygies(self):
|
| 646 |
+
"""Implementation of syzygy computation wrt self generators."""
|
| 647 |
+
raise NotImplementedError
|
| 648 |
+
|
| 649 |
+
def _in_terms_of_generators(self, e):
|
| 650 |
+
"""Implementation of expression in terms of generators."""
|
| 651 |
+
raise NotImplementedError
|
| 652 |
+
|
| 653 |
+
def convert(self, elem, M=None):
|
| 654 |
+
"""
|
| 655 |
+
Convert ``elem`` into the internal represantition.
|
| 656 |
+
|
| 657 |
+
Mostly called implicitly.
|
| 658 |
+
|
| 659 |
+
Examples
|
| 660 |
+
========
|
| 661 |
+
|
| 662 |
+
>>> from sympy.abc import x
|
| 663 |
+
>>> from sympy import QQ
|
| 664 |
+
>>> M = QQ.old_poly_ring(x).free_module(2).submodule([1, x])
|
| 665 |
+
>>> M.convert([2, 2*x])
|
| 666 |
+
[2, 2*x]
|
| 667 |
+
"""
|
| 668 |
+
if isinstance(elem, self.container.dtype) and elem.module is self:
|
| 669 |
+
return elem
|
| 670 |
+
r = copy(self.container.convert(elem, M))
|
| 671 |
+
r.module = self
|
| 672 |
+
if not self._contains(r):
|
| 673 |
+
raise CoercionFailed
|
| 674 |
+
return r
|
| 675 |
+
|
| 676 |
+
def _intersect(self, other):
|
| 677 |
+
"""Implementation of intersection.
|
| 678 |
+
Other is guaranteed to be a submodule of same free module."""
|
| 679 |
+
raise NotImplementedError
|
| 680 |
+
|
| 681 |
+
def _module_quotient(self, other):
|
| 682 |
+
"""Implementation of quotient.
|
| 683 |
+
Other is guaranteed to be a submodule of same free module."""
|
| 684 |
+
raise NotImplementedError
|
| 685 |
+
|
| 686 |
+
def intersect(self, other, **options):
|
| 687 |
+
"""
|
| 688 |
+
Returns the intersection of ``self`` with submodule ``other``.
|
| 689 |
+
|
| 690 |
+
Examples
|
| 691 |
+
========
|
| 692 |
+
|
| 693 |
+
>>> from sympy.abc import x, y
|
| 694 |
+
>>> from sympy import QQ
|
| 695 |
+
>>> F = QQ.old_poly_ring(x, y).free_module(2)
|
| 696 |
+
>>> F.submodule([x, x]).intersect(F.submodule([y, y]))
|
| 697 |
+
<[x*y, x*y]>
|
| 698 |
+
|
| 699 |
+
Some implementation allow further options to be passed. Currently, to
|
| 700 |
+
only one implemented is ``relations=True``, in which case the function
|
| 701 |
+
will return a triple ``(res, rela, relb)``, where ``res`` is the
|
| 702 |
+
intersection module, and ``rela`` and ``relb`` are lists of coefficient
|
| 703 |
+
vectors, expressing the generators of ``res`` in terms of the
|
| 704 |
+
generators of ``self`` (``rela``) and ``other`` (``relb``).
|
| 705 |
+
|
| 706 |
+
>>> F.submodule([x, x]).intersect(F.submodule([y, y]), relations=True)
|
| 707 |
+
(<[x*y, x*y]>, [(DMP_Python([[1, 0]], QQ),)], [(DMP_Python([[1], []], QQ),)])
|
| 708 |
+
|
| 709 |
+
The above result says: the intersection module is generated by the
|
| 710 |
+
single element `(-xy, -xy) = -y (x, x) = -x (y, y)`, where
|
| 711 |
+
`(x, x)` and `(y, y)` respectively are the unique generators of
|
| 712 |
+
the two modules being intersected.
|
| 713 |
+
"""
|
| 714 |
+
if not isinstance(other, SubModule):
|
| 715 |
+
raise TypeError('%s is not a SubModule' % other)
|
| 716 |
+
if other.container != self.container:
|
| 717 |
+
raise ValueError(
|
| 718 |
+
'%s is contained in a different free module' % other)
|
| 719 |
+
return self._intersect(other, **options)
|
| 720 |
+
|
| 721 |
+
def module_quotient(self, other, **options):
|
| 722 |
+
r"""
|
| 723 |
+
Returns the module quotient of ``self`` by submodule ``other``.
|
| 724 |
+
|
| 725 |
+
That is, if ``self`` is the module `M` and ``other`` is `N`, then
|
| 726 |
+
return the ideal `\{f \in R | fN \subset M\}`.
|
| 727 |
+
|
| 728 |
+
Examples
|
| 729 |
+
========
|
| 730 |
+
|
| 731 |
+
>>> from sympy import QQ
|
| 732 |
+
>>> from sympy.abc import x, y
|
| 733 |
+
>>> F = QQ.old_poly_ring(x, y).free_module(2)
|
| 734 |
+
>>> S = F.submodule([x*y, x*y])
|
| 735 |
+
>>> T = F.submodule([x, x])
|
| 736 |
+
>>> S.module_quotient(T)
|
| 737 |
+
<y>
|
| 738 |
+
|
| 739 |
+
Some implementations allow further options to be passed. Currently, the
|
| 740 |
+
only one implemented is ``relations=True``, which may only be passed
|
| 741 |
+
if ``other`` is principal. In this case the function
|
| 742 |
+
will return a pair ``(res, rel)`` where ``res`` is the ideal, and
|
| 743 |
+
``rel`` is a list of coefficient vectors, expressing the generators of
|
| 744 |
+
the ideal, multiplied by the generator of ``other`` in terms of
|
| 745 |
+
generators of ``self``.
|
| 746 |
+
|
| 747 |
+
>>> S.module_quotient(T, relations=True)
|
| 748 |
+
(<y>, [[DMP_Python([[1]], QQ)]])
|
| 749 |
+
|
| 750 |
+
This means that the quotient ideal is generated by the single element
|
| 751 |
+
`y`, and that `y (x, x) = 1 (xy, xy)`, `(x, x)` and `(xy, xy)` being
|
| 752 |
+
the generators of `T` and `S`, respectively.
|
| 753 |
+
"""
|
| 754 |
+
if not isinstance(other, SubModule):
|
| 755 |
+
raise TypeError('%s is not a SubModule' % other)
|
| 756 |
+
if other.container != self.container:
|
| 757 |
+
raise ValueError(
|
| 758 |
+
'%s is contained in a different free module' % other)
|
| 759 |
+
return self._module_quotient(other, **options)
|
| 760 |
+
|
| 761 |
+
def union(self, other):
|
| 762 |
+
"""
|
| 763 |
+
Returns the module generated by the union of ``self`` and ``other``.
|
| 764 |
+
|
| 765 |
+
Examples
|
| 766 |
+
========
|
| 767 |
+
|
| 768 |
+
>>> from sympy.abc import x
|
| 769 |
+
>>> from sympy import QQ
|
| 770 |
+
>>> F = QQ.old_poly_ring(x).free_module(1)
|
| 771 |
+
>>> M = F.submodule([x**2 + x]) # <x(x+1)>
|
| 772 |
+
>>> N = F.submodule([x**2 - 1]) # <(x-1)(x+1)>
|
| 773 |
+
>>> M.union(N) == F.submodule([x+1])
|
| 774 |
+
True
|
| 775 |
+
"""
|
| 776 |
+
if not isinstance(other, SubModule):
|
| 777 |
+
raise TypeError('%s is not a SubModule' % other)
|
| 778 |
+
if other.container != self.container:
|
| 779 |
+
raise ValueError(
|
| 780 |
+
'%s is contained in a different free module' % other)
|
| 781 |
+
return self.__class__(self.gens + other.gens, self.container)
|
| 782 |
+
|
| 783 |
+
def is_zero(self):
|
| 784 |
+
"""
|
| 785 |
+
Return True if ``self`` is a zero module.
|
| 786 |
+
|
| 787 |
+
Examples
|
| 788 |
+
========
|
| 789 |
+
|
| 790 |
+
>>> from sympy.abc import x
|
| 791 |
+
>>> from sympy import QQ
|
| 792 |
+
>>> F = QQ.old_poly_ring(x).free_module(2)
|
| 793 |
+
>>> F.submodule([x, 1]).is_zero()
|
| 794 |
+
False
|
| 795 |
+
>>> F.submodule([0, 0]).is_zero()
|
| 796 |
+
True
|
| 797 |
+
"""
|
| 798 |
+
return all(x == 0 for x in self.gens)
|
| 799 |
+
|
| 800 |
+
def submodule(self, *gens):
|
| 801 |
+
"""
|
| 802 |
+
Generate a submodule.
|
| 803 |
+
|
| 804 |
+
Examples
|
| 805 |
+
========
|
| 806 |
+
|
| 807 |
+
>>> from sympy.abc import x
|
| 808 |
+
>>> from sympy import QQ
|
| 809 |
+
>>> M = QQ.old_poly_ring(x).free_module(2).submodule([x, 1])
|
| 810 |
+
>>> M.submodule([x**2, x])
|
| 811 |
+
<[x**2, x]>
|
| 812 |
+
"""
|
| 813 |
+
if not self.subset(gens):
|
| 814 |
+
raise ValueError('%s not a subset of %s' % (gens, self))
|
| 815 |
+
return self.__class__(gens, self.container)
|
| 816 |
+
|
| 817 |
+
def is_full_module(self):
|
| 818 |
+
"""
|
| 819 |
+
Return True if ``self`` is the entire free module.
|
| 820 |
+
|
| 821 |
+
Examples
|
| 822 |
+
========
|
| 823 |
+
|
| 824 |
+
>>> from sympy.abc import x
|
| 825 |
+
>>> from sympy import QQ
|
| 826 |
+
>>> F = QQ.old_poly_ring(x).free_module(2)
|
| 827 |
+
>>> F.submodule([x, 1]).is_full_module()
|
| 828 |
+
False
|
| 829 |
+
>>> F.submodule([1, 1], [1, 2]).is_full_module()
|
| 830 |
+
True
|
| 831 |
+
"""
|
| 832 |
+
return all(self.contains(x) for x in self.container.basis())
|
| 833 |
+
|
| 834 |
+
def is_submodule(self, other):
|
| 835 |
+
"""
|
| 836 |
+
Returns True if ``other`` is a submodule of ``self``.
|
| 837 |
+
|
| 838 |
+
>>> from sympy.abc import x
|
| 839 |
+
>>> from sympy import QQ
|
| 840 |
+
>>> F = QQ.old_poly_ring(x).free_module(2)
|
| 841 |
+
>>> M = F.submodule([2, x])
|
| 842 |
+
>>> N = M.submodule([2*x, x**2])
|
| 843 |
+
>>> M.is_submodule(M)
|
| 844 |
+
True
|
| 845 |
+
>>> M.is_submodule(N)
|
| 846 |
+
True
|
| 847 |
+
>>> N.is_submodule(M)
|
| 848 |
+
False
|
| 849 |
+
"""
|
| 850 |
+
if isinstance(other, SubModule):
|
| 851 |
+
return self.container == other.container and \
|
| 852 |
+
all(self.contains(x) for x in other.gens)
|
| 853 |
+
if isinstance(other, (FreeModule, QuotientModule)):
|
| 854 |
+
return self.container == other and self.is_full_module()
|
| 855 |
+
return False
|
| 856 |
+
|
| 857 |
+
def syzygy_module(self, **opts):
|
| 858 |
+
r"""
|
| 859 |
+
Compute the syzygy module of the generators of ``self``.
|
| 860 |
+
|
| 861 |
+
Suppose `M` is generated by `f_1, \ldots, f_n` over the ring
|
| 862 |
+
`R`. Consider the homomorphism `\phi: R^n \to M`, given by
|
| 863 |
+
sending `(r_1, \ldots, r_n) \to r_1 f_1 + \cdots + r_n f_n`.
|
| 864 |
+
The syzygy module is defined to be the kernel of `\phi`.
|
| 865 |
+
|
| 866 |
+
Examples
|
| 867 |
+
========
|
| 868 |
+
|
| 869 |
+
The syzygy module is zero iff the generators generate freely a free
|
| 870 |
+
submodule:
|
| 871 |
+
|
| 872 |
+
>>> from sympy.abc import x, y
|
| 873 |
+
>>> from sympy import QQ
|
| 874 |
+
>>> QQ.old_poly_ring(x).free_module(2).submodule([1, 0], [1, 1]).syzygy_module().is_zero()
|
| 875 |
+
True
|
| 876 |
+
|
| 877 |
+
A slightly more interesting example:
|
| 878 |
+
|
| 879 |
+
>>> M = QQ.old_poly_ring(x, y).free_module(2).submodule([x, 2*x], [y, 2*y])
|
| 880 |
+
>>> S = QQ.old_poly_ring(x, y).free_module(2).submodule([y, -x])
|
| 881 |
+
>>> M.syzygy_module() == S
|
| 882 |
+
True
|
| 883 |
+
"""
|
| 884 |
+
F = self.ring.free_module(len(self.gens))
|
| 885 |
+
# NOTE we filter out zero syzygies. This is for convenience of the
|
| 886 |
+
# _syzygies function and not meant to replace any real "generating set
|
| 887 |
+
# reduction" algorithm
|
| 888 |
+
return F.submodule(*[x for x in self._syzygies() if F.convert(x) != 0],
|
| 889 |
+
**opts)
|
| 890 |
+
|
| 891 |
+
def in_terms_of_generators(self, e):
|
| 892 |
+
"""
|
| 893 |
+
Express element ``e`` of ``self`` in terms of the generators.
|
| 894 |
+
|
| 895 |
+
Examples
|
| 896 |
+
========
|
| 897 |
+
|
| 898 |
+
>>> from sympy.abc import x
|
| 899 |
+
>>> from sympy import QQ
|
| 900 |
+
>>> F = QQ.old_poly_ring(x).free_module(2)
|
| 901 |
+
>>> M = F.submodule([1, 0], [1, 1])
|
| 902 |
+
>>> M.in_terms_of_generators([x, x**2]) # doctest: +SKIP
|
| 903 |
+
[DMP_Python([-1, 1, 0], QQ), DMP_Python([1, 0, 0], QQ)]
|
| 904 |
+
"""
|
| 905 |
+
try:
|
| 906 |
+
e = self.convert(e)
|
| 907 |
+
except CoercionFailed:
|
| 908 |
+
raise ValueError('%s is not an element of %s' % (e, self))
|
| 909 |
+
return self._in_terms_of_generators(e)
|
| 910 |
+
|
| 911 |
+
def reduce_element(self, x):
|
| 912 |
+
"""
|
| 913 |
+
Reduce the element ``x`` of our ring modulo the ideal ``self``.
|
| 914 |
+
|
| 915 |
+
Here "reduce" has no specific meaning, it could return a unique normal
|
| 916 |
+
form, simplify the expression a bit, or just do nothing.
|
| 917 |
+
"""
|
| 918 |
+
return x
|
| 919 |
+
|
| 920 |
+
def quotient_module(self, other, **opts):
|
| 921 |
+
"""
|
| 922 |
+
Return a quotient module.
|
| 923 |
+
|
| 924 |
+
This is the same as taking a submodule of a quotient of the containing
|
| 925 |
+
module.
|
| 926 |
+
|
| 927 |
+
Examples
|
| 928 |
+
========
|
| 929 |
+
|
| 930 |
+
>>> from sympy.abc import x
|
| 931 |
+
>>> from sympy import QQ
|
| 932 |
+
>>> F = QQ.old_poly_ring(x).free_module(2)
|
| 933 |
+
>>> S1 = F.submodule([x, 1])
|
| 934 |
+
>>> S2 = F.submodule([x**2, x])
|
| 935 |
+
>>> S1.quotient_module(S2)
|
| 936 |
+
<[x, 1] + <[x**2, x]>>
|
| 937 |
+
|
| 938 |
+
Or more coincisely, using the overloaded division operator:
|
| 939 |
+
|
| 940 |
+
>>> F.submodule([x, 1]) / [(x**2, x)]
|
| 941 |
+
<[x, 1] + <[x**2, x]>>
|
| 942 |
+
"""
|
| 943 |
+
if not self.is_submodule(other):
|
| 944 |
+
raise ValueError('%s not a submodule of %s' % (other, self))
|
| 945 |
+
return SubQuotientModule(self.gens,
|
| 946 |
+
self.container.quotient_module(other), **opts)
|
| 947 |
+
|
| 948 |
+
def __add__(self, oth):
|
| 949 |
+
return self.container.quotient_module(self).convert(oth)
|
| 950 |
+
|
| 951 |
+
__radd__ = __add__
|
| 952 |
+
|
| 953 |
+
def multiply_ideal(self, I):
|
| 954 |
+
"""
|
| 955 |
+
Multiply ``self`` by the ideal ``I``.
|
| 956 |
+
|
| 957 |
+
Examples
|
| 958 |
+
========
|
| 959 |
+
|
| 960 |
+
>>> from sympy.abc import x
|
| 961 |
+
>>> from sympy import QQ
|
| 962 |
+
>>> I = QQ.old_poly_ring(x).ideal(x**2)
|
| 963 |
+
>>> M = QQ.old_poly_ring(x).free_module(2).submodule([1, 1])
|
| 964 |
+
>>> I*M
|
| 965 |
+
<[x**2, x**2]>
|
| 966 |
+
"""
|
| 967 |
+
return self.submodule(*[x*g for [x] in I._module.gens for g in self.gens])
|
| 968 |
+
|
| 969 |
+
def inclusion_hom(self):
|
| 970 |
+
"""
|
| 971 |
+
Return a homomorphism representing the inclusion map of ``self``.
|
| 972 |
+
|
| 973 |
+
That is, the natural map from ``self`` to ``self.container``.
|
| 974 |
+
|
| 975 |
+
Examples
|
| 976 |
+
========
|
| 977 |
+
|
| 978 |
+
>>> from sympy.abc import x
|
| 979 |
+
>>> from sympy import QQ
|
| 980 |
+
>>> QQ.old_poly_ring(x).free_module(2).submodule([x, x]).inclusion_hom()
|
| 981 |
+
Matrix([
|
| 982 |
+
[1, 0], : <[x, x]> -> QQ[x]**2
|
| 983 |
+
[0, 1]])
|
| 984 |
+
"""
|
| 985 |
+
return self.container.identity_hom().restrict_domain(self)
|
| 986 |
+
|
| 987 |
+
def identity_hom(self):
|
| 988 |
+
"""
|
| 989 |
+
Return the identity homomorphism on ``self``.
|
| 990 |
+
|
| 991 |
+
Examples
|
| 992 |
+
========
|
| 993 |
+
|
| 994 |
+
>>> from sympy.abc import x
|
| 995 |
+
>>> from sympy import QQ
|
| 996 |
+
>>> QQ.old_poly_ring(x).free_module(2).submodule([x, x]).identity_hom()
|
| 997 |
+
Matrix([
|
| 998 |
+
[1, 0], : <[x, x]> -> <[x, x]>
|
| 999 |
+
[0, 1]])
|
| 1000 |
+
"""
|
| 1001 |
+
return self.container.identity_hom().restrict_domain(
|
| 1002 |
+
self).restrict_codomain(self)
|
| 1003 |
+
|
| 1004 |
+
|
| 1005 |
+
class SubQuotientModule(SubModule):
|
| 1006 |
+
"""
|
| 1007 |
+
Submodule of a quotient module.
|
| 1008 |
+
|
| 1009 |
+
Equivalently, quotient module of a submodule.
|
| 1010 |
+
|
| 1011 |
+
Do not instantiate this, instead use the submodule or quotient_module
|
| 1012 |
+
constructing methods:
|
| 1013 |
+
|
| 1014 |
+
>>> from sympy.abc import x
|
| 1015 |
+
>>> from sympy import QQ
|
| 1016 |
+
>>> F = QQ.old_poly_ring(x).free_module(2)
|
| 1017 |
+
>>> S = F.submodule([1, 0], [1, x])
|
| 1018 |
+
>>> Q = F/[(1, 0)]
|
| 1019 |
+
>>> S/[(1, 0)] == Q.submodule([5, x])
|
| 1020 |
+
True
|
| 1021 |
+
|
| 1022 |
+
Attributes:
|
| 1023 |
+
|
| 1024 |
+
- base - base module we are quotient of
|
| 1025 |
+
- killed_module - submodule used to form the quotient
|
| 1026 |
+
"""
|
| 1027 |
+
def __init__(self, gens, container, **opts):
|
| 1028 |
+
SubModule.__init__(self, gens, container)
|
| 1029 |
+
self.killed_module = self.container.killed_module
|
| 1030 |
+
# XXX it is important for some code below that the generators of base
|
| 1031 |
+
# are in this particular order!
|
| 1032 |
+
self.base = self.container.base.submodule(
|
| 1033 |
+
*[x.data for x in self.gens], **opts).union(self.killed_module)
|
| 1034 |
+
|
| 1035 |
+
def _contains(self, elem):
|
| 1036 |
+
return self.base.contains(elem.data)
|
| 1037 |
+
|
| 1038 |
+
def _syzygies(self):
|
| 1039 |
+
# let N = self.killed_module be generated by e_1, ..., e_r
|
| 1040 |
+
# let F = self.base be generated by f_1, ..., f_s and e_1, ..., e_r
|
| 1041 |
+
# Then self = F/N.
|
| 1042 |
+
# Let phi: R**s --> self be the evident surjection.
|
| 1043 |
+
# Similarly psi: R**(s + r) --> F.
|
| 1044 |
+
# We need to find generators for ker(phi). Let chi: R**s --> F be the
|
| 1045 |
+
# evident lift of phi. For X in R**s, phi(X) = 0 iff chi(X) is
|
| 1046 |
+
# contained in N, iff there exists Y in R**r such that
|
| 1047 |
+
# psi(X, Y) = 0.
|
| 1048 |
+
# Hence if alpha: R**(s + r) --> R**s is the projection map, then
|
| 1049 |
+
# ker(phi) = alpha ker(psi).
|
| 1050 |
+
return [X[:len(self.gens)] for X in self.base._syzygies()]
|
| 1051 |
+
|
| 1052 |
+
def _in_terms_of_generators(self, e):
|
| 1053 |
+
return self.base._in_terms_of_generators(e.data)[:len(self.gens)]
|
| 1054 |
+
|
| 1055 |
+
def is_full_module(self):
|
| 1056 |
+
"""
|
| 1057 |
+
Return True if ``self`` is the entire free module.
|
| 1058 |
+
|
| 1059 |
+
Examples
|
| 1060 |
+
========
|
| 1061 |
+
|
| 1062 |
+
>>> from sympy.abc import x
|
| 1063 |
+
>>> from sympy import QQ
|
| 1064 |
+
>>> F = QQ.old_poly_ring(x).free_module(2)
|
| 1065 |
+
>>> F.submodule([x, 1]).is_full_module()
|
| 1066 |
+
False
|
| 1067 |
+
>>> F.submodule([1, 1], [1, 2]).is_full_module()
|
| 1068 |
+
True
|
| 1069 |
+
"""
|
| 1070 |
+
return self.base.is_full_module()
|
| 1071 |
+
|
| 1072 |
+
def quotient_hom(self):
|
| 1073 |
+
"""
|
| 1074 |
+
Return the quotient homomorphism to self.
|
| 1075 |
+
|
| 1076 |
+
That is, return the natural map from ``self.base`` to ``self``.
|
| 1077 |
+
|
| 1078 |
+
Examples
|
| 1079 |
+
========
|
| 1080 |
+
|
| 1081 |
+
>>> from sympy.abc import x
|
| 1082 |
+
>>> from sympy import QQ
|
| 1083 |
+
>>> M = (QQ.old_poly_ring(x).free_module(2) / [(1, x)]).submodule([1, 0])
|
| 1084 |
+
>>> M.quotient_hom()
|
| 1085 |
+
Matrix([
|
| 1086 |
+
[1, 0], : <[1, 0], [1, x]> -> <[1, 0] + <[1, x]>, [1, x] + <[1, x]>>
|
| 1087 |
+
[0, 1]])
|
| 1088 |
+
"""
|
| 1089 |
+
return self.base.identity_hom().quotient_codomain(self.killed_module)
|
| 1090 |
+
|
| 1091 |
+
|
| 1092 |
+
_subs0 = lambda x: x[0]
|
| 1093 |
+
_subs1 = lambda x: x[1:]
|
| 1094 |
+
|
| 1095 |
+
|
| 1096 |
+
class ModuleOrder(ProductOrder):
|
| 1097 |
+
"""A product monomial order with a zeroth term as module index."""
|
| 1098 |
+
|
| 1099 |
+
def __init__(self, o1, o2, TOP):
|
| 1100 |
+
if TOP:
|
| 1101 |
+
ProductOrder.__init__(self, (o2, _subs1), (o1, _subs0))
|
| 1102 |
+
else:
|
| 1103 |
+
ProductOrder.__init__(self, (o1, _subs0), (o2, _subs1))
|
| 1104 |
+
|
| 1105 |
+
|
| 1106 |
+
class SubModulePolyRing(SubModule):
|
| 1107 |
+
"""
|
| 1108 |
+
Submodule of a free module over a generalized polynomial ring.
|
| 1109 |
+
|
| 1110 |
+
Do not instantiate this, use the constructor method of FreeModule instead:
|
| 1111 |
+
|
| 1112 |
+
>>> from sympy.abc import x, y
|
| 1113 |
+
>>> from sympy import QQ
|
| 1114 |
+
>>> F = QQ.old_poly_ring(x, y).free_module(2)
|
| 1115 |
+
>>> F.submodule([x, y], [1, 0])
|
| 1116 |
+
<[x, y], [1, 0]>
|
| 1117 |
+
|
| 1118 |
+
Attributes:
|
| 1119 |
+
|
| 1120 |
+
- order - monomial order used
|
| 1121 |
+
"""
|
| 1122 |
+
|
| 1123 |
+
#self._gb - cached groebner basis
|
| 1124 |
+
#self._gbe - cached groebner basis relations
|
| 1125 |
+
|
| 1126 |
+
def __init__(self, gens, container, order="lex", TOP=True):
|
| 1127 |
+
SubModule.__init__(self, gens, container)
|
| 1128 |
+
if not isinstance(container, FreeModulePolyRing):
|
| 1129 |
+
raise NotImplementedError('This implementation is for submodules of '
|
| 1130 |
+
+ 'FreeModulePolyRing, got %s' % container)
|
| 1131 |
+
self.order = ModuleOrder(monomial_key(order), self.ring.order, TOP)
|
| 1132 |
+
self._gb = None
|
| 1133 |
+
self._gbe = None
|
| 1134 |
+
|
| 1135 |
+
def __eq__(self, other):
|
| 1136 |
+
if isinstance(other, SubModulePolyRing) and self.order != other.order:
|
| 1137 |
+
return False
|
| 1138 |
+
return SubModule.__eq__(self, other)
|
| 1139 |
+
|
| 1140 |
+
def _groebner(self, extended=False):
|
| 1141 |
+
"""Returns a standard basis in sdm form."""
|
| 1142 |
+
from sympy.polys.distributedmodules import sdm_groebner, sdm_nf_mora
|
| 1143 |
+
if self._gbe is None and extended:
|
| 1144 |
+
gb, gbe = sdm_groebner(
|
| 1145 |
+
[self.ring._vector_to_sdm(x, self.order) for x in self.gens],
|
| 1146 |
+
sdm_nf_mora, self.order, self.ring.dom, extended=True)
|
| 1147 |
+
self._gb, self._gbe = tuple(gb), tuple(gbe)
|
| 1148 |
+
if self._gb is None:
|
| 1149 |
+
self._gb = tuple(sdm_groebner(
|
| 1150 |
+
[self.ring._vector_to_sdm(x, self.order) for x in self.gens],
|
| 1151 |
+
sdm_nf_mora, self.order, self.ring.dom))
|
| 1152 |
+
if extended:
|
| 1153 |
+
return self._gb, self._gbe
|
| 1154 |
+
else:
|
| 1155 |
+
return self._gb
|
| 1156 |
+
|
| 1157 |
+
def _groebner_vec(self, extended=False):
|
| 1158 |
+
"""Returns a standard basis in element form."""
|
| 1159 |
+
if not extended:
|
| 1160 |
+
return [FreeModuleElement(self,
|
| 1161 |
+
tuple(self.ring._sdm_to_vector(x, self.rank)))
|
| 1162 |
+
for x in self._groebner()]
|
| 1163 |
+
gb, gbe = self._groebner(extended=True)
|
| 1164 |
+
return ([self.convert(self.ring._sdm_to_vector(x, self.rank))
|
| 1165 |
+
for x in gb],
|
| 1166 |
+
[self.ring._sdm_to_vector(x, len(self.gens)) for x in gbe])
|
| 1167 |
+
|
| 1168 |
+
def _contains(self, x):
|
| 1169 |
+
from sympy.polys.distributedmodules import sdm_zero, sdm_nf_mora
|
| 1170 |
+
return sdm_nf_mora(self.ring._vector_to_sdm(x, self.order),
|
| 1171 |
+
self._groebner(), self.order, self.ring.dom) == \
|
| 1172 |
+
sdm_zero()
|
| 1173 |
+
|
| 1174 |
+
def _syzygies(self):
|
| 1175 |
+
"""Compute syzygies. See [SCA, algorithm 2.5.4]."""
|
| 1176 |
+
# NOTE if self.gens is a standard basis, this can be done more
|
| 1177 |
+
# efficiently using Schreyer's theorem
|
| 1178 |
+
|
| 1179 |
+
# First bullet point
|
| 1180 |
+
k = len(self.gens)
|
| 1181 |
+
r = self.rank
|
| 1182 |
+
zero = self.ring.convert(0)
|
| 1183 |
+
one = self.ring.convert(1)
|
| 1184 |
+
Rkr = self.ring.free_module(r + k)
|
| 1185 |
+
newgens = []
|
| 1186 |
+
for j, f in enumerate(self.gens):
|
| 1187 |
+
m = [0]*(r + k)
|
| 1188 |
+
for i, v in enumerate(f):
|
| 1189 |
+
m[i] = v
|
| 1190 |
+
for i in range(k):
|
| 1191 |
+
m[r + i] = one if j == i else zero
|
| 1192 |
+
m = FreeModuleElement(Rkr, tuple(m))
|
| 1193 |
+
newgens.append(m)
|
| 1194 |
+
# Note: we need *descending* order on module index, and TOP=False to
|
| 1195 |
+
# get an elimination order
|
| 1196 |
+
F = Rkr.submodule(*newgens, order='ilex', TOP=False)
|
| 1197 |
+
|
| 1198 |
+
# Second bullet point: standard basis of F
|
| 1199 |
+
G = F._groebner_vec()
|
| 1200 |
+
|
| 1201 |
+
# Third bullet point: G0 = G intersect the new k components
|
| 1202 |
+
G0 = [x[r:] for x in G if all(y == zero for y in x[:r])]
|
| 1203 |
+
|
| 1204 |
+
# Fourth and fifth bullet points: we are done
|
| 1205 |
+
return G0
|
| 1206 |
+
|
| 1207 |
+
def _in_terms_of_generators(self, e):
|
| 1208 |
+
"""Expression in terms of generators. See [SCA, 2.8.1]."""
|
| 1209 |
+
# NOTE: if gens is a standard basis, this can be done more efficiently
|
| 1210 |
+
M = self.ring.free_module(self.rank).submodule(*((e,) + self.gens))
|
| 1211 |
+
S = M.syzygy_module(
|
| 1212 |
+
order="ilex", TOP=False) # We want decreasing order!
|
| 1213 |
+
G = S._groebner_vec()
|
| 1214 |
+
# This list cannot not be empty since e is an element
|
| 1215 |
+
e = [x for x in G if self.ring.is_unit(x[0])][0]
|
| 1216 |
+
return [-x/e[0] for x in e[1:]]
|
| 1217 |
+
|
| 1218 |
+
def reduce_element(self, x, NF=None):
|
| 1219 |
+
"""
|
| 1220 |
+
Reduce the element ``x`` of our container modulo ``self``.
|
| 1221 |
+
|
| 1222 |
+
This applies the normal form ``NF`` to ``x``. If ``NF`` is passed
|
| 1223 |
+
as none, the default Mora normal form is used (which is not unique!).
|
| 1224 |
+
"""
|
| 1225 |
+
from sympy.polys.distributedmodules import sdm_nf_mora
|
| 1226 |
+
if NF is None:
|
| 1227 |
+
NF = sdm_nf_mora
|
| 1228 |
+
return self.container.convert(self.ring._sdm_to_vector(NF(
|
| 1229 |
+
self.ring._vector_to_sdm(x, self.order), self._groebner(),
|
| 1230 |
+
self.order, self.ring.dom),
|
| 1231 |
+
self.rank))
|
| 1232 |
+
|
| 1233 |
+
def _intersect(self, other, relations=False):
|
| 1234 |
+
# See: [SCA, section 2.8.2]
|
| 1235 |
+
fi = self.gens
|
| 1236 |
+
hi = other.gens
|
| 1237 |
+
r = self.rank
|
| 1238 |
+
ci = [[0]*(2*r) for _ in range(r)]
|
| 1239 |
+
for k in range(r):
|
| 1240 |
+
ci[k][k] = 1
|
| 1241 |
+
ci[k][r + k] = 1
|
| 1242 |
+
di = [list(f) + [0]*r for f in fi]
|
| 1243 |
+
ei = [[0]*r + list(h) for h in hi]
|
| 1244 |
+
syz = self.ring.free_module(2*r).submodule(*(ci + di + ei))._syzygies()
|
| 1245 |
+
nonzero = [x for x in syz if any(y != self.ring.zero for y in x[:r])]
|
| 1246 |
+
res = self.container.submodule(*([-y for y in x[:r]] for x in nonzero))
|
| 1247 |
+
reln1 = [x[r:r + len(fi)] for x in nonzero]
|
| 1248 |
+
reln2 = [x[r + len(fi):] for x in nonzero]
|
| 1249 |
+
if relations:
|
| 1250 |
+
return res, reln1, reln2
|
| 1251 |
+
return res
|
| 1252 |
+
|
| 1253 |
+
def _module_quotient(self, other, relations=False):
|
| 1254 |
+
# See: [SCA, section 2.8.4]
|
| 1255 |
+
if relations and len(other.gens) != 1:
|
| 1256 |
+
raise NotImplementedError
|
| 1257 |
+
if len(other.gens) == 0:
|
| 1258 |
+
return self.ring.ideal(1)
|
| 1259 |
+
elif len(other.gens) == 1:
|
| 1260 |
+
# We do some trickery. Let f be the (vector!) generating ``other``
|
| 1261 |
+
# and f1, .., fn be the (vectors) generating self.
|
| 1262 |
+
# Consider the submodule of R^{r+1} generated by (f, 1) and
|
| 1263 |
+
# {(fi, 0) | i}. Then the intersection with the last module
|
| 1264 |
+
# component yields the quotient.
|
| 1265 |
+
g1 = list(other.gens[0]) + [1]
|
| 1266 |
+
gi = [list(x) + [0] for x in self.gens]
|
| 1267 |
+
# NOTE: We *need* to use an elimination order
|
| 1268 |
+
M = self.ring.free_module(self.rank + 1).submodule(*([g1] + gi),
|
| 1269 |
+
order='ilex', TOP=False)
|
| 1270 |
+
if not relations:
|
| 1271 |
+
return self.ring.ideal(*[x[-1] for x in M._groebner_vec() if
|
| 1272 |
+
all(y == self.ring.zero for y in x[:-1])])
|
| 1273 |
+
else:
|
| 1274 |
+
G, R = M._groebner_vec(extended=True)
|
| 1275 |
+
indices = [i for i, x in enumerate(G) if
|
| 1276 |
+
all(y == self.ring.zero for y in x[:-1])]
|
| 1277 |
+
return (self.ring.ideal(*[G[i][-1] for i in indices]),
|
| 1278 |
+
[[-x for x in R[i][1:]] for i in indices])
|
| 1279 |
+
# For more generators, we use I : <h1, .., hn> = intersection of
|
| 1280 |
+
# {I : <hi> | i}
|
| 1281 |
+
# TODO this can be done more efficiently
|
| 1282 |
+
return reduce(lambda x, y: x.intersect(y),
|
| 1283 |
+
(self._module_quotient(self.container.submodule(x)) for x in other.gens))
|
| 1284 |
+
|
| 1285 |
+
|
| 1286 |
+
class SubModuleQuotientRing(SubModule):
|
| 1287 |
+
"""
|
| 1288 |
+
Class for submodules of free modules over quotient rings.
|
| 1289 |
+
|
| 1290 |
+
Do not instantiate this. Instead use the submodule methods.
|
| 1291 |
+
|
| 1292 |
+
>>> from sympy.abc import x, y
|
| 1293 |
+
>>> from sympy import QQ
|
| 1294 |
+
>>> M = (QQ.old_poly_ring(x, y)/[x**2 - y**2]).free_module(2).submodule([x, x + y])
|
| 1295 |
+
>>> M
|
| 1296 |
+
<[x + <x**2 - y**2>, x + y + <x**2 - y**2>]>
|
| 1297 |
+
>>> M.contains([y**2, x**2 + x*y])
|
| 1298 |
+
True
|
| 1299 |
+
>>> M.contains([x, y])
|
| 1300 |
+
False
|
| 1301 |
+
|
| 1302 |
+
Attributes:
|
| 1303 |
+
|
| 1304 |
+
- quot - the subquotient of `R^n/IR^n` generated by lifts of our generators
|
| 1305 |
+
"""
|
| 1306 |
+
|
| 1307 |
+
def __init__(self, gens, container):
|
| 1308 |
+
SubModule.__init__(self, gens, container)
|
| 1309 |
+
self.quot = self.container.quot.submodule(
|
| 1310 |
+
*[self.container.lift(x) for x in self.gens])
|
| 1311 |
+
|
| 1312 |
+
def _contains(self, elem):
|
| 1313 |
+
return self.quot._contains(self.container.lift(elem))
|
| 1314 |
+
|
| 1315 |
+
def _syzygies(self):
|
| 1316 |
+
return [tuple(self.ring.convert(y, self.quot.ring) for y in x)
|
| 1317 |
+
for x in self.quot._syzygies()]
|
| 1318 |
+
|
| 1319 |
+
def _in_terms_of_generators(self, elem):
|
| 1320 |
+
return [self.ring.convert(x, self.quot.ring) for x in
|
| 1321 |
+
self.quot._in_terms_of_generators(self.container.lift(elem))]
|
| 1322 |
+
|
| 1323 |
+
##########################################################################
|
| 1324 |
+
## Quotient Modules ######################################################
|
| 1325 |
+
##########################################################################
|
| 1326 |
+
|
| 1327 |
+
|
| 1328 |
+
class QuotientModuleElement(ModuleElement):
|
| 1329 |
+
"""Element of a quotient module."""
|
| 1330 |
+
|
| 1331 |
+
def eq(self, d1, d2):
|
| 1332 |
+
"""Equality comparison."""
|
| 1333 |
+
return self.module.killed_module.contains(d1 - d2)
|
| 1334 |
+
|
| 1335 |
+
def __repr__(self):
|
| 1336 |
+
return repr(self.data) + " + " + repr(self.module.killed_module)
|
| 1337 |
+
|
| 1338 |
+
|
| 1339 |
+
class QuotientModule(Module):
|
| 1340 |
+
"""
|
| 1341 |
+
Class for quotient modules.
|
| 1342 |
+
|
| 1343 |
+
Do not instantiate this directly. For subquotients, see the
|
| 1344 |
+
SubQuotientModule class.
|
| 1345 |
+
|
| 1346 |
+
Attributes:
|
| 1347 |
+
|
| 1348 |
+
- base - the base module we are a quotient of
|
| 1349 |
+
- killed_module - the submodule used to form the quotient
|
| 1350 |
+
- rank of the base
|
| 1351 |
+
"""
|
| 1352 |
+
|
| 1353 |
+
dtype = QuotientModuleElement
|
| 1354 |
+
|
| 1355 |
+
def __init__(self, ring, base, submodule):
|
| 1356 |
+
Module.__init__(self, ring)
|
| 1357 |
+
if not base.is_submodule(submodule):
|
| 1358 |
+
raise ValueError('%s is not a submodule of %s' % (submodule, base))
|
| 1359 |
+
self.base = base
|
| 1360 |
+
self.killed_module = submodule
|
| 1361 |
+
self.rank = base.rank
|
| 1362 |
+
|
| 1363 |
+
def __repr__(self):
|
| 1364 |
+
return repr(self.base) + "/" + repr(self.killed_module)
|
| 1365 |
+
|
| 1366 |
+
def is_zero(self):
|
| 1367 |
+
"""
|
| 1368 |
+
Return True if ``self`` is a zero module.
|
| 1369 |
+
|
| 1370 |
+
This happens if and only if the base module is the same as the
|
| 1371 |
+
submodule being killed.
|
| 1372 |
+
|
| 1373 |
+
Examples
|
| 1374 |
+
========
|
| 1375 |
+
|
| 1376 |
+
>>> from sympy.abc import x
|
| 1377 |
+
>>> from sympy import QQ
|
| 1378 |
+
>>> F = QQ.old_poly_ring(x).free_module(2)
|
| 1379 |
+
>>> (F/[(1, 0)]).is_zero()
|
| 1380 |
+
False
|
| 1381 |
+
>>> (F/[(1, 0), (0, 1)]).is_zero()
|
| 1382 |
+
True
|
| 1383 |
+
"""
|
| 1384 |
+
return self.base == self.killed_module
|
| 1385 |
+
|
| 1386 |
+
def is_submodule(self, other):
|
| 1387 |
+
"""
|
| 1388 |
+
Return True if ``other`` is a submodule of ``self``.
|
| 1389 |
+
|
| 1390 |
+
Examples
|
| 1391 |
+
========
|
| 1392 |
+
|
| 1393 |
+
>>> from sympy.abc import x
|
| 1394 |
+
>>> from sympy import QQ
|
| 1395 |
+
>>> Q = QQ.old_poly_ring(x).free_module(2) / [(x, x)]
|
| 1396 |
+
>>> S = Q.submodule([1, 0])
|
| 1397 |
+
>>> Q.is_submodule(S)
|
| 1398 |
+
True
|
| 1399 |
+
>>> S.is_submodule(Q)
|
| 1400 |
+
False
|
| 1401 |
+
"""
|
| 1402 |
+
if isinstance(other, QuotientModule):
|
| 1403 |
+
return self.killed_module == other.killed_module and \
|
| 1404 |
+
self.base.is_submodule(other.base)
|
| 1405 |
+
if isinstance(other, SubQuotientModule):
|
| 1406 |
+
return other.container == self
|
| 1407 |
+
return False
|
| 1408 |
+
|
| 1409 |
+
def submodule(self, *gens, **opts):
|
| 1410 |
+
"""
|
| 1411 |
+
Generate a submodule.
|
| 1412 |
+
|
| 1413 |
+
This is the same as taking a quotient of a submodule of the base
|
| 1414 |
+
module.
|
| 1415 |
+
|
| 1416 |
+
Examples
|
| 1417 |
+
========
|
| 1418 |
+
|
| 1419 |
+
>>> from sympy.abc import x
|
| 1420 |
+
>>> from sympy import QQ
|
| 1421 |
+
>>> Q = QQ.old_poly_ring(x).free_module(2) / [(x, x)]
|
| 1422 |
+
>>> Q.submodule([x, 0])
|
| 1423 |
+
<[x, 0] + <[x, x]>>
|
| 1424 |
+
"""
|
| 1425 |
+
return SubQuotientModule(gens, self, **opts)
|
| 1426 |
+
|
| 1427 |
+
def convert(self, elem, M=None):
|
| 1428 |
+
"""
|
| 1429 |
+
Convert ``elem`` into the internal representation.
|
| 1430 |
+
|
| 1431 |
+
This method is called implicitly whenever computations involve elements
|
| 1432 |
+
not in the internal representation.
|
| 1433 |
+
|
| 1434 |
+
Examples
|
| 1435 |
+
========
|
| 1436 |
+
|
| 1437 |
+
>>> from sympy.abc import x
|
| 1438 |
+
>>> from sympy import QQ
|
| 1439 |
+
>>> F = QQ.old_poly_ring(x).free_module(2) / [(1, 2), (1, x)]
|
| 1440 |
+
>>> F.convert([1, 0])
|
| 1441 |
+
[1, 0] + <[1, 2], [1, x]>
|
| 1442 |
+
"""
|
| 1443 |
+
if isinstance(elem, QuotientModuleElement):
|
| 1444 |
+
if elem.module is self:
|
| 1445 |
+
return elem
|
| 1446 |
+
if self.killed_module.is_submodule(elem.module.killed_module):
|
| 1447 |
+
return QuotientModuleElement(self, self.base.convert(elem.data))
|
| 1448 |
+
raise CoercionFailed
|
| 1449 |
+
return QuotientModuleElement(self, self.base.convert(elem))
|
| 1450 |
+
|
| 1451 |
+
def identity_hom(self):
|
| 1452 |
+
"""
|
| 1453 |
+
Return the identity homomorphism on ``self``.
|
| 1454 |
+
|
| 1455 |
+
Examples
|
| 1456 |
+
========
|
| 1457 |
+
|
| 1458 |
+
>>> from sympy.abc import x
|
| 1459 |
+
>>> from sympy import QQ
|
| 1460 |
+
>>> M = QQ.old_poly_ring(x).free_module(2) / [(1, 2), (1, x)]
|
| 1461 |
+
>>> M.identity_hom()
|
| 1462 |
+
Matrix([
|
| 1463 |
+
[1, 0], : QQ[x]**2/<[1, 2], [1, x]> -> QQ[x]**2/<[1, 2], [1, x]>
|
| 1464 |
+
[0, 1]])
|
| 1465 |
+
"""
|
| 1466 |
+
return self.base.identity_hom().quotient_codomain(
|
| 1467 |
+
self.killed_module).quotient_domain(self.killed_module)
|
| 1468 |
+
|
| 1469 |
+
def quotient_hom(self):
|
| 1470 |
+
"""
|
| 1471 |
+
Return the quotient homomorphism to ``self``.
|
| 1472 |
+
|
| 1473 |
+
That is, return a homomorphism representing the natural map from
|
| 1474 |
+
``self.base`` to ``self``.
|
| 1475 |
+
|
| 1476 |
+
Examples
|
| 1477 |
+
========
|
| 1478 |
+
|
| 1479 |
+
>>> from sympy.abc import x
|
| 1480 |
+
>>> from sympy import QQ
|
| 1481 |
+
>>> M = QQ.old_poly_ring(x).free_module(2) / [(1, 2), (1, x)]
|
| 1482 |
+
>>> M.quotient_hom()
|
| 1483 |
+
Matrix([
|
| 1484 |
+
[1, 0], : QQ[x]**2 -> QQ[x]**2/<[1, 2], [1, x]>
|
| 1485 |
+
[0, 1]])
|
| 1486 |
+
"""
|
| 1487 |
+
return self.base.identity_hom().quotient_codomain(
|
| 1488 |
+
self.killed_module)
|