diff --git a/Eigen/src/SparseCore/SparseMatrix.h b/Eigen/src/SparseCore/SparseMatrix.h index 7ddb6fab901621f15ff026d4ec405509f13abf68..8fcdfdf1968059744efef8b9c08c5167fcf54fca 100644 --- a/Eigen/src/SparseCore/SparseMatrix.h +++ b/Eigen/src/SparseCore/SparseMatrix.h @@ -1130,7 +1130,11 @@ void set_from_triplets(const InputIterator& begin, const InputIterator& end, Spa using TransposedSparseMatrix = SparseMatrix; - if (begin == end) return; + if (begin == end) { + // Clear out existing data (if any). + mat.setZero(); + return; + } // There are two strategies to consider for constructing a matrix from unordered triplets: // A) construct the 'mat' in its native storage order and sort in-place (less memory); or,