aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/sparse_basic.cpp
diff options
context:
space:
mode:
authorGravatar Gael Guennebaud <g.gael@free.fr>2016-11-14 14:05:53 +0100
committerGravatar Gael Guennebaud <g.gael@free.fr>2016-11-14 14:05:53 +0100
commiteedb87f4ba7fa835808168952f70acac6e458452 (patch)
tree3617d5793477f22da631648aaae2c5a6074ad4ab /test/sparse_basic.cpp
parentf4722aa47991823d2f002e57ce45850790ea86b9 (diff)
Fix regression in SparseMatrix::ReverseInnerIterator
Diffstat (limited to 'test/sparse_basic.cpp')
-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 7b5f3eb38..552bbac4d 100644
--- a/test/sparse_basic.cpp
+++ b/test/sparse_basic.cpp
@@ -219,6 +219,36 @@ template<typename SparseMatrixType> void sparse_basic(const SparseMatrixType& re
}
}
+ // test reverse iterators
+ {
+ DenseMatrix refMat2 = DenseMatrix::Zero(rows, cols);
+ SparseMatrixType m2(rows, cols);
+ initSparse<Scalar>(density, refMat2, m2);
+ std::vector<Scalar> ref_value(m2.innerSize());
+ std::vector<Index> ref_index(m2.innerSize());
+ if(internal::random<bool>())
+ m2.makeCompressed();
+ for(Index j = 0; j<m2.outerSize(); ++j)
+ {
+ Index count_forward = 0;
+
+ for(typename SparseMatrixType::InnerIterator it(m2,j); it; ++it)
+ {
+ ref_value[ref_value.size()-1-count_forward] = it.value();
+ ref_index[ref_index.size()-1-count_forward] = it.index();
+ count_forward++;
+ }
+ Index count_reverse = 0;
+ for(typename SparseMatrixType::ReverseInnerIterator it(m2,j); it; --it)
+ {
+ VERIFY_IS_APPROX( std::abs(ref_value[ref_value.size()-count_forward+count_reverse])+1, std::abs(it.value())+1);
+ VERIFY_IS_EQUAL( ref_index[ref_index.size()-count_forward+count_reverse] , it.index());
+ count_reverse++;
+ }
+ VERIFY_IS_EQUAL(count_forward, count_reverse);
+ }
+ }
+
// test transpose
{
DenseMatrix refMat2 = DenseMatrix::Zero(rows, cols);