mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-07-24 05:44:26 +08:00
Propagate compile-time size with "all" and add c++11 array unit test
This commit is contained in:
parent
3730e3ca9e
commit
fad1fa75b3
@ -159,16 +159,16 @@ span(FirstType first, SizeType size) {
|
|||||||
|
|
||||||
namespace internal {
|
namespace internal {
|
||||||
|
|
||||||
template<typename T, typename EnableIf = void> struct get_compile_time_size {
|
template<typename T, int XprSize, typename EnableIf = void> struct get_compile_time_size {
|
||||||
enum { value = -1 };
|
enum { value = -1 };
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename T> struct get_compile_time_size<T,typename internal::enable_if<((T::SizeAtCompileTime&0)==0)>::type> {
|
template<typename T, int XprSize> struct get_compile_time_size<T,XprSize,typename internal::enable_if<((T::SizeAtCompileTime&0)==0)>::type> {
|
||||||
enum { value = T::SizeAtCompileTime };
|
enum { value = T::SizeAtCompileTime };
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef EIGEN_HAS_CXX11
|
#ifdef EIGEN_HAS_CXX11
|
||||||
template<typename T,int N> struct get_compile_time_size<std::array<T,N> > {
|
template<typename T, int XprSize, int N> struct get_compile_time_size<std::array<T,N>,XprSize> {
|
||||||
enum { value = N };
|
enum { value = N };
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
@ -250,6 +250,10 @@ AllRange make_indexing(all_t , Index size) {
|
|||||||
return AllRange(size);
|
return AllRange(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<int XprSize> struct get_compile_time_size<AllRange,XprSize> {
|
||||||
|
enum { value = XprSize };
|
||||||
|
};
|
||||||
|
|
||||||
} // end namespace internal
|
} // end namespace internal
|
||||||
|
|
||||||
} // end namespace Eigen
|
} // end namespace Eigen
|
||||||
|
@ -19,8 +19,8 @@ struct traits<IndexedView<XprType, RowIndices, ColIndices> >
|
|||||||
: traits<XprType>
|
: traits<XprType>
|
||||||
{
|
{
|
||||||
enum {
|
enum {
|
||||||
RowsAtCompileTime = get_compile_time_size<RowIndices>::value,
|
RowsAtCompileTime = get_compile_time_size<RowIndices,traits<XprType>::RowsAtCompileTime>::value,
|
||||||
ColsAtCompileTime = get_compile_time_size<ColIndices>::value,
|
ColsAtCompileTime = get_compile_time_size<ColIndices,traits<XprType>::ColsAtCompileTime>::value,
|
||||||
MaxRowsAtCompileTime = RowsAtCompileTime != Dynamic ? int(RowsAtCompileTime) : int(traits<XprType>::MaxRowsAtCompileTime),
|
MaxRowsAtCompileTime = RowsAtCompileTime != Dynamic ? int(RowsAtCompileTime) : int(traits<XprType>::MaxRowsAtCompileTime),
|
||||||
MaxColsAtCompileTime = ColsAtCompileTime != Dynamic ? int(ColsAtCompileTime) : int(traits<XprType>::MaxColsAtCompileTime),
|
MaxColsAtCompileTime = ColsAtCompileTime != Dynamic ? int(ColsAtCompileTime) : int(traits<XprType>::MaxColsAtCompileTime),
|
||||||
|
|
||||||
|
@ -11,6 +11,10 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
|
||||||
|
#if EIGEN_HAS_CXX11
|
||||||
|
#include <array>
|
||||||
|
#endif
|
||||||
|
|
||||||
typedef std::pair<Index,Index> IndexPair;
|
typedef std::pair<Index,Index> IndexPair;
|
||||||
|
|
||||||
int encode(Index i, Index j) {
|
int encode(Index i, Index j) {
|
||||||
@ -108,6 +112,13 @@ void check_indexed_view()
|
|||||||
VERIFY( (B(all,1)).ColsAtCompileTime == 1);
|
VERIFY( (B(all,1)).ColsAtCompileTime == 1);
|
||||||
VERIFY( (B(all,1)).RowsAtCompileTime == 4);
|
VERIFY( (B(all,1)).RowsAtCompileTime == 4);
|
||||||
|
|
||||||
|
VERIFY( (A(all, eii)).ColsAtCompileTime == eii.SizeAtCompileTime);
|
||||||
|
#if EIGEN_HAS_CXX11
|
||||||
|
VERIFY( (A(all, std::array<int,4>{{1,3,2,4}})).ColsAtCompileTime == 4);
|
||||||
|
|
||||||
|
VERIFY_IS_APPROX( (A(std::array<int,3>{{1,3,5}}, std::array<int,4>{{9,6,3,0}})), A(span(1,3,2), span(9,4,-3)) );
|
||||||
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_indexed_view()
|
void test_indexed_view()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user