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
CECCO::Matrix< T > Class Template Reference

Dense m × n matrix over a CECCO::ComponentType. More...

#include <matrices.hpp>

Inheritance diagram for CECCO::Matrix< T >:
Inheritance graph

Public Member Functions

template<FiniteFieldType S>
constexpr Matrix< T > & operator= (const Matrix< S > &other)
template<typename U>
requires std::convertible_to<std::decay_t<U>, T>
Matrix< T > & set_component (size_t i, size_t j, U &&c)
Constructors
constexpr Matrix () noexcept=default
 Default constructor: empty matrix.
constexpr Matrix (size_t m, size_t n)
 m × n zero matrix (tag details::Zero)
 Matrix (size_t m, size_t n, const T &l)
 m × n matrix with every component equal to l
constexpr Matrix (size_t m, size_t n, std::initializer_list< T > l)
 m × n matrix from a flat initializer list (row-major)
 Matrix (std::initializer_list< std::initializer_list< T > > l)
 From nested initializer lists, e.g. {{1, 2, 3}, {4, 5, 6}}.
 Matrix (const Vector< T > &v)
 1 × n row matrix from a Vector<T>
constexpr Matrix (const Matrix &other)
constexpr Matrix (Matrix &&other) noexcept
template<FiniteFieldType S>
requires FiniteFieldType<T> && (T::get_characteristic() == S::get_characteristic())
constexpr Matrix (const Matrix< S > &other)
 Cross-field conversion between two finite fields of the same characteristic.
 Matrix (const std::string &filename)
 Read from a PPM (P3) image file using the 64-entry colormap of export_as_ppm.
Assignment Operators
constexpr Matrixoperator= (const Matrix &rhs)
constexpr Matrixoperator= (Matrix &&rhs) noexcept
template<FiniteFieldType S>
constexpr Matrixoperator= (const Matrix< S > &other)
 Cross-field assignment (same semantics as the cross-field constructor).
Unary Arithmetic Operations
constexpr Matrix operator+ () const &
 Unary + (lvalue): returns a copy.
constexpr Matrix operator+ () &&noexcept
 Unary + (rvalue): returns the rvalue itself.
constexpr Matrix operator- () const &
 Unary (lvalue): returns a new matrix with each component negated.
constexpr Matrix operator- () &&
 Unary (rvalue): negates components in place.
Compound Assignment Operations
Matrixoperator+= (const Matrix &rhs)
 Component-wise addition this(i, j) += rhs(i, j).
Matrixoperator-= (const Matrix &rhs)
 Component-wise subtraction this(i, j) -= rhs(i, j).
Matrixoperator*= (const Matrix &rhs)
 Matrix multiplication *this = *this · rhs.
constexpr Matrixoperator*= (const T &s)
 Multiply every component by the scalar s.
Matrixoperator/= (const T &s)
 Divide every component by the scalar s.
Randomization
Matrixrandomize ()
 Fill matrix with random values.
Information and Properties
constexpr size_t get_m () const noexcept
 Get the number of rows.
constexpr size_t get_n () const noexcept
 Get the number of columns.
constexpr bool is_empty () const noexcept
 Check if matrix is empty.
constexpr bool is_zero ()
 Check if the matrix is zero, caching the result via the type tag.
constexpr bool is_zero () const
 Check if the matrix is zero (no caching).
size_t wH () const
 Hamming weight: number of non-zero, non-erased components; cached on first call.
size_t rank () const
 Matrix rank, computed once and cached.
bool is_invertible () const
 Check if matrix is invertible.
Vector< T > diagonal () const
 Main diagonal as a vector.
Polynomial< T > characteristic_polynomial () const
 Characteristic polynomial det(λI − A).
Matrix< T > basis_of_nullspace () const
 Basis of the nullspace (right kernel).
Matrix< T > basis_of_kernel () const
 Alias for basis_of_nullspace.
determinant () const
 Matrix determinant.
std::vector< T > eigenvalues () const
 Eigenvalues lying in the underlying finite field.
std::vector< Vector< T > > rowspace () const
 Enumerate every vector in the row space.
std::vector< Vector< T > > span () const
 Alias for rowspace.
Component Access and Manipulation
template<typename U>
requires std::convertible_to<std::decay_t<U>, T>
Matrixset_component (size_t i, size_t j, U &&c)
 Set component (i, j) by perfect forwarding.
const T & operator() (size_t i, size_t j) const
 Access component (i, j) (read-only).
Vector< T > get_row (size_t i) const
 Extract row i as a vector.
Vector< T > get_col (size_t j) const
 Extract column j as a (row) vector.
Matrix< T > get_submatrix (size_t i, size_t j, size_t h, size_t w) const
 Extract submatrix from region [i, i+h) × [j, j+w).
Matrix< T > & set_submatrix (size_t i, size_t j, const Matrix &N)
 Overwrite the region starting at (i, j) with N.
Matrix< T > & horizontal_join (const Matrix &other)
 Concatenate other to the right (column-wise).
Matrix< T > & vertical_join (const Matrix &other)
 Concatenate other below (row-wise).
Matrix< T > & diagonal_join (const Matrix &other)
 Block-diagonal join: this in the upper-left, other in the lower-right.
Matrix< T > & Kronecker_product (const Matrix &other)
 Kronecker (tensor) product with other.
Matrix< T > & swap_rows (size_t i, size_t j)
 Swap rows i and j.
Matrix< T > & swap_columns (size_t i, size_t j)
 Swap columns i and j.
Matrix< T > & scale_row (const T &s, size_t i)
 row[i] ← s · row[i]
