23 const idx n =
A.rows();
31 for (
idx k = 0;
k < n; ++
k) {
35 for (
idx i =
k + 1;
i < n; ++
i) {
42 for (
idx j = 0;
j < n; ++
j)
43 std::swap(
M(
k,
j),
M(pivot_row,
j));
55 for (
idx i =
k + 1;
i < n; ++
i) {
68 const idx n =
f.LU.rows();
73 for (
idx k = 0;
k < n; ++
k)
75 std::swap(y[
k], y[
f.piv[
k]]);
77 for (
idx i = 1;
i < n; ++
i)
79 y[
i] -=
M(
i,
j) * y[
j];
81 for (
idx i = n;
i-- > 0; ) {
83 y[
i] -=
M(
i,
j) * y[
j];
92 const idx n =
B.rows();
112 for (
idx i = 0;
i < n; ++
i)
115 for (
idx k = 0;
k < n; ++
k)
126 for (
idx j = 0;
j < n; ++
j) {
Dense row-major matrix with optional GPU storage.
constexpr idx rows() const noexcept
LU factorization with partial pivoting.
LUResult lu(const Matrix &A)
LU factorization of a square matrix A with partial pivoting.
constexpr T ipow(T x) noexcept
Compute x^N at compile time via repeated squaring.
real lu_det(const LUResult &f)
Determinant of A from its LU factorization.
Matrix lu_inv(const LUResult &f)
Inverse of A from its LU factorization.
void lu_solve(const LUResult &f, const Vector &b, Vector &x)
Solve A*x = b using a precomputed LU factorization.
Result of an LU factorization with partial pivoting (PA = LU)