Sparse: fix long int as index type in simplicial cholesky and other decompositions

This commit is contained in:
Gael Guennebaud
2011-06-06 10:17:28 +02:00
parent 7a61a564ef
commit 421ece38e1
7 changed files with 68 additions and 63 deletions

View File

@@ -103,7 +103,7 @@ Index cs_tdfs(Index j, Index k, Index *head, const Index *next, Index *post, Ind
* The input matrix \a C must be a selfadjoint compressed column major SparseMatrix object. Both the upper and lower parts have to be stored, but the diagonal entries are optional.
* On exit the values of C are destroyed */
template<typename Scalar, typename Index>
void minimum_degree_ordering(SparseMatrix<Scalar,ColMajor,Index>& C, PermutationMatrix<Dynamic>& perm)
void minimum_degree_ordering(SparseMatrix<Scalar,ColMajor,Index>& C, PermutationMatrix<Dynamic,Dynamic,Index>& perm)
{
typedef SparseMatrix<Scalar,ColMajor,Index> CCS;
@@ -151,7 +151,7 @@ void minimum_degree_ordering(SparseMatrix<Scalar,ColMajor,Index>& C, Permutation
elen[i] = 0; // Ek of node i is empty
degree[i] = len[i]; // degree of node i
}
mark = cs_wclear (0, 0, w, n); /* clear w */
mark = cs_wclear<Index>(0, 0, w, n); /* clear w */
elen[n] = -2; /* n is a dead element */
Cp[n] = -1; /* n is a root of assembly tree */
w[n] = 0; /* n is a dead element */
@@ -266,7 +266,7 @@ void minimum_degree_ordering(SparseMatrix<Scalar,ColMajor,Index>& C, Permutation
elen[k] = -2; /* k is now an element */
/* --- Find set differences ----------------------------------------- */
mark = cs_wclear (mark, lemax, w, n); /* clear w if necessary */
mark = cs_wclear<Index>(mark, lemax, w, n); /* clear w if necessary */
for(pk = pk1; pk < pk2; pk++) /* scan 1: find |Le\Lk| */
{
i = Ci[pk];
@@ -349,7 +349,7 @@ void minimum_degree_ordering(SparseMatrix<Scalar,ColMajor,Index>& C, Permutation
} /* scan2 is done */
degree[k] = dk; /* finalize |Lk| */
lemax = std::max<Index>(lemax, dk);
mark = cs_wclear (mark+lemax, lemax, w, n); /* clear w */
mark = cs_wclear<Index>(mark+lemax, lemax, w, n); /* clear w */
/* --- Supernode detection ------------------------------------------ */
for(pk = pk1; pk < pk2; pk++)
@@ -435,7 +435,7 @@ void minimum_degree_ordering(SparseMatrix<Scalar,ColMajor,Index>& C, Permutation
}
for(k = 0, i = 0; i <= n; i++) /* postorder the assembly tree */
{
if(Cp[i] == -1) k = cs_tdfs (i, k, head, next, perm.indices().data(), w);
if(Cp[i] == -1) k = cs_tdfs<Index>(i, k, head, next, perm.indices().data(), w);
}
perm.indices().conservativeResize(n);

View File

@@ -193,12 +193,12 @@ class SimplicialCholesky
/** \returns the permutation P
* \sa permutationPinv() */
const PermutationMatrix<Dynamic>& permutationP() const
const PermutationMatrix<Dynamic,Dynamic,Index>& permutationP() const
{ return m_P; }
/** \returns the inverse P^-1 of the permutation P
* \sa permutationP() */
const PermutationMatrix<Dynamic>& permutationPinv() const
const PermutationMatrix<Dynamic,Dynamic,Index>& permutationPinv() const
{ return m_Pinv; }
#ifndef EIGEN_PARSED_BY_DOXYGEN
@@ -282,8 +282,8 @@ class SimplicialCholesky
VectorType m_diag; // the diagonal coefficients in case of a LDLt decomposition
VectorXi m_parent; // elimination tree
VectorXi m_nonZerosPerCol;
PermutationMatrix<Dynamic> m_P; // the permutation
PermutationMatrix<Dynamic> m_Pinv; // the inverse permutation
PermutationMatrix<Dynamic,Dynamic,Index> m_P; // the permutation
PermutationMatrix<Dynamic,Dynamic,Index> m_Pinv; // the inverse permutation
};
template<typename _MatrixType, int _UpLo>

View File

@@ -90,10 +90,9 @@ class SparseLDLT
};
public:
typedef SparseMatrix<Scalar> CholMatrixType;
typedef _MatrixType MatrixType;
typedef typename MatrixType::Index Index;
typedef SparseMatrix<Scalar,ColMajor,Index> CholMatrixType;
/** Creates a dummy LDLT factorization object with flags \a flags. */
SparseLDLT(int flags = 0)
@@ -187,8 +186,8 @@ class SparseLDLT
VectorXi m_parent; // elimination tree
VectorXi m_nonZerosPerCol;
// VectorXi m_w; // workspace
PermutationMatrix<Dynamic> m_P;
PermutationMatrix<Dynamic> m_Pinv;
PermutationMatrix<Dynamic,Dynamic,Index> m_P;
PermutationMatrix<Dynamic,Dynamic,Index> m_Pinv;
RealScalar m_precision;
int m_flags;
mutable int m_status;
@@ -257,7 +256,7 @@ void SparseLDLT<_MatrixType,Backend>::_symbolic(const _MatrixType& a)
if(P)
{
m_P.indices() = VectorXi::Map(P,size);
m_P.indices() = Map<const Matrix<Index,Dynamic,1> >(P,size);
m_Pinv = m_P.inverse();
Pinv = m_Pinv.indices().data();
}