C(++)ECCO
C++ Error Control COding: a header-only library for ECC simulations and experiments, modeling complete coding systems across arbitrary finite fields and complex inter-field relationships - Christian Senger <senger@inue.uni-stuttgart.de>
Loading...
Searching...
No Matches
matrices.hpp File Reference

Matrix arithmetic library. More...

#include <cassert>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <ranges>
#include <set>
#include <sstream>
#include <unordered_map>
#include "field_concepts_traits.hpp"
Include dependency graph for matrices.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  CECCO::Matrix< T >
 Dense m × n matrix over a CECCO::ComponentType. More...

Namespaces

namespace  CECCO
 Provides a framework for error correcting codes.
namespace  CECCO::details
 Contains implementation details not to be exposed to the user. Functions and classes here may change without notice.

Enumerations

enum  CECCO::details::matrix_type_t : uint8_t {
  CECCO::details::Generic , CECCO::details::Zero , CECCO::details::Diagonal , CECCO::details::Identity ,
  CECCO::details::Vandermonde , CECCO::details::Toeplitz
}
 Matrix structural type tag for optimization (internal). More...

Functions

template<ComponentType T>
constexpr Matrix< T > CECCO::ZeroMatrix (size_t m, size_t n)
 m × n matrix of zeros (tag details::Zero)
template<ComponentType T>
constexpr Matrix< T > CECCO::IdentityMatrix (size_t m)
 m × m identity matrix I_m (tag details::Identity)
template<ComponentType T>
constexpr Matrix< T > CECCO::DiagonalMatrix (const Vector< T > &v)
 Diagonal matrix with diagonal v (tag details::Diagonal).
template<ComponentType T>
constexpr Matrix< T > CECCO::ToeplitzMatrix (const Vector< T > &v, size_t m, size_t n)
 m × n Toeplitz matrix from its diagonal entries (tag details::Toeplitz)
template<ComponentType T>
constexpr Matrix< T > CECCO::VandermondeMatrix (const Vector< T > &v, size_t m)
 Vandermonde matrix V_{i, j} = v[j]^i (tag details::Vandermonde).
template<ComponentType T>
std::ostream & CECCO::operator<< (std::ostream &os, const Matrix< T > &rhs)
 Pretty-print the matrix with column alignment and bracket borders.
