ARPACK-Armadillo
DenseGenRealShiftSolve.h
1 // Copyright (C) 2015 Yixuan Qiu
2 //
3 // This Source Code Form is subject to the terms of the Mozilla Public
4 // License, v. 2.0. If a copy of the MPL was not distributed with this
5 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 
7 #ifndef DENSE_GEN_REAL_SHIFT_SOLVE_H
8 #define DENSE_GEN_REAL_SHIFT_SOLVE_H
9 
10 #include <armadillo>
11 #include <stdexcept>
12 #include "../LinAlg/GeneralLU.h"
13 
21 template <typename Scalar>
23 {
24 private:
25  typedef arma::Mat<Scalar> Matrix;
26  typedef arma::Col<Scalar> Vector;
27 
28  const Matrix mat;
29  const int dim_n;
30  GeneralLU<Scalar> solver;
31 public:
38  DenseGenRealShiftSolve(Matrix &mat_) :
39  mat(mat_.memptr(), mat_.n_rows, mat_.n_cols, false),
40  dim_n(mat_.n_rows)
41  {
42  if(!mat_.is_square())
43  throw std::invalid_argument("DenseGenRealShiftSolve: matrix must be square");
44  }
45 
49  int rows() { return dim_n; }
53  int cols() { return dim_n; }
54 
58  void set_shift(Scalar sigma)
59  {
60  solver.compute(mat - sigma * arma::eye<Matrix>(dim_n, dim_n));
61  }
62 
69  // y_out = inv(A - sigma * I) * x_in
70  void perform_op(Scalar *x_in, Scalar *y_out)
71  {
72  Vector x(x_in, dim_n, false);
73  Vector y(y_out, dim_n, false);
74  solver.solve(x, y);
75  }
76 };
77 
78 
79 #endif // DENSE_GEN_REAL_SHIFT_SOLVE_H
void compute(const Matrix &mat)
Definition: GeneralLU.h:72
void set_shift(Scalar sigma)
void solve(Vector &vec_in, Vector &vec_out)
Definition: GeneralLU.h:104
void perform_op(Scalar *x_in, Scalar *y_out)