diff options
author | Gael Guennebaud <g.gael@free.fr> | 2015-10-13 10:53:38 +0200 |
---|---|---|
committer | Gael Guennebaud <g.gael@free.fr> | 2015-10-13 10:53:38 +0200 |
commit | a44d91a0b213f513468c5b09221250513d271205 (patch) | |
tree | f59649170587c8a19b87b06f51cc6142fa743625 /test/sparse_basic.cpp | |
parent | ac22b66f1c724cc3a3289585e3847a743e5fe939 (diff) |
extend unit test for SparseMatrix::prune
Diffstat (limited to 'test/sparse_basic.cpp')
-rw-r--r-- | test/sparse_basic.cpp | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/test/sparse_basic.cpp b/test/sparse_basic.cpp index 492b3a4f2..95bbfab0e 100644 --- a/test/sparse_basic.cpp +++ b/test/sparse_basic.cpp @@ -219,10 +219,10 @@ template<typename SparseMatrixType> void sparse_basic(const SparseMatrixType& re refM2.setZero(); int countFalseNonZero = 0; int countTrueNonZero = 0; - for (Index j=0; j<m2.outerSize(); ++j) + m2.reserve(VectorXi::Constant(m2.outerSize(), int(m2.innerSize()))); + for (Index j=0; j<m2.cols(); ++j) { - m2.startVec(j); - for (Index i=0; i<m2.innerSize(); ++i) + for (Index i=0; i<m2.rows(); ++i) { float x = internal::random<float>(0,1); if (x<0.1) @@ -232,22 +232,21 @@ template<typename SparseMatrixType> void sparse_basic(const SparseMatrixType& re else if (x<0.5) { countFalseNonZero++; - m2.insertBackByOuterInner(j,i) = Scalar(0); + m2.insert(i,j) = Scalar(0); } else { countTrueNonZero++; - m2.insertBackByOuterInner(j,i) = Scalar(1); - if(SparseMatrixType::IsRowMajor) - refM2(j,i) = Scalar(1); - else - refM2(i,j) = Scalar(1); + m2.insert(i,j) = Scalar(1); + refM2(i,j) = Scalar(1); } } } - m2.finalize(); + if(internal::random<bool>()) + m2.makeCompressed(); VERIFY(countFalseNonZero+countTrueNonZero == m2.nonZeros()); - VERIFY_IS_APPROX(m2, refM2); + if(countTrueNonZero>0) + VERIFY_IS_APPROX(m2, refM2); m2.prune(Scalar(1)); VERIFY(countTrueNonZero==m2.nonZeros()); VERIFY_IS_APPROX(m2, refM2); |