Please, help us to better know about our user community by answering the following short survey: https://forms.gle/wpyrxWi18ox9Z5ae9
Eigen  3.4.0
 
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
14namespace Eigen {
15
16#include "Eigen_Colamd.h"
17
18namespace internal {
19
26template<typename MatrixType>
27void ordering_helper_at_plus_a(const MatrixType& A, MatrixType& symmat)
28{
29 MatrixType C;
30 C = A.transpose(); // NOTE: Could be costly
31 for (int i = 0; i < C.rows(); i++)
32 {
33 for (typename MatrixType::InnerIterator it(C, i); it; ++it)
34 it.valueRef() = typename MatrixType::Scalar(0);
35 }
36 symmat = C + A;
37}
38
39}
40
49template <typename StorageIndex>
51{
52 public:
54
58 template <typename MatrixType>
59 void operator()(const MatrixType& mat, PermutationType& perm)
60 {
61 // Compute the symmetric pattern
63 internal::ordering_helper_at_plus_a(mat,symm);
64
65 // Call the AMD routine
66 //m_mat.prune(keep_diag());
67 internal::minimum_degree_ordering(symm, perm);
68 }
69
71 template <typename SrcType, unsigned int SrcUpLo>
73 {
75
76 // Call the AMD routine
77 // m_mat.prune(keep_diag()); //Remove the diagonal elements
78 internal::minimum_degree_ordering(C, perm);
79 }
80};
81
90template <typename StorageIndex>
92{
93 public:
95
97 template <typename MatrixType>
98 void operator()(const MatrixType& /*mat*/, PermutationType& perm)
99 {
100 perm.resize(0);
101 }
102
103};
104
113template<typename StorageIndex>
115{
116 public:
119
123 template <typename MatrixType>
124 void operator() (const MatrixType& mat, PermutationType& perm)
125 {
126 eigen_assert(mat.isCompressed() && "COLAMDOrdering requires a sparse matrix in compressed mode. Call .makeCompressed() before passing it to COLAMDOrdering");
127
128 StorageIndex m = StorageIndex(mat.rows());
129 StorageIndex n = StorageIndex(mat.cols());
130 StorageIndex nnz = StorageIndex(mat.nonZeros());
131 // Get the recommended value of Alen to be used by colamd
132 StorageIndex Alen = internal::Colamd::recommended(nnz, m, n);
133 // Set the default parameters
134 double knobs [internal::Colamd::NKnobs];
135 StorageIndex stats [internal::Colamd::NStats];
136 internal::Colamd::set_defaults(knobs);
137
138 IndexVector p(n+1), A(Alen);
139 for(StorageIndex i=0; i <= n; i++) p(i) = mat.outerIndexPtr()[i];
140 for(StorageIndex i=0; i < nnz; i++) A(i) = mat.innerIndexPtr()[i];
141 // Call Colamd routine to compute the ordering
142 StorageIndex info = internal::Colamd::compute_ordering(m, n, Alen, A.data(), p.data(), knobs, stats);
143 EIGEN_UNUSED_VARIABLE(info);
144 eigen_assert( info && "COLAMD failed " );
145
146 perm.resize(n);
147 for (StorageIndex i = 0; i < n; i++) perm.indices()(p(i)) = i;
148 }
149};
150
151} // end namespace Eigen
152
153#endif
Definition: Ordering.h:51
void operator()(const SparseSelfAdjointView< SrcType, SrcUpLo > &mat, PermutationType &perm)
Definition: Ordering.h:72
void operator()(const MatrixType &mat, PermutationType &perm)
Definition: Ordering.h:59
Definition: Ordering.h:115
void operator()(const MatrixType &mat, PermutationType &perm)
Definition: Ordering.h:124
The matrix class, also used for vectors and row-vectors.
Definition: Matrix.h:180
Definition: Ordering.h:92
void operator()(const MatrixType &, PermutationType &perm)
Definition: Ordering.h:98
void resize(Index newSize)
Definition: PermutationMatrix.h:125
Permutation matrix.
Definition: PermutationMatrix.h:298
const IndicesType & indices() const
Definition: PermutationMatrix.h:360
const Scalar * data() const
Definition: PlainObjectBase.h:247
A versatible sparse matrix representation.
Definition: SparseMatrix.h:98
Pseudo expression to manipulate a triangular sparse matrix as a selfadjoint matrix.
Definition: SparseSelfAdjointView.h:45
Namespace containing all symbols from the Eigen library.
Definition: Core:141