31 #ifndef SPARSE_COLETREE_H 32 #define SPARSE_COLETREE_H 39 template<
typename Index,
typename IndexVector>
60 template <
typename MatrixType,
typename IndexVector>
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);
79 StorageIndex pcol =
col;
81 for (
typename MatrixType::InnerIterator it(mat, pcol); it; ++it)
84 firstRowElt(row) = (
std::min)(firstRowElt(row),
col);
91 StorageIndex
rset, cset, rroot;
101 StorageIndex pcol =
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);
110 if (row >=
col)
continue;
129 template <
typename IndexVector>
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;
177 template <
typename IndexVector>
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);
206 #endif // SPARSE_COLETREE_H
Index etree_find(Index i, IndexVector &pp)
int coletree(const MatrixType &mat, IndexVector &parent, IndexVector &firstRowElt, typename MatrixType::StorageIndex *perm=0)
Namespace containing all symbols from the Eigen library.
EIGEN_CONSTEXPR Index first(const T &x) EIGEN_NOEXCEPT
void nr_etdfs(typename IndexVector::Scalar n, IndexVector &parent, IndexVector &first_kid, IndexVector &next_kid, IndexVector &post, typename IndexVector::Scalar postnum)
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Array< int, Dynamic, 1 > v
idx_t idx_t idx_t idx_t idx_t * perm
void treePostorder(typename IndexVector::Scalar n, IndexVector &parent, IndexVector &post)
Post order a tree.