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:
50  DenseCholesky(ConstGenericMatrix& mat) :
51  m_n(mat.rows()), m_info(NOT_COMPUTED)
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
Eigen::Matrix< Scalar, Eigen::Dynamic, 1 > Vector
Definition: DenseCholesky.h:31
SCALAR Scalar
Definition: bench_gemm.cpp:33
Scalar * y
void upper_triangular_solve(const Scalar *x_in, Scalar *y_out) const
Definition: DenseCholesky.h:98
A matrix or vector expression mapping an existing array of data.
Definition: Map.h:94
Traits::MatrixU matrixU() const
Definition: LLT.h:119
Index rows() const
Definition: DenseCholesky.h:65
Index cols() const
Definition: DenseCholesky.h:69
Computation was successful.
Definition: CompInfo.h:19
ComputationInfo info() const
Reports whether previous computation was successful.
Definition: LLT.h:186
Eigen::Map< const Matrix > MapConstMat
Definition: DenseCholesky.h:32
Eigen::Map< Vector > MapVec
Definition: DenseCholesky.h:34
Standard Cholesky decomposition (LL^T) of a matrix and associated features.
Definition: LLT.h:56
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:33
Eigen::Matrix< Scalar, Eigen::Dynamic, Eigen::Dynamic > Matrix
Definition: DenseCholesky.h:30
DenseCholesky(ConstGenericMatrix &mat)
Definition: DenseCholesky.h:50
void lower_triangular_solve(const Scalar *x_in, Scalar *y_out) const
Definition: DenseCholesky.h:84
Eigen::LLT< Matrix, Uplo > m_decomp
Definition: DenseCholesky.h:38
LLT & compute(const EigenBase< InputType > &matrix)
const Eigen::Ref< const Matrix > ConstGenericMatrix
Definition: DenseCholesky.h:35
Traits::MatrixL matrixL() const
Definition: LLT.h:126
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
Eigen::Map< const Vector > MapConstVec
Definition: DenseCholesky.h:33


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:41:57