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