template<ComponentType T>
constexpr Matrix< T > CECCO::operator+ (const Matrix< T > &lhs, const Matrix< T > &rhs)
template<ComponentType T>
constexpr Matrix< T > CECCO::operator+ (Matrix< T > &&lhs, const Matrix< T > &rhs)
template<ComponentType T>
constexpr Matrix< T > CECCO::operator+ (const Matrix< T > &lhs, Matrix< T > &&rhs)
template<ComponentType T>
constexpr Matrix< T > CECCO::operator+ (Matrix< T > &&lhs, Matrix< T > &&rhs)
template<ComponentType T>
constexpr Matrix< T > CECCO::operator- (const Matrix< T > &lhs, const Matrix< T > &rhs)
template<ComponentType T>
constexpr Matrix< T > CECCO::operator- (Matrix< T > &&lhs, const Matrix< T > &rhs)
template<ComponentType T>
constexpr Matrix< T > CECCO::operator- (const Matrix< T > &lhs, Matrix< T > &&rhs)
template<ComponentType T>
constexpr Matrix< T > CECCO::operator- (Matrix< T > &&lhs, Matrix< T > &&rhs)
template<ComponentType T>
constexpr Matrix< T > CECCO::operator* (const Matrix< T > &lhs, const Matrix< T > &rhs)
template<ComponentType T>
constexpr Matrix< T > CECCO::operator* (Matrix< T > &&lhs, const Matrix< T > &rhs)
template<ComponentType T>
constexpr Vector< T > CECCO::operator* (const Vector< T > &lhs, const Matrix< T > &rhs)
template<ComponentType T>
constexpr Vector< T > CECCO::operator* (Vector< T > &&lhs, const Matrix< T > &rhs)
template<ComponentType T>
constexpr Matrix< T > CECCO::operator* (const Matrix< T > &lhs, const T &rhs)
template<ComponentType T>
constexpr Matrix< T > CECCO::operator* (Matrix< T > &&lhs, const T &rhs)
template<ComponentType T>
constexpr Matrix< T > CECCO::operator* (const T &lhs, const Matrix< T > &rhs)
template<ComponentType T>
constexpr Matrix< T > CECCO::operator* (const T &lhs, Matrix< T > &&rhs)
template<ComponentType T>
constexpr Matrix< T > CECCO::operator/ (const Matrix< T > &lhs, const T &rhs)
template<ComponentType T>
constexpr Matrix< T > CECCO::operator/ (Matrix< T > &&lhs, const T &rhs)
template<ComponentType T>
Matrix< T > CECCO::randomize (const Matrix< T > &M)
template<ComponentType T>
Matrix< T > CECCO::randomize (Matrix< T > &&M)
template<ReliablyComparableType T>
constexpr size_t CECCO::wH (const Matrix< T > &M)
template<ComponentType T>
requires std::convertible_to<std::decay_t<decltype(M)>, Matrix<T>>
Matrix< T > CECCO::set_component (auto &&M, size_t i, size_t j, const T &c)
template<ComponentType T>
Matrix< T > CECCO::get_submatrix (const Matrix< T > &M, size_t i, size_t j, size_t h, size_t w)
template<ComponentType T>
Matrix< T > CECCO::get_submatrix (Matrix< T > &&M, size_t i, size_t j, size_t h, size_t w)
template<ComponentType T>
Matrix< T > CECCO::set_submatrix (const Matrix< T > &M, size_t i, size_t j, const Matrix< T > &N)
template<ComponentType T>
Matrix< T > CECCO::set_submatrix (Matrix< T > &&M, size_t i, size_t j, const Matrix< T > &N)
template<ComponentType T>
Matrix< T > CECCO::horizontal_join (const Matrix< T > &lhs, const Matrix< T > &rhs)
template<ComponentType T>
Matrix< T > CECCO::horizontal_join (Matrix< T > &&lhs, const Matrix< T > &rhs)
template<ComponentType T>
Matrix< T > CECCO::horizontal_join (Matrix< T > &&lhs, Matrix< T > &&rhs)
template<ComponentType T>
Matrix< T > CECCO::vertical_join (const Matrix< T > &lhs, const Matrix< T > &rhs)
template<ComponentType T>
Matrix< T > CECCO::vertical_join (Matrix< T > &&lhs, const Matrix< T > &rhs)
template<ComponentType T>
Matrix< T > CECCO::vertical_join (Matrix< T > &&lhs, Matrix< T > &&rhs)
template<ComponentType T>
Matrix< T > CECCO::diagonal_join (const Matrix< T > &lhs, const Matrix< T > &rhs)
template<ComponentType T>
Matrix< T > CECCO::diagonal_join (Matrix< T > &&lhs, const Matrix< T > &rhs)
template<ComponentType T>
Matrix< T > CECCO::diagonal_join (Matrix< T > &&lhs, Matrix< T > &&rhs)
template<ComponentType T>
Matrix< T > CECCO::Kronecker_product (const Matrix< T > &lhs, const Matrix< T > &rhs)
template<ComponentType T>
Matrix< T > CECCO::Kronecker_product (Matrix< T > &&lhs, const Matrix< T > &rhs)
template<ComponentType T>
Matrix< T > CECCO::Kronecker_product (Matrix< T > &&lhs, Matrix< T > &&rhs)
template<ComponentType T>
Matrix< T > CECCO::swap_rows (const Matrix< T > &M, size_t i, size_t j)
template<ComponentType T>
Matrix< T > CECCO::swap_columns (const Matrix< T > &M, size_t i, size_t j)
template<ComponentType T>
Matrix< T > CECCO::swap_rows (Matrix< T > &&M, size_t i, size_t j)
template<ComponentType T>
Matrix< T > CECCO::swap_columns (Matrix< T > &&M, size_t i, size_t j)
template<ComponentType T>
Matrix< T > CECCO::scale_row (const Matrix< T > &M, const T &s, size_t i)
template<ComponentType T>
Matrix< T > CECCO::scale_column (const Matrix< T > &M, const T &s, size_t i)
template<ComponentType T>
Matrix< T > CECCO::scale_row (Matrix< T > &&M, const T &s, size_t i)
template<ComponentType T>
Matrix< T > CECCO::scale_column (Matrix< T > &&M, const T &s, size_t i)
template<ComponentType T>
Matrix< T > CECCO::add_scaled_row (const Matrix< T > &M, const T &s, size_t i, size_t j)
template<ComponentType T>
Matrix< T > CECCO::add_scaled_column (const Matrix< T > &M, const T &s, size_t i, size_t j)
template<ComponentType T>
Matrix< T > CECCO::add_scaled_row (Matrix< T > &&M, const T &s, size_t i, size_t j)
template<ComponentType T>
Matrix< T > CECCO::add_scaled_column (Matrix< T > &&M, const T &s, size_t i, size_t j)
template<ComponentType T>
Matrix< T > CECCO::add_row (const Matrix< T > &M, size_t i, size_t j)
template<ComponentType T>
Matrix< T > CECCO::add_column (const Matrix< T > &M, size_t i, size_t j)
template<ComponentType T>
Matrix< T > CECCO::add_row (Matrix< T > &&M, size_t i, size_t j)
template<ComponentType T>
Matrix< T > CECCO::add_column (Matrix< T > &&M, size_t i, size_t j)
template<ComponentType T>
constexpr Matrix< T > CECCO::delete_columns (const Matrix< T > &lhs, const std::vector< size_t > &v)
template<ComponentType T>
constexpr Matrix< T > CECCO::delete_columns (Matrix< T > &&lhs, const std::vector< size_t > &v)
template<ComponentType T>
constexpr Matrix< T > CECCO::delete_column (const Matrix< T > &lhs, size_t i)
template<ComponentType T>
constexpr Matrix< T > CECCO::delete_column (Matrix< T > &&lhs, size_t i)
template<ComponentType T>
constexpr Matrix< T > CECCO::delete_rows (const Matrix< T > &lhs, const std::vector< size_t > &v)
template<ComponentType T>
constexpr Matrix< T > CECCO::delete_rows (Matrix< T > &&lhs, const std::vector< size_t > &v)
template<ComponentType T>
constexpr Matrix< T > CECCO::delete_row (const Matrix< T > &lhs, size_t i)
template<ComponentType T>
constexpr Matrix< T > CECCO::delete_row (Matrix< T > &&lhs, size_t i)
template<ComponentType T>
constexpr Matrix< T > CECCO::erase_component (const Matrix< T > &lhs, size_t i, size_t j)
template<ComponentType T>
constexpr Matrix< T > CECCO::erase_component (Matrix< T > &&lhs, size_t i, size_t j)
template<ComponentType T>
constexpr Matrix< T > CECCO::unerase_component (const Matrix< T > &lhs, size_t i, size_t j)
template<ComponentType T>
constexpr Matrix< T > CECCO::unerase_component (Matrix< T > &&lhs, size_t i, size_t j)
template<ComponentType T>
constexpr Matrix< T > CECCO::erase_columns (const Matrix< T > &lhs, const std::vector< size_t > &v)
template<ComponentType T>
constexpr Matrix< T > CECCO::erase_columns (Matrix< T > &&lhs, const std::vector< size_t > &v)
template<ComponentType T>
constexpr Matrix< T > CECCO::erase_column (const Matrix< T > &lhs, size_t i)
template<ComponentType T>
constexpr Matrix< T > CECCO::erase_column (Matrix< T > &&lhs, size_t i)
template<ComponentType T>
constexpr Matrix< T > CECCO::unerase_columns (const Matrix< T > &lhs, const std::vector< size_t > &v)
template<ComponentType T>
constexpr Matrix< T > CECCO::unerase_columns (Matrix< T > &&lhs, const std::vector< size_t > &v)
template<ComponentType T>
constexpr Matrix< T > CECCO::unerase_column (const Matrix< T > &lhs, size_t i)
template<ComponentType T>
constexpr Matrix< T > CECCO::unerase_column (Matrix< T > &&lhs, size_t i)
template<ComponentType T>
constexpr Matrix< T > CECCO::erase_rows (const Matrix< T > &lhs, const std::vector< size_t > &v)
template<ComponentType T>
constexpr Matrix< T > CECCO::erase_rows (Matrix< T > &&lhs, const std::vector< size_t > &v)
template<ComponentType T>
constexpr Matrix< T > CECCO::erase_row (const Matrix< T > &lhs, size_t i)
template<ComponentType T>
constexpr Matrix< T > CECCO::erase_row (Matrix< T > &&lhs, size_t i)
template<ComponentType T>
constexpr Matrix< T > CECCO::unerase_rows (const Matrix< T > &lhs, const std::vector< size_t > &v)
template<ComponentType T>
constexpr Matrix< T > CECCO::unerase_rows (Matrix< T > &&lhs, const std::vector< size_t > &v)
template<ComponentType T>
constexpr Matrix< T > CECCO::unerase_row (const Matrix< T > &lhs, size_t i)
template<ComponentType T>
constexpr Matrix< T > CECCO::unerase_row (Matrix< T > &&lhs, size_t i)
template<ComponentType T>
Matrix< T > CECCO::reverse_rows (const Matrix< T > &M)
template<ComponentType T>
Matrix< T > CECCO::reverse_rows (Matrix< T > &&M)
template<ComponentType T>
Matrix< T > CECCO::reverse_columns (const Matrix< T > &M)
template<ComponentType T>
Matrix< T > CECCO::reverse_columns (Matrix< T > &&M)
template<ComponentType T>
constexpr Matrix< T > CECCO::fill (const Matrix< T > &m, const T &value)
template<ComponentType T>
constexpr Matrix< T > CECCO::fill (Matrix< T > &&m, const T &value)
template<ComponentType T>
constexpr Matrix< T > CECCO::transpose (const Matrix< T > &M)
template<ComponentType T>
constexpr Matrix< T > CECCO::transpose (Matrix< T > &&M)
template<FieldType T>
Matrix< T > CECCO::rref (const Matrix< T > &M)
template<FieldType T>
Matrix< T > CECCO::rref (Matrix< T > &&M)
template<ComponentType T>
Matrix< T > CECCO::inverse (const Matrix< T > &M)
template<ComponentType T>
Matrix< T > CECCO::inverse (Matrix< T > &&M)
template<ReliablyComparableType T>
constexpr bool CECCO::operator== (const Matrix< T > &lhs, const Matrix< T > &rhs)
 Equality of two matrices.
