bug #1105: fix default preallocation when moving from compressed to uncompressed mode

This commit is contained in:
Gael Guennebaud 2015-11-06 15:05:37 +01:00
parent 29038b982d
commit bfd6ee64f3
2 changed files with 16 additions and 1 deletions

View File

@ -1221,7 +1221,7 @@ typename SparseMatrix<_Scalar,_Options,_Index>::Scalar& SparseMatrix<_Scalar,_Op
{ {
// make sure the matrix is compatible to random un-compressed insertion: // make sure the matrix is compatible to random un-compressed insertion:
m_data.resize(m_data.allocatedSize()); m_data.resize(m_data.allocatedSize());
this->reserveInnerVectors(Array<StorageIndex,Dynamic,1>::Constant(2*m_outerSize, convert_index(m_outerSize))); this->reserveInnerVectors(Array<StorageIndex,Dynamic,1>::Constant(m_outerSize, 2));
} }
return insertUncompressed(row,col); return insertUncompressed(row,col);

View File

@ -513,4 +513,19 @@ void test_sparse_basic()
// Regression test for bug 900: (manually insert higher values here, if you have enough RAM): // Regression test for bug 900: (manually insert higher values here, if you have enough RAM):
CALL_SUBTEST_3((big_sparse_triplet<SparseMatrix<float, RowMajor, int> >(10000, 10000, 0.125))); CALL_SUBTEST_3((big_sparse_triplet<SparseMatrix<float, RowMajor, int> >(10000, 10000, 0.125)));
CALL_SUBTEST_4((big_sparse_triplet<SparseMatrix<double, ColMajor, long int> >(10000, 10000, 0.125))); CALL_SUBTEST_4((big_sparse_triplet<SparseMatrix<double, ColMajor, long int> >(10000, 10000, 0.125)));
// Regression test for bug 1105
#ifdef EIGEN_TEST_PART_6
{
int n = Eigen::internal::random<int>(200,600);
SparseMatrix<std::complex<double>,0, long> mat(n, n);
std::complex<double> val;
for(int i=0; i<n; ++i)
{
mat.coeffRef(i, i%(n/10)) = val;
VERIFY(mat.data().allocatedSize()<20*n);
}
}
#endif
} }