31 #ifndef SPARSE_COLETREE_H 32 #define SPARSE_COLETREE_H 39 template<
typename Index,
typename IndexVector>
60 template <
typename MatrixType,
typename IndexVector>
61 int coletree(
const MatrixType& mat, IndexVector& parent, IndexVector& firstRowElt,
typename MatrixType::Index *perm=0)
63 typedef typename MatrixType::Index Index;
64 Index nc = mat.cols();
70 parent.resize(mat.cols());
73 firstRowElt.resize(m);
74 firstRowElt.setConstant(nc);
75 firstRowElt.segment(0, nc).setLinSpaced(nc, 0, nc-1);
77 for (col = 0; col < nc; col++)
80 if(perm) pcol = perm[
col];
81 for (
typename MatrixType::InnerIterator it(mat, pcol); it; ++it)
84 firstRowElt(row) = (std::min)(firstRowElt(row),
col);
91 Index rset, cset, rroot;
92 for (col = 0; col < nc; 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;
108 row = firstRowElt(i);
109 if (row >= col)
continue;
128 template <
typename Index,
typename IndexVector>
129 void nr_etdfs (Index n, IndexVector& parent, IndexVector& first_kid, IndexVector& next_kid, IndexVector& post, Index postnum)
131 Index current = n, first,
next;
135 first = first_kid(current);
141 post(current) = postnum++;
144 next = next_kid(current);
148 current = parent(current);
150 post(current) = postnum++;
153 next = next_kid(current);
156 if (postnum == n+1)
return;
175 template <
typename Index,
typename IndexVector>
178 IndexVector first_kid, next_kid;
181 first_kid.resize(n+1);
182 next_kid.setZero(n+1);
187 first_kid.setConstant(-1);
188 for (v = n-1; v >= 0; v--)
191 next_kid(v) = first_kid(dad);
204 #endif // SPARSE_COLETREE_H Index etree_find(Index i, IndexVector &pp)
void nr_etdfs(Index n, IndexVector &parent, IndexVector &first_kid, IndexVector &next_kid, IndexVector &post, Index postnum)
iterative scaling algorithm to equilibrate rows and column norms in matrices
int coletree(const MatrixType &mat, IndexVector &parent, IndexVector &firstRowElt, typename MatrixType::Index *perm=0)
Expression next(const Expression &arg)
void treePostorder(Index n, IndexVector &parent, IndexVector &post)
Post order a tree.