kmolan / multicalc-rust

Multivariable calculus in pure rust
MIT License
44 stars 0 forks source link

accept closure rather than a function #1

Closed eweca-d closed 3 months ago

eweca-d commented 3 months ago

Thank you for doing this great job!

I am trying to make use of this crate to generate jacobian matrix for curve fitting of arbitrary functions with crate levenberg-marquardt. Therefore, I need to derive jacobian matrix based on the generated closures that capture input xdata in runtime. Do you have any plan to support closure as the element of function_matrix in the module of Jacabian?

kmolan commented 3 months ago

Hi, can you provide a self-contained example so I can reproduce the error? It was my understanding that jacobian should not have any problem accepting a vector of closures.

eweca-d commented 3 months ago

My bad. Just find I did not remember to annotate like func: Vec<&dyn Fn(&[f64; M]) -> f64> = vec![];. Thank you for your great job again!

kmolan commented 3 months ago

No problem. Glad it all worked out. Closing the issue as resolved. @eweca-d btw, from your comment it looks like you're using an older version of this crate. The API recently changed to get rid of vectors entirely, to better support no-std environments and no heap allocations. If you choose to update multicalc, the annotation must be changed to func: [&dyn Fn(&[f64; M]) -> f64; N] , where M is number of variables and N is number of closures in the function_matrix. You can refer to the example code here: https://github.com/kmolan/multicalc-rust/blob/main/src/numerical_derivative/test.rs#L653