sarah-ek / faer-rs

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

easy conversion to vec and ndarray #111

Closed azmyrajab closed 7 months ago

azmyrajab commented 7 months ago

Is your feature request related to a problem? Please describe. to integrate well with the rest of the rust ecosystem I need to be able to convert other array-like formats (e.g. ndarray / built-in vec) to and from faer matrices. I could find "into_faer" for conversion to but could not find anything for the way back and so I have to loop through elements and populate a new Vec which isn't ideal

Describe the solution you'd like Implement central 'to_vec' & 'to_ndarray' (latter feature) methods which make conversion easier (and probably more efficient and less error prone by being done properly centrally)

Describe alternatives you've considered Iterating through the data and populating manually. I failed to find any methods which convert to the formats I need (pls let me know if I missed anything).

Additional context Typical workflow, for me, in faer is to convert polars data series to ndarray, then to faer, do some math and then I need to go back to polars series. One way to do this is via Vec, thus the need to convert to that

Thanks!

sarah-ek commented 7 months ago

what about https://docs.rs/faer-ext/latest/faer_ext/trait.IntoNdarray.html

it can be used to convert faer matrix views to ndarray

azmyrajab commented 7 months ago

hi @sarah-ek that works perfectly and I discovered the polars feature there which saves me an extra step. Apologies for missing faer-ext functionalities

I will close this issue