SymEigsShiftSolver.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_SYM_EIGS_SHIFT_SOLVER_H
8 #define SPECTRA_SYM_EIGS_SHIFT_SOLVER_H
9 
10 #include <Eigen/Core>
11 
12 #include "HermEigsBase.h"
13 #include "Util/SelectionRule.h"
15 
16 namespace Spectra {
17 
148 template <typename OpType = DenseSymShiftSolve<double>>
149 class SymEigsShiftSolver : public HermEigsBase<OpType, IdentityBOp>
150 {
151 private:
152  using Scalar = typename OpType::Scalar;
155 
157  using Base::m_nev;
158  using Base::m_ritz_val;
159 
161 
162  // First transform back the Ritz values, and then sort
163  void sort_ritzpair(SortRule sort_rule) override
164  {
165  // The eigenvalues we get from the iteration is nu = 1 / (lambda - sigma)
166  // So the eigenvalues of the original problem is lambda = 1 / nu + sigma
167  m_ritz_val.head(m_nev).array() = Scalar(1) / m_ritz_val.head(m_nev).array() + m_sigma;
168  Base::sort_ritzpair(sort_rule);
169  }
170 
171 public:
190  SymEigsShiftSolver(OpType& op, Index nev, Index ncv, const Scalar& sigma) :
191  Base(op, IdentityBOp(), nev, ncv),
192  m_sigma(sigma)
193  {
194  op.set_shift(m_sigma);
195  }
196 };
197 
198 } // namespace Spectra
199 
200 #endif // SPECTRA_SYM_EIGS_SHIFT_SOLVER_H
Spectra::HermEigsBase::m_ritz_val
RealVector m_ritz_val
Definition: HermEigsBase.h:84
Eigen::Array
General-purpose arrays with easy API for coefficient-wise operations.
Definition: Array.h:45
DenseSymShiftSolve.h
Spectra::HermEigsBase::m_nev
const Index m_nev
Definition: HermEigsBase.h:78
Spectra::SymEigsShiftSolver::Scalar
typename OpType::Scalar Scalar
Definition: SymEigsShiftSolver.h:152
Spectra::HermEigsBase::sort_ritzpair
virtual void sort_ritzpair(SortRule sort_rule)
Definition: HermEigsBase.h:223
sampling::sigma
static const double sigma
Definition: testGaussianBayesNet.cpp:170
Spectra::SymEigsShiftSolver::sort_ritzpair
void sort_ritzpair(SortRule sort_rule) override
Definition: SymEigsShiftSolver.h:163
HermEigsBase.h
Spectra::IdentityBOp
Definition: ArnoldiOp.h:102
Spectra::SymEigsShiftSolver::Index
Eigen::Index Index
Definition: SymEigsShiftSolver.h:153
Spectra::SymEigsShiftSolver::m_sigma
const Scalar m_sigma
Definition: SymEigsShiftSolver.h:160
SelectionRule.h
Spectra::SymEigsShiftSolver
Definition: SymEigsShiftSolver.h:149
Spectra::SortRule
SortRule
Definition: SelectionRule.h:33
Spectra
Definition: LOBPCGSolver.h:19
Spectra::HermEigsBase
Definition: HermEigsBase.h:44
Spectra::SymEigsShiftSolver::SymEigsShiftSolver
SymEigsShiftSolver(OpType &op, Index nev, Index ncv, const Scalar &sigma)
Definition: SymEigsShiftSolver.h:190
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 Fri Mar 28 2025 03:04:43