New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for Integral with lambdify (using scipy or mpmath) #20134
Conversation
also combines similar symbolic tests into one function
✅ Hi, I am the SymPy bot (v160). I'm here to help you write a release notes entry. Please read the guide on how to write release notes. Your release notes are in good order. Here is what the release notes will look like: This will be added to https://github.com/sympy/sympy/wiki/Release-Notes-for-1.7. Note: This comment will be updated with the latest check if you edit the pull request. You need to reload the page to see it. Click here to see the pull request description that was parsed.
Update The release notes on the wiki have been updated. |
Codecov Report
@@ Coverage Diff @@
## master #20134 +/- ##
=============================================
+ Coverage 64.466% 72.360% +7.894%
=============================================
Files 671 671
Lines 173707 173803 +96
Branches 41020 41048 +28
=============================================
+ Hits 111982 125765 +13783
+ Misses 55307 42086 -13221
+ Partials 6418 5952 -466 |
This looks good to me. Nice addition! +1 merge after all CI passes. |
Does this work with vectorised inputs? |
If I understand correctly this seems to be the same question asked about the simpler case of constant functions in issue #5642 where it is desired that when a sympy constant function is lambdified but passed a vector parameter the constant result is returned in an array with the same shape as the parameter passed to the lambdified func. So right now this has the same problem. Adapting an example from that issue:
There's also |
For the vectorized situation, using the |
Another option is using trapz, simps, or romb for vectorized input: https://stackoverflow.com/questions/41223186/numpy-vectorization-with-integration That also begs the question of why quad is chosen versus another algorithm. If a user specifies a replacement function, it should also work. The lambdify api lets you swap out functions. |
This is an aside, but this is a pretty sweet package: https://github.com/nschloe/quadpy (just discovered it myself). |
One issue with the user specified replacement functions is they do have to accept the same signature as the sympy version but I guess it's documented that way (so the user would basically have to repeat the parsing code added here for supporting another numerical routine). Just a check that custom modules work with Integral (this would already work in master):
This PR also sweeps under the rug the additional options that can be passed to mpmath and scipy's quad but we likely have that issue with lambdifying other sympy functions. Incidentally, found a few more duplicate issues (added to references section). |
I think that's what the modules option is for. |
It might be nice if you could just pass additional keyword arguments to a module function but I think this could be a maintenance burden so it's best to leave it as is. |
This looks good. Thanks for fixing this long-standing issue. |
References to other Issues or PRs
Fixes #19641, Fixes #6408, Fixes #4470, Fixes #4471, Fixes #5932
Brief description of what is fixed or changed
Add support for Integral with lambdify (using scipy or mpmath printers)
Other comments
Release Notes