Skip to main content

MatrixLUCI

Struct MatrixLUCI 

Source
pub struct MatrixLUCI<T: Scalar + Scalar> { /* private fields */ }
Expand description

Matrix LU-based Cross Interpolation.

This is a higher-level row-major wrapper around the lower-level matrixluci substrate.

§Examples

use tensor4all_tcicore::{AbstractMatrixCI, MatrixLUCI, 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>

Source

pub fn from_matrix(a: &Matrix<T>, options: Option<RrLUOptions>) -> Result<Self>

Create a MatrixLUCI from a dense row-major matrix.

§Examples
use tensor4all_tcicore::{AbstractMatrixCI, MatrixLUCI, 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);
Source

pub fn left(&self) -> Matrix<T>

Left CI factor (shape: nrows x rank).

The approximation is left * right.

§Examples
use tensor4all_tcicore::{AbstractMatrixCI, MatrixLUCI, from_vec2d, matrix::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());
for i in 0..2 {
    for j in 0..2 {
        assert!((reconstructed[[i, j]] - m[[i, j]]).abs() < 1e-10);
    }
}
Source

pub fn right(&self) -> Matrix<T>

Right CI factor (shape: rank x ncols).

The approximation is left * right.

§Examples
use tensor4all_tcicore::{AbstractMatrixCI, MatrixLUCI, from_vec2d, matrix::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);
for i in 0..2 {
    for j in 0..2 {
        assert!((recon[[i, j]] - m[[i, j]]).abs() < 1e-10);
    }
}
Source

pub fn pivot_errors(&self) -> Vec<f64>

Pivot error history (one entry per pivot, plus a final residual estimate).

§Examples
use tensor4all_tcicore::{MatrixLUCI, 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);
}
Source

pub fn last_pivot_error(&self) -> f64

Last pivot error (the residual estimate after all pivots).

§Examples
use tensor4all_tcicore::{MatrixLUCI, 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 + Scalar,

Source§

fn nrows(&self) -> usize

Number of rows in the approximated matrix Read more
Source§

fn ncols(&self) -> usize

Number of columns in the approximated matrix Read more
Source§

fn rank(&self) -> usize

Current rank of the approximation (number of pivots) Read more
Source§

fn row_indices(&self) -> &[usize]

Row indices selected as pivots (I set) Read more
Source§

fn col_indices(&self) -> &[usize]

Column indices selected as pivots (J set) Read more
Source§

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>

Get a submatrix of the approximation Read more
Source§

fn is_empty(&self) -> bool

Check if the approximation is empty (no pivots) Read more
Source§

fn row(&self, i: usize) -> Vec<T>

Get a row of the approximation Read more
Source§

fn col(&self, j: usize) -> Vec<T>

Get a column of the approximation Read more
Source§

fn to_matrix(&self) -> Matrix<T>

Get the full approximated matrix Read more
Source§

fn available_rows(&self) -> Vec<usize>

Get available row indices (rows without pivots) Read more
Source§

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>,

Compute local error |A - CI| for given indices Read more
Source§

fn find_new_pivot(&self, a: &Matrix<T>) -> Result<((usize, usize), T)>
where T: Sub<Output = T>,

Find a new pivot that maximizes the local error Read more
Source§

fn find_new_pivot_in( &self, a: &Matrix<T>, rows: &[usize], cols: &[usize], ) -> Result<((usize, usize), T)>
where T: Sub<Output = T>,

Find a new pivot in the given row/column subsets Read more
Source§

impl<T: Clone + Scalar + Scalar> Clone for MatrixLUCI<T>

Source§

fn clone(&self) -> MatrixLUCI<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug + Scalar + Scalar> Debug for MatrixLUCI<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<U> As for U

§

fn as_<T>(self) -> T
where T: CastFrom<U>,

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

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> ByRef<T> for T

§

fn by_ref(&self) -> &T

§

impl<T> ByRef<T> for T

§

fn by_ref(&self) -> &T

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> DistributionExt for T
where T: ?Sized,

§

fn rand<T>(&self, rng: &mut (impl Rng + ?Sized)) -> T
where Self: Distribution<T>,

§

impl<T> DistributionExt for T
where T: ?Sized,

§

fn rand<T>(&self, rng: &mut (impl Rng + ?Sized)) -> T
where Self: Distribution<T>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T, U> Imply<T> for U
where T: ?Sized, U: ?Sized,

§

impl<T> MaybeSend for T

§

impl<T> MaybeSendSync for T

§

impl<T> MaybeSync for T