Matrix< T > & scale_column (const T &s, size_t i)
 col[i] ← s · col[i]
Matrix< T > & add_scaled_row (const T &s, size_t i, size_t j)
 row[j] ← row[j] + s · row[i]
Matrix< T > & add_scaled_column (const T &s, size_t i, size_t j)
 col[j] ← col[j] + s · col[i]
Matrix< T > & add_row (size_t i, size_t j)
 row[j] ← row[j] + row[i]
Matrix< T > & add_column (size_t i, size_t j)
 col[j] ← col[j] + col[i]
Matrix< T > & delete_columns (const std::vector< size_t > &v)
 Delete the columns whose indices appear in v.
Matrix< T > & delete_column (size_t i)
 Delete column i (single-index convenience for delete_columns).
Matrix< T > & delete_rows (const std::vector< size_t > &v)
 Delete the rows whose indices appear in v.
Matrix< T > & delete_row (size_t i)
 Delete row i (single-index convenience for delete_rows).
Matrix< T > & erase_component (size_t i, size_t j)
 Flag component (i, j) as erased.
Matrix< T > & unerase_component (size_t i, size_t j)
 Clear the erasure flag on component (i, j).
Matrix< T > & erase_columns (const std::vector< size_t > &v)
 Flag every component of the specified columns as erased.
Matrix< T > & erase_column (size_t i)
 Erase column i (single-index convenience for erase_columns).
Matrix< T > & unerase_columns (const std::vector< size_t > &v)
 Clear erasure flags on every component of the specified columns.
Matrix< T > & unerase_column (size_t i)
 Un-erase column i (single-index convenience for unerase_columns).
Matrixerase_rows (const std::vector< size_t > &v)
 Flag every component of the specified rows as erased.
Matrixerase_row (size_t i)
 Erase row i (single-index convenience for erase_rows).
Matrixunerase_rows (const std::vector< size_t > &v)
 Clear erasure flags on every component of the specified rows.
Matrixunerase_row (size_t i)
 Un-erase row i (single-index convenience for unerase_rows).
Transformations
Matrix< T > & reverse_rows ()
 Reverse the row order.
Matrix< T > & reverse_columns ()
 Reverse the column order.
constexpr Matrix< T > & fill (const T &s)
 Set every component to s.
constexpr Matrix< T > & transpose ()
 Transpose in place.
Matrix< T > & ref (size_t *rank=nullptr)
 Row echelon form (REF), with a binary-field fast path.
Matrix< T > & rref (size_t *rank=nullptr)
 Reduced row echelon form (RREF).
Matrix< T > & invert ()
 Invert in place.
Finite Field Specific Operations
template<FiniteFieldType S>
requires FiniteFieldType<T> && ExtensionOf<T, S> && (!std::is_same_v<T, S>)
constexpr Vector< S > as_vector () const
 Reinterpret the columns as elements of a superfield.
Vector< T > to_vector () const
 Flatten in row-major order.
void export_as_ppm (const std::string &filename) const
 Export the matrix as a PPM (P3) image.

Friends

template<ComponentType>
class Matrix
constexpr Matrix< T > IdentityMatrix (size_t m)
 m × m identity matrix I_m (tag details::Identity)
constexpr Matrix< T > DiagonalMatrix (const Vector< T > &v)
 Diagonal matrix with diagonal v (tag details::Diagonal).
constexpr Matrix< T > ToeplitzMatrix (const Vector< T > &v, size_t m, size_t n)
 m × n Toeplitz matrix from its diagonal entries (tag details::Toeplitz)
constexpr Matrix< T > VandermondeMatrix (const Vector< T > &v, size_t m)
 Vandermonde matrix V_{i, j} = v[j]^i (tag details::Vandermonde).
template<ReliablyComparableType U>
constexpr bool operator== (const Matrix< U > &lhs, const Matrix< U > &rhs)
std::ostream & operator<< (std::ostream &os, const Matrix &rhs)
 Pretty-print the matrix with column alignment and bracket borders.

Detailed Description

template<ComponentType T>
class CECCO::Matrix< T >

Dense m × n matrix over a CECCO::ComponentType.

Template Parameters
TComponent type satisfying CECCO::ComponentType (finite field, double, std::complex<double>, or signed integer including InfInt)

Components are stored row-major in a contiguous buffer. A structural tag (details::matrix_type_t) tracks Zero / Identity / Diagonal / Vandermonde / Toeplitz structures and dispatches to specialised fast paths; mutating operations that break a tracked structure demote the tag to Generic and structure is not re-detected. Dimension mismatches in arithmetic throw std::invalid_argument.

Methods that need division (REF/RREF, inversion, nullspace, determinant, characteristic polynomial, …) are gated by requires FieldType<T>; eigenvalue computation by requires FiniteFieldType<T>. Methods that compare against zero (Hamming weight, rank, structural tests, …) are gated by requires ReliablyComparableType<T>.

Cross-field constructors and assignment operators between two finite fields of the same characteristic route through CECCO::details::largest_common_subfield_t, so matrices over fields from disjoint construction towers can interoperate.

Usage_Example

using F4 = Ext<Fp<2>, MOD{1, 1, 1}>;
Matrix<F4> M = {{1, 0}, {1, 1}};
size_t r = M.rank(); // cached
auto null_basis = M.basis_of_nullspace();
Extension field 𝔽_{q^m} ≅ B[x]/(f(x)), constructed from a base field and an irreducible monic modulus...
Definition fields.hpp:2221
Dense m × n matrix over a CECCO::ComponentType.
Definition matrices.hpp:174
Polynomial< T > characteristic_polynomial() const
Characteristic polynomial det(λI − A).
Matrix< T > basis_of_nullspace() const
Basis of the nullspace (right kernel).
size_t rank() const
Matrix rank, computed once and cached.
#define MOD
Alias for std::array, used to spell modulus polynomials in CECCO::Ext.

