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 doesn't generate public functions #26562
Comments
Can you take some example of function? Also are you using |
I'm using RustCodegen with it's dump_rs function from sympy import exp, sin, cos, diff
from sympy.abc import x
from sympy.utilities.codegen import make_routine, RustCodeGen
with open("src/functions.rs", "w") as fout:
functions = {}
functions["y"] = exp(-x) * sin(x)
functions["y_prime"] = diff(functions["y"], x, 1)
functions["p"] = x**2
functions["q"] = cos(x)
functions["f"] = (
diff(functions["y"], x, 2)
+ functions["p"] * diff(functions["y"], x, 1)
+ functions["q"] * functions["y"]
)
c = RustCodeGen()
c.dump_rs(
[make_routine(name, expr) for name, expr in functions.items()], fout, ""
) generating the following code: /*
* Code generated with SymPy 1.12
*
* See http://www.sympy.org/ for more information.
*
* This file is part of 'project'
*/
fn y(x: f64) -> f64 {
let result_2048249359719250003 = (-x).exp()*x.sin();
result_2048249359719250003
}
fn y_prime(x: f64) -> f64 {
let result_54348404940285614 = -(-x).exp()*x.sin() + (-x).exp()*x.cos();
result_54348404940285614
}
fn p(x: f64) -> f64 {
let result_1966259434947152376 = x.powi(2);
result_1966259434947152376
}
fn q(x: f64) -> f64 {
let result_7659997875259276922 = x.cos();
result_7659997875259276922
}
fn f(x: f64) -> f64 {
let result_2450520253889769909 = x.powi(2)*(-(-x).exp()*x.sin() + (-x).exp()*x.cos()) + (-x).exp()*x.sin()*x.cos() - 2*(-x).exp()*x.cos();
result_2450520253889769909
} There's an error with an int multiplying floats in f(x), but that's in #25173. Apart from that, here it doesn't seem possible to make all generated functions visible with |
As an extra error I found using this method was when importing |
Coming back to this problem, adding Nonetheless, I don't know the scope and intention behind the code generators in sympy. Making all generated code I'd do a PR but depending on what would be more suitable to do, I'd prefer not making someone waste time reading code first before knowing what would be better for this lib. |
I'm okay with replacing
However, such expressions is not necessary to add to, because it is immature way of speaking, in general life advices. If your statements are not very 'genius', then please don't communicate in this format. Technically speaking, replacing (References) |
Since changing Giving the possibility to generate code ready for it's inclusion in a crate as soon as it's generated would be ideal. Since Rust's functions are private by default, having to add to every function the The limitation of this approach would be:
|
I'm trying to generate functions to import them in my code. I haven't managed to get the code generator to make the functions
pub
. If there's a way to do this automatically rather than manually, it'd be of great help.I have a script generating code to
src/functions.rs
, then usingmod functions
, I'm trying to import them but they are not visible forsrc/main.rs
.The text was updated successfully, but these errors were encountered: