diff --git a/Eigen/src/SparseCore/SparseMatrix.h b/Eigen/src/SparseCore/SparseMatrix.h index c8c31fd83..22a6bd803 100644 --- a/Eigen/src/SparseCore/SparseMatrix.h +++ b/Eigen/src/SparseCore/SparseMatrix.h @@ -437,6 +437,10 @@ class SparseMatrix template void setFromTriplets(const InputIterators& begin, const InputIterators& end); + template + void setFromTriplets(const InputIterators& begin, const InputIterators& end); + + template void sumupDuplicates(); //--- @@ -889,7 +893,7 @@ private: namespace internal { -template +template void set_from_triplets(const InputIterator& begin, const InputIterator& end, SparseMatrixType& mat, int Options = 0) { EIGEN_UNUSED_VARIABLE(Options); @@ -915,7 +919,7 @@ void set_from_triplets(const InputIterator& begin, const InputIterator& end, Spa trMat.insertBackUncompressed(it->row(),it->col()) = it->value(); // pass 3: - trMat.sumupDuplicates(); + trMat.template sumupDuplicates(); } // pass 4: transposed copy -> implicit sorting @@ -966,11 +970,24 @@ template template void SparseMatrix::setFromTriplets(const InputIterators& begin, const InputIterators& end) { - internal::set_from_triplets(begin, end, *this); + internal::set_from_triplets, internal::scalar_sum_op >(begin, end, *this); +} + +/** The same as setFromTriplets but when duplicates are met the functor \a DupFunctor is applied: + * \code + * value = DupFunctor()(OldValue, NewValue) + * \endcode + */ +template +template +void SparseMatrix::setFromTriplets(const InputIterators& begin, const InputIterators& end) +{ + internal::set_from_triplets, DupFunctor>(begin, end, *this); } /** \internal */ template +template void SparseMatrix::sumupDuplicates() { eigen_assert(!isCompressed()); @@ -989,7 +1006,7 @@ void SparseMatrix::sumupDuplicates() if(wi(i)>=start) { // we already meet this entry => accumulate it - m_data.value(wi(i)) += m_data.value(k); + m_data.value(wi(i)) = DupFunctor()(m_data.value(wi(i)), m_data.value(k)); } else {