Definition at line 174 of file matrices.hpp.

Constructor & Destructor Documentation

◆ Matrix() [1/10]

template<ComponentType T>
CECCO::Matrix< T >::Matrix ( )
constexprdefaultnoexcept

Default constructor: empty matrix.

◆ Matrix() [2/10]

template<ComponentType T>
CECCO::Matrix< T >::Matrix ( size_t m,
size_t n )
inlineconstexpr

m × n zero matrix (tag details::Zero)

Definition at line 194 of file matrices.hpp.

◆ Matrix() [3/10]

template<ComponentType T>
CECCO::Matrix< T >::Matrix ( size_t m,
size_t n,
const T & l )

m × n matrix with every component equal to l

Tag is details::Zero if l == T(0), otherwise details::Generic.

Definition at line 1227 of file matrices.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Matrix() [4/10]

template<ComponentType T>
CECCO::Matrix< T >::Matrix ( size_t m,
size_t n,
std::initializer_list< T > l )
constexpr

m × n matrix from a flat initializer list (row-major)

Exceptions
std::invalid_argumentif l.size() != m * n

Definition at line 1237 of file matrices.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Matrix() [5/10]

template<ComponentType T>
CECCO::Matrix< T >::Matrix ( std::initializer_list< std::initializer_list< T > > l)

From nested initializer lists, e.g. {{1, 2, 3}, {4, 5, 6}}.

Rows of unequal length are zero-padded to the longest row.

Definition at line 1246 of file matrices.hpp.

◆ Matrix() [6/10]

template<ComponentType T>
CECCO::Matrix< T >::Matrix ( const Vector< T > & v)

1 × n row matrix from a Vector<T>

Definition at line 1263 of file matrices.hpp.

◆ Matrix() [7/10]

template<ComponentType T>
CECCO::Matrix< T >::Matrix ( const Matrix< T > & other)
inlineconstexpr

Definition at line 220 of file matrices.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Matrix() [8/10]

template<ComponentType T>
CECCO::Matrix< T >::Matrix ( Matrix< T > && other)
inlineconstexprnoexcept

Definition at line 228 of file matrices.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Matrix() [9/10]

template<ComponentType T>
requires FiniteFieldType<T> && (T::get_characteristic() == S::get_characteristic())
template<FiniteFieldType S>
requires FiniteFieldType<T> && (T::get_characteristic() == S::get_characteristic())
CECCO::Matrix< T >::Matrix ( const Matrix< S > & other)
constexpr

Cross-field conversion between two finite fields of the same characteristic.

Template Parameters
SSource field type (Matrix<S>); must share characteristic with T

Converts component by component via T's cross-field constructor, which routes through CECCO::details::largest_common_subfield_t and so handles disjoint construction towers. Propagates std::invalid_argument if any component is not representable in T.

Definition at line 1271 of file matrices.hpp.

◆ Matrix() [10/10]

template<ComponentType T>
requires FiniteFieldType<T> && (T::get_size() <= 64)
CECCO::Matrix< T >::Matrix ( const std::string & filename)

Read from a PPM (P3) image file using the 64-entry colormap of export_as_ppm.

Pixels whose RGB does not match any colormap entry are erased (under CECCO_ERASURE_SUPPORT) or replaced by a random field element.

Note
Convert other formats with ImageMagick:
magick input.png -alpha remove -background black +dither -remap palette.ppm -compress none output.ppm

Definition at line 1290 of file matrices.hpp.

Member Function Documentation

◆ add_column()

template<ComponentType T>
Matrix< T > & CECCO::Matrix< T >::add_column ( size_t i,
size_t j )
inline

col[j] ← col[j] + col[i]

Parameters
iSource column index
jDestination column index
Returns
Reference to this matrix after the update
Exceptions
std::invalid_argumentif either index is out of bounds

Definition at line 730 of file matrices.hpp.

Here is the call graph for this function:

◆ add_row()

template<ComponentType T>
Matrix< T > & CECCO::Matrix< T >::add_row ( size_t i,
size_t j )
inline

row[j] ← row[j] + row[i]

Parameters
iSource row index
jDestination row index
Returns
Reference to this matrix after the update
Exceptions
std::invalid_argumentif either index is out of bounds

Definition at line 715 of file matrices.hpp.

◆ add_scaled_column()

template<ComponentType T>
Matrix< T > & CECCO::Matrix< T >::add_scaled_column ( const T & s,
size_t i,
size_t j )

col[j] ← col[j] + s · col[i]

Parameters
sScalar multiplier on the source column
iSource column index
jDestination column index
Returns
Reference to this matrix after the update
Exceptions
std::invalid_argumentif either index is out of bounds

Definition at line 2130 of file matrices.hpp.

◆ add_scaled_row()

template<ComponentType T>
Matrix< T > & CECCO::Matrix< T >::add_scaled_row ( const T & s,
size_t i,
size_t j )

row[j] ← row[j] + s · row[i]

Parameters
sScalar multiplier on the source row
iSource row index
jDestination row index
Returns
Reference to this matrix after the update
Exceptions
std::invalid_argumentif either index is out of bounds

Definition at line 2106 of file matrices.hpp.

◆ as_vector()

