4#include "../math/constmath.hpp"
23template <
typename T, Size R, Size C>
29 for (Size row{0}; row <
R; ++row)
31 for (Size col{0}; col <
C; ++col)
48template <
typename T, Size R, Size C>
54 for (Size row{0}; row <
R; ++row)
56 for (Size col{0}; col <
C; ++col)
77template <
typename T, Size R1, Size C1, Size R2, Size C2>
81 static_assert(
C1 ==
R2,
"Number of columns must equal number of rows");
84 for (Size row{0}; row <
R1; row++)
86 for (Size col{0}; col <
C2; col++)
109template <
typename T, Size R, Size C>
114 for (Size row{0}; row <
R; row++)
116 for (Size col{0}; col <
C; col++)
136template <
typename T, Size R, Size C>
139 static_assert(
R == 1,
"Dot Product expects two 1xN matrices");
153template <
typename T, Size R, Size C>
158 for (Size row{0}; row <
R; row++)
160 for (Size col{0}; col <
C; col++)
180 for (Size row{0}, col{0}; row <
S; row++, col++)
210template <
typename T, Size R, Size C>
215 for (Size row{0}; row <
R; row++)
217 for (Size col{0}; col <
C; col++)
234template <
typename T, Size R, Size C>
238 for (Size col{0}; col <
C; ++col)
241 for (Size row{0}; row <
R; ++row)
261template <
typename T, Size R, Size C>
265 for (Size row{0}; row <
R; ++row)
268 for (Size col{0}; col <
C; ++col)
290template <
typename T, Size R, Size C>
295 for (Size row{0}; row <
R; row++)
297 for (Size col{0}; col <
C; col++)
322template <
typename T, Size R, Size C>
325 static_assert(
R ==
C,
"Can only find determinant of a square matrix");
327 if constexpr (
R == 1)
331 else if constexpr (
R == 2)
333 return (
mat(0, 0) *
mat(1, 1)) - (
mat(0, 1) *
mat(1, 0));
338 for (Size col{0}; col <
R; col++)
341 for (Size row{1}; row <
R; row++)
354 T sign = (col % 2 == 0) ?
static_cast<T>(1) :
static_cast<T>(-1);
369template <
typename T, Size R, Size C>
372 static_assert(
R ==
C,
"Trace expects a square matrix");
393template <
typename T, Size N>
401 for (Size
k = 1u;
k <=
N; ++
k)
426template <
typename T, Size R, Size C>
Fixed-size matrix with compile-time dimensions.
Definition matrix.hpp:56
constexpr T sqrt(const T x)
Constexpr square root.
Definition sqrt.hpp:67
constexpr T abs(const T x)
Absolute value of a real number.
Definition abs.hpp:17
constexpr T epsilon()
Machine epsilon for type T.
Definition utilities.hpp:82
constexpr Matrix< T, S, S > diagonal(const T val)
Create an S×S matrix with val on the main diagonal and zeros elsewhere.
Definition operations.hpp:176
constexpr T determinant(const Matrix< T, R, C > &mat)
Determinant via Laplace (cofactor) expansion.
Definition operations.hpp:323
constexpr Matrix< T, S, S > eye()
Create an S×S identity matrix.
Definition operations.hpp:197
constexpr T norm1(const Matrix< T, R, C > &mat)
1-norm (maximum absolute column sum).
Definition operations.hpp:235
constexpr T norm(const Matrix< T, R, C > &mat)
Frobenius (Euclidean) norm: sqrt(sum of squared elements).
Definition operations.hpp:211
constexpr bool equalWithinMat(const Matrix< T, R, C > &a, const Matrix< T, R, C > &b, const T thresh)
Element-wise approximate equality within an absolute tolerance.
Definition operations.hpp:427
constexpr Matrix< T, C, R > transpose(const Matrix< T, R, C > &mat)
Matrix transpose.
Definition operations.hpp:154
constexpr Matrix< T, N+1u, 1u > char_poly(const Matrix< T, N, N > &A)
Monic characteristic polynomial via the Faddeev-LeVerrier algorithm.
Definition operations.hpp:394
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 T normInf(const Matrix< T, R, C > &mat)
Infinity-norm (maximum absolute row sum).
Definition operations.hpp:262