Save one extra temporary when assigning a sparse product to a row-major sparse matrix

This commit is contained in:
Gael Guennebaud 2020-05-30 23:14:29 +02:00
parent 95177362ed
commit ab615e4114
3 changed files with 16 additions and 1 deletions

View File

@ -782,6 +782,9 @@ class SparseMatrix
template<typename OtherDerived>
inline SparseMatrix& operator=(const EigenBase<OtherDerived>& other)
{ return Base::operator=(other.derived()); }
template<typename Lhs, typename Rhs>
inline SparseMatrix& operator=(const Product<Lhs,Rhs,AliasFreeProduct>& other);
#endif // EIGEN_PARSED_BY_DOXYGEN
template<typename OtherDerived>

View File

@ -164,6 +164,18 @@ protected:
} // end namespace internal
// sparse matrix = sparse-product (can be sparse*sparse, sparse*perm, etc.)
template<typename Scalar, int _Options, typename _StorageIndex>
template<typename Lhs, typename Rhs>
SparseMatrix<Scalar,_Options,_StorageIndex>& SparseMatrix<Scalar,_Options,_StorageIndex>::operator=(const Product<Lhs,Rhs,AliasFreeProduct>& src)
{
// std::cout << "in Assignment : " << DstOptions << "\n";
SparseMatrix dst(src.rows(),src.cols());
internal::generic_product_impl<Lhs, Rhs>::evalTo(dst,src.lhs(),src.rhs());
this->swap(dst);
return *this;
}
} // end namespace Eigen
#endif // EIGEN_SPARSEPRODUCT_H

View File

@ -103,7 +103,7 @@ template<typename SparseMatrixType> void sparse_product()
// make sure the right product implementation is called:
if((!SparseMatrixType::IsRowMajor) && m2.rows()<=m3.cols())
{
VERIFY_EVALUATION_COUNT(m4 = m2*m3, 3); // 1 temp for the result + 2 for transposing and get a sorted result.
VERIFY_EVALUATION_COUNT(m4 = m2*m3, 2); // 2 for transposing and get a sorted result.
VERIFY_EVALUATION_COUNT(m4 = (m2*m3).pruned(0), 1);
VERIFY_EVALUATION_COUNT(m4 = (m2*m3).eval().pruned(0), 4);
}