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>
|
|
|
|
|
//
|
|
|
|
|
// Eigen is free software; you can redistribute it and/or
|
|
|
|
|
// modify it under the terms of the GNU Lesser General Public
|
|
|
|
|
// License as published by the Free Software Foundation; either
|
|
|
|
|
// version 3 of the License, or (at your option) any later version.
|
|
|
|
|
//
|
|
|
|
|
// Alternatively, you can redistribute it and/or
|
|
|
|
|
// modify it under the terms of the GNU General Public License as
|
|
|
|
|
// published by the Free Software Foundation; either version 2 of
|
|
|
|
|
// the License, or (at your option) any later version.
|
|
|
|
|
//
|
|
|
|
|
// Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
|
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
|
// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
|
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
//
|
|
|
|
|
// You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
// License and a copy of the GNU General Public License along with
|
|
|
|
|
// Eigen. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
2012-06-14 18:45:04 +02:00
|
|
|
#ifndef EIGEN_SPARSELU_UTILS_H
|
2012-05-25 18:17:57 +02:00
|
|
|
#define EIGEN_SPARSELU_UTILS_H
|
|
|
|
|
|
2012-05-31 17:10:29 +02:00
|
|
|
|
2012-06-14 18:45:04 +02:00
|
|
|
|
|
|
|
|
template <typename IndexVector, typename ScalarVector>
|
|
|
|
|
void LU_countnz(const int n, int& nnzL, int& nnzU, LU_GlobalLU_t<IndexVector, ScalarVector>& glu)
|
2012-05-31 17:10:29 +02:00
|
|
|
{
|
2012-06-14 18:45:04 +02:00
|
|
|
IndexVector& xsup = glu.xsup;
|
|
|
|
|
IndexVector& xlsub = glu.xlsub;
|
2012-05-31 17:10:29 +02:00
|
|
|
nnzL = 0;
|
2012-06-14 18:45:04 +02:00
|
|
|
nnzU = (glu.xusub)(n);
|
|
|
|
|
int nsuper = (glu.supno)(n);
|
|
|
|
|
int jlen;
|
|
|
|
|
int i, j, fsupc;
|
2012-05-31 17:10:29 +02:00
|
|
|
if (n <= 0 ) return;
|
|
|
|
|
// For each supernode
|
|
|
|
|
for (i = 0; i <= nsuper; i++)
|
|
|
|
|
{
|
|
|
|
|
fsupc = xsup(i);
|
|
|
|
|
jlen = xlsub(fsupc+1) - xlsub(fsupc);
|
|
|
|
|
|
|
|
|
|
for (j = fsupc; j < xsup(i+1); j++)
|
|
|
|
|
{
|
|
|
|
|
nnzL += jlen;
|
2012-06-14 18:45:04 +02:00
|
|
|
nnzU += j - fsupc + 1;
|
2012-05-31 17:10:29 +02:00
|
|
|
jlen--;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* \brief Fix up the data storage lsub for L-subscripts.
|
|
|
|
|
*
|
|
|
|
|
* It removes the subscripts sets for structural pruning,
|
|
|
|
|
* and applies permutation to the remaining subscripts
|
|
|
|
|
*
|
|
|
|
|
*/
|
2012-06-14 18:45:04 +02:00
|
|
|
template <typename IndexVector, typename ScalarVector>
|
|
|
|
|
void LU_fixupL(const int n, const IndexVector& perm_r, LU_GlobalLU_t<IndexVector, ScalarVector>& glu)
|
2012-05-31 17:10:29 +02:00
|
|
|
{
|
2012-06-14 18:45:04 +02:00
|
|
|
int fsupc, i, j, k, jstart;
|
|
|
|
|
IndexVector& xsup = glu.xsup;
|
|
|
|
|
IndexVector& lsub = glu.lsub;
|
|
|
|
|
IndexVector& xlsub = glu.xlsub;
|
2012-05-31 17:10:29 +02:00
|
|
|
|
|
|
|
|
int nextl = 0;
|
2012-06-14 18:45:04 +02:00
|
|
|
int nsuper = (glu.supno)(n);
|
2012-05-31 17:10:29 +02:00
|
|
|
|
|
|
|
|
// For each supernode
|
|
|
|
|
for (i = 0; i <= nsuper; i++)
|
|
|
|
|
{
|
|
|
|
|
fsupc = xsup(i);
|
|
|
|
|
jstart = xlsub(fsupc);
|
|
|
|
|
xlsub(fsupc) = nextl;
|
|
|
|
|
for (j = jstart; j < xlsub(fsupc + 1); j++)
|
|
|
|
|
{
|
|
|
|
|
lsub(nextl) = perm_r(lsub(j)); // Now indexed into P*A
|
2012-06-14 18:45:04 +02:00
|
|
|
nextl++;
|
2012-05-31 17:10:29 +02:00
|
|
|
}
|
|
|
|
|
for (k = fsupc+1; k < xsup(i+1); k++)
|
|
|
|
|
xlsub(k) = nextl; // other columns in supernode i
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
xlsub(n) = nextl;
|
|
|
|
|
}
|
2012-06-01 18:44:51 +02:00
|
|
|
|
2012-05-31 17:10:29 +02:00
|
|
|
#endif
|