| 346 | */ |
| 347 | template <typename MatrixType, typename OrderingType> |
| 348 | void 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(); |
nothing calls this directly
no test coverage detected