Preserve sparse storage
Apply centering and scaling through matrix operations without turning structural zeros into stored entries.
Normalized design matrices for Rust. Keep sparse matrices sparse, reuse fitted parameters, and choose when to materialize.


LazyMatrix represents
without storing the centered matrix. Here, holds the column centers, and is diagonal with the column scales. Products use the original storage and apply normalization algebraically.
Here is what each one represents, with :
First, add the crate to your project with the ndarray feature:
cargo add lazymatrix --features ndarray
cargo add ndarray@0.17Then, use the LazyMatrix type to wrap an existing matrix and apply normalization. Here, we center by the mean and scale by the maximum absolute value of each column. Then, we multiply the normalized matrix by a vector.
use lazymatrix::{Centering, LazyMatrix, MatVec, ColumnNormalization, Scaling};
use ndarray::array;
let x = array![[3.0, 6.0, 0.0], [0.0, 6.0, 0.0], [0.0, 0.0, 9.0]];
let lazy = LazyMatrix::new(
x.view(),
ColumnNormalization::new(Centering::Mean, Scaling::MaxAbs),
).unwrap();
let y = lazy.matvec(&array![1.0, 1.0, 1.0]).unwrap();
assert_eq!(y, array![1.0, -0.5, -0.5]);See Citing LazyMatrix for a text citation and BibLaTeX and BibTeX entries.
Read the guide for installation and eager conversion, or see how it works for the normalization identities. The benchmark comparisons explain the costs of construction, repeated operations, and additional memory.
LazyMatrix is in early development, and breaking changes are expected. Find releases on crates.io and source code on GitHub.