aboutsummaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorGravatar Christoph Hertzberg <chtz@informatik.uni-bremen.de>2014-10-31 17:19:05 +0100
committerGravatar Christoph Hertzberg <chtz@informatik.uni-bremen.de>2014-10-31 17:19:05 +0100
commitc5a3777666f5876ced7274297c797dac555f53e0 (patch)
treea7fde4c150e82d279d9308554ed98af08edd09c1 /test
parent0833b82efd3988aaa71841b678bead016edd6bab (diff)
Regression test for (invalid) bug #900. We should make it possible somehow to increase the problem size depending on the available RAM.
Diffstat (limited to 'test')
-rw-r--r--test/sparse_basic.cpp30
1 files changed, 30 insertions, 0 deletions
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<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 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<double,ColMajor,short int>(short(r), short(c))) ));
CALL_SUBTEST_1(( sparse_basic(SparseMatrix<double,RowMajor,short int>(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<SparseMatrix<float, RowMajor, int> >(10000, 10000, 0.125)));
+ CALL_SUBTEST_4((big_sparse_triplet<SparseMatrix<double, ColMajor, long int> >(10000, 10000, 0.125)));
}