aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Gael Guennebaud <g.gael@free.fr>2020-05-30 23:14:29 +0200
committerGravatar Gael Guennebaud <g.gael@free.fr>2020-05-30 23:15:12 +0200
commitab615e4114aafebcf44268aae93b97858f549a11 (patch)
treed032bd07671092a827e6ec101bee5042d21ec4d7
parent95177362edc9c814a102c8a2236695c632892232 (diff)
Save one extra temporary when assigning a sparse product to a row-major sparse matrix
-rw-r--r--Eigen/src/SparseCore/SparseMatrix.h3
-rw-r--r--Eigen/src/SparseCore/SparseProduct.h12
-rw-r--r--test/sparse_product.cpp2
3 files changed, 16 insertions, 1 deletions
diff --git a/Eigen/src/SparseCore/SparseMatrix.h b/Eigen/src/SparseCore/SparseMatrix.h
index e0910a2cb..2218b220b 100644
--- a/Eigen/src/SparseCore/SparseMatrix.h
+++ b/Eigen/src/SparseCore/SparseMatrix.h
@@ -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>
diff --git a/Eigen/src/SparseCore/SparseProduct.h b/Eigen/src/SparseCore/SparseProduct.h
index c495a7398..af8a7744d 100644
--- a/Eigen/src/SparseCore/SparseProduct.h
+++ b/Eigen/src/SparseCore/SparseProduct.h
@@ -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
diff --git a/test/sparse_product.cpp b/test/sparse_product.cpp
index db1b0e833..c8caebef7 100644
--- a/test/sparse_product.cpp
+++ b/test/sparse_product.cpp
@@ -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);
}