SparseLU_heap_relax_snode.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 /* This file is a modified version of heap_relax_snode.c file in SuperLU
11  * -- SuperLU routine (version 3.0) --
12  * Univ. of California Berkeley, Xerox Palo Alto Research Center,
13  * and Lawrence Berkeley National Lab.
14  * October 15, 2003
15  *
16  * Copyright (c) 1994 by Xerox Corporation. All rights reserved.
17  *
18  * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY
19  * EXPRESSED OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
20  *
21  * Permission is hereby granted to use or copy this program for any
22  * purpose, provided the above notices are retained on all copies.
23  * Permission to modify the code and to distribute modified code is
24  * granted, provided the above notices are retained, and a notice that
25  * the code was modified is included with the above copyright notice.
26  */
27 
28 #ifndef SPARSELU_HEAP_RELAX_SNODE_H
29 #define SPARSELU_HEAP_RELAX_SNODE_H
30 
31 #include "./InternalHeaderCheck.h"
32 
33 namespace Eigen {
34 namespace internal {
35 
47 template <typename Scalar, typename StorageIndex>
48 void SparseLUImpl<Scalar,StorageIndex>::heap_relax_snode (const Index n, IndexVector& et, const Index relax_columns, IndexVector& descendants, IndexVector& relax_end)
49 {
50 
51  // The etree may not be postordered, but its heap ordered
52  IndexVector post;
53  internal::treePostorder(StorageIndex(n), et, post); // Post order etree
54  IndexVector inv_post(n+1);
55  for (StorageIndex i = 0; i < n+1; ++i) inv_post(post(i)) = i; // inv_post = post.inverse()???
56 
57  // Renumber etree in postorder
58  IndexVector iwork(n);
59  IndexVector et_save(n+1);
60  for (Index i = 0; i < n; ++i)
61  {
62  iwork(post(i)) = post(et(i));
63  }
64  et_save = et; // Save the original etree
65  et = iwork;
66 
67  // compute the number of descendants of each node in the etree
68  relax_end.setConstant(emptyIdxLU);
69  Index j, parent;
70  descendants.setZero();
71  for (j = 0; j < n; j++)
72  {
73  parent = et(j);
74  if (parent != n) // not the dummy root
75  descendants(parent) += descendants(j) + 1;
76  }
77  // Identify the relaxed supernodes by postorder traversal of the etree
78  Index snode_start; // beginning of a snode
79  StorageIndex k;
80  StorageIndex l;
81  for (j = 0; j < n; )
82  {
83  parent = et(j);
84  snode_start = j;
85  while ( parent != n && descendants(parent) < relax_columns )
86  {
87  j = parent;
88  parent = et(j);
89  }
90  // Found a supernode in postordered etree, j is the last column
91  k = StorageIndex(n);
92  for (Index i = snode_start; i <= j; ++i)
93  k = (std::min)(k, inv_post(i));
94  l = inv_post(j);
95  if ( (l - k) == (j - snode_start) ) // Same number of columns in the snode
96  {
97  // This is also a supernode in the original etree
98  relax_end(k) = l; // Record last column
99  }
100  else
101  {
102  for (Index i = snode_start; i <= j; ++i)
103  {
104  l = inv_post(i);
105  if (descendants(i) == 0)
106  {
107  relax_end(l) = l;
108  }
109  }
110  }
111  j++;
112  // Search for a new leaf
113  while (descendants(j) != 0 && j < n) j++;
114  } // End postorder traversal of the etree
115 
116  // Recover the original etree
117  et = et_save;
118 }
119 
120 } // end namespace internal
121 
122 } // end namespace Eigen
123 #endif // SPARSELU_HEAP_RELAX_SNODE_H
int n
bfloat16() min(const bfloat16 &a, const bfloat16 &b)
Definition: BFloat16.h:684
void treePostorder(typename IndexVector::Scalar n, IndexVector &parent, IndexVector &post)
Post order a tree.
: InteropHeaders
Definition: Core:139
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:82
std::ptrdiff_t j