mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-08-12 03:39:01 +08:00
fix overflow and ambiguity in SparseLU memory allocation
This commit is contained in:
parent
e59b38abef
commit
6b471f205e
@ -93,7 +93,7 @@ Index SparseLUImpl<Scalar,Index>::expand(VectorType& vec, Index& length, Index
|
|||||||
{
|
{
|
||||||
// First time to allocate from LUMemInit()
|
// First time to allocate from LUMemInit()
|
||||||
// Let LUMemInit() deals with it.
|
// Let LUMemInit() deals with it.
|
||||||
return 0;
|
return -1;
|
||||||
}
|
}
|
||||||
if (keep_prev)
|
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 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
|
Index& num_expansions = glu.num_expansions; //No memory expansions so far
|
||||||
num_expansions = 0;
|
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
|
glu.nzlmax = (std::max)(Index(4), fillratio) * annz / 4; // estimated nnz in L factor
|
||||||
|
|
||||||
// Return the estimated size to the user if necessary
|
// Return the estimated size to the user if necessary
|
||||||
Index tempSpace;
|
Index tempSpace;
|
||||||
tempSpace = (2*panel_size + 4 + LUNoMarker) * m * sizeof(Index) + (panel_size + 1) * m * sizeof(Scalar);
|
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
|
// Reserve memory for L/U factors
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if( (!expand<ScalarVector>(glu.lusup, glu.nzlumax, 0, 0, num_expansions))
|
if( (expand<ScalarVector>(glu.lusup, glu.nzlumax, 0, 0, num_expansions)<0)
|
||||||
|| (!expand<ScalarVector>(glu.ucol, glu.nzumax, 0, 0, num_expansions))
|
|| (expand<ScalarVector>(glu.ucol, glu.nzumax, 0, 0, num_expansions)<0)
|
||||||
|| (!expand<IndexVector> (glu.lsub, glu.nzlmax, 0, 0, num_expansions))
|
|| (expand<IndexVector> (glu.lsub, glu.nzlmax, 0, 0, num_expansions)<0)
|
||||||
|| (!expand<IndexVector> (glu.usub, glu.nzumax, 0, 1, num_expansions)) )
|
|| (expand<IndexVector> (glu.usub, glu.nzumax, 0, 1, num_expansions)<0) )
|
||||||
{
|
{
|
||||||
//Reduce the estimated size and retry
|
//Reduce the estimated size and retry
|
||||||
glu.nzlumax /= 2;
|
glu.nzlumax /= 2;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user