Linear algebra computations — solvers, Kalman filter covariance updates, regression — depend on the numerical health of the matrices involved. Norms formalise the notion of "size" for matrices and vectors and are the building blocks of every conditioning, stability, and error-bound estimate in the library. They are also the cheapest such quantities to compute: a single pass over the entries with no allocation, suitable for real-time embedded paths.
Vector normalisation, closely related, produces the unit-length direction of a vector and is a recurring primitive in geometry, attitude estimation, and gradient methods.
For vectors
VectorNorm is implemented in terms of DotProduct. The unit vector
Frobenius norm — treats the matrix as a flattened vector:
It is rotationally invariant under unitary transformations and cheap to compute.
1-norm (maximum absolute column sum):
Infinity norm (maximum absolute row sum):
The 1-norm and infinity-norm are dual:
| Operation | Time | Space | Notes |
|---|---|---|---|
| DotProduct | Single pass; VectorNorm builds on it |
||
| FrobeniusNorm | Single pass, no allocation | ||
| OneNorm | Column-wise sum, running max | ||
| InfinityNorm | Row-wise sum, running max | ||
| VectorNorm | Single pass | ||
| Normalize | Output vector on stack |
Matrix $A = \begin{bmatrix}3 & 1 \ 1 & 2\end{bmatrix}$:
-
FrobeniusNorm:
$\sqrt{9 + 1 + 1 + 4} = \sqrt{15} \approx 3.873$ -
OneNorm: column 0 sum
$= |3| + |1| = 4$ ; column 1 sum$= |1| + |2| = 3$ ; max$= 4$ -
InfinityNorm: row 0 sum
$= |3| + |1| = 4$ ; row 1 sum$= |1| + |2| = 3$ ; max$= 4$
Vector
Zero vector normalisation — dividing by
Fast-math semantics — -ffast-math may reorder floating-point operations. The norms are sums of non-negative values, so reordering does not change the sign of the result, but catastrophic cancellation can still occur for near-zero off-diagonal entries.
Non-square matrices — FrobeniusNorm, OneNorm, and InfinityNorm apply to any
The spectral norm (largest singular value,
General p-norms and weighted norms generalise the vector case; the L2 norm is the only one currently exposed because it is the natural quantity for geometric and least-squares work.
- Conditioning estimates: the 1-norm feeds the condition number (see
solvers::ConditionNumber). - Convergence tests: iterative solvers and optimisers stop when a residual norm falls below tolerance.
- Attitude / geometry: vector normalisation produces unit direction and rotation axes.
- Covariance sanity: the Frobenius norm of a covariance matrix bounds its total variance.
The 1-norm is the norm used by solvers::ConditionNumber for its math::Matrix type provides the storage and transpose the norms operate on. Norm-based residual tests appear in solvers and optimization.
- Golub, G. H. & Van Loan, C. F., "Matrix Computations", 4th ed., Chapter 2 (matrix norms)
- Trefethen, L. N. & Bau, D., "Numerical Linear Algebra", Lecture 3 (norms)
- Higham, N. J., "Accuracy and Stability of Numerical Algorithms", 2nd ed.