$treeview $search $mathjax
Eigen  3.2.3
$projectbrief
$projectbrief
$searchbox

SparseLU.h

00001 // This file is part of Eigen, a lightweight C++ template library
00002 // for linear algebra.
00003 //
00004 // Copyright (C) 2012 Désiré Nuentsa-Wakam <desire.nuentsa_wakam@inria.fr>
00005 // Copyright (C) 2012 Gael Guennebaud <gael.guennebaud@inria.fr>
00006 //
00007 // This Source Code Form is subject to the terms of the Mozilla
00008 // Public License v. 2.0. If a copy of the MPL was not distributed
00009 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
00010 
00011 
00012 #ifndef EIGEN_SPARSE_LU_H
00013 #define EIGEN_SPARSE_LU_H
00014 
00015 namespace Eigen {
00016 
00017 template <typename _MatrixType, typename _OrderingType = COLAMDOrdering<typename _MatrixType::Index> > class SparseLU;
00018 template <typename MappedSparseMatrixType> struct SparseLUMatrixLReturnType;
00019 template <typename MatrixLType, typename MatrixUType> struct SparseLUMatrixUReturnType;
00020 
00072 template <typename _MatrixType, typename _OrderingType>
00073 class SparseLU : public internal::SparseLUImpl<typename _MatrixType::Scalar, typename _MatrixType::Index>
00074 {
00075   public:
00076     typedef _MatrixType MatrixType; 
00077     typedef _OrderingType OrderingType;
00078     typedef typename MatrixType::Scalar Scalar; 
00079     typedef typename MatrixType::RealScalar RealScalar; 
00080     typedef typename MatrixType::Index Index; 
00081     typedef SparseMatrix<Scalar,ColMajor,Index> NCMatrix;
00082     typedef internal::MappedSuperNodalMatrix<Scalar, Index> SCMatrix; 
00083     typedef Matrix<Scalar,Dynamic,1> ScalarVector;
00084     typedef Matrix<Index,Dynamic,1> IndexVector;
00085     typedef PermutationMatrix<Dynamic, Dynamic, Index> PermutationType;
00086     typedef internal::SparseLUImpl<Scalar, Index> Base;
00087     
00088   public:
00089     SparseLU():m_isInitialized(true),m_lastError(""),m_Ustore(0,0,0,0,0,0),m_symmetricmode(false),m_diagpivotthresh(1.0),m_detPermR(1)
00090     {
00091       initperfvalues(); 
00092     }
00093     SparseLU(const MatrixType& matrix):m_isInitialized(true),m_lastError(""),m_Ustore(0,0,0,0,0,0),m_symmetricmode(false),m_diagpivotthresh(1.0),m_detPermR(1)
00094     {
00095       initperfvalues(); 
00096       compute(matrix);
00097     }
00098     
00099     ~SparseLU()
00100     {
00101       // Free all explicit dynamic pointers 
00102     }
00103     
00104     void analyzePattern (const MatrixType& matrix);
00105     void factorize (const MatrixType& matrix);
00106     void simplicialfactorize(const MatrixType& matrix);
00107     
00112     void compute (const MatrixType& matrix)
00113     {
00114       // Analyze 
00115       analyzePattern(matrix); 
00116       //Factorize
00117       factorize(matrix);
00118     } 
00119     
00120     inline Index rows() const { return m_mat.rows(); }
00121     inline Index cols() const { return m_mat.cols(); }
00123     void isSymmetric(bool sym)
00124     {
00125       m_symmetricmode = sym;
00126     }
00127     
00134     SparseLUMatrixLReturnType<SCMatrix> matrixL() const
00135     {
00136       return SparseLUMatrixLReturnType<SCMatrix>(m_Lstore);
00137     }
00144     SparseLUMatrixUReturnType<SCMatrix,MappedSparseMatrix<Scalar,ColMajor,Index> > matrixU() const
00145     {
00146       return SparseLUMatrixUReturnType<SCMatrix, MappedSparseMatrix<Scalar,ColMajor,Index> >(m_Lstore, m_Ustore);
00147     }
00148 
00153     inline const PermutationType& rowsPermutation() const
00154     {
00155       return m_perm_r;
00156     }
00161     inline const PermutationType& colsPermutation() const
00162     {
00163       return m_perm_c;
00164     }
00166     void setPivotThreshold(const RealScalar& thresh)
00167     {
00168       m_diagpivotthresh = thresh; 
00169     }
00170 
00177     template<typename Rhs>
00178     inline const internal::solve_retval<SparseLU, Rhs> solve(const MatrixBase<Rhs>& B) const 
00179     {
00180       eigen_assert(m_factorizationIsOk && "SparseLU is not initialized."); 
00181       eigen_assert(rows()==B.rows()
00182                     && "SparseLU::solve(): invalid number of rows of the right hand side matrix B");
00183           return internal::solve_retval<SparseLU, Rhs>(*this, B.derived());
00184     }
00185 
00190     template<typename Rhs>
00191     inline const internal::sparse_solve_retval<SparseLU, Rhs> solve(const SparseMatrixBase<Rhs>& B) const 
00192     {
00193       eigen_assert(m_factorizationIsOk && "SparseLU is not initialized."); 
00194       eigen_assert(rows()==B.rows()
00195                     && "SparseLU::solve(): invalid number of rows of the right hand side matrix B");
00196           return internal::sparse_solve_retval<SparseLU, Rhs>(*this, B.derived());
00197     }
00198     
00207     ComputationInfo info() const
00208     {
00209       eigen_assert(m_isInitialized && "Decomposition is not initialized.");
00210       return m_info;
00211     }
00212     
00216     std::string lastErrorMessage() const
00217     {
00218       return m_lastError; 
00219     }
00220 
00221     template<typename Rhs, typename Dest>
00222     bool _solve(const MatrixBase<Rhs> &B, MatrixBase<Dest> &X_base) const
00223     {
00224       Dest& X(X_base.derived());
00225       eigen_assert(m_factorizationIsOk && "The matrix should be factorized first");
00226       EIGEN_STATIC_ASSERT((Dest::Flags&RowMajorBit)==0,
00227                         THIS_METHOD_IS_ONLY_FOR_COLUMN_MAJOR_MATRICES);
00228       
00229       // Permute the right hand side to form X = Pr*B
00230       // on return, X is overwritten by the computed solution
00231       X.resize(B.rows(),B.cols());
00232 
00233       // this ugly const_cast_derived() helps to detect aliasing when applying the permutations
00234       for(Index j = 0; j < B.cols(); ++j)
00235         X.col(j) = rowsPermutation() * B.const_cast_derived().col(j);
00236       
00237       //Forward substitution with L
00238       this->matrixL().solveInPlace(X);
00239       this->matrixU().solveInPlace(X);
00240       
00241       // Permute back the solution 
00242       for (Index j = 0; j < B.cols(); ++j)
00243         X.col(j) = colsPermutation().inverse() * X.col(j);
00244       
00245       return true; 
00246     }
00247     
00258      Scalar absDeterminant()
00259     {
00260       eigen_assert(m_factorizationIsOk && "The matrix should be factorized first.");
00261       // Initialize with the determinant of the row matrix
00262       Scalar det = Scalar(1.);
00263       // Note that the diagonal blocks of U are stored in supernodes,
00264       // which are available in the  L part :)
00265       for (Index j = 0; j < this->cols(); ++j)
00266       {
00267         for (typename SCMatrix::InnerIterator it(m_Lstore, j); it; ++it)
00268         {
00269           if(it.index() == j)
00270           {
00271             det *= (std::abs)(it.value());
00272             break;
00273           }
00274         }
00275        }
00276        return det;
00277      }
00278 
00287      Scalar logAbsDeterminant() const
00288      {
00289        eigen_assert(m_factorizationIsOk && "The matrix should be factorized first.");
00290        Scalar det = Scalar(0.);
00291        for (Index j = 0; j < this->cols(); ++j)
00292        {
00293          for (typename SCMatrix::InnerIterator it(m_Lstore, j); it; ++it)
00294          {
00295            if(it.row() < j) continue;
00296            if(it.row() == j)
00297            {
00298              det += (std::log)((std::abs)(it.value()));
00299              break;
00300            }
00301          }
00302        }
00303        return det;
00304      }
00305 
00310      Scalar signDeterminant()
00311      {
00312        eigen_assert(m_factorizationIsOk && "The matrix should be factorized first.");
00313        return Scalar(m_detPermR);
00314      }
00315 
00316   protected:
00317     // Functions 
00318     void initperfvalues()
00319     {
00320       m_perfv.panel_size = 1;
00321       m_perfv.relax = 1; 
00322       m_perfv.maxsuper = 128; 
00323       m_perfv.rowblk = 16; 
00324       m_perfv.colblk = 8; 
00325       m_perfv.fillfactor = 20;  
00326     }
00327       
00328     // Variables 
00329     mutable ComputationInfo m_info;
00330     bool m_isInitialized;
00331     bool m_factorizationIsOk;
00332     bool m_analysisIsOk;
00333     std::string m_lastError;
00334     NCMatrix m_mat; // The input (permuted ) matrix 
00335     SCMatrix m_Lstore; // The lower triangular matrix (supernodal)
00336     MappedSparseMatrix<Scalar,ColMajor,Index> m_Ustore; // The upper triangular matrix
00337     PermutationType m_perm_c; // Column permutation 
00338     PermutationType m_perm_r ; // Row permutation
00339     IndexVector m_etree; // Column elimination tree 
00340     
00341     typename Base::GlobalLU_t m_glu; 
00342                                
00343     // SparseLU options 
00344     bool m_symmetricmode;
00345     // values for performance 
00346     internal::perfvalues<Index> m_perfv; 
00347     RealScalar m_diagpivotthresh; // Specifies the threshold used for a diagonal entry to be an acceptable pivot
00348     Index m_nnzL, m_nnzU; // Nonzeros in L and U factors 
00349     Index m_detPermR; // Determinant of the coefficient matrix
00350   private:
00351     // Disable copy constructor 
00352     SparseLU (const SparseLU& );
00353   
00354 }; // End class SparseLU
00355 
00356 
00357 
00358 // Functions needed by the anaysis phase
00369 template <typename MatrixType, typename OrderingType>
00370 void SparseLU<MatrixType, OrderingType>::analyzePattern(const MatrixType& mat)
00371 {
00372   
00373   //TODO  It is possible as in SuperLU to compute row and columns scaling vectors to equilibrate the matrix mat.
00374   
00375   OrderingType ord; 
00376   ord(mat,m_perm_c);
00377   
00378   // Apply the permutation to the column of the input  matrix
00379   //First copy the whole input matrix. 
00380   m_mat = mat;
00381   if (m_perm_c.size()) {
00382     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.  
00383     //Then, permute only the column pointers
00384     const Index * outerIndexPtr;
00385     if (mat.isCompressed()) outerIndexPtr = mat.outerIndexPtr();
00386     else
00387     {
00388       Index *outerIndexPtr_t = new Index[mat.cols()+1];
00389       for(Index i = 0; i <= mat.cols(); i++) outerIndexPtr_t[i] = m_mat.outerIndexPtr()[i];
00390       outerIndexPtr = outerIndexPtr_t;
00391     }
00392     for (Index i = 0; i < mat.cols(); i++)
00393     {
00394       m_mat.outerIndexPtr()[m_perm_c.indices()(i)] = outerIndexPtr[i];
00395       m_mat.innerNonZeroPtr()[m_perm_c.indices()(i)] = outerIndexPtr[i+1] - outerIndexPtr[i];
00396     }
00397     if(!mat.isCompressed()) delete[] outerIndexPtr;
00398   }
00399   // Compute the column elimination tree of the permuted matrix 
00400   IndexVector firstRowElt;
00401   internal::coletree(m_mat, m_etree,firstRowElt); 
00402      
00403   // In symmetric mode, do not do postorder here
00404   if (!m_symmetricmode) {
00405     IndexVector post, iwork; 
00406     // Post order etree
00407     internal::treePostorder(m_mat.cols(), m_etree, post); 
00408       
00409    
00410     // Renumber etree in postorder 
00411     Index m = m_mat.cols(); 
00412     iwork.resize(m+1);
00413     for (Index i = 0; i < m; ++i) iwork(post(i)) = post(m_etree(i));
00414     m_etree = iwork;
00415     
00416     // Postmultiply A*Pc by post, i.e reorder the matrix according to the postorder of the etree
00417     PermutationType post_perm(m); 
00418     for (Index i = 0; i < m; i++) 
00419       post_perm.indices()(i) = post(i); 
00420         
00421     // Combine the two permutations : postorder the permutation for future use
00422     if(m_perm_c.size()) {
00423       m_perm_c = post_perm * m_perm_c;
00424     }
00425     
00426   } // end postordering 
00427   
00428   m_analysisIsOk = true; 
00429 }
00430 
00431 // Functions needed by the numerical factorization phase
00432 
00433 
00452 template <typename MatrixType, typename OrderingType>
00453 void SparseLU<MatrixType, OrderingType>::factorize(const MatrixType& matrix)
00454 {
00455   using internal::emptyIdxLU;
00456   eigen_assert(m_analysisIsOk && "analyzePattern() should be called first"); 
00457   eigen_assert((matrix.rows() == matrix.cols()) && "Only for squared matrices");
00458   
00459   typedef typename IndexVector::Scalar Index; 
00460   
00461   
00462   // Apply the column permutation computed in analyzepattern()
00463   //   m_mat = matrix * m_perm_c.inverse(); 
00464   m_mat = matrix;
00465   if (m_perm_c.size()) 
00466   {
00467     m_mat.uncompress(); //NOTE: The effect of this command is only to create the InnerNonzeros pointers.
00468     //Then, permute only the column pointers
00469     const Index * outerIndexPtr;
00470     if (matrix.isCompressed()) outerIndexPtr = matrix.outerIndexPtr();
00471     else
00472     {
00473       Index* outerIndexPtr_t = new Index[matrix.cols()+1];
00474       for(Index i = 0; i <= matrix.cols(); i++) outerIndexPtr_t[i] = m_mat.outerIndexPtr()[i];
00475       outerIndexPtr = outerIndexPtr_t;
00476     }
00477     for (Index i = 0; i < matrix.cols(); i++)
00478     {
00479       m_mat.outerIndexPtr()[m_perm_c.indices()(i)] = outerIndexPtr[i];
00480       m_mat.innerNonZeroPtr()[m_perm_c.indices()(i)] = outerIndexPtr[i+1] - outerIndexPtr[i];
00481     }
00482     if(!matrix.isCompressed()) delete[] outerIndexPtr;
00483   } 
00484   else 
00485   { //FIXME This should not be needed if the empty permutation is handled transparently
00486     m_perm_c.resize(matrix.cols());
00487     for(Index i = 0; i < matrix.cols(); ++i) m_perm_c.indices()(i) = i;
00488   }
00489   
00490   Index m = m_mat.rows();
00491   Index n = m_mat.cols();
00492   Index nnz = m_mat.nonZeros();
00493   Index maxpanel = m_perfv.panel_size * m;
00494   // Allocate working storage common to the factor routines
00495   Index lwork = 0;
00496   Index info = Base::memInit(m, n, nnz, lwork, m_perfv.fillfactor, m_perfv.panel_size, m_glu); 
00497   if (info) 
00498   {
00499     m_lastError = "UNABLE TO ALLOCATE WORKING MEMORY\n\n" ;
00500     m_factorizationIsOk = false;
00501     return ; 
00502   }
00503   
00504   // Set up pointers for integer working arrays 
00505   IndexVector segrep(m); segrep.setZero();
00506   IndexVector parent(m); parent.setZero();
00507   IndexVector xplore(m); xplore.setZero();
00508   IndexVector repfnz(maxpanel);
00509   IndexVector panel_lsub(maxpanel);
00510   IndexVector xprune(n); xprune.setZero();
00511   IndexVector marker(m*internal::LUNoMarker); marker.setZero();
00512   
00513   repfnz.setConstant(-1); 
00514   panel_lsub.setConstant(-1);
00515   
00516   // Set up pointers for scalar working arrays 
00517   ScalarVector dense; 
00518   dense.setZero(maxpanel);
00519   ScalarVector tempv; 
00520   tempv.setZero(internal::LUnumTempV(m, m_perfv.panel_size, m_perfv.maxsuper, /*m_perfv.rowblk*/m) );
00521   
00522   // Compute the inverse of perm_c
00523   PermutationType iperm_c(m_perm_c.inverse()); 
00524   
00525   // Identify initial relaxed snodes
00526   IndexVector relax_end(n);
00527   if ( m_symmetricmode == true ) 
00528     Base::heap_relax_snode(n, m_etree, m_perfv.relax, marker, relax_end);
00529   else
00530     Base::relax_snode(n, m_etree, m_perfv.relax, marker, relax_end);
00531   
00532   
00533   m_perm_r.resize(m); 
00534   m_perm_r.indices().setConstant(-1);
00535   marker.setConstant(-1);
00536   m_detPermR = 1; // Record the determinant of the row permutation
00537   
00538   m_glu.supno(0) = emptyIdxLU; m_glu.xsup.setConstant(0);
00539   m_glu.xsup(0) = m_glu.xlsub(0) = m_glu.xusub(0) = m_glu.xlusup(0) = Index(0);
00540   
00541   // Work on one 'panel' at a time. A panel is one of the following :
00542   //  (a) a relaxed supernode at the bottom of the etree, or
00543   //  (b) panel_size contiguous columns, <panel_size> defined by the user
00544   Index jcol; 
00545   IndexVector panel_histo(n);
00546   Index pivrow; // Pivotal row number in the original row matrix
00547   Index nseg1; // Number of segments in U-column above panel row jcol
00548   Index nseg; // Number of segments in each U-column 
00549   Index irep; 
00550   Index i, k, jj; 
00551   for (jcol = 0; jcol < n; )
00552   {
00553     // Adjust panel size so that a panel won't overlap with the next relaxed snode. 
00554     Index panel_size = m_perfv.panel_size; // upper bound on panel width
00555     for (k = jcol + 1; k < (std::min)(jcol+panel_size, n); k++)
00556     {
00557       if (relax_end(k) != emptyIdxLU) 
00558       {
00559         panel_size = k - jcol; 
00560         break; 
00561       }
00562     }
00563     if (k == n) 
00564       panel_size = n - jcol; 
00565       
00566     // Symbolic outer factorization on a panel of columns 
00567     Base::panel_dfs(m, panel_size, jcol, m_mat, m_perm_r.indices(), nseg1, dense, panel_lsub, segrep, repfnz, xprune, marker, parent, xplore, m_glu); 
00568     
00569     // Numeric sup-panel updates in topological order 
00570     Base::panel_bmod(m, panel_size, jcol, nseg1, dense, tempv, segrep, repfnz, m_glu); 
00571     
00572     // Sparse LU within the panel, and below the panel diagonal 
00573     for ( jj = jcol; jj< jcol + panel_size; jj++) 
00574     {
00575       k = (jj - jcol) * m; // Column index for w-wide arrays 
00576       
00577       nseg = nseg1; // begin after all the panel segments
00578       //Depth-first-search for the current column
00579       VectorBlock<IndexVector> panel_lsubk(panel_lsub, k, m);
00580       VectorBlock<IndexVector> repfnz_k(repfnz, k, m); 
00581       info = Base::column_dfs(m, jj, m_perm_r.indices(), m_perfv.maxsuper, nseg, panel_lsubk, segrep, repfnz_k, xprune, marker, parent, xplore, m_glu); 
00582       if ( info ) 
00583       {
00584         m_lastError =  "UNABLE TO EXPAND MEMORY IN COLUMN_DFS() ";
00585         m_info = NumericalIssue; 
00586         m_factorizationIsOk = false; 
00587         return; 
00588       }
00589       // Numeric updates to this column 
00590       VectorBlock<ScalarVector> dense_k(dense, k, m); 
00591       VectorBlock<IndexVector> segrep_k(segrep, nseg1, m-nseg1); 
00592       info = Base::column_bmod(jj, (nseg - nseg1), dense_k, tempv, segrep_k, repfnz_k, jcol, m_glu); 
00593       if ( info ) 
00594       {
00595         m_lastError = "UNABLE TO EXPAND MEMORY IN COLUMN_BMOD() ";
00596         m_info = NumericalIssue; 
00597         m_factorizationIsOk = false; 
00598         return; 
00599       }
00600       
00601       // Copy the U-segments to ucol(*)
00602       info = Base::copy_to_ucol(jj, nseg, segrep, repfnz_k ,m_perm_r.indices(), dense_k, m_glu); 
00603       if ( info ) 
00604       {
00605         m_lastError = "UNABLE TO EXPAND MEMORY IN COPY_TO_UCOL() ";
00606         m_info = NumericalIssue; 
00607         m_factorizationIsOk = false; 
00608         return; 
00609       }
00610       
00611       // Form the L-segment 
00612       info = Base::pivotL(jj, m_diagpivotthresh, m_perm_r.indices(), iperm_c.indices(), pivrow, m_glu);
00613       if ( info ) 
00614       {
00615         m_lastError = "THE MATRIX IS STRUCTURALLY SINGULAR ... ZERO COLUMN AT ";
00616         std::ostringstream returnInfo;
00617         returnInfo << info; 
00618         m_lastError += returnInfo.str();
00619         m_info = NumericalIssue; 
00620         m_factorizationIsOk = false; 
00621         return; 
00622       }
00623       
00624       // Update the determinant of the row permutation matrix
00625       if (pivrow != jj) m_detPermR *= -1;
00626 
00627       // Prune columns (0:jj-1) using column jj
00628       Base::pruneL(jj, m_perm_r.indices(), pivrow, nseg, segrep, repfnz_k, xprune, m_glu); 
00629       
00630       // Reset repfnz for this column 
00631       for (i = 0; i < nseg; i++)
00632       {
00633         irep = segrep(i); 
00634         repfnz_k(irep) = emptyIdxLU; 
00635       }
00636     } // end SparseLU within the panel  
00637     jcol += panel_size;  // Move to the next panel
00638   } // end for -- end elimination 
00639   
00640   // Count the number of nonzeros in factors 
00641   Base::countnz(n, m_nnzL, m_nnzU, m_glu); 
00642   // Apply permutation  to the L subscripts 
00643   Base::fixupL(n, m_perm_r.indices(), m_glu); 
00644   
00645   // Create supernode matrix L 
00646   m_Lstore.setInfos(m, n, m_glu.lusup, m_glu.xlusup, m_glu.lsub, m_glu.xlsub, m_glu.supno, m_glu.xsup); 
00647   // Create the column major upper sparse matrix  U; 
00648   new (&m_Ustore) MappedSparseMatrix<Scalar, ColMajor, Index> ( m, n, m_nnzU, m_glu.xusub.data(), m_glu.usub.data(), m_glu.ucol.data() ); 
00649   
00650   m_info = Success;
00651   m_factorizationIsOk = true;
00652 }
00653 
00654 template<typename MappedSupernodalType>
00655 struct SparseLUMatrixLReturnType : internal::no_assignment_operator
00656 {
00657   typedef typename MappedSupernodalType::Index Index;
00658   typedef typename MappedSupernodalType::Scalar Scalar;
00659   SparseLUMatrixLReturnType(const MappedSupernodalType& mapL) : m_mapL(mapL)
00660   { }
00661   Index rows() { return m_mapL.rows(); }
00662   Index cols() { return m_mapL.cols(); }
00663   template<typename Dest>
00664   void solveInPlace( MatrixBase<Dest> &X) const
00665   {
00666     m_mapL.solveInPlace(X);
00667   }
00668   const MappedSupernodalType& m_mapL;
00669 };
00670 
00671 template<typename MatrixLType, typename MatrixUType>
00672 struct SparseLUMatrixUReturnType : internal::no_assignment_operator
00673 {
00674   typedef typename MatrixLType::Index Index;
00675   typedef typename MatrixLType::Scalar Scalar;
00676   SparseLUMatrixUReturnType(const MatrixLType& mapL, const MatrixUType& mapU)
00677   : m_mapL(mapL),m_mapU(mapU)
00678   { }
00679   Index rows() { return m_mapL.rows(); }
00680   Index cols() { return m_mapL.cols(); }
00681 
00682   template<typename Dest>   void solveInPlace(MatrixBase<Dest> &X) const
00683   {
00684     Index nrhs = X.cols();
00685     Index n = X.rows();
00686     // Backward solve with U
00687     for (Index k = m_mapL.nsuper(); k >= 0; k--)
00688     {
00689       Index fsupc = m_mapL.supToCol()[k];
00690       Index lda = m_mapL.colIndexPtr()[fsupc+1] - m_mapL.colIndexPtr()[fsupc]; // leading dimension
00691       Index nsupc = m_mapL.supToCol()[k+1] - fsupc;
00692       Index luptr = m_mapL.colIndexPtr()[fsupc];
00693 
00694       if (nsupc == 1)
00695       {
00696         for (Index j = 0; j < nrhs; j++)
00697         {
00698           X(fsupc, j) /= m_mapL.valuePtr()[luptr];
00699         }
00700       }
00701       else
00702       {
00703         Map<const Matrix<Scalar,Dynamic,Dynamic>, 0, OuterStride<> > A( &(m_mapL.valuePtr()[luptr]), nsupc, nsupc, OuterStride<>(lda) );
00704         Map< Matrix<Scalar,Dynamic,Dynamic>, 0, OuterStride<> > U (&(X(fsupc,0)), nsupc, nrhs, OuterStride<>(n) );
00705         U = A.template triangularView<Upper>().solve(U);
00706       }
00707 
00708       for (Index j = 0; j < nrhs; ++j)
00709       {
00710         for (Index jcol = fsupc; jcol < fsupc + nsupc; jcol++)
00711         {
00712           typename MatrixUType::InnerIterator it(m_mapU, jcol);
00713           for ( ; it; ++it)
00714           {
00715             Index irow = it.index();
00716             X(irow, j) -= X(jcol, j) * it.value();
00717           }
00718         }
00719       }
00720     } // End For U-solve
00721   }
00722   const MatrixLType& m_mapL;
00723   const MatrixUType& m_mapU;
00724 };
00725 
00726 namespace internal {
00727   
00728 template<typename _MatrixType, typename Derived, typename Rhs>
00729 struct solve_retval<SparseLU<_MatrixType,Derived>, Rhs>
00730   : solve_retval_base<SparseLU<_MatrixType,Derived>, Rhs>
00731 {
00732   typedef SparseLU<_MatrixType,Derived> Dec;
00733   EIGEN_MAKE_SOLVE_HELPERS(Dec,Rhs)
00734 
00735   template<typename Dest> void evalTo(Dest& dst) const
00736   {
00737     dec()._solve(rhs(),dst);
00738   }
00739 };
00740 
00741 template<typename _MatrixType, typename Derived, typename Rhs>
00742 struct sparse_solve_retval<SparseLU<_MatrixType,Derived>, Rhs>
00743   : sparse_solve_retval_base<SparseLU<_MatrixType,Derived>, Rhs>
00744 {
00745   typedef SparseLU<_MatrixType,Derived> Dec;
00746   EIGEN_MAKE_SPARSE_SOLVE_HELPERS(Dec,Rhs)
00747 
00748   template<typename Dest> void evalTo(Dest& dst) const
00749   {
00750     this->defaultEvalTo(dst);
00751   }
00752 };
00753 } // end namespace internal
00754 
00755 } // End namespace Eigen 
00756 
00757 #endif