ARPACK-Armadillo
SparseGenMatProd.h
1 // Copyright (C) 2015 Yixuan Qiu
2 //
3 // This Source Code Form is subject to the terms of the Mozilla Public
4 // License, v. 2.0. If a copy of the MPL was not distributed with this
5 // 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 <armadillo>
11 
20 template <typename Scalar>
22 {
23 private:
24  typedef arma::Mat<Scalar> Matrix;
25  typedef arma::Col<Scalar> Vector;
26  typedef arma::SpMat<Scalar> SpMatrix;
27 
28  const SpMatrix* mat;
29 
30 public:
37  SparseGenMatProd(const SpMatrix &mat_) :
38  mat(&mat_)
39  {}
40 
44  int rows() { return mat->n_rows; }
48  int cols() { return mat->n_cols; }
49 
56  // y_out = A * x_in
57  void perform_op(Scalar *x_in, Scalar *y_out)
58  {
59  Vector x(x_in, mat->n_cols, false);
60  Vector y(y_out, mat->n_rows, false);
61  y = (*mat) * x;
62  }
63 };
64 
65 
66 #endif // SPARSE_GEN_MAT_PROD_H
void perform_op(Scalar *x_in, Scalar *y_out)
SparseGenMatProd(const SpMatrix &mat_)