fix overflow and ambiguity in SparseLU memory allocation

This commit is contained in:
Gael Guennebaud 2013-11-15 10:59:19 +01:00
parent e59b38abef
commit 6b471f205e

View File

@ -93,7 +93,7 @@ Index SparseLUImpl<Scalar,Index>::expand(VectorType& vec, Index& length, Index
{
// First time to allocate from LUMemInit()
// Let LUMemInit() deals with it.
return 0;
return -1;
}
if (keep_prev)
{
@ -153,9 +153,8 @@ Index SparseLUImpl<Scalar,Index>::memInit(Index m, Index n, Index annz, Index lw
{
Index& num_expansions = glu.num_expansions; //No memory expansions so far
num_expansions = 0;
glu.nzumax = glu.nzlumax = (std::min)(fillratio * annz, m*n); // estimated number of nonzeros in U
glu.nzumax = glu.nzlumax = (std::min)(fillratio * annz / n, m) * n; // estimated number of nonzeros in U
glu.nzlmax = (std::max)(Index(4), fillratio) * annz / 4; // estimated nnz in L factor
// Return the estimated size to the user if necessary
Index tempSpace;
tempSpace = (2*panel_size + 4 + LUNoMarker) * m * sizeof(Index) + (panel_size + 1) * m * sizeof(Scalar);
@ -179,10 +178,10 @@ Index SparseLUImpl<Scalar,Index>::memInit(Index m, Index n, Index annz, Index lw
// Reserve memory for L/U factors
do
{
if( (!expand<ScalarVector>(glu.lusup, glu.nzlumax, 0, 0, num_expansions))
|| (!expand<ScalarVector>(glu.ucol, glu.nzumax, 0, 0, num_expansions))
|| (!expand<IndexVector> (glu.lsub, glu.nzlmax, 0, 0, num_expansions))
|| (!expand<IndexVector> (glu.usub, glu.nzumax, 0, 1, num_expansions)) )
if( (expand<ScalarVector>(glu.lusup, glu.nzlumax, 0, 0, num_expansions)<0)
|| (expand<ScalarVector>(glu.ucol, glu.nzumax, 0, 0, num_expansions)<0)
|| (expand<IndexVector> (glu.lsub, glu.nzlmax, 0, 0, num_expansions)<0)
|| (expand<IndexVector> (glu.usub, glu.nzumax, 0, 1, num_expansions)<0) )
{
//Reduce the estimated size and retry
glu.nzlumax /= 2;