diff --git a/Eigen/src/Core/ArithmeticSequence.h b/Eigen/src/Core/ArithmeticSequence.h index 7c104ad91..6c9cb9ef3 100644 --- a/Eigen/src/Core/ArithmeticSequence.h +++ b/Eigen/src/Core/ArithmeticSequence.h @@ -219,7 +219,8 @@ protected: IncrType m_incr; }; -template struct cleanup_seq_type { typedef T type; }; +template struct cleanup_seq_type { typedef T type; }; +template struct cleanup_seq_type::value>::type> { typedef Index type; }; template struct cleanup_seq_type > { typedef fix_t type; }; template struct cleanup_seq_type (*)() > { typedef fix_t type; }; @@ -235,10 +236,11 @@ seqN(FirstType first, SizeType size) { return ArithemeticSequence::type,typename cleanup_seq_type::type>(first,size); } +#if EIGEN_HAS_CXX11 template -auto seq(FirstType f, LastType l) -> decltype(seqN(f,(l-f+1))) +auto seq(FirstType f, LastType l) -> decltype(seqN(f,(l-f+fix<1>()))) { - return seqN(f,(l-f+1)); + return seqN(f,(l-f+fix<1>())); } template @@ -248,6 +250,80 @@ auto seq(FirstType f, LastType l, IncrType incr) typedef typename cleanup_seq_type::type CleanedIncrType; return seqN(f,(l-f+CleanedIncrType(incr))/CleanedIncrType(incr),CleanedIncrType(incr)); } +#else +template +typename internal::enable_if::value || is_symbolic::value), + ArithemeticSequence::type,Index> >::type +seq(FirstType f, LastType l) +{ + return seqN(f,(l-f+1)); +} + +template +typename internal::enable_if::value, + ArithemeticSequence,symbolic_value_wrapper>,symbolic_value_wrapper> > >::type +seq(const symbolic_index_base &f, LastType l) +{ + return seqN(f.derived(),(l-f.derived()+1)); +} + +template +typename internal::enable_if::value, + ArithemeticSequence::type,symbolic_add,symbolic_value_wrapper> > >::type +seq(FirstType f, const symbolic_index_base &l) +{ + return seqN(f,(l.derived()-f+1)); +} + +template +ArithemeticSequence >,symbolic_value_wrapper> > +seq(const symbolic_index_base &f, const symbolic_index_base &l) +{ + return seqN(f.derived(),(l.derived()-f.derived()+1)); +} + + +template +typename internal::enable_if::value || is_symbolic::value), + ArithemeticSequence::type,Index,typename cleanup_seq_type::type> >::type +seq(FirstType f, LastType l, IncrType incr) +{ + typedef typename cleanup_seq_type::type CleanedIncrType; + return seqN(f,(l-f+CleanedIncrType(incr))/CleanedIncrType(incr), incr); +} + +template +typename internal::enable_if::value, + ArithemeticSequence,symbolic_value_wrapper>,symbolic_value_wrapper>,symbolic_value_wrapper>, + typename cleanup_seq_type::type> >::type +seq(const symbolic_index_base &f, LastType l, IncrType incr) +{ + typedef typename cleanup_seq_type::type CleanedIncrType; + return seqN(f.derived(),(l-f.derived()+CleanedIncrType(incr))/CleanedIncrType(incr), incr); +} + +template +typename internal::enable_if::value, + ArithemeticSequence::type, + symbolic_quotient,symbolic_value_wrapper>,symbolic_value_wrapper>, + typename cleanup_seq_type::type> >::type +seq(FirstType f, const symbolic_index_base &l, IncrType incr) +{ + typedef typename cleanup_seq_type::type CleanedIncrType; + return seqN(f,(l.derived()-f+CleanedIncrType(incr))/CleanedIncrType(incr), incr); +} + +template +ArithemeticSequence >,symbolic_value_wrapper>,symbolic_value_wrapper>, + typename cleanup_seq_type::type> +seq(const symbolic_index_base &f, const symbolic_index_base &l, IncrType incr) +{ + typedef typename cleanup_seq_type::type CleanedIncrType; + return seqN(f.derived(),(l.derived()-f.derived()+CleanedIncrType(incr))/CleanedIncrType(incr), incr); +} +#endif namespace internal { @@ -255,7 +331,7 @@ template Index size(const T& x) { return x.size(); } template -Index size(const T (&x) [N]) { return N; } +Index size(const T (&) [N]) { return N; } template struct get_compile_time_size { enum { value = Dynamic }; @@ -326,7 +402,6 @@ fix_t symbolic2value(fix_t x, Index /*size*/) { return x; } template Index symbolic2value(const symbolic_index_base &x, Index size) { - Index h=x.derived().eval(symbolic_value_pair(size-1)); return x.derived().eval(symbolic_value_pair(size-1)); } diff --git a/test/indexed_view.cpp b/test/indexed_view.cpp index 5c5cb5cde..13eb1ef35 100644 --- a/test/indexed_view.cpp +++ b/test/indexed_view.cpp @@ -7,6 +7,11 @@ // Public License v. 2.0. If a copy of the MPL was not distributed // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. +#ifdef EIGEN_TEST_PART_2 +// Make sure we also check c++98 implementation +#define EIGEN_MAX_CPP_VER 03 +#endif + #include #include #include "main.h" @@ -144,6 +149,13 @@ void check_indexed_view() VERIFY_IS_APPROX( A(seq((n-1)/2,(n)/2+3), seqN(2,4)), A(seq(last/2,(last+1)/2+3), seqN(last+2-last,4)) ); VERIFY_IS_APPROX( A(seq(n-2,2,-2), seqN(n-8,4)), A(seq(end-2,2,-2), seqN(end-8,4)) ); + // Check all combinations of seq: + VERIFY_IS_APPROX( A(seq(1,n-1-2,2), seq(1,n-1-2,2)), A(seq(1,last-2,2), seq(1,last-2,fix<2>)) ); + VERIFY_IS_APPROX( A(seq(n-1-5,n-1-2,2), seq(n-1-5,n-1-2,2)), A(seq(last-5,last-2,2), seq(last-5,last-2,fix<2>)) ); + VERIFY_IS_APPROX( A(seq(n-1-5,7,2), seq(n-1-5,7,2)), A(seq(last-5,7,2), seq(last-5,7,fix<2>)) ); + VERIFY_IS_APPROX( A(seq(1,n-1-2), seq(n-1-5,7)), A(seq(1,last-2), seq(last-5,7)) ); + VERIFY_IS_APPROX( A(seq(n-1-5,n-1-2), seq(n-1-5,n-1-2)), A(seq(last-5,last-2), seq(last-5,last-2)) ); + #if EIGEN_HAS_CXX11 VERIFY( (A(all, std::array{{1,3,2,4}})).ColsAtCompileTime == 4); @@ -170,5 +182,6 @@ void test_indexed_view() { // for(int i = 0; i < g_repeat; i++) { CALL_SUBTEST_1( check_indexed_view() ); + CALL_SUBTEST_2( check_indexed_view() ); // } }