Skip to main content

SparseMat

Trait SparseMat 

Source
pub trait SparseMat<T: SvdFloat>: Sync {
    // Required methods
    fn rows(&self) -> usize;
    fn cols(&self) -> usize;
    fn nnz(&self) -> usize;
    fn mul_vec(&self, x: &[T], y: &mut [T], trans: bool);
    fn squared_frobenius(&self) -> f64;

    // Provided method
    fn centered_squared_frobenius(&self, means: ArrayView1<'_, T>) -> f64 { ... }
}
Expand description

The operand interface the Krylov solvers (crate::lanczos, crate::irlba) need: shape and a matrix-vector product.

In 1.x this trait also carried the four blocked-product methods, which meant every built-in implementation left them as todo!() and the randomized solvers panicked on all three stock matrix types. Those methods now live on SparseMatDense, which has working defaults, so the gap cannot reappear.

Required Methods§

Source

fn rows(&self) -> usize

Source

fn cols(&self) -> usize

Source

fn nnz(&self) -> usize

Source

fn mul_vec(&self, x: &[T], y: &mut [T], trans: bool)

y = A·x when trans is false, y = Aᵀ·x when true.

y is fully overwritten. x must have length cols() (rows() when transposed) and y length rows() (cols() when transposed).

Source

fn squared_frobenius(&self) -> f64

‖A‖²_F. Accumulated in f64 even for f32 data — this sums every non-zero, and an f32 accumulator would drop the tail or overflow.

Provided Methods§

Source

fn centered_squared_frobenius(&self, means: ArrayView1<'_, T>) -> f64

‖A − 1·meansᵀ‖²_F.

The default is the closed form ‖A‖²_F − rows·Σⱼ meanⱼ², which needs no pass over the matrix but cancels badly when columns are large against their own spread: on f32 columns of offset + O(1) noise it is 3e-8 wrong at offset 0 and 5e-1 wrong at offset 1000. Fine for counts data, where most entries are zero. The built-in types override it with a per-entry sum that never cancels; do the same if your data carries an offset.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<T, I, Iptr> SparseMat<T> for CsMatI<T, I, Iptr>
where T: SvdFloat, I: SpIndex, Iptr: SpIndex,

Source§

fn rows(&self) -> usize

Source§

fn cols(&self) -> usize

Source§

fn nnz(&self) -> usize

Source§

fn mul_vec(&self, x: &[T], y: &mut [T], trans: bool)

Source§

fn squared_frobenius(&self) -> f64

Source§

fn centered_squared_frobenius(&self, means: ArrayView1<'_, T>) -> f64

Source§

impl<T: SvdFloat, M: SparseMat<T> + ?Sized> SparseMat<T> for &M

Source§

fn rows(&self) -> usize

Source§

fn cols(&self) -> usize

Source§

fn nnz(&self) -> usize

Source§

fn mul_vec(&self, x: &[T], y: &mut [T], trans: bool)

Source§

fn squared_frobenius(&self) -> f64

Source§

fn centered_squared_frobenius(&self, means: ArrayView1<'_, T>) -> f64

Implementors§

Source§

impl<T, I, Iptr> SparseMat<T> for MaskedCsMat<'_, T, I, Iptr>
where T: SvdFloat, I: SpIndex, Iptr: SpIndex,