template<ReliablyComparableType T>
constexpr bool CECCO::operator!= (const Matrix< T > &lhs, const Matrix< T > &rhs)
 Negation of operator==.
template<ComponentType T>
constexpr Matrix< T > CECCO::PermutationMatrix (const std::vector< size_t > &perm)
 Permutation matrix P with P_{i, perm[i]} = 1.
template<ComponentType T>
constexpr Matrix< T > CECCO::ExchangeMatrix (size_t m)
 m × m exchange matrix (ones on the anti-diagonal)
template<ComponentType T>
constexpr Matrix< T > CECCO::HankelMatrix (const Vector< T > &v, size_t m, size_t n)
 m × n Hankel matrix from its anti-diagonal entries
template<ComponentType T>
constexpr Matrix< T > CECCO::UpperShiftMatrix (size_t m)
 m × m upper shift matrix (ones on the superdiagonal)
template<ComponentType T>
constexpr Matrix< T > CECCO::LowerShiftMatrix (size_t m)
 m × m lower shift matrix (ones on the subdiagonal); transpose of UpperShiftMatrix
template<ComponentType T>
constexpr Matrix< T > CECCO::CompanionMatrix (const Polynomial< T > &poly)
 Companion matrix of a monic polynomial p(x) = x^n + a_{n−1} x^{n−1} + … + a_0.

