Fix inner iterator for sparse block.

This commit is contained in:
Antonio Sánchez 2022-08-03 17:26:12 +00:00 committed by Rasmus Munk Larsen
parent 39d22ef46b
commit 5a1c7807e6
2 changed files with 20 additions and 2 deletions

View File

@ -196,8 +196,7 @@ class SparseCompressedBase<Derived>::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);
}

View File

@ -288,6 +288,25 @@ template<typename SparseMatrixType> 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<Scalar>(density, refMat2, m2);
Index j0 =internal::random<Index>(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)