Build process...

This commit is contained in:
Desire NUENTSA
2012-06-13 18:26:05 +02:00
parent c0ad109499
commit f8a0745cb0
22 changed files with 559 additions and 548 deletions

View File

@@ -26,9 +26,7 @@
#ifndef EIGEN_ORDERING_H
#define EIGEN_ORDERING_H
#include <Eigen_Colamd.h>
#include <Amd.h>
#include "Amd.h"
namespace Eigen {
template<class Derived>
class OrderingBase
@@ -68,8 +66,23 @@ class OrderingBase
if (m_isInitialized = true) return m_P;
else abort(); // FIXME Should find a smoother way to exit with error code
}
/**
* Get the symmetric pattern A^T+A from the input matrix A.
* FIXME: The values should not be considered here
*/
template<typename MatrixType>
void at_plus_a(const MatrixType& mat);
void at_plus_a(const MatrixType& mat)
{
MatrixType C;
C = mat.transpose(); // NOTE: Could be costly
for (int i = 0; i < C.rows(); i++)
{
for (typename MatrixType::InnerIterator it(C, i); it; ++it)
it.valueRef() = 0.0;
}
m_mat = C + mat;
}
/** keeps off-diagonal entries; drops diagonal entries */
struct keep_diag {
@@ -87,99 +100,30 @@ class OrderingBase
PermutationType m_P; // The computed permutation
mutable bool m_isInitialized;
SparseMatrix<Scalar,ColMajor,Index> m_mat; // Stores the (symmetrized) matrix to permute
}
/**
* Get the symmetric pattern A^T+A from the input matrix A.
* NOTE: The values should not be considered here
*/
template<typename MatrixType>
void OrderingBase::at_plus_a(const MatrixType& mat)
{
MatrixType C;
C = mat.transpose(); // NOTE: Could be costly
for (int i = 0; i < C.rows(); i++)
{
for (typename MatrixType::InnerIterator it(C, i); it; ++it)
it.valueRef() = 0.0;
}
m_mat = C + mat;
/**
* Get the column approximate minimum degree ordering
* The matrix should be in column-major format
*/
template<typename Scalar, typename Index>
class COLAMDOrdering: public OrderingBase< ColamdOrdering<Scalar, Index> >
{
public:
typedef OrderingBase< ColamdOrdering<Scalar, Index> > Base;
typedef SparseMatrix<Scalar,ColMajor,Index> MatrixType;
public:
COLAMDOrdering():Base() {}
COLAMDOrdering(const MatrixType& matrix):Base()
{
compute(matrix);
}
COLAMDOrdering(const MatrixType& mat, PermutationType& perm_c):Base()
{
compute(matrix);
perm_c = this.get_perm();
}
void compute(const MatrixType& mat)
{
// Test if the matrix is column major...
int m = mat.rows();
int n = mat.cols();
int nnz = mat.nonZeros();
// Get the recommended value of Alen to be used by colamd
int Alen = colamd_recommended(nnz, m, n);
// Set the default parameters
double knobs[COLAMD_KNOBS];
colamd_set_defaults(knobs);
int info;
VectorXi p(n), A(nnz);
for(int i=0; i < n; i++) p(i) = mat.outerIndexPtr()(i);
for(int i=0; i < nnz; i++) A(i) = mat.innerIndexPtr()(i);
// Call Colamd routine to compute the ordering
info = colamd(m, n, Alen, A,p , knobs, stats)
eigen_assert( (info != FALSE)&& "COLAMD failed " );
m_P.resize(n);
for (int i = 0; i < n; i++) m_P(p(i)) = i;
m_isInitialized = true;
}
protected:
using Base::m_isInitialized;
using Base m_P;
}
};
/**
* Get the approximate minimum degree ordering
* If the matrix is not structurally symmetric, an ordering of A^T+A is computed
* \tparam Scalar The type of the scalar of the matrix for which the ordering is applied
* \tparam Index The type of indices of the matrix
* \tparam _UpLo If the matrix is symmetric, indicates which part to use
*/
template <typename Scalar, typename Index, typename _UpLo>
class AMDordering : public OrderingBase<AMDOrdering<Scalar, Index> >
template <typename Scalar, typename Index>
class AMDOrdering : public OrderingBase<AMDOrdering<Scalar, Index> >
{
public:
enum { UpLo = _UpLo };
typedef OrderingBase< AMDOrdering<Scalar, Index> > Base;
typedef SparseMatrix<Scalar, ColMajor,Index> MatrixType;
typedef PermutationMatrix<Dynamic, Dynamic, Index> PermutationType;
public:
AMDOrdering():Base(){}
AMDOrdering(const MatrixType& mat):Base()
{
compute(matrix);
compute(mat);
}
AMDOrdering(const MatrixType& mat, PermutationType& perm_c):Base()
{
compute(matrix);
compute(mat);
perm_c = this.get_perm();
}
/** Compute the permutation vector from a column-major sparse matrix */
@@ -200,15 +144,75 @@ class AMDordering : public OrderingBase<AMDOrdering<Scalar, Index> >
m_mat = mat;
// Call the AMD routine
m_mat.prune(keep_diag());
m_mat.prune(keep_diag()); //Remove the diagonal elements
internal::minimum_degree_ordering(m_mat, m_P);
if (m_P.size()>0) m_isInitialized = true;
}
protected:
struct keep_diag{
inline bool operator() (const Index& row, const Index& col, const Scalar&) const
{
return row!=col;
}
};
using Base::m_isInitialized;
using Base::m_P;
using Base::m_mat;
}
};
/**
* Get the column approximate minimum degree ordering
* The matrix should be in column-major format
*/
// template<typename Scalar, typename Index>
// class COLAMDOrdering: public OrderingBase< ColamdOrdering<Scalar, Index> >
// {
// public:
// typedef OrderingBase< ColamdOrdering<Scalar, Index> > Base;
// typedef SparseMatrix<Scalar,ColMajor,Index> MatrixType;
//
// public:
// COLAMDOrdering():Base() {}
//
// COLAMDOrdering(const MatrixType& matrix):Base()
// {
// compute(matrix);
// }
// COLAMDOrdering(const MatrixType& mat, PermutationType& perm_c):Base()
// {
// compute(matrix);
// perm_c = this.get_perm();
// }
// void compute(const MatrixType& mat)
// {
// // Test if the matrix is column major...
//
// int m = mat.rows();
// int n = mat.cols();
// int nnz = mat.nonZeros();
// // Get the recommended value of Alen to be used by colamd
// int Alen = colamd_recommended(nnz, m, n);
// // Set the default parameters
// double knobs[COLAMD_KNOBS];
// colamd_set_defaults(knobs);
//
// int info;
// VectorXi p(n), A(nnz);
// for(int i=0; i < n; i++) p(i) = mat.outerIndexPtr()(i);
// for(int i=0; i < nnz; i++) A(i) = mat.innerIndexPtr()(i);
// // Call Colamd routine to compute the ordering
// info = colamd(m, n, Alen, A,p , knobs, stats)
// eigen_assert( (info != FALSE)&& "COLAMD failed " );
//
// m_P.resize(n);
// for (int i = 0; i < n; i++) m_P(p(i)) = i;
// m_isInitialized = true;
// }
// protected:
// using Base::m_isInitialized;
// using Base m_P;
// };
} // end namespace Eigen
#endif