From c5a3777666f5876ced7274297c797dac555f53e0 Mon Sep 17 00:00:00 2001 From: Christoph Hertzberg Date: Fri, 31 Oct 2014 17:19:05 +0100 Subject: Regression test for (invalid) bug #900. We should make it possible somehow to increase the problem size depending on the available RAM. --- test/sparse_basic.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'test/sparse_basic.cpp') diff --git a/test/sparse_basic.cpp b/test/sparse_basic.cpp index 02a568cf2..2380dfa34 100644 --- a/test/sparse_basic.cpp +++ b/test/sparse_basic.cpp @@ -520,6 +520,32 @@ template void sparse_basic(const SparseMatrixType& re } +template +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 TripletType; +std::vector triplets; +double nelements = density * rows*cols; +VERIFY(nelements>=0 && nelements < NumTraits::highest()); +Index ntriplets = Index(nelements); +triplets.reserve(ntriplets); +Scalar sum = Scalar(0); +for(Index i=0;i(0,rows-1); + Index c = internal::random(0,cols-1); + Scalar v = internal::random(); + 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 test_sparse_basic() { for(int i = 0; i < g_repeat; i++) { @@ -539,4 +565,8 @@ void test_sparse_basic() CALL_SUBTEST_1(( sparse_basic(SparseMatrix(short(r), short(c))) )); CALL_SUBTEST_1(( sparse_basic(SparseMatrix(short(r), short(c))) )); } + + // Regression test for bug 900: (manually insert higher values here, if you have enough RAM): + CALL_SUBTEST_3((big_sparse_triplet >(10000, 10000, 0.125))); + CALL_SUBTEST_4((big_sparse_triplet >(10000, 10000, 0.125))); } -- cgit v1.2.3