| 508 | */ |
| 509 | template <typename MatrixType, typename OrderingType> |
| 510 | void SparseLU<MatrixType, OrderingType>::analyzePattern(const MatrixType& mat) |
| 511 | { |
| 512 | |
| 513 | //TODO It is possible as in SuperLU to compute row and columns scaling vectors to equilibrate the matrix mat. |
| 514 | |
| 515 | // Firstly, copy the whole input matrix. |
| 516 | m_mat = mat; |
| 517 | |
| 518 | // Compute fill-in ordering |
| 519 | OrderingType ord; |
| 520 | ord(m_mat,m_perm_c); |
| 521 | |
| 522 | // Apply the permutation to the column of the input matrix |
| 523 | if (m_perm_c.size()) |
| 524 | { |
| 525 | m_mat.uncompress(); //NOTE: The effect of this command is only to create the InnerNonzeros pointers. FIXME : This vector is filled but not subsequently used. |
| 526 | // Then, permute only the column pointers |
| 527 | ei_declare_aligned_stack_constructed_variable(StorageIndex,outerIndexPtr,mat.cols()+1,mat.isCompressed()?const_cast<StorageIndex*>(mat.outerIndexPtr()):0); |
| 528 | |
| 529 | // If the input matrix 'mat' is uncompressed, then the outer-indices do not match the ones of m_mat, and a copy is thus needed. |
| 530 | if(!mat.isCompressed()) |
| 531 | IndexVector::Map(outerIndexPtr, mat.cols()+1) = IndexVector::Map(m_mat.outerIndexPtr(),mat.cols()+1); |
| 532 | |
| 533 | // Apply the permutation and compute the nnz per column. |
| 534 | for (Index i = 0; i < mat.cols(); i++) |
| 535 | { |
| 536 | m_mat.outerIndexPtr()[m_perm_c.indices()(i)] = outerIndexPtr[i]; |
| 537 | m_mat.innerNonZeroPtr()[m_perm_c.indices()(i)] = outerIndexPtr[i+1] - outerIndexPtr[i]; |
| 538 | } |
| 539 | } |
| 540 | |
| 541 | // Compute the column elimination tree of the permuted matrix |
| 542 | IndexVector firstRowElt; |
| 543 | internal::coletree(m_mat, m_etree,firstRowElt); |
| 544 | |
| 545 | // In symmetric mode, do not do postorder here |
| 546 | if (!m_symmetricmode) { |
| 547 | IndexVector post, iwork; |
| 548 | // Post order etree |
| 549 | internal::treePostorder(StorageIndex(m_mat.cols()), m_etree, post); |
| 550 | |
| 551 | |
| 552 | // Renumber etree in postorder |
| 553 | Index m = m_mat.cols(); |
| 554 | iwork.resize(m+1); |
| 555 | for (Index i = 0; i < m; ++i) iwork(post(i)) = post(m_etree(i)); |
| 556 | m_etree = iwork; |
| 557 | |
| 558 | // Postmultiply A*Pc by post, i.e reorder the matrix according to the postorder of the etree |
| 559 | PermutationType post_perm(m); |
| 560 | for (Index i = 0; i < m; i++) |
| 561 | post_perm.indices()(i) = post(i); |
| 562 | |
| 563 | // Combine the two permutations : postorder the permutation for future use |
| 564 | if(m_perm_c.size()) { |
| 565 | m_perm_c = post_perm * m_perm_c; |
| 566 | } |
| 567 | |