|
NumericAL
A header-only C++20 lexer built on REAL
|
A QR factorisation A = Q R of an m × n matrix, as NumPy's qr, reduced by default.
More...
#include <factorizations.hpp>
Public Member Functions | |
| qr_decomposition (const matrix< T > &a, qr_mode mode=qr_mode::reduced) | |
Factorises a. | |
| qr_decomposition (matrix< T > &&a, qr_mode mode=qr_mode::reduced) | |
Factorises a in its own storage, an expiring matrix's elements taken over: no copy of them. | |
| matrix< T > | q () const & |
The factor Q (orthonormal columns): m × k, k = min(m, n), or m × m complete. | |
| matrix< T > | q () && |
Q, moved out of an expiring decomposition (r stays). | |
| matrix< T > | r () const & |
The upper-trapezoidal factor R: k × n, k = min(m, n), or m × n complete. | |
| matrix< T > | r () && |
R, moved out of an expiring decomposition (q stays). | |
| vector< T > | solve (const vector< T > &b) const |
The least-squares solution of A x ≈ b (x = R⁻¹ Qᴴ b) for a full-rank A. | |
| matrix< T > | solve (const matrix< T > &b) const |
The least-squares solutions of A X ≈ B (X = R⁻¹ Qᴴ B) for a full-rank A, every column of b at once: Qᴴ B through the matrix product kernel, then the back substitution by rows of R over all the columns (each column solve's to rounding: the product sums its terms in another order). | |
Private Attributes | |
| std::size_t | rows_ |
| The number of rows (m). | |
| std::size_t | cols_ |
| The number of columns (n). | |
| std::size_t | depth_ |
| min(m, n). | |
| std::size_t | width_ |
| Q's columns and R's rows: k, or m complete. | |
| buffer< T > | q_ |
| The factor Q, row-major, m × width_. | |
| buffer< T > | r_ |
| The upper-trapezoidal factor R, row-major, width_ × n. | |
A QR factorisation A = Q R of an m × n matrix, as NumPy's qr, reduced by default.
| T | The scalar element type (a field: double, std::complex<double>, …). |
With k = min(m, n), Q is m × k with orthonormal columns (Qᴴ Q = I) and R is k × n upper trapezoidal (triangular when m ≥ n) with a real, non-negative diagonal; complete (qr_mode::complete), Q is m × m and R m × n, its rows past k zero. Computed by Householder reflections, so Q stays orthonormal to rounding however ill-conditioned A is, and a rank-deficient A factorises too (with zeros on R's diagonal). solve returns the least-squares solution of A x ≈ b for a full-column-rank A (m ≥ n); for a rank-deficient or wide one, numerical::lstsq gives the minimum-norm solution.
Definition at line 3798 of file factorizations.hpp.
|
inlineexplicit |
Factorises a.
| [in] | a | The matrix, any shape. |
| [in] | mode | qr_mode::reduced (Q m × k) or qr_mode::complete (Q m × m). |
| non_finite_error | If an entry is infinite or NaN. |
Definition at line 3807 of file factorizations.hpp.
|
inlineexplicit |
Factorises a in its own storage, an expiring matrix's elements taken over: no copy of them.
| [in] | a | The matrix, any shape. |
| [in] | mode | qr_mode::reduced (Q m × k) or qr_mode::complete (Q m × m). |
| non_finite_error | If an entry is infinite or NaN. |
Definition at line 3819 of file factorizations.hpp.
|
inline |
Q, moved out of an expiring decomposition (r stays).
Definition at line 3838 of file factorizations.hpp.
|
inline |
The factor Q (orthonormal columns): m × k, k = min(m, n), or m × m complete.
Definition at line 3832 of file factorizations.hpp.
|
inline |
R, moved out of an expiring decomposition (q stays).
Definition at line 3850 of file factorizations.hpp.
|
inline |
The upper-trapezoidal factor R: k × n, k = min(m, n), or m × n complete.
Definition at line 3844 of file factorizations.hpp.
|
inline |
The least-squares solutions of A X ≈ B (X = R⁻¹ Qᴴ B) for a full-rank A, every column of b at once: Qᴴ B through the matrix product kernel, then the back substitution by rows of R over all the columns (each column solve's to rounding: the product sums its terms in another order).
| [in] | b | The right-hand sides (m × k). |
X (n × k). | dimension_error | If b's row count differs from the matrix's, or A is wide (as solve). |
| singular_matrix_error | If A is rank-deficient (as solve). |
Definition at line 3908 of file factorizations.hpp.
|
inline |
The least-squares solution of A x ≈ b (x = R⁻¹ Qᴴ b) for a full-rank A.
| [in] | b | The right-hand side (size m). |
x (size n). | dimension_error | If b's size differs from the row count, or A is wide (m < n: its system is underdetermined, and numerical::lstsq gives its minimum-norm solution). |
| singular_matrix_error | If A is rank-deficient: a diagonal entry of R is under detail::rank_tolerance (numerical::lstsq solves such a system). |
Definition at line 3864 of file factorizations.hpp.
|
private |
The number of columns (n).
Definition at line 3954 of file factorizations.hpp.
|
private |
min(m, n).
Definition at line 3955 of file factorizations.hpp.
|
private |
The factor Q, row-major, m × width_.
Definition at line 3957 of file factorizations.hpp.
|
private |
The upper-trapezoidal factor R, row-major, width_ × n.
Definition at line 3958 of file factorizations.hpp.
|
private |
The number of rows (m).
Definition at line 3953 of file factorizations.hpp.
|
private |
Q's columns and R's rows: k, or m complete.
Definition at line 3956 of file factorizations.hpp.