23template <MatrixContainer Mat>
34 "QR Factorization requires [square | overdetermined] system");
41 constexpr QR(
const Mat&
A) { solve_householder(
A); }
59 constexpr auto Q()
const {
return get_unitary_matrix(); }
78 for (std::size_t
i = 0;
i <
mn; ++
i)
100 return back_solve(
LT, c);
109 constexpr void solve_householder(Mat
A) {
112 std::integral_constant<std::size_t, j>) {
127 for (std::size_t
k =
j,
a = 0;
k <
Rows; ++
k, ++
a)
128 for (std::size_t
l =
j,
b = 0;
l <
Cols; ++
l, ++
b)
132 for (std::size_t
k =
j + 1,
a = 1;
k <
Rows; ++
k, ++
a) H(
k,
j) = v(
a, 0);
141 constexpr auto get_unitary_matrix()
const {
144 std::integral_constant<std::size_t, jj>) {
145 const std::size_t
j =
Cols -
jj - 1;
148 for (std::size_t
i =
j + 1,
a = 1;
i <
Rows; ++
i, ++
a) v(
a) = H(
i,
j);
158 for (std::size_t
r =
j,
a = 0;
r <
Rows; ++
r, ++
a)
159 for (std::size_t c = 0; c <
Rows; ++c) U(
r, c) =
Q_block(
a, c);
172 const Vector<T, Rows>&
rhs)
const {
176 for (
int i =
static_cast<int>(
mn) - 1;
i >= 0; --
i) {
181 "QR back_solve requires non-zero diagonal in R");
192 return std::tuple{x,
event};
197 Vector<T, Rows> beta;
Field classified by scalar_traits as complex.
typename scalar_traits_t< T >::real_type real_type_t
Associated real component type registered for T.
constexpr auto conjugate_transpose(const Mat &A)
conjugate transpose of a matrix
Vector(T, Ts...) -> Vector< std::common_type_t< T, Ts... >, 1+sizeof...(Ts)>
Deduce coordinate type and dimension from constructor arguments.
constexpr auto transpose(const Vec &x)
tranpose of a vector
constexpr T constexpr_abs(T x)
Compute real absolute value or complex magnitude.
constexpr std::size_t mat_rows_v
Registered compile-time row count after cv/ref normalization.
constexpr auto get_col(const Mat &A, std::size_t idx)
get the column of matrix A based on given index
NumericalEvent
NumericalEvent.
@ NEAR_SINGULAR_TRIANGULAR_SOLVE
typename mat_traits< remove_cvref_t< Mat > >::value_type matrix_scalar_t
Registered matrix scalar type after cv/ref normalization.
constexpr auto as_col_vector(const Vec &X)
express the vector X as a column vector (N x 1)
constexpr auto get_upper_right_triangular_matrix(const Mat &A)
get upper right triangular matrix from A
Configuration for generic numerical factorizations.
Compact representation of a real or complex Householder reflector.
forward declaration for L2 norm
Factors A = Q R using Householder reflections.
constexpr auto R() const
Extract the upper-trapezoidal factor.
constexpr auto Q() const
Reconstruct the full orthogonal or unitary factor.
constexpr QR(const Mat &A, const config::FactorConfig< ScalarT > &config_in)
Factor A with an explicit solve configuration.
constexpr QR(const Mat &A)
Factor A using Householder reflections.
static constexpr std::size_t Rows
constexpr auto solve(const Vector< T, Rows > &b) const
Solve A x = b in the least-squares sense.
static constexpr std::size_t Cols
constexpr auto rank(ScalarT tol=1e-6) const
Estimate rank from the diagonal of R.
Owning, fixed-size vector container.