Warning, file /include/eigen3/Eigen/src/OrderingMethods/Ordering.h was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef EIGEN_ORDERING_H
0012 #define EIGEN_ORDERING_H
0013
0014 namespace Eigen {
0015
0016 #include "Eigen_Colamd.h"
0017
0018 namespace internal {
0019
0020
0021
0022
0023
0024
0025
0026 template<typename MatrixType>
0027 void ordering_helper_at_plus_a(const MatrixType& A, MatrixType& symmat)
0028 {
0029 MatrixType C;
0030 C = A.transpose();
0031 for (int i = 0; i < C.rows(); i++)
0032 {
0033 for (typename MatrixType::InnerIterator it(C, i); it; ++it)
0034 it.valueRef() = typename MatrixType::Scalar(0);
0035 }
0036 symmat = C + A;
0037 }
0038
0039 }
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049 template <typename StorageIndex>
0050 class AMDOrdering
0051 {
0052 public:
0053 typedef PermutationMatrix<Dynamic, Dynamic, StorageIndex> PermutationType;
0054
0055
0056
0057
0058 template <typename MatrixType>
0059 void operator()(const MatrixType& mat, PermutationType& perm)
0060 {
0061
0062 SparseMatrix<typename MatrixType::Scalar, ColMajor, StorageIndex> symm;
0063 internal::ordering_helper_at_plus_a(mat,symm);
0064
0065
0066
0067 internal::minimum_degree_ordering(symm, perm);
0068 }
0069
0070
0071 template <typename SrcType, unsigned int SrcUpLo>
0072 void operator()(const SparseSelfAdjointView<SrcType, SrcUpLo>& mat, PermutationType& perm)
0073 {
0074 SparseMatrix<typename SrcType::Scalar, ColMajor, StorageIndex> C; C = mat;
0075
0076
0077
0078 internal::minimum_degree_ordering(C, perm);
0079 }
0080 };
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090 template <typename StorageIndex>
0091 class NaturalOrdering
0092 {
0093 public:
0094 typedef PermutationMatrix<Dynamic, Dynamic, StorageIndex> PermutationType;
0095
0096
0097 template <typename MatrixType>
0098 void operator()(const MatrixType& , PermutationType& perm)
0099 {
0100 perm.resize(0);
0101 }
0102
0103 };
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113 template<typename StorageIndex>
0114 class COLAMDOrdering
0115 {
0116 public:
0117 typedef PermutationMatrix<Dynamic, Dynamic, StorageIndex> PermutationType;
0118 typedef Matrix<StorageIndex, Dynamic, 1> IndexVector;
0119
0120
0121
0122
0123 template <typename MatrixType>
0124 void operator() (const MatrixType& mat, PermutationType& perm)
0125 {
0126 eigen_assert(mat.isCompressed() && "COLAMDOrdering requires a sparse matrix in compressed mode. Call .makeCompressed() before passing it to COLAMDOrdering");
0127
0128 StorageIndex m = StorageIndex(mat.rows());
0129 StorageIndex n = StorageIndex(mat.cols());
0130 StorageIndex nnz = StorageIndex(mat.nonZeros());
0131
0132 StorageIndex Alen = internal::Colamd::recommended(nnz, m, n);
0133
0134 double knobs [internal::Colamd::NKnobs];
0135 StorageIndex stats [internal::Colamd::NStats];
0136 internal::Colamd::set_defaults(knobs);
0137
0138 IndexVector p(n+1), A(Alen);
0139 for(StorageIndex i=0; i <= n; i++) p(i) = mat.outerIndexPtr()[i];
0140 for(StorageIndex i=0; i < nnz; i++) A(i) = mat.innerIndexPtr()[i];
0141
0142 StorageIndex info = internal::Colamd::compute_ordering(m, n, Alen, A.data(), p.data(), knobs, stats);
0143 EIGEN_UNUSED_VARIABLE(info);
0144 eigen_assert( info && "COLAMD failed " );
0145
0146 perm.resize(n);
0147 for (StorageIndex i = 0; i < n; i++) perm.indices()(p(i)) = i;
0148 }
0149 };
0150
0151 }
0152
0153 #endif