30#ifndef SPARSE_COLETREE_H
31#define SPARSE_COLETREE_H
34#include "./InternalHeaderCheck.h"
41template <
typename Index,
typename IndexVector>
42Index etree_find(Index i, IndexVector& pp) {
60template <
typename MatrixType,
typename IndexVector>
61int coletree(
const MatrixType& mat, IndexVector& parent, IndexVector& firstRowElt,
62 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++) {
78 StorageIndex pcol = col;
79 if (perm) pcol = perm[col];
80 for (
typename MatrixType::InnerIterator it(mat, pcol); it; ++it) {
82 firstRowElt(row) = (std::min)(firstRowElt(row), col);
89 StorageIndex rset, cset, rroot;
90 for (StorageIndex col = 0; col < nc; col++) {
91 found_diag = col >= m;
98 StorageIndex pcol = col;
99 if (perm) pcol = perm[col];
100 for (
typename MatrixType::InnerIterator it(mat, pcol); it || !found_diag;
103 if (it) i = it.index();
104 if (i == col) found_diag =
true;
106 StorageIndex row = firstRowElt(i);
107 if (row >= col)
continue;
108 rset = internal::etree_find(row, pp);
125template <
typename IndexVector>
126void nr_etdfs(
typename IndexVector::Scalar n, IndexVector& parent, IndexVector& first_kid, IndexVector& next_kid,
127 IndexVector& post,
typename IndexVector::Scalar postnum) {
128 typedef typename IndexVector::Scalar StorageIndex;
129 StorageIndex current = n, first, next;
130 while (postnum != n) {
132 first = first_kid(current);
137 post(current) = postnum++;
140 next = next_kid(current);
143 current = parent(current);
145 post(current) = postnum++;
148 next = next_kid(current);
151 if (postnum == n + 1)
return;
167template <
typename IndexVector>
168void treePostorder(
typename IndexVector::Scalar n, IndexVector& parent, IndexVector& post) {
169 typedef typename IndexVector::Scalar StorageIndex;
170 IndexVector first_kid, next_kid;
171 StorageIndex postnum;
173 first_kid.resize(n + 1);
174 next_kid.setZero(n + 1);
178 first_kid.setConstant(-1);
179 for (StorageIndex v = n - 1; v >= 0; v--) {
180 StorageIndex dad = parent(v);
181 next_kid(v) = first_kid(dad);
187 internal::nr_etdfs(n, parent, first_kid, next_kid, post, postnum);
Namespace containing all symbols from the Eigen library.
Definition Core:137