template<ComponentType T>
requires FiniteFieldType<T> && ExtensionOf<T, S> && (!std::is_same_v<T, S>)
template<FiniteFieldType S>
requires FiniteFieldType<T> && ExtensionOf<T, S> && (!std::is_same_v<T, S>)
Vector< S > CECCO::Matrix< T >::as_vector ( ) const
constexpr

Reinterpret the columns as elements of a superfield.

Template Parameters
SSuperfield of T (same construction tower)
Returns
Vector over S, one component per column

Each column is read as the coordinate representation of an element of S over T.

Definition at line 2553 of file matrices.hpp.

◆ basis_of_kernel()

template<ComponentType T>
Matrix< T > CECCO::Matrix< T >::basis_of_kernel ( ) const
inline

Alias for basis_of_nullspace.

Returns
Matrix whose rows form a basis of the kernel

Definition at line 470 of file matrices.hpp.

◆ basis_of_nullspace()

template<ComponentType T>
requires FieldType<T>
Matrix< T > CECCO::Matrix< T >::basis_of_nullspace ( ) const

Basis of the nullspace (right kernel).

Returns
Matrix whose rows span { x : A xᵀ = 0 }; empty matrix if the nullspace is trivial

Computed by row reduction.

Definition at line 1693 of file matrices.hpp.

◆ characteristic_polynomial()

template<ComponentType T>
requires FieldType<T>
Polynomial< T > CECCO::Matrix< T >::characteristic_polynomial ( ) const

Characteristic polynomial det(λI − A).

Returns
Polynomial of degree m

Computed via the Samuelson–Berkowitz algorithm in the general case; the details::Diagonal and details::Vandermonde tags trigger closed-form shortcuts.

Exceptions
std::invalid_argumentif the matrix is not square or is empty

Definition at line 1618 of file matrices.hpp.

◆ delete_column()

template<ComponentType T>
Matrix< T > & CECCO::Matrix< T >::delete_column ( size_t i)
inline

Delete column i (single-index convenience for delete_columns).

Parameters
iColumn index
Returns
Reference to this matrix after deletion
Exceptions
std::invalid_argumentif i is out of bounds

Definition at line 757 of file matrices.hpp.

◆ delete_columns()

template<ComponentType T>
Matrix< T > & CECCO::Matrix< T >::delete_columns ( const std::vector< size_t > & v)

Delete the columns whose indices appear in v.

Parameters
vColumn indices (deduplicated internally)
Returns
Reference to this matrix after deletion
Exceptions
std::invalid_argumentif any index in v is out of bounds

Definition at line 2138 of file matrices.hpp.

◆ delete_row()

template<ComponentType T>
Matrix< T > & CECCO::Matrix< T >::delete_row ( size_t i)
inline

Delete row i (single-index convenience for delete_rows).

Parameters
iRow index
Returns
Reference to this matrix after deletion
Exceptions
std::invalid_argumentif i is out of bounds

Definition at line 777 of file matrices.hpp.

◆ delete_rows()

template<ComponentType T>
Matrix< T > & CECCO::Matrix< T >::delete_rows ( const std::vector< size_t > & v)

Delete the rows whose indices appear in v.

Parameters
vRow indices (deduplicated internally)
Returns
Reference to this matrix after deletion
Exceptions
std::invalid_argumentif any index in v is out of bounds

Definition at line 2160 of file matrices.hpp.

◆ determinant()

template<ComponentType T>
requires FieldType<T>
T CECCO::Matrix< T >::determinant ( ) const

Matrix determinant.

Returns
det(A); T(0) for singular matrices

Algorithm depends on the type tag: closed-form for details::Identity, details::Zero, and details::Diagonal; Samuelson–Berkowitz otherwise.

Exceptions
std::invalid_argumentif the matrix is not square or is empty

Definition at line 1746 of file matrices.hpp.

◆ diagonal()

template<ComponentType T>
Vector< T > CECCO::Matrix< T >::diagonal ( ) const

Main diagonal as a vector.

Returns
Vector containing entries (i, i) for i = 0, …, m−1
Exceptions
std::invalid_argumentif the matrix is not square

Definition at line 1610 of file matrices.hpp.

◆ diagonal_join()

template<ComponentType T>
Matrix< T > & CECCO::Matrix< T >::diagonal_join ( const Matrix< T > & other)

Block-diagonal join: this in the upper-left, other in the lower-right.

Parameters
otherMatrix placed in the lower-right block
Returns
Reference to this matrix after the join

Off-diagonal blocks are filled with zeros.

Definition at line 1994 of file matrices.hpp.

◆ eigenvalues()

template<ComponentType T>
requires FiniteFieldType<T>
std::vector< T > CECCO::Matrix< T >::eigenvalues ( ) const

Eigenvalues lying in the underlying finite field.

Returns
Roots of the characteristic polynomial that lie in T

Eigenvalues that exist only in an extension of T are omitted.

Exceptions
std::invalid_argumentif the matrix is not square

Definition at line 1777 of file matrices.hpp.

◆ erase_column()

template<ComponentType T>
Matrix< T > & CECCO::Matrix< T >::erase_column ( size_t i)
inline

Erase column i (single-index convenience for erase_columns).

Parameters
iColumn index
Returns
Reference to this matrix after erasing
Exceptions
std::invalid_argumentif i is out of bounds

Definition at line 832 of file matrices.hpp.

◆ erase_columns()

template<ComponentType T>
requires FieldType<T>
Matrix< T > & CECCO::Matrix< T >::erase_columns ( const std::vector< size_t > & v)

Flag every component of the specified columns as erased.

Parameters
vColumn indices (deduplicated internally)
Returns
Reference to this matrix after erasing
Warning
See erase_component for the semantics and caller obligations.
Exceptions
std::invalid_argumentif any index in v is out of bounds

