MCPcopy Create free account
hub / github.com/abess-team/abess / factorize

Method factorize

python/include/Eigen/src/SparseQR/SparseQR.h:348–597  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

346 */
347template <typename MatrixType, typename OrderingType>
348void SparseQR<MatrixType,OrderingType>::factorize(const MatrixType& mat)
349{
350 using std::abs;
351
352 eigen_assert(m_analysisIsok && "analyzePattern() should be called before this step");
353 StorageIndex m = StorageIndex(mat.rows());
354 StorageIndex n = StorageIndex(mat.cols());
355 StorageIndex diagSize = (std::min)(m,n);
356 IndexVector mark((std::max)(m,n)); mark.setConstant(-1); // Record the visited nodes
357 IndexVector Ridx(n), Qidx(m); // Store temporarily the row indexes for the current column of R and Q
358 Index nzcolR, nzcolQ; // Number of nonzero for the current column of R and Q
359 ScalarVector tval(m); // The dense vector used to compute the current column
360 RealScalar pivotThreshold = m_threshold;
361
362 m_R.setZero();
363 m_Q.setZero();
364 m_pmat = mat;
365 if(!m_isEtreeOk)
366 {
367 m_outputPerm_c = m_perm_c.inverse();
368 internal::coletree(m_pmat, m_etree, m_firstRowElt, m_outputPerm_c.indices().data());
369 m_isEtreeOk = true;
370 }
371
372 m_pmat.uncompress(); // To have the innerNonZeroPtr allocated
373
374 // Apply the fill-in reducing permutation lazily:
375 {
376 // If the input is row major, copy the original column indices,
377 // otherwise directly use the input matrix
378 //
379 IndexVector originalOuterIndicesCpy;
380 const StorageIndex *originalOuterIndices = mat.outerIndexPtr();
381 if(MatrixType::IsRowMajor)
382 {
383 originalOuterIndicesCpy = IndexVector::Map(m_pmat.outerIndexPtr(),n+1);
384 originalOuterIndices = originalOuterIndicesCpy.data();
385 }
386
387 for (int i = 0; i < n; i++)
388 {
389 Index p = m_perm_c.size() ? m_perm_c.indices()(i) : i;
390 m_pmat.outerIndexPtr()[p] = originalOuterIndices[i];
391 m_pmat.innerNonZeroPtr()[p] = originalOuterIndices[i+1] - originalOuterIndices[i];
392 }
393 }
394
395 /* Compute the default threshold as in MatLab, see:
396 * Tim Davis, "Algorithm 915, SuiteSparseQR: Multifrontal Multithreaded Rank-Revealing
397 * Sparse QR Factorization, ACM Trans. on Math. Soft. 38(1), 2011, Page 8:3
398 */
399 if(m_useDefaultThreshold)
400 {
401 RealScalar max2Norm = 0.0;
402 for (int j = 0; j < n; j++) max2Norm = numext::maxi(max2Norm, m_pmat.col(j).norm());
403 if(max2Norm==RealScalar(0))
404 max2Norm = RealScalar(1);
405 pivotThreshold = 20 * (m + n) * max2Norm * NumTraits<RealScalar>::epsilon();

Callers

nothing calls this directly

Calls 15

coletreeFunction · 0.85
maxiFunction · 0.85
conjFunction · 0.85
uncompressMethod · 0.80
makeCompressedMethod · 0.80
MapFunction · 0.50
swapFunction · 0.50
abs2Function · 0.50
imagFunction · 0.50
realFunction · 0.50
sqrtFunction · 0.50
absFunction · 0.50

Tested by

no test coverage detected