8 RW = std::move(matrix);
45 for (
size_t r = 0; r < R.
cols(); ++r) {
46 for (
size_t c = 0; c < r; ++c)
49 for (
size_t c = r + 1; c < R.
cols(); ++c)
52 for (
size_t r = R.
cols(); r < R.
rows(); ++r) {
53 for (
size_t c = 0; c < R.
cols(); ++c)
66 for (
size_t r = 0; r <
RW.
cols(); ++r) {
67 for (
size_t c = 0; c < r; ++c)
72 for (
size_t c = 0; c <
RW.
cols(); ++c)
116 os <<
"Not factored." << std::endl;
121 os <<
"Q = " << std::endl;
125 int w = os.precision() + 9;
127 const auto &RW = qr.
get_RW();
129 os <<
"R = " << std::endl;
130 for (
size_t r = 0; r < RW.cols(); ++r) {
131 for (
size_t c = 0; c < r; ++c)
132 os << std::setw(w) << 0;
133 os << std::setw(w) << R_diag(r);
134 for (
size_t c = r + 1; c < RW.cols(); ++c)
135 os << std::setw(w) << RW(r, c);
138 for (
size_t r = RW.cols(); r < RW.rows(); ++r) {
139 for (
size_t c = 0; c < RW.cols(); ++c)
140 os << std::setw(w) << 0;
QR factorization using Householder reflectors.
Vector R_diag
Contains the diagonal elements of R.
std::ostream & operator<<(std::ostream &os, const HouseholderQR &qr)
Print the Q and R matrices of a HouseholderQR object.
void apply_QT_inplace(Matrix &B) const
Compute the product QᵀB, overwriting B with the result.
void get_Q_inplace(SquareMatrix &Q) const
Compute the unitary matrix Q and copy it to the given matrix.
Matrix solve(const Matrix &B) const
Solve the system AX = B or QRX = B.
Matrix apply_Q(const Matrix &X) const
Compute the product QB.
Matrix get_R() const &
Get a copy of the upper-triangular matrix R.
const Vector & get_R_diag() const &
Get the internal storage of the diagonal elements of R.
Matrix && steal_R()
Get the upper-triangular matrix R, reusing the internal storage.
enum HouseholderQR::State state
void back_subs(const Matrix &B, Matrix &X) const
Back substitution algorithm for solving upper-triangular systems RX = B.
Matrix RW
Result of a Householder QR factorization: stores the strict upper-triangular part of matrix R and the...
Matrix apply_QT(const Matrix &B) const
Compute the product QᵀB.
void solve_inplace(Matrix &B) const
Solve the system AX = B or QRX = B.
bool is_factored() const
Check if this object contains a valid factorization.
void compute_factorization()
The actual QR factorization algorithm.
SquareMatrix get_Q() const
Compute the unitary matrix Q.
const Matrix & get_RW() const &
Get the internal storage of the strict upper-triangular part of R and the Householder reflector vecto...
void compute(Matrix &&matrix)
Perform the QR factorization of the given matrix.
void get_R_inplace(Matrix &R) const
Copy the upper-triangular matrix R to the given matrix.
void apply_Q_inplace(Matrix &X) const
Compute the product QB, overwriting B with the result.
size_t rows() const
Get the number of rows of the matrix.
void fill_identity()
Fill the matrix as an identity matrix (all zeros except the diagonal which is one).
size_t cols() const
Get the number of columns of the matrix.
void print(std::ostream &os, uint8_t precision=0, uint8_t width=0) const
Print a matrix.
A column vector (n×1 matrix).
void resize(size_t size)
Resize the vector.