Definition at line 2216 of file matrices.hpp.

◆ erase_component()

template<ComponentType T>
requires FieldType<T>
Matrix< T > & CECCO::Matrix< T >::erase_component ( size_t i,
size_t j )

Flag component (i, j) as erased.

Parameters
iRow index
jColumn index
Returns
Reference to this matrix after erasing

Marks the component as erased; field arithmetic on erased elements is undefined — see CECCO_ERASURE_SUPPORT and the erase()/unerase() interface in fields.hpp.

Warning
An erased element can no longer participate in field operations or property queries. Correct handling of erased elements is the caller's responsibility.
Exceptions
std::invalid_argumentif (i, j) is out of bounds

Definition at line 2184 of file matrices.hpp.

◆ erase_row()

template<ComponentType T>
Matrix & CECCO::Matrix< T >::erase_row ( size_t i)
inline

Erase row i (single-index convenience for erase_rows).

Parameters
iRow index
Returns
Reference to this matrix after erasing
Exceptions
std::invalid_argumentif i is out of bounds

Definition at line 884 of file matrices.hpp.

◆ erase_rows()

template<ComponentType T>
requires FieldType<T>
Matrix< T > & CECCO::Matrix< T >::erase_rows ( const std::vector< size_t > & v)

Flag every component of the specified rows as erased.

Parameters
vRow indices (deduplicated internally)
Returns
Reference to this matrix after erasing
Warning
See erase_component for the semantics and caller obligations.
Exceptions
std::invalid_argumentif any index in v is out of bounds

Definition at line 2238 of file matrices.hpp.

◆ export_as_ppm()

template<ComponentType T>
requires FiniteFieldType<T> && (T::get_size() <= 64)
void CECCO::Matrix< T >::export_as_ppm ( const std::string & filename) const

Export the matrix as a PPM (P3) image.

Parameters
filenameOutput path

Each component is mapped through a built-in 64-entry colormap (black → blue → green → yellow → white). The image is n wide and m tall.

Note
With CECCO_ERASURE_SUPPORT, erased components render in red.

Definition at line 2588 of file matrices.hpp.

◆ fill()

template<ComponentType T>
Matrix< T > & CECCO::Matrix< T >::fill ( const T & s)
constexpr

Set every component to s.

Parameters
sValue assigned to every component
Returns
Reference to this matrix after filling
Note
Tag becomes details::Zero if s == T(0), otherwise details::Generic.

Definition at line 2347 of file matrices.hpp.

◆ get_col()

template<ComponentType T>
Vector< T > CECCO::Matrix< T >::get_col ( size_t j) const

Extract column j as a (row) vector.

Parameters
jColumn index
Returns
Vector containing the components of column j; transposed, since Vector models row vectors
Exceptions
std::invalid_argumentif j is out of bounds

Definition at line 1890 of file matrices.hpp.

◆ get_m()

template<ComponentType T>
size_t CECCO::Matrix< T >::get_m ( ) const
inlineconstexprnoexcept

Get the number of rows.

Returns
Number of rows in the matrix

Definition at line 363 of file matrices.hpp.

◆ get_n()

template<ComponentType T>
size_t CECCO::Matrix< T >::get_n ( ) const
inlineconstexprnoexcept

Get the number of columns.

Returns
Number of columns in the matrix

Definition at line 370 of file matrices.hpp.

◆ get_row()

template<ComponentType T>
Vector< T > CECCO::Matrix< T >::get_row ( size_t i) const

Extract row i as a vector.

Parameters
iRow index
Returns
Vector containing the components of row i
Exceptions
std::invalid_argumentif i is out of bounds

Definition at line 1878 of file matrices.hpp.

◆ get_submatrix()

template<ComponentType T>
Matrix< T > CECCO::Matrix< T >::get_submatrix ( size_t i,
size_t j,
size_t h,
size_t w ) const

Extract submatrix from region [i, i+h) × [j, j+w).

Parameters
iStarting row index
jStarting column index
hHeight (number of rows)
wWidth (number of columns)
Returns
Submatrix of shape h × w
Exceptions
std::invalid_argumentif the region extends beyond the matrix

Definition at line 1902 of file matrices.hpp.

◆ horizontal_join()

template<ComponentType T>
Matrix< T > & CECCO::Matrix< T >::horizontal_join ( const Matrix< T > & other)

Concatenate other to the right (column-wise).

Parameters
otherMatrix to append on the right; must have the same number of rows as this
Returns
Reference to this matrix after the join
Exceptions
std::invalid_argumentif row counts differ

Definition at line 1960 of file matrices.hpp.

◆ invert()

template<ComponentType T>
requires FieldType<T>
Matrix< T > & CECCO::Matrix< T >::invert ( )

Invert in place.

Returns
Reference to this matrix after inversion

Gaussian elimination with partial pivoting. Requires a square non-singular matrix.

Exceptions
std::invalid_argumentif the matrix is not square or is singular

Definition at line 2508 of file matrices.hpp.

◆ is_empty()

template<ComponentType T>
bool CECCO::Matrix< T >::is_empty ( ) const
inlineconstexprnoexcept

Check if matrix is empty.

Returns
true if matrix has zero rows or columns, false otherwise

Definition at line 377 of file matrices.hpp.

◆ is_invertible()

template<ComponentType T>
bool CECCO::Matrix< T >::is_invertible ( ) const
inline

Check if matrix is invertible.

Returns
true iff the matrix is square and has full rank

Definition at line 427 of file matrices.hpp.

◆ is_zero() [1/2]

