DenseGenComplexShiftSolve.h
Go to the documentation of this file.
1 // Copyright (C) 2016-2019 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 DENSE_GEN_COMPLEX_SHIFT_SOLVE_H
8 #define DENSE_GEN_COMPLEX_SHIFT_SOLVE_H
9 
10 #include <Eigen/Core>
11 #include <Eigen/LU>
12 #include <stdexcept>
13 
14 namespace Spectra {
15 
24 template <typename Scalar>
26 {
27 private:
34 
35  typedef std::complex<Scalar> Complex;
38 
40 
42  const Index m_n;
45 
46 public:
56  m_mat(mat), m_n(mat.rows())
57  {
58  if (mat.rows() != mat.cols())
59  throw std::invalid_argument("DenseGenComplexShiftSolve: matrix must be square");
60  }
61 
65  Index rows() const { return m_n; }
69  Index cols() const { return m_n; }
70 
77  void set_shift(Scalar sigmar, Scalar sigmai)
78  {
79  m_solver.compute(m_mat.template cast<Complex>() - Complex(sigmar, sigmai) * ComplexMatrix::Identity(m_n, m_n));
82  }
83 
91  // y_out = Re( inv(A - sigma * I) * x_in )
92  void perform_op(const Scalar* x_in, Scalar* y_out)
93  {
94  m_x_cache.real() = MapConstVec(x_in, m_n);
95  MapVec y(y_out, m_n);
96  y.noalias() = m_solver.solve(m_x_cache).real();
97  }
98 };
99 
100 } // namespace Spectra
101 
102 #endif // DENSE_GEN_COMPLEX_SHIFT_SOLVE_H
Eigen
Namespace containing all symbols from the Eigen library.
Definition: jet.h:637
Spectra::DenseGenComplexShiftSolve::MapConstVec
Eigen::Map< const Vector > MapConstVec
Definition: DenseGenComplexShiftSolve.h:31
Spectra::DenseGenComplexShiftSolve
Definition: DenseGenComplexShiftSolve.h:25
Eigen::PartialPivLU< ComplexMatrix >
Spectra::DenseGenComplexShiftSolve::ComplexVector
Eigen::Matrix< Complex, Eigen::Dynamic, 1 > ComplexVector
Definition: DenseGenComplexShiftSolve.h:37
Spectra::DenseGenComplexShiftSolve::set_shift
void set_shift(Scalar sigmar, Scalar sigmai)
Definition: DenseGenComplexShiftSolve.h:77
mat
MatrixXf mat
Definition: Tutorial_AdvancedInitialization_CommaTemporary.cpp:1
Eigen::PlainObjectBase::resize
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void resize(Index rows, Index cols)
Definition: PlainObjectBase.h:271
Spectra::DenseGenComplexShiftSolve::Matrix
Eigen::Matrix< Scalar, Eigen::Dynamic, Eigen::Dynamic > Matrix
Definition: DenseGenComplexShiftSolve.h:29
Spectra::DenseGenComplexShiftSolve::m_mat
ConstGenericMatrix m_mat
Definition: DenseGenComplexShiftSolve.h:41
Spectra::DenseGenComplexShiftSolve::ComplexMatrix
Eigen::Matrix< Complex, Eigen::Dynamic, Eigen::Dynamic > ComplexMatrix
Definition: DenseGenComplexShiftSolve.h:36
Spectra::DenseGenComplexShiftSolve::m_solver
ComplexSolver m_solver
Definition: DenseGenComplexShiftSolve.h:43
Spectra::DenseGenComplexShiftSolve::DenseGenComplexShiftSolve
DenseGenComplexShiftSolve(ConstGenericMatrix &mat)
Definition: DenseGenComplexShiftSolve.h:55
Spectra::DenseGenComplexShiftSolve::ComplexSolver
Eigen::PartialPivLU< ComplexMatrix > ComplexSolver
Definition: DenseGenComplexShiftSolve.h:39
Spectra::DenseGenComplexShiftSolve::Complex
std::complex< Scalar > Complex
Definition: DenseGenComplexShiftSolve.h:35
Spectra::DenseGenComplexShiftSolve::Index
Eigen::Index Index
Definition: DenseGenComplexShiftSolve.h:28
Spectra::DenseGenComplexShiftSolve::rows
Index rows() const
Definition: DenseGenComplexShiftSolve.h:65
Eigen::Map
A matrix or vector expression mapping an existing array of data.
Definition: Map.h:94
Spectra::DenseGenComplexShiftSolve::Vector
Eigen::Matrix< Scalar, Eigen::Dynamic, 1 > Vector
Definition: DenseGenComplexShiftSolve.h:30
y
Scalar * y
Definition: level1_cplx_impl.h:124
Spectra::DenseGenComplexShiftSolve::perform_op
void perform_op(const Scalar *x_in, Scalar *y_out)
Definition: DenseGenComplexShiftSolve.h:92
Spectra::DenseGenComplexShiftSolve::MapVec
Eigen::Map< Vector > MapVec
Definition: DenseGenComplexShiftSolve.h:32
Spectra::DenseGenComplexShiftSolve::m_n
const Index m_n
Definition: DenseGenComplexShiftSolve.h:42
Eigen::Ref
A matrix or vector expression mapping an existing expression.
Definition: Ref.h:281
Spectra::DenseGenComplexShiftSolve::ConstGenericMatrix
const typedef Eigen::Ref< const Matrix > ConstGenericMatrix
Definition: DenseGenComplexShiftSolve.h:33
Spectra
Definition: LOBPCGSolver.h:19
Eigen::Matrix< Scalar, Eigen::Dynamic, Eigen::Dynamic >
Eigen::PlainObjectBase::setZero
EIGEN_DEVICE_FUNC Derived & setZero(Index size)
Definition: CwiseNullaryOp.h:562
Spectra::DenseGenComplexShiftSolve::m_x_cache
ComplexVector m_x_cache
Definition: DenseGenComplexShiftSolve.h:44
Eigen::PartialPivLU::compute
PartialPivLU & compute(const EigenBase< InputType > &matrix)
Definition: PartialPivLU.h:131
Spectra::DenseGenComplexShiftSolve::cols
Index cols() const
Definition: DenseGenComplexShiftSolve.h:69
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 Sat Nov 16 2024 04:02:12