akreon-linalg
Fixed-size linear algebra and numerical methods in C++26.
Loading...
Searching...
No Matches
linalg::QR< Mat > Struct Template Reference

Factors A = Q R using Householder reflections. More...

#include <qr.hpp>

Public Types

using T = matrix_scalar_t< Mat >
 
using ScalarT = real_type_t< T >
 

Public Member Functions

constexpr QR (const Mat &A)
 Factor A using Householder reflections.
 
constexpr QR (const Mat &A, const config::FactorConfig< ScalarT > &config_in)
 Factor A with an explicit solve configuration.
 
constexpr auto Q () const
 Reconstruct the full orthogonal or unitary factor.
 
constexpr auto R () const
 Extract the upper-trapezoidal factor.
 
constexpr auto rank (ScalarT tol=1e-6) const
 Estimate rank from the diagonal of R.
 
constexpr auto solve (const Vector< T, Rows > &b) const
 Solve A x = b in the least-squares sense.
 

Static Public Attributes

static constexpr std::size_t Rows = mat_rows_v<Mat>
 
static constexpr std::size_t Cols = mat_cols_v<Mat>
 

Detailed Description

template<MatrixContainer Mat>
struct linalg::QR< Mat >

Factors A = Q R using Householder reflections.

Successive reflections eliminate each column below its diagonal. The upper triangle stores R; reflector tails and coefficients reconstruct the full orthogonal or unitary Q. For wide matrices, factor A^* to obtain an LQ form.

Template Parameters
MatInput matrix type with at least as many rows as columns.

Definition at line 24 of file qr.hpp.

Member Typedef Documentation

◆ ScalarT

template<MatrixContainer Mat>
using linalg::QR< Mat >::ScalarT = real_type_t<T>

Definition at line 27 of file qr.hpp.

◆ T

template<MatrixContainer Mat>
using linalg::QR< Mat >::T = matrix_scalar_t<Mat>

Definition at line 26 of file qr.hpp.

Constructor & Destructor Documentation

◆ QR() [1/2]

template<MatrixContainer Mat>
constexpr linalg::QR< Mat >::QR ( const Mat &  A)
inlineconstexpr

Factor A using Householder reflections.

Parameters
[in]AInput matrix with Rows >= Cols.

Definition at line 41 of file qr.hpp.

References linalg::mat_rows_v.

◆ QR() [2/2]

template<MatrixContainer Mat>
constexpr linalg::QR< Mat >::QR ( const Mat &  A,
const config::FactorConfig< ScalarT > &  config_in 
)
inlineconstexpr

Factor A with an explicit solve configuration.

Parameters
[in]AInput matrix with Rows >= Cols.
[in]config_inFactorization settings and triangular pivot floor.

Definition at line 49 of file qr.hpp.

References linalg::mat_rows_v.

Member Function Documentation

◆ Q()

template<MatrixContainer Mat>
constexpr auto linalg::QR< Mat >::Q ( ) const
inlineconstexpr

Reconstruct the full orthogonal or unitary factor.

Returns
Matrix<T, Rows, Rows> containing Q in A = Q R.

Definition at line 59 of file qr.hpp.

Referenced by linalg::QR< Mat >::solve().

◆ R()

template<MatrixContainer Mat>
constexpr auto linalg::QR< Mat >::R ( ) const
inlineconstexpr

Extract the upper-trapezoidal factor.

Returns
Matrix<T, Rows, Cols> containing R in A = Q R.

Definition at line 66 of file qr.hpp.

References linalg::get_upper_right_triangular_matrix().

Referenced by linalg::QR< Mat >::rank(), and linalg::QR< Mat >::solve().

◆ rank()

template<MatrixContainer Mat>
constexpr auto linalg::QR< Mat >::rank ( ScalarT  tol = 1e-6) const
inlineconstexpr

Estimate rank from the diagonal of R.

Parameters
[in]tolAbsolute threshold for counting nonzero diagonal entries.
Returns
Number of diagonal magnitudes greater than tol (std::size_t).

Definition at line 74 of file qr.hpp.

References linalg::QR< Mat >::Cols, linalg::mat_rows_v, linalg::QR< Mat >::R(), linalg::QR< Mat >::rank(), and linalg::QR< Mat >::Rows.

Referenced by linalg::QR< Mat >::rank().

◆ solve()

template<MatrixContainer Mat>
constexpr auto linalg::QR< Mat >::solve ( const Vector< T, Rows > &  b) const
inlineconstexpr

Solve A x = b in the least-squares sense.

Project c = Q^* b, then back-substitute through the leading block of R.

Parameters
[in]bRight-hand side with Rows entries.
Returns
Tuple (Vector<T, Cols> x, NumericalEvent event).

Definition at line 91 of file qr.hpp.

References linalg::conjugate_transpose(), linalg::mat_rows_v, linalg::QR< Mat >::Q(), linalg::QR< Mat >::R(), and linalg::transpose().

Member Data Documentation

◆ Cols

template<MatrixContainer Mat>
constexpr std::size_t linalg::QR< Mat >::Cols = mat_cols_v<Mat>
staticconstexpr

Definition at line 31 of file qr.hpp.

Referenced by linalg::QR< Mat >::rank().

◆ Rows

template<MatrixContainer Mat>
constexpr std::size_t linalg::QR< Mat >::Rows = mat_rows_v<Mat>
staticconstexpr

Definition at line 30 of file qr.hpp.

Referenced by linalg::QR< Mat >::rank().


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