SparseRegularInverse.h
Go to the documentation of this file.
1 // Copyright (C) 2017-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_REGULAR_INVERSE_H
8 #define SPARSE_REGULAR_INVERSE_H
9 
10 #include <Eigen/Core>
11 #include <Eigen/SparseCore>
12 #include <Eigen/IterativeLinearSolvers>
13 #include <stdexcept>
14 
15 namespace Spectra {
16 
28 template <typename Scalar, int Uplo = Eigen::Lower, int Flags = 0, typename StorageIndex = int>
30 {
31 private:
38 
40  const int m_n;
42 
43 public:
52  m_mat(mat), m_n(mat.rows())
53  {
54  if (mat.rows() != mat.cols())
55  throw std::invalid_argument("SparseRegularInverse: matrix must be square");
56 
57  m_cg.compute(mat);
58  }
59 
63  Index rows() const { return m_n; }
67  Index cols() const { return m_n; }
68 
75  // y_out = inv(B) * x_in
76  void solve(const Scalar* x_in, Scalar* y_out) const
77  {
78  MapConstVec x(x_in, m_n);
79  MapVec y(y_out, m_n);
80  y.noalias() = m_cg.solve(x);
81  }
82 
89  // y_out = B * x_in
90  void mat_prod(const Scalar* x_in, Scalar* y_out) const
91  {
92  MapConstVec x(x_in, m_n);
93  MapVec y(y_out, m_n);
94  y.noalias() = m_mat.template selfadjointView<Uplo>() * x;
95  }
96 };
97 
98 } // namespace Spectra
99 
100 #endif // SPARSE_REGULAR_INVERSE_H
Eigen::SparseMatrix
A versatible sparse matrix representation.
Definition: SparseMatrix.h:96
Spectra::SparseRegularInverse
Definition: SparseRegularInverse.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
mat
MatrixXf mat
Definition: Tutorial_AdvancedInitialization_CommaTemporary.cpp:1
Spectra::SparseRegularInverse::SparseRegularInverse
SparseRegularInverse(ConstGenericSparseMatrix &mat)
Definition: SparseRegularInverse.h:51
Eigen::ConjugateGradient
A conjugate gradient solver for sparse (or dense) self-adjoint problems.
Definition: ConjugateGradient.h:97
Spectra::SparseRegularInverse::m_mat
ConstGenericSparseMatrix m_mat
Definition: SparseRegularInverse.h:39
Spectra::SparseRegularInverse::solve
void solve(const Scalar *x_in, Scalar *y_out) const
Definition: SparseRegularInverse.h:76
Spectra::SparseRegularInverse::Vector
Eigen::Matrix< Scalar, Eigen::Dynamic, 1 > Vector
Definition: SparseRegularInverse.h:33
Spectra::SparseRegularInverse::cols
Index cols() const
Definition: SparseRegularInverse.h:67
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::SparseRegularInverse::SparseMatrix
Eigen::SparseMatrix< Scalar, Flags, StorageIndex > SparseMatrix
Definition: SparseRegularInverse.h:36
Eigen::Ref
A matrix or vector expression mapping an existing expression.
Definition: Ref.h:281
Spectra::SparseRegularInverse::MapVec
Eigen::Map< Vector > MapVec
Definition: SparseRegularInverse.h:35
Spectra::SparseRegularInverse::m_cg
Eigen::ConjugateGradient< SparseMatrix > m_cg
Definition: SparseRegularInverse.h:41
Spectra
Definition: LOBPCGSolver.h:19
Eigen::Matrix< Scalar, Eigen::Dynamic, 1 >
Spectra::SparseRegularInverse::m_n
const int m_n
Definition: SparseRegularInverse.h:40
Spectra::SparseRegularInverse::ConstGenericSparseMatrix
const typedef Eigen::Ref< const SparseMatrix > ConstGenericSparseMatrix
Definition: SparseRegularInverse.h:37
Spectra::SparseRegularInverse::mat_prod
void mat_prod(const Scalar *x_in, Scalar *y_out) const
Definition: SparseRegularInverse.h:90
Spectra::SparseRegularInverse::rows
Index rows() const
Definition: SparseRegularInverse.h:63
Spectra::SparseRegularInverse::Index
Eigen::Index Index
Definition: SparseRegularInverse.h:32
Spectra::SparseRegularInverse::MapConstVec
Eigen::Map< const Vector > MapConstVec
Definition: SparseRegularInverse.h:34
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 Sun Dec 22 2024 04:13:49