DenseCholesky.h
Go to the documentation of this file.
1 // Copyright (C) 2016-2019 Yixuan Qiu <yixuan.qiu@cos.name>
2 //
3 // This Source Code Form is subject to the terms of the Mozilla
4 // Public License v. 2.0. If a copy of the MPL was not distributed
5 // with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
6 
7 #ifndef DENSE_CHOLESKY_H
8 #define DENSE_CHOLESKY_H
9 
10 #include <Eigen/Core>
11 #include <Eigen/Cholesky>
12 #include <stdexcept>
13 #include "../Util/CompInfo.h"
14 
15 namespace Spectra {
16 
25 template <typename Scalar, int Uplo = Eigen::Lower>
27 {
28 private:
36 
37  const Index m_n;
39  int m_info; // status of the decomposition
40 
41 public:
52  {
53  if (mat.rows() != mat.cols())
54  throw std::invalid_argument("DenseCholesky: matrix must be square");
55 
56  m_decomp.compute(mat);
57  m_info = (m_decomp.info() == Eigen::Success) ?
58  SUCCESSFUL :
60  }
61 
65  Index rows() const { return m_n; }
69  Index cols() const { return m_n; }
70 
75  int info() const { return m_info; }
76 
83  // y_out = inv(L) * x_in
84  void lower_triangular_solve(const Scalar* x_in, Scalar* y_out) const
85  {
86  MapConstVec x(x_in, m_n);
87  MapVec y(y_out, m_n);
88  y.noalias() = m_decomp.matrixL().solve(x);
89  }
90 
97  // y_out = inv(L') * x_in
98  void upper_triangular_solve(const Scalar* x_in, Scalar* y_out) const
99  {
100  MapConstVec x(x_in, m_n);
101  MapVec y(y_out, m_n);
102  y.noalias() = m_decomp.matrixU().solve(x);
103  }
104 };
105 
106 } // namespace Spectra
107 
108 #endif // DENSE_CHOLESKY_H
Spectra::DenseCholesky::DenseCholesky
DenseCholesky(ConstGenericMatrix &mat)
Definition: DenseCholesky.h:50
Spectra::DenseCholesky::cols
Index cols() const
Definition: DenseCholesky.h:69
Spectra::DenseCholesky::lower_triangular_solve
void lower_triangular_solve(const Scalar *x_in, Scalar *y_out) const
Definition: DenseCholesky.h:84
Spectra::NUMERICAL_ISSUE
@ NUMERICAL_ISSUE
Definition: CompInfo.h:29
Spectra::DenseCholesky::rows
Index rows() const
Definition: DenseCholesky.h:65
x
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy x
Definition: gnuplot_common_settings.hh:12
Spectra::DenseCholesky::ConstGenericMatrix
const typedef Eigen::Ref< const Matrix > ConstGenericMatrix
Definition: DenseCholesky.h:35
Eigen::Success
@ Success
Definition: Constants.h:442
Spectra::DenseCholesky::upper_triangular_solve
void upper_triangular_solve(const Scalar *x_in, Scalar *y_out) const
Definition: DenseCholesky.h:98
mat
MatrixXf mat
Definition: Tutorial_AdvancedInitialization_CommaTemporary.cpp:1
Spectra::DenseCholesky::m_n
const Index m_n
Definition: DenseCholesky.h:37
Spectra::DenseCholesky::MapConstVec
Eigen::Map< const Vector > MapConstVec
Definition: DenseCholesky.h:33
Spectra::DenseCholesky::Vector
Eigen::Matrix< Scalar, Eigen::Dynamic, 1 > Vector
Definition: DenseCholesky.h:31
Spectra::NOT_COMPUTED
@ NOT_COMPUTED
Definition: CompInfo.h:21
Spectra::DenseCholesky
Definition: DenseCholesky.h:26
Spectra::DenseCholesky::info
int info() const
Definition: DenseCholesky.h:75
Eigen::Map
A matrix or vector expression mapping an existing array of data.
Definition: Map.h:94
y
Scalar * y
Definition: level1_cplx_impl.h:124
Spectra::DenseCholesky::Matrix
Eigen::Matrix< Scalar, Eigen::Dynamic, Eigen::Dynamic > Matrix
Definition: DenseCholesky.h:30
Spectra::DenseCholesky::MapVec
Eigen::Map< Vector > MapVec
Definition: DenseCholesky.h:34
Eigen::LLT
Standard Cholesky decomposition (LL^T) of a matrix and associated features.
Definition: LLT.h:66
Spectra::DenseCholesky::m_decomp
Eigen::LLT< Matrix, Uplo > m_decomp
Definition: DenseCholesky.h:38
Eigen::Ref
A matrix or vector expression mapping an existing expression.
Definition: Ref.h:281
Spectra::DenseCholesky::MapConstMat
Eigen::Map< const Matrix > MapConstMat
Definition: DenseCholesky.h:32
Spectra::DenseCholesky::m_info
int m_info
Definition: DenseCholesky.h:39
Spectra
Definition: LOBPCGSolver.h:19
Spectra::SUCCESSFUL
@ SUCCESSFUL
Computation was successful.
Definition: CompInfo.h:19
Eigen::Matrix< Scalar, Eigen::Dynamic, Eigen::Dynamic >
Spectra::DenseCholesky::Index
Eigen::Index Index
Definition: DenseCholesky.h:29
Scalar
SCALAR Scalar
Definition: bench_gemm.cpp:46
Eigen::Index
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:74


gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:02:12