31 #ifndef EIGEN_SPARSELU_MEMORY
32 #define EIGEN_SPARSELU_MEMORY
37 enum { LUNoMarker = 3 };
38 enum {emptyIdxLU = -1};
39 template<
typename Index>
40 inline Index LUnumTempV(Index& m, Index& w, Index& t, Index& b)
42 return (std::max)(m, (t+b)*w);
45 template<
typename Scalar,
typename Index>
46 inline Index LUTempSpace(Index&m, Index& w)
48 return (2*w + 4 + LUNoMarker) * m *
sizeof(Index) + (w + 1) * m *
sizeof(Scalar);
62 template <
typename Scalar,
typename Index>
63 template <
typename VectorType>
64 Index SparseLUImpl<Scalar,Index>::expand(VectorType& vec, Index& length, Index nbElts, Index keep_prev, Index& num_expansions)
70 if(num_expansions == 0 || keep_prev)
73 new_len = Index(alpha * length);
77 old_vec = vec.segment(0,nbElts);
84 catch(std::bad_alloc& )
86 if ( !num_expansions )
102 alpha = (alpha + 1)/2;
103 new_len = Index(alpha * length);
108 catch(std::bad_alloc& )
111 if ( tries > 10)
return new_len;
113 }
while (!vec.size());
118 vec.segment(0, nbElts) = old_vec;
122 if(num_expansions) ++num_expansions;
138 template <
typename Scalar,
typename Index>
139 Index SparseLUImpl<Scalar,Index>::memInit(Index m, Index n, Index annz, Index lwork, Index fillratio, Index panel_size, GlobalLU_t& glu)
141 Index& num_expansions = glu.num_expansions;
143 glu.nzumax = glu.nzlumax = (std::max)(fillratio * annz, m*n);
144 glu.nzlmax = (std::max)(Index(4), fillratio) * annz / 4;
148 tempSpace = (2*panel_size + 4 + LUNoMarker) * m *
sizeof(Index) + (panel_size + 1) * m *
sizeof(Scalar);
149 if (lwork == emptyIdxLU)
151 Index estimated_size;
152 estimated_size = (5 * n + 5) *
sizeof(Index) + tempSpace
153 + (glu.nzlmax + glu.nzumax) *
sizeof(Index) + (glu.nzlumax+glu.nzumax) *
sizeof(Scalar) + n;
154 return estimated_size;
160 glu.xsup.resize(n+1);
161 glu.supno.resize(n+1);
162 glu.xlsub.resize(n+1);
163 glu.xlusup.resize(n+1);
164 glu.xusub.resize(n+1);
171 expand<ScalarVector>(glu.lusup, glu.nzlumax, 0, 0, num_expansions);
172 expand<ScalarVector>(glu.ucol,glu.nzumax, 0, 0, num_expansions);
173 expand<IndexVector>(glu.lsub,glu.nzlmax, 0, 0, num_expansions);
174 expand<IndexVector>(glu.usub,glu.nzumax, 0, 1, num_expansions);
176 catch(std::bad_alloc& )
182 if (glu.nzlumax < annz )
return glu.nzlumax;
185 }
while (!glu.lusup.size() || !glu.ucol.size() || !glu.lsub.size() || !glu.usub.size());
203 template <
typename Scalar,
typename Index>
204 template <
typename VectorType>
205 Index SparseLUImpl<Scalar,Index>::memXpand(VectorType& vec, Index& maxlen, Index nbElts, MemType memtype, Index& num_expansions)
209 failed_size = this->expand<VectorType>(vec, maxlen, nbElts, 1, num_expansions);
211 failed_size = this->expand<VectorType>(vec, maxlen, nbElts, 0, num_expansions);
222 #endif // EIGEN_SPARSELU_MEMORY