Eigen::MetisOrdering< StorageIndex > Class Template Reference

Public Types

typedef Matrix< StorageIndex, Dynamic, 1 > IndexVector
 
typedef PermutationMatrix< Dynamic, Dynamic, StorageIndex > PermutationType
 

Public Member Functions

template<typename MatrixType >
void get_symmetrized_graph (const MatrixType &A)
 
template<typename MatrixType >
void operator() (const MatrixType &A, PermutationType &matperm)
 

Protected Attributes

IndexVector m_indexPtr
 
IndexVector m_innerIndices
 

Detailed Description

template<typename StorageIndex>
class Eigen::MetisOrdering< StorageIndex >

Get the fill-reducing ordering from the METIS package

If A is the original matrix and Ap is the permuted matrix, the fill-reducing permutation is defined as follows : Row (column) i of A is the matperm(i) row (column) of Ap. WARNING: As computed by METIS, this corresponds to the vector iperm (instead of perm)

Definition at line 24 of file MetisSupport.h.

Member Typedef Documentation

◆ IndexVector

template<typename StorageIndex >
typedef Matrix<StorageIndex,Dynamic,1> Eigen::MetisOrdering< StorageIndex >::IndexVector

Definition at line 28 of file MetisSupport.h.

◆ PermutationType

template<typename StorageIndex >
typedef PermutationMatrix<Dynamic,Dynamic,StorageIndex> Eigen::MetisOrdering< StorageIndex >::PermutationType

Definition at line 27 of file MetisSupport.h.

Member Function Documentation

◆ get_symmetrized_graph()

template<typename StorageIndex >
template<typename MatrixType >
void Eigen::MetisOrdering< StorageIndex >::get_symmetrized_graph ( const MatrixType A)
inline

Definition at line 31 of file MetisSupport.h.

32  {
33  Index m = A.cols();
34  eigen_assert((A.rows() == A.cols()) && "ONLY FOR SQUARED MATRICES");
35  // Get the transpose of the input matrix
36  MatrixType At = A.transpose();
37  // Get the number of nonzeros elements in each row/col of At+A
38  Index TotNz = 0;
39  IndexVector visited(m);
40  visited.setConstant(-1);
41  for (StorageIndex j = 0; j < m; j++)
42  {
43  // Compute the union structure of of A(j,:) and At(j,:)
44  visited(j) = j; // Do not include the diagonal element
45  // Get the nonzeros in row/column j of A
46  for (typename MatrixType::InnerIterator it(A, j); it; ++it)
47  {
48  Index idx = it.index(); // Get the row index (for column major) or column index (for row major)
49  if (visited(idx) != j )
50  {
51  visited(idx) = j;
52  ++TotNz;
53  }
54  }
55  //Get the nonzeros in row/column j of At
56  for (typename MatrixType::InnerIterator it(At, j); it; ++it)
57  {
58  Index idx = it.index();
59  if(visited(idx) != j)
60  {
61  visited(idx) = j;
62  ++TotNz;
63  }
64  }
65  }
66  // Reserve place for A + At
67  m_indexPtr.resize(m+1);
68  m_innerIndices.resize(TotNz);
69 
70  // Now compute the real adjacency list of each column/row
71  visited.setConstant(-1);
72  StorageIndex CurNz = 0;
73  for (StorageIndex j = 0; j < m; j++)
74  {
75  m_indexPtr(j) = CurNz;
76 
77  visited(j) = j; // Do not include the diagonal element
78  // Add the pattern of row/column j of A to A+At
79  for (typename MatrixType::InnerIterator it(A,j); it; ++it)
80  {
81  StorageIndex idx = it.index(); // Get the row index (for column major) or column index (for row major)
82  if (visited(idx) != j )
83  {
84  visited(idx) = j;
85  m_innerIndices(CurNz) = idx;
86  CurNz++;
87  }
88  }
89  //Add the pattern of row/column j of At to A+At
90  for (typename MatrixType::InnerIterator it(At, j); it; ++it)
91  {
92  StorageIndex idx = it.index();
93  if(visited(idx) != j)
94  {
95  visited(idx) = j;
96  m_innerIndices(CurNz) = idx;
97  ++CurNz;
98  }
99  }
100  }
101  m_indexPtr(m) = CurNz;
102  }
Matrix3f m
MatrixXcf A
#define eigen_assert(x)
Definition: Macros.h:902
Matrix< float, 1, Dynamic > MatrixType
IndexVector m_indexPtr
Definition: MetisSupport.h:134
IndexVector m_innerIndices
Definition: MetisSupport.h:135
Matrix< StorageIndex, Dynamic, 1 > IndexVector
Definition: MetisSupport.h:28
constexpr void resize(Index rows, Index cols)
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:82
std::ptrdiff_t j

◆ operator()()

template<typename StorageIndex >
template<typename MatrixType >
void Eigen::MetisOrdering< StorageIndex >::operator() ( const MatrixType A,
PermutationType matperm 
)
inline

Definition at line 105 of file MetisSupport.h.

106  {
107  StorageIndex m = internal::convert_index<StorageIndex>(A.cols()); // must be StorageIndex, because it is passed by address to METIS
108  IndexVector perm(m),iperm(m);
109  // First, symmetrize the matrix graph.
111  int output_error;
112 
113  // Call the fill-reducing routine from METIS
114  output_error = METIS_NodeND(&m, m_indexPtr.data(), m_innerIndices.data(), NULL, NULL, perm.data(), iperm.data());
115 
116  if(output_error != METIS_OK)
117  {
118  //FIXME The ordering interface should define a class of possible errors
119  std::cerr << "ERROR WHILE CALLING THE METIS PACKAGE \n";
120  return;
121  }
122 
123  // Get the fill-reducing permutation
124  //NOTE: If Ap is the permuted matrix then perm and iperm vectors are defined as follows
125  // Row (column) i of Ap is the perm(i) row(column) of A, and row (column) i of A is the iperm(i) row(column) of Ap
126 
127  matperm.resize(m);
128  for (int j = 0; j < m; j++)
129  matperm.indices()(iperm(j)) = j;
130 
131  }
void get_symmetrized_graph(const MatrixType &A)
Definition: MetisSupport.h:31
const Scalar * data() const

Member Data Documentation

◆ m_indexPtr

template<typename StorageIndex >
IndexVector Eigen::MetisOrdering< StorageIndex >::m_indexPtr
protected

Definition at line 134 of file MetisSupport.h.

◆ m_innerIndices

template<typename StorageIndex >
IndexVector Eigen::MetisOrdering< StorageIndex >::m_innerIndices
protected

Definition at line 135 of file MetisSupport.h.


The documentation for this class was generated from the following file: