mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-06-04 18:54:00 +08:00
Save one extra temporary when assigning a sparse product to a row-major sparse matrix
This commit is contained in:
parent
95177362ed
commit
ab615e4114
@ -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>
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user