2012-05-25 18:17:57 +02:00
|
|
|
// This file is part of Eigen, a lightweight C++ template library
|
|
|
|
|
// for linear algebra.
|
|
|
|
|
//
|
|
|
|
|
// Copyright (C) 2012 Désiré Nuentsa-Wakam <desire.nuentsa_wakam@inria.fr>
|
|
|
|
|
//
|
2012-08-01 11:38:32 +02:00
|
|
|
// This Source Code Form is subject to the terms of the Mozilla
|
|
|
|
|
// Public License v. 2.0. If a copy of the MPL was not distributed
|
|
|
|
|
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
2012-05-25 18:17:57 +02:00
|
|
|
|
|
|
|
|
/* This file is a modified version of heap_relax_snode.c file in SuperLU
|
|
|
|
|
* -- SuperLU routine (version 3.0) --
|
|
|
|
|
* Univ. of California Berkeley, Xerox Palo Alto Research Center,
|
|
|
|
|
* and Lawrence Berkeley National Lab.
|
|
|
|
|
* October 15, 2003
|
|
|
|
|
*
|
|
|
|
|
* Copyright (c) 1994 by Xerox Corporation. All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY
|
|
|
|
|
* EXPRESSED OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
|
|
|
|
|
*
|
|
|
|
|
* Permission is hereby granted to use or copy this program for any
|
|
|
|
|
* purpose, provided the above notices are retained on all copies.
|
|
|
|
|
* Permission to modify the code and to distribute modified code is
|
|
|
|
|
* granted, provided the above notices are retained, and a notice that
|
|
|
|
|
* the code was modified is included with the above copyright notice.
|
|
|
|
|
*/
|
|
|
|
|
|
2012-06-11 18:52:26 +02:00
|
|
|
#ifndef SPARSELU_RELAX_SNODE_H
|
|
|
|
|
#define SPARSELU_RELAX_SNODE_H
|
2013-01-12 11:55:16 +01:00
|
|
|
|
2023-08-21 16:25:22 +00:00
|
|
|
// IWYU pragma: private
|
2021-09-10 19:12:26 +00:00
|
|
|
#include "./InternalHeaderCheck.h"
|
|
|
|
|
|
2013-01-12 11:55:16 +01:00
|
|
|
namespace Eigen {
|
2013-01-25 20:38:26 +01:00
|
|
|
|
|
|
|
|
namespace internal {
|
2023-11-29 11:12:48 +00:00
|
|
|
|
2012-05-25 18:17:57 +02:00
|
|
|
/**
|
|
|
|
|
* \brief Identify the initial relaxed supernodes
|
|
|
|
|
*
|
2012-06-11 18:52:26 +02:00
|
|
|
* This routine is applied to a column elimination tree.
|
2012-05-25 18:17:57 +02:00
|
|
|
* It assumes that the matrix has been reordered according to the postorder of the etree
|
2013-01-21 15:39:18 +01:00
|
|
|
* \param n the number of columns
|
2012-05-25 18:17:57 +02:00
|
|
|
* \param et elimination tree
|
|
|
|
|
* \param relax_columns Maximum number of columns allowed in a relaxed snode
|
|
|
|
|
* \param descendants Number of descendants of each node in the etree
|
|
|
|
|
* \param relax_end last column in a supernode
|
|
|
|
|
*/
|
2015-02-13 18:57:41 +01:00
|
|
|
template <typename Scalar, typename StorageIndex>
|
|
|
|
|
void SparseLUImpl<Scalar, StorageIndex>::relax_snode(const Index n, IndexVector& et, const Index relax_columns,
|
|
|
|
|
IndexVector& descendants, IndexVector& relax_end) {
|
2012-05-25 18:17:57 +02:00
|
|
|
// compute the number of descendants of each node in the etree
|
2015-02-16 13:19:05 +01:00
|
|
|
Index parent;
|
2013-01-25 20:38:26 +01:00
|
|
|
relax_end.setConstant(emptyIdxLU);
|
2012-05-25 18:17:57 +02:00
|
|
|
descendants.setZero();
|
2015-02-16 13:19:05 +01:00
|
|
|
for (Index j = 0; j < n; j++) {
|
2012-05-25 18:17:57 +02:00
|
|
|
parent = et(j);
|
|
|
|
|
if (parent != n) // not the dummy root
|
|
|
|
|
descendants(parent) += descendants(j) + 1;
|
|
|
|
|
}
|
|
|
|
|
// Identify the relaxed supernodes by postorder traversal of the etree
|
2013-01-29 16:21:24 +01:00
|
|
|
Index snode_start; // beginning of a snode
|
2015-02-16 13:19:05 +01:00
|
|
|
for (Index j = 0; j < n;) {
|
2012-05-25 18:17:57 +02:00
|
|
|
parent = et(j);
|
|
|
|
|
snode_start = j;
|
|
|
|
|
while (parent != n && descendants(parent) < relax_columns) {
|
|
|
|
|
j = parent;
|
|
|
|
|
parent = et(j);
|
|
|
|
|
}
|
|
|
|
|
// Found a supernode in postordered etree, j is the last column
|
2015-02-16 13:19:05 +01:00
|
|
|
relax_end(snode_start) = StorageIndex(j); // Record last column
|
2012-05-25 18:17:57 +02:00
|
|
|
j++;
|
|
|
|
|
// Search for a new leaf
|
|
|
|
|
while (descendants(j) != 0 && j < n) j++;
|
|
|
|
|
} // End postorder traversal of the etree
|
|
|
|
|
}
|
2013-01-12 11:55:16 +01:00
|
|
|
|
2013-01-25 20:38:26 +01:00
|
|
|
} // end namespace internal
|
2013-01-12 11:55:16 +01:00
|
|
|
|
2013-01-25 20:38:26 +01:00
|
|
|
} // end namespace Eigen
|
2012-05-25 18:17:57 +02:00
|
|
|
#endif
|