From 7f0f7ab5b4a0c13c0d4aba6ab6469d3e9a2f8868 Mon Sep 17 00:00:00 2001 From: Desire NUENTSA Date: Fri, 25 Jan 2013 20:38:26 +0100 Subject: Add additional methods in SparseLU and Improve the naming conventions --- Eigen/src/SparseLU/SparseLU_Memory.h | 43 ++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 16 deletions(-) (limited to 'Eigen/src/SparseLU/SparseLU_Memory.h') diff --git a/Eigen/src/SparseLU/SparseLU_Memory.h b/Eigen/src/SparseLU/SparseLU_Memory.h index 049d5e694..f82826cbe 100644 --- a/Eigen/src/SparseLU/SparseLU_Memory.h +++ b/Eigen/src/SparseLU/SparseLU_Memory.h @@ -32,15 +32,23 @@ #define EIGEN_SPARSELU_MEMORY namespace Eigen { +namespace internal { -#define LU_NO_MARKER 3 -#define LU_NUM_TEMPV(m,w,t,b) ((std::max)(m, (t+b)*w) ) -#define IND_EMPTY (-1) +enum { LUNoMarker = 3 }; +enum {emptyIdxLU = -1}; +template +inline Index LUnumTempV(Index& m, Index& w, Index& t, Index& b) +{ + return (std::max)(m, (t+b)*w); +} + +template< typename Scalar, typename Index> +inline Index LUTempSpace(Index&m, Index& w) +{ + return (2*w + 4 + LUNoMarker) * m * sizeof(Index) + (w + 1) * m * sizeof(Scalar); +} + -#define LU_Reduce(alpha) ((alpha + 1) / 2) // i.e (alpha-1)/2 + 1 -#define LU_GluIntArray(n) (5* (n) + 5) -#define LU_TempSpace(m, w) ( (2*w + 4 + LU_NO_MARKER) * m * sizeof(Index) \ - + (w + 1) * m * sizeof(Scalar) ) /** @@ -53,7 +61,7 @@ namespace Eigen { */ template template -int SparseLUBase::expand(VectorType& vec, int& length, int nbElts, int keep_prev, int& num_expansions) +int SparseLUImpl::expand(VectorType& vec, int& length, int nbElts, int keep_prev, int& num_expansions) { float alpha = 1.5; // Ratio of the memory increase @@ -91,7 +99,7 @@ int SparseLUBase::expand(VectorType& vec, int& length, int nbElts int tries = 0; // Number of attempts do { - alpha = LU_Reduce(alpha); + alpha = (alpha + 1)/2; new_len = alpha * length ; try { @@ -128,7 +136,7 @@ int SparseLUBase::expand(VectorType& vec, int& length, int nbElts * \note Unlike SuperLU, this routine does not support successive factorization with the same pattern and the same row permutation */ template -int SparseLUBase::LUMemInit(int m, int n, int annz, int lwork, int fillratio, int panel_size, GlobalLU_t& glu) +int SparseLUImpl::memInit(int m, int n, int annz, int lwork, int fillratio, int panel_size, GlobalLU_t& glu) { int& num_expansions = glu.num_expansions; //No memory expansions so far num_expansions = 0; @@ -136,10 +144,12 @@ int SparseLUBase::LUMemInit(int m, int n, int annz, int lwork, int glu.nzlmax = (std::max)(1., fillratio/4.) * annz; // estimated nnz in L factor // Return the estimated size to the user if necessary - if (lwork == IND_EMPTY) + Index tempSpace; + tempSpace = (2*panel_size + 4 + LUNoMarker) * m * sizeof(Index) + (panel_size + 1) * m * sizeof(Scalar); + if (lwork == emptyIdxLU) { int estimated_size; - estimated_size = LU_GluIntArray(n) * sizeof(Index) + LU_TempSpace(m, panel_size) + estimated_size = (5 * n + 5) * sizeof(Index) + tempSpace + (glu.nzlmax + glu.nzumax) * sizeof(Index) + (glu.nzlumax+glu.nzumax) * sizeof(Scalar) + n; return estimated_size; } @@ -192,13 +202,13 @@ int SparseLUBase::LUMemInit(int m, int n, int annz, int lwork, int */ template template -int SparseLUBase::LUMemXpand(VectorType& vec, int& maxlen, int nbElts, LU_MemType memtype, int& num_expansions) +int SparseLUImpl::memXpand(VectorType& vec, int& maxlen, int nbElts, MemType memtype, int& num_expansions) { int failed_size; if (memtype == USUB) - failed_size = expand(vec, maxlen, nbElts, 1, num_expansions); + failed_size = this->expand(vec, maxlen, nbElts, 1, num_expansions); else - failed_size = expand(vec, maxlen, nbElts, 0, num_expansions); + failed_size = this->expand(vec, maxlen, nbElts, 0, num_expansions); if (failed_size) return failed_size; @@ -206,6 +216,7 @@ int SparseLUBase::LUMemXpand(VectorType& vec, int& maxlen, int nbE return 0 ; } -} // end namespace Eigen +} // end namespace internal +} // end namespace Eigen #endif // EIGEN_SPARSELU_MEMORY -- cgit v1.2.3