DenseGenRealShiftSolve.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_REAL_SHIFT_SOLVE_H
8 #define SPECTRA_DENSE_GEN_REAL_SHIFT_SOLVE_H
9 
10 #include <Eigen/Core>
11 #include <Eigen/LU>
12 #include <stdexcept>
13 
14 namespace Spectra {
15 
28 template <typename Scalar_, int Flags = Eigen::ColMajor>
30 {
31 public:
35  using Scalar = Scalar_;
36 
37 private:
44 
46  const Index m_n;
48 
49 public:
58  template <typename Derived>
60  m_mat(mat), m_n(mat.rows())
61  {
62  static_assert(
63  static_cast<int>(Derived::PlainObject::IsRowMajor) == static_cast<int>(Matrix::IsRowMajor),
64  "DenseGenRealShiftSolve: the \"Flags\" template parameter does not match the input matrix (Eigen::ColMajor/Eigen::RowMajor)");
65 
66  if (mat.rows() != mat.cols())
67  throw std::invalid_argument("DenseGenRealShiftSolve: matrix must be square");
68  }
69 
73  Index rows() const { return m_n; }
77  Index cols() const { return m_n; }
78 
82  void set_shift(const Scalar& sigma)
83  {
84  m_solver.compute(m_mat - sigma * Matrix::Identity(m_n, m_n));
85  }
86 
93  // y_out = inv(A - sigma * I) * x_in
94  void perform_op(const Scalar* x_in, Scalar* y_out) const
95  {
96  MapConstVec x(x_in, m_n);
97  MapVec y(y_out, m_n);
98  y.noalias() = m_solver.solve(x);
99  }
100 };
101 
102 } // namespace Spectra
103 
104 #endif // SPECTRA_DENSE_GEN_REAL_SHIFT_SOLVE_H
Spectra::DenseGenRealShiftSolve::cols
Index cols() const
Definition: DenseGenRealShiftSolve.h:77
Eigen::PartialPivLU
LU decomposition of a matrix with partial pivoting, and related features.
Definition: ForwardDeclarations.h:269
Spectra::DenseGenRealShiftSolve::set_shift
void set_shift(const Scalar &sigma)
Definition: DenseGenRealShiftSolve.h:82
x
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy x
Definition: gnuplot_common_settings.hh:12
Spectra::DenseGenRealShiftSolve< double >::Scalar
double Scalar
Definition: DenseGenRealShiftSolve.h:35
mat
MatrixXf mat
Definition: Tutorial_AdvancedInitialization_CommaTemporary.cpp:1
Spectra::DenseGenRealShiftSolve::perform_op
void perform_op(const Scalar *x_in, Scalar *y_out) const
Definition: DenseGenRealShiftSolve.h:94
sampling::sigma
static const double sigma
Definition: testGaussianBayesNet.cpp:170
Spectra::DenseGenRealShiftSolve::m_n
const Index m_n
Definition: DenseGenRealShiftSolve.h:46
Spectra::DenseGenRealShiftSolve::Index
Eigen::Index Index
Definition: DenseGenRealShiftSolve.h:38
Spectra::DenseGenRealShiftSolve::m_solver
Eigen::PartialPivLU< Matrix > m_solver
Definition: DenseGenRealShiftSolve.h:47
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
Spectra::DenseGenRealShiftSolve
Definition: DenseGenRealShiftSolve.h:29
Eigen::Ref< const Matrix >
Spectra
Definition: LOBPCGSolver.h:19
Eigen::Matrix
The matrix class, also used for vectors and row-vectors.
Definition: 3rdparty/Eigen/Eigen/src/Core/Matrix.h:178
Spectra::DenseGenRealShiftSolve::DenseGenRealShiftSolve
DenseGenRealShiftSolve(const Eigen::MatrixBase< Derived > &mat)
Definition: DenseGenRealShiftSolve.h:59
Eigen::MatrixBase
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:48
Spectra::DenseGenRealShiftSolve::rows
Index rows() const
Definition: DenseGenRealShiftSolve.h:73
Spectra::DenseGenRealShiftSolve::m_mat
ConstGenericMatrix m_mat
Definition: DenseGenRealShiftSolve.h:45
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