From ecd9cc54126c6d01859fbf26276cc1d03e370aec Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Tue, 10 Jan 2017 09:34:25 +0100 Subject: Isolate legacy code (we keep it for performance comparison purpose) --- Eigen/src/Core/ArithmeticSequence.h | 208 +++++++++++++++++++----------------- test/indexed_view.cpp | 4 + 2 files changed, 113 insertions(+), 99 deletions(-) diff --git a/Eigen/src/Core/ArithmeticSequence.h b/Eigen/src/Core/ArithmeticSequence.h index 9f4fe327b..7c104ad91 100644 --- a/Eigen/src/Core/ArithmeticSequence.h +++ b/Eigen/src/Core/ArithmeticSequence.h @@ -19,41 +19,6 @@ namespace Eigen { struct all_t { all_t() {} }; static const all_t all; -struct shifted_last { - explicit shifted_last(int o) : offset(o) {} - int offset; - shifted_last operator+ (int x) const { return shifted_last(offset+x); } - shifted_last operator- (int x) const { return shifted_last(offset-x); } - int operator- (shifted_last x) const { return offset-x.offset; } -}; - -struct last_t { - last_t() {} - shifted_last operator- (int offset) const { return shifted_last(-offset); } - shifted_last operator+ (int offset) const { return shifted_last(+offset); } - int operator- (last_t) const { return 0; } - int operator- (shifted_last x) const { return -x.offset; } -}; -static const last_t last_legacy; - - -struct shifted_end { - explicit shifted_end(int o) : offset(o) {} - int offset; - shifted_end operator+ (int x) const { return shifted_end(offset+x); } - shifted_end operator- (int x) const { return shifted_end(offset-x); } - int operator- (shifted_end x) const { return offset-x.offset; } -}; - -struct end_t { - end_t() {} - shifted_end operator- (int offset) const { return shifted_end (-offset); } - shifted_end operator+ (int offset) const { return shifted_end ( offset); } - int operator- (end_t) const { return 0; } - int operator- (shifted_end x) const { return -x.offset; } -}; -static const end_t end_legacy; - // A simple wrapper around an Index to provide the eval method. // We could also use a free-function symbolic_eval... class symbolic_value_wrapper { @@ -228,49 +193,6 @@ inline fix_t fix() { return fix_t(); } // seq(first,last,incr) and seqN(first,size,incr) //-------------------------------------------------------------------------------- - -template > -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; -}; - -template struct cleanup_seq_type { typedef T type; }; -template struct cleanup_seq_type > { typedef fix_t type; }; -template struct cleanup_seq_type (*)() > { typedef fix_t type; }; - -template -ArithemeticSequenceProxyWithBounds::type,typename cleanup_seq_type::type > -seq_legacy(FirstType f, LastType l) { - return ArithemeticSequenceProxyWithBounds::type,typename cleanup_seq_type::type>(f,l); -} - -template -ArithemeticSequenceProxyWithBounds::type,typename cleanup_seq_type::type,typename cleanup_seq_type::type > -seq_legacy(FirstType f, LastType l, IncrType s) { - return ArithemeticSequenceProxyWithBounds::type,typename cleanup_seq_type::type,typename cleanup_seq_type::type>(f,l,typename cleanup_seq_type::type(s)); -} - - template > class ArithemeticSequence { @@ -297,6 +219,9 @@ protected: IncrType m_incr; }; +template struct cleanup_seq_type { typedef T type; }; +template struct cleanup_seq_type > { typedef fix_t type; }; +template struct cleanup_seq_type (*)() > { typedef fix_t type; }; template ArithemeticSequence::type,typename cleanup_seq_type::type,typename cleanup_seq_type::type > @@ -354,11 +279,6 @@ template struct get_compile_time_incr { enum { value = UndefinedIncr }; }; -template -struct get_compile_time_incr > { - enum { value = get_compile_time::value }; -}; - template struct get_compile_time_incr > { enum { value = get_compile_time::value }; @@ -399,10 +319,6 @@ struct MakeIndexing::val // Replace symbolic last/end "keywords" by their true runtime value Index symbolic2value(Index x, Index /* size */) { return x; } -Index symbolic2value(last_t, Index size) { return size-1; } -Index symbolic2value(shifted_last x, Index size) { return size+x.offset-1; } -Index symbolic2value(end_t, Index size) { return size; } -Index symbolic2value(shifted_end x, Index size) { return size+x.offset; } template fix_t symbolic2value(fix_t x, Index /*size*/) { return x; } @@ -414,18 +330,6 @@ Index symbolic2value(const symbolic_index_base &x, Index size) return x.derived().eval(symbolic_value_pair(size-1)); } - -// Convert a symbolic range into a usable one (i.e., remove last/end "keywords") -template -struct MakeIndexing > { - typedef ArithemeticSequenceProxyWithBounds type; -}; - -template -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 make_size_type { @@ -474,6 +378,112 @@ template<> struct get_compile_time_incr { } // end namespace internal +//-------------------------------------------------------------------------------- + +namespace legacy { +// Here are some initial code that I keep here for now to compare the quality of the code generated by the compilers + +struct shifted_last { + explicit shifted_last(int o) : offset(o) {} + int offset; + shifted_last operator+ (int x) const { return shifted_last(offset+x); } + shifted_last operator- (int x) const { return shifted_last(offset-x); } + int operator- (shifted_last x) const { return offset-x.offset; } +}; + +struct last_t { + last_t() {} + shifted_last operator- (int offset) const { return shifted_last(-offset); } + shifted_last operator+ (int offset) const { return shifted_last(+offset); } + int operator- (last_t) const { return 0; } + int operator- (shifted_last x) const { return -x.offset; } +}; +static const last_t last; + + +struct shifted_end { + explicit shifted_end(int o) : offset(o) {} + int offset; + shifted_end operator+ (int x) const { return shifted_end(offset+x); } + shifted_end operator- (int x) const { return shifted_end(offset-x); } + int operator- (shifted_end x) const { return offset-x.offset; } +}; + +struct end_t { + end_t() {} + shifted_end operator- (int offset) const { return shifted_end (-offset); } + shifted_end operator+ (int offset) const { return shifted_end ( offset); } + int operator- (end_t) const { return 0; } + int operator- (shifted_end x) const { return -x.offset; } +}; +static const end_t end; + +Index symbolic2value(last_t, Index size) { return size-1; } +Index symbolic2value(shifted_last x, Index size) { return size+x.offset-1; } +Index symbolic2value(end_t, Index size) { return size; } +Index symbolic2value(shifted_end x, Index size) { return size+x.offset; } + +template > +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; +}; + +template +ArithemeticSequenceProxyWithBounds::type,typename cleanup_seq_type::type > +seq(FirstType f, LastType l) { + return ArithemeticSequenceProxyWithBounds::type,typename cleanup_seq_type::type>(f,l); +} + +template +ArithemeticSequenceProxyWithBounds::type,typename cleanup_seq_type::type,typename cleanup_seq_type::type > +seq(FirstType f, LastType l, IncrType s) { + return ArithemeticSequenceProxyWithBounds::type,typename cleanup_seq_type::type,typename cleanup_seq_type::type>(f,l,typename cleanup_seq_type::type(s)); +} + +} + +namespace internal { + +template +struct get_compile_time_incr > { + enum { value = get_compile_time::value }; +}; + +// Convert a symbolic range into a usable one (i.e., remove last/end "keywords") +template +struct MakeIndexing > { + typedef legacy::ArithemeticSequenceProxyWithBounds type; +}; + +template +legacy::ArithemeticSequenceProxyWithBounds +make_indexing(const legacy::ArithemeticSequenceProxyWithBounds& ids, Index size) { + return legacy::ArithemeticSequenceProxyWithBounds( + symbolic2value(ids.firstObject(),size),symbolic2value(ids.lastObject(),size),ids.incrObject()); +} + +} + } // end namespace Eigen #endif // EIGEN_ARITHMETIC_SEQUENCE_H diff --git a/test/indexed_view.cpp b/test/indexed_view.cpp index 25a25499c..5c5cb5cde 100644 --- a/test/indexed_view.cpp +++ b/test/indexed_view.cpp @@ -160,6 +160,10 @@ void check_indexed_view() #endif + // check legacy code + VERIFY_IS_APPROX( A(legacy::seq(legacy::last,2,-2), legacy::seq(legacy::last-6,7)), A(seq(last,2,-2), seq(last-6,7)) ); + VERIFY_IS_APPROX( A(seqN(legacy::last,2,-2), seqN(legacy::last-6,3)), A(seqN(last,2,-2), seqN(last-6,3)) ); + } void test_indexed_view() -- cgit v1.2.3