From ce2035af868d57b85b4078c15843d5c1f51047dc Mon Sep 17 00:00:00 2001 From: Jitse Niesen Date: Sat, 27 Sep 2014 23:25:58 +0100 Subject: New doc page on implementing a new expression class. --- doc/examples/make_circulant.cpp | 11 ++++++++++ doc/examples/make_circulant.cpp.entry | 5 +++++ doc/examples/make_circulant.cpp.evaluator | 33 ++++++++++++++++++++++++++++++ doc/examples/make_circulant.cpp.expression | 20 ++++++++++++++++++ doc/examples/make_circulant.cpp.main | 8 ++++++++ doc/examples/make_circulant.cpp.preamble | 4 ++++ doc/examples/make_circulant.cpp.traits | 19 +++++++++++++++++ 7 files changed, 100 insertions(+) create mode 100644 doc/examples/make_circulant.cpp create mode 100644 doc/examples/make_circulant.cpp.entry create mode 100644 doc/examples/make_circulant.cpp.evaluator create mode 100644 doc/examples/make_circulant.cpp.expression create mode 100644 doc/examples/make_circulant.cpp.main create mode 100644 doc/examples/make_circulant.cpp.preamble create mode 100644 doc/examples/make_circulant.cpp.traits (limited to 'doc/examples') diff --git a/doc/examples/make_circulant.cpp b/doc/examples/make_circulant.cpp new file mode 100644 index 000000000..92e6aaa2b --- /dev/null +++ b/doc/examples/make_circulant.cpp @@ -0,0 +1,11 @@ +/* +This program is presented in several fragments in the doc page. +Every fragment is in its own file; this file simply combines them. +*/ + +#include "make_circulant.cpp.preamble" +#include "make_circulant.cpp.traits" +#include "make_circulant.cpp.expression" +#include "make_circulant.cpp.evaluator" +#include "make_circulant.cpp.entry" +#include "make_circulant.cpp.main" diff --git a/doc/examples/make_circulant.cpp.entry b/doc/examples/make_circulant.cpp.entry new file mode 100644 index 000000000..f9d2eb8a9 --- /dev/null +++ b/doc/examples/make_circulant.cpp.entry @@ -0,0 +1,5 @@ +template +Circulant makeCirculant(const Eigen::MatrixBase& arg) +{ + return Circulant(arg.derived()); +} diff --git a/doc/examples/make_circulant.cpp.evaluator b/doc/examples/make_circulant.cpp.evaluator new file mode 100644 index 000000000..98713cdc0 --- /dev/null +++ b/doc/examples/make_circulant.cpp.evaluator @@ -0,0 +1,33 @@ +namespace Eigen { + namespace internal { + template + struct evaluator > + : evaluator_base > + { + typedef Circulant XprType; + typedef typename nested_eval::type ArgTypeNested; + typedef typename remove_all::type ArgTypeNestedCleaned; + typedef typename XprType::CoeffReturnType CoeffReturnType; + typedef typename XprType::Index Index; + + enum { + CoeffReadCost = evaluator::CoeffReadCost, + Flags = Eigen::ColMajor + }; + + evaluator(const XprType& xpr) + : m_argImpl(xpr.m_arg), m_rows(xpr.rows()) + { } + + CoeffReturnType coeff(Index row, Index col) const + { + Index index = row - col; + if (index < 0) index += m_rows; + return m_argImpl.coeff(index); + } + + typename evaluator::nestedType m_argImpl; + const Index m_rows; + }; + } +} diff --git a/doc/examples/make_circulant.cpp.expression b/doc/examples/make_circulant.cpp.expression new file mode 100644 index 000000000..a68bcb730 --- /dev/null +++ b/doc/examples/make_circulant.cpp.expression @@ -0,0 +1,20 @@ +template +class Circulant : public Eigen::MatrixBase > +{ +public: + Circulant(const ArgType& arg) + : m_arg(arg) + { + EIGEN_STATIC_ASSERT(ArgType::ColsAtCompileTime == 1, + YOU_TRIED_CALLING_A_VECTOR_METHOD_ON_A_MATRIX); + } + + typedef typename Eigen::internal::ref_selector::type Nested; + + typedef typename Eigen::internal::traits::Index Index; + Index rows() const { return m_arg.rows(); } + Index cols() const { return m_arg.rows(); } + + typedef typename Eigen::internal::ref_selector::type ArgTypeNested; + ArgTypeNested m_arg; +}; diff --git a/doc/examples/make_circulant.cpp.main b/doc/examples/make_circulant.cpp.main new file mode 100644 index 000000000..877f97f62 --- /dev/null +++ b/doc/examples/make_circulant.cpp.main @@ -0,0 +1,8 @@ +int main() +{ + Eigen::VectorXd vec(4); + vec << 1, 2, 4, 8; + Eigen::MatrixXd mat; + mat = makeCirculant(vec); + std::cout << mat << std::endl; +} diff --git a/doc/examples/make_circulant.cpp.preamble b/doc/examples/make_circulant.cpp.preamble new file mode 100644 index 000000000..e575cce14 --- /dev/null +++ b/doc/examples/make_circulant.cpp.preamble @@ -0,0 +1,4 @@ +#include +#include + +template class Circulant; diff --git a/doc/examples/make_circulant.cpp.traits b/doc/examples/make_circulant.cpp.traits new file mode 100644 index 000000000..f91e43717 --- /dev/null +++ b/doc/examples/make_circulant.cpp.traits @@ -0,0 +1,19 @@ +namespace Eigen { + namespace internal { + template + struct traits > + { + typedef Eigen::Dense StorageKind; + typedef Eigen::MatrixXpr XprKind; + typedef typename ArgType::Index Index; + typedef typename ArgType::Scalar Scalar; + enum { + Flags = Eigen::ColMajor, + RowsAtCompileTime = ArgType::RowsAtCompileTime, + ColsAtCompileTime = ArgType::RowsAtCompileTime, + MaxRowsAtCompileTime = ArgType::MaxRowsAtCompileTime, + MaxColsAtCompileTime = ArgType::MaxRowsAtCompileTime + }; + }; + } +} -- cgit v1.2.3