consteig
Compile-time eigenvalue and eigenvector computation for C++17
Loading...
Searching...
No Matches
Public Member Functions | List of all members
consteig::Matrix< T, R, C > Class Template Reference

Fixed-size matrix with compile-time dimensions. More...

#include <matrix.hpp>

Inheritance diagram for consteig::Matrix< T, R, C >:
Inheritance graph
[legend]

Public Member Functions

constexpr Toperator() (const Size row, const Size col)
 Access element at row row, column col (mutable).
 
constexpr const Toperator() (const Size row, const Size col) const
 Access element at row row, column col (read-only).
 
template<typename U >
constexpr bool operator== (const Matrix< U, R, C > &rhs) const
 Exact element-wise equality. Prefer equalWithin(rhs, thresh) for floats.
 
template<typename U >
constexpr bool operator!= (const Matrix< U, R, C > &rhs) const
 Inequality (exact). Prefer negated equalWithin(rhs, thresh) for floats.
 
constexpr Matrix< T, 1, Crow (const Size n) const
 Extract row n as a 1×C matrix.
 
template<Size startIndex, Size endIndex>
constexpr Matrix< T, 1, endIndex - startIndex+1 > row (const Size n) const
 Extract a contiguous subset of row n.
 
constexpr Matrix< T, R, 1 > col (const Size n) const
 Extract column n as an R×1 matrix.
 
template<Size startIndex, Size endIndex>
constexpr Matrix< T, endIndex - startIndex+1, 1 > col (const Size n) const
 Extract a contiguous subset of column n.
 
template<Size numRows, Size numCols>
constexpr Matrix< T, numRows, numColsblock (Size startRow, Size startCol) const
 Extract a rectangular submatrix.
 
constexpr void setRow (const Matrix< T, 1, C > &mat, const Size n)
 Overwrite row n with the contents of mat.
 
template<Size startIndex, Size endIndex>
constexpr void setRow (const Matrix< T, 1, endIndex - startIndex+1 > &mat, const Size n)
 Overwrite a contiguous subset of row n.
 
constexpr void setCol (const Matrix< T, R, 1 > &mat, const Size n)
 Overwrite column n with the contents of mat.
 
template<Size startIndex, Size endIndex>
constexpr void setCol (const Matrix< T, endIndex - startIndex+1, 1 > &mat, const Size n)
 Overwrite a contiguous subset of column n.
 
template<Size numRows, Size numCols>
constexpr void setBlock (const Matrix< T, numRows, numCols > &mat, Size startRow, Size startCol)
 Overwrite a rectangular subregion of this matrix.
 
constexpr bool isSquare () const
 Returns true if the matrix has equal row and column counts.
 
constexpr bool isSymmetric () const
 Returns true if the matrix is symmetric within machine epsilon.
 
template<typename U >
constexpr bool isSymmetric (const U thresh) const
 Returns true if the matrix is symmetric within thresh.
 
constexpr bool equalWithin (const Matrix< T, R, C > &rhs, const T thresh) const
 Returns true if every element of rhs is within thresh of the corresponding element of *this.
 
constexpr Size rows () const
 Number of rows (same as template parameter R).
 
constexpr Size cols () const
 Number of columns (same as template parameter C).
 
constexpr Tdata ()
 Raw pointer to first element (mutable).
 
constexpr const Tdata () const
 Raw pointer to first element (read-only).
 
constexpr Matrix< T, C, Rtranspose () const
 Member convenience wrappers that delegate to free functions.
 
constexpr T trace () const
 Returns the trace. Delegates to consteig::trace.
 
constexpr T determinant () const
 Returns the determinant. Delegates to consteig::determinant.
 
constexpr T norm () const
 Returns the Frobenius norm. Delegates to consteig::norm.
 
constexpr T dot (const Matrix< T, R, C > &other) const
 Dot product with other. Delegates to consteig::dot.
 

Detailed Description

template<typename T, Size R, Size C>
class consteig::Matrix< T, R, C >

Fixed-size matrix with compile-time dimensions.

The primary container type for all consteig operations. All member functions are constexpr, enabling full compile-time evaluation when the matrix is declared static constexpr.

Storage is row-major: _data[i][j] holds row i, column j. Element access uses operator()(i, j) using zero-based indices.

Template Parameters
TScalar element type. Floating-point types (float, double, long double) are required for eigensolver and decomposition operations. Integer types are supported for pure arithmetic.
RNumber of rows (compile-time constant).
CNumber of columns (compile-time constant).
// 2x2 matrix of doubles
{1.0, 2.0},
{3.0, 4.0}
}};
static constexpr double val = A(0, 1); // 2.0
Fixed-size matrix with compile-time dimensions.
Definition matrix.hpp:56
constexpr T epsilon()
Machine epsilon for type T.
Definition utilities.hpp:82

Member Function Documentation

◆ row() [1/2]

template<typename T , Size R, Size C>
constexpr Matrix< T, 1, C > consteig::Matrix< T, R, C >::row ( const Size n) const
inlineconstexpr

Extract row n as a 1×C matrix.

Parameters
nZero-based row index. Must be < R.

◆ row() [2/2]

template<typename T , Size R, Size C>
template<Size startIndex, Size endIndex>
constexpr Matrix< T, 1, endIndex - startIndex+1 > consteig::Matrix< T, R, C >::row ( const Size n) const
inlineconstexpr

Extract a contiguous subset of row n.

Template Parameters
startIndexFirst column index (inclusive, compile-time).
endIndexLast column index (inclusive, compile-time).
Parameters
nZero-based row index.
Returns
1×(endIndex-startIndex+1) matrix.

◆ col() [1/2]

