pub struct MatrixLUCI<T: Scalar + MatrixLuciScalar> { /* private fields */ }Expand description
Matrix LU-based Cross Interpolation.
This is a higher-level Matrix wrapper around the lower-level matrixluci
substrate.
§Examples
use tensor4all_core::{AbstractMatrixCI, MatrixLUCI};
use tensor4all_tensorbackend::from_vec2d;
let m = from_vec2d(vec![
vec![1.0_f64, 2.0, 3.0],
vec![4.0, 5.0, 6.0],
vec![7.0, 8.0, 9.0],
]);
let ci = MatrixLUCI::from_matrix(&m, None).unwrap();
// The approximation must have at most rank min(nrows, ncols)
assert!(ci.rank() <= 3);
// Reconstructed matrix should match original at pivot positions
let row_indices = ci.row_indices().to_vec();
let col_indices = ci.col_indices().to_vec();
for (&i, &j) in row_indices.iter().zip(col_indices.iter()) {
let approx = ci.evaluate(i, j);
let exact = m[[i, j]];
assert!((approx - exact).abs() < 1e-10);
}Implementations§
Source§impl<T> MatrixLUCI<T>where
T: Scalar + MatrixLuciScalar,
impl<T> MatrixLUCI<T>where
T: Scalar + MatrixLuciScalar,
Sourcepub fn from_matrix(a: &Matrix<T>, options: Option<RrLUOptions>) -> Result<Self>
pub fn from_matrix(a: &Matrix<T>, options: Option<RrLUOptions>) -> Result<Self>
Create a MatrixLUCI from a dense matrix.
§Errors
Returns an error when the construction or conversion fails (a shape or /// index mismatch, or a backend failure).
§Examples
use tensor4all_core::{AbstractMatrixCI, MatrixLUCI};
use tensor4all_tensorbackend::from_vec2d;
let m = from_vec2d(vec![
vec![2.0_f64, 0.0],
vec![0.0, 3.0],
]);
let ci = MatrixLUCI::from_matrix(&m, None).unwrap();
assert!(ci.rank() >= 1);Sourcepub fn left(&self) -> Matrix<T>
pub fn left(&self) -> Matrix<T>
Left CI factor (shape: nrows x rank).
The approximation is left * right.
§Examples
use tensor4all_core::{AbstractMatrixCI, MatrixLUCI};
use tensor4all_tensorbackend::{from_vec2d, mat_mul};
let m = from_vec2d(vec![
vec![1.0_f64, 2.0],
vec![3.0, 4.0],
]);
let ci = MatrixLUCI::from_matrix(&m, None).unwrap();
let reconstructed = mat_mul(&ci.left(), &ci.right()).unwrap();
for i in 0..2 {
for j in 0..2 {
assert!((reconstructed[[i, j]] - m[[i, j]]).abs() < 1e-10);
}
}Sourcepub fn right(&self) -> Matrix<T>
pub fn right(&self) -> Matrix<T>
Right CI factor (shape: rank x ncols).
The approximation is left * right.
§Examples
use tensor4all_core::{AbstractMatrixCI, MatrixLUCI};
use tensor4all_tensorbackend::{from_vec2d, mat_mul};
let m = from_vec2d(vec![vec![1.0_f64, 2.0], vec![3.0, 4.0]]);
let ci = MatrixLUCI::from_matrix(&m, None).unwrap();
let r = ci.right();
assert_eq!(r.nrows(), ci.rank());
assert_eq!(r.ncols(), ci.ncols());
// left * right reconstructs the matrix
let recon = mat_mul(&ci.left(), &r).unwrap();
for i in 0..2 {
for j in 0..2 {
assert!((recon[[i, j]] - m[[i, j]]).abs() < 1e-10);
}
}Sourcepub fn pivot_errors(&self) -> Vec<f64>
pub fn pivot_errors(&self) -> Vec<f64>
Pivot error history (one entry per pivot, plus a final residual estimate).
§Examples
use tensor4all_core::MatrixLUCI;
use tensor4all_tensorbackend::from_vec2d;
let m = from_vec2d(vec![vec![1.0_f64, 2.0], vec![3.0, 4.0]]);
let ci = MatrixLUCI::from_matrix(&m, None).unwrap();
let errs = ci.pivot_errors();
assert!(!errs.is_empty());
// All errors are non-negative
for &e in &errs {
assert!(e >= 0.0);
}Sourcepub fn last_pivot_error(&self) -> f64
pub fn last_pivot_error(&self) -> f64
Last pivot error (the residual estimate after all pivots).
§Examples
use tensor4all_core::MatrixLUCI;
use tensor4all_tensorbackend::from_vec2d;
let m = from_vec2d(vec![vec![1.0_f64, 2.0], vec![3.0, 4.0]]);
let ci = MatrixLUCI::from_matrix(&m, None).unwrap();
let err = ci.last_pivot_error();
assert!(err >= 0.0);Trait Implementations§
Source§impl<T> AbstractMatrixCI<T> for MatrixLUCI<T>where
T: Scalar + MatrixLuciScalar,
impl<T> AbstractMatrixCI<T> for MatrixLUCI<T>where
T: Scalar + MatrixLuciScalar,
Source§fn row_indices(&self) -> &[usize]
fn row_indices(&self) -> &[usize]
Row indices selected as pivots (I set) Read more
Source§fn col_indices(&self) -> &[usize]
fn col_indices(&self) -> &[usize]
Column indices selected as pivots (J set) Read more
Source§fn evaluate(&self, i: usize, j: usize) -> T
fn evaluate(&self, i: usize, j: usize) -> T
Evaluate the approximation at position (i, j) Read more
Source§fn submatrix(&self, rows: &[usize], cols: &[usize]) -> Matrix<T>
fn submatrix(&self, rows: &[usize], cols: &[usize]) -> Matrix<T>
Get a submatrix of the approximation Read more
Source§fn available_rows(&self) -> Vec<usize>
fn available_rows(&self) -> Vec<usize>
Get available row indices (rows without pivots) Read more
Source§fn available_cols(&self) -> Vec<usize>
fn available_cols(&self) -> Vec<usize>
Get available column indices (columns without pivots) Read more
Source§fn local_error(
&self,
a: &Matrix<T>,
rows: &[usize],
cols: &[usize],
) -> Matrix<T>where
T: Sub<Output = T>,
fn local_error(
&self,
a: &Matrix<T>,
rows: &[usize],
cols: &[usize],
) -> Matrix<T>where
T: Sub<Output = T>,
Compute local error |A - CI| for given indices Read more
Source§impl<T: Clone + Scalar + MatrixLuciScalar> Clone for MatrixLUCI<T>
impl<T: Clone + Scalar + MatrixLuciScalar> Clone for MatrixLUCI<T>
Source§fn clone(&self) -> MatrixLUCI<T>
fn clone(&self) -> MatrixLUCI<T>
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl<T> Freeze for MatrixLUCI<T>
impl<T> RefUnwindSafe for MatrixLUCI<T>where
T: RefUnwindSafe,
impl<T> Send for MatrixLUCI<T>
impl<T> Sync for MatrixLUCI<T>
impl<T> Unpin for MatrixLUCI<T>where
T: Unpin,
impl<T> UnsafeUnpin for MatrixLUCI<T>
impl<T> UnwindSafe for MatrixLUCI<T>where
T: UnwindSafe,
Blanket Implementations§
§impl<U> As for U
impl<U> As for U
§fn as_<T>(self) -> Twhere
T: CastFrom<U>,
U: Sized,
fn as_<T>(self) -> Twhere
T: CastFrom<U>,
U: Sized,
Casts
self to type T. The semantics of numeric casting with the as operator are followed, so <T as As>::as_::<U> can be used in the same way as T as U for numeric conversions. Read moreSource§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T, U> Imply<T> for U
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more