mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-09-12 17:33:15 +08:00
Fix SparseMatrix::conservativeResize() when one dimension is null
This commit is contained in:
parent
444c09e313
commit
5431473d67
@ -534,6 +534,9 @@ class SparseMatrix
|
|||||||
// No change
|
// No change
|
||||||
if (this->rows() == rows && this->cols() == cols) return;
|
if (this->rows() == rows && this->cols() == cols) return;
|
||||||
|
|
||||||
|
// If one dimension is null, then there is nothing to be preserved
|
||||||
|
if(rows==0 || cols==0) return resize(rows,cols);
|
||||||
|
|
||||||
Index innerChange = IsRowMajor ? cols - this->cols() : rows - this->rows();
|
Index innerChange = IsRowMajor ? cols - this->cols() : rows - this->rows();
|
||||||
Index outerChange = IsRowMajor ? rows - this->rows() : cols - this->cols();
|
Index outerChange = IsRowMajor ? rows - this->rows() : cols - this->cols();
|
||||||
Index newInnerSize = IsRowMajor ? cols : rows;
|
Index newInnerSize = IsRowMajor ? cols : rows;
|
||||||
@ -559,7 +562,8 @@ class SparseMatrix
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Change the m_innerNonZeros in case of a decrease of inner size
|
// Change the m_innerNonZeros in case of a decrease of inner size
|
||||||
if (m_innerNonZeros && innerChange < 0) {
|
if (m_innerNonZeros && innerChange < 0)
|
||||||
|
{
|
||||||
for(Index i = 0; i < m_outerSize + (std::min)(outerChange, Index(0)); i++)
|
for(Index i = 0; i < m_outerSize + (std::min)(outerChange, Index(0)); i++)
|
||||||
{
|
{
|
||||||
Index &n = m_innerNonZeros[i];
|
Index &n = m_innerNonZeros[i];
|
||||||
@ -577,13 +581,13 @@ class SparseMatrix
|
|||||||
Index *newOuterIndex = static_cast<Index*>(std::realloc(m_outerIndex, (m_outerSize + outerChange + 1) * sizeof(Index)));
|
Index *newOuterIndex = static_cast<Index*>(std::realloc(m_outerIndex, (m_outerSize + outerChange + 1) * sizeof(Index)));
|
||||||
if (!newOuterIndex) internal::throw_std_bad_alloc();
|
if (!newOuterIndex) internal::throw_std_bad_alloc();
|
||||||
m_outerIndex = newOuterIndex;
|
m_outerIndex = newOuterIndex;
|
||||||
if (outerChange > 0) {
|
if (outerChange > 0)
|
||||||
|
{
|
||||||
Index last = m_outerSize == 0 ? 0 : m_outerIndex[m_outerSize];
|
Index last = m_outerSize == 0 ? 0 : m_outerIndex[m_outerSize];
|
||||||
for(Index i=m_outerSize; i<m_outerSize+outerChange+1; i++)
|
for(Index i=m_outerSize; i<m_outerSize+outerChange+1; i++)
|
||||||
m_outerIndex[i] = last;
|
m_outerIndex[i] = last;
|
||||||
}
|
}
|
||||||
m_outerSize += outerChange;
|
m_outerSize += outerChange;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Resizes the matrix to a \a rows x \a cols matrix and initializes it to zero.
|
/** Resizes the matrix to a \a rows x \a cols matrix and initializes it to zero.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user