Linear Algebra
master
Accessible implementations of linear algebra algorithms
|
#include <linalg/RowPivotLU.hpp>
LU factorization with row pivoting.
Factorizes a square matrix into a lower triangular and an upper-triangular factor.
This version uses row pivoting, but it is not rank-revealing.
Definition at line 16 of file RowPivotLU.hpp.
Constructors | |
RowPivotLU ()=default | |
Default constructor. More... | |
RowPivotLU (const SquareMatrix &matrix) | |
Factorize the given matrix. More... | |
RowPivotLU (SquareMatrix &&matrix) | |
Factorize the given matrix. More... | |
Factorization | |
void | compute (SquareMatrix &&matrix) |
Perform the LU factorization of the given matrix. More... | |
void | compute (const SquareMatrix &matrix) |
Perform the LU factorization of the given matrix. More... | |
Retrieving the L factor | |
SquareMatrix && | steal_L () |
Get the lower-triangular matrix L, reusing the internal storage. More... | |
void | get_L_inplace (Matrix &L) const |
Copy the lower-triangular matrix L to the given matrix. More... | |
SquareMatrix | get_L () const & |
Get a copy of the lower-triangular matrix L. More... | |
SquareMatrix && | get_L () && |
Get the lower-triangular matrix L. More... | |
Retrieving the U factor | |
SquareMatrix && | steal_U () |
Get the upper-triangular matrix U, reusing the internal storage. More... | |
void | get_U_inplace (Matrix &U) const |
Copy the upper-triangular matrix U to the given matrix. More... | |
SquareMatrix | get_U () const & |
Get a copy of the upper-triangular matrix U. More... | |
SquareMatrix && | get_U () && |
Get the upper-triangular matrix U. More... | |
Retrieving the P factor | |
PermutationMatrix && | steal_P () |
Get the permutation matrix P, reusing the internal storage. More... | |
PermutationMatrix | get_P () const & |
Get a copy of the permutation matrix P. More... | |
PermutationMatrix && | get_P () && |
Get the permutation matrix P. More... | |
Solving systems of equations problems | |
void | solve_inplace (Matrix &B) const |
Solve the system AX = B or LUX = B. More... | |
Matrix | solve (const Matrix &B) const |
Solve the system AX = B or LUX = B. More... | |
Matrix && | solve (Matrix &&B) const |
Solve the system AX = B or LUX = B. More... | |
Vector | solve (const Vector &B) const |
Solve the system Ax = b or LUx = b. More... | |
Vector && | solve (Vector &&B) const |
Solve the system Ax = b or LUx = b. More... | |
Access to internal representation | |
bool | is_factored () const |
Check if this object contains a factorization. More... | |
bool | has_LU () const |
Check if this object contains valid L and U factors. More... | |
bool | has_P () const |
Check if this object contains a valid permutation matrix P. More... | |
SquareMatrix && | steal_LU () |
Get the internal storage of the upper-triangular matrix U and the strict lower-triangular part of matrix L. More... | |
const SquareMatrix & | get_LU () const & |
Get a copy of the internal storage of the upper-triangular matrix U and the strict lower-triangular part of matrix L. More... | |
SquareMatrix && | get_LU () && |
Get the internal storage of the upper-triangular matrix U and the strict lower-triangular part of matrix L. More... | |
Private Types | |
enum | State { NotFactored = 0 , Factored = 1 } |
Private Member Functions | |
void | compute_factorization () |
The actual LU factorization algorithm. More... | |
void | back_subs (const Matrix &B, Matrix &X) const |
Back substitution algorithm for solving upper-triangular systems UX = B. More... | |
void | forward_subs (const Matrix &B, Matrix &X) const |
Forward substitution algorithm for solving lower-triangular systems LX = B. More... | |
Private Attributes | |
SquareMatrix | LU |
Result of a LU factorization: stores the upper-triangular matrix U and the strict lower-triangular part of matrix L. More... | |
PermutationMatrix | P = PermutationMatrix::RowPermutation |
The permutation of A that maximizes pivot size. More... | |
enum RowPivotLU::State | state = NotFactored |
bool | valid_LU = false |
bool | valid_P = false |
Related Functions | |
(Note that these are not member functions.) | |
std::ostream & | operator<< (std::ostream &os, const RowPivotLU &lu) |
Print the L and U matrices of an LU object. More... | |
|
private |
Enumerator | |
---|---|
NotFactored | |
Factored |
Definition at line 163 of file RowPivotLU.hpp.
|
default |
Default constructor.
|
inline |
Factorize the given matrix.
Definition at line 24 of file RowPivotLU.hpp.
|
inline |
Factorize the given matrix.
Definition at line 26 of file RowPivotLU.hpp.
void compute | ( | SquareMatrix && | matrix | ) |
Perform the LU factorization of the given matrix.
Definition at line 7 of file RowPivotLU.ipp.
void compute | ( | const SquareMatrix & | matrix | ) |
Perform the LU factorization of the given matrix.
Definition at line 14 of file RowPivotLU.ipp.
SquareMatrix && steal_L | ( | ) |
Get the lower-triangular matrix L, reusing the internal storage.
Definition at line 21 of file RowPivotLU.ipp.
void get_L_inplace | ( | Matrix & | L | ) | const |
Copy the lower-triangular matrix L to the given matrix.
Definition at line 36 of file RowPivotLU.ipp.
SquareMatrix get_L | ( | ) | const & |
Get a copy of the lower-triangular matrix L.
Definition at line 52 of file RowPivotLU.ipp.
|
inline |
Get the lower-triangular matrix L.
Definition at line 57 of file RowPivotLU.hpp.
SquareMatrix && steal_U | ( | ) |
Get the upper-triangular matrix U, reusing the internal storage.
Definition at line 58 of file RowPivotLU.ipp.
void get_U_inplace | ( | Matrix & | U | ) | const |
Copy the upper-triangular matrix U to the given matrix.
Definition at line 71 of file RowPivotLU.ipp.
SquareMatrix get_U | ( | ) | const & |
Get a copy of the upper-triangular matrix U.
Definition at line 85 of file RowPivotLU.ipp.
|
inline |
Get the upper-triangular matrix U.
Definition at line 77 of file RowPivotLU.hpp.
PermutationMatrix && steal_P | ( | ) |
Get the permutation matrix P, reusing the internal storage.
Definition at line 91 of file RowPivotLU.ipp.
|
inline |
Get a copy of the permutation matrix P.
Definition at line 92 of file RowPivotLU.hpp.
|
inline |
Get the permutation matrix P.
Definition at line 94 of file RowPivotLU.hpp.
void solve_inplace | ( | Matrix & | B | ) | const |
Solve the system AX = B or LUX = B.
Matrix B is overwritten with the result X.
Definition at line 214 of file RowPivotLU.cpp.
Solve the system AX = B or LUX = B.
Definition at line 103 of file RowPivotLU.ipp.
Solve the system AX = B or LUX = B.
Definition at line 109 of file RowPivotLU.ipp.
Solve the system Ax = b or LUx = b.
Definition at line 114 of file RowPivotLU.ipp.
Solve the system Ax = b or LUx = b.
Definition at line 118 of file RowPivotLU.ipp.
|
inline |
Check if this object contains a factorization.
Definition at line 121 of file RowPivotLU.hpp.
|
inline |
Check if this object contains valid L and U factors.
Definition at line 124 of file RowPivotLU.hpp.
|
inline |
Check if this object contains a valid permutation matrix P.
Definition at line 127 of file RowPivotLU.hpp.
SquareMatrix && steal_LU | ( | ) |
Get the internal storage of the upper-triangular matrix U and the strict lower-triangular part of matrix L.
Definition at line 97 of file RowPivotLU.ipp.
|
inline |
Get a copy of the internal storage of the upper-triangular matrix U and the strict lower-triangular part of matrix L.
Definition at line 139 of file RowPivotLU.hpp.
|
inline |
Get the internal storage of the upper-triangular matrix U and the strict lower-triangular part of matrix L.
Definition at line 142 of file RowPivotLU.hpp.
|
private |
The actual LU factorization algorithm.
LU
contains the matrix A to be factorized P
contains the identity matrix (no permutations) LU.rows() == LU.cols()
P.size() == LU.rows()
LU
contains the full upper-triangular matrix U and the strict lower-triangular part of matrix L. The diagonal elements of L are implicitly 1. get_L() * get_U() == get_P() * A
(up to rounding errors)Definition at line 25 of file RowPivotLU.cpp.
Back substitution algorithm for solving upper-triangular systems UX = B.
Definition at line 149 of file RowPivotLU.cpp.
Forward substitution algorithm for solving lower-triangular systems LX = B.
Definition at line 181 of file RowPivotLU.cpp.
|
related |
Print the L and U matrices of an LU object.
Definition at line 125 of file RowPivotLU.ipp.
|
private |
Result of a LU factorization: stores the upper-triangular matrix U and the strict lower-triangular part of matrix L.
The diagonal elements of L are implicitly 1.
Definition at line 159 of file RowPivotLU.hpp.
|
private |
The permutation of A that maximizes pivot size.
Definition at line 161 of file RowPivotLU.hpp.
|
private |
|
private |
Definition at line 168 of file RowPivotLU.hpp.
|
private |
Definition at line 169 of file RowPivotLU.hpp.