Crate mdarray_linalg_faer

Crate mdarray_linalg_faer 

Source
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§

eig
lu
matmul
qr
solve
svd

Structs§

Faer

Functions§

into_faer
Converts a DSlice<T, 2, L> (from mdarray) into a faer::MatRef<'static, T>. This function does not copy any data.
into_faer_diag_mut
Converts a mutable DSlice<T, 2, L> (from mdarray) into a faer::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> (from mdarray) into a faer::MatMut<'static, T>. This function does not copy any data.
into_faer_mut_transpose
Converts a DSlice<T, 2, L> (from mdarray) into a faer::MatMut<'static, T> and transposes data. This function does not copy any data.
into_mdarray
Converts a faer::Mat<T> into a DTensor<T, 2> (from mdarray) by constructing a strided view over the matrix memory. This function does not copy any data.