NiHu  2.0
convolution_matrix.hpp
Go to the documentation of this file.
1 
7 #ifndef NIHU_CONVOLUTION_MATRIX_HPP_INCLUDED
8 #define NIHU_CONVOLUTION_MATRIX_HPP_INCLUDED
9 
10 #include <Eigen/Dense>
11 
12 #include <complex>
13 
14 namespace NiHu
15 {
16 namespace fmm
17 {
18 
23 template <class Scalar>
25 {
26 public:
28  typedef Scalar scalar_t;
30  typedef Eigen::Matrix<scalar_t, Eigen::Dynamic, 1> vector_t;
31 
34  {
35  }
36 
42  convolution_matrix(size_t N, size_t M, vector_t const &diag_coeffs)
43  : m_N(N)
44  , m_M(M)
45  , m_diag_coeffs(diag_coeffs)
46  {
47  }
48 
54  vector_t operator *(vector_t const &rhs) const
55  {
56  if (rhs.rows() != Eigen::Index(2 * m_M + 1))
57  throw std::runtime_error("Invalid input size in convolution matrix");
58 
59  vector_t res = vector_t::Zero(2 * m_N + 1, 1);
60  int L = int((m_diag_coeffs.rows() - 1) / 2);
61  // perform convolution by definition
62  for (int n = -int(m_N); n <= int(m_N); ++n)
63  {
64  for (int m = -int(m_M); m <= int(m_M); ++m)
65  {
66  int c = n - m;
67  if (c >= L || c <= -L)
68  continue;
69  res(n + m_N) += m_diag_coeffs(c + L) * rhs(m + m_M);
70  }
71  }
72  return res;
73  }
74 
75 private:
76  size_t m_N;
77  size_t m_M;
78  vector_t m_diag_coeffs;
79 };
80 
81 } // end of namespace fmm
82 } // end of namespace NiHu
83 
84 #endif /* NIHU_CONVOLUTION_MATRIX_HPP_INCLUDED */
NiHu::fmm::convolution_matrix
Class performing convolution.
Definition: convolution_matrix.hpp:24
NiHu::fmm::convolution_matrix::convolution_matrix
convolution_matrix(size_t N, size_t M, vector_t const &diag_coeffs)
constructor
Definition: convolution_matrix.hpp:42
NiHu::fmm::convolution_matrix::vector_t
Eigen::Matrix< scalar_t, Eigen::Dynamic, 1 > vector_t
the column vector type
Definition: convolution_matrix.hpp:30
NiHu::fmm::convolution_matrix::operator*
vector_t operator*(vector_t const &rhs) const
Multiply the convolution matrix by a vector from the right.
Definition: convolution_matrix.hpp:54
NiHu::fmm::convolution_matrix::convolution_matrix
convolution_matrix()
constructor
Definition: convolution_matrix.hpp:33
NiHu::fmm::convolution_matrix::scalar_t
Scalar scalar_t
template parameter as nested type
Definition: convolution_matrix.hpp:28