Detailed Description

Matrix arithmetic library.

Author
Christian Senger senge.nosp@m.r@in.nosp@m.ue.un.nosp@m.i-st.nosp@m.uttga.nosp@m.rt.d.nosp@m.e
Version
2.2.9
Date
2026

Licensed for noncommercial use only, including academic teaching, research, and personal non-profit purposes. Commercial use is prohibited without a separate commercial license. See the LICENSE file in the repository root for full terms and how to request a commercial license.

Description

Dense and structured matrices over any CECCO::ComponentType (finite fields, floating-point, complex, signed integers). Provides REF/RREF (with binary-field fast paths), cached rank, determinant, nullspace, characteristic polynomial, and matrix inversion. Cross-field operations bridge through CECCO::largest_common_subfield_t.

The class template Matrix<T> automatically tracks structural type (CECCO::details::matrix_type_t — Zero, Identity, Diagonal, Vandermonde, Toeplitz) to enable specialized fast paths. The type tag is transparent to callers; factories (IdentityMatrix, DiagonalMatrix, VandermondeMatrix, …) all return Matrix<T>.

// Factory + arithmetic
auto I = IdentityMatrix<double>(3);
auto D = DiagonalMatrix(Vector<double>{1, 2, 3});
auto M = I + D; // 3×3, type tag stays Diagonal
// Finite-field linear algebra
Matrix<Fp<7>> P = {{1, 2}, {3, 4}};
size_t r = P.rank(); // Cached
auto null_basis = P.basis_of_nullspace();
See also
fields.hpp, vectors.hpp, field_concepts_traits.hpp

Definition in file matrices.hpp.