Medial Code Documentation
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
25template<typename MatrixType>
26void ordering_helper_at_plus_a(const MatrixType& mat, MatrixType& symmat)
27{
28 MatrixType C;
29 C = mat.transpose(); // NOTE: Could be costly
30 for (int i = 0; i < C.rows(); i++)
31 {
32 for (typename MatrixType::InnerIterator it(C, i); it; ++it)
33 it.valueRef() = 0.0;
34 }
35 symmat = C + mat;
36}
37
38}
39
40#ifndef EIGEN_MPL2_ONLY
41
50template <typename StorageIndex>
52{
53 public:
55
59 template <typename MatrixType>
60 void operator()(const MatrixType& mat, PermutationType& perm)
61 {
62 // Compute the symmetric pattern
64 internal::ordering_helper_at_plus_a(mat,symm);
65
66 // Call the AMD routine
67 //m_mat.prune(keep_diag());
68 internal::minimum_degree_ordering(symm, perm);
69 }
70
72 template <typename SrcType, unsigned int SrcUpLo>
74 {
76
77 // Call the AMD routine
78 // m_mat.prune(keep_diag()); //Remove the diagonal elements
79 internal::minimum_degree_ordering(C, perm);
80 }
81};
82
83#endif // EIGEN_MPL2_ONLY
84
93template <typename StorageIndex>
95{
96 public:
98
100 template <typename MatrixType>
101 void operator()(const MatrixType& /*mat*/, PermutationType& perm)
102 {
103 perm.resize(0);
104 }
105
106};
107
116template<typename StorageIndex>
118{
119 public:
122
126 template <typename MatrixType>
127 void operator() (const MatrixType& mat, PermutationType& perm)
128 {
129 eigen_assert(mat.isCompressed() && "COLAMDOrdering requires a sparse matrix in compressed mode. Call .makeCompressed() before passing it to COLAMDOrdering");
130
131 StorageIndex m = StorageIndex(mat.rows());
132 StorageIndex n = StorageIndex(mat.cols());
133 StorageIndex nnz = StorageIndex(mat.nonZeros());
134 // Get the recommended value of Alen to be used by colamd
135 StorageIndex Alen = internal::colamd_recommended(nnz, m, n);
136 // Set the default parameters
137 double knobs [COLAMD_KNOBS];
138 StorageIndex stats [COLAMD_STATS];
139 internal::colamd_set_defaults(knobs);
140
141 IndexVector p(n+1), A(Alen);
142 for(StorageIndex i=0; i <= n; i++) p(i) = mat.outerIndexPtr()[i];
143 for(StorageIndex i=0; i < nnz; i++) A(i) = mat.innerIndexPtr()[i];
144 // Call Colamd routine to compute the ordering
145 StorageIndex info = internal::colamd(m, n, Alen, A.data(), p.data(), knobs, stats);
146 EIGEN_UNUSED_VARIABLE(info);
147 eigen_assert( info && "COLAMD failed " );
148
149 perm.resize(n);
150 for (StorageIndex i = 0; i < n; i++) perm.indices()(p(i)) = i;
151 }
152};
153
154} // end namespace Eigen
155
156#endif
Functor computing the approximate minimum degree ordering If the matrix is not structurally symmetric...
Definition Ordering.h:52
void operator()(const SparseSelfAdjointView< SrcType, SrcUpLo > &mat, PermutationType &perm)
Compute the permutation with a selfadjoint matrix.
Definition Ordering.h:73
void operator()(const MatrixType &mat, PermutationType &perm)
Compute the permutation vector from a sparse matrix This routine is much faster if the input matrix i...
Definition Ordering.h:60
Definition Ordering.h:118
void operator()(const MatrixType &mat, PermutationType &perm)
Compute the permutation vector perm form the sparse matrix mat.
Definition Ordering.h:127
Functor computing the natural ordering (identity)
Definition Ordering.h:95
void operator()(const MatrixType &, PermutationType &perm)
Compute the permutation vector from a column-major sparse matrix.
Definition Ordering.h:101
void resize(Index newSize)
Resizes to given size.
Definition PermutationMatrix.h:137
const IndicesType & indices() const
const version of indices().
Definition PermutationMatrix.h:390
Pseudo expression representing a solving operation.
Definition Solve.h:63