mirror of
https://gitlab.com/libeigen/eigen.git
synced 2024-12-15 07:10:37 +08:00
bug #1531: expose NumDimensions for compatibility with Tensor
This commit is contained in:
parent
f05dea6b23
commit
89d65bb9d6
@ -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".
|
||||
|
@ -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 ));
|
||||
|
@ -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; \
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user