xref: /aosp_15_r20/external/eigen/Eigen/src/SparseLU/SparseLU_pruneL.h (revision bf2c37156dfe67e5dfebd6d394bad8b2ab5804d4)
1*bf2c3715SXin Li // This file is part of Eigen, a lightweight C++ template library
2*bf2c3715SXin Li // for linear algebra.
3*bf2c3715SXin Li //
4*bf2c3715SXin Li // Copyright (C) 2012 Désiré Nuentsa-Wakam <[email protected]>
5*bf2c3715SXin Li //
6*bf2c3715SXin Li // This Source Code Form is subject to the terms of the Mozilla
7*bf2c3715SXin Li // Public License v. 2.0. If a copy of the MPL was not distributed
8*bf2c3715SXin Li // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9*bf2c3715SXin Li 
10*bf2c3715SXin Li /*
11*bf2c3715SXin Li 
12*bf2c3715SXin Li  * NOTE: This file is the modified version of [s,d,c,z]pruneL.c file in SuperLU
13*bf2c3715SXin Li 
14*bf2c3715SXin Li  * -- SuperLU routine (version 2.0) --
15*bf2c3715SXin Li  * Univ. of California Berkeley, Xerox Palo Alto Research Center,
16*bf2c3715SXin Li  * and Lawrence Berkeley National Lab.
17*bf2c3715SXin Li  * November 15, 1997
18*bf2c3715SXin Li  *
19*bf2c3715SXin Li  * Copyright (c) 1994 by Xerox Corporation.  All rights reserved.
20*bf2c3715SXin Li  *
21*bf2c3715SXin Li  * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY
22*bf2c3715SXin Li  * EXPRESSED OR IMPLIED.  ANY USE IS AT YOUR OWN RISK.
23*bf2c3715SXin Li  *
24*bf2c3715SXin Li  * Permission is hereby granted to use or copy this program for any
25*bf2c3715SXin Li  * purpose, provided the above notices are retained on all copies.
26*bf2c3715SXin Li  * Permission to modify the code and to distribute modified code is
27*bf2c3715SXin Li  * granted, provided the above notices are retained, and a notice that
28*bf2c3715SXin Li  * the code was modified is included with the above copyright notice.
29*bf2c3715SXin Li  */
30*bf2c3715SXin Li #ifndef SPARSELU_PRUNEL_H
31*bf2c3715SXin Li #define SPARSELU_PRUNEL_H
32*bf2c3715SXin Li 
33*bf2c3715SXin Li namespace Eigen {
34*bf2c3715SXin Li namespace internal {
35*bf2c3715SXin Li 
36*bf2c3715SXin Li /**
37*bf2c3715SXin Li  * \brief Prunes the L-structure.
38*bf2c3715SXin Li  *
39*bf2c3715SXin Li  * It prunes the L-structure  of supernodes whose L-structure contains the current pivot row "pivrow"
40*bf2c3715SXin Li  *
41*bf2c3715SXin Li  *
42*bf2c3715SXin Li  * \param jcol The current column of L
43*bf2c3715SXin Li  * \param[in] perm_r Row permutation
44*bf2c3715SXin Li  * \param[out] pivrow  The pivot row
45*bf2c3715SXin Li  * \param nseg Number of segments
46*bf2c3715SXin Li  * \param segrep
47*bf2c3715SXin Li  * \param repfnz
48*bf2c3715SXin Li  * \param[out] xprune
49*bf2c3715SXin Li  * \param glu Global LU data
50*bf2c3715SXin Li  *
51*bf2c3715SXin Li  */
52*bf2c3715SXin Li template <typename Scalar, typename StorageIndex>
pruneL(const Index jcol,const IndexVector & perm_r,const Index pivrow,const Index nseg,const IndexVector & segrep,BlockIndexVector repfnz,IndexVector & xprune,GlobalLU_t & glu)53*bf2c3715SXin Li void SparseLUImpl<Scalar,StorageIndex>::pruneL(const Index jcol, const IndexVector& perm_r, const Index pivrow, const Index nseg,
54*bf2c3715SXin Li                                                const IndexVector& segrep, BlockIndexVector repfnz, IndexVector& xprune, GlobalLU_t& glu)
55*bf2c3715SXin Li {
56*bf2c3715SXin Li   // For each supernode-rep irep in U(*,j]
57*bf2c3715SXin Li   Index jsupno = glu.supno(jcol);
58*bf2c3715SXin Li   Index i,irep,irep1;
59*bf2c3715SXin Li   bool movnum, do_prune = false;
60*bf2c3715SXin Li   Index kmin = 0, kmax = 0, minloc, maxloc,krow;
61*bf2c3715SXin Li   for (i = 0; i < nseg; i++)
62*bf2c3715SXin Li   {
63*bf2c3715SXin Li     irep = segrep(i);
64*bf2c3715SXin Li     irep1 = irep + 1;
65*bf2c3715SXin Li     do_prune = false;
66*bf2c3715SXin Li 
67*bf2c3715SXin Li     // Don't prune with a zero U-segment
68*bf2c3715SXin Li     if (repfnz(irep) == emptyIdxLU) continue;
69*bf2c3715SXin Li 
70*bf2c3715SXin Li     // If a snode overlaps with the next panel, then the U-segment
71*bf2c3715SXin Li     // is fragmented into two parts -- irep and irep1. We should let
72*bf2c3715SXin Li     // pruning occur at the rep-column in irep1s snode.
73*bf2c3715SXin Li     if (glu.supno(irep) == glu.supno(irep1) ) continue; // don't prune
74*bf2c3715SXin Li 
75*bf2c3715SXin Li     // If it has not been pruned & it has a nonz in row L(pivrow,i)
76*bf2c3715SXin Li     if (glu.supno(irep) != jsupno )
77*bf2c3715SXin Li     {
78*bf2c3715SXin Li       if ( xprune (irep) >= glu.xlsub(irep1) )
79*bf2c3715SXin Li       {
80*bf2c3715SXin Li         kmin = glu.xlsub(irep);
81*bf2c3715SXin Li         kmax = glu.xlsub(irep1) - 1;
82*bf2c3715SXin Li         for (krow = kmin; krow <= kmax; krow++)
83*bf2c3715SXin Li         {
84*bf2c3715SXin Li           if (glu.lsub(krow) == pivrow)
85*bf2c3715SXin Li           {
86*bf2c3715SXin Li             do_prune = true;
87*bf2c3715SXin Li             break;
88*bf2c3715SXin Li           }
89*bf2c3715SXin Li         }
90*bf2c3715SXin Li       }
91*bf2c3715SXin Li 
92*bf2c3715SXin Li       if (do_prune)
93*bf2c3715SXin Li       {
94*bf2c3715SXin Li         // do a quicksort-type partition
95*bf2c3715SXin Li         // movnum=true means that the num values have to be exchanged
96*bf2c3715SXin Li         movnum = false;
97*bf2c3715SXin Li         if (irep == glu.xsup(glu.supno(irep)) ) // Snode of size 1
98*bf2c3715SXin Li           movnum = true;
99*bf2c3715SXin Li 
100*bf2c3715SXin Li         while (kmin <= kmax)
101*bf2c3715SXin Li         {
102*bf2c3715SXin Li           if (perm_r(glu.lsub(kmax)) == emptyIdxLU)
103*bf2c3715SXin Li             kmax--;
104*bf2c3715SXin Li           else if ( perm_r(glu.lsub(kmin)) != emptyIdxLU)
105*bf2c3715SXin Li             kmin++;
106*bf2c3715SXin Li           else
107*bf2c3715SXin Li           {
108*bf2c3715SXin Li             // kmin below pivrow (not yet pivoted), and kmax
109*bf2c3715SXin Li             // above pivrow: interchange the two suscripts
110*bf2c3715SXin Li             std::swap(glu.lsub(kmin), glu.lsub(kmax));
111*bf2c3715SXin Li 
112*bf2c3715SXin Li             // If the supernode has only one column, then we
113*bf2c3715SXin Li             // only keep one set of subscripts. For any subscript
114*bf2c3715SXin Li             // intercnahge performed, similar interchange must be
115*bf2c3715SXin Li             // done on the numerical values.
116*bf2c3715SXin Li             if (movnum)
117*bf2c3715SXin Li             {
118*bf2c3715SXin Li               minloc = glu.xlusup(irep) + ( kmin - glu.xlsub(irep) );
119*bf2c3715SXin Li               maxloc = glu.xlusup(irep) + ( kmax - glu.xlsub(irep) );
120*bf2c3715SXin Li               std::swap(glu.lusup(minloc), glu.lusup(maxloc));
121*bf2c3715SXin Li             }
122*bf2c3715SXin Li             kmin++;
123*bf2c3715SXin Li             kmax--;
124*bf2c3715SXin Li           }
125*bf2c3715SXin Li         } // end while
126*bf2c3715SXin Li 
127*bf2c3715SXin Li         xprune(irep) = StorageIndex(kmin);  //Pruning
128*bf2c3715SXin Li       } // end if do_prune
129*bf2c3715SXin Li     } // end pruning
130*bf2c3715SXin Li   } // End for each U-segment
131*bf2c3715SXin Li }
132*bf2c3715SXin Li 
133*bf2c3715SXin Li } // end namespace internal
134*bf2c3715SXin Li } // end namespace Eigen
135*bf2c3715SXin Li 
136*bf2c3715SXin Li #endif // SPARSELU_PRUNEL_H
137