SparseCholesky.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 SPARSE_CHOLESKY_H
8 #define SPARSE_CHOLESKY_H
9 
10 #include <Eigen/Core>
11 #include <Eigen/SparseCore>
12 #include <Eigen/SparseCholesky>
13 #include <stdexcept>
14 #include "../Util/CompInfo.h"
15 
16 namespace Spectra {
17 
26 template <typename Scalar, int Uplo = Eigen::Lower, int Flags = 0, typename StorageIndex = int>
28 {
29 private:
36 
37  const Index m_n;
39  int m_info; // status of the decomposition
40 
41 public:
50  m_n(mat.rows())
51  {
52  if (mat.rows() != mat.cols())
53  throw std::invalid_argument("SparseCholesky: matrix must be square");
54 
55  m_decomp.compute(mat);
56  m_info = (m_decomp.info() == Eigen::Success) ?
57  SUCCESSFUL :
59  }
60 
64  Index rows() const { return m_n; }
68  Index cols() const { return m_n; }
69 
74  int info() const { return m_info; }
75 
82  // y_out = inv(L) * x_in
83  void lower_triangular_solve(const Scalar* x_in, Scalar* y_out) const
84  {
85  MapConstVec x(x_in, m_n);
86  MapVec y(y_out, m_n);
87  y.noalias() = m_decomp.permutationP() * x;
88  m_decomp.matrixL().solveInPlace(y);
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  y = m_decomp.permutationPinv() * y;
104  }
105 };
106 
107 } // namespace Spectra
108 
109 #endif // SPARSE_CHOLESKY_H
Spectra::SparseCholesky::info
int info() const
Definition: SparseCholesky.h:74
Eigen::SparseMatrix
A versatible sparse matrix representation.
Definition: SparseMatrix.h:96
Spectra::SparseCholesky::m_decomp
Eigen::SimplicialLLT< SparseMatrix, Uplo > m_decomp
Definition: SparseCholesky.h:38
Spectra::SparseCholesky::Vector
Eigen::Matrix< Scalar, Eigen::Dynamic, 1 > Vector
Definition: SparseCholesky.h:31
Spectra::NUMERICAL_ISSUE
@ NUMERICAL_ISSUE
Definition: CompInfo.h:29
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
Eigen::Success
@ Success
Definition: Constants.h:442
mat
MatrixXf mat
Definition: Tutorial_AdvancedInitialization_CommaTemporary.cpp:1
Eigen::SimplicialLLT
A direct sparse LLT Cholesky factorizations.
Definition: SimplicialCholesky.h:274
Spectra::SparseCholesky::MapVec
Eigen::Map< Vector > MapVec
Definition: SparseCholesky.h:33
Eigen::Map
A matrix or vector expression mapping an existing array of data.
Definition: Map.h:94
Spectra::SparseCholesky
Definition: SparseCholesky.h:27
y
Scalar * y
Definition: level1_cplx_impl.h:124
Spectra::SparseCholesky::m_n
const Index m_n
Definition: SparseCholesky.h:37
Spectra::SparseCholesky::rows
Index rows() const
Definition: SparseCholesky.h:64
Eigen::Ref
A matrix or vector expression mapping an existing expression.
Definition: Ref.h:281
Spectra::SparseCholesky::m_info
int m_info
Definition: SparseCholesky.h:39
Spectra::SparseCholesky::SparseMatrix
Eigen::SparseMatrix< Scalar, Flags, StorageIndex > SparseMatrix
Definition: SparseCholesky.h:34
Spectra
Definition: LOBPCGSolver.h:19
Spectra::SparseCholesky::SparseCholesky
SparseCholesky(ConstGenericSparseMatrix &mat)
Definition: SparseCholesky.h:49
Spectra::SUCCESSFUL
@ SUCCESSFUL
Computation was successful.
Definition: CompInfo.h:19
Eigen::Matrix< Scalar, Eigen::Dynamic, 1 >
Spectra::SparseCholesky::ConstGenericSparseMatrix
const typedef Eigen::Ref< const SparseMatrix > ConstGenericSparseMatrix
Definition: SparseCholesky.h:35
Spectra::SparseCholesky::cols
Index cols() const
Definition: SparseCholesky.h:68
Spectra::SparseCholesky::upper_triangular_solve
void upper_triangular_solve(const Scalar *x_in, Scalar *y_out) const
Definition: SparseCholesky.h:98
Spectra::SparseCholesky::Index
Eigen::Index Index
Definition: SparseCholesky.h:30
Spectra::SparseCholesky::MapConstVec
Eigen::Map< const Vector > MapConstVec
Definition: SparseCholesky.h:32
Spectra::SparseCholesky::lower_triangular_solve
void lower_triangular_solve(const Scalar *x_in, Scalar *y_out) const
Definition: SparseCholesky.h:83
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:04:26