MCPcopy Create free account
hub / github.com/TinyMPC/TinyMPC / memInit

Method memInit

include/Eigen/Eigen/src/SparseLU/SparseLU_Memory.h:153–198  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

151 */
152template <typename Scalar, typename StorageIndex>
153Index SparseLUImpl<Scalar,StorageIndex>::memInit(Index m, Index n, Index annz, Index lwork, Index fillratio, Index panel_size, GlobalLU_t& glu)
154{
155 Index& num_expansions = glu.num_expansions; //No memory expansions so far
156 num_expansions = 0;
157 glu.nzumax = glu.nzlumax = (std::min)(fillratio * (annz+1) / n, m) * n; // estimated number of nonzeros in U
158 glu.nzlmax = (std::max)(Index(4), fillratio) * (annz+1) / 4; // estimated nnz in L factor
159 // Return the estimated size to the user if necessary
160 Index tempSpace;
161 tempSpace = (2*panel_size + 4 + LUNoMarker) * m * sizeof(Index) + (panel_size + 1) * m * sizeof(Scalar);
162 if (lwork == emptyIdxLU)
163 {
164 Index estimated_size;
165 estimated_size = (5 * n + 5) * sizeof(Index) + tempSpace
166 + (glu.nzlmax + glu.nzumax) * sizeof(Index) + (glu.nzlumax+glu.nzumax) * sizeof(Scalar) + n;
167 return estimated_size;
168 }
169
170 // Setup the required space
171
172 // First allocate Integer pointers for L\U factors
173 glu.xsup.resize(n+1);
174 glu.supno.resize(n+1);
175 glu.xlsub.resize(n+1);
176 glu.xlusup.resize(n+1);
177 glu.xusub.resize(n+1);
178
179 // Reserve memory for L/U factors
180 do
181 {
182 if( (expand<ScalarVector>(glu.lusup, glu.nzlumax, 0, 0, num_expansions)<0)
183 || (expand<ScalarVector>(glu.ucol, glu.nzumax, 0, 0, num_expansions)<0)
184 || (expand<IndexVector> (glu.lsub, glu.nzlmax, 0, 0, num_expansions)<0)
185 || (expand<IndexVector> (glu.usub, glu.nzumax, 0, 1, num_expansions)<0) )
186 {
187 //Reduce the estimated size and retry
188 glu.nzlumax /= 2;
189 glu.nzumax /= 2;
190 glu.nzlmax /= 2;
191 if (glu.nzlumax < annz ) return glu.nzlumax;
192 }
193 } while (!glu.lusup.size() || !glu.ucol.size() || !glu.lsub.size() || !glu.usub.size());
194
195 ++num_expansions;
196 return 0;
197
198} // end LuMemInit
199
200/**
201 * \brief Expand the existing storage

Callers

nothing calls this directly

Calls 2

resizeMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected