diff --git a/Eigen/src/Core/ArithmeticSequence.h b/Eigen/src/Core/ArithmeticSequence.h index 3439a2586..1e7812c8c 100644 --- a/Eigen/src/Core/ArithmeticSequence.h +++ b/Eigen/src/Core/ArithmeticSequence.h @@ -12,6 +12,9 @@ namespace Eigen { +//-------------------------------------------------------------------------------- +// Pseudo keywords: all, last, end +//-------------------------------------------------------------------------------- struct all_t { all_t() {} }; static const all_t all; @@ -51,32 +54,55 @@ struct end_t { }; static const end_t end; -template struct Index_c { +//-------------------------------------------------------------------------------- +// integral constant +//-------------------------------------------------------------------------------- + +template struct fix_t { static const int value = N; operator int() const { return value; } - Index_c (Index_c (*)() ) {} - Index_c() {} - // Needed in C++14 to allow c(): - Index_c operator() () const { return *this; } + fix_t (fix_t (*)() ) {} + fix_t() {} + // Needed in C++14 to allow fix(): + fix_t operator() () const { return *this; } }; +template struct get_compile_time { + enum { value = Default }; +}; + +template struct get_compile_time,Default> { + enum { value = N }; +}; + +template struct is_compile_time { enum { value = false }; }; +template struct is_compile_time > { enum { value = true }; }; + +#if __cplusplus > 201103L +template +static const fix_t fix{}; +#else +template +inline fix_t fix() { return fix_t(); } +#endif + //-------------------------------------------------------------------------------- -// Range(first,last) and Slice(first,step,last) +// range(first,last,incr) and span(first,size,incr) //-------------------------------------------------------------------------------- -template > +template > struct Range_t { Range_t(FirstType f, LastType l) : m_first(f), m_last(l) {} - Range_t(FirstType f, LastType l, StepType s) : m_first(f), m_last(l), m_step(s) {} + Range_t(FirstType f, LastType l, IncrType s) : m_first(f), m_last(l), m_incr(s) {} FirstType m_first; LastType m_last; - StepType m_step; + IncrType m_incr; enum { SizeAtCompileTime = -1 }; - Index size() const { return (m_last-m_first+m_step)/m_step; } - Index operator[] (Index k) const { return m_first + k*m_step; } + 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; }; @@ -84,8 +110,8 @@ template<> struct cleanup_slice_type { typedef last_t type; }; template<> struct cleanup_slice_type { typedef shifted_last type; }; template<> struct cleanup_slice_type { typedef end_t type; }; template<> struct cleanup_slice_type { typedef shifted_end type; }; -template struct cleanup_slice_type > { typedef Index_c type; }; -template struct cleanup_slice_type (*)() > { typedef Index_c type; }; +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 > @@ -93,43 +119,34 @@ range(FirstType f, LastType l) { return Range_t::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, StepType s) { - return Range_t::type,typename cleanup_slice_type::type,typename cleanup_slice_type::type>(f,l,typename cleanup_slice_type::type(s)); +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)); } -template struct get_compile_time { - enum { value = Default }; -}; -template struct get_compile_time,Default> { - enum { value = N }; -}; -template struct is_compile_time { enum { value = false }; }; -template struct is_compile_time > { enum { value = true }; }; - -template > +template > struct Span_t { Span_t(FirstType first, SizeType size) : m_first(first), m_size(size) {} - Span_t(FirstType first, SizeType size, StepType step) : m_first(first), m_size(size), m_step(step) {} + Span_t(FirstType first, SizeType size, IncrType incr) : m_first(first), m_size(size), m_incr(incr) {} FirstType m_first; SizeType m_size; - StepType m_step; + 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_step; } + 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, StepType step) { - return Span_t::type,typename cleanup_slice_type::type,typename cleanup_slice_type::type>(first,size,step); +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); } template @@ -138,16 +155,24 @@ span(FirstType first, SizeType size) { return Span_t::type,typename cleanup_slice_type::type>(first,size); } -#if __cplusplus > 201103L -template -static const Index_c c{}; -#else -template -inline Index_c c() { return Index_c(); } -#endif + namespace internal { +template struct get_compile_time_size { + enum { value = -1 }; +}; + +template struct get_compile_time_size::type> { + enum { value = T::SizeAtCompileTime }; +}; + +#ifdef EIGEN_HAS_CXX11 +template struct get_compile_time_size > { + enum { value = N }; +}; +#endif + // MakeIndexing/make_indexing turn an arbitrary object of type T into something usable by MatrixSlice template struct MakeIndexing { @@ -158,6 +183,9 @@ template const T& make_indexing(const T& x, Index size) { return x; } struct IntAsArray { + enum { + SizeAtCompileTime = 1 + }; IntAsArray(Index val) : m_value(val) {} Index operator[](Index) const { return m_value; } Index size() const { return 1; } @@ -181,25 +209,25 @@ Index symbolic2value(end_t, Index size) { return size; } 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; +template +struct MakeIndexing > { + typedef Range_t 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_step); +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); } // Convert a symbolic span into a usable one (i.e., remove last/end "keywords") -template -struct MakeIndexing > { - typedef Span_t type; +template +struct MakeIndexing > { + typedef Span_t 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_step); +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); } // Convert a symbolic 'all' into a usable range diff --git a/Eigen/src/Core/IndexedView.h b/Eigen/src/Core/IndexedView.h index e11739a99..7fc856feb 100644 --- a/Eigen/src/Core/IndexedView.h +++ b/Eigen/src/Core/IndexedView.h @@ -19,8 +19,19 @@ struct traits > : traits { enum { + RowsAtCompileTime = get_compile_time_size::value, + ColsAtCompileTime = get_compile_time_size::value, + MaxRowsAtCompileTime = RowsAtCompileTime != Dynamic ? int(RowsAtCompileTime) : int(traits::MaxRowsAtCompileTime), + MaxColsAtCompileTime = ColsAtCompileTime != Dynamic ? int(ColsAtCompileTime) : int(traits::MaxColsAtCompileTime), + + XprTypeIsRowMajor = (int(traits::Flags)&RowMajorBit) != 0, + IsRowMajor = (MaxRowsAtCompileTime==1&&MaxColsAtCompileTime!=1) ? 1 + : (MaxColsAtCompileTime==1&&MaxRowsAtCompileTime!=1) ? 0 + : XprTypeIsRowMajor, + + FlagsRowMajorBit = IsRowMajor ? RowMajorBit : 0, FlagsLvalueBit = is_lvalue::value ? LvalueBit : 0, - Flags = traits::Flags & (RowMajorBit | FlagsLvalueBit /*| DirectAccessBit*/), + Flags = (traits::Flags & HereditaryBits) | FlagsLvalueBit | FlagsRowMajorBit, //MatrixTypeInnerStride = inner_stride_at_compile_time::ret, InnerStrideAtCompileTime = int(Dynamic), OuterStrideAtCompileTime = int(Dynamic) diff --git a/test/indexed_view.cpp b/test/indexed_view.cpp index 1bb2b4256..0be5e434c 100644 --- a/test/indexed_view.cpp +++ b/test/indexed_view.cpp @@ -13,8 +13,8 @@ typedef std::pair IndexPair; -Index encode(Index i, Index j) { - return i*100 + j; +int encode(Index i, Index j) { + return int(i*100 + j); } IndexPair decode(Index ij) { @@ -97,6 +97,17 @@ void check_indexed_view() "300 301 302 303 304 305 306 307 308 309") ); + Array44i B; + VERIFY( (A(span(2,5), 5)).ColsAtCompileTime == 1); + VERIFY( (A(span(2,5), 5)).RowsAtCompileTime == Dynamic); + VERIFY( (A(span(2,fix<5>), 5)).RowsAtCompileTime == 5); + VERIFY( (A(4, all)).ColsAtCompileTime == Dynamic); + VERIFY( (A(4, all)).RowsAtCompileTime == 1); + VERIFY( (B(1, all)).ColsAtCompileTime == 4); + VERIFY( (B(1, all)).RowsAtCompileTime == 1); + VERIFY( (B(all,1)).ColsAtCompileTime == 1); + VERIFY( (B(all,1)).RowsAtCompileTime == 4); + } void test_indexed_view()