aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Gael Guennebaud <g.gael@free.fr>2020-08-26 12:32:20 +0200
committerGravatar Gael Guennebaud <g.gael@free.fr>2020-08-26 12:32:20 +0200
commit25424d91f60a9f858e7dc1c7936021cc1dd72019 (patch)
tree4f03de72f59a571c94834b32cc1f4f22c3b97ad8
parent8bb0febaf9c911a9eb560c49983033b707e757d1 (diff)
Fix #1974: assertion when reserving an empty sparse matrix
-rw-r--r--Eigen/src/SparseCore/SparseMatrix.h3
-rw-r--r--test/sparse_basic.cpp8
2 files changed, 10 insertions, 1 deletions
diff --git a/Eigen/src/SparseCore/SparseMatrix.h b/Eigen/src/SparseCore/SparseMatrix.h
index 2218b220b..4e639d1f8 100644
--- a/Eigen/src/SparseCore/SparseMatrix.h
+++ b/Eigen/src/SparseCore/SparseMatrix.h
@@ -329,7 +329,8 @@ class SparseMatrix
m_outerIndex[j] = newOuterIndex[j];
m_innerNonZeros[j] = innerNNZ;
}
- m_outerIndex[m_outerSize] = m_outerIndex[m_outerSize-1] + m_innerNonZeros[m_outerSize-1] + reserveSizes[m_outerSize-1];
+ if(m_outerSize>0)
+ m_outerIndex[m_outerSize] = m_outerIndex[m_outerSize-1] + m_innerNonZeros[m_outerSize-1] + reserveSizes[m_outerSize-1];
m_data.resize(m_outerIndex[m_outerSize]);
}
diff --git a/test/sparse_basic.cpp b/test/sparse_basic.cpp
index 9e735b38b..5f8762172 100644
--- a/test/sparse_basic.cpp
+++ b/test/sparse_basic.cpp
@@ -662,6 +662,14 @@ template<typename SparseMatrixType> void sparse_basic(const SparseMatrixType& re
iters[0] = IteratorType(m2,0);
iters[1] = IteratorType(m2,m2.outerSize()-1);
}
+
+ // test reserve with empty rows/columns
+ {
+ SparseMatrixType m1(0,cols);
+ m1.reserve(ArrayXi::Constant(m1.outerSize(),1));
+ SparseMatrixType m2(rows,0);
+ m2.reserve(ArrayXi::Constant(m2.outerSize(),1));
+ }
}