Linear Algebra  arduino
Accessible implementations of linear algebra algorithms
NoPivotLU.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include "Matrix.hpp"
4 
20 class NoPivotLU {
21  public:
24 
26  NoPivotLU() = default;
28  NoPivotLU(const SquareMatrix &matrix) { compute(matrix); }
30  NoPivotLU(SquareMatrix &&matrix) { compute(std::move(matrix)); }
31 
33 
34  public:
37 
39  void compute(SquareMatrix &&matrix);
41  void compute(const SquareMatrix &matrix);
42 
44 
45  public:
48 
53 
55  void get_L_inplace(Matrix &L) const;
57  SquareMatrix get_L() const &;
59  SquareMatrix &&get_L() && { return steal_L(); }
60 
62 
63  public:
66 
71 
73  void get_U_inplace(Matrix &U) const;
75  SquareMatrix get_U() const &;
77  SquareMatrix &&get_U() && { return steal_U(); }
78 
80 
81  public:
84 
87  void solve_inplace(Matrix &B) const;
89  Matrix solve(const Matrix &B) const;
91  Matrix &&solve(Matrix &&B) const;
93  Vector solve(const Vector &B) const;
95  Vector &&solve(Vector &&B) const;
96 
98 
99  public:
102 
104  bool is_factored() const { return state == Factored; }
105 
107  bool has_LU() const { return is_factored(); }
108 
114 
117  const SquareMatrix &get_LU() const & { return LU; }
120  SquareMatrix &&get_LU() && { return steal_LU(); }
121 
123 
124  private:
126  void compute_factorization();
128  void back_subs(const Matrix &B, Matrix &X) const;
131  void forward_subs(const Matrix &B, Matrix &X) const;
132 
133  private:
138 
139  enum State {
141  Factored = 1,
143 };
144 
147 std::ostream &operator<<(std::ostream &os, const NoPivotLU &lu);
std::ostream & operator<<(std::ostream &os, const HouseholderQR &qr)
Print the Q and R matrices of a HouseholderQR object.
General matrix class.
Definition: Matrix.hpp:34
LU factorization without pivoting.
Definition: NoPivotLU.hpp:20
SquareMatrix LU
Result of a LU factorization: stores the upper-triangular matrix U and the strict lower-triangular pa...
Definition: NoPivotLU.hpp:137
void get_U_inplace(Matrix &U) const
Copy the upper-triangular matrix U to the given matrix.
Definition: NoPivotLU.ipp:67
SquareMatrix && steal_LU()
Get the internal storage of the upper-triangular matrix U and the strict lower-triangular part of mat...
Definition: NoPivotLU.ipp:87
const SquareMatrix & get_LU() const &
Get a copy of the internal storage of the upper-triangular matrix U and the strict lower-triangular p...
Definition: NoPivotLU.hpp:117
NoPivotLU()=default
Default constructor.
bool has_LU() const
Check if this object contains valid L and U factors.
Definition: NoPivotLU.hpp:107
Matrix solve(const Matrix &B) const
Solve the system AX = B or LUX = B.
Definition: NoPivotLU.ipp:92
void get_L_inplace(Matrix &L) const
Copy the lower-triangular matrix L to the given matrix.
Definition: NoPivotLU.ipp:33
void compute(SquareMatrix &&matrix)
Perform the LU factorization of the given matrix.
Definition: NoPivotLU.ipp:9
SquareMatrix && steal_L()
Get the lower-triangular matrix L, reusing the internal storage.
Definition: NoPivotLU.ipp:19
void back_subs(const Matrix &B, Matrix &X) const
Back substitution algorithm for solving upper-triangular systems UX = B.
Definition: NoPivotLU.cpp:173
void solve_inplace(Matrix &B) const
Solve the system AX = B or LUX = B.
Definition: NoPivotLU.cpp:238
bool is_factored() const
Check if this object contains a factorization.
Definition: NoPivotLU.hpp:104
void forward_subs(const Matrix &B, Matrix &X) const
Forward substitution algorithm for solving lower-triangular systems LX = B.
Definition: NoPivotLU.cpp:205
void compute_factorization()
The actual LU factorization algorithm.
Definition: NoPivotLU.cpp:21
enum NoPivotLU::State state
SquareMatrix get_L() const &
Get a copy of the lower-triangular matrix L.
Definition: NoPivotLU.ipp:49
SquareMatrix get_U() const &
Get a copy of the upper-triangular matrix U.
Definition: NoPivotLU.ipp:81
SquareMatrix && get_LU() &&
Get the internal storage of the upper-triangular matrix U and the strict lower-triangular part of mat...
Definition: NoPivotLU.hpp:120
SquareMatrix && steal_U()
Get the upper-triangular matrix U, reusing the internal storage.
Definition: NoPivotLU.ipp:55
NoPivotLU(SquareMatrix &&matrix)
Factorize the given matrix.
Definition: NoPivotLU.hpp:30
NoPivotLU(const SquareMatrix &matrix)
Factorize the given matrix.
Definition: NoPivotLU.hpp:28
Square matrix class.
Definition: Matrix.hpp:572
A column vector (nĂ—1 matrix).
Definition: Matrix.hpp:278