-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Rust codegen is broken #25173
Comments
Thank you for reporting this @smups . I think some of the issues can be fixed in the RustCodePrinter itself, others might require a preprocessing step (which |
@bjodah Yeah sure. The main issue that comes to mind is that rust does not support implicit conversion of numeric types. Sympy sometimes mixes floats and integer types in the output code. Things like: I believe it's currently ambiguous what type each parsed sympy symbol should have. I think it might be most straightforward to allow the user to specify the output type of the whole expression (with some sane default like For example, calling One complication (perhaps for a later revision) is that rust has a Here's an overview of which mathematics functions are available in rust's std: Float only:(arguments and return type are all floats)
Integer only:(arguments and return type are all integers)
Then there's
|
Thank you for expanding on this. I think the proper way forward is to add As for float vs. integer, I was hoping that using |
Yes, I think that would be a great solution. So to properly parse a sympy expression we would need:
|
The current rust printer is broken, it does not output valid rust code. It sometimes places floats where only integers are allowed and vice versa.
In rust,
2*arg[1].powi(2)
does not compile because 2 is not a float, 2.0 is.2.0*arg[1].powi(2.0)
also does not compile, becausepowi
expects an integer, not a float.Currently, sympy does not do this correctly. For example:
is printed as:
Python 3.11.3
Sympy 1.11.1
Fedora 38, virtual environment
The text was updated successfully, but these errors were encountered: