13 throw std::invalid_argument(
"cholesky: matrix must be square");
19 for (
idx i = 0; i < n; ++i) {
20 for (
idx j = 0; j <= i; ++j) {
22 for (
idx k = 0; k < j; ++k) {
23 sum -= L(i, k) * L(j, k);
28 return {std::move(L),
false};
30 L(i, j) = std::sqrt(sum);
32 L(i, j) = sum / L(j, j);
37 return {std::move(L),
true};
42 throw std::invalid_argument(
"cholesky_solve: factorization failed");
46 throw std::invalid_argument(
"cholesky_solve: dimension mismatch");
50 for (
idx i = 0; i < n; ++i) {
52 for (
idx k = 0; k < i; ++k) {
53 sum -= f.
L(i, k) * y[k];
55 y[i] = sum / f.
L(i, i);
58 for (
idx ii = n; ii > 0;) {
61 for (
idx k = ii + 1; k < n; ++k) {
62 sum -= f.
L(k, ii) * x[k];
64 x[ii] = sum / f.
L(ii, ii);
Dense Cholesky factorization for SPD matrices.
constexpr idx rows() const noexcept
constexpr idx cols() const noexcept
constexpr idx size() const noexcept
const Mat & base() const noexcept
CholeskyResult cholesky(const linalg::SPDMatrix< Matrix > &A)
void cholesky_solve(const CholeskyResult &f, const Vector &b, Vector &x)
Lower-triangular factorization .