|
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 <decomposition.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. | |
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 2554 of file decomposition.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 2563 of file decomposition.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 2575 of file decomposition.hpp.
Q, moved out of an expiring decomposition (r stays).
Definition at line 2594 of file decomposition.hpp.
The factor Q (orthonormal columns): m × k, k = min(m, n), or m × m complete.
Definition at line 2588 of file decomposition.hpp.
R, moved out of an expiring decomposition (q stays).
Definition at line 2606 of file decomposition.hpp.
The upper-trapezoidal factor R: k × n, k = min(m, n), or m × n complete.
Definition at line 2600 of file decomposition.hpp.
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 2620 of file decomposition.hpp.
|
private |
The number of columns (n).
Definition at line 2658 of file decomposition.hpp.
|
private |
min(m, n).
Definition at line 2659 of file decomposition.hpp.
The factor Q, row-major, m × width_.
Definition at line 2661 of file decomposition.hpp.
The upper-trapezoidal factor R, row-major, width_ × n.
Definition at line 2662 of file decomposition.hpp.
|
private |
The number of rows (m).
Definition at line 2657 of file decomposition.hpp.
|
private |
Q's columns and R's rows: k, or m complete.
Definition at line 2660 of file decomposition.hpp.