GenEigsRealShiftSolver.h
Go to the documentation of this file.
1 // Copyright (C) 2016-2025 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 SPECTRA_GEN_EIGS_REAL_SHIFT_SOLVER_H
8 #define SPECTRA_GEN_EIGS_REAL_SHIFT_SOLVER_H
9 
10 #include <Eigen/Core>
11 
12 #include "GenEigsBase.h"
13 #include "Util/SelectionRule.h"
15 
16 namespace Spectra {
17 
32 template <typename OpType = DenseGenRealShiftSolve<double>>
33 class GenEigsRealShiftSolver : public GenEigsBase<OpType, IdentityBOp>
34 {
35 private:
36  using Scalar = typename OpType::Scalar;
38  using Complex = std::complex<Scalar>;
40 
42  using Base::m_nev;
43  using Base::m_ritz_val;
44 
45  const Scalar m_sigma;
46 
47  // First transform back the Ritz values, and then sort
48  void sort_ritzpair(SortRule sort_rule) override
49  {
50  // The eigenvalues we get from the iteration is nu = 1 / (lambda - sigma)
51  // So the eigenvalues of the original problem is lambda = 1 / nu + sigma
52  m_ritz_val.head(m_nev) = Scalar(1) / m_ritz_val.head(m_nev).array() + m_sigma;
53  Base::sort_ritzpair(sort_rule);
54  }
55 
56 public:
75  GenEigsRealShiftSolver(OpType& op, Index nev, Index ncv, const Scalar& sigma) :
76  Base(op, IdentityBOp(), nev, ncv),
77  m_sigma(sigma)
78  {
79  op.set_shift(m_sigma);
80  }
81 };
82 
83 } // namespace Spectra
84 
85 #endif // SPECTRA_GEN_EIGS_REAL_SHIFT_SOLVER_H
Spectra::GenEigsBase::sort_ritzpair
virtual void sort_ritzpair(SortRule sort_rule)
Definition: GenEigsBase.h:261
Spectra::GenEigsRealShiftSolver::Complex
std::complex< Scalar > Complex
Definition: GenEigsRealShiftSolver.h:38
Spectra::GenEigsBase::m_ritz_val
ComplexVector m_ritz_val
Definition: GenEigsBase.h:70
DenseGenRealShiftSolve.h
Spectra::GenEigsRealShiftSolver::GenEigsRealShiftSolver
GenEigsRealShiftSolver(OpType &op, Index nev, Index ncv, const Scalar &sigma)
Definition: GenEigsRealShiftSolver.h:75
Eigen::Array
General-purpose arrays with easy API for coefficient-wise operations.
Definition: Array.h:45
Spectra::GenEigsRealShiftSolver::m_sigma
const Scalar m_sigma
Definition: GenEigsRealShiftSolver.h:45
sampling::sigma
static const double sigma
Definition: testGaussianBayesNet.cpp:170
Spectra::IdentityBOp
Definition: ArnoldiOp.h:102
Spectra::GenEigsRealShiftSolver
Definition: GenEigsRealShiftSolver.h:33
Spectra::GenEigsBase
Definition: GenEigsBase.h:38
Spectra::GenEigsRealShiftSolver::sort_ritzpair
void sort_ritzpair(SortRule sort_rule) override
Definition: GenEigsRealShiftSolver.h:48
Spectra::GenEigsRealShiftSolver::Index
Eigen::Index Index
Definition: GenEigsRealShiftSolver.h:37
SelectionRule.h
Spectra::SortRule
SortRule
Definition: SelectionRule.h:33
Spectra
Definition: LOBPCGSolver.h:19
Spectra::GenEigsRealShiftSolver::Scalar
typename OpType::Scalar Scalar
Definition: GenEigsRealShiftSolver.h:36
Spectra::GenEigsBase::m_nev
const Index m_nev
Definition: GenEigsBase.h:63
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
GenEigsBase.h


gtsam
Author(s):
autogenerated on Thu Apr 10 2025 03:01:28