MCPcopy Create free account
hub / github.com/PX4/eigen / coletree

Function coletree

Eigen/src/SparseCore/SparseColEtree.h:61–123  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

59 */
60template <typename MatrixType, typename IndexVector>
61int coletree(const MatrixType& mat, IndexVector& parent, IndexVector& firstRowElt, typename MatrixType::StorageIndex *perm=0)
62{
63 typedef typename MatrixType::StorageIndex StorageIndex;
64 StorageIndex nc = convert_index<StorageIndex>(mat.cols()); // Number of columns
65 StorageIndex m = convert_index<StorageIndex>(mat.rows());
66 StorageIndex diagSize = (std::min)(nc,m);
67 IndexVector root(nc); // root of subtree of etree
68 root.setZero();
69 IndexVector pp(nc); // disjoint sets
70 pp.setZero(); // Initialize disjoint sets
71 parent.resize(mat.cols());
72 //Compute first nonzero column in each row
73 firstRowElt.resize(m);
74 firstRowElt.setConstant(nc);
75 firstRowElt.segment(0, diagSize).setLinSpaced(diagSize, 0, diagSize-1);
76 bool found_diag;
77 for (StorageIndex col = 0; col < nc; col++)
78 {
79 StorageIndex pcol = col;
80 if(perm) pcol = perm[col];
81 for (typename MatrixType::InnerIterator it(mat, pcol); it; ++it)
82 {
83 Index row = it.row();
84 firstRowElt(row) = (std::min)(firstRowElt(row), col);
85 }
86 }
87 /* Compute etree by Liu's algorithm for symmetric matrices,
88 except use (firstRowElt[r],c) in place of an edge (r,c) of A.
89 Thus each row clique in A'*A is replaced by a star
90 centered at its first vertex, which has the same fill. */
91 StorageIndex rset, cset, rroot;
92 for (StorageIndex col = 0; col < nc; col++)
93 {
94 found_diag = col>=m;
95 pp(col) = col;
96 cset = col;
97 root(cset) = col;
98 parent(col) = nc;
99 /* The diagonal element is treated here even if it does not exist in the matrix
100 * hence the loop is executed once more */
101 StorageIndex pcol = col;
102 if(perm) pcol = perm[col];
103 for (typename MatrixType::InnerIterator it(mat, pcol); it||!found_diag; ++it)
104 { // A sequence of interleaved find and union is performed
105 Index i = col;
106 if(it) i = it.index();
107 if (i == col) found_diag = true;
108
109 StorageIndex row = firstRowElt(i);
110 if (row >= col) continue;
111 rset = internal::etree_find(row, pp); // Find the name of the set containing row
112 rroot = root(rset);
113 if (rroot != col)
114 {
115 parent(rroot) = col;
116 pp(cset) = rset;
117 cset = rset;
118 root(cset) = col;

Callers 3

analyzePatternMethod · 0.85
analyzePatternMethod · 0.85
factorizeMethod · 0.85

Calls 8

rootFunction · 0.85
etree_findFunction · 0.85
colsMethod · 0.45
rowsMethod · 0.45
setZeroMethod · 0.45
resizeMethod · 0.45
rowMethod · 0.45
indexMethod · 0.45

Tested by

no test coverage detected