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 // IWYU pragma: private
15 #include "./InternalHeaderCheck.h"
16 
17 namespace Eigen {
18 
19 #include "Eigen_Colamd.h"
20 
21 namespace internal {
22 
29 template <typename MatrixType>
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 
49 template <typename StorageIndex>
50 class AMDOrdering {
51  public:
53 
57  template <typename MatrixType>
58  void operator()(const MatrixType& mat, PermutationType& perm) {
59  // Compute the symmetric pattern
62 
63  // Call the AMD routine
64  // m_mat.prune(keep_diag());
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
77  }
78 };
79 
88 template <typename StorageIndex>
90  public:
92 
94  template <typename MatrixType>
95  void operator()(const MatrixType& /*mat*/, PermutationType& perm) {
96  perm.resize(0);
97  }
98 };
99 
108 template <typename StorageIndex>
110  public:
113 
117  template <typename MatrixType>
118  void operator()(const MatrixType& mat, PermutationType& perm) {
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];
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);
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
int i
Definition: BiCGSTAB_step_by_step.cpp:9
const unsigned n
Definition: CG3DPackingUnitTest.cpp:11
Eigen::SparseMatrix< double > mat
Definition: EigenUnitTest.cpp:10
#define EIGEN_UNUSED_VARIABLE(var)
Definition: Macros.h:966
#define eigen_assert(x)
Definition: Macros.h:910
float * p
Definition: Tutorial_Map_using.cpp:9
SCALAR Scalar
Definition: bench_gemm.cpp:45
Matrix< SCALARA, Dynamic, Dynamic, opt_A > A
Definition: bench_gemm.cpp:47
Matrix< Scalar, Dynamic, Dynamic > C
Definition: bench_gemm.cpp:49
MatrixXf MatrixType
Definition: benchmark-blocking-sizes.cpp:52
Definition: Ordering.h:50
void operator()(const SparseSelfAdjointView< SrcType, SrcUpLo > &mat, PermutationType &perm)
Definition: Ordering.h:70
PermutationMatrix< Dynamic, Dynamic, StorageIndex > PermutationType
Definition: Ordering.h:52
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
Matrix< StorageIndex, Dynamic, 1 > IndexVector
Definition: Ordering.h:112
PermutationMatrix< Dynamic, Dynamic, StorageIndex > PermutationType
Definition: Ordering.h:111
The matrix class, also used for vectors and row-vectors.
Definition: Eigen/Eigen/src/Core/Matrix.h:186
Definition: Ordering.h:89
void operator()(const MatrixType &, PermutationType &perm)
Definition: Ordering.h:95
PermutationMatrix< Dynamic, Dynamic, StorageIndex > PermutationType
Definition: Ordering.h:91
void resize(Index newSize)
Definition: PermutationMatrix.h:119
const IndicesType & indices() const
Definition: PermutationMatrix.h:334
constexpr EIGEN_DEVICE_FUNC const Scalar * data() const
Definition: PlainObjectBase.h:273
Index nonZeros() const
Definition: SparseCompressedBase.h:64
Index cols() const
Definition: SparseMatrix.h:161
bool isCompressed() const
Definition: SparseCompressedBase.h:114
Index rows() const
Definition: SparseMatrix.h:159
const StorageIndex * outerIndexPtr() const
Definition: SparseMatrix.h:189
const StorageIndex * innerIndexPtr() const
Definition: SparseMatrix.h:180
Pseudo expression to manipulate a triangular sparse matrix as a selfadjoint matrix.
Definition: SparseSelfAdjointView.h:52
Definition: matrices.h:74
void ordering_helper_at_plus_a(const MatrixType &A, MatrixType &symmat)
Definition: Ordering.h:30
void minimum_degree_ordering(SparseMatrix< Scalar, ColMajor, StorageIndex > &C, PermutationMatrix< Dynamic, Dynamic, StorageIndex > &perm)
Definition: Amd.h:92
int * m
Definition: level2_cplx_impl.h:294
int info
Definition: level2_cplx_impl.h:39
Namespace containing all symbols from the Eigen library.
Definition: bench_norm.cpp:70
const int NKnobs
Definition: Eigen_Colamd.h:63
IndexType recommended(IndexType nnz, IndexType n_row, IndexType n_col)
Returns the recommended value of Alen.
Definition: Eigen_Colamd.h:267
static bool compute_ordering(IndexType n_row, IndexType n_col, IndexType Alen, IndexType *A, IndexType *p, double knobs[NKnobs], IndexType stats[NStats])
Computes a column ordering using the column approximate minimum degree ordering.
Definition: Eigen_Colamd.h:328
const int NStats
Definition: Eigen_Colamd.h:66
static void set_defaults(double knobs[NKnobs])
set default parameters The use of this routine is optional.
Definition: Eigen_Colamd.h:295
Definition: Eigen_Colamd.h:49
void symm(int size=Size, int othersize=OtherSize)
Definition: product_symm.cpp:13