Eigen  5.0.1-dev+60122df6
 
Loading...
Searching...
No Matches
Ordering.h
1
2// This file is part of Eigen, a lightweight C++ template library
3// for linear algebra.
4//
5// Copyright (C) 2012 Désiré Nuentsa-Wakam <desire.nuentsa_wakam@inria.fr>
6//
7// This Source Code Form is subject to the terms of the Mozilla
8// Public License v. 2.0. If a copy of the MPL was not distributed
9// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
10
11#ifndef EIGEN_ORDERING_H
12#define EIGEN_ORDERING_H
13
14// IWYU pragma: private
15#include "./InternalHeaderCheck.h"
16#include "Eigen_Colamd.h"
17
18namespace Eigen {
19namespace internal {
20
27template <typename MatrixType>
28void ordering_helper_at_plus_a(const MatrixType& A, MatrixType& symmat) {
29 MatrixType C;
30 C = A.transpose(); // NOTE: Could be costly
31 for (int i = 0; i < C.rows(); i++) {
32 for (typename MatrixType::InnerIterator it(C, i); it; ++it) it.valueRef() = typename MatrixType::Scalar(0);
33 }
34 symmat = C + A;
35}
36
37} // namespace internal
38
47template <typename StorageIndex>
49 public:
51
55 template <typename MatrixType>
56 void operator()(const MatrixType& mat, PermutationType& perm) {
57 // Compute the symmetric pattern
59 internal::ordering_helper_at_plus_a(mat, symm);
60
61 // Call the AMD routine
62 // m_mat.prune(keep_diag());
63 internal::minimum_degree_ordering(symm, perm);
64 }
65
67 template <typename SrcType, unsigned int SrcUpLo>
68 void operator()(const SparseSelfAdjointView<SrcType, SrcUpLo>& mat, PermutationType& perm) {
70 C = mat;
71
72 // Call the AMD routine
73 // m_mat.prune(keep_diag()); //Remove the diagonal elements
74 internal::minimum_degree_ordering(C, perm);
75 }
76};
77
86template <typename StorageIndex>
88 public:
90
92 template <typename MatrixType>
93 void operator()(const MatrixType& /*mat*/, PermutationType& perm) {
94 perm.resize(0);
95 }
96};
97
106template <typename StorageIndex>
108 public:
110 typedef Matrix<StorageIndex, Dynamic, 1> IndexVector;
111
115 template <typename MatrixType>
116 void operator()(const MatrixType& mat, PermutationType& perm) {
117 eigen_assert(mat.isCompressed() &&
118 "COLAMDOrdering requires a sparse matrix in compressed mode. Call .makeCompressed() before passing it "
119 "to COLAMDOrdering");
120
121 StorageIndex m = StorageIndex(mat.rows());
122 StorageIndex n = StorageIndex(mat.cols());
123 StorageIndex nnz = StorageIndex(mat.nonZeros());
124 // Get the recommended value of Alen to be used by colamd
125 StorageIndex Alen = internal::Colamd::recommended(nnz, m, n);
126 // Set the default parameters
127 double knobs[internal::Colamd::NKnobs];
128 StorageIndex stats[internal::Colamd::NStats];
129 internal::Colamd::set_defaults(knobs);
130
131 IndexVector p(n + 1), A(Alen);
132 for (StorageIndex i = 0; i <= n; i++) p(i) = mat.outerIndexPtr()[i];
133 for (StorageIndex i = 0; i < nnz; i++) A(i) = mat.innerIndexPtr()[i];
134 // Call Colamd routine to compute the ordering
135 StorageIndex info = internal::Colamd::compute_ordering(m, n, Alen, A.data(), p.data(), knobs, stats);
136 EIGEN_UNUSED_VARIABLE(info);
137 eigen_assert(info && "COLAMD failed ");
138
139 perm.resize(n);
140 for (StorageIndex i = 0; i < n; i++) perm.indices()(p(i)) = i;
141 }
142};
143
144} // end namespace Eigen
145
146#endif
Definition Ordering.h:48
void operator()(const SparseSelfAdjointView< SrcType, SrcUpLo > &mat, PermutationType &perm)
Definition Ordering.h:68
void operator()(const MatrixType &mat, PermutationType &perm)
Definition Ordering.h:56
Definition Ordering.h:107
void operator()(const MatrixType &mat, PermutationType &perm)
Definition Ordering.h:116
The matrix class, also used for vectors and row-vectors.
Definition Matrix.h:186
Definition Ordering.h:87
void operator()(const MatrixType &, PermutationType &perm)
Definition Ordering.h:93
void resize(Index newSize)
Definition PermutationMatrix.h:122
Permutation matrix.
Definition PermutationMatrix.h:283
const IndicesType & indices() const
Definition PermutationMatrix.h:337
constexpr const Scalar * data() const
Definition PlainObjectBase.h:247
A versatible sparse matrix representation.
Definition SparseMatrix.h:121
Pseudo expression to manipulate a triangular sparse matrix as a selfadjoint matrix.
Definition SparseSelfAdjointView.h:52
Namespace containing all symbols from the Eigen library.
Definition B01_Experimental.dox:1