template<ComponentType T>
bool CECCO::Matrix< T >::is_zero ( )
inlineconstexpr

Check if the matrix is zero, caching the result via the type tag.

Returns
true iff every component equals T(0)

On a positive result the tag is updated to details::Zero, so subsequent calls and other tag-aware fast paths short-circuit.

Definition at line 387 of file matrices.hpp.

◆ is_zero() [2/2]

template<ComponentType T>
bool CECCO::Matrix< T >::is_zero ( ) const
inlineconstexpr

Check if the matrix is zero (no caching).

Returns
true iff every component equals T(0)

Definition at line 399 of file matrices.hpp.

◆ Kronecker_product()

template<ComponentType T>
Matrix< T > & CECCO::Matrix< T >::Kronecker_product ( const Matrix< T > & other)

Kronecker (tensor) product with other.

Parameters
otherRight operand
Returns
Reference to this matrix after the product

If this is m × n and other is p × q, the result is mp × nq.

Definition at line 2013 of file matrices.hpp.

◆ operator()()

template<ComponentType T>
const T & CECCO::Matrix< T >::operator() ( size_t i,
size_t j ) const

Access component (i, j) (read-only).

Parameters
iRow index (0-based)
jColumn index (0-based)
Returns
Const reference to the component at (i, j)
Exceptions
std::invalid_argumentif either index is out of bounds

Definition at line 1871 of file matrices.hpp.

◆ operator*=() [1/2]

template<ComponentType T>
Matrix< T > & CECCO::Matrix< T >::operator*= ( const Matrix< T > & rhs)

Matrix multiplication *this = *this · rhs.

Exceptions
std::invalid_argumentif this->get_n() != rhs.get_m()

Definition at line 1483 of file matrices.hpp.

Here is the caller graph for this function:

◆ operator*=() [2/2]

template<ComponentType T>
Matrix< T > & CECCO::Matrix< T >::operator*= ( const T & s)
constexpr

Multiply every component by the scalar s.

Definition at line 1542 of file matrices.hpp.

◆ operator+() [1/2]

template<ComponentType T>
Matrix CECCO::Matrix< T >::operator+ ( ) &&
inlineconstexprnoexcept

Unary + (rvalue): returns the rvalue itself.

Definition at line 286 of file matrices.hpp.

◆ operator+() [2/2]

template<ComponentType T>
Matrix CECCO::Matrix< T >::operator+ ( ) const &
inlineconstexpr

Unary + (lvalue): returns a copy.

Definition at line 284 of file matrices.hpp.

◆ operator+=()

template<ComponentType T>
Matrix< T > & CECCO::Matrix< T >::operator+= ( const Matrix< T > & rhs)

Component-wise addition this(i, j) += rhs(i, j).

Exceptions
std::invalid_argumentif dimensions differ

Definition at line 1439 of file matrices.hpp.

Here is the caller graph for this function:

◆ operator-() [1/2]

template<ComponentType T>
Matrix< T > CECCO::Matrix< T >::operator- ( ) &&
constexpr

Unary (rvalue): negates components in place.

Definition at line 1417 of file matrices.hpp.

◆ operator-() [2/2]

template<ComponentType T>
Matrix< T > CECCO::Matrix< T >::operator- ( ) const &
constexpr

Unary (lvalue): returns a new matrix with each component negated.

Definition at line 1395 of file matrices.hpp.

◆ operator-=()

template<ComponentType T>
Matrix< T > & CECCO::Matrix< T >::operator-= ( const Matrix< T > & rhs)

Component-wise subtraction this(i, j) -= rhs(i, j).

Exceptions
std::invalid_argumentif dimensions differ

Definition at line 1472 of file matrices.hpp.

Here is the call graph for this function:

◆ operator/=()

template<ComponentType T>
Matrix< T > & CECCO::Matrix< T >::operator/= ( const T & s)

Divide every component by the scalar s.

Exceptions
std::invalid_argumentif s == T(0)
Note
Round-trip (M / s) * s == M is only guaranteed when T satisfies CECCO::FieldType (otherwise integer rounding may corrupt components).

Definition at line 1558 of file matrices.hpp.

Here is the call graph for this function:

◆ operator=() [1/4]

template<ComponentType T>
Matrix< T > & CECCO::Matrix< T >::operator= ( const Matrix< T > & rhs)
constexpr

Definition at line 1357 of file matrices.hpp.

◆ operator=() [2/4]

template<ComponentType T>
template<FiniteFieldType S>
Matrix< T > & CECCO::Matrix< T >::operator= ( const Matrix< S > & other)
constexpr

Definition at line 1382 of file matrices.hpp.

◆ operator=() [3/4]

template<ComponentType T>
template<FiniteFieldType S>
Matrix & CECCO::Matrix< T >::operator= ( const Matrix< S > & other)
constexpr

Cross-field assignment (same semantics as the cross-field constructor).

◆ operator=() [4/4]

template<ComponentType T>
Matrix< T > & CECCO::Matrix< T >::operator= ( Matrix< T > && rhs)
constexprnoexcept

Definition at line 1369 of file matrices.hpp.

◆ randomize()

template<ComponentType T>
Matrix< T > & CECCO::Matrix< T >::randomize ( )

Fill matrix with random values.

Returns
Reference to this matrix after randomization

Distribution depends on the component type: finite-field types draw uniformly from the field; signed integers from [−100, 100]; double and the real/imaginary parts of std::complex<double> from [−1.0, 1.0].

Note
Tag becomes details::Generic — incidental structure (e.g. an accidental zero matrix) is not re-detected.

Definition at line 1565 of file matrices.hpp.

