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]
Eigen
Namespace containing all symbols from the Eigen library.
Definition: jet.h:637
col
m col(1)
MatrixType
MatrixXf MatrixType
Definition: benchmark-blocking-sizes.cpp:52
circulant_functor::m_vec
const ArgType & m_vec
Definition: make_circulant2.cpp:9
makeCirculant
CwiseNullaryOp< circulant_functor< ArgType >, typename circulant_helper< ArgType >::MatrixType > makeCirculant(const Eigen::MatrixBase< ArgType > &arg)
Definition: make_circulant2.cpp:36
mat
MatrixXf mat
Definition: Tutorial_AdvancedInitialization_CommaTemporary.cpp:1
Eigen::CwiseNullaryOp
Generic expression of a matrix where all coefficients are defined by a functor.
Definition: CwiseNullaryOp.h:60
main
int main()
Definition: make_circulant2.cpp:44
operator()
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
Definition: IndexedViewMethods.h:73
arg
Definition: cast.h:1277
circulant_helper::MatrixType
Matrix< typename ArgType::Scalar, ArgType::SizeAtCompileTime, ArgType::SizeAtCompileTime, ColMajor, ArgType::MaxSizeAtCompileTime, ArgType::MaxSizeAtCompileTime > MatrixType
Definition: make_circulant2.cpp:29
row
m row(1)
Eigen::Matrix
The matrix class, also used for vectors and row-vectors.
Definition: 3rdparty/Eigen/Eigen/src/Core/Matrix.h:178
Eigen::MatrixBase
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:48
Eigen::ColMajor
@ ColMajor
Definition: Constants.h:319
circulant_functor
Definition: make_circulant2.cpp:8
circulant_helper
Definition: make_circulant2.cpp:23
Scalar
SCALAR Scalar
Definition: bench_gemm.cpp:46
Eigen::Index
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:74
circulant_functor::circulant_functor
circulant_functor(const ArgType &arg)
Definition: make_circulant2.cpp:11


gtsam
Author(s):
autogenerated on Sat Jun 1 2024 03:01:59