12#include "backends/seq/impl.hpp"
13#include "backends/lapack/impl.hpp"
34 for (
idx k = 0; k < n; ++k)
36 std::swap(y[k], y[f.
piv[k]]);
38 for (
idx i = 1; i < n; ++i)
39 for (
idx j = 0; j < i; ++j)
40 y[i] -= M(i, j) * y[j];
42 for (
idx i = n; i-- > 0;) {
43 for (
idx j = i + 1; j < n; ++j)
44 y[i] -= M(i, j) * y[j];
55 for (
idx j = 0; j < nrhs; ++j) {
56 for (
idx i = 0; i < n; ++i)
59 for (
idx i = 0; i < n; ++i)
69 for (
idx i = 0; i < n; ++i)
72 for (
idx k = 0; k < n; ++k)
75 return (swaps % 2 == 0) ? det : -det;
84 for (
idx j = 0; j < n; ++j) {
87 for (
idx i = 0; i < n; ++i)
Dense row-major matrix with optional GPU storage.
constexpr idx rows() const noexcept
constexpr idx cols() const noexcept
LU factorization with partial pivoting.
LUResult lu(const Matrix &A)
LUResult lu(const Matrix &A)
Backend
Selects which backend handles a linalg operation.
@ lapack
LAPACKE – industry-standard factorizations, SVD, eigen.
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.
LUResult lu(const Matrix &A, Backend backend=lapack_backend)
LU factorization of a square matrix A with partial pivoting.
Result of an LU factorization with partial pivoting (PA = LU)