31 template <
typename MatrixType>
32 void get_symmetrized_graph(
const MatrixType& A) {
34 eigen_assert((A.rows() == A.cols()) &&
"ONLY FOR SQUARED MATRICES");
36 MatrixType At = A.transpose();
39 IndexVector visited(m);
41 for (StorageIndex j = 0; j < m; j++) {
45 for (
typename MatrixType::InnerIterator it(A, j); it; ++it) {
46 Index idx = it.index();
47 if (visited(idx) != j) {
53 for (
typename MatrixType::InnerIterator it(At, j); it; ++it) {
54 Index idx = it.index();
55 if (visited(idx) != j) {
62 m_indexPtr.resize(m + 1);
63 m_innerIndices.resize(TotNz);
67 StorageIndex CurNz = 0;
68 for (StorageIndex j = 0; j < m; j++) {
69 m_indexPtr(j) = CurNz;
73 for (
typename MatrixType::InnerIterator it(A, j); it; ++it) {
74 StorageIndex idx = it.index();
75 if (visited(idx) != j) {
77 m_innerIndices(CurNz) = idx;
82 for (
typename MatrixType::InnerIterator it(At, j); it; ++it) {
83 StorageIndex idx = it.index();
84 if (visited(idx) != j) {
86 m_innerIndices(CurNz) = idx;
91 m_indexPtr(m) = CurNz;
94 template <
typename MatrixType>
95 void operator()(
const MatrixType& A, PermutationType& matperm) {
96 StorageIndex m = internal::convert_index<StorageIndex>(
98 IndexVector perm(m), iperm(m);
100 get_symmetrized_graph(A);
105 METIS_NodeND(&m, m_indexPtr.data(), m_innerIndices.data(),
nullptr,
nullptr, perm.data(), iperm.
data());
107 if (output_error != METIS_OK) {
109 std::cerr <<
"ERROR WHILE CALLING THE METIS PACKAGE \n";
118 for (
int j = 0; j < m; j++) matperm.
indices()(iperm(j)) = j;
122 IndexVector m_indexPtr;
123 IndexVector m_innerIndices;