SparseGenRealShiftSolve.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_GEN_REAL_SHIFT_SOLVE_H
8 #define SPARSE_GEN_REAL_SHIFT_SOLVE_H
9 
10 #include <Eigen/Core>
11 #include <Eigen/SparseCore>
12 #include <Eigen/SparseLU>
13 #include <stdexcept>
14 
15 namespace Spectra {
16 
24 template <typename Scalar, int Flags = 0, typename StorageIndex = int>
26 {
27 private:
34 
36  const int m_n;
38 
39 public:
48  m_mat(mat), m_n(mat.rows())
49  {
50  if (mat.rows() != mat.cols())
51  throw std::invalid_argument("SparseGenRealShiftSolve: matrix must be square");
52  }
53 
57  Index rows() const { return m_n; }
61  Index cols() const { return m_n; }
62 
67  {
69  I.setIdentity();
70 
71  m_solver.compute(m_mat - sigma * I);
72  if (m_solver.info() != Eigen::Success)
73  throw std::invalid_argument("SparseGenRealShiftSolve: factorization failed with the given shift");
74  }
75 
82  // y_out = inv(A - sigma * I) * x_in
83  void perform_op(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_solver.solve(x);
88  }
89 };
90 
91 } // namespace Spectra
92 
93 #endif // SPARSE_GEN_REAL_SHIFT_SOLVE_H
Eigen::SparseMatrix
A versatible sparse matrix representation.
Definition: SparseMatrix.h:96
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::SparseGenRealShiftSolve::MapConstVec
Eigen::Map< const Vector > MapConstVec
Definition: SparseGenRealShiftSolve.h:30
Spectra::SparseGenRealShiftSolve::ConstGenericSparseMatrix
const typedef Eigen::Ref< const SparseMatrix > ConstGenericSparseMatrix
Definition: SparseGenRealShiftSolve.h:33
Eigen::Success
@ Success
Definition: Constants.h:442
Spectra::SparseGenRealShiftSolve::perform_op
void perform_op(const Scalar *x_in, Scalar *y_out) const
Definition: SparseGenRealShiftSolve.h:83
Spectra::SparseGenRealShiftSolve::rows
Index rows() const
Definition: SparseGenRealShiftSolve.h:57
mat
MatrixXf mat
Definition: Tutorial_AdvancedInitialization_CommaTemporary.cpp:1
Spectra::SparseGenRealShiftSolve
Definition: SparseGenRealShiftSolve.h:25
sampling::sigma
static const double sigma
Definition: testGaussianBayesNet.cpp:170
Spectra::SparseGenRealShiftSolve::SparseGenRealShiftSolve
SparseGenRealShiftSolve(ConstGenericSparseMatrix &mat)
Definition: SparseGenRealShiftSolve.h:47
Spectra::SparseGenRealShiftSolve::m_n
const int m_n
Definition: SparseGenRealShiftSolve.h:36
Spectra::SparseGenRealShiftSolve::Index
Eigen::Index Index
Definition: SparseGenRealShiftSolve.h:28
I
#define I
Definition: main.h:112
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::SparseGenRealShiftSolve::set_shift
void set_shift(Scalar sigma)
Definition: SparseGenRealShiftSolve.h:66
Eigen::Ref
A matrix or vector expression mapping an existing expression.
Definition: Ref.h:281
Spectra::SparseGenRealShiftSolve::SparseMatrix
Eigen::SparseMatrix< Scalar, Flags, StorageIndex > SparseMatrix
Definition: SparseGenRealShiftSolve.h:32
Spectra::SparseGenRealShiftSolve::MapVec
Eigen::Map< Vector > MapVec
Definition: SparseGenRealShiftSolve.h:31
Spectra::SparseGenRealShiftSolve::m_solver
Eigen::SparseLU< SparseMatrix > m_solver
Definition: SparseGenRealShiftSolve.h:37
Spectra::SparseGenRealShiftSolve::Vector
Eigen::Matrix< Scalar, Eigen::Dynamic, 1 > Vector
Definition: SparseGenRealShiftSolve.h:29
Spectra
Definition: LOBPCGSolver.h:19
Spectra::SparseGenRealShiftSolve::m_mat
ConstGenericSparseMatrix m_mat
Definition: SparseGenRealShiftSolve.h:35
Spectra::SparseGenRealShiftSolve::cols
Index cols() const
Definition: SparseGenRealShiftSolve.h:61
Eigen::Matrix< Scalar, Eigen::Dynamic, 1 >
Eigen::SparseLU
Sparse supernodal LU factorization for general matrices.
Definition: SparseLU.h:17
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:30