diff options
author | Christoph Hertzberg <chtz@informatik.uni-bremen.de> | 2014-12-04 22:48:53 +0100 |
---|---|---|
committer | Christoph Hertzberg <chtz@informatik.uni-bremen.de> | 2014-12-04 22:48:53 +0100 |
commit | e8cdbedefb1913b5a0e2f2b7d38470f081cb8d29 (patch) | |
tree | b64cb33df57f4cfcd87bf42643279629dc0900d3 /test | |
parent | 6ccf97f3e6ce39c210e225ba7aae66da15b71660 (diff) |
bug #877, bug #572: Introduce a global Index typedef. Rename Sparse*::Index to StorageIndex, make Dense*::StorageIndex an alias to DenseIndex. Overall this commit gets rid of all Index conversion warnings.
Diffstat (limited to 'test')
-rw-r--r-- | test/bandmatrix.cpp | 3 | ||||
-rw-r--r-- | test/main.h | 10 | ||||
-rw-r--r-- | test/nullary.cpp | 4 | ||||
-rw-r--r-- | test/product.h | 1 | ||||
-rw-r--r-- | test/sparse_basic.cpp | 98 | ||||
-rw-r--r-- | test/sparse_permutations.cpp | 8 | ||||
-rw-r--r-- | test/sparse_product.cpp | 2 | ||||
-rw-r--r-- | test/sparse_solver.h | 6 |
8 files changed, 62 insertions, 70 deletions
diff --git a/test/bandmatrix.cpp b/test/bandmatrix.cpp index 5e4e8e07b..f8c38f7c3 100644 --- a/test/bandmatrix.cpp +++ b/test/bandmatrix.cpp @@ -11,7 +11,6 @@ template<typename MatrixType> void bandmatrix(const MatrixType& _m) { - typedef typename MatrixType::Index Index; typedef typename MatrixType::Scalar Scalar; typedef typename NumTraits<Scalar>::Real RealScalar; typedef Matrix<Scalar,Dynamic,Dynamic> DenseMatrixType; @@ -62,8 +61,6 @@ using Eigen::internal::BandMatrix; void test_bandmatrix() { - typedef BandMatrix<float>::Index Index; - for(int i = 0; i < 10*g_repeat ; i++) { Index rows = internal::random<Index>(1,10); Index cols = internal::random<Index>(1,10); diff --git a/test/main.h b/test/main.h index b3fa68476..a1ccd28b5 100644 --- a/test/main.h +++ b/test/main.h @@ -373,11 +373,10 @@ bool test_is_equal(const T& actual, const U& expected) */ // Forward declaration to avoid ICC warning template<typename MatrixType> -void createRandomPIMatrixOfRank(typename MatrixType::Index desired_rank, typename MatrixType::Index rows, typename MatrixType::Index cols, MatrixType& m); +void createRandomPIMatrixOfRank(Index desired_rank, Index rows, Index cols, MatrixType& m); template<typename MatrixType> -void createRandomPIMatrixOfRank(typename MatrixType::Index desired_rank, typename MatrixType::Index rows, typename MatrixType::Index cols, MatrixType& m) +void createRandomPIMatrixOfRank(Index desired_rank, Index rows, Index cols, MatrixType& m) { - typedef typename internal::traits<MatrixType>::Index Index; typedef typename internal::traits<MatrixType>::Scalar Scalar; enum { Rows = MatrixType::RowsAtCompileTime, Cols = MatrixType::ColsAtCompileTime }; @@ -414,11 +413,10 @@ void createRandomPIMatrixOfRank(typename MatrixType::Index desired_rank, typenam // Forward declaration to avoid ICC warning template<typename PermutationVectorType> -void randomPermutationVector(PermutationVectorType& v, typename PermutationVectorType::Index size); +void randomPermutationVector(PermutationVectorType& v, Index size); template<typename PermutationVectorType> -void randomPermutationVector(PermutationVectorType& v, typename PermutationVectorType::Index size) +void randomPermutationVector(PermutationVectorType& v, Index size) { - typedef typename PermutationVectorType::Index Index; typedef typename PermutationVectorType::Scalar Scalar; v.resize(size); for(Index i = 0; i < size; ++i) v(i) = Scalar(i); diff --git a/test/nullary.cpp b/test/nullary.cpp index 5408d88b2..a19c674e4 100644 --- a/test/nullary.cpp +++ b/test/nullary.cpp @@ -35,8 +35,8 @@ bool equalsIdentity(const MatrixType& A) template<typename VectorType> void testVectorType(const VectorType& base) { - typedef typename internal::traits<VectorType>::Index Index; - typedef typename internal::traits<VectorType>::Scalar Scalar; + typedef typename VectorType::Index Index; + typedef typename VectorType::Scalar Scalar; const Index size = base.size(); diff --git a/test/product.h b/test/product.h index 0b3abe402..672d0cee9 100644 --- a/test/product.h +++ b/test/product.h @@ -22,7 +22,6 @@ template<typename MatrixType> void product(const MatrixType& m) /* this test covers the following files: Identity.h Product.h */ - typedef typename MatrixType::Index Index; typedef typename MatrixType::Scalar Scalar; typedef Matrix<Scalar, MatrixType::RowsAtCompileTime, 1> RowVectorType; typedef Matrix<Scalar, MatrixType::ColsAtCompileTime, 1> ColVectorType; diff --git a/test/sparse_basic.cpp b/test/sparse_basic.cpp index 097959c84..a26fd5dcd 100644 --- a/test/sparse_basic.cpp +++ b/test/sparse_basic.cpp @@ -13,11 +13,11 @@ template<typename SparseMatrixType> void sparse_basic(const SparseMatrixType& ref) { - typedef typename SparseMatrixType::Index Index; - typedef Matrix<Index,2,1> Vector2; + typedef typename SparseMatrixType::StorageIndex StorageIndex; + typedef Matrix<StorageIndex,2,1> Vector2; - const Index rows = ref.rows(); - const Index cols = ref.cols(); + const StorageIndex rows = ref.rows(); + const StorageIndex cols = ref.cols(); const Index inner = ref.innerSize(); const Index outer = ref.outerSize(); @@ -56,27 +56,27 @@ template<typename SparseMatrixType> void sparse_basic(const SparseMatrixType& re VERIFY_IS_APPROX(m, refMat); // test InnerIterators and Block expressions - for (int t=0; t<10; ++t) + for (Index t=0; t<10; ++t) { - int j = internal::random<int>(0,cols-1); - int i = internal::random<int>(0,rows-1); - int w = internal::random<int>(1,cols-j-1); - int h = internal::random<int>(1,rows-i-1); + Index j = internal::random<Index>(0,cols-1); + Index i = internal::random<Index>(0,rows-1); + Index w = internal::random<Index>(1,cols-j-1); + Index h = internal::random<Index>(1,rows-i-1); VERIFY_IS_APPROX(m.block(i,j,h,w), refMat.block(i,j,h,w)); - for(int c=0; c<w; c++) + for(Index c=0; c<w; c++) { VERIFY_IS_APPROX(m.block(i,j,h,w).col(c), refMat.block(i,j,h,w).col(c)); - for(int r=0; r<h; r++) + for(Index r=0; r<h; r++) { // FIXME col().coeff() not implemented yet // VERIFY_IS_APPROX(m.block(i,j,h,w).col(c).coeff(r), refMat.block(i,j,h,w).col(c).coeff(r)); } } - for(int r=0; r<h; r++) + for(Index r=0; r<h; r++) { VERIFY_IS_APPROX(m.block(i,j,h,w).row(r), refMat.block(i,j,h,w).row(r)); - for(int c=0; c<w; c++) + for(Index c=0; c<w; c++) { // FIXME row().coeff() not implemented yet // VERIFY_IS_APPROX(m.block(i,j,h,w).row(r).coeff(c), refMat.block(i,j,h,w).row(r).coeff(c)); @@ -84,13 +84,13 @@ template<typename SparseMatrixType> void sparse_basic(const SparseMatrixType& re } } - for(int c=0; c<cols; c++) + for(Index c=0; c<cols; c++) { VERIFY_IS_APPROX(m.col(c) + m.col(c), (m + m).col(c)); VERIFY_IS_APPROX(m.col(c) + m.col(c), refMat.col(c) + refMat.col(c)); } - for(int r=0; r<rows; r++) + for(Index r=0; r<rows; r++) { VERIFY_IS_APPROX(m.row(r) + m.row(r), (m + m).row(r)); VERIFY_IS_APPROX(m.row(r) + m.row(r), refMat.row(r) + refMat.row(r)); @@ -153,7 +153,7 @@ template<typename SparseMatrixType> void sparse_basic(const SparseMatrixType& re SparseMatrixType m2(rows,cols); VectorXi r(VectorXi::Constant(m2.outerSize(), ((mode%2)==0) ? int(m2.innerSize()) : std::max<int>(1,int(m2.innerSize())/8))); m2.reserve(r); - for (int k=0; k<rows*cols; ++k) + for (Index k=0; k<rows*cols; ++k) { Index i = internal::random<Index>(0,rows-1); Index j = internal::random<Index>(0,cols-1); @@ -390,7 +390,7 @@ template<typename SparseMatrixType> void sparse_basic(const SparseMatrixType& re // test setFromTriplets { - typedef Triplet<Scalar,Index> TripletType; + typedef Triplet<Scalar,StorageIndex> TripletType; std::vector<TripletType> triplets; Index ntriplets = rows*cols; triplets.reserve(ntriplets); @@ -398,8 +398,8 @@ template<typename SparseMatrixType> void sparse_basic(const SparseMatrixType& re refMat.setZero(); for(Index i=0;i<ntriplets;++i) { - Index r = internal::random<Index>(0,rows-1); - Index c = internal::random<Index>(0,cols-1); + StorageIndex r = internal::random<StorageIndex>(0,rows-1); + StorageIndex c = internal::random<StorageIndex>(0,cols-1); Scalar v = internal::random<Scalar>(); triplets.push_back(TripletType(r,c,v)); refMat(r,c) += v; @@ -482,17 +482,17 @@ template<typename SparseMatrixType> void sparse_basic(const SparseMatrixType& re // test conservative resize { - std::vector< std::pair<Index,Index> > inc; + std::vector< std::pair<StorageIndex,StorageIndex> > inc; if(rows > 3 && cols > 2) - inc.push_back(std::pair<Index,Index>(-3,-2)); - inc.push_back(std::pair<Index,Index>(0,0)); - inc.push_back(std::pair<Index,Index>(3,2)); - inc.push_back(std::pair<Index,Index>(3,0)); - inc.push_back(std::pair<Index,Index>(0,3)); + inc.push_back(std::pair<StorageIndex,StorageIndex>(-3,-2)); + inc.push_back(std::pair<StorageIndex,StorageIndex>(0,0)); + inc.push_back(std::pair<StorageIndex,StorageIndex>(3,2)); + inc.push_back(std::pair<StorageIndex,StorageIndex>(3,0)); + inc.push_back(std::pair<StorageIndex,StorageIndex>(0,3)); for(size_t i = 0; i< inc.size(); i++) { - Index incRows = inc[i].first; - Index incCols = inc[i].second; + StorageIndex incRows = inc[i].first; + StorageIndex incCols = inc[i].second; SparseMatrixType m1(rows, cols); DenseMatrix refMat1 = DenseMatrix::Zero(rows, cols); initSparse<Scalar>(density, refMat1, m1); @@ -527,28 +527,28 @@ template<typename SparseMatrixType> void sparse_basic(const SparseMatrixType& re template<typename SparseMatrixType> -void big_sparse_triplet(typename SparseMatrixType::Index rows, typename SparseMatrixType::Index cols, double density) { -typedef typename SparseMatrixType::Index Index; -typedef typename SparseMatrixType::Scalar Scalar; -typedef Triplet<Scalar,Index> TripletType; -std::vector<TripletType> triplets; -double nelements = density * rows*cols; -VERIFY(nelements>=0 && nelements < NumTraits<Index>::highest()); -Index ntriplets = Index(nelements); -triplets.reserve(ntriplets); -Scalar sum = Scalar(0); -for(Index i=0;i<ntriplets;++i) -{ - Index r = internal::random<Index>(0,rows-1); - Index c = internal::random<Index>(0,cols-1); - Scalar v = internal::random<Scalar>(); - triplets.push_back(TripletType(r,c,v)); - sum += v; -} -SparseMatrixType m(rows,cols); -m.setFromTriplets(triplets.begin(), triplets.end()); -VERIFY(m.nonZeros() <= ntriplets); -VERIFY_IS_APPROX(sum, m.sum()); +void big_sparse_triplet(Index rows, Index cols, double density) { + typedef typename SparseMatrixType::StorageIndex StorageIndex; + typedef typename SparseMatrixType::Scalar Scalar; + typedef Triplet<Scalar,Index> TripletType; + std::vector<TripletType> triplets; + double nelements = density * rows*cols; + VERIFY(nelements>=0 && nelements < NumTraits<StorageIndex>::highest()); + Index ntriplets = Index(nelements); + triplets.reserve(ntriplets); + Scalar sum = Scalar(0); + for(Index i=0;i<ntriplets;++i) + { + Index r = internal::random<Index>(0,rows-1); + Index c = internal::random<Index>(0,cols-1); + Scalar v = internal::random<Scalar>(); + triplets.push_back(TripletType(r,c,v)); + sum += v; + } + SparseMatrixType m(rows,cols); + m.setFromTriplets(triplets.begin(), triplets.end()); + VERIFY(m.nonZeros() <= ntriplets); + VERIFY_IS_APPROX(sum, m.sum()); } diff --git a/test/sparse_permutations.cpp b/test/sparse_permutations.cpp index e4ce1d679..dec586776 100644 --- a/test/sparse_permutations.cpp +++ b/test/sparse_permutations.cpp @@ -11,15 +11,13 @@ template<int OtherStorage, typename SparseMatrixType> void sparse_permutations(const SparseMatrixType& ref) { - typedef typename SparseMatrixType::Index Index; - const Index rows = ref.rows(); const Index cols = ref.cols(); typedef typename SparseMatrixType::Scalar Scalar; - typedef typename SparseMatrixType::Index Index; - typedef SparseMatrix<Scalar, OtherStorage, Index> OtherSparseMatrixType; + typedef typename SparseMatrixType::StorageIndex StorageIndex; + typedef SparseMatrix<Scalar, OtherStorage, StorageIndex> OtherSparseMatrixType; typedef Matrix<Scalar,Dynamic,Dynamic> DenseMatrix; - typedef Matrix<Index,Dynamic,1> VectorI; + typedef Matrix<StorageIndex,Dynamic,1> VectorI; double density = (std::max)(8./(rows*cols), 0.01); diff --git a/test/sparse_product.cpp b/test/sparse_product.cpp index 366e27274..b3f653d0e 100644 --- a/test/sparse_product.cpp +++ b/test/sparse_product.cpp @@ -11,7 +11,7 @@ template<typename SparseMatrixType> void sparse_product() { - typedef typename SparseMatrixType::Index Index; + typedef typename SparseMatrixType::StorageIndex Index; Index n = 100; const Index rows = internal::random<Index>(1,n); const Index cols = internal::random<Index>(1,n); diff --git a/test/sparse_solver.h b/test/sparse_solver.h index ee350d561..afda26b93 100644 --- a/test/sparse_solver.h +++ b/test/sparse_solver.h @@ -15,7 +15,7 @@ void check_sparse_solving(Solver& solver, const typename Solver::MatrixType& A, { typedef typename Solver::MatrixType Mat; typedef typename Mat::Scalar Scalar; - typedef typename Mat::Index Index; + typedef typename Mat::StorageIndex StorageIndex; DenseRhs refX = dA.lu().solve(db); { @@ -60,7 +60,7 @@ void check_sparse_solving(Solver& solver, const typename Solver::MatrixType& A, x.setZero(); // test with Map - MappedSparseMatrix<Scalar,Mat::Options,Index> Am(A.rows(), A.cols(), A.nonZeros(), const_cast<Index*>(A.outerIndexPtr()), const_cast<Index*>(A.innerIndexPtr()), const_cast<Scalar*>(A.valuePtr())); + MappedSparseMatrix<Scalar,Mat::Options,StorageIndex> Am(A.rows(), A.cols(), A.nonZeros(), const_cast<StorageIndex*>(A.outerIndexPtr()), const_cast<StorageIndex*>(A.innerIndexPtr()), const_cast<Scalar*>(A.valuePtr())); solver.compute(Am); if (solver.info() != Success) { @@ -95,7 +95,7 @@ void check_sparse_solving(Solver& solver, const typename Solver::MatrixType& A, // test uncompressed inputs { Mat A2 = A; - A2.reserve((ArrayXf::Random(A.outerSize())+2).template cast<typename Mat::Index>().eval()); + A2.reserve((ArrayXf::Random(A.outerSize())+2).template cast<typename Mat::StorageIndex>().eval()); solver.compute(A2); Rhs x = solver.solve(b); VERIFY(x.isApprox(refX,test_precision<Scalar>())); |