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 // IWYU pragma: private
34 #include "./InternalHeaderCheck.h"
35 
36 namespace Eigen {
37 namespace internal {
38 
62 template <typename Scalar, typename StorageIndex>
64  IndexVector& perm_r, IndexVector& iperm_c, Index& pivrow,
65  GlobalLU_t& glu) {
66  Index fsupc = (glu.xsup)((glu.supno)(jcol)); // First column in the supernode containing the column jcol
67  Index nsupc = jcol - fsupc; // Number of columns in the supernode portion, excluding jcol; nsupc >=0
68  Index lptr = glu.xlsub(fsupc); // pointer to the starting location of the row subscripts for this supernode portion
69  Index nsupr = glu.xlsub(fsupc + 1) - lptr; // Number of rows in the supernode
70  Index lda = glu.xlusup(fsupc + 1) - glu.xlusup(fsupc); // leading dimension
71  Scalar* lu_sup_ptr = &(glu.lusup.data()[glu.xlusup(fsupc)]); // Start of the current supernode
72  Scalar* lu_col_ptr = &(glu.lusup.data()[glu.xlusup(jcol)]); // Start of jcol in the supernode
73  StorageIndex* lsub_ptr = &(glu.lsub.data()[lptr]); // Start of row indices of the supernode
74 
75  // Determine the largest abs numerical value for partial pivoting
76  Index diagind = iperm_c(jcol); // diagonal index
77  RealScalar pivmax(-1.0);
78  Index pivptr = nsupc;
80  RealScalar rtemp;
81  Index isub, icol, itemp, k;
82  for (isub = nsupc; isub < nsupr; ++isub) {
83  using std::abs;
84  rtemp = abs(lu_col_ptr[isub]);
85  if (rtemp > pivmax) {
86  pivmax = rtemp;
87  pivptr = isub;
88  }
89  if (lsub_ptr[isub] == diagind) diag = isub;
90  }
91 
92  // Test for singularity
93  if (pivmax <= RealScalar(0.0)) {
94  // if pivmax == -1, the column is structurally empty, otherwise it is only numerically zero
95  pivrow = pivmax < RealScalar(0.0) ? diagind : lsub_ptr[pivptr];
96  perm_r(pivrow) = StorageIndex(jcol);
97  return (jcol + 1);
98  }
99 
100  RealScalar thresh = diagpivotthresh * pivmax;
101 
102  // Choose appropriate pivotal element
103 
104  {
105  // Test if the diagonal element can be used as a pivot (given the threshold value)
106  if (diag >= 0) {
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  std::swap(lsub_ptr[pivptr], lsub_ptr[nsupc]);
120  // Interchange numerical values as well, for the two rows in the whole snode
121  // such that L is indexed the same way as A
122  for (icol = 0; icol <= nsupc; icol++) {
123  itemp = pivptr + icol * lda;
124  std::swap(lu_sup_ptr[itemp], lu_sup_ptr[nsupc + icol * lda]);
125  }
126  }
127  // cdiv operations
128  Scalar temp = Scalar(1.0) / lu_col_ptr[nsupc];
129  for (k = nsupc + 1; k < nsupr; k++) lu_col_ptr[k] *= temp;
130  return 0;
131 }
132 
133 } // end namespace internal
134 } // end namespace Eigen
135 
136 #endif // SPARSELU_PIVOTL_H
AnnoyingScalar abs(const AnnoyingScalar &x)
Definition: AnnoyingScalar.h:135
SCALAR Scalar
Definition: bench_gemm.cpp:45
NumTraits< Scalar >::Real RealScalar
Definition: bench_gemm.cpp:46
ScalarVector::RealScalar RealScalar
Definition: SparseLUImpl.h:29
Index pivotL(const Index jcol, const RealScalar &diagpivotthresh, IndexVector &perm_r, IndexVector &iperm_c, Index &pivrow, GlobalLU_t &glu)
Performs the numerical pivoting on the current column of L, and the CDIV operation.
Definition: SparseLU_pivotL.h:63
EIGEN_BLAS_FUNC() swap(int *n, RealScalar *px, int *incx, RealScalar *py, int *incy)
Definition: level1_impl.h:117
const char const int const RealScalar const RealScalar const int * lda
Definition: level2_cplx_impl.h:20
const char const char const char * diag
Definition: level2_impl.h:86
char char char int int * k
Definition: level2_impl.h:374
@ emptyIdxLU
Definition: SparseLU_Memory.h:41
Namespace containing all symbols from the Eigen library.
Definition: bench_norm.cpp:70
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:83
Definition: Eigen_Colamd.h:49
Definition: SparseLU_Structs.h:80
IndexVector xsup
Definition: SparseLU_Structs.h:82
IndexVector xlusup
Definition: SparseLU_Structs.h:86
IndexVector supno
Definition: SparseLU_Structs.h:83
IndexVector lsub
Definition: SparseLU_Structs.h:85
IndexVector xlsub
Definition: SparseLU_Structs.h:87
ScalarVector lusup
Definition: SparseLU_Structs.h:84