Eigen  5.0.1
 
Loading...
Searching...
No Matches
SparseLU_heap_relax_snode.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/* This file is a modified version of heap_relax_snode.c file in SuperLU
12 * -- SuperLU routine (version 3.0) --
13 * Univ. of California Berkeley, Xerox Palo Alto Research Center,
14 * and Lawrence Berkeley National Lab.
15 * October 15, 2003
16 *
17 * Copyright (c) 1994 by Xerox Corporation. All rights reserved.
18 *
19 * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY
20 * EXPRESSED OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
21 *
22 * Permission is hereby granted to use or copy this program for any
23 * purpose, provided the above notices are retained on all copies.
24 * Permission to modify the code and to distribute modified code is
25 * granted, provided the above notices are retained, and a notice that
26 * the code was modified is included with the above copyright notice.
27 */
28
29#ifndef SPARSELU_HEAP_RELAX_SNODE_H
30#define SPARSELU_HEAP_RELAX_SNODE_H
31
32// IWYU pragma: private
33#include "./InternalHeaderCheck.h"
34
35namespace Eigen {
36namespace internal {
37
42 * It assumes that the matrix has been reordered according to the postorder of the etree
43 * \param n The number of columns
44 * \param et elimination tree
45 * \param relax_columns Maximum number of columns allowed in a relaxed snode
46 * \param descendants Number of descendants of each node in the etree
47 * \param relax_end last column in a supernode
48 */
49template <typename Scalar, typename StorageIndex>
50void SparseLUImpl<Scalar, StorageIndex>::heap_relax_snode(const Index n, IndexVector& et, const Index relax_columns,
51 IndexVector& descendants, IndexVector& relax_end) {
52 // The etree may not be postordered, but it's heap ordered
53 IndexVector post;
54 internal::treePostorder(StorageIndex(n), et, post); // Post order etree
55 IndexVector inv_post(n + 1);
56 for (StorageIndex i = 0; i < n + 1; ++i) inv_post(post(i)) = i; // Compute the inverse postorder permutation.
57
58 // Renumber etree in postorder
59 IndexVector iwork(n);
60 IndexVector et_save(n + 1);
61 for (Index i = 0; i < n; ++i) {
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 parent = et(j);
73 if (parent != n) // not the dummy root
74 descendants(parent) += descendants(j) + 1;
75 }
76 // Identify the relaxed supernodes by postorder traversal of the etree
77 Index snode_start; // beginning of a snode
78 StorageIndex k;
79 StorageIndex l;
80 for (j = 0; j < n;) {
81 parent = et(j);
82 snode_start = j;
83 while (parent != n && descendants(parent) < relax_columns) {
84 j = parent;
85 parent = et(j);
86 }
87 // Found a supernode in postordered etree, j is the last column
88 k = StorageIndex(n);
89 for (Index i = snode_start; i <= j; ++i) k = (std::min)(k, inv_post(i));
90 l = inv_post(j);
91 if ((l - k) == (j - snode_start)) // Same number of columns in the snode
92 {
93 // This is also a supernode in the original etree
94 relax_end(k) = l; // Record last column
95 } else {
96 for (Index i = snode_start; i <= j; ++i) {
97 l = inv_post(i);
98 if (descendants(i) == 0) {
99 relax_end(l) = l;
100 }
101 }
102 }
103 j++;
104 // Search for a new leaf
105 while (descendants(j) != 0 && j < n) j++;
106 } // End postorder traversal of the etree
107
108 // Recover the original etree
109 et = et_save;
110}
111
112} // end namespace internal
113
114} // end namespace Eigen
115#endif // SPARSELU_HEAP_RELAX_SNODE_H
Derived & setConstant(Index size, const Scalar &val)
Definition CwiseNullaryOp.h:349
Derived & setZero(Index size)
Definition CwiseNullaryOp.h:536
void heap_relax_snode(const Index n, IndexVector &et, const Index relax_columns, IndexVector &descendants, IndexVector &relax_end)
Identify the initial relaxed supernodes.
Definition SparseLU_heap_relax_snode.h:50