Eigen  3.4.90 (git rev 5a9f66fb35d03a4da9ef8976e67a61b30aa16dcf)
 
Loading...
Searching...
No Matches
SparseLU_pivotL.h
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 <[email protected]>
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
36namespace Eigen {
37namespace internal {
38
62template <typename Scalar, typename StorageIndex>
63Index SparseLUImpl<Scalar, StorageIndex>::pivotL(const Index jcol, const RealScalar& diagpivotthresh,
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;
79 Index diag = emptyIdxLU;
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
Namespace containing all symbols from the Eigen library.
Definition Core:137
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_abs_op< typename Derived::Scalar >, const Derived > abs(const Eigen::ArrayBase< Derived > &x)