SparseLU_pruneL.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 [s,d,c,z]pruneL.c file in SuperLU
13 
14  * -- SuperLU routine (version 2.0) --
15  * Univ. of California Berkeley, Xerox Palo Alto Research Center,
16  * and Lawrence Berkeley National Lab.
17  * November 15, 1997
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_PRUNEL_H
31 #define SPARSELU_PRUNEL_H
32 
33 #include "./InternalHeaderCheck.h"
34 
35 namespace Eigen {
36 namespace internal {
37 
54 template <typename Scalar, typename StorageIndex>
55 void SparseLUImpl<Scalar,StorageIndex>::pruneL(const Index jcol, const IndexVector& perm_r, const Index pivrow, const Index nseg,
56  const IndexVector& segrep, BlockIndexVector repfnz, IndexVector& xprune, GlobalLU_t& glu)
57 {
58  // For each supernode-rep irep in U(*,j]
59  Index jsupno = glu.supno(jcol);
60  Index i,irep,irep1;
61  bool movnum, do_prune = false;
62  Index kmin = 0, kmax = 0, minloc, maxloc,krow;
63  for (i = 0; i < nseg; i++)
64  {
65  irep = segrep(i);
66  irep1 = irep + 1;
67  do_prune = false;
68 
69  // Don't prune with a zero U-segment
70  if (repfnz(irep) == emptyIdxLU) continue;
71 
72  // If a snode overlaps with the next panel, then the U-segment
73  // is fragmented into two parts -- irep and irep1. We should let
74  // pruning occur at the rep-column in irep1s snode.
75  if (glu.supno(irep) == glu.supno(irep1) ) continue; // don't prune
76 
77  // If it has not been pruned & it has a nonz in row L(pivrow,i)
78  if (glu.supno(irep) != jsupno )
79  {
80  if ( xprune (irep) >= glu.xlsub(irep1) )
81  {
82  kmin = glu.xlsub(irep);
83  kmax = glu.xlsub(irep1) - 1;
84  for (krow = kmin; krow <= kmax; krow++)
85  {
86  if (glu.lsub(krow) == pivrow)
87  {
88  do_prune = true;
89  break;
90  }
91  }
92  }
93 
94  if (do_prune)
95  {
96  // do a quicksort-type partition
97  // movnum=true means that the num values have to be exchanged
98  movnum = false;
99  if (irep == glu.xsup(glu.supno(irep)) ) // Snode of size 1
100  movnum = true;
101 
102  while (kmin <= kmax)
103  {
104  if (perm_r(glu.lsub(kmax)) == emptyIdxLU)
105  kmax--;
106  else if ( perm_r(glu.lsub(kmin)) != emptyIdxLU)
107  kmin++;
108  else
109  {
110  // kmin below pivrow (not yet pivoted), and kmax
111  // above pivrow: interchange the two suscripts
112  std::swap(glu.lsub(kmin), glu.lsub(kmax));
113 
114  // If the supernode has only one column, then we
115  // only keep one set of subscripts. For any subscript
116  // intercnahge performed, similar interchange must be
117  // done on the numerical values.
118  if (movnum)
119  {
120  minloc = glu.xlusup(irep) + ( kmin - glu.xlsub(irep) );
121  maxloc = glu.xlusup(irep) + ( kmax - glu.xlsub(irep) );
122  std::swap(glu.lusup(minloc), glu.lusup(maxloc));
123  }
124  kmin++;
125  kmax--;
126  }
127  } // end while
128 
129  xprune(irep) = StorageIndex(kmin); //Pruning
130  } // end if do_prune
131  } // end pruning
132  } // End for each U-segment
133 }
134 
135 } // end namespace internal
136 } // end namespace Eigen
137 
138 #endif // SPARSELU_PRUNEL_H
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