diff options
author | Gael Guennebaud <g.gael@free.fr> | 2013-11-15 10:59:19 +0100 |
---|---|---|
committer | Gael Guennebaud <g.gael@free.fr> | 2013-11-15 10:59:19 +0100 |
commit | 6b471f205ef00572abebaf403d55433f2ce40eee (patch) | |
tree | c783150a346d97a77855e26f785a8957b9a3559d /Eigen/src/SparseLU | |
parent | e59b38abef4dec8e37037284760607d3e108958f (diff) |
fix overflow and ambiguity in SparseLU memory allocation
Diffstat (limited to 'Eigen/src/SparseLU')
-rw-r--r-- | Eigen/src/SparseLU/SparseLU_Memory.h | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/Eigen/src/SparseLU/SparseLU_Memory.h b/Eigen/src/SparseLU/SparseLU_Memory.h index e1e7de043..d068d62df 100644 --- a/Eigen/src/SparseLU/SparseLU_Memory.h +++ b/Eigen/src/SparseLU/SparseLU_Memory.h @@ -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) { @@ -152,10 +152,9 @@ template <typename Scalar, typename Index> Index SparseLUImpl<Scalar,Index>::memInit(Index m, Index n, Index annz, Index lwork, Index fillratio, Index panel_size, GlobalLU_t& glu) { 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 + num_expansions = 0; + 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; |