29#ifndef GPR_LINALG_STDPARBACKEND_H_
30#define GPR_LINALG_STDPARBACKEND_H_
50 if (C.rows() != C.cols())
return false;
52 if (!scaling.compute(C.diagonal()))
return false;
53 const int n =
static_cast<int>(C.rows());
56 int info = LAPACKE_dpotrf(LAPACK_COL_MAJOR,
'L', n, factor.data(), n);
59 if (info != 0)
return false;
60 scaling.restoreFactor(factor);
61 L = std::move(factor);
63 for (
int j = 1; j < n; ++j)
64 for (
int i = 0; i < j; ++i)
70 const Eigen::VectorXd& b)
72 Eigen::VectorXd
x = b;
73 const int n =
static_cast<int>(L.rows());
75 cblas_dtrsv(CblasColMajor, CblasLower, CblasNoTrans, CblasNonUnit, n,
76 L.data(), n,
x.data(), 1);
81 const Eigen::VectorXd& b)
83 Eigen::VectorXd
x = b;
84 const int n =
static_cast<int>(L.rows());
86 cblas_dtrsv(CblasColMajor, CblasLower, CblasTrans, CblasNonUnit, n,
87 L.data(), n,
x.data(), 1);
94 const int m =
static_cast<int>(L.rows());
95 const int n =
static_cast<int>(B.cols());
97 cblas_dtrsm(CblasColMajor, CblasLeft, CblasLower, CblasNoTrans,
98 CblasNonUnit, m, n, 1.0, L.data(), m, X.data(), m);
105 const int m =
static_cast<int>(L.rows());
106 const int n =
static_cast<int>(B.cols());
108 cblas_dtrsm(CblasColMajor, CblasLeft, CblasLower, CblasTrans, CblasNonUnit,
109 m, n, 1.0, L.data(), m, X.data(), m);
117 return X.colwise().squaredNorm().transpose();
122 const Eigen::VectorXd& prior)
129 const int n =
static_cast<int>(L.rows());
133 int info = LAPACKE_dpotri(LAPACK_COL_MAJOR,
'L', n, invC.data(), n);
136 for (
int j = 0; j < n; ++j)
137 for (
int i = 0; i < j; ++i)
138 invC(i, j) = invC(j, i);
144 const auto n =
static_cast<std::size_t
>(A.size());
145 if (n == 0)
return 0.0;
146 constexpr std::size_t kChunk = 256;
147 const std::size_t n_chunks = (n + kChunk - 1) / kChunk;
148 std::vector<ExactSum> chunks(n_chunks);
149 const double* a_ptr = A.data();
150 const double* b_ptr = B.data();
154 const std::size_t begin = c * kChunk;
155 const std::size_t end = std::min(n, begin + kChunk);
157 for (std::size_t i = begin; i < end; ++i)
163 for (std::size_t c = 0; c < n_chunks; ++c)
164 total.
merge(chunks[c]);
165 return total.value();
170 const int n =
static_cast<int>(L.rows());
171 const int stride = n + 1;
173 for (
int i = 0; i < n; ++i)
174 sum += std::log(L.data()[i * stride]);
Correctly rounded Schur-complement diagonals from Cholesky solves.
Exact floating-point accumulator (Kulisch long accumulator).
void scaleLower(Eigen::MatrixBase< Derived > &matrix) const
void addProduct(double a, double b) noexcept
void merge(const ExactSum &other) noexcept
Adds another accumulator exactly.
void forEach(std::size_t count, Operation &&operation, Grain grain=Grain::Fine) const
Dense and structured linear algebra behind the GP: Cholesky and eigen solvers, linear operators,...
EigenMatrix back_solve_mat(const EigenMatrix &L, const EigenMatrix &B)
Back triangular solve with matrix RHS (BLAS equivalent: dtrsm with side=L, uplo=L,...
Eigen::VectorXd forward_solve(const EigenMatrix &L, const Eigen::VectorXd &b)
Forward triangular solve with vector RHS (BLAS equivalent: dtrsv).
EigenMatrix forward_solve_mat(const EigenMatrix &L, const EigenMatrix &B)
Forward triangular solve with matrix RHS (BLAS equivalent: dtrsm).
Eigen::VectorXd forward_solve_mat_colwise_squared_norm(const EigenMatrix &L, const EigenMatrix &B)
Forward triangular solve followed by columnwise squared norms.
double log_det_cholesky(const EigenMatrix &L)
Half log-determinant from Cholesky factor.
Eigen::VectorXd back_solve(const EigenMatrix &L, const Eigen::VectorXd &b)
Back triangular solve with vector RHS (BLAS equivalent: dtrsv).
double trace_product(const EigenMatrix &A, const EigenMatrix &B)
Frobenius inner product / trace of matrix product.
Eigen::VectorXd bordered_cholesky_diagonal(const EigenMatrix &L, const EigenMatrix &B, const Eigen::VectorXd &prior)
Posterior diagonal from bordered Cholesky pivots.
EigenMatrix cholesky_inverse(const EigenMatrix &L)
Symmetric inverse from Cholesky factor (LAPACK equivalent: dpotri).
bool cholesky(const EigenMatrix &C, EigenMatrix &L)
Cholesky decomposition (LAPACK equivalent: dpotrf).
Eigen::VectorXd borderedCholeskyDiagonal(const Eigen::VectorXd &prior, const Eigen::MatrixBase< Derived > &whitened)
borderedCholeskyDiagonal for a whitened block L^-1 K_tq with no factor in hand: the allowance is the ...
Gaussian-process regression, kernels, priors, and the searches that run on the surrogate.
Eigen::Matrix< double, EigenDynamic, EigenDynamic, EigenMatrixStorage > EigenMatrix