31 #ifndef SPARSE_COLETREE_H
32 #define SPARSE_COLETREE_H
41 template<
typename Index,
typename IndexVector>
62 template <
typename MatrixType,
typename IndexVector>
63 int 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());
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)
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);
131 template <
typename IndexVector>
132 void 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;
179 template <
typename IndexVector>
180 void 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);
Array< int, Dynamic, 1 > v
RowXpr row(Index i)
This is the const version of row(). */.
ColXpr col(Index i)
This is the const version of col().
Matrix< float, 1, Dynamic > MatrixType
bfloat16() min(const bfloat16 &a, const bfloat16 &b)
int coletree(const MatrixType &mat, IndexVector &parent, IndexVector &firstRowElt, typename MatrixType::StorageIndex *perm=0)
EIGEN_CONSTEXPR Index first(const T &x) EIGEN_NOEXCEPT
void treePostorder(typename IndexVector::Scalar n, IndexVector &parent, IndexVector &post)
Post order a tree.
void nr_etdfs(typename IndexVector::Scalar n, IndexVector &parent, IndexVector &first_kid, IndexVector &next_kid, IndexVector &post, typename IndexVector::Scalar postnum)
Index etree_find(Index i, IndexVector &pp)
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.