From 5a1c7807e6eedbeea4338043e55c973d9f35d2d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20S=C3=A1nchez?= Date: Wed, 3 Aug 2022 17:26:12 +0000 Subject: [PATCH] Fix inner iterator for sparse block. --- Eigen/src/SparseCore/SparseCompressedBase.h | 3 +-- test/sparse_block.cpp | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/Eigen/src/SparseCore/SparseCompressedBase.h b/Eigen/src/SparseCore/SparseCompressedBase.h index b3c716d0a..ede576681 100644 --- a/Eigen/src/SparseCore/SparseCompressedBase.h +++ b/Eigen/src/SparseCore/SparseCompressedBase.h @@ -196,8 +196,7 @@ class SparseCompressedBase::InnerIterator } } - explicit InnerIterator(const SparseCompressedBase& mat) - : m_values(mat.valuePtr()), m_indices(mat.innerIndexPtr()), m_outer(0), m_id(0), m_end(mat.nonZeros()) + explicit InnerIterator(const SparseCompressedBase& mat) : InnerIterator(mat, Index(0)) { EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived); } diff --git a/test/sparse_block.cpp b/test/sparse_block.cpp index 2b19ac57f..955aa600a 100644 --- a/test/sparse_block.cpp +++ b/test/sparse_block.cpp @@ -288,6 +288,25 @@ template void sparse_block(const SparseMatrixType& re VERIFY_IS_APPROX(m3, refMat3); } } + + // Explicit inner iterator. + { + DenseMatrix refMat2 = DenseMatrix::Zero(rows, cols); + SparseMatrixType m2(rows, cols); + initSparse(density, refMat2, m2); + + Index j0 =internal::random(0, outer - 1); + auto v = innervec(m2, j0); + + typename decltype(v)::InnerIterator block_iterator(v); + typename SparseMatrixType::InnerIterator matrix_iterator(m2, j0); + while (block_iterator) { + VERIFY_IS_EQUAL(block_iterator.index(), matrix_iterator.index()); + ++block_iterator; + ++matrix_iterator; + } + + } } EIGEN_DECLARE_TEST(sparse_block)