mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-06-20 11:56:17 +08:00
Improve the permutation
This commit is contained in:
parent
c0fa5811ec
commit
ce30d50e3e
@ -477,6 +477,18 @@ class SparseMatrix
|
|||||||
m_data.squeeze();
|
m_data.squeeze();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Turns the matrix into the uncompressed mode */
|
||||||
|
void Uncompress()
|
||||||
|
{
|
||||||
|
if(m_innerNonZeros != 0)
|
||||||
|
return;
|
||||||
|
m_innerNonZeros = new Index[m_outerSize];
|
||||||
|
for (int i = 0; i < m_outerSize; i++)
|
||||||
|
{
|
||||||
|
m_innerNonZeros[i] = m_outerIndex[i+1] - m_outerIndex[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** Suppresses all nonzeros which are \b much \b smaller \b than \a reference under the tolerence \a epsilon */
|
/** Suppresses all nonzeros which are \b much \b smaller \b than \a reference under the tolerence \a epsilon */
|
||||||
void prune(Scalar reference, RealScalar epsilon = NumTraits<RealScalar>::dummy_precision())
|
void prune(Scalar reference, RealScalar epsilon = NumTraits<RealScalar>::dummy_precision())
|
||||||
{
|
{
|
||||||
|
@ -346,8 +346,17 @@ void SparseLU<MatrixType, OrderingType>::analyzePattern(const MatrixType& mat)
|
|||||||
|
|
||||||
|
|
||||||
// Apply the permutation to the column of the input matrix
|
// Apply the permutation to the column of the input matrix
|
||||||
m_mat = mat * m_perm_c.inverse(); //FIXME It should be less expensive here to permute only the structural pattern of the matrix
|
// m_mat = mat * m_perm_c.inverse(); //FIXME It should be less expensive here to permute only the structural pattern of the matrix
|
||||||
|
|
||||||
|
//First copy the whole input matrix.
|
||||||
|
m_mat = mat;
|
||||||
|
m_mat.Uncompress(); //NOTE: The effect of this command is only to create the InnerNonzeros pointers. FIXME : This vector is filled but not subsequently used.
|
||||||
|
//Then, permute only the column pointers
|
||||||
|
for (int i = 0; i < mat.cols(); i++)
|
||||||
|
{
|
||||||
|
m_mat.outerIndexPtr()[m_perm_c.indices()(i)] = mat.outerIndexPtr()[i];
|
||||||
|
m_mat.innerNonZeroPtr()[m_perm_c.indices()(i)] = mat.outerIndexPtr()[i+1] - mat.outerIndexPtr()[i];
|
||||||
|
}
|
||||||
|
|
||||||
// Compute the column elimination tree of the permuted matrix
|
// Compute the column elimination tree of the permuted matrix
|
||||||
if (m_etree.size() == 0) m_etree.resize(m_mat.cols());
|
if (m_etree.size() == 0) m_etree.resize(m_mat.cols());
|
||||||
@ -424,8 +433,15 @@ void SparseLU<MatrixType, OrderingType>::factorize(const MatrixType& matrix)
|
|||||||
|
|
||||||
|
|
||||||
// Apply the column permutation computed in analyzepattern()
|
// Apply the column permutation computed in analyzepattern()
|
||||||
m_mat = matrix * m_perm_c.inverse();
|
// m_mat = matrix * m_perm_c.inverse();
|
||||||
m_mat.makeCompressed();
|
m_mat = matrix;
|
||||||
|
m_mat.Uncompress(); //NOTE: The effect of this command is only to create the InnerNonzeros pointers.
|
||||||
|
//Then, permute only the column pointers
|
||||||
|
for (int i = 0; i < matrix.cols(); i++)
|
||||||
|
{
|
||||||
|
m_mat.outerIndexPtr()[m_perm_c.indices()(i)] = matrix.outerIndexPtr()[i];
|
||||||
|
m_mat.innerNonZeroPtr()[m_perm_c.indices()(i)] = matrix.outerIndexPtr()[i+1] - matrix.outerIndexPtr()[i];
|
||||||
|
}
|
||||||
|
|
||||||
int m = m_mat.rows();
|
int m = m_mat.rows();
|
||||||
int n = m_mat.cols();
|
int n = m_mat.cols();
|
||||||
@ -504,7 +520,7 @@ void SparseLU<MatrixType, OrderingType>::factorize(const MatrixType& matrix)
|
|||||||
|
|
||||||
// Factorize the relaxed supernode(jcol:kcol)
|
// Factorize the relaxed supernode(jcol:kcol)
|
||||||
// First, determine the union of the row structure of the snode
|
// First, determine the union of the row structure of the snode
|
||||||
info = LU_snode_dfs(jcol, kcol, m_mat.innerIndexPtr(), m_mat.outerIndexPtr(), xprune, marker, m_glu);
|
info = LU_snode_dfs(jcol, kcol, m_mat, xprune, marker, m_glu);
|
||||||
if ( info )
|
if ( info )
|
||||||
{
|
{
|
||||||
std::cerr << "MEMORY ALLOCATION FAILED IN SNODE_DFS() \n";
|
std::cerr << "MEMORY ALLOCATION FAILED IN SNODE_DFS() \n";
|
||||||
|
@ -57,8 +57,8 @@
|
|||||||
* \param marker (in/out) working vector
|
* \param marker (in/out) working vector
|
||||||
* \return 0 on success, > 0 size of the memory when memory allocation failed
|
* \return 0 on success, > 0 size of the memory when memory allocation failed
|
||||||
*/
|
*/
|
||||||
template <typename IndexVector, typename ScalarVector>
|
template <typename MatrixType, typename IndexVector, typename ScalarVector>
|
||||||
int LU_snode_dfs(const int jcol, const int kcol, const typename IndexVector::Scalar* asub, const typename IndexVector::Scalar* colptr, IndexVector& xprune, IndexVector& marker, LU_GlobalLU_t<IndexVector, ScalarVector>& glu)
|
int LU_snode_dfs(const int jcol, const int kcol,const MatrixType& mat, IndexVector& xprune, IndexVector& marker, LU_GlobalLU_t<IndexVector, ScalarVector>& glu)
|
||||||
{
|
{
|
||||||
typedef typename IndexVector::Scalar Index;
|
typedef typename IndexVector::Scalar Index;
|
||||||
IndexVector& xsup = glu.xsup;
|
IndexVector& xsup = glu.xsup;
|
||||||
@ -69,14 +69,13 @@
|
|||||||
int mem;
|
int mem;
|
||||||
Index nsuper = ++supno(jcol); // Next available supernode number
|
Index nsuper = ++supno(jcol); // Next available supernode number
|
||||||
int nextl = xlsub(jcol); //Index of the starting location of the jcol-th column in lsub
|
int nextl = xlsub(jcol); //Index of the starting location of the jcol-th column in lsub
|
||||||
int i,k;
|
|
||||||
int krow,kmark;
|
int krow,kmark;
|
||||||
for (i = jcol; i <=kcol; i++)
|
for (int i = jcol; i <=kcol; i++)
|
||||||
{
|
{
|
||||||
// For each nonzero in A(*,i)
|
// For each nonzero in A(*,i)
|
||||||
for (k = colptr[i]; k < colptr[i+1]; k++)
|
for (typename MatrixType::InnerIterator it(mat, i); it; ++it)
|
||||||
{
|
{
|
||||||
krow = asub[k];
|
krow = it.row();
|
||||||
kmark = marker(krow);
|
kmark = marker(krow);
|
||||||
if ( kmark != kcol )
|
if ( kmark != kcol )
|
||||||
{
|
{
|
||||||
@ -105,7 +104,7 @@
|
|||||||
Index ifrom, ito = nextl;
|
Index ifrom, ito = nextl;
|
||||||
for (ifrom = xlsub(jcol); ifrom < nextl;)
|
for (ifrom = xlsub(jcol); ifrom < nextl;)
|
||||||
lsub(ito++) = lsub(ifrom++);
|
lsub(ito++) = lsub(ifrom++);
|
||||||
for (i = jcol+1; i <=kcol; i++) xlsub(i) = nextl;
|
for (int i = jcol+1; i <=kcol; i++) xlsub(i) = nextl;
|
||||||
nextl = ito;
|
nextl = ito;
|
||||||
}
|
}
|
||||||
xsup(nsuper+1) = kcol + 1; // Start of next available supernode
|
xsup(nsuper+1) = kcol + 1; // Start of next available supernode
|
||||||
|
Loading…
x
Reference in New Issue
Block a user