DenseSymShiftSolve.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_SYM_SHIFT_SOLVE_H
8 #define DENSE_SYM_SHIFT_SOLVE_H
9 
10 #include <Eigen/Core>
11 #include <stdexcept>
12 
13 #include "../LinAlg/BKLDLT.h"
14 #include "../Util/CompInfo.h"
15 
16 namespace Spectra {
17 
25 template <typename Scalar, int Uplo = Eigen::Lower>
27 {
28 private:
35 
37  const int m_n;
39 
40 public:
50  m_mat(mat), m_n(mat.rows())
51  {
52  if (mat.rows() != mat.cols())
53  throw std::invalid_argument("DenseSymShiftSolve: matrix must be square");
54  }
55 
59  Index rows() const { return m_n; }
63  Index cols() const { return m_n; }
64 
69  {
70  m_solver.compute(m_mat, Uplo, sigma);
71  if (m_solver.info() != SUCCESSFUL)
72  throw std::invalid_argument("DenseSymShiftSolve: factorization failed with the given shift");
73  }
74 
81  // y_out = inv(A - sigma * I) * x_in
82  void perform_op(const Scalar* x_in, Scalar* y_out) const
83  {
84  MapConstVec x(x_in, m_n);
85  MapVec y(y_out, m_n);
86  y.noalias() = m_solver.solve(x);
87  }
88 };
89 
90 } // namespace Spectra
91 
92 #endif // DENSE_SYM_SHIFT_SOLVE_H
Spectra::DenseSymShiftSolve::m_mat
ConstGenericMatrix m_mat
Definition: DenseSymShiftSolve.h:36
Spectra::DenseSymShiftSolve
Definition: DenseSymShiftSolve.h:26
Spectra::DenseSymShiftSolve::MapConstVec
Eigen::Map< const Vector > MapConstVec
Definition: DenseSymShiftSolve.h:32
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::DenseSymShiftSolve::cols
Index cols() const
Definition: DenseSymShiftSolve.h:63
Spectra::DenseSymShiftSolve::m_n
const int m_n
Definition: DenseSymShiftSolve.h:37
mat
MatrixXf mat
Definition: Tutorial_AdvancedInitialization_CommaTemporary.cpp:1
sampling::sigma
static const double sigma
Definition: testGaussianBayesNet.cpp:170
Spectra::DenseSymShiftSolve::MapVec
Eigen::Map< Vector > MapVec
Definition: DenseSymShiftSolve.h:33
Spectra::DenseSymShiftSolve::set_shift
void set_shift(Scalar sigma)
Definition: DenseSymShiftSolve.h:68
Spectra::DenseSymShiftSolve::m_solver
BKLDLT< Scalar > m_solver
Definition: DenseSymShiftSolve.h:38
Spectra::DenseSymShiftSolve::Vector
Eigen::Matrix< Scalar, Eigen::Dynamic, 1 > Vector
Definition: DenseSymShiftSolve.h:31
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
A matrix or vector expression mapping an existing expression.
Definition: Ref.h:281
Spectra::DenseSymShiftSolve::perform_op
void perform_op(const Scalar *x_in, Scalar *y_out) const
Definition: DenseSymShiftSolve.h:82
Spectra
Definition: LOBPCGSolver.h:19
Spectra::DenseSymShiftSolve::Matrix
Eigen::Matrix< Scalar, Eigen::Dynamic, Eigen::Dynamic > Matrix
Definition: DenseSymShiftSolve.h:30
Spectra::SUCCESSFUL
@ SUCCESSFUL
Computation was successful.
Definition: CompInfo.h:19
Eigen::Matrix< Scalar, Eigen::Dynamic, Eigen::Dynamic >
Spectra::DenseSymShiftSolve::rows
Index rows() const
Definition: DenseSymShiftSolve.h:59
Spectra::DenseSymShiftSolve::Index
Eigen::Index Index
Definition: DenseSymShiftSolve.h:29
Spectra::DenseSymShiftSolve::DenseSymShiftSolve
DenseSymShiftSolve(ConstGenericMatrix &mat)
Definition: DenseSymShiftSolve.h:49
Spectra::BKLDLT
Definition: BKLDLT.h:27
Spectra::DenseSymShiftSolve::ConstGenericMatrix
const typedef Eigen::Ref< const Matrix > ConstGenericMatrix
Definition: DenseSymShiftSolve.h:34
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