DenseGenComplexShiftSolve.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_DENSE_GEN_COMPLEX_SHIFT_SOLVE_H
8 #define SPECTRA_DENSE_GEN_COMPLEX_SHIFT_SOLVE_H
9 
10 #include <Eigen/Core>
11 #include <Eigen/LU>
12 #include <stdexcept>
13 
14 namespace Spectra {
15 
29 template <typename Scalar_, int Flags = Eigen::ColMajor>
31 {
32 public:
36  using Scalar = Scalar_;
37 
38 private:
45 
46  using Complex = std::complex<Scalar>;
49 
51 
53  const Index m_n;
56 
57 public:
66  template <typename Derived>
68  m_mat(mat), m_n(mat.rows())
69  {
70  static_assert(
71  static_cast<int>(Derived::PlainObject::IsRowMajor) == static_cast<int>(Matrix::IsRowMajor),
72  "DenseGenComplexShiftSolve: the \"Flags\" template parameter does not match the input matrix (Eigen::ColMajor/Eigen::RowMajor)");
73 
74  if (mat.rows() != mat.cols())
75  throw std::invalid_argument("DenseGenComplexShiftSolve: matrix must be square");
76  }
77 
81  Index rows() const { return m_n; }
85  Index cols() const { return m_n; }
86 
93  void set_shift(const Scalar& sigmar, const Scalar& sigmai)
94  {
95  m_solver.compute(m_mat.template cast<Complex>() - Complex(sigmar, sigmai) * ComplexMatrix::Identity(m_n, m_n));
98  }
99 
107  // y_out = Re( inv(A - sigma * I) * x_in )
108  void perform_op(const Scalar* x_in, Scalar* y_out) const
109  {
110  m_x_cache.real() = MapConstVec(x_in, m_n);
111  MapVec y(y_out, m_n);
112  y.noalias() = m_solver.solve(m_x_cache).real();
113  }
114 };
115 
116 } // namespace Spectra
117 
118 #endif // SPECTRA_DENSE_GEN_COMPLEX_SHIFT_SOLVE_H
Spectra::DenseGenComplexShiftSolve::m_solver
ComplexSolver m_solver
Definition: DenseGenComplexShiftSolve.h:54
Spectra::DenseGenComplexShiftSolve::MapConstVec
Eigen::Map< const Vector > MapConstVec
Definition: DenseGenComplexShiftSolve.h:42
Spectra::DenseGenComplexShiftSolve::m_mat
ConstGenericMatrix m_mat
Definition: DenseGenComplexShiftSolve.h:52
Eigen
Namespace containing all symbols from the Eigen library.
Definition: jet.h:637
Spectra::DenseGenComplexShiftSolve::perform_op
void perform_op(const Scalar *x_in, Scalar *y_out) const
Definition: DenseGenComplexShiftSolve.h:108
Spectra::DenseGenComplexShiftSolve
Definition: DenseGenComplexShiftSolve.h:30
Eigen::PartialPivLU< ComplexMatrix >
Spectra::DenseGenComplexShiftSolve::cols
Index cols() const
Definition: DenseGenComplexShiftSolve.h:85
Spectra::DenseGenComplexShiftSolve::set_shift
void set_shift(const Scalar &sigmar, const Scalar &sigmai)
Definition: DenseGenComplexShiftSolve.h:93
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::m_x_cache
ComplexVector m_x_cache
Definition: DenseGenComplexShiftSolve.h:55
Spectra::DenseGenComplexShiftSolve< double >::Scalar
double Scalar
Definition: DenseGenComplexShiftSolve.h:36
Eigen::Map
A matrix or vector expression mapping an existing array of data.
Definition: Map.h:94
y
Scalar * y
Definition: level1_cplx_impl.h:124
Eigen::Ref< const Matrix >
Spectra::DenseGenComplexShiftSolve< double >::Complex
std::complex< Scalar > Complex
Definition: DenseGenComplexShiftSolve.h:46
Spectra::DenseGenComplexShiftSolve< double >::Index
Eigen::Index Index
Definition: DenseGenComplexShiftSolve.h:39
Spectra
Definition: LOBPCGSolver.h:19
Spectra::DenseGenComplexShiftSolve::rows
Index rows() const
Definition: DenseGenComplexShiftSolve.h:81
Eigen::Matrix
The matrix class, also used for vectors and row-vectors.
Definition: 3rdparty/Eigen/Eigen/src/Core/Matrix.h:178
Eigen::PlainObjectBase::setZero
EIGEN_DEVICE_FUNC Derived & setZero(Index size)
Definition: CwiseNullaryOp.h:562
Eigen::MatrixBase
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:48
Spectra::DenseGenComplexShiftSolve::DenseGenComplexShiftSolve
DenseGenComplexShiftSolve(const Eigen::MatrixBase< Derived > &mat)
Definition: DenseGenComplexShiftSolve.h:67
Spectra::DenseGenComplexShiftSolve::m_n
const Index m_n
Definition: DenseGenComplexShiftSolve.h:53
Eigen::PartialPivLU::compute
PartialPivLU & compute(const EigenBase< InputType > &matrix)
Definition: PartialPivLU.h:131
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 Thu Apr 10 2025 03:01:21