interoperability with other crates
conversions from/to external library types is provided separately from faer itself, in the faer-ext crate.
note
only matrix view types can be converted. owning matrices can't be converted due to faer using a different allocation scheme from nalgebra and ndarray.
converting to/from nalgebra matrices
conversion from nalgebra types is done by enabling the nalgebra feature and using the IntoFaer
trait.
conversion to nalgebra types is enabled by the same feature and uses the IntoNalgebra
trait.
use faer::Mat;
use faer_ext::*;
let mut I_faer = Mat::<f32>::identity(8, 7);
let mut I_nalgebra = nalgebra::DMatrix::<f32>::identity(8, 7);
assert!(I_nalgebra.view_range(.., ..).into_faer() == I_faer);
assert!(I_faer.as_ref().into_nalgebra() == I_nalgebra);
assert!(I_nalgebra.view_range_mut(.., ..).into_faer() == I_faer);
assert!(I_faer.as_mut().into_nalgebra() == I_nalgebra);
converting to/from ndarray matrices
conversion from ndarray types is done by enabling the ndarray feature and using the IntoFaer
trait.
conversion to ndarray types is enabled by the same feature and uses the IntoNdarray
trait.
use faer::Mat;
use faer_ext::*;
let mut I_faer = Mat::<f32>::identity(8, 7);
let mut I_ndarray = ndarray::Array2::<f32>::zeros([8, 7]);
I_ndarray.diag_mut().fill(1.0);
assert!(I_ndarray.view().into_faer() == I_faer);
assert!(I_faer.as_ref().into_ndarray() == I_ndarray);
assert!(I_ndarray.view_mut().into_faer() == I_faer);
assert!(I_faer.as_mut().into_ndarray() == I_ndarray);