◆ rank()

template<ComponentType T>
requires FieldType<T>
size_t CECCO::Matrix< T >::rank ( ) const

Matrix rank, computed once and cached.

Returns
Dimension of the row space (equivalently, of the column space)

Uses row reduction to echelon form. Subsequent calls return the cached value until a mutating operation invalidates it.

Definition at line 1603 of file matrices.hpp.

◆ ref()

template<ComponentType T>
requires FieldType<T>
Matrix< T > & CECCO::Matrix< T >::ref ( size_t * rank = nullptr)

Row echelon form (REF), with a binary-field fast path.

Parameters
rankOptional out-parameter; if non-null, receives the rank
Returns
Reference to this matrix after the reduction

Forward Gaussian elimination only — cheaper than RREF when only the rank or a triangularised form is needed. For Fp<2>, pivot scaling is skipped at compile time. Rank is cached when rank is non-null.

Definition at line 2376 of file matrices.hpp.

◆ reverse_columns()

template<ComponentType T>
Matrix< T > & CECCO::Matrix< T >::reverse_columns ( )

Reverse the column order.

Returns
Reference to this matrix after the reversal

Definition at line 2324 of file matrices.hpp.

◆ reverse_rows()

template<ComponentType T>
Matrix< T > & CECCO::Matrix< T >::reverse_rows ( )

Reverse the row order.

Returns
Reference to this matrix after the reversal

Definition at line 2302 of file matrices.hpp.

◆ rowspace()

template<ComponentType T>
requires FieldType<T>
std::vector< Vector< T > > CECCO::Matrix< T >::rowspace ( ) const

Enumerate every vector in the row space.

Returns
All q^rank vectors in span(rows), where q = |T|
Warning
Size grows as q^rank — only practical for small fields and small rank.

Definition at line 1790 of file matrices.hpp.

◆ rref()

template<ComponentType T>
requires FieldType<T>
Matrix< T > & CECCO::Matrix< T >::rref ( size_t * rank = nullptr)

Reduced row echelon form (RREF).

Parameters
rankOptional out-parameter; if non-null, receives the rank
Returns
Reference to this matrix after the reduction

Two phases: forward elimination (REF) followed by backward elimination. Rank is always cached.

Definition at line 2425 of file matrices.hpp.

◆ scale_column()

template<ComponentType T>
Matrix< T > & CECCO::Matrix< T >::scale_column ( const T & s,
size_t i )

col[i] ← s · col[i]

Parameters
sScalar multiplier
iColumn index
Returns
Reference to this matrix after the scaling
Exceptions
std::invalid_argumentif i is out of bounds

Definition at line 2098 of file matrices.hpp.

◆ scale_row()

template<ComponentType T>
Matrix< T > & CECCO::Matrix< T >::scale_row ( const T & s,
size_t i )

row[i] ← s · row[i]

Parameters
sScalar multiplier
iRow index
Returns
Reference to this matrix after the scaling
Exceptions
std::invalid_argumentif i is out of bounds

Definition at line 2075 of file matrices.hpp.

◆ set_component() [1/2]

template<ComponentType T>
template<typename U>
requires std::convertible_to<std::decay_t<U>, T>
Matrix< T > & CECCO::Matrix< T >::set_component ( size_t i,
size_t j,
U && c )

Definition at line 1818 of file matrices.hpp.

◆ set_component() [2/2]

template<ComponentType T>
template<typename U>
requires std::convertible_to<std::decay_t<U>, T>
Matrix & CECCO::Matrix< T >::set_component ( size_t i,
size_t j,
U && c )

Set component (i, j) by perfect forwarding.

Parameters
iRow index (0-based)
jColumn index (0-based)
cValue to assign; bound by lvalue or rvalue reference
Returns
Reference to this matrix after modification
Exceptions
std::invalid_argumentif either index is out of bounds

◆ set_submatrix()

template<ComponentType T>
Matrix< T > & CECCO::Matrix< T >::set_submatrix ( size_t i,
size_t j,
const Matrix< T > & N )

Overwrite the region starting at (i, j) with N.

Parameters
iStarting row index
jStarting column index
NSource matrix; its shape must fit within this matrix from (i, j)
Returns
Reference to this matrix after the assignment
Exceptions
std::invalid_argumentif the region would extend beyond bounds

Definition at line 1941 of file matrices.hpp.

◆ span()

template<ComponentType T>
std::vector< Vector< T > > CECCO::Matrix< T >::span ( ) const
inline

Alias for rowspace.

Returns
Every vector in the span of the rows

Definition at line 516 of file matrices.hpp.

◆ swap_columns()

template<ComponentType T>
Matrix< T > & CECCO::Matrix< T >::swap_columns ( size_t i,
size_t j )

Swap columns i and j.

Parameters
iFirst column index
jSecond column index
Returns
Reference to this matrix after the swap
Exceptions
std::invalid_argumentif either index is out of bounds

Definition at line 2067 of file matrices.hpp.

◆ swap_rows()

template<ComponentType T>
Matrix< T > & CECCO::Matrix< T >::swap_rows ( size_t i,
size_t j )

Swap rows i and j.

Parameters
iFirst row index
jSecond row index
Returns
Reference to this matrix after the swap
Exceptions
std::invalid_argumentif either index is out of bounds

Definition at line 2046 of file matrices.hpp.

◆ to_vector()

template<ComponentType T>
Vector< T > CECCO::Matrix< T >::to_vector ( ) const

Flatten in row-major order.

Returns
Vector of length m·n; component (i, j) maps to index i·n + j

Definition at line 2571 of file matrices.hpp.

