From 68064e14fac8c72c05faaeff98c1b70e2dae6ee7 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Mon, 9 Jan 2017 17:35:21 +0100 Subject: Rename span/range to seqN/seq --- Eigen/src/Core/ArithmeticSequence.h | 101 ++++++++++++++++++++++-------------- 1 file changed, 61 insertions(+), 40 deletions(-) (limited to 'Eigen/src/Core/ArithmeticSequence.h') diff --git a/Eigen/src/Core/ArithmeticSequence.h b/Eigen/src/Core/ArithmeticSequence.h index 3b469ba6e..71301797a 100644 --- a/Eigen/src/Core/ArithmeticSequence.h +++ b/Eigen/src/Core/ArithmeticSequence.h @@ -87,22 +87,33 @@ inline fix_t fix() { return fix_t(); } #endif //-------------------------------------------------------------------------------- -// range(first,last,incr) and span(first,size,incr) +// seq(first,last,incr) and seqN(first,size,incr) //-------------------------------------------------------------------------------- + template > -struct Range_t { - Range_t(FirstType f, LastType l) : m_first(f), m_last(l) {} - Range_t(FirstType f, LastType l, IncrType s) : m_first(f), m_last(l), m_incr(s) {} +class ArithemeticSequenceProxyWithBounds +{ +public: + ArithemeticSequenceProxyWithBounds(FirstType f, LastType l) : m_first(f), m_last(l) {} + ArithemeticSequenceProxyWithBounds(FirstType f, LastType l, IncrType s) : m_first(f), m_last(l), m_incr(s) {} + + enum { + SizeAtCompileTime = -1, + IncrAtCompileTime = get_compile_time::value + }; + + Index size() const { return (m_last-m_first+m_incr)/m_incr; } + Index operator[](Index i) const { return m_first + i * m_incr; } + + const FirstType& firstObject() const { return m_first; } + const LastType& lastObject() const { return m_last; } + const IncrType& incrObject() const { return m_incr; } +protected: FirstType m_first; LastType m_last; IncrType m_incr; - - enum { SizeAtCompileTime = -1 }; - - Index size() const { return (m_last-m_first+m_incr)/m_incr; } - Index operator[] (Index k) const { return m_first + k*m_incr; } }; template struct cleanup_slice_type { typedef Index type; }; @@ -114,45 +125,55 @@ template struct cleanup_slice_type > { typedef fix_t type; }; template struct cleanup_slice_type (*)() > { typedef fix_t type; }; template -Range_t::type,typename cleanup_slice_type::type > -range(FirstType f, LastType l) { - return Range_t::type,typename cleanup_slice_type::type>(f,l); +ArithemeticSequenceProxyWithBounds::type,typename cleanup_slice_type::type > +seq(FirstType f, LastType l) { + return ArithemeticSequenceProxyWithBounds::type,typename cleanup_slice_type::type>(f,l); } template -Range_t::type,typename cleanup_slice_type::type,typename cleanup_slice_type::type > -range(FirstType f, LastType l, IncrType s) { - return Range_t::type,typename cleanup_slice_type::type,typename cleanup_slice_type::type>(f,l,typename cleanup_slice_type::type(s)); +ArithemeticSequenceProxyWithBounds::type,typename cleanup_slice_type::type,typename cleanup_slice_type::type > +seq(FirstType f, LastType l, IncrType s) { + return ArithemeticSequenceProxyWithBounds::type,typename cleanup_slice_type::type,typename cleanup_slice_type::type>(f,l,typename cleanup_slice_type::type(s)); } +template > +class ArithemeticSequenceProxyWithSize +{ +public: + ArithemeticSequenceProxyWithSize(FirstType first, SizeType size) : m_first(first), m_size(size) {} + ArithemeticSequenceProxyWithSize(FirstType first, SizeType size, IncrType incr) : m_first(first), m_size(size), m_incr(incr) {} -template > -struct Span_t { - Span_t(FirstType first, SizeType size) : m_first(first), m_size(size) {} - Span_t(FirstType first, SizeType size, IncrType incr) : m_first(first), m_size(size), m_incr(incr) {} + enum { + SizeAtCompileTime = get_compile_time::value, + IncrAtCompileTime = get_compile_time::value + }; + + Index size() const { return m_size; } + Index operator[](Index i) const { return m_first + i * m_incr; } + const FirstType& firstObject() const { return m_first; } + const SizeType& sizeObject() const { return m_size; } + const IncrType& incrObject() const { return m_incr; } + +protected: FirstType m_first; SizeType m_size; IncrType m_incr; - - enum { SizeAtCompileTime = get_compile_time::value }; - - Index size() const { return m_size; } - Index operator[] (Index k) const { return m_first + k*m_incr; } }; + template -Span_t::type,typename cleanup_slice_type::type,typename cleanup_slice_type::type > -span(FirstType first, SizeType size, IncrType incr) { - return Span_t::type,typename cleanup_slice_type::type,typename cleanup_slice_type::type>(first,size,incr); +ArithemeticSequenceProxyWithSize::type,typename cleanup_slice_type::type,typename cleanup_slice_type::type > +seqN(FirstType first, SizeType size, IncrType incr) { + return ArithemeticSequenceProxyWithSize::type,typename cleanup_slice_type::type,typename cleanup_slice_type::type>(first,size,incr); } template -Span_t::type,typename cleanup_slice_type::type > -span(FirstType first, SizeType size) { - return Span_t::type,typename cleanup_slice_type::type>(first,size); +ArithemeticSequenceProxyWithSize::type,typename cleanup_slice_type::type > +seqN(FirstType first, SizeType size) { + return ArithemeticSequenceProxyWithSize::type,typename cleanup_slice_type::type>(first,size); } @@ -188,12 +209,12 @@ template struct get_compile_time_incr { }; template -struct get_compile_time_incr > { +struct get_compile_time_incr > { enum { value = get_compile_time::value }; }; template -struct get_compile_time_incr > { +struct get_compile_time_incr > { enum { value = get_compile_time::value }; }; @@ -239,24 +260,24 @@ Index symbolic2value(shifted_end x, Index size) { return size+x.offset; } // Convert a symbolic range into a usable one (i.e., remove last/end "keywords") template -struct MakeIndexing > { - typedef Range_t type; +struct MakeIndexing > { + typedef ArithemeticSequenceProxyWithBounds type; }; template -Range_t make_indexing(const Range_t& ids, Index size) { - return Range_t(symbolic2value(ids.m_first,size),symbolic2value(ids.m_last,size),ids.m_incr); +ArithemeticSequenceProxyWithBounds make_indexing(const ArithemeticSequenceProxyWithBounds& ids, Index size) { + return ArithemeticSequenceProxyWithBounds(symbolic2value(ids.firstObject(),size),symbolic2value(ids.lastObject(),size),ids.incrObject()); } // Convert a symbolic span into a usable one (i.e., remove last/end "keywords") template -struct MakeIndexing > { - typedef Span_t type; +struct MakeIndexing > { + typedef ArithemeticSequenceProxyWithSize type; }; template -Span_t make_indexing(const Span_t& ids, Index size) { - return Span_t(symbolic2value(ids.m_first,size),ids.m_size,ids.m_incr); +ArithemeticSequenceProxyWithSize make_indexing(const ArithemeticSequenceProxyWithSize& ids, Index size) { + return ArithemeticSequenceProxyWithSize(symbolic2value(ids.firstObject(),size),ids.sizeObject(),ids.incrObject()); } // Convert a symbolic 'all' into a usable range -- cgit v1.2.3