sarah-quinones / faer-rs

Linear algebra foundation for the Rust programming language
https://faer-rs.github.io
MIT License
1.82k stars 61 forks source link

Matrix Exponentiation #22

Open matthagan15 opened 1 year ago

matthagan15 commented 1 year ago

Is your feature request related to a problem? Please describe. Matrix exponentation utilizing the standard double precision algorithm by Al-Mohy and Higham.

Describe the solution you'd like A simple function that takes in a reference or matrix view (of some sorts not familiar with this library just yet) and yields a Result< ,> containing the exponentiated matrix if it worked and an error if not.

Describe alternatives you've considered n/a

Additional context I have implemented this function for ndarray-linalg but the maintainers have taken months and still no word. I am using my implementation for research purposes, using ndarray I have an error one-norm of about 20x scipy at 200x200 dense matrices and an error of machine precision for 1-sparse matrices up to 1024x1024. It might take some time but I'd be willing to port it over to this library to help move it along, would like to hear how this should best be done.

sarah-quinones commented 1 year ago

i'll look into it. right now i'm in the middle of a full rewrite of the library so i'm hesitant to start working on other stuff at the same time, but i should be done after a week or two hopefully. in the mean time, i could take a look at the algorithm if you have any references i can check out

matthagan15 commented 1 year ago

Ah sorry I think I miscommunicated, this is an offer for me to port the implemented algorithm from ndarray-linalg over to this project. All I'd need to learn how to do is multiplication and scaled addition, which I'd think shouldn't be too bad. I was mostly wondering what you think the best place to put this would be, it doesn't seem like a core contribution but doesn't quite fit in with the other "crates"/workspaces (still learning this type of organization). Let me know where and how you'd want it to be added and I'll get started on it.

sarah-quinones commented 1 year ago

i think it might make sense to create a new faer-math top level crate that contains math functions, kind of like eigen's matrix functions module https://eigen.tuxfamily.org/dox/unsupported/group__MatrixFunctions__Module.html

ilayn commented 2 weeks ago

I converted the SciPy version to C in case it makes things easier to convert https://github.com/scipy/scipy/blob/main/scipy/linalg/_matfuncs_expm.c