Files
eigen/Eigen/src/SparseLU/SparseLU_snode_dfs.h

101 lines
3.8 KiB
C
Raw Normal View History

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
/*
2012-08-01 11:38:32 +02:00
* NOTE: This file is the modified version of [s,d,c,z]snode_dfs.c file in SuperLU
2012-05-25 18:17:57 +02:00
* -- SuperLU routine (version 2.0) --
* Univ. of California Berkeley, Xerox Palo Alto Research Center,
* and Lawrence Berkeley National Lab.
* November 15, 1997
*
* 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-14 18:45:04 +02:00
#ifndef SPARSELU_SNODE_DFS_H
2012-06-11 18:52:26 +02:00
#define SPARSELU_SNODE_DFS_H
2012-05-25 18:17:57 +02:00
/**
* \brief Determine the union of the row structures of those columns within the relaxed snode.
* NOTE: The relaxed snodes are leaves of the supernodal etree, therefore,
* the portion outside the rectangular supernode must be zero.
*
* \param jcol start of the supernode
* \param kcol end of the supernode
* \param asub Row indices
* \param colptr Pointer to the beginning of each column
* \param xprune (out) The pruned tree ??
* \param marker (in/out) working vector
2012-06-07 19:06:22 +02:00
* \return 0 on success, > 0 size of the memory when memory allocation failed
2012-05-25 18:17:57 +02:00
*/
2012-07-27 16:38:20 +02:00
template <typename MatrixType, typename IndexVector, typename ScalarVector>
int LU_snode_dfs(const int jcol, const int kcol,const MatrixType& mat, IndexVector& xprune, IndexVector& marker, LU_GlobalLU_t<IndexVector, ScalarVector>& glu)
2012-05-25 18:17:57 +02:00
{
2012-06-14 18:45:04 +02:00
typedef typename IndexVector::Scalar Index;
2012-06-11 18:52:26 +02:00
IndexVector& xsup = glu.xsup;
IndexVector& supno = glu.supno; // Supernode number corresponding to this column
IndexVector& lsub = glu.lsub;
IndexVector& xlsub = glu.xlsub;
Index& nzlmax = glu.nzlmax;
2012-06-07 19:06:22 +02:00
int mem;
Index nsuper = ++supno(jcol); // Next available supernode number
2012-07-06 20:18:16 +02:00
int nextl = xlsub(jcol); //Index of the starting location of the jcol-th column in lsub
2012-05-25 18:17:57 +02:00
int krow,kmark;
2012-07-27 16:38:20 +02:00
for (int i = jcol; i <=kcol; i++)
2012-05-25 18:17:57 +02:00
{
// For each nonzero in A(*,i)
2012-07-27 16:38:20 +02:00
for (typename MatrixType::InnerIterator it(mat, i); it; ++it)
2012-05-25 18:17:57 +02:00
{
2012-07-27 16:38:20 +02:00
krow = it.row();
2012-05-25 18:17:57 +02:00
kmark = marker(krow);
if ( kmark != kcol )
{
// First time to visit krow
marker(krow) = kcol;
lsub(nextl++) = krow;
if( nextl >= nzlmax )
{
2012-06-13 18:26:05 +02:00
mem = LUMemXpand<IndexVector>(lsub, nzlmax, nextl, LSUB, glu.num_expansions);
2012-07-06 20:18:16 +02:00
if (mem) return mem; // Memory expansion failed... Return the memory allocated so far
2012-05-25 18:17:57 +02:00
}
}
}
2012-06-07 19:06:22 +02:00
supno(i) = nsuper;
2012-05-25 18:17:57 +02:00
}
// If supernode > 1, then make a copy of the subscripts for pruning
if (jcol < kcol)
{
2012-06-07 19:06:22 +02:00
Index new_next = nextl + (nextl - xlsub(jcol));
2012-05-25 18:17:57 +02:00
while (new_next > nzlmax)
{
2012-06-13 18:26:05 +02:00
mem = LUMemXpand<IndexVector>(lsub, nzlmax, nextl, LSUB, glu.num_expansions);
2012-07-06 20:18:16 +02:00
if (mem) return mem; // Memory expansion failed... Return the memory allocated so far
2012-05-25 18:17:57 +02:00
}
2012-06-07 19:06:22 +02:00
Index ifrom, ito = nextl;
2012-05-25 18:17:57 +02:00
for (ifrom = xlsub(jcol); ifrom < nextl;)
lsub(ito++) = lsub(ifrom++);
2012-07-27 16:38:20 +02:00
for (int i = jcol+1; i <=kcol; i++) xlsub(i) = nextl;
2012-05-25 18:17:57 +02:00
nextl = ito;
}
xsup(nsuper+1) = kcol + 1; // Start of next available supernode
supno(kcol+1) = nsuper;
xprune(kcol) = nextl;
xlsub(kcol+1) = nextl;
return 0;
}
#endif