Eigen  5.0.1
 
Loading...
Searching...
No Matches
SparseLU_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_RELAX_SNODE_H
30#define SPARSELU_RELAX_SNODE_H
31
32// IWYU pragma: private
33#include "./InternalHeaderCheck.h"
34
35namespace Eigen {
36
37namespace internal {
38
44 * \param n the number of columns
45 * \param et elimination tree
46 * \param relax_columns Maximum number of columns allowed in a relaxed snode
47 * \param descendants Number of descendants of each node in the etree
48 * \param relax_end last column in a supernode
49 */
50template <typename Scalar, typename StorageIndex>
51void SparseLUImpl<Scalar, StorageIndex>::relax_snode(const Index n, IndexVector& et, const Index relax_columns,
52 IndexVector& descendants, IndexVector& relax_end) {
53 // compute the number of descendants of each node in the etree
54 Index parent;
55 relax_end.setConstant(emptyIdxLU);
56 descendants.setZero();
57 for (Index j = 0; j < n; j++) {
58 parent = et(j);
59 if (parent != n) // not the dummy root
60 descendants(parent) += descendants(j) + 1;
61 }
62 // Identify the relaxed supernodes by postorder traversal of the etree
63 Index snode_start; // beginning of a snode
64 for (Index j = 0; j < n;) {
65 parent = et(j);
66 snode_start = j;
67 while (parent != n && descendants(parent) < relax_columns) {
68 j = parent;
69 parent = et(j);
70 }
71 // Found a supernode in postordered etree, j is the last column
72 relax_end(snode_start) = StorageIndex(j); // Record last column
73 j++;
74 // Search for a new leaf
75 while (descendants(j) != 0 && j < n) j++;
76 } // End postorder traversal of the etree
77}
78
79} // end namespace internal
80
81} // end namespace Eigen
82#endif
Derived & setConstant(Index size, const Scalar &val)
Definition CwiseNullaryOp.h:349
Derived & setZero(Index size)
Definition CwiseNullaryOp.h:536
void relax_snode(const Index n, IndexVector &et, const Index relax_columns, IndexVector &descendants, IndexVector &relax_end)
Identify the initial relaxed supernodes.
Definition SparseLU_relax_snode.h:51