Eigen  3.4.90 (git rev 5a9f66fb35d03a4da9ef8976e67a61b30aa16dcf)
 
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 <[email protected]>
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
17namespace Eigen {
18
19#include "Eigen_Colamd.h"
20
21namespace internal {
22
29template <typename MatrixType>
30void ordering_helper_at_plus_a(const MatrixType& A, MatrixType& symmat) {
31 MatrixType C;
32 C = A.transpose(); // NOTE: Could be costly
33 for (int i = 0; i < C.rows(); i++) {
34 for (typename MatrixType::InnerIterator it(C, i); it; ++it) it.valueRef() = typename MatrixType::Scalar(0);
35 }
36 symmat = C + A;
37}
38
39} // namespace internal
40
49template <typename StorageIndex>
51 public:
53
57 template <typename MatrixType>
58 void operator()(const MatrixType& mat, PermutationType& perm) {
59 // Compute the symmetric pattern
61 internal::ordering_helper_at_plus_a(mat, symm);
62
63 // Call the AMD routine
64 // m_mat.prune(keep_diag());
65 internal::minimum_degree_ordering(symm, perm);
66 }
67
69 template <typename SrcType, unsigned int SrcUpLo>
72 C = mat;
73
74 // Call the AMD routine
75 // m_mat.prune(keep_diag()); //Remove the diagonal elements
76 internal::minimum_degree_ordering(C, perm);
77 }
78};
79
88template <typename StorageIndex>
90 public:
92
94 template <typename MatrixType>
95 void operator()(const MatrixType& /*mat*/, PermutationType& perm) {
96 perm.resize(0);
97 }
98};
99
108template <typename StorageIndex>
110 public:
113
117 template <typename MatrixType>
118 void operator()(const MatrixType& mat, PermutationType& perm) {
119 eigen_assert(mat.isCompressed() &&
120 "COLAMDOrdering requires a sparse matrix in compressed mode. Call .makeCompressed() before passing it "
121 "to COLAMDOrdering");
122
123 StorageIndex m = StorageIndex(mat.rows());
124 StorageIndex n = StorageIndex(mat.cols());
125 StorageIndex nnz = StorageIndex(mat.nonZeros());
126 // Get the recommended value of Alen to be used by colamd
127 StorageIndex Alen = internal::Colamd::recommended(nnz, m, n);
128 // Set the default parameters
129 double knobs[internal::Colamd::NKnobs];
130 StorageIndex stats[internal::Colamd::NStats];
131 internal::Colamd::set_defaults(knobs);
132
133 IndexVector p(n + 1), A(Alen);
134 for (StorageIndex i = 0; i <= n; i++) p(i) = mat.outerIndexPtr()[i];
135 for (StorageIndex i = 0; i < nnz; i++) A(i) = mat.innerIndexPtr()[i];
136 // Call Colamd routine to compute the ordering
137 StorageIndex info = internal::Colamd::compute_ordering(m, n, Alen, A.data(), p.data(), knobs, stats);
138 EIGEN_UNUSED_VARIABLE(info);
139 eigen_assert(info && "COLAMD failed ");
140
141 perm.resize(n);
142 for (StorageIndex i = 0; i < n; i++) perm.indices()(p(i)) = i;
143 }
144};
145
146} // end namespace Eigen
147
148#endif
Definition Ordering.h:50
void operator()(const SparseSelfAdjointView< SrcType, SrcUpLo > &mat, PermutationType &perm)
Definition Ordering.h:70
void operator()(const MatrixType &mat, PermutationType &perm)
Definition Ordering.h:58
Definition Ordering.h:109
void operator()(const MatrixType &mat, PermutationType &perm)
Definition Ordering.h:118
The matrix class, also used for vectors and row-vectors.
Definition Matrix.h:186
Definition Ordering.h:89
void operator()(const MatrixType &, PermutationType &perm)
Definition Ordering.h:95
void resize(Index newSize)
Definition PermutationMatrix.h:119
Permutation matrix.
Definition PermutationMatrix.h:280
const IndicesType & indices() const
Definition PermutationMatrix.h:334
const Scalar * data() const
Definition PlainObjectBase.h:273
A versatible sparse matrix representation.
Definition SparseUtil.h:47
Pseudo expression to manipulate a triangular sparse matrix as a selfadjoint matrix.
Definition SparseUtil.h:52
Namespace containing all symbols from the Eigen library.
Definition Core:137