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 
35  ConstGenericSparseMatrix m_mat;
36  const int m_n;
38 
39 public:
47  SparseGenRealShiftSolve(ConstGenericSparseMatrix& mat) :
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  {
68  SparseMatrix I(m_n, m_n);
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::SparseLU< SparseMatrix > m_solver
SCALAR Scalar
Definition: bench_gemm.cpp:46
#define I
Definition: main.h:112
Scalar * y
A versatible sparse matrix representation.
Definition: SparseMatrix.h:96
A matrix or vector expression mapping an existing array of data.
Definition: Map.h:94
const Solve< SparseLU< _MatrixType, _OrderingType >, Rhs > solve(const MatrixBase< Rhs > &b) const
Sparse supernodal LU factorization for general matrices.
Definition: SparseLU.h:17
Eigen::Matrix< Scalar, Eigen::Dynamic, 1 > Vector
const Eigen::Ref< const SparseMatrix > ConstGenericSparseMatrix
void compute(const MatrixType &matrix)
Definition: SparseLU.h:182
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:74
void perform_op(const Scalar *x_in, Scalar *y_out) const
SparseGenRealShiftSolve(ConstGenericSparseMatrix &mat)
Eigen::Map< const Vector > MapConstVec
static const double sigma
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
ComputationInfo info() const
Reports whether previous computation was successful.
Definition: SparseLU.h:299
Eigen::SparseMatrix< Scalar, Flags, StorageIndex > SparseMatrix


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:35:57