| 320 | */ |
| 321 | template <typename MatrixType, typename OrderingType> |
| 322 | void SparseQR<MatrixType,OrderingType>::analyzePattern(const MatrixType& mat) |
| 323 | { |
| 324 | eigen_assert(mat.isCompressed() && "SparseQR requires a sparse matrix in compressed mode. Call .makeCompressed() before passing it to SparseQR"); |
| 325 | // Copy to a column major matrix if the input is rowmajor |
| 326 | std::conditional_t<MatrixType::IsRowMajor,QRMatrixType,const MatrixType&> matCpy(mat); |
| 327 | // Compute the column fill reducing ordering |
| 328 | OrderingType ord; |
| 329 | ord(matCpy, m_perm_c); |
| 330 | Index n = mat.cols(); |
| 331 | Index m = mat.rows(); |
| 332 | Index diagSize = (std::min)(m,n); |
| 333 | |
| 334 | if (!m_perm_c.size()) |
| 335 | { |
| 336 | m_perm_c.resize(n); |
| 337 | m_perm_c.indices().setLinSpaced(n, 0,StorageIndex(n-1)); |
| 338 | } |
| 339 | |
| 340 | // Compute the column elimination tree of the permuted matrix |
| 341 | m_outputPerm_c = m_perm_c.inverse(); |
| 342 | internal::coletree(matCpy, m_etree, m_firstRowElt, m_outputPerm_c.indices().data()); |
| 343 | m_isEtreeOk = true; |
| 344 | |
| 345 | m_R.resize(m, n); |
| 346 | m_Q.resize(m, diagSize); |
| 347 | |
| 348 | // Allocate space for nonzero elements: rough estimation |
| 349 | m_R.reserve(2*mat.nonZeros()); //FIXME Get a more accurate estimation through symbolic factorization with the etree |
| 350 | m_Q.reserve(2*mat.nonZeros()); |
| 351 | m_hcoeffs.resize(diagSize); |
| 352 | m_analysisIsok = true; |
| 353 | } |
| 354 | |
| 355 | /** \brief Performs the numerical QR factorization of the input matrix |
| 356 | * |