Implement evaluators for sparse * sparse products

This commit is contained in:
Gael Guennebaud
2014-07-01 11:50:20 +02:00
parent 0ad7a644df
commit 441f97b2df
4 changed files with 88 additions and 4 deletions

View File

@@ -36,6 +36,11 @@ static void conservative_sparse_sparse_product_impl(const Lhs& lhs, const Rhs& r
// per column of the lhs.
// Therefore, we have nnz(lhs*rhs) = nnz(lhs) + nnz(rhs)
Index estimated_nnz_prod = lhs.nonZeros() + rhs.nonZeros();
#ifdef EIGEN_TEST_EVALUATORS
typename evaluator<Lhs>::type lhsEval(lhs);
typename evaluator<Rhs>::type rhsEval(rhs);
#endif
res.setZero();
res.reserve(Index(estimated_nnz_prod));
@@ -45,11 +50,19 @@ static void conservative_sparse_sparse_product_impl(const Lhs& lhs, const Rhs& r
res.startVec(j);
Index nnz = 0;
#ifndef EIGEN_TEST_EVALUATORS
for (typename Rhs::InnerIterator rhsIt(rhs, j); rhsIt; ++rhsIt)
#else
for (typename evaluator<Rhs>::InnerIterator rhsIt(rhsEval, j); rhsIt; ++rhsIt)
#endif
{
Scalar y = rhsIt.value();
Index k = rhsIt.index();
#ifndef EIGEN_TEST_EVALUATORS
for (typename Lhs::InnerIterator lhsIt(lhs, k); lhsIt; ++lhsIt)
#else
for (typename evaluator<Lhs>::InnerIterator lhsIt(lhsEval, k); lhsIt; ++lhsIt)
#endif
{
Index i = lhsIt.index();
Scalar x = lhsIt.value();