syncing this fork with upstream

This commit is contained in:
Deven Desai
2018-06-13 12:09:52 -04:00
88 changed files with 1266 additions and 395 deletions

View File

@@ -47,7 +47,7 @@ set(EIGEN_TEST_MATRIX_DIR "" CACHE STRING "Enable testing of realword sparse mat
if(EIGEN_TEST_MATRIX_DIR)
if(NOT WIN32)
message(STATUS "Test realworld sparse matrices: ${EIGEN_TEST_MATRIX_DIR}")
add_definitions( -DTEST_REAL_CASES=${EIGEN_TEST_MATRIX_DIR} )
add_definitions( -DTEST_REAL_CASES="${EIGEN_TEST_MATRIX_DIR}" )
else(NOT WIN32)
message(STATUS "REAL CASES CAN NOT BE CURRENTLY TESTED ON WIN32")
endif(NOT WIN32)
@@ -292,6 +292,7 @@ ei_add_test(mpl2only)
ei_add_test(inplace_decomposition)
ei_add_test(half_float)
ei_add_test(array_of_string)
ei_add_test(num_dimensions)
add_executable(bug1213 bug1213.cpp bug1213_main.cpp)

View File

@@ -140,7 +140,7 @@ void check_indexed_view()
"500 501 502 503 504 505 506 507 508 509")
);
// takes the row numer 3, and repeat it 5 times
// take row number 3, and repeat it 5 times
VERIFY( MATCH( A(seqN(3,5,0), all),
"300 301 302 303 304 305 306 307 308 309\n"
"300 301 302 303 304 305 306 307 308 309\n"
@@ -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

@@ -345,6 +345,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; \
@@ -365,7 +367,7 @@ template<> inline long double test_precision<std::complex<long double> >() { ret
inline bool test_isApprox(const short& a, const short& b)
{ return internal::isApprox(a, b, test_precision<short>()); }
inline bool test_isApprox(const unsigned short& a, const unsigned short& b)
{ return internal::isApprox(a, b, test_precision<unsigned long>()); }
{ return internal::isApprox(a, b, test_precision<unsigned short>()); }
inline bool test_isApprox(const unsigned int& a, const unsigned int& b)
{ return internal::isApprox(a, b, test_precision<unsigned int>()); }
inline bool test_isApprox(const long& a, const long& b)

View File

@@ -205,7 +205,6 @@ 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>() );
}
}

90
test/num_dimensions.cpp Normal file
View File

@@ -0,0 +1,90 @@
// This file is part of Eigen, a lightweight C++ template library
// for linear algebra.
//
// Copyright (C) 2018 Gael Guennebaud <gael.guennebaud@inria.fr>
//
// This Source Code Form is subject to the terms of the Mozilla
// 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/.
#include "main.h"
#include <Eigen/SparseCore>
template<int ExpectedDim,typename Xpr>
void check_dim(const Xpr& ) {
STATIC_CHECK( Xpr::NumDimensions == ExpectedDim );
}
#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_num_dimensions()
{
int n = 10;
ArrayXXd A(n,n);
CALL_SUBTEST( check_dim<2>(A) );
CALL_SUBTEST( check_dim<2>(A.block(1,1,2,2)) );
CALL_SUBTEST( check_dim<1>(A.col(1)) );
CALL_SUBTEST( check_dim<1>(A.row(1)) );
MatrixXd M(n,n);
CALL_SUBTEST( check_dim<0>(M.row(1)*M.col(1)) );
SparseMatrix<double> S(n,n);
CALL_SUBTEST( check_dim<2>(S) );
CALL_SUBTEST( check_dim<2>(S.block(1,1,2,2)) );
CALL_SUBTEST( check_dim<1>(S.col(1)) );
CALL_SUBTEST( check_dim<1>(S.row(1)) );
SparseVector<double> s(n);
CALL_SUBTEST( check_dim<1>(s) );
CALL_SUBTEST( check_dim<1>(s.head(2)) );
#if EIGEN_HAS_CXX11
CALL_SUBTEST( map_num_dimensions<TArray>() );
CALL_SUBTEST( map_num_dimensions<TMatrix>() );
#endif
}