Spectra 1.1.0
Header-only C++ Library for Large Scale Eigenvalue Problems
Loading...
Searching...
No Matches
SymGEigsSolver.h
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_GEIGS_SOLVER_H
8#define SPECTRA_SYM_GEIGS_SOLVER_H
9
10#include "HermEigsBase.h"
11#include "Util/GEigsMode.h"
12#include "MatOp/internal/SymGEigsCholeskyOp.h"
13#include "MatOp/internal/SymGEigsRegInvOp.h"
14
15namespace Spectra {
16
22
42
43// Empty class template
44template <typename OpType, typename BOpType, GEigsMode Mode>
46{};
47
146
147// Partial specialization for mode = GEigsMode::Cholesky
148template <typename OpType, typename BOpType>
149class SymGEigsSolver<OpType, BOpType, GEigsMode::Cholesky> :
150 public HermEigsBase<SymGEigsCholeskyOp<OpType, BOpType>, IdentityBOp>
151{
152private:
153 using Scalar = typename OpType::Scalar;
154 using Index = Eigen::Index;
155 using Matrix = Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic>;
156 using Vector = Eigen::Matrix<Scalar, Eigen::Dynamic, 1>;
157
158 using ModeMatOp = SymGEigsCholeskyOp<OpType, BOpType>;
160
161 const BOpType& m_Bop;
162
163public:
188 SymGEigsSolver(OpType& op, BOpType& Bop, Index nev, Index ncv) :
189 Base(ModeMatOp(op, Bop), IdentityBOp(), nev, ncv),
190 m_Bop(Bop)
191 {}
192
194
195 Matrix eigenvectors(Index nvec) const override
196 {
197 Matrix res = Base::eigenvectors(nvec);
198 Vector tmp(res.rows());
199 const Index nconv = res.cols();
200 for (Index i = 0; i < nconv; i++)
201 {
202 m_Bop.upper_triangular_solve(&res(0, i), tmp.data());
203 res.col(i).noalias() = tmp;
204 }
205
206 return res;
207 }
208
209 Matrix eigenvectors() const override
210 {
211 return SymGEigsSolver<OpType, BOpType, GEigsMode::Cholesky>::eigenvectors(this->m_nev);
212 }
213
215};
216
248
249// Partial specialization for mode = GEigsMode::RegularInverse
250template <typename OpType, typename BOpType>
251class SymGEigsSolver<OpType, BOpType, GEigsMode::RegularInverse> :
252 public HermEigsBase<SymGEigsRegInvOp<OpType, BOpType>, BOpType>
253{
254private:
255 using Index = Eigen::Index;
256
257 using ModeMatOp = SymGEigsRegInvOp<OpType, BOpType>;
259
260public:
283 SymGEigsSolver(OpType& op, BOpType& Bop, Index nev, Index ncv) :
284 Base(ModeMatOp(op, Bop), Bop, nev, ncv)
285 {}
286};
287
288} // namespace Spectra
289
290#endif // SPECTRA_SYM_GEIGS_SOLVER_H
SymGEigsSolver(OpType &op, BOpType &Bop, Index nev, Index ncv)
SymGEigsSolver(OpType &op, BOpType &Bop, Index nev, Index ncv)
@ RegularInverse
Regular inverse mode for generalized eigenvalue solver.
Definition GEigsMode.h:20
@ Cholesky
Using Cholesky decomposition to solve generalized eigenvalues.
Definition GEigsMode.h:19