Fix #1974: assertion when reserving an empty sparse matrix

This commit is contained in:
Gael Guennebaud 2020-08-26 12:32:20 +02:00
parent 8bb0febaf9
commit 25424d91f6
2 changed files with 10 additions and 1 deletions

View File

@ -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]);
}

View File

@ -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));
}
}