make_circulant2.cpp
Go to the documentation of this file.
1 #include <Eigen/Core>
2 #include <iostream>
3 
4 // [circulant_func]
5 template<class ArgType>
6 class circulant_functor {
7  const ArgType &m_vec;
8 public:
9  circulant_functor(const ArgType& arg) : m_vec(arg) {}
10 
11  const typename ArgType::Scalar& operator() (Eigen::Index row, Eigen::Index col) const {
12  Eigen::Index index = row - col;
13  if (index < 0) index += m_vec.size();
14  return m_vec(index);
15  }
16 };
17 // [circulant_func]
18 
19 // [square]
20 template<class ArgType>
21 struct circulant_helper {
22  typedef Eigen::Matrix<typename ArgType::Scalar,
23  ArgType::SizeAtCompileTime,
24  ArgType::SizeAtCompileTime,
26  ArgType::MaxSizeAtCompileTime,
27  ArgType::MaxSizeAtCompileTime> MatrixType;
28 };
29 // [square]
30 
31 // [makeCirculant]
32 template <class ArgType>
35 {
37  return MatrixType::NullaryExpr(arg.size(), arg.size(), circulant_functor<ArgType>(arg.derived()));
38 }
39 // [makeCirculant]
40 
41 // [main]
42 int main()
43 {
44  Eigen::VectorXd vec(4);
45  vec << 1, 2, 4, 8;
47  mat = makeCirculant(vec);
48  std::cout << mat << std::endl;
49 }
50 // [main]
const ArgReturnType arg() const
RowXpr row(Index i)
This is the const version of row(). *‍/.
ColXpr col(Index i)
This is the const version of col().
IndexedView_or_Block operator()(const RowIndices &rowIndices, const ColIndices &colIndices)
Matrix< float, 1, Dynamic > MatrixType
Generic expression of a matrix where all coefficients are defined by a functor.
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:52
The matrix class, also used for vectors and row-vectors.
Definition: Matrix.h:182
@ ColMajor
Definition: Constants.h:321
Eigen::CwiseNullaryOp< circulant_functor< ArgType >, typename circulant_helper< ArgType >::MatrixType > makeCirculant(const Eigen::MatrixBase< ArgType > &arg)
int main()
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:82