make_circulant2.cpp
Go to the documentation of this file.
1 #include <Eigen/Core>
2 #include <iostream>
3 
4 using namespace Eigen;
5 
6 // [circulant_func]
7 template<class ArgType>
9  const ArgType &m_vec;
10 public:
11  circulant_functor(const ArgType& arg) : m_vec(arg) {}
12 
13  const typename ArgType::Scalar& operator() (Index row, Index col) const {
14  Index index = row - col;
15  if (index < 0) index += m_vec.size();
16  return m_vec(index);
17  }
18 };
19 // [circulant_func]
20 
21 // [square]
22 template<class ArgType>
24  typedef Matrix<typename ArgType::Scalar,
25  ArgType::SizeAtCompileTime,
26  ArgType::SizeAtCompileTime,
27  ColMajor,
28  ArgType::MaxSizeAtCompileTime,
29  ArgType::MaxSizeAtCompileTime> MatrixType;
30 };
31 // [square]
32 
33 // [makeCirculant]
34 template <class ArgType>
37 {
39  return MatrixType::NullaryExpr(arg.size(), arg.size(), circulant_functor<ArgType>(arg.derived()));
40 }
41 // [makeCirculant]
42 
43 // [main]
44 int main()
45 {
46  Eigen::VectorXd vec(4);
47  vec << 1, 2, 4, 8;
48  Eigen::MatrixXd mat;
49  mat = makeCirculant(vec);
50  std::cout << mat << std::endl;
51 }
52 // [main]
Generic expression of a matrix where all coefficients are defined by a functor.
const ArgType & m_vec
SCALAR Scalar
Definition: bench_gemm.cpp:46
circulant_functor(const ArgType &arg)
CwiseNullaryOp< circulant_functor< ArgType >, typename circulant_helper< ArgType >::MatrixType > makeCirculant(const Eigen::MatrixBase< ArgType > &arg)
Namespace containing all symbols from the Eigen library.
Definition: jet.h:637
MatrixXf MatrixType
int main()
Definition: cast.h:1238
m row(1)
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:74
Matrix< typename ArgType::Scalar, ArgType::SizeAtCompileTime, ArgType::SizeAtCompileTime, ColMajor, ArgType::MaxSizeAtCompileTime, ArgType::MaxSizeAtCompileTime > MatrixType
m col(1)
The matrix class, also used for vectors and row-vectors.
internal::enable_if< internal::valid_indexed_view_overload< RowIndices, ColIndices >::value &&internal::traits< typename EIGEN_INDEXED_VIEW_METHOD_TYPE< RowIndices, ColIndices >::type >::ReturnAsIndexedView, typename EIGEN_INDEXED_VIEW_METHOD_TYPE< RowIndices, ColIndices >::type >::type operator()(const RowIndices &rowIndices, const ColIndices &colIndices) EIGEN_INDEXED_VIEW_METHOD_CONST
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:48


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:34:35