Expand description
use mdarray::{DTensor, tensor};
use mdarray_linalg::prelude::*; // Imports only traits
use mdarray_linalg::eig::EigDecomp;
use mdarray_linalg::svd::SVDDecomp;
use mdarray_linalg_faer::Faer;
// Declare two matrices
let a = tensor![[1., 2.], [3., 4.]];
let b = tensor![[5., 6.], [7., 8.]];
// ----- Matrix multiplication -----
let c = Faer.matmul(&a, &b).eval();
println!("A * B = {:?}", c);
// ----- Eigenvalue decomposition -----
// Note: we must clone `a` here because decomposition routines destroy the input.
let bd = Faer;
let EigDecomp {
eigenvalues,
right_eigenvectors,
..
} = bd.eig(&mut a.clone()).expect("Eigenvalue decomposition failed");
println!("Eigenvalues: {:?}", eigenvalues);
if let Some(vectors) = right_eigenvectors {
println!("Right eigenvectors: {:?}", vectors);
}
// ----- Singular Value Decomposition (SVD) -----
let SVDDecomp { s, u, vt } = bd.svd(&mut a.clone()).expect("SVD failed");
println!("Singular values: {:?}", s);
println!("Left singular vectors U: {:?}", u);
println!("Right singular vectors V^T: {:?}", vt);
// ----- QR Decomposition -----
let (m, n) = *a.shape();
let mut q = DTensor::<f64, 2>::zeros([m, m]);
let mut r = DTensor::<f64, 2>::zeros([m, n]);
bd.qr_overwrite(&mut a.clone(), &mut q, &mut r); //
println!("Q: {:?}", q);
println!("R: {:?}", r);Modules§
Structs§
Functions§
- into_
faer - Converts a
DSlice<T, 2, L>(frommdarray) into afaer::MatRef<'static, T>. This function does not copy any data. - into_
faer_ diag_ mut - Converts a mutable
DSlice<T, 2, L>(frommdarray) into afaer::diag::DiagMut<'static, T>, which is a mutable view over the diagonal elements of a matrix in Faer. - into_
faer_ mut - Converts a
DSlice<T, 2, L>(frommdarray) into afaer::MatMut<'static, T>. This function does not copy any data. - into_
faer_ mut_ transpose - Converts a
DSlice<T, 2, L>(frommdarray) into afaer::MatMut<'static, T>and transposes data. This function does not copy any data. - into_
mdarray - Converts a
faer::Mat<T>into aDTensor<T, 2>(frommdarray) by constructing a strided view over the matrix memory. This function does not copy any data.