From 15471432fe809f47e1d4986e9d81547a949e3e07 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Wed, 18 Jan 2017 11:35:27 +0100 Subject: Add a .reverse() member to ArithmeticSequence. --- Eigen/src/Core/ArithmeticSequence.h | 84 +++++++++++++++++++++++++++++++++---- 1 file changed, 75 insertions(+), 9 deletions(-) (limited to 'Eigen/src/Core/ArithmeticSequence.h') diff --git a/Eigen/src/Core/ArithmeticSequence.h b/Eigen/src/Core/ArithmeticSequence.h index 2ad4c0906..0f9c72e2e 100644 --- a/Eigen/src/Core/ArithmeticSequence.h +++ b/Eigen/src/Core/ArithmeticSequence.h @@ -12,10 +12,69 @@ namespace Eigen { +namespace internal { + +#if !EIGEN_HAS_CXX11 +template struct aseq_negate {}; + +template<> struct aseq_negate { + typedef Index type; +}; + +template struct aseq_negate > { + typedef fix_t<-N> type; +}; + +// Compilation error in the following case: +template<> struct aseq_negate > {}; + +template::value, + bool SizeIsSymbolic =Symbolic::is_symbolic::value> +struct aseq_reverse_first_type { + typedef Index type; +}; + +template +struct aseq_reverse_first_type { + typedef Symbolic::AddExpr, + Symbolic::ValueExpr> + > type; +}; + +template +struct aseq_reverse_first_type { + typedef Symbolic::AddExpr type; +}; + +template +struct aseq_reverse_first_type { + typedef Symbolic::AddExpr,Symbolic::ValueExpr>, + Symbolic::ValueExpr> type; +}; +#endif + +// Helper to cleanup the type of the increment: +template struct cleanup_seq_incr { + typedef typename cleanup_index_type::type type; +}; + +} + //-------------------------------------------------------------------------------- // seq(first,last,incr) and seqN(first,size,incr) //-------------------------------------------------------------------------------- +template > +class ArithmeticSequence; + +template +ArithmeticSequence::type, + typename internal::cleanup_index_type::type, + typename internal::cleanup_seq_incr::type > +seqN(FirstType first, SizeType size, IncrType incr); + /** \class ArithmeticSequence * \ingroup Core_Module * @@ -35,10 +94,9 @@ namespace Eigen { * * \sa Eigen::seq, Eigen::seqN, DenseBase::operator()(const RowIndices&, const ColIndices&), class IndexedView */ -template > +template class ArithmeticSequence { - public: ArithmeticSequence(FirstType first, SizeType size) : m_first(first), m_size(size) {} ArithmeticSequence(FirstType first, SizeType size, IncrType incr) : m_first(first), m_size(size), m_incr(incr) {} @@ -65,17 +123,25 @@ protected: FirstType m_first; SizeType m_size; IncrType m_incr; -}; -namespace internal { +public: -// Helper to cleanup the type of the increment: -template struct cleanup_seq_incr { - typedef typename cleanup_index_type::type type; +#if EIGEN_HAS_CXX11 + auto reverse() const -> decltype(Eigen::seqN(m_first+(m_size-1)*Index(m_incr),m_size,-m_incr)) { + return seqN(m_first+(m_size-1)*Index(m_incr),m_size,-m_incr); + } +#else +protected: + typedef typename internal::aseq_negate::type ReverseIncrType; + typedef typename internal::aseq_reverse_first_type::type ReverseFirstType; +public: + ArithmeticSequence + reverse() const { + return seqN(m_first+(m_size-1)*Index(m_incr),m_size,-m_incr); + } +#endif }; -} - /** \returns an ArithmeticSequence starting at \a first, of length \a size, and increment \a incr * * \sa seqN(FirstType,SizeType), seq(FirstType,LastType,IncrType) */ -- cgit v1.2.3