TypedLinearAlgebra
Typed Linear Algebra
Typed linear algebra brings compile time unit safety to C++ matrix math
A C++ strongly typed facade over a matrix backend that enforces dimensional consistency and unit compatibility so invalid operations fail to compile.
What the library does
TypedLinearAlgebra is a C++ strongly typed facade to a matrix linear algebra backend. Its purpose is to bring type safety to matrix operations by enforcing dimensional consistency and unit compatibility, which helps prevent common errors in scientific and engineering computations. The README shows a state vector built from quantities with units such as meters, meters per second, and meters per second squared, and when the vector is multiplied by its transpose the result carries squared and mixed units in each cell. Instead of treating a matrix as a bag of interchangeable numbers, the library attaches an index type to each row and column. That means a mismatched unit, an out-of-order axis, or a mixed-up reference frame fails to compile rather than producing a wrong number at runtime. The README notes the library serves computations where a matrix is a collection of meaningful quantities, such as a state estimate, sensor readings, or correlated measures. It integrates with established backends including Eigen, Kokkos, mp-units, and std::linalg, and built-in types and std::linalg need no plug-in. The header is included as fcarouge/typed_linear_algebra.hpp, and sample usage lives in the sample directory of the repository for anyone who wants to see realistic code before adopting it. The reference section of the README documents the typed_matrix class, its operations, aliases, literals, and concepts in full for developers who want to integrate the facade into their own numerical code.
Type safety and the operations it supports
The core type is typed_matrix, a template that composes an underlying linear algebra matrix with row and column index tuples. The library provides typed_row_vector and typed_column_vector aliases, a standard formatter specialization so std::format can print a matrix, and a user defined literal _i in the fcarouge::literals namespace that converts a decimal integer into a compile time index for traditional accessor syntax. Operations follow the nomenclature of std::linalg and include addition, subtraction, multiplication, and an inverse-like division, plus element-wise add, Euclidean magnitude, matrix product, matrix vector product, scale, and transposed. A set of concepts describes the type system: rank_typed_matrix for singleton, one dimension, and two dimension matrices, column_typed_matrix and row_typed_matrix for vectors, same_shape for matrices with equal rows and columns, and uniform_typed_matrix for matrices whose elements all share one type. The element_caster template is a customization point that lets you define conversions to and from an element type and its underlying storage, so new quantity types can plug in through template specialization. The library also documents its member functions, including read and write access through at, and a variety of constructors that build a typed matrix from arrays, lists, or an underlying matrix. A user defined literal _i in the fcarouge::literals namespace turns a decimal integer into a compile time index, so traditional accessor syntax works with the strong types.
Where it is used and how it was shared
The README lists use cases across estimation and filtering, guidance navigation and control, aerospace and spacecraft systems, robotics, structural and mechanical engineering, process and chemical engineering, quantitative finance and econometrics, computer graphics and simulation, and machine learning and scientific computing. In each domain a unit or frame mismatch can corrupt a result or, in aerospace history, cause mission-critical failures, so keeping meaning at the type level matters. The library is used by a Kalman filter project called Kalman, and the author invites other projects to be listed. It was presented at CppNow 2026 as a first free and open-source implementation that integrates dimensional analysis into linear algebra through the type system while preserving the performance of established numerical backends. The talk covered the safety proposition, the typed matrix definition, ergonomics and compatibility with std::linalg, std::mdspan, Eigen, and mp-units, and the lessons learned from building it. The README also documents design tradeoffs such as index safety, the absence of lvalue reference assignment, and why strongly typed memory storage was not selected because of performance cost, giving readers an honest account of the limits of the approach. The library was presented at CppNow 2026 as a first free and open-source implementation that integrates dimensional analysis into linear algebra while keeping backend performance intact.
Editorial conclusion
The library is released into the public domain, as stated in the README, and the repository metadata lists 22 stars with a last update of 2026-08-24.
Community notes