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§
fn rows(&self) -> usize
fn cols(&self) -> usize
fn nnz(&self) -> usize
Sourcefn mul_vec(&self, x: &[T], y: &mut [T], trans: bool)
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).
Sourcefn squared_frobenius(&self) -> f64
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§
Sourcefn centered_squared_frobenius(&self, means: ArrayView1<'_, T>) -> f64
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".