4#include "../consteig_types.hpp"
5#include "../math/math_backend.hpp"
15template <
typename T, Size R, Size C>
class Matrix;
17template <
typename T, Size R, Size C>
20template <
typename T, Size R, Size C>
23template <
typename T, Size R, Size C>
26template <
typename T, Size R, Size C>
29template <
typename T, Size R, Size C>
55template <
typename T, Size R, Size C>
class Matrix
93 return !(*
this ==
rhs);
117 template <Size startIndex, Size endIndex>
120 static_assert(
C >
startIndex,
"startIndex cannot be larger than array");
121 static_assert(
C >
endIndex,
"endIndex cannot be larger than array");
123 "startIndex cannot be larger than endIndex");
156 template <Size startIndex, Size endIndex>
159 static_assert(
R >
startIndex,
"startIndex cannot be larger than array");
160 static_assert(
R >
endIndex,
"endIndex cannot be larger than array");
162 "startIndex cannot be larger than endIndex");
184 template <Size numRows, Size numCols>
218 template <Size startIndex, Size endIndex>
222 static_assert(
C >
startIndex,
"startIndex cannot be larger than array");
223 static_assert(
C >
endIndex,
"endIndex cannot be larger than array");
225 "startIndex cannot be larger than endIndex");
250 template <Size startIndex, Size endIndex>
254 static_assert(
R >
startIndex,
"startIndex cannot be larger than array");
255 static_assert(
R >
endIndex,
"endIndex cannot be larger than array");
257 "startIndex cannot be larger than endIndex");
276 template <Size numRows, Size numCols>
304 static_assert(
R ==
C,
"Symmetric matrices should be square.");
315 eq = consteig::equalWithin(
347 "isSymmetric with threshold requires floating-point "
348 "matrix elements; integer T would truncate thresh");
349 static_assert(
is_float<U>(),
"isSymmetric with arg expects to compare\
350 floating point values");
351 static_assert(
R ==
C,
"Symmetric matrices should be square.");
359 if (!consteig::equalWithin((*
this)(
row,
col),
486template <
typename T, Size
R, Size
C,
typename...
Args>
489 static_assert(
sizeof...(Args) ==
R *
C,
490 "make_matrix: argument count must equal R * C");
495 for (Size row{0}; row <
R; row++)
497 for (Size col{0}; col <
C; col++)
523template <
typename To,
typename From, Size R, Size C>
528 for (Size row{0}; row <
R; row++)
530 for (Size col{0}; col <
C; col++)
Fixed-size matrix with compile-time dimensions.
Definition matrix.hpp:56
constexpr bool isSymmetric(const U thresh) const
Returns true if the matrix is symmetric within thresh.
Definition matrix.hpp:344
constexpr Matrix< T, 1, endIndex - startIndex+1 > row(const Size n) const
Extract a contiguous subset of row n.
Definition matrix.hpp:118
constexpr T trace() const
Returns the trace. Delegates to consteig::trace.
Definition matrix.hpp:428
constexpr void setCol(const Matrix< T, R, 1 > &mat, const Size n)
Overwrite column n with the contents of mat.
Definition matrix.hpp:236
constexpr void setRow(const Matrix< T, 1, endIndex - startIndex+1 > &mat, const Size n)
Overwrite a contiguous subset of row n.
Definition matrix.hpp:219
constexpr T determinant() const
Returns the determinant. Delegates to consteig::determinant.
Definition matrix.hpp:434
constexpr const T & operator()(const Size row, const Size col) const
Access element at row row, column col (read-only).
Definition matrix.hpp:65
constexpr Matrix< T, numRows, numCols > block(Size startRow, Size startCol) const
Extract a rectangular submatrix.
Definition matrix.hpp:185
constexpr T dot(const Matrix< T, R, C > &other) const
Dot product with other. Delegates to consteig::dot.
Definition matrix.hpp:446
constexpr bool isSquare() const
Returns true if the matrix has equal row and column counts.
Definition matrix.hpp:290
constexpr Matrix< T, endIndex - startIndex+1, 1 > col(const Size n) const
Extract a contiguous subset of column n.
Definition matrix.hpp:157
constexpr T norm() const
Returns the Frobenius norm. Delegates to consteig::norm.
Definition matrix.hpp:440
constexpr Matrix< T, C, R > transpose() const
Member convenience wrappers that delegate to free functions.
Definition matrix.hpp:422
constexpr Matrix< T, 1, C > row(const Size n) const
Extract row n as a 1×C matrix.
Definition matrix.hpp:98
constexpr Matrix< T, R, 1 > col(const Size n) const
Extract column n as an R×1 matrix.
Definition matrix.hpp:137
constexpr void setRow(const Matrix< T, 1, C > &mat, const Size n)
Overwrite row n with the contents of mat.
Definition matrix.hpp:204
constexpr Size rows() const
Number of rows (same as template parameter R).
Definition matrix.hpp:396
constexpr const T * data() const
Raw pointer to first element (read-only).
Definition matrix.hpp:413
constexpr bool operator!=(const Matrix< U, R, C > &rhs) const
Inequality (exact). Prefer negated equalWithin(rhs, thresh) for floats.
Definition matrix.hpp:91
constexpr void setCol(const Matrix< T, endIndex - startIndex+1, 1 > &mat, const Size n)
Overwrite a contiguous subset of column n.
Definition matrix.hpp:251
constexpr T & operator()(const Size row, const Size col)
Access element at row row, column col (mutable).
Definition matrix.hpp:59
constexpr Size cols() const
Number of columns (same as template parameter C).
Definition matrix.hpp:401
constexpr bool operator==(const Matrix< U, R, C > &rhs) const
Exact element-wise equality. Prefer equalWithin(rhs, thresh) for floats.
Definition matrix.hpp:73
constexpr T * data()
Raw pointer to first element (mutable).
Definition matrix.hpp:407
constexpr bool isSymmetric() const
Returns true if the matrix is symmetric within machine epsilon.
Definition matrix.hpp:302
constexpr void setBlock(const Matrix< T, numRows, numCols > &mat, Size startRow, Size startCol)
Overwrite a rectangular subregion of this matrix.
Definition matrix.hpp:277
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.
Definition matrix.hpp:379
constexpr T epsilon()
Machine epsilon for type T.
Definition utilities.hpp:82
constexpr T determinant(const Matrix< T, R, C > &mat)
Determinant via Laplace (cofactor) expansion.
Definition operations.hpp:323
constexpr T norm(const Matrix< T, R, C > &mat)
Frobenius (Euclidean) norm: sqrt(sum of squared elements).
Definition operations.hpp:211
constexpr Matrix< To, R, C > matrix_cast(const Matrix< From, R, C > &src)
Convert a matrix from one element type to another.
Definition matrix.hpp:524
constexpr Matrix< T, C, R > transpose(const Matrix< T, R, C > &mat)
Matrix transpose.
Definition operations.hpp:154
constexpr T dot(const Matrix< T, R, C > &lhs, const Matrix< T, R, C > &rhs)
Dot product of two 1×N row vectors.
Definition operations.hpp:137
constexpr T trace(const Matrix< T, R, C > &mat)
Trace: sum of diagonal elements.
Definition operations.hpp:370
constexpr Matrix< T, R, C > make_matrix(Args... args)
Construct a Matrix from a flat list of scalar arguments in row-major order.
Definition matrix.hpp:487