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
Python code printer #12213
Comments
@Upabjojr , I would like to work on this issue, could you please refer the starting point |
Better discuss this issue a bit before starting, especially to get an idea of what other community members think about it. This could potentially clash with the |
Yes, you are right. |
Do you mean the printer in I agree it would be better to expand the functionality of this. It would be useful to directly codegen to Python. For instance, one could then subclass this to create a CythonPrinter. It does tie in pretty closely with the LambdaPrinter. They should definitely share some code. I'm not entirely sure what that should look like. LambdaPrinter is constrained in that it needs to print expressions, whereas the Maybe @bjodah has some ideas? |
And I should add that the |
I agree this is needed. I've needed it many times and just hacked around the str printer. I think it should likely be separate than lambdify because lambdify does all these import tricks. It should just be another code printer that ties into the rest of the codegen framework. |
Also, for what it's worth, the lambdify restriction that it prints an expression is not strictly needed. Right now, lambdify works like
(roughly). But it could also work like
which would open up the possibility to do things like variable assignment inside of the lambdified expression. And then, in the long run, |
@Upabjojr , I read about Lambdify as well as about codegen. I don't know about the difficulty of this issue if it is easy to fix then I would like to work. Could you please refer to the starting point for solving this issue. |
@mohit3011 , I would roughly try to see how |
@asmeurer , could you refer to any starting point on this issue and it's difficulty level. Thanks. |
@Upabjojr , did you look into this issue further ? |
No. The way to go is to debug the |
@Upabjojr , I looked into lambdify function in lambdify.py and also lambdarepr.py , but I couldn't get anything . Could you please help me |
@mohit3011 I suggest reading the documentation on how printing works: http://docs.sympy.org/latest/modules/printing.html as a start. |
@mohit3011 just debug the code, put some breakpoints and explore the local variables. Once you understand how the code works, it will be easier to purpose an edit. |
Since there is a rudimentary Python code printer now (since gh-12808) should we close this issue? We can open up new issues for the new printer (wishlists and/or bug-reports) |
The current Python printer prints expressions in a SymPy-style.
It could be useful to have a printer that prints non-SymPy Python code, for example:
Mod(x, 2)
asx % 2
And(x, y)
asx and y
instead of SymPy's operator overloadedx & y
.Currently:
str( )
is supposed to return a valid Python code that is (with some exceptions/caveats) able to reconstruct the SymPy object.lambdify( )
returns a lambda objects for optimized operations.The text was updated successfully, but these errors were encountered: