diff --git a/Eigen/src/SparseCore/SparseMatrix.h b/Eigen/src/SparseCore/SparseMatrix.h index 782e59511..36646c8ab 100644 --- a/Eigen/src/SparseCore/SparseMatrix.h +++ b/Eigen/src/SparseCore/SparseMatrix.h @@ -1008,7 +1008,7 @@ class SparseMatrix : public SparseCompressedBase>::value; if (overwrite) { - if ((m_outerSize != n) || (m_innerSize != n)) resize(n, n); + if ((m_outerSize != n) || (m_innerSize != n) || (n == 0)) resize(n, n); } if (m_data.size() == 0 || overwrite) { diff --git a/test/sparse_basic.cpp b/test/sparse_basic.cpp index b239eab58..f1fd6b771 100644 --- a/test/sparse_basic.cpp +++ b/test/sparse_basic.cpp @@ -871,6 +871,10 @@ void sparse_basic(const SparseMatrixType& ref) { m2 -= d.asDiagonal(); refMat2 -= d.asDiagonal(); VERIFY_IS_APPROX(m2, refMat2); + + // zero-length diagonal + d = DenseVector(0); + SparseMatrixType m4(d.asDiagonal()); } // test conservative resize