Ordering.h
Go to the documentation of this file.
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 #include "./InternalHeaderCheck.h"
15 
16 namespace Eigen {
17 
18 #include "Eigen_Colamd.h"
19 
20 namespace internal {
21 
28 template<typename MatrixType>
30 {
31  MatrixType C;
32  C = A.transpose(); // NOTE: Could be costly
33  for (int i = 0; i < C.rows(); i++)
34  {
35  for (typename MatrixType::InnerIterator it(C, i); it; ++it)
36  it.valueRef() = typename MatrixType::Scalar(0);
37  }
38  symmat = C + A;
39 }
40 
41 }
42 
51 template <typename StorageIndex>
53 {
54  public:
56 
60  template <typename MatrixType>
62  {
63  // Compute the symmetric pattern
66 
67  // Call the AMD routine
68  //m_mat.prune(keep_diag());
70  }
71 
73  template <typename SrcType, unsigned int SrcUpLo>
75  {
77 
78  // Call the AMD routine
79  // m_mat.prune(keep_diag()); //Remove the diagonal elements
81  }
82 };
83 
92 template <typename StorageIndex>
94 {
95  public:
97 
99  template <typename MatrixType>
100  void operator()(const MatrixType& /*mat*/, PermutationType& perm)
101  {
102  perm.resize(0);
103  }
104 
105 };
106 
115 template<typename StorageIndex>
117 {
118  public:
121 
125  template <typename MatrixType>
127  {
128  eigen_assert(mat.isCompressed() && "COLAMDOrdering requires a sparse matrix in compressed mode. Call .makeCompressed() before passing it to COLAMDOrdering");
129 
130  StorageIndex m = StorageIndex(mat.rows());
131  StorageIndex n = StorageIndex(mat.cols());
132  StorageIndex nnz = StorageIndex(mat.nonZeros());
133  // Get the recommended value of Alen to be used by colamd
134  StorageIndex Alen = internal::Colamd::recommended(nnz, m, n);
135  // Set the default parameters
136  double knobs [internal::Colamd::NKnobs];
137  StorageIndex stats [internal::Colamd::NStats];
138  internal::Colamd::set_defaults(knobs);
139 
140  IndexVector p(n+1), A(Alen);
141  for(StorageIndex i=0; i <= n; i++) p(i) = mat.outerIndexPtr()[i];
142  for(StorageIndex i=0; i < nnz; i++) A(i) = mat.innerIndexPtr()[i];
143  // Call Colamd routine to compute the ordering
144  StorageIndex info = internal::Colamd::compute_ordering(m, n, Alen, A.data(), p.data(), knobs, stats);
145  EIGEN_UNUSED_VARIABLE(info);
146  eigen_assert( info && "COLAMD failed " );
147 
148  perm.resize(n);
149  for (StorageIndex i = 0; i < n; i++) perm.indices()(p(i)) = i;
150  }
151 };
152 
153 } // end namespace Eigen
154 
155 #endif
Matrix3f m
int n
MatrixXcf A
#define EIGEN_UNUSED_VARIABLE(var)
Definition: Macros.h:957
#define eigen_assert(x)
Definition: Macros.h:902
float * p
Matrix< float, 1, Dynamic > MatrixType
void operator()(const SparseSelfAdjointView< SrcType, SrcUpLo > &mat, PermutationType &perm)
Definition: Ordering.h:74
PermutationMatrix< Dynamic, Dynamic, StorageIndex > PermutationType
Definition: Ordering.h:55
void operator()(const MatrixType &mat, PermutationType &perm)
Definition: Ordering.h:61
void operator()(const MatrixType &mat, PermutationType &perm)
Definition: Ordering.h:126
Matrix< StorageIndex, Dynamic, 1 > IndexVector
Definition: Ordering.h:120
PermutationMatrix< Dynamic, Dynamic, StorageIndex > PermutationType
Definition: Ordering.h:119
The matrix class, also used for vectors and row-vectors.
Definition: Matrix.h:182
void operator()(const MatrixType &, PermutationType &perm)
Definition: Ordering.h:100
PermutationMatrix< Dynamic, Dynamic, StorageIndex > PermutationType
Definition: Ordering.h:96
void resize(Index newSize)
const IndicesType & indices() const
A versatible sparse matrix representation.
Definition: SparseMatrix.h:125
Pseudo expression to manipulate a triangular sparse matrix as a selfadjoint matrix.
void ordering_helper_at_plus_a(const MatrixType &A, MatrixType &symmat)
Definition: Ordering.h:29
void minimum_degree_ordering(SparseMatrix< Scalar, ColMajor, StorageIndex > &C, PermutationMatrix< Dynamic, Dynamic, StorageIndex > &perm)
Definition: Amd.h:86
: InteropHeaders
Definition: Core:139