MCPcopy Create free account
hub / github.com/ErrorAtLine0/infinipaint / coletree

Function coletree

include/Eigen/src/SparseCore/SparseColEtree.h:61–119  ·  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,
62 typename MatrixType::StorageIndex* perm = 0) {
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 StorageIndex pcol = col;
79 if (perm) pcol = perm[col];
80 for (typename MatrixType::InnerIterator it(mat, pcol); it; ++it) {
81 Index row = it.row();
82 firstRowElt(row) = (std::min)(firstRowElt(row), col);
83 }
84 }
85 /* Compute etree by Liu's algorithm for symmetric matrices,
86 except use (firstRowElt[r],c) in place of an edge (r,c) of A.
87 Thus each row clique in A'*A is replaced by a star
88 centered at its first vertex, which has the same fill. */
89 StorageIndex rset, cset, rroot;
90 for (StorageIndex col = 0; col < nc; col++) {
91 found_diag = col >= m;
92 pp(col) = col;
93 cset = col;
94 root(cset) = col;
95 parent(col) = nc;
96 /* The diagonal element is treated here even if it does not exist in the matrix
97 * hence the loop is executed once more */
98 StorageIndex pcol = col;
99 if (perm) pcol = perm[col];
100 for (typename MatrixType::InnerIterator it(mat, pcol); it || !found_diag;
101 ++it) { // A sequence of interleaved find and union is performed
102 Index i = col;
103 if (it) i = it.index();
104 if (i == col) found_diag = true;
105
106 StorageIndex row = firstRowElt(i);
107 if (row >= col) continue;
108 rset = internal::etree_find(row, pp); // Find the name of the set containing row
109 rroot = root(rset);
110 if (rroot != col) {
111 parent(rroot) = col;
112 pp(cset) = rset;
113 cset = rset;
114 root(cset) = col;
115 }
116 }
117 }
118 return 0;

Callers 3

analyzePatternMethod · 0.85
analyzePatternMethod · 0.85
factorizeMethod · 0.85

Calls 7

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