Fix sparse_extra_3, disable counting temporaries for testing DynamicSparseMatrix.

Multiplication of column-major `DynamicSparseMatrix`es involves three
temporaries:
- two for transposing twice to sort the coefficients
(`ConservativeSparseSparseProduct.h`, L160-161)
- one for a final copy assignment (`SparseAssign.h`, L108)
The latter is avoided in an optimization for `SparseMatrix`.

Since `DynamicSparseMatrix` is deprecated in favor of `SparseMatrix`, it's not
worth the effort to optimize further, so I simply disabled counting
temporaries via a macro.

Note that due to the inclusion of `sparse_product.cpp`, the `sparse_extra`
tests actually re-run all the original `sparse_product` tests as well.

We may want to simply drop the `DynamicSparseMatrix` tests altogether, which
would eliminate the test duplication.

Related to #2048
This commit is contained in:
Antonio Sanchez 2020-11-18 13:23:13 -08:00 committed by Rasmus Munk Larsen
parent 11e4056f6b
commit a8fdcae55d
3 changed files with 25 additions and 20 deletions

View File

@ -155,7 +155,7 @@ struct conservative_sparse_sparse_product_selector<Lhs,Rhs,ResultType,ColMajor,C
else else
{ {
ColMajorMatrixAux resCol(lhs.rows(),rhs.cols()); ColMajorMatrixAux resCol(lhs.rows(),rhs.cols());
// ressort to transpose to sort the entries // resort to transpose to sort the entries
internal::conservative_sparse_sparse_product_impl<Lhs,Rhs,ColMajorMatrixAux>(lhs, rhs, resCol, false); internal::conservative_sparse_sparse_product_impl<Lhs,Rhs,ColMajorMatrixAux>(lhs, rhs, resCol, false);
RowMajorMatrix resRow(resCol); RowMajorMatrix resRow(resCol);
res = resRow.markAsRValue(); res = resRow.markAsRValue();

View File

@ -100,6 +100,7 @@ template<typename SparseMatrixType> void sparse_product()
VERIFY_IS_APPROX(m4=(m2t.transpose()*m3t.transpose()).pruned(0), refMat4=refMat2t.transpose()*refMat3t.transpose()); VERIFY_IS_APPROX(m4=(m2t.transpose()*m3t.transpose()).pruned(0), refMat4=refMat2t.transpose()*refMat3t.transpose());
VERIFY_IS_APPROX(m4=(m2*m3t.transpose()).pruned(0), refMat4=refMat2*refMat3t.transpose()); VERIFY_IS_APPROX(m4=(m2*m3t.transpose()).pruned(0), refMat4=refMat2*refMat3t.transpose());
#ifndef EIGEN_SPARSE_PRODUCT_IGNORE_TEMPORARY_COUNT
// make sure the right product implementation is called: // make sure the right product implementation is called:
if((!SparseMatrixType::IsRowMajor) && m2.rows()<=m3.cols()) if((!SparseMatrixType::IsRowMajor) && m2.rows()<=m3.cols())
{ {
@ -107,6 +108,7 @@ template<typename SparseMatrixType> void sparse_product()
VERIFY_EVALUATION_COUNT(m4 = (m2*m3).pruned(0), 1); VERIFY_EVALUATION_COUNT(m4 = (m2*m3).pruned(0), 1);
VERIFY_EVALUATION_COUNT(m4 = (m2*m3).eval().pruned(0), 4); VERIFY_EVALUATION_COUNT(m4 = (m2*m3).eval().pruned(0), 4);
} }
#endif
// and that pruning is effective: // and that pruning is effective:
{ {

View File

@ -22,6 +22,9 @@ static long g_dense_op_sparse_count = 0;
#endif #endif
#define EIGEN_NO_DEPRECATED_WARNING #define EIGEN_NO_DEPRECATED_WARNING
// Disable counting of temporaries, since sparse_product(DynamicSparseMatrix)
// has an extra copy-assignment.
#define EIGEN_SPARSE_PRODUCT_IGNORE_TEMPORARY_COUNT
#include "sparse_product.cpp" #include "sparse_product.cpp"
#if 0 // sparse_basic(DynamicSparseMatrix) does not compile at all -> disabled #if 0 // sparse_basic(DynamicSparseMatrix) does not compile at all -> disabled