1#ifndef FUSED_ALGORITHMS_CHOLESKY_H
2#define FUSED_ALGORITHMS_CHOLESKY_H
86 template <
typename MatrixType>
91 static_assert(is_floating_point_v<typename MatrixType::value_type>,
92 "Cholesky requires a floating-point scalar type");
100 for (
my_size_t i = 0; i < A.getDim(0); ++i)
104 typename MatrixType::value_type
sum = 0;
108 sum += L(i, k) * L(j, k);
113 typename MatrixType::value_type diag = A(i, i) -
sum;
117 return Unexpected{MatrixStatus::NotPositiveDefinite};
124 L(i, j) = (A(i, j) -
sum) / L(j, j);
143 template <
typename MatrixType>
148 if (!result.has_value())
153 return move(result.value());
static void error(const T &msg)
Definition error_handler.h:30
A discriminated union holding either a success value or an error.
Definition expected.h:86
Global configuration for the tesseract tensor library.
#define my_size_t
Size/index type used throughout the library.
Definition config.h:126
#define PRECISION_TOLERANCE
Tolerance for floating-point comparisons (e.g. symmetry checks, Cholesky).
Definition config.h:117
A minimal, STL-free expected/result type for failable operations.
Runtime property descriptors and error codes for matrices.
constexpr T sqrt(T x) noexcept
Compute the square root of a floating-point value.
Definition math_utils.h:29
Expected< MatrixType, MatrixStatus > cholesky(const MatrixType &A, typename MatrixType::value_type tol=typename MatrixType::value_type(PRECISION_TOLERANCE))
Compute the Cholesky decomposition of a symmetric positive-definite matrix.
Definition cholesky.h:87
MatrixType cholesky_or_die(const MatrixType &A)
Cholesky decomposition — abort on failure.
Definition cholesky.h:144
MatrixStatus
Error codes for matrix decomposition and solver algorithms.
Definition matrix_traits.h:33
Expr::value_type sum(const BaseExpr< Expr > &expr)
Definition reductions.h:30
constexpr remove_reference_t< T > && move(T &&t) noexcept
Cast to rvalue reference (replacement for std::move).
Definition simple_type_traits.h:178
Tag type for constructing an Expected in the error state.
Definition expected.h:30