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

76 lines
1.9 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-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-08-03 16:36:00 +02:00
/**
* \brief Count Nonzero elements in the factors
*/
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
{
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++)
{
2012-08-03 16:36:00 +02:00
fsupc = glu.xsup(i);
jlen = glu.xlsub(fsupc+1) - glu.xlsub(fsupc);
2012-05-31 17:10:29 +02:00
2012-08-03 16:36:00 +02:00
for (j = fsupc; j < glu.xsup(i+1); j++)
2012-05-31 17:10:29 +02:00
{
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;
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++)
{
2012-08-03 16:36:00 +02:00
fsupc = glu.xsup(i);
jstart = glu.xlsub(fsupc);
glu.xlsub(fsupc) = nextl;
for (j = jstart; j < glu.xlsub(fsupc + 1); j++)
2012-05-31 17:10:29 +02:00
{
2012-08-03 16:36:00 +02:00
glu.lsub(nextl) = perm_r(glu.lsub(j)); // Now indexed into P*A
2012-06-14 18:45:04 +02:00
nextl++;
2012-05-31 17:10:29 +02:00
}
2012-08-03 16:36:00 +02:00
for (k = fsupc+1; k < glu.xsup(i+1); k++)
glu.xlsub(k) = nextl; // other columns in supernode i
2012-05-31 17:10:29 +02:00
}
2012-08-03 16:36:00 +02:00
glu.xlsub(n) = nextl;
2012-05-31 17:10:29 +02:00
}
2012-06-01 18:44:51 +02:00
2012-05-31 17:10:29 +02:00
#endif