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:33
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
static const double sigma
const Solve< SparseLU< _MatrixType, _OrderingType >, Rhs > solve(const MatrixBase< Rhs > &b) const
ComputationInfo info() const
Reports whether previous computation was successful.
Definition: SparseLU.h:202
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:124
void perform_op(const Scalar *x_in, Scalar *y_out) const
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:33
static const Matrix I
Definition: lago.cpp:35
SparseGenRealShiftSolve(ConstGenericSparseMatrix &mat)
Eigen::Map< const Vector > MapConstVec
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::SparseMatrix< Scalar, Flags, StorageIndex > SparseMatrix


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:44:21