Spectra
SymGEigsSolver.h
1 // Copyright (C) 2016-2018 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 SYM_GEIGS_SOLVER_H
8 #define SYM_GEIGS_SOLVER_H
9 
10 #include "SymEigsBase.h"
11 #include "Util/GEigsMode.h"
12 #include "MatOp/internal/SymGEigsCholeskyOp.h"
13 #include "MatOp/internal/SymGEigsRegInvOp.h"
14 
15 namespace Spectra {
16 
17 
23 
43 
44 // Empty class template
45 template < typename Scalar,
46  int SelectionRule,
47  typename OpType,
48  typename BOpType,
49  int GEigsMode >
51 {};
52 
53 
54 
161 
162 // Partial specialization for GEigsMode = GEIGS_CHOLESKY
163 template < typename Scalar,
164  int SelectionRule,
165  typename OpType,
166  typename BOpType >
167 class SymGEigsSolver<Scalar, SelectionRule, OpType, BOpType, GEIGS_CHOLESKY>:
168  public SymEigsBase<Scalar, SelectionRule, SymGEigsCholeskyOp<Scalar, OpType, BOpType>, IdentityBOp>
169 {
170 private:
171  typedef Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic> Matrix;
172  typedef Eigen::Matrix<Scalar, Eigen::Dynamic, 1> Vector;
173 
174  BOpType* m_Bop;
175 
176 public:
202  SymGEigsSolver(OpType* op, BOpType* Bop, int nev, int ncv) :
203  SymEigsBase<Scalar, SelectionRule, SymGEigsCholeskyOp<Scalar, OpType, BOpType>, IdentityBOp>(
204  new SymGEigsCholeskyOp<Scalar, OpType, BOpType>(*op, *Bop), NULL, nev, ncv
205  ),
206  m_Bop(Bop)
207  {}
208 
210 
211  ~SymGEigsSolver()
212  {
213  // m_op contains the constructed SymGEigsCholeskyOp object
214  delete this->m_op;
215  }
216 
217  Matrix eigenvectors(int nvec) const
218  {
219  Matrix res = SymEigsBase<Scalar, SelectionRule, SymGEigsCholeskyOp<Scalar, OpType, BOpType>, IdentityBOp>::eigenvectors(nvec);
220  Vector tmp(res.rows());
221  const int nconv = res.cols();
222  for(int i = 0; i < nconv; i++)
223  {
224  m_Bop->upper_triangular_solve(&res(0, i), tmp.data());
225  res.col(i).noalias() = tmp;
226  }
227 
228  return res;
229  }
230 
231  Matrix eigenvectors() const
232  {
234  }
235 
237 };
238 
239 
240 
279 
280 // Partial specialization for GEigsMode = GEIGS_REGULAR_INVERSE
281 template < typename Scalar,
282  int SelectionRule,
283  typename OpType,
284  typename BOpType >
285 class SymGEigsSolver<Scalar, SelectionRule, OpType, BOpType, GEIGS_REGULAR_INVERSE>:
286  public SymEigsBase<Scalar, SelectionRule, SymGEigsRegInvOp<Scalar, OpType, BOpType>, BOpType>
287 {
288 public:
312  SymGEigsSolver(OpType* op, BOpType* Bop, int nev, int ncv) :
313  SymEigsBase<Scalar, SelectionRule, SymGEigsRegInvOp<Scalar, OpType, BOpType>, BOpType>(
314  new SymGEigsRegInvOp<Scalar, OpType, BOpType>(*op, *Bop), Bop, nev, ncv
315  )
316  {}
317 
319  ~SymGEigsSolver()
320  {
321  // m_op contains the constructed SymGEigsRegInvOp object
322  delete this->m_op;
323  }
325 };
326 
327 
328 } // namespace Spectra
329 
330 #endif // SYM_GEIGS_SOLVER_H
Using Cholesky decomposition to solve generalized eigenvalues.
Definition: GEigsMode.h:20
Regular inverse mode for generalized eigenvalue solver.
Definition: GEigsMode.h:22