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 
36  ConstGenericMatrix m_mat;
37  const int m_n;
39 
40 public:
49  DenseSymShiftSolve(ConstGenericMatrix& mat) :
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
SCALAR Scalar
Definition: bench_gemm.cpp:46
void compute(ConstGenericMatrix &mat, int uplo=Eigen::Lower, const Scalar &shift=Scalar(0))
Definition: BKLDLT.h:386
Scalar * y
Eigen::Map< const Vector > MapConstVec
A matrix or vector expression mapping an existing array of data.
Definition: Map.h:94
Eigen::Map< Vector > MapVec
Computation was successful.
Definition: CompInfo.h:19
Vector solve(ConstGenericVector &b) const
Definition: BKLDLT.h:518
int info() const
Definition: BKLDLT.h:525
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:74
Eigen::Matrix< Scalar, Eigen::Dynamic, 1 > Vector
static const double sigma
Eigen::Matrix< Scalar, Eigen::Dynamic, Eigen::Dynamic > Matrix
void perform_op(const Scalar *x_in, Scalar *y_out) const
const Eigen::Ref< const Matrix > ConstGenericMatrix
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
DenseSymShiftSolve(ConstGenericMatrix &mat)


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:34:09