SparseLU_heap_relax_snode.h
Go to the documentation of this file.
00001 // This file is part of Eigen, a lightweight C++ template library
00002 // for linear algebra.
00003 //
00004 // Copyright (C) 2012 Désiré Nuentsa-Wakam <desire.nuentsa_wakam@inria.fr>
00005 //
00006 // This Source Code Form is subject to the terms of the Mozilla
00007 // Public License v. 2.0. If a copy of the MPL was not distributed
00008 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
00009 
00010 /* This file is a modified version of heap_relax_snode.c file in SuperLU
00011  * -- SuperLU routine (version 3.0) --
00012  * Univ. of California Berkeley, Xerox Palo Alto Research Center,
00013  * and Lawrence Berkeley National Lab.
00014  * October 15, 2003
00015  *
00016  * Copyright (c) 1994 by Xerox Corporation.  All rights reserved.
00017  *
00018  * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY
00019  * EXPRESSED OR IMPLIED.  ANY USE IS AT YOUR OWN RISK.
00020  *
00021  * Permission is hereby granted to use or copy this program for any
00022  * purpose, provided the above notices are retained on all copies.
00023  * Permission to modify the code and to distribute modified code is
00024  * granted, provided the above notices are retained, and a notice that
00025  * the code was modified is included with the above copyright notice.
00026  */
00027 
00028 #ifndef SPARSELU_HEAP_RELAX_SNODE_H
00029 #define SPARSELU_HEAP_RELAX_SNODE_H
00030 
00031 namespace Eigen {
00032 namespace internal {
00033 
00045 template <typename Scalar, typename Index>
00046 void SparseLUImpl<Scalar,Index>::heap_relax_snode (const Index n, IndexVector& et, const Index relax_columns, IndexVector& descendants, IndexVector& relax_end)
00047 {
00048   
00049   // The etree may not be postordered, but its heap ordered  
00050   IndexVector post;
00051   internal::treePostorder(n, et, post); // Post order etree
00052   IndexVector inv_post(n+1); 
00053   Index i;
00054   for (i = 0; i < n+1; ++i) inv_post(post(i)) = i; // inv_post = post.inverse()???
00055   
00056   // Renumber etree in postorder 
00057   IndexVector iwork(n);
00058   IndexVector et_save(n+1);
00059   for (i = 0; i < n; ++i)
00060   {
00061     iwork(post(i)) = post(et(i));
00062   }
00063   et_save = et; // Save the original etree
00064   et = iwork; 
00065   
00066   // compute the number of descendants of each node in the etree
00067   relax_end.setConstant(emptyIdxLU);
00068   Index j, parent; 
00069   descendants.setZero();
00070   for (j = 0; j < n; j++) 
00071   {
00072     parent = et(j);
00073     if (parent != n) // not the dummy root
00074       descendants(parent) += descendants(j) + 1;
00075   }
00076   // Identify the relaxed supernodes by postorder traversal of the etree
00077   Index snode_start; // beginning of a snode 
00078   Index k;
00079   Index nsuper_et_post = 0; // Number of relaxed snodes in postordered etree 
00080   Index nsuper_et = 0; // Number of relaxed snodes in the original etree 
00081   Index l; 
00082   for (j = 0; j < n; )
00083   {
00084     parent = et(j);
00085     snode_start = j; 
00086     while ( parent != n && descendants(parent) < relax_columns ) 
00087     {
00088       j = parent; 
00089       parent = et(j);
00090     }
00091     // Found a supernode in postordered etree, j is the last column 
00092     ++nsuper_et_post;
00093     k = n;
00094     for (i = snode_start; i <= j; ++i)
00095       k = (std::min)(k, inv_post(i));
00096     l = inv_post(j);
00097     if ( (l - k) == (j - snode_start) )  // Same number of columns in the snode
00098     {
00099       // This is also a supernode in the original etree
00100       relax_end(k) = l; // Record last column 
00101       ++nsuper_et; 
00102     }
00103     else 
00104     {
00105       for (i = snode_start; i <= j; ++i) 
00106       {
00107         l = inv_post(i);
00108         if (descendants(i) == 0) 
00109         {
00110           relax_end(l) = l;
00111           ++nsuper_et;
00112         }
00113       }
00114     }
00115     j++;
00116     // Search for a new leaf
00117     while (descendants(j) != 0 && j < n) j++;
00118   } // End postorder traversal of the etree
00119   
00120   // Recover the original etree
00121   et = et_save; 
00122 }
00123 
00124 } // end namespace internal
00125 
00126 } // end namespace Eigen
00127 #endif // SPARSELU_HEAP_RELAX_SNODE_H


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Sat Jun 8 2019 19:39:22