◆ transpose()

template<ComponentType T>
Matrix< T > & CECCO::Matrix< T >::transpose ( )
constexpr

Transpose in place.

Returns
Reference to this matrix after transposition

For an m × n matrix the result is n × m, with component (i, j) moved to (j, i).

Definition at line 2362 of file matrices.hpp.

Here is the caller graph for this function:

◆ unerase_column()

template<ComponentType T>
Matrix< T > & CECCO::Matrix< T >::unerase_column ( size_t i)
inline

Un-erase column i (single-index convenience for unerase_columns).

Parameters
iColumn index
Returns
Reference to this matrix after un-erasing
Exceptions
std::invalid_argumentif i is out of bounds

Definition at line 857 of file matrices.hpp.

◆ unerase_columns()

template<ComponentType T>
requires FieldType<T>
Matrix< T > & CECCO::Matrix< T >::unerase_columns ( const std::vector< size_t > & v)

Clear erasure flags on every component of the specified columns.

Parameters
vColumn indices (deduplicated internally)
Returns
Reference to this matrix after un-erasing
Exceptions
std::invalid_argumentif any index in v is out of bounds

Definition at line 2260 of file matrices.hpp.

◆ unerase_component()

template<ComponentType T>
requires FieldType<T>
Matrix< T > & CECCO::Matrix< T >::unerase_component ( size_t i,
size_t j )

Clear the erasure flag on component (i, j).

Parameters
iRow index
jColumn index
Returns
Reference to this matrix after un-erasing
Exceptions
std::invalid_argumentif (i, j) is out of bounds

Definition at line 2200 of file matrices.hpp.

◆ unerase_row()

template<ComponentType T>
Matrix & CECCO::Matrix< T >::unerase_row ( size_t i)
inline

Un-erase row i (single-index convenience for unerase_rows).

Parameters
iRow index
Returns
Reference to this matrix after un-erasing
Exceptions
std::invalid_argumentif i is out of bounds

Definition at line 909 of file matrices.hpp.

◆ unerase_rows()

template<ComponentType T>
requires FieldType<T>
Matrix< T > & CECCO::Matrix< T >::unerase_rows ( const std::vector< size_t > & v)

Clear erasure flags on every component of the specified rows.

Parameters
vRow indices (deduplicated internally)
Returns
Reference to this matrix after un-erasing
Exceptions
std::invalid_argumentif any index in v is out of bounds

Definition at line 2280 of file matrices.hpp.

◆ vertical_join()

template<ComponentType T>
Matrix< T > & CECCO::Matrix< T >::vertical_join ( const Matrix< T > & other)

Concatenate other below (row-wise).

Parameters
otherMatrix to append below; must have the same number of columns as this
Returns
Reference to this matrix after the join
Exceptions
std::invalid_argumentif column counts differ

Definition at line 1977 of file matrices.hpp.

◆ wH()

template<ComponentType T>
size_t CECCO::Matrix< T >::wH ( ) const
inline

Hamming weight: number of non-zero, non-erased components; cached on first call.

Definition at line 405 of file matrices.hpp.

◆ DiagonalMatrix

template<ComponentType T>
Matrix< T > DiagonalMatrix ( const Vector< T > & v)
friend

Diagonal matrix with diagonal v (tag details::Diagonal).

Parameters
vVector of diagonal entries; the result is v.length() × v.length()
Returns
Diagonal matrix with v[i] on position (i, i), zeros elsewhere

Definition at line 3511 of file matrices.hpp.

◆ IdentityMatrix

template<ComponentType T>
Matrix< T > IdentityMatrix ( size_t m)
friend

m × m identity matrix I_m (tag details::Identity)

Parameters
mSide length
Returns
Newly constructed identity matrix

Definition at line 3455 of file matrices.hpp.

◆ Matrix

template<ComponentType T>
template<ComponentType>
friend class Matrix
friend

Definition at line 183 of file matrices.hpp.

◆ operator<<

template<ComponentType T>
std::ostream & operator<< ( std::ostream & os,
const Matrix< T > & rhs )
friend

Pretty-print the matrix with column alignment and bracket borders.

Returns
Reference to os for chaining

An empty matrix is printed as "(empty matrix)".

Definition at line 3388 of file matrices.hpp.

◆ operator==

template<ComponentType T>
template<ReliablyComparableType U>
bool operator== ( const Matrix< U > & lhs,
const Matrix< U > & rhs )
friend

◆ ToeplitzMatrix

template<ComponentType T>
Matrix< T > ToeplitzMatrix ( const Vector< T > & v,
size_t m,
size_t n )
friend

m × n Toeplitz matrix from its diagonal entries (tag details::Toeplitz)

Parameters
vDiagonal values, ordered so that v[i − j + n − 1] sits on entry (i, j); length m + n − 1
mNumber of rows
nNumber of columns
Returns
Toeplitz matrix; each descending diagonal is constant
Exceptions
std::invalid_argumentif v.length() != m + n - 1

Definition at line 3530 of file matrices.hpp.

◆ VandermondeMatrix

template<ComponentType T>
Matrix< T > VandermondeMatrix ( const Vector< T > & v,
size_t m )
friend

Vandermonde matrix V_{i, j} = v[j]^i (tag details::Vandermonde).

Parameters
vEvaluation points; must be pairwise distinct
mNumber of rows (i.e. the highest power is m − 1)
Returns
m × v.length() Vandermonde matrix
Exceptions
std::invalid_argumentif v is empty, has duplicates, or m is zero

Definition at line 3577 of file matrices.hpp.


The documentation for this class was generated from the following files: