From 68064e14fac8c72c05faaeff98c1b70e2dae6ee7 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Mon, 9 Jan 2017 17:35:21 +0100 Subject: [PATCH] Rename span/range to seqN/seq --- Eigen/src/Core/ArithmeticSequence.h | 105 +++++++++++++++++----------- test/indexed_view.cpp | 52 +++++++------- 2 files changed, 88 insertions(+), 69 deletions(-) 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) {} +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; - - 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 > -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) {} +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) {} + + 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 diff --git a/test/indexed_view.cpp b/test/indexed_view.cpp index 5372a3a90..23ad2d743 100644 --- a/test/indexed_view.cpp +++ b/test/indexed_view.cpp @@ -52,11 +52,11 @@ void check_indexed_view() std::valarray vali(4); Map(&vali[0],4) = eii; std::vector veci(4); Map(veci.data(),4) = eii; - VERIFY( MATCH( A(3, range(9,3,-1)), + VERIFY( MATCH( A(3, seq(9,3,-1)), "309 308 307 306 305 304 303") ); - VERIFY( MATCH( A(span(2,5), range(9,3,-1)), + VERIFY( MATCH( A(seqN(2,5), seq(9,3,-1)), "209 208 207 206 205 204 203\n" "309 308 307 306 305 304 303\n" "409 408 407 406 405 404 403\n" @@ -64,7 +64,7 @@ void check_indexed_view() "609 608 607 606 605 604 603") ); - VERIFY( MATCH( A(span(2,5), 5), + VERIFY( MATCH( A(seqN(2,5), 5), "205\n" "305\n" "405\n" @@ -72,7 +72,7 @@ void check_indexed_view() "605") ); - VERIFY( MATCH( A(span(last,5,-1), range(2,last)), + VERIFY( MATCH( A(seqN(last,5,-1), seq(2,last)), "902 903 904 905 906 907 908 909\n" "802 803 804 805 806 807 808 809\n" "702 703 704 705 706 707 708 709\n" @@ -95,7 +95,7 @@ void check_indexed_view() ); // takes the row numer 3, and repeat it 5 times - VERIFY( MATCH( A(span(3,5,0), all), + VERIFY( MATCH( A(seqN(3,5,0), all), "300 301 302 303 304 305 306 307 308 309\n" "300 301 302 303 304 305 306 307 308 309\n" "300 301 302 303 304 305 306 307 308 309\n" @@ -105,28 +105,28 @@ void check_indexed_view() Array44i B; B.setRandom(); - VERIFY( (A(span(2,5), 5)).ColsAtCompileTime == 1); - VERIFY( (A(span(2,5), 5)).RowsAtCompileTime == Dynamic); - VERIFY_IS_EQUAL( (A(span(2,5), 5)).InnerStrideAtCompileTime , A.InnerStrideAtCompileTime); - VERIFY_IS_EQUAL( (A(span(2,5), 5)).OuterStrideAtCompileTime , A.col(5).OuterStrideAtCompileTime); + VERIFY( (A(seqN(2,5), 5)).ColsAtCompileTime == 1); + VERIFY( (A(seqN(2,5), 5)).RowsAtCompileTime == Dynamic); + VERIFY_IS_EQUAL( (A(seqN(2,5), 5)).InnerStrideAtCompileTime , A.InnerStrideAtCompileTime); + VERIFY_IS_EQUAL( (A(seqN(2,5), 5)).OuterStrideAtCompileTime , A.col(5).OuterStrideAtCompileTime); - VERIFY_IS_EQUAL( (A(5,span(2,5))).InnerStrideAtCompileTime , A.row(5).InnerStrideAtCompileTime); - VERIFY_IS_EQUAL( (A(5,span(2,5))).OuterStrideAtCompileTime , A.row(5).OuterStrideAtCompileTime); - VERIFY_IS_EQUAL( (B(1,span(1,2))).InnerStrideAtCompileTime , B.row(1).InnerStrideAtCompileTime); - VERIFY_IS_EQUAL( (B(1,span(1,2))).OuterStrideAtCompileTime , B.row(1).OuterStrideAtCompileTime); + VERIFY_IS_EQUAL( (A(5,seqN(2,5))).InnerStrideAtCompileTime , A.row(5).InnerStrideAtCompileTime); + VERIFY_IS_EQUAL( (A(5,seqN(2,5))).OuterStrideAtCompileTime , A.row(5).OuterStrideAtCompileTime); + VERIFY_IS_EQUAL( (B(1,seqN(1,2))).InnerStrideAtCompileTime , B.row(1).InnerStrideAtCompileTime); + VERIFY_IS_EQUAL( (B(1,seqN(1,2))).OuterStrideAtCompileTime , B.row(1).OuterStrideAtCompileTime); - VERIFY_IS_EQUAL( (A(span(2,5), range(1,3))).InnerStrideAtCompileTime , A.InnerStrideAtCompileTime); - VERIFY_IS_EQUAL( (A(span(2,5), range(1,3))).OuterStrideAtCompileTime , A.OuterStrideAtCompileTime); - VERIFY_IS_EQUAL( (B(span(1,2), range(1,3))).InnerStrideAtCompileTime , B.InnerStrideAtCompileTime); - VERIFY_IS_EQUAL( (B(span(1,2), range(1,3))).OuterStrideAtCompileTime , B.OuterStrideAtCompileTime); - VERIFY_IS_EQUAL( (A(span(2,5,2), range(1,3,2))).InnerStrideAtCompileTime , Dynamic); - VERIFY_IS_EQUAL( (A(span(2,5,2), range(1,3,2))).OuterStrideAtCompileTime , Dynamic); - VERIFY_IS_EQUAL( (A(span(2,5,fix<2>), range(1,3,fix<3>))).InnerStrideAtCompileTime , 2); - VERIFY_IS_EQUAL( (A(span(2,5,fix<2>), range(1,3,fix<3>))).OuterStrideAtCompileTime , Dynamic); - VERIFY_IS_EQUAL( (B(span(1,2,fix<2>), range(1,3,fix<3>))).InnerStrideAtCompileTime , 2); - VERIFY_IS_EQUAL( (B(span(1,2,fix<2>), range(1,3,fix<3>))).OuterStrideAtCompileTime , 3*4); + VERIFY_IS_EQUAL( (A(seqN(2,5), seq(1,3))).InnerStrideAtCompileTime , A.InnerStrideAtCompileTime); + VERIFY_IS_EQUAL( (A(seqN(2,5), seq(1,3))).OuterStrideAtCompileTime , A.OuterStrideAtCompileTime); + VERIFY_IS_EQUAL( (B(seqN(1,2), seq(1,3))).InnerStrideAtCompileTime , B.InnerStrideAtCompileTime); + VERIFY_IS_EQUAL( (B(seqN(1,2), seq(1,3))).OuterStrideAtCompileTime , B.OuterStrideAtCompileTime); + VERIFY_IS_EQUAL( (A(seqN(2,5,2), seq(1,3,2))).InnerStrideAtCompileTime , Dynamic); + VERIFY_IS_EQUAL( (A(seqN(2,5,2), seq(1,3,2))).OuterStrideAtCompileTime , Dynamic); + VERIFY_IS_EQUAL( (A(seqN(2,5,fix<2>), seq(1,3,fix<3>))).InnerStrideAtCompileTime , 2); + VERIFY_IS_EQUAL( (A(seqN(2,5,fix<2>), seq(1,3,fix<3>))).OuterStrideAtCompileTime , Dynamic); + VERIFY_IS_EQUAL( (B(seqN(1,2,fix<2>), seq(1,3,fix<3>))).InnerStrideAtCompileTime , 2); + VERIFY_IS_EQUAL( (B(seqN(1,2,fix<2>), seq(1,3,fix<3>))).OuterStrideAtCompileTime , 3*4); - VERIFY( (A(span(2,fix<5>), 5)).RowsAtCompileTime == 5); + VERIFY( (A(seqN(2,fix<5>), 5)).RowsAtCompileTime == 5); VERIFY( (A(4, all)).ColsAtCompileTime == Dynamic); VERIFY( (A(4, all)).RowsAtCompileTime == 1); VERIFY( (B(1, all)).ColsAtCompileTime == 4); @@ -139,12 +139,10 @@ void check_indexed_view() VERIFY_IS_EQUAL( (A(eii, eii)).InnerStrideAtCompileTime, 0); VERIFY_IS_EQUAL( (A(eii, eii)).OuterStrideAtCompileTime, 0); - - #if EIGEN_HAS_CXX11 VERIFY( (A(all, std::array{{1,3,2,4}})).ColsAtCompileTime == 4); - VERIFY_IS_APPROX( (A(std::array{{1,3,5}}, std::array{{9,6,3,0}})), A(span(1,3,2), span(9,4,-3)) ); + VERIFY_IS_APPROX( (A(std::array{{1,3,5}}, std::array{{9,6,3,0}})), A(seqN(1,3,2), seqN(9,4,-3)) ); #if (!EIGEN_COMP_CLANG) || (EIGEN_COMP_CLANG>=308 && !defined(__apple_build_version__)) VERIFY_IS_APPROX( A({3, 1, 6, 5}, all), A(std::array{{3, 1, 6, 5}}, all) );