pub fn capped_full_piv_lu<T: CappedFullPivLuScalar>(
a: Matrix<T>,
max_rank: Option<usize>,
) -> Result<CappedFullPivLu<T>, BackendLinalgError>Expand description
Complete-pivoting LU of a square matrix, stopped after at most max_rank pivots.
The elimination runs in place on a’s column-major buffer, sequentially.
None factors to full rank; Some(r) stops once r pivots are taken, so
the work is O(n^2 r). Either stops earlier at a zero or subnormal Schur
complement, but only Some reports that stop in CappedFullPivLu::rank.
Pivot acceptance (tolerances, degenerate pivots) is left to the caller, who
reads it from CappedFullPivLu::diagonal. The complex pivot score depends
on the dispatched SIMD path (see the module docs).
Non-finite entries are not checked here: validate the input first if a non-finite value must be refused.
§Errors
Returns BackendLinalgError when a is not square.
§Examples
use tensor4all_tensorbackend::{capped_full_piv_lu, Matrix};
// diag(1, 4, 2): complete pivoting takes 4, then 2, then 1.
let a = Matrix::from_col_major_vec(3, 3, vec![
1.0_f64, 0.0, 0.0,
0.0, 4.0, 0.0,
0.0, 0.0, 2.0,
]);
let lu = capped_full_piv_lu(a, Some(2))?;
assert_eq!(lu.rank(), 2);
assert_eq!(&lu.row_perm()[..2], &[1, 2]);
assert_eq!(&lu.col_perm()[..2], &[1, 2]);
assert_eq!(&lu.diagonal()[..2], &[4.0, 2.0]);
// The trailing entry is the remaining Schur complement.
assert_eq!(lu.diagonal()[2], 1.0);