Loading...
Searching...
No Matches
gpr::linalg::DenseLLTInverse Class Referencefinal

#include <gpr/linalg/DenseLLTInverse.h>

Inheritance diagram for gpr::linalg::DenseLLTInverse:

Public Member Functions

bool factorise (const EigenMatrix &K)
Kind kind () const noexcept override
Eigen::VectorXd solve (const Eigen::VectorXd &b) const override
 Solve K x = b for a single right-hand side.
EigenMatrix solve_mat (const EigenMatrix &B) const override
 Solve K X = B for a multi right-hand side.
double log_det () const override
 Returns the log determinant of K.
double trace_inv_times (const EigenMatrix &A) const override
Public Member Functions inherited from gpr::linalg::KernelInverse
virtual ~KernelInverse ()=default

Additional Inherited Members

Public Types inherited from gpr::linalg::KernelInverse
enum class  Kind { RankLocal , Distributed }

Detailed Description

Definition at line 24 of file DenseLLTInverse.h.

Member Function Documentation

◆ factorise()

bool gpr::linalg::DenseLLTInverse::factorise ( const EigenMatrix & K)
nodiscard

Factor K via Eigen LLT. Returns true on success, false if the decomposition reports NumericalIssue (i.e. K is not numerically PD); the caller decides how to react. Each subsequent solve / solve_mat / log_det / trace_inv_times call requires a successful factorise; otherwise the op throws std::logic_error.

Definition at line 19 of file DenseLLTInverse.cpp.

20{
21 [[maybe_unused]] const SerialEigenFactor serial_factor;
22 llt_.compute(K);
23 factored_ = (llt_.info() == Eigen::Success);
24 return factored_;
25}

◆ kind()

Kind gpr::linalg::DenseLLTInverse::kind ( ) const
inlinenodiscardoverridevirtualnoexcept

Reports whether the operator parallelises internally (Distributed) or is rank-local (RankLocal). Used by ProbeExecutor to choose the dispatch strategy.

Implements gpr::linalg::KernelInverse.

Definition at line 33 of file DenseLLTInverse.h.

◆ log_det()

double gpr::linalg::DenseLLTInverse::log_det ( ) const
nodiscardoverridevirtual

Returns the log determinant of K.

Implements gpr::linalg::KernelInverse.

Definition at line 47 of file DenseLLTInverse.cpp.

48{
49 if (!factored_) {
50 throw std::logic_error(
51 "DenseLLTInverse: log_det called before factorise");
52 }
53 // log |K| = log |L L^T| = 2 sum_i log L_ii. matrixLLT() returns the
54 // packed in-place LLT storage (lower triangle holds L); .diagonal()
55 // is a non-allocating view of L's diagonal entries. Cost is O(n)
56 // reads, no allocation. Numerically identical to reading the
57 // diagonal of the materialised lower factor.
58 return 2.0 * llt_.matrixLLT().diagonal().array().log().sum();
59}

◆ solve()

Eigen::VectorXd gpr::linalg::DenseLLTInverse::solve ( const Eigen::VectorXd & b) const
nodiscardoverridevirtual

Solve K x = b for a single right-hand side.

Implements gpr::linalg::KernelInverse.

Definition at line 27 of file DenseLLTInverse.cpp.

28{
29 if (!factored_) {
30 throw std::logic_error(
31 "DenseLLTInverse: solve called before factorise");
32 }
33 [[maybe_unused]] const SerialEigenFactor serial_factor;
34 return llt_.solve(b);
35}

◆ solve_mat()

EigenMatrix gpr::linalg::DenseLLTInverse::solve_mat ( const EigenMatrix & B) const
nodiscardoverridevirtual

Solve K X = B for a multi right-hand side.

Implements gpr::linalg::KernelInverse.

Definition at line 37 of file DenseLLTInverse.cpp.

38{
39 if (!factored_) {
40 throw std::logic_error(
41 "DenseLLTInverse: solve_mat called before factorise");
42 }
43 [[maybe_unused]] const SerialEigenFactor serial_factor;
44 return llt_.solve(B);
45}

◆ trace_inv_times()

double gpr::linalg::DenseLLTInverse::trace_inv_times ( const EigenMatrix & A) const
nodiscardoverridevirtual

Returns tr(K^{-1} A). Implementations may exploit structure (e.g. ScaLAPACK's distributed dpotri) rather than materialising K^{-1} A.

Symmetry contract: A is treated as a general dense matrix; no symmetry of A is exploited by the base contract. Concrete implementations may relax this contract if their override docstring documents the additional assumption.

Implements gpr::linalg::KernelInverse.

Definition at line 61 of file DenseLLTInverse.cpp.

62{
63 if (!factored_) {
64 throw std::logic_error(
65 "DenseLLTInverse: trace_inv_times called before factorise");
66 }
67 // tr(K^{-1} A) = tr(L^{-T} L^{-1} A). Solve K Z = A then sum the
68 // diagonal of Z. The two-step trsm route avoids materialising
69 // K^{-1} explicitly, so the cost is one O(n^2) solve per RHS column
70 // times n columns = O(n^3) total -- same as forming K^{-1} A but
71 // without the upper-triangle pollution of dpotri.
72 [[maybe_unused]] const SerialEigenFactor serial_factor;
73 const EigenMatrix Z = llt_.solve(A);
74 return Z.trace();
75}
Eigen::Matrix< double, EigenDynamic, EigenDynamic, EigenMatrixStorage > EigenMatrix
Definition Macros.h:20

The documentation for this class was generated from the following files: