SparseLU_pivotL.h
Go to the documentation of this file.
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2012 Désiré Nuentsa-Wakam <desire.nuentsa_wakam@inria.fr>
5 //
6 // This Source Code Form is subject to the terms of the Mozilla
7 // Public License v. 2.0. If a copy of the MPL was not distributed
8 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 
10 /*
11 
12  * NOTE: This file is the modified version of xpivotL.c file in SuperLU
13 
14  * -- SuperLU routine (version 3.0) --
15  * Univ. of California Berkeley, Xerox Palo Alto Research Center,
16  * and Lawrence Berkeley National Lab.
17  * October 15, 2003
18  *
19  * Copyright (c) 1994 by Xerox Corporation. All rights reserved.
20  *
21  * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY
22  * EXPRESSED OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
23  *
24  * Permission is hereby granted to use or copy this program for any
25  * purpose, provided the above notices are retained on all copies.
26  * Permission to modify the code and to distribute modified code is
27  * granted, provided the above notices are retained, and a notice that
28  * the code was modified is included with the above copyright notice.
29  */
30 #ifndef SPARSELU_PIVOTL_H
31 #define SPARSELU_PIVOTL_H
32 
33 #include "./InternalHeaderCheck.h"
34 
35 namespace Eigen {
36 namespace internal {
37 
61 template <typename Scalar, typename StorageIndex>
62 Index SparseLUImpl<Scalar,StorageIndex>::pivotL(const Index jcol, const RealScalar& diagpivotthresh, IndexVector& perm_r, IndexVector& iperm_c, Index& pivrow, GlobalLU_t& glu)
63 {
64 
65  Index fsupc = (glu.xsup)((glu.supno)(jcol)); // First column in the supernode containing the column jcol
66  Index nsupc = jcol - fsupc; // Number of columns in the supernode portion, excluding jcol; nsupc >=0
67  Index lptr = glu.xlsub(fsupc); // pointer to the starting location of the row subscripts for this supernode portion
68  Index nsupr = glu.xlsub(fsupc+1) - lptr; // Number of rows in the supernode
69  Index lda = glu.xlusup(fsupc+1) - glu.xlusup(fsupc); // leading dimension
70  Scalar* lu_sup_ptr = &(glu.lusup.data()[glu.xlusup(fsupc)]); // Start of the current supernode
71  Scalar* lu_col_ptr = &(glu.lusup.data()[glu.xlusup(jcol)]); // Start of jcol in the supernode
72  StorageIndex* lsub_ptr = &(glu.lsub.data()[lptr]); // Start of row indices of the supernode
73 
74  // Determine the largest abs numerical value for partial pivoting
75  Index diagind = iperm_c(jcol); // diagonal index
76  RealScalar pivmax(-1.0);
77  Index pivptr = nsupc;
78  Index diag = emptyIdxLU;
79  RealScalar rtemp;
80  Index isub, icol, itemp, k;
81  for (isub = nsupc; isub < nsupr; ++isub) {
82  using std::abs;
83  rtemp = abs(lu_col_ptr[isub]);
84  if (rtemp > pivmax) {
85  pivmax = rtemp;
86  pivptr = isub;
87  }
88  if (lsub_ptr[isub] == diagind) diag = isub;
89  }
90 
91  // Test for singularity
92  if ( pivmax <= RealScalar(0.0) ) {
93  // if pivmax == -1, the column is structurally empty, otherwise it is only numerically zero
94  pivrow = pivmax < RealScalar(0.0) ? diagind : lsub_ptr[pivptr];
95  perm_r(pivrow) = StorageIndex(jcol);
96  return (jcol+1);
97  }
98 
99  RealScalar thresh = diagpivotthresh * pivmax;
100 
101  // Choose appropriate pivotal element
102 
103  {
104  // Test if the diagonal element can be used as a pivot (given the threshold value)
105  if (diag >= 0 )
106  {
107  // Diagonal element exists
108  using std::abs;
109  rtemp = abs(lu_col_ptr[diag]);
110  if (rtemp != RealScalar(0.0) && rtemp >= thresh) pivptr = diag;
111  }
112  pivrow = lsub_ptr[pivptr];
113  }
114 
115  // Record pivot row
116  perm_r(pivrow) = StorageIndex(jcol);
117  // Interchange row subscripts
118  if (pivptr != nsupc )
119  {
120  std::swap( lsub_ptr[pivptr], lsub_ptr[nsupc] );
121  // Interchange numerical values as well, for the two rows in the whole snode
122  // such that L is indexed the same way as A
123  for (icol = 0; icol <= nsupc; icol++)
124  {
125  itemp = pivptr + icol * lda;
126  std::swap(lu_sup_ptr[itemp], lu_sup_ptr[nsupc + icol * lda]);
127  }
128  }
129  // cdiv operations
130  Scalar temp = Scalar(1.0) / lu_col_ptr[nsupc];
131  for (k = nsupc+1; k < nsupr; k++)
132  lu_col_ptr[k] *= temp;
133  return 0;
134 }
135 
136 } // end namespace internal
137 } // end namespace Eigen
138 
139 #endif // SPARSELU_PIVOTL_H
const AbsReturnType abs() const
void swap(scoped_array< T > &a, scoped_array< T > &b)
Definition: Memory.h:788
: InteropHeaders
Definition: Core:139
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:82
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_abs_op< typename Derived::Scalar >, const Derived > abs(const Eigen::ArrayBase< Derived > &x)