31#ifndef SPARSE_COLETREE_H
32#define SPARSE_COLETREE_H
39template<
typename Index,
typename IndexVector>
60template <
typename MatrixType,
typename IndexVector>
61int coletree(
const MatrixType& mat, IndexVector& parent, IndexVector& firstRowElt,
typename MatrixType::StorageIndex *perm=0)
63 typedef typename MatrixType::StorageIndex StorageIndex;
64 StorageIndex nc = convert_index<StorageIndex>(mat.cols());
65 StorageIndex m = convert_index<StorageIndex>(mat.rows());
66 StorageIndex diagSize = (
std::min)(nc,m);
71 parent.resize(mat.cols());
73 firstRowElt.resize(m);
74 firstRowElt.setConstant(nc);
75 firstRowElt.segment(0, diagSize).setLinSpaced(diagSize, 0, diagSize-1);
77 for (StorageIndex
col = 0;
col < nc;
col++)
79 StorageIndex pcol =
col;
80 if(perm) pcol = perm[
col];
81 for (
typename MatrixType::InnerIterator it(mat, pcol); it; ++it)
91 StorageIndex rset, cset, rroot;
92 for (StorageIndex
col = 0;
col < nc;
col++)
101 StorageIndex pcol =
col;
102 if(perm) pcol = perm[
col];
103 for (
typename MatrixType::InnerIterator it(mat, pcol); it||!found_diag; ++it)
106 if(it) i = it.index();
107 if (i ==
col) found_diag =
true;
109 StorageIndex
row = firstRowElt(i);
129template <
typename IndexVector>
130void nr_etdfs (
typename IndexVector::Scalar n, IndexVector& parent, IndexVector& first_kid, IndexVector& next_kid, IndexVector& post,
typename IndexVector::Scalar postnum)
132 typedef typename IndexVector::Scalar StorageIndex;
133 StorageIndex current = n,
first, next;
137 first = first_kid(current);
143 post(current) = postnum++;
146 next = next_kid(current);
150 current = parent(current);
152 post(current) = postnum++;
155 next = next_kid(current);
158 if (postnum == n+1)
return;
177template <
typename IndexVector>
178void treePostorder(
typename IndexVector::Scalar n, IndexVector& parent, IndexVector& post)
180 typedef typename IndexVector::Scalar StorageIndex;
181 IndexVector first_kid, next_kid;
182 StorageIndex postnum;
184 first_kid.resize(n+1);
185 next_kid.setZero(n+1);
189 first_kid.setConstant(-1);
190 for (StorageIndex v = n-1; v >= 0; v--)
192 StorageIndex dad = parent(v);
193 next_kid(v) = first_kid(dad);
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ColXpr col(Index i)
This is the const version of col().
Definition: BlockMethods.h:1097
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE RowXpr row(Index i)
This is the const version of row(). */.
Definition: BlockMethods.h:1118
constexpr common_t< T1, T2 > min(const T1 x, const T2 y) noexcept
Compile-time pairwise minimum function.
Definition: min.hpp:35
int coletree(const MatrixType &mat, IndexVector &parent, IndexVector &firstRowElt, typename MatrixType::StorageIndex *perm=0)
Compute the column elimination tree of a sparse matrix.
Definition: SparseColEtree.h:61
EIGEN_CONSTEXPR Index first(const T &x) EIGEN_NOEXCEPT
Definition: IndexedViewHelper.h:81
void treePostorder(typename IndexVector::Scalar n, IndexVector &parent, IndexVector &post)
Post order a tree.
Definition: SparseColEtree.h:178
void nr_etdfs(typename IndexVector::Scalar n, IndexVector &parent, IndexVector &first_kid, IndexVector &next_kid, IndexVector &post, typename IndexVector::Scalar postnum)
Depth-first search from vertex n.
Definition: SparseColEtree.h:130
Index etree_find(Index i, IndexVector &pp)
Find the root of the tree/set containing the vertex i : Use Path halving.
Definition: SparseColEtree.h:40
Namespace containing all symbols from the Eigen library.
Definition: Core:141
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:74
Definition: Eigen_Colamd.h:50