Spectra
SparseGenMatProd.h
1 // Copyright (C) 2016-2017 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 http://mozilla.org/MPL/2.0/.
6 
7 #ifndef SPARSE_GEN_MAT_PROD_H
8 #define SPARSE_GEN_MAT_PROD_H
9 
10 #include <Eigen/Core>
11 #include <Eigen/SparseCore>
12 
13 namespace Spectra {
14 
15 
24 template <typename Scalar, int Flags = 0, typename StorageIndex = int>
26 {
27 private:
28  typedef Eigen::Matrix<Scalar, Eigen::Dynamic, 1> Vector;
29  typedef Eigen::Map<const Vector> MapConstVec;
30  typedef Eigen::Map<Vector> MapVec;
31  typedef Eigen::SparseMatrix<Scalar, Flags, StorageIndex> SparseMatrix;
32 
33  const SparseMatrix& m_mat;
34 
35 public:
42  SparseGenMatProd(const SparseMatrix& mat_) :
43  m_mat(mat_)
44  {}
45 
49  int rows() const { return m_mat.rows(); }
53  int cols() const { return m_mat.cols(); }
54 
61  // y_out = A * x_in
62  void perform_op(const Scalar* x_in, Scalar* y_out) const
63  {
64  MapConstVec x(x_in, m_mat.cols());
65  MapVec y(y_out, m_mat.rows());
66  y.noalias() = m_mat * x;
67  }
68 };
69 
70 
71 } // namespace Spectra
72 
73 #endif // SPARSE_GEN_MAT_PROD_H
void perform_op(const Scalar *x_in, Scalar *y_out) const
SparseGenMatProd(const SparseMatrix &mat_)