Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifndef SPARSELU_PIVOTL_H
00031 #define SPARSELU_PIVOTL_H
00032
00033 namespace Eigen {
00034 namespace internal {
00035
00059 template <typename Scalar, typename Index>
00060 Index SparseLUImpl<Scalar,Index>::pivotL(const Index jcol, const RealScalar& diagpivotthresh, IndexVector& perm_r, IndexVector& iperm_c, Index& pivrow, GlobalLU_t& glu)
00061 {
00062
00063 Index fsupc = (glu.xsup)((glu.supno)(jcol));
00064 Index nsupc = jcol - fsupc;
00065 Index lptr = glu.xlsub(fsupc);
00066 Index nsupr = glu.xlsub(fsupc+1) - lptr;
00067 Index lda = glu.xlusup(fsupc+1) - glu.xlusup(fsupc);
00068 Scalar* lu_sup_ptr = &(glu.lusup.data()[glu.xlusup(fsupc)]);
00069 Scalar* lu_col_ptr = &(glu.lusup.data()[glu.xlusup(jcol)]);
00070 Index* lsub_ptr = &(glu.lsub.data()[lptr]);
00071
00072
00073 Index diagind = iperm_c(jcol);
00074 RealScalar pivmax = 0.0;
00075 Index pivptr = nsupc;
00076 Index diag = emptyIdxLU;
00077 RealScalar rtemp;
00078 Index isub, icol, itemp, k;
00079 for (isub = nsupc; isub < nsupr; ++isub) {
00080 using std::abs;
00081 rtemp = abs(lu_col_ptr[isub]);
00082 if (rtemp > pivmax) {
00083 pivmax = rtemp;
00084 pivptr = isub;
00085 }
00086 if (lsub_ptr[isub] == diagind) diag = isub;
00087 }
00088
00089
00090 if ( pivmax == 0.0 ) {
00091 pivrow = lsub_ptr[pivptr];
00092 perm_r(pivrow) = jcol;
00093 return (jcol+1);
00094 }
00095
00096 RealScalar thresh = diagpivotthresh * pivmax;
00097
00098
00099
00100 {
00101
00102 if (diag >= 0 )
00103 {
00104
00105 using std::abs;
00106 rtemp = abs(lu_col_ptr[diag]);
00107 if (rtemp != 0.0 && rtemp >= thresh) pivptr = diag;
00108 }
00109 pivrow = lsub_ptr[pivptr];
00110 }
00111
00112
00113 perm_r(pivrow) = jcol;
00114
00115 if (pivptr != nsupc )
00116 {
00117 std::swap( lsub_ptr[pivptr], lsub_ptr[nsupc] );
00118
00119
00120 for (icol = 0; icol <= nsupc; icol++)
00121 {
00122 itemp = pivptr + icol * lda;
00123 std::swap(lu_sup_ptr[itemp], lu_sup_ptr[nsupc + icol * lda]);
00124 }
00125 }
00126
00127 Scalar temp = Scalar(1.0) / lu_col_ptr[nsupc];
00128 for (k = nsupc+1; k < nsupr; k++)
00129 lu_col_ptr[k] *= temp;
00130 return 0;
00131 }
00132
00133 }
00134 }
00135
00136 #endif // SPARSELU_PIVOTL_H