Skip to content
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

lambdify improvement via Direct mappings from Sympy Operations to Numpy/Scipy/ect. #13652

Open
GProtoZeroW opened this issue Nov 30, 2017 · 5 comments

Comments

@GProtoZeroW
Copy link

Tried using pycode and its scipy code with just the binomial coefficient and it did not work. And lambdify is just not verbose enough. So here is my prototype of a way to verbosely define the mappings between sympy mathematical operations and their respective main numerical python implementation by means of defining the mapping as a dunder method in the sympy operations class definition. I am more of front-end user then developer so this is the best I know how to do at the moment

https://github.com/GProtoZeroW/PythonToolForge/blob/master/SympyNumericalBinding.ipynb

@moorepants
Copy link
Member

This is an outstanding issue: #7229

There have been a number of attempts to add this functionality but seem to be stale pull requests. You may want to look into some of their implementations. Maybe you can improve it.

@GProtoZeroW
Copy link
Author

That issue chain has not been touched since '15. What I am suggesting is more than just scipy integration. For instance, I work with myHDL to generate verilog/VHDL code from python. And at one point it could take input from lambda but that is not the case and I have no idea why, but that's beside the point. For the boolean algebra operations, they can have a Dunder method for a version of lambdfy that works with that library. And Xilinx is working a lot with python for there FPGA's and may incorporate it into the HLS system. So if there where mappings for that it would be useful.

So what I am trying to get at is that lambdfy (and the code printing modules) might be the single most powerful function in all of python that allows math to be made code. But that is all in theory; until some more verbose internal mapping on each of the sympy operations (Integral, And, Sum (this one does work in numpy), ect.) is implemented where still stuck in the current haphazard implementation.

So I am going to keep tolling at this, but like I noted in the notebook I have no idea how to do some crazy OOP magic to make a method be auto-executed when the class instances are passed into a function like lambdfy or pycode. Where the direction that lambdfy needs to go to is pycode. But I don't understand what it is doing under the hood yet, and for that matter there still aspects of lambdfy I don't get.

@moorepants
Copy link
Member

This summer we finally implemented a proper Python code printer. A good next step would be to change out the backend of lambdify to use this printer. Lambdify is currently built in way that makes it hard to understand due to it being too clever with namspace injection. If it were backed by our normal printers, then adding dunder methods for a variety of common NumPy, SciPy, etc operations would become much easier and clearer.

@moorepants
Copy link
Member

And at one point it could take input from lambda but that is not the case and I have no idea why

Could it be because we recently made the default lambdify module numpy instead of mpmath? It was a subtle backwards incompatible change.

@GProtoZeroW
Copy link
Author

on the myHDL lambda thing and mpmath most likely. I have put my myHDL work on hold for the time do work on Fourier Optics that give's rise to the dreaded Fresnel integrals and then visualizing the output to yt. Which is why I need Integrate to be able to translate scipy.integrate.nquad .

@moorepants do you have any R&D files/notebooks(most preferable) of the python printer utility or lambdarepr.py. I would like to figure out how it does its voodoo. And where is this all development work happing on the net outside of the sympy's GitHub issue section.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants