bug #1531: expose NumDimensions for compatibility with Tensor

This commit is contained in:
Gael Guennebaud 2018-06-08 16:50:17 +02:00
parent f05dea6b23
commit 89d65bb9d6
4 changed files with 55 additions and 5 deletions

View File

@ -157,6 +157,11 @@ template<typename Derived> class DenseBase
* we are dealing with a column-vector (if there is only one column) or with
* a row-vector (if there is only one row). */
NumDimensions = int(MaxSizeAtCompileTime) == 1 ? 0 : bool(IsVectorAtCompileTime) ? 1 : 2,
/**< This value is equal to Tensor::NumDimensions, i.e. 0 for scalars, 1 for vectors,
* and 2 for matrices.
*/
Flags = internal::traits<Derived>::Flags,
/**< This stores expression \ref flags flags which may or may not be inherited by new expressions
* constructed from this one. See the \ref flags "list of flags".

View File

@ -397,10 +397,6 @@ void test_indexed_view()
// }
// static checks of some internals:
#define STATIC_CHECK( COND ) \
EIGEN_STATIC_ASSERT( (COND) , EIGEN_INTERNAL_ERROR_PLEASE_FILE_A_BUG_REPORT )
STATIC_CHECK(( internal::is_valid_index_type<int>::value ));
STATIC_CHECK(( internal::is_valid_index_type<unsigned int>::value ));
STATIC_CHECK(( internal::is_valid_index_type<short>::value ));

View File

@ -339,6 +339,8 @@ inline void verify_impl(bool condition, const char *testname, const char *file,
#define VERIFY_IS_UNITARY(a) VERIFY(test_isUnitary(a))
#define STATIC_CHECK(COND) EIGEN_STATIC_ASSERT( (COND) , EIGEN_INTERNAL_ERROR_PLEASE_FILE_A_BUG_REPORT )
#define CALL_SUBTEST(FUNC) do { \
g_test_stack.push_back(EI_PP_MAKE_STRING(FUNC)); \
FUNC; \

View File

@ -181,6 +181,49 @@ void map_not_aligned_on_scalar()
internal::aligned_delete(array1, (size+1)*(size+1)+1);
}
#if EIGEN_HAS_CXX11
template<template <typename,int,int> class Object>
void map_num_dimensions()
{
typedef Object<double, 1, 1> ArrayScalarType;
typedef Object<double, 2, 1> ArrayVectorType;
typedef Object<double, 1, 2> TransposeArrayVectorType;
typedef Object<double, 2, 2> ArrayType;
typedef Object<double, Eigen::Dynamic, 1> DynamicArrayVectorType;
typedef Object<double, 1, Eigen::Dynamic> DynamicTransposeArrayVectorType;
typedef Object<double, Eigen::Dynamic, Eigen::Dynamic> DynamicArrayType;
STATIC_CHECK(ArrayScalarType::NumDimensions == 0);
STATIC_CHECK(ArrayVectorType::NumDimensions == 1);
STATIC_CHECK(TransposeArrayVectorType::NumDimensions == 1);
STATIC_CHECK(ArrayType::NumDimensions == 2);
STATIC_CHECK(DynamicArrayVectorType::NumDimensions == 1);
STATIC_CHECK(DynamicTransposeArrayVectorType::NumDimensions == 1);
STATIC_CHECK(DynamicArrayType::NumDimensions == 2);
typedef Eigen::Map<ArrayScalarType> ArrayScalarMap;
typedef Eigen::Map<ArrayVectorType> ArrayVectorMap;
typedef Eigen::Map<TransposeArrayVectorType> TransposeArrayVectorMap;
typedef Eigen::Map<ArrayType> ArrayMap;
typedef Eigen::Map<DynamicArrayVectorType> DynamicArrayVectorMap;
typedef Eigen::Map<DynamicTransposeArrayVectorType> DynamicTransposeArrayVectorMap;
typedef Eigen::Map<DynamicArrayType> DynamicArrayMap;
STATIC_CHECK(ArrayScalarMap::NumDimensions == 0);
STATIC_CHECK(ArrayVectorMap::NumDimensions == 1);
STATIC_CHECK(TransposeArrayVectorMap::NumDimensions == 1);
STATIC_CHECK(ArrayMap::NumDimensions == 2);
STATIC_CHECK(DynamicArrayVectorMap::NumDimensions == 1);
STATIC_CHECK(DynamicTransposeArrayVectorMap::NumDimensions == 1);
STATIC_CHECK(DynamicArrayMap::NumDimensions == 2);
}
template<typename Scalar, int Rows, int Cols>
using TArray = Array<Scalar,Rows,Cols>;
template<typename Scalar, int Rows, int Cols>
using TMatrix = Matrix<Scalar,Rows,Cols>;
#endif
void test_mapped_matrix()
{
for(int i = 0; i < g_repeat; i++) {
@ -205,7 +248,11 @@ void test_mapped_matrix()
CALL_SUBTEST_8( map_static_methods(RowVector3d()) );
CALL_SUBTEST_9( map_static_methods(VectorXcd(8)) );
CALL_SUBTEST_10( map_static_methods(VectorXf(12)) );
CALL_SUBTEST_11( map_not_aligned_on_scalar<double>() );
}
#if EIGEN_HAS_CXX11
CALL_SUBTEST_12( map_num_dimensions<TArray>() );
CALL_SUBTEST_12( map_num_dimensions<TMatrix>() );
#endif
}