bug #808: use double instead of float for the increasing size ratio in CompressedStorage::resize

(grafted from 0e0ae400843cd9a459e5306d4d6560dbea759a42
)
This commit is contained in:
Gael Guennebaud 2014-07-08 18:58:41 +02:00
parent 5214466b7a
commit e3557e8dd2
2 changed files with 7 additions and 7 deletions

View File

@ -83,10 +83,10 @@ class CompressedStorage
reallocate(m_size); reallocate(m_size);
} }
void resize(size_t size, float reserveSizeFactor = 0) void resize(size_t size, double reserveSizeFactor = 0)
{ {
if (m_allocatedSize<size) if (m_allocatedSize<size)
reallocate(size + size_t(reserveSizeFactor*size)); reallocate(size + size_t(reserveSizeFactor*double(size)));
m_size = size; m_size = size;
} }

View File

@ -1178,7 +1178,7 @@ EIGEN_DONT_INLINE typename SparseMatrix<_Scalar,_Options,_Index>::Scalar& Sparse
size_t p = m_outerIndex[outer+1]; size_t p = m_outerIndex[outer+1];
++m_outerIndex[outer+1]; ++m_outerIndex[outer+1];
float reallocRatio = 1; double reallocRatio = 1;
if (m_data.allocatedSize()<=m_data.size()) if (m_data.allocatedSize()<=m_data.size())
{ {
// if there is no preallocated memory, let's reserve a minimum of 32 elements // if there is no preallocated memory, let's reserve a minimum of 32 elements
@ -1190,13 +1190,13 @@ EIGEN_DONT_INLINE typename SparseMatrix<_Scalar,_Options,_Index>::Scalar& Sparse
{ {
// we need to reallocate the data, to reduce multiple reallocations // we need to reallocate the data, to reduce multiple reallocations
// we use a smart resize algorithm based on the current filling ratio // we use a smart resize algorithm based on the current filling ratio
// in addition, we use float to avoid integers overflows // in addition, we use double to avoid integers overflows
float nnzEstimate = float(m_outerIndex[outer])*float(m_outerSize)/float(outer+1); double nnzEstimate = double(m_outerIndex[outer])*double(m_outerSize)/double(outer+1);
reallocRatio = (nnzEstimate-float(m_data.size()))/float(m_data.size()); reallocRatio = (nnzEstimate-double(m_data.size()))/double(m_data.size());
// furthermore we bound the realloc ratio to: // furthermore we bound the realloc ratio to:
// 1) reduce multiple minor realloc when the matrix is almost filled // 1) reduce multiple minor realloc when the matrix is almost filled
// 2) avoid to allocate too much memory when the matrix is almost empty // 2) avoid to allocate too much memory when the matrix is almost empty
reallocRatio = (std::min)((std::max)(reallocRatio,1.5f),8.f); reallocRatio = (std::min)((std::max)(reallocRatio,1.5),8.);
} }
} }
m_data.resize(m_data.size()+1,reallocRatio); m_data.resize(m_data.size()+1,reallocRatio);