Warning, file /include/eigen3/Eigen/src/MetisSupport/MetisSupport.h was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef METIS_SUPPORT_H
0010 #define METIS_SUPPORT_H
0011
0012 namespace Eigen {
0013
0014
0015
0016
0017
0018
0019
0020
0021 template <typename StorageIndex>
0022 class MetisOrdering
0023 {
0024 public:
0025 typedef PermutationMatrix<Dynamic,Dynamic,StorageIndex> PermutationType;
0026 typedef Matrix<StorageIndex,Dynamic,1> IndexVector;
0027
0028 template <typename MatrixType>
0029 void get_symmetrized_graph(const MatrixType& A)
0030 {
0031 Index m = A.cols();
0032 eigen_assert((A.rows() == A.cols()) && "ONLY FOR SQUARED MATRICES");
0033
0034 MatrixType At = A.transpose();
0035
0036 Index TotNz = 0;
0037 IndexVector visited(m);
0038 visited.setConstant(-1);
0039 for (StorageIndex j = 0; j < m; j++)
0040 {
0041
0042 visited(j) = j;
0043
0044 for (typename MatrixType::InnerIterator it(A, j); it; ++it)
0045 {
0046 Index idx = it.index();
0047 if (visited(idx) != j )
0048 {
0049 visited(idx) = j;
0050 ++TotNz;
0051 }
0052 }
0053
0054 for (typename MatrixType::InnerIterator it(At, j); it; ++it)
0055 {
0056 Index idx = it.index();
0057 if(visited(idx) != j)
0058 {
0059 visited(idx) = j;
0060 ++TotNz;
0061 }
0062 }
0063 }
0064
0065 m_indexPtr.resize(m+1);
0066 m_innerIndices.resize(TotNz);
0067
0068
0069 visited.setConstant(-1);
0070 StorageIndex CurNz = 0;
0071 for (StorageIndex j = 0; j < m; j++)
0072 {
0073 m_indexPtr(j) = CurNz;
0074
0075 visited(j) = j;
0076
0077 for (typename MatrixType::InnerIterator it(A,j); it; ++it)
0078 {
0079 StorageIndex idx = it.index();
0080 if (visited(idx) != j )
0081 {
0082 visited(idx) = j;
0083 m_innerIndices(CurNz) = idx;
0084 CurNz++;
0085 }
0086 }
0087
0088 for (typename MatrixType::InnerIterator it(At, j); it; ++it)
0089 {
0090 StorageIndex idx = it.index();
0091 if(visited(idx) != j)
0092 {
0093 visited(idx) = j;
0094 m_innerIndices(CurNz) = idx;
0095 ++CurNz;
0096 }
0097 }
0098 }
0099 m_indexPtr(m) = CurNz;
0100 }
0101
0102 template <typename MatrixType>
0103 void operator() (const MatrixType& A, PermutationType& matperm)
0104 {
0105 StorageIndex m = internal::convert_index<StorageIndex>(A.cols());
0106 IndexVector perm(m),iperm(m);
0107
0108 get_symmetrized_graph(A);
0109 int output_error;
0110
0111
0112 output_error = METIS_NodeND(&m, m_indexPtr.data(), m_innerIndices.data(), NULL, NULL, perm.data(), iperm.data());
0113
0114 if(output_error != METIS_OK)
0115 {
0116
0117 std::cerr << "ERROR WHILE CALLING THE METIS PACKAGE \n";
0118 return;
0119 }
0120
0121
0122
0123
0124
0125 matperm.resize(m);
0126 for (int j = 0; j < m; j++)
0127 matperm.indices()(iperm(j)) = j;
0128
0129 }
0130
0131 protected:
0132 IndexVector m_indexPtr;
0133 IndexVector m_innerIndices;
0134 };
0135
0136 }
0137 #endif