Eigen  5.0.1
 
Loading...
Searching...
No Matches
SparseLU_pruneL.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 <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// SPDX-License-Identifier: MPL-2.0
10
11/*
12
13 * NOTE: This file is the modified version of [s,d,c,z]pruneL.c file in SuperLU
14
15 * -- SuperLU routine (version 2.0) --
16 * Univ. of California Berkeley, Xerox Palo Alto Research Center,
17 * and Lawrence Berkeley National Lab.
18 * November 15, 1997
19 *
20 * Copyright (c) 1994 by Xerox Corporation. All rights reserved.
21 *
22 * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY
23 * EXPRESSED OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
24 *
25 * Permission is hereby granted to use or copy this program for any
26 * purpose, provided the above notices are retained on all copies.
27 * Permission to modify the code and to distribute modified code is
28 * granted, provided the above notices are retained, and a notice that
29 * the code was modified is included with the above copyright notice.
30 */
31#ifndef SPARSELU_PRUNEL_H
32#define SPARSELU_PRUNEL_H
33
34// IWYU pragma: private
35#include "./InternalHeaderCheck.h"
36
37namespace Eigen {
38namespace internal {
39
56template <typename Scalar, typename StorageIndex>
57void SparseLUImpl<Scalar, StorageIndex>::pruneL(const Index jcol, const IndexVector& perm_r, const Index pivrow,
58 const Index nseg, const IndexVector& segrep, BlockIndexVector repfnz,
59 IndexVector& xprune, GlobalLU_t& glu) {
60 // For each supernode-rep irep in U(*,j]
61 Index jsupno = glu.supno(jcol);
62 Index i, irep, irep1;
63 bool movnum, do_prune = false;
64 Index kmin = 0, kmax = 0, minloc, maxloc, krow;
65 for (i = 0; i < nseg; i++) {
66 irep = segrep(i);
67 irep1 = irep + 1;
68 do_prune = false;
69
70 // Don't prune with a zero U-segment
71 if (repfnz(irep) == emptyIdxLU) continue;
72
73 // If a snode overlaps with the next panel, then the U-segment
74 // is fragmented into two parts -- irep and irep1. We should let
75 // pruning occur at the rep-column in irep1's snode.
76 if (glu.supno(irep) == glu.supno(irep1)) continue; // don't prune
77
78 // If it has not been pruned & it has a nonz in row L(pivrow,i)
79 if (glu.supno(irep) != jsupno) {
80 if (xprune(irep) >= glu.xlsub(irep1)) {
81 kmin = glu.xlsub(irep);
82 kmax = glu.xlsub(irep1) - 1;
83 for (krow = kmin; krow <= kmax; krow++) {
84 if (glu.lsub(krow) == pivrow) {
85 do_prune = true;
86 break;
87 }
88 }
89 }
90
91 if (do_prune) {
92 // do a quicksort-type partition
93 // movnum=true means that the num values have to be exchanged
94 movnum = false;
95 if (irep == glu.xsup(glu.supno(irep))) // Snode of size 1
96 movnum = true;
97
98 while (kmin <= kmax) {
99 if (perm_r(glu.lsub(kmax)) == emptyIdxLU)
100 kmax--;
101 else if (perm_r(glu.lsub(kmin)) != emptyIdxLU)
102 kmin++;
103 else {
104 // kmin below pivrow (not yet pivoted), and kmax
105 // above pivrow: interchange the two subscripts
106 std::swap(glu.lsub(kmin), glu.lsub(kmax));
107
108 // If the supernode has only one column, then we
109 // only keep one set of subscripts. For any subscript
110 // interchange performed, similar interchange must be
111 // done on the numerical values.
112 if (movnum) {
113 minloc = glu.xlusup(irep) + (kmin - glu.xlsub(irep));
114 maxloc = glu.xlusup(irep) + (kmax - glu.xlsub(irep));
115 std::swap(glu.lusup(minloc), glu.lusup(maxloc));
116 }
117 kmin++;
118 kmax--;
119 }
120 } // end while
121
122 xprune(irep) = StorageIndex(kmin); // Pruning
123 } // end if do_prune
124 } // end pruning
125 } // End for each U-segment
126}
127
128} // end namespace internal
129} // end namespace Eigen
130
131#endif // SPARSELU_PRUNEL_H
void pruneL(const Index jcol, const IndexVector &perm_r, const Index pivrow, const Index nseg, const IndexVector &segrep, BlockIndexVector repfnz, IndexVector &xprune, GlobalLU_t &glu)
Prunes the L-structure.
Definition SparseLU_pruneL.h:57