4#include "../../math/constmath.hpp"
5#include "../matrix.hpp"
6#include "../operations.hpp"
25template <
typename T, Size S>
struct QRMatrix
58template <
typename T, Size R, Size C>
61 static_assert(
R ==
C,
"QR decomposition must be a square matrix");
66 for (Size col = 0; col <
R - 1; ++col)
70 T y =
r(col + 1, col);
72 if (
abs(
y) >
static_cast<T>(1
e-15))
79 for (Size
k = col;
k <
R; ++
k)
88 for (Size row = 0; row <
R; ++row)
139template <
typename T, Size R, Size C>
142 static_assert(
R ==
C,
"QR decomposition must be a square matrix");
147 for (Size col = 0; col <
C; ++col)
149 for (Size row =
R - 1; row > col; --row)
152 T x =
r(row - 1, col);
155 if (
abs(
y) >
static_cast<T>(1
e-15))
158 if (
mag >
static_cast<T>(1
e-18))
165 for (Size
k = col;
k <
C; ++
k)
174 for (Size
k = 0;
k <
R; ++
k)
187 QRMatrix<T, R>
res{};
Fixed-size matrix with compile-time dimensions.
Definition matrix.hpp:56
constexpr QRMatrix< T, R > qr_hessenberg(const Matrix< T, R, C > a)
QR decomposition optimized for upper Hessenberg matrices.
Definition qr.hpp:59
constexpr QRMatrix< T, R > qr(const Matrix< T, R, C > a)
General QR decomposition using Givens rotations.
Definition qr.hpp:140
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