Skip to content

LazyMatrixCenter and scale matrices without materializing them.

Normalized design matrices for Rust. Keep sparse matrices sparse, reuse fitted parameters, and choose when to materialize.

A normalized matrix, used as an operator ​

LazyMatrix represents

X~=(X−1c⊤)S−1

without storing the centered matrix. Here, c holds the column centers, and S is diagonal with the column scales. Products use the original storage and apply normalization algebraically.

sh
cargo add lazymatrix --features ndarray
cargo add ndarray@0.17
rust
use lazymatrix::{Centering, LazyMatrix, MatVec, Normalization, Scaling};
use ndarray::array;

let x = array![[1.0, 0.0], [2.0, 3.0], [0.0, 4.0]];
let lazy = LazyMatrix::new(
    x.view(),
    Normalization::new(Centering::Mean, Scaling::Sd),
).unwrap();

let y = lazy.matvec(&array![1.0, -1.0]).unwrap();

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.

Released under the MIT and Apache 2.0 licenses.