diff options
author | Gael Guennebaud <g.gael@free.fr> | 2018-06-08 17:11:45 +0200 |
---|---|---|
committer | Gael Guennebaud <g.gael@free.fr> | 2018-06-08 17:11:45 +0200 |
commit | cb4c9a6a9459a1c9bee1b22cabb5e8aa154968d9 (patch) | |
tree | 9f1abb957f503b5e93a609ede40b97e4a3bf6047 | |
parent | d6813fb1c565e0150cad0332b5afa6ac2e1ed286 (diff) |
bug #1531: make dedicatd unit testing for NumDimensions
-rw-r--r-- | test/CMakeLists.txt | 1 | ||||
-rw-r--r-- | test/mapped_matrix.cpp | 48 | ||||
-rw-r--r-- | test/num_dimensions.cpp | 90 |
3 files changed, 91 insertions, 48 deletions
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index af4fa73e4..ab3ff4795 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -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) diff --git a/test/mapped_matrix.cpp b/test/mapped_matrix.cpp index b9f36d8d6..7b9e1fe52 100644 --- a/test/mapped_matrix.cpp +++ b/test/mapped_matrix.cpp @@ -181,49 +181,6 @@ 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++) { @@ -250,9 +207,4 @@ void test_mapped_matrix() 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 } diff --git a/test/num_dimensions.cpp b/test/num_dimensions.cpp new file mode 100644 index 000000000..f5209283d --- /dev/null +++ b/test/num_dimensions.cpp @@ -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 +} |