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

#include <gpr/linalg/CusolverInverse.h>

Inheritance diagram for gpr::linalg::CusolverInverse:

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 30 of file CusolverInverse.h.

Member Function Documentation

◆ factorise()

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

Factor K = L L^T via the compiled backend's cholesky(). Returns true on success, false if K is not numerically PD (the backend cholesky returned false); the caller decides how to react. Each subsequent op requires a successful factorise or throws std::logic_error.

Definition at line 12 of file CusolverInverse.cpp.

13{
14 factored_ = cholesky(K, L_);
15 return factored_;
16}
bool cholesky(const EigenMatrix &C, EigenMatrix &L)
Cholesky decomposition (LAPACK equivalent: dpotrf).

◆ kind()

Kind gpr::linalg::CusolverInverse::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 39 of file CusolverInverse.h.

◆ log_det()

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

Returns the log determinant of K.

Implements gpr::linalg::KernelInverse.

Definition at line 37 of file CusolverInverse.cpp.

38{
39 if (!factored_) {
40 throw std::logic_error(
41 "CusolverInverse: log_det called before factorise");
42 }
43 // log|K| = 2 sum_i log L_ii; log_det_cholesky returns sum_i log L_ii.
44 return 2.0 * log_det_cholesky(L_);
45}
double log_det_cholesky(const EigenMatrix &L)
Half log-determinant from Cholesky factor.

◆ solve()

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

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

Implements gpr::linalg::KernelInverse.

Definition at line 18 of file CusolverInverse.cpp.

19{
20 if (!factored_) {
21 throw std::logic_error(
22 "CusolverInverse: solve called before factorise");
23 }
24 // K x = b with K = L L^T: L y = b (forward), L^T x = y (back).
25 return back_solve(L_, forward_solve(L_, b));
26}
Eigen::VectorXd forward_solve(const EigenMatrix &L, const Eigen::VectorXd &b)
Forward triangular solve with vector RHS (BLAS equivalent: dtrsv).
Eigen::VectorXd back_solve(const EigenMatrix &L, const Eigen::VectorXd &b)
Back triangular solve with vector RHS (BLAS equivalent: dtrsv).

◆ solve_mat()

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

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

Implements gpr::linalg::KernelInverse.

Definition at line 28 of file CusolverInverse.cpp.

29{
30 if (!factored_) {
31 throw std::logic_error(
32 "CusolverInverse: solve_mat called before factorise");
33 }
34 return back_solve_mat(L_, forward_solve_mat(L_, B));
35}
EigenMatrix back_solve_mat(const EigenMatrix &L, const EigenMatrix &B)
Back triangular solve with matrix RHS (BLAS equivalent: dtrsm with side=L, uplo=L,...
EigenMatrix forward_solve_mat(const EigenMatrix &L, const EigenMatrix &B)
Forward triangular solve with matrix RHS (BLAS equivalent: dtrsm).

◆ trace_inv_times()

double gpr::linalg::CusolverInverse::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 47 of file CusolverInverse.cpp.

48{
49 if (!factored_) {
50 throw std::logic_error(
51 "CusolverInverse: trace_inv_times called before factorise");
52 }
53 // tr(K^{-1} A) = tr(L^{-T} L^{-1} A). Solve K Z = A column-wise, sum
54 // the diagonal -- avoids forming K^{-1} explicitly, matching the
55 // DenseLLTInverse contract (A treated as general dense).
56 return solve_mat(A).trace();
57}
EigenMatrix solve_mat(const EigenMatrix &B) const override
Solve K X = B for a multi right-hand side.

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