Spectra
SparseSymMatProd.h
1 // Copyright (C) 2016-2018 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 SPARSE_SYM_MAT_PROD_H
8 #define SPARSE_SYM_MAT_PROD_H
9 
10 #include <Eigen/Core>
11 #include <Eigen/SparseCore>
12 
13 namespace Spectra {
14 
15 
23 template <typename Scalar, int Uplo = Eigen::Lower, int Flags = 0, typename StorageIndex = int>
25 {
26 private:
27  typedef Eigen::Matrix<Scalar, Eigen::Dynamic, 1> Vector;
28  typedef Eigen::Map<const Vector> MapConstVec;
29  typedef Eigen::Map<Vector> MapVec;
30  typedef Eigen::SparseMatrix<Scalar, Flags, StorageIndex> SparseMatrix;
31  typedef const Eigen::Ref<const SparseMatrix> ConstGenericSparseMatrix;
32 
33  ConstGenericSparseMatrix m_mat;
34 
35 public:
43  SparseSymMatProd(ConstGenericSparseMatrix& mat) :
44  m_mat(mat)
45  {}
46 
50  int rows() const { return m_mat.rows(); }
54  int cols() const { return m_mat.cols(); }
55 
62  // y_out = A * x_in
63  void perform_op(const Scalar* x_in, Scalar* y_out) const
64  {
65  MapConstVec x(x_in, m_mat.cols());
66  MapVec y(y_out, m_mat.rows());
67  y.noalias() = m_mat.template selfadjointView<Uplo>() * x;
68  }
69 };
70 
71 
72 } // namespace Spectra
73 
74 #endif // SPARSE_SYM_MAT_PROD_H
void perform_op(const Scalar *x_in, Scalar *y_out) const
SparseSymMatProd(ConstGenericSparseMatrix &mat)