31#ifndef SPARSE_COLETREE_H
32#define SPARSE_COLETREE_H
34#include "./InternalHeaderCheck.h"
41template<
typename Index,
typename IndexVector>
62template <
typename MatrixType,
typename IndexVector>
63int coletree(
const MatrixType& mat, IndexVector& parent, IndexVector& firstRowElt,
typename MatrixType::StorageIndex *perm=0)
65 typedef typename MatrixType::StorageIndex StorageIndex;
66 StorageIndex nc = convert_index<StorageIndex>(mat.cols());
67 StorageIndex m = convert_index<StorageIndex>(mat.rows());
68 StorageIndex diagSize = (std::min)(nc,m);
73 parent.resize(mat.cols());
75 firstRowElt.resize(m);
76 firstRowElt.setConstant(nc);
77 firstRowElt.segment(0, diagSize).setLinSpaced(diagSize, 0, diagSize-1);
79 for (StorageIndex col = 0; col < nc; col++)
81 StorageIndex pcol = col;
82 if(perm) pcol = perm[col];
83 for (
typename MatrixType::InnerIterator it(mat, pcol); it; ++it)
86 firstRowElt(row) = (std::min)(firstRowElt(row), col);
93 StorageIndex rset, cset, rroot;
94 for (StorageIndex col = 0; col < nc; col++)
103 StorageIndex pcol = col;
104 if(perm) pcol = perm[col];
105 for (
typename MatrixType::InnerIterator it(mat, pcol); it||!found_diag; ++it)
108 if(it) i = it.index();
109 if (i == col) found_diag =
true;
111 StorageIndex row = firstRowElt(i);
112 if (row >= col)
continue;
113 rset = internal::etree_find(row, pp);
131template <
typename IndexVector>
132void nr_etdfs (
typename IndexVector::Scalar n, IndexVector& parent, IndexVector& first_kid, IndexVector& next_kid, IndexVector& post,
typename IndexVector::Scalar postnum)
134 typedef typename IndexVector::Scalar StorageIndex;
135 StorageIndex current = n, first, next;
139 first = first_kid(current);
145 post(current) = postnum++;
148 next = next_kid(current);
152 current = parent(current);
154 post(current) = postnum++;
157 next = next_kid(current);
160 if (postnum == n+1)
return;
179template <
typename IndexVector>
180void treePostorder(
typename IndexVector::Scalar n, IndexVector& parent, IndexVector& post)
182 typedef typename IndexVector::Scalar StorageIndex;
183 IndexVector first_kid, next_kid;
184 StorageIndex postnum;
186 first_kid.resize(n+1);
187 next_kid.setZero(n+1);
191 first_kid.setConstant(-1);
192 for (StorageIndex v = n-1; v >= 0; v--)
194 StorageIndex dad = parent(v);
195 next_kid(v) = first_kid(dad);
201 internal::nr_etdfs(n, parent, first_kid, next_kid, post, postnum);
Namespace containing all symbols from the Eigen library.
Definition: B01_Experimental.dox:1
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:59