SymGEigsCayleyOp.h
Go to the documentation of this file.
1 // Copyright (C) 2020-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_SYM_GEIGS_CAYLEY_OP_H
8 #define SPECTRA_SYM_GEIGS_CAYLEY_OP_H
9 
10 #include <Eigen/Core>
11 
12 #include "../SymShiftInvert.h"
13 #include "../SparseSymMatProd.h"
14 
15 namespace Spectra {
16 
26 template <typename OpType = SymShiftInvert<double>,
27  typename BOpType = SparseSymMatProd<double>>
29 {
30 public:
31  using Scalar = typename OpType::Scalar;
32 
33 private:
38 
39  OpType& m_op;
40  const BOpType& m_Bop;
41  mutable Vector m_cache; // temporary working space
43 
44 public:
51  SymGEigsCayleyOp(OpType& op, const BOpType& Bop) :
52  m_op(op), m_Bop(Bop), m_cache(op.rows())
53  {}
54 
60  {
61  // We emulate the move constructor for Vector using Vector::swap()
62  m_cache.swap(other.m_cache);
63  }
64 
68  Index rows() const { return m_op.rows(); }
72  Index cols() const { return m_op.rows(); }
73 
77  void set_shift(const Scalar& sigma)
78  {
79  m_op.set_shift(sigma);
80  m_sigma = sigma;
81  }
82 
89  // y_out = inv(A - sigma * B) * (A + sigma * B) * x_in
90  void perform_op(const Scalar* x_in, Scalar* y_out) const
91  {
92  // inv(A - sigma * B) * (A + sigma * B) * x
93  // = inv(A - sigma * B) * (A - sigma * B + 2 * sigma * B) * x
94  // = x + 2 * sigma * inv(A - sigma * B) * B * x
95  m_Bop.perform_op(x_in, m_cache.data());
96  m_op.perform_op(m_cache.data(), y_out);
97  MapConstVec x(x_in, this->rows());
98  MapVec y(y_out, this->rows());
99  y.noalias() = x + (Scalar(2) * m_sigma) * y;
100  }
101 };
102 
103 } // namespace Spectra
104 
105 #endif // SPECTRA_SYM_GEIGS_CAYLEY_OP_H
Spectra::SymGEigsCayleyOp::Scalar
typename OpType::Scalar Scalar
Definition: SymGEigsCayleyOp.h:31
Spectra::SymGEigsCayleyOp::perform_op
void perform_op(const Scalar *x_in, Scalar *y_out) const
Definition: SymGEigsCayleyOp.h:90
Eigen::PlainObjectBase::swap
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void swap(DenseBase< OtherDerived > &other)
Definition: PlainObjectBase.h:953
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::SymGEigsCayleyOp::m_op
OpType & m_op
Definition: SymGEigsCayleyOp.h:39
Spectra::SymGEigsCayleyOp
Definition: SymGEigsCayleyOp.h:28
sampling::sigma
static const double sigma
Definition: testGaussianBayesNet.cpp:170
Spectra::SymGEigsCayleyOp::set_shift
void set_shift(const Scalar &sigma)
Definition: SymGEigsCayleyOp.h:77
Spectra::SymGEigsCayleyOp::Index
Eigen::Index Index
Definition: SymGEigsCayleyOp.h:34
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::SymGEigsCayleyOp::SymGEigsCayleyOp
SymGEigsCayleyOp(SymGEigsCayleyOp &&other)
Definition: SymGEigsCayleyOp.h:58
Spectra::SymGEigsCayleyOp::m_Bop
const BOpType & m_Bop
Definition: SymGEigsCayleyOp.h:40
Spectra::SymGEigsCayleyOp::m_cache
Vector m_cache
Definition: SymGEigsCayleyOp.h:41
Spectra
Definition: LOBPCGSolver.h:19
Eigen::PlainObjectBase::data
EIGEN_DEVICE_FUNC const EIGEN_STRONG_INLINE Scalar * data() const
Definition: PlainObjectBase.h:247
Spectra::SymGEigsCayleyOp::SymGEigsCayleyOp
SymGEigsCayleyOp(OpType &op, const BOpType &Bop)
Definition: SymGEigsCayleyOp.h:51
Eigen::Matrix< Scalar, Eigen::Dynamic, 1 >
Spectra::SymGEigsCayleyOp::cols
Index cols() const
Definition: SymGEigsCayleyOp.h:72
Spectra::SymGEigsCayleyOp::rows
Index rows() const
Definition: SymGEigsCayleyOp.h:68
pybind_wrapper_test_script.other
other
Definition: pybind_wrapper_test_script.py:42
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
Spectra::SymGEigsCayleyOp::m_sigma
Scalar m_sigma
Definition: SymGEigsCayleyOp.h:42


gtsam
Author(s):
autogenerated on Wed May 28 2025 03:04:19