numerics 0.1.0
Loading...
Searching...
No Matches
lu.hpp
Go to the documentation of this file.
1/// @file lu.hpp
2/// @brief LU factorization with partial pivoting.
3#pragma once
4
5#include "core/matrix.hpp"
6#include "core/policy.hpp"
7#include <vector>
8
9namespace num {
10
11/// @brief Packed factorization \f$PA=LU\f$.
12struct LUResult {
14 std::vector<idx> piv;
15 bool singular = false;
16};
17
18LUResult lu(const Matrix& A, Backend backend = lapack_backend);
19
20/// @brief Solve \f$Ax=b\f$ from a precomputed \f$PA=LU\f$ factorization.
21void lu_solve(const LUResult& f, const Vector& b, Vector& x);
22
23/// @brief Solve \f$AX=B\f$ from a precomputed \f$PA=LU\f$ factorization.
24void lu_solve(const LUResult& f, const Matrix& B, Matrix& X);
25
26/// @brief Compute \f$\det(A)=\det(P)^{-1}\prod_i U_{ii}\f$.
27real lu_det(const LUResult& f);
28
29/// @brief Compute \f$A^{-1}\f$ by solving \f$AX=I\f$.
30Matrix lu_inv(const LUResult& f);
31
32} // namespace num
Backend enum and default backend selection.
Dense row-major matrix templated over scalar type T.
double real
Definition types.hpp:10
Backend
Definition policy.hpp:7
real lu_det(const LUResult &f)
Compute .
Definition lu.cpp:57
constexpr Backend lapack_backend
Definition policy.hpp:66
Matrix lu_inv(const LUResult &f)
Compute by solving .
Definition lu.cpp:71
void lu_solve(const LUResult &f, const Vector &b, Vector &x)
Solve from a precomputed factorization.
Definition lu.cpp:19
LUResult lu(const Matrix &A, Backend backend=lapack_backend)
Definition lu.cpp:10
Packed factorization .
Definition lu.hpp:12
Matrix LU
Definition lu.hpp:13
std::vector< idx > piv
Definition lu.hpp:14
bool singular
Definition lu.hpp:15