How it works
Let
Subtracting a nonzero center changes every implicit zero in a sparse column. Storing those entries can require a full dense matrix. LazyMatrix instead keeps the original storage and folds normalization into each operation.
Matrix–vector products
For a coefficient vector
Scale the coefficients, multiply the original matrix, and subtract a scalar from each output entry. For a row-space vector
Both identities let the backend use its original dense, sparse, or chunked storage. Logical column and sparse row views also expose normalized values without allocating an entire normalized matrix.
Fit once, apply many times
Fitting computes column centers and scales. When both are enabled, scaling statistics use the centered columns. Sparse statistics include the contribution of implicit zeros. Exact zero fitted scales become one, and nonfinite values retain their IEEE behavior.
NormalizationParams stores the fitted centers and scales independently of the matrix backend. Reuse those parameters for prediction data or after converting to an eager representation.
Choose lazy or eager
| Consideration | Lazy | Eager |
|---|---|---|
| Normalized storage | Original matrix plus fitted parameters | Normalized dense matrix plus fitted parameters |
| Sparse input | Preserves sparse storage | Materializes implicit entries into dense storage |
| Construction | Fits statistics | Fits statistics and normalizes entries |
| Repeated operations | Applies normalization corrections | Operates on already normalized values |
| Existing writable dense input | Keeps normalization implicit | Can normalize in place with into_eager |
For a dense copy of an f64 values, the values alone require
Eager normalization can pay off over repeated operations, but sparse products can remain faster than dense products. Benchmarks compare the construction and execution phases separately. Lazy and eager arithmetic can also differ slightly because the floating-point operation order changes.