From da1a34a6ba6ebed3c4174a1300ad75764f1409e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20S=C3=A1nchez?= Date: Tue, 2 Sep 2025 22:51:17 +0000 Subject: [PATCH] Zero-out matrix for empty set of triplets. --- Eigen/src/SparseCore/SparseMatrix.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Eigen/src/SparseCore/SparseMatrix.h b/Eigen/src/SparseCore/SparseMatrix.h index 7ddb6fab9..8fcdfdf19 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,