lazymatrix 0.1.0

Lazy normalized design matrices: apply column centering/scaling without materializing (X - 1cᵀ)S⁻¹, preserving sparsity.
Documentation

lazymatrix

CI crates.io docs.rs

Lazy column normalization for design matrices in Rust. lazymatrix presents

X̃ = (X − 1cᵀ) S⁻¹

as a linear operator without materializing the centered matrix. This matters for sparse matrices, where subtracting a column center would turn structural zeros into nonzeros. Matrix–vector products instead use the original matrix:

X̃v  = X(S⁻¹v) − 1(cᵀS⁻¹v)
X̃ᵀu = S⁻¹(Xᵀu − c Σu)

Centering and scaling are independently optional. The crate also provides borrowed logical column views and sparse column access for algorithms such as coordinate descent.

Install

The core trait and operator API has no linear algebra dependency beyond num-traits. Enable a backend for ready-made dense and CSC implementations:

cargo add lazymatrix --features faer
# or
cargo add lazymatrix --features nalgebra

Example

use lazymatrix::{
    Centering, LazyMatrix, MatVec, Normalization, Scaling,
};
use nalgebra::{DMatrix, DVector};

let x = DMatrix::from_row_slice(
    3,
    2,
    &[1.0, 0.0, 2.0, 3.0, 0.0, 4.0],
);
let x = LazyMatrix::new(
    x,
    Normalization::new(Centering::Mean, Scaling::Sd),
);

let y = x.matvec(&DVector::from_vec(vec![1.0, -1.0]));

The same interface works with faer and nalgebra dense matrices, their borrowed views, and CSC sparse matrices. See examples/ for complete solver examples that consume the operator.

License

Licensed under either the Apache License, Version 2.0 or the MIT license, at your option.