template<typename T , Size R, Size C>
constexpr Matrix< T, R, 1 > consteig::Matrix< T, R, C >::col ( const Size n) const
inlineconstexpr

Extract column n as an R×1 matrix.

Parameters
nZero-based column index. Must be < C.

◆ col() [2/2]

template<typename T , Size R, Size C>
template<Size startIndex, Size endIndex>
constexpr Matrix< T, endIndex - startIndex+1, 1 > consteig::Matrix< T, R, C >::col ( const Size n) const
inlineconstexpr

Extract a contiguous subset of column n.

Template Parameters
startIndexFirst row index (inclusive, compile-time).
endIndexLast row index (inclusive, compile-time).
Parameters
nZero-based column index.
Returns
(endIndex-startIndex+1)×1 matrix.

◆ block()

template<typename T , Size R, Size C>
template<Size numRows, Size numCols>
constexpr Matrix< T, numRows, numCols > consteig::Matrix< T, R, C >::block ( Size startRow,
Size startCol ) const
inlineconstexpr

Extract a rectangular submatrix.

Returns a numRows × numCols submatrix starting at (startRow, startCol). Dimensions are compile-time constants; start position is runtime.

Template Parameters
numRowsNumber of rows to extract (compile-time).
numColsNumber of columns to extract (compile-time).
Parameters
startRowTop-left row index (zero-based, runtime).
startColTop-left column index (zero-based, runtime).

◆ setRow() [1/2]

template<typename T , Size R, Size C>
constexpr void consteig::Matrix< T, R, C >::setRow ( const Matrix< T, 1, C > & mat,
const Size n )
inlineconstexpr

Overwrite row n with the contents of mat.

Parameters
mat1×C source matrix.
nZero-based target row index.

◆ setRow() [2/2]

template<typename T , Size R, Size C>
template<Size startIndex, Size endIndex>
constexpr void consteig::Matrix< T, R, C >::setRow ( const Matrix< T, 1, endIndex - startIndex+1 > & mat,
const Size n )
inlineconstexpr

Overwrite a contiguous subset of row n.

Template Parameters
startIndexFirst column to write (inclusive, compile-time).
endIndexLast column to write (inclusive, compile-time).
Parameters
matSource 1×(endIndex-startIndex+1) matrix.
nZero-based target row index.

◆ setCol() [1/2]

template<typename T , Size R, Size C>
constexpr void consteig::Matrix< T, R, C >::setCol ( const Matrix< T, R, 1 > & mat,
const Size n )
inlineconstexpr

Overwrite column n with the contents of mat.

Parameters
matR×1 source matrix.
nZero-based target column index.

◆ setCol() [2/2]

template<typename T , Size R, Size C>
template<Size startIndex, Size endIndex>
constexpr void consteig::Matrix< T, R, C >::setCol ( const Matrix< T, endIndex - startIndex+1, 1 > & mat,
const Size n )
inlineconstexpr

Overwrite a contiguous subset of column n.

Template Parameters
startIndexFirst row to write (inclusive, compile-time).
endIndexLast row to write (inclusive, compile-time).
Parameters
matSource (endIndex-startIndex+1)×1 matrix.
nZero-based target column index.

◆ setBlock()

template<typename T , Size R, Size C>
template<Size numRows, Size numCols>
constexpr void consteig::Matrix< T, R, C >::setBlock ( const Matrix< T, numRows, numCols > & mat,
Size startRow,
Size startCol )
inlineconstexpr

Overwrite a rectangular subregion of this matrix.

Copies the numRows × numCols source matrix mat into this matrix starting at (startRow, startCol). Dimensions are compile-time; start position is runtime.

Template Parameters
numRowsNumber of rows to write (compile-time).
numColsNumber of columns to write (compile-time).
Parameters
matSource matrix of dimensions numRows × numCols.
startRowTop-left target row (zero-based, runtime).
startColTop-left target column (zero-based, runtime).

◆ isSymmetric() [1/2]

template<typename T , Size R, Size C>
constexpr bool consteig::Matrix< T, R, C >::isSymmetric ( ) const
inlineconstexpr

Returns true if the matrix is symmetric within machine epsilon.

Uses equalWithin with epsilon<T>() as the tolerance. For floating-point matrices, prefer the threshold overload to control the tolerance explicitly.

Precondition
R == C (enforced by static_assert).

◆ isSymmetric() [2/2]

template<typename T , Size R, Size C>
template<typename U >
constexpr bool consteig::Matrix< T, R, C >::isSymmetric ( const U thresh) const
inlineconstexpr

Returns true if the matrix is symmetric within thresh.

Checks every off-diagonal pair (i,j) / (j,i) using equalWithin. Use this overload when you need explicit control over the symmetry tolerance (e.g., for the eigenvalue solver routing threshold CONSTEIG_DEFAULT_SYMMETRIC_TOLERANCE).

Template Parameters
UType of the threshold. Must be floating-point.
Parameters
threshAbsolute tolerance for the symmetry check.
Precondition
R == C and T must be a floating-point type.

◆ equalWithin()

template<typename T , Size R, Size C>
constexpr bool consteig::Matrix< T, R, C >::equalWithin ( const Matrix< T, R, C > & rhs,
const T thresh ) const
inlineconstexpr

Returns true if every element of rhs is within thresh of the corresponding element of *this.

The free function equalWithinMat delegates to this. Prefer this over operator== for floating-point matrices.

Parameters
rhsMatrix to compare against.
threshAbsolute per-element tolerance.

◆ transpose()

template<typename T , Size R, Size C>
constexpr Matrix< T, C, R > consteig::Matrix< T, R, C >::transpose ( ) const
inlineconstexpr

Member convenience wrappers that delegate to free functions.

Returns the transpose. Delegates to consteig::transpose.


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