Skip to content

Commit f3534f8

Browse files
author
Teseo Schneider
committed
connected_components
1 parent 39f782c commit f3534f8

File tree

3 files changed

+65
-58
lines changed

3 files changed

+65
-58
lines changed

src/connected_components.cpp

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#include <common.h>
2+
#include <npe.h>
3+
#include <typedefs.h>
4+
5+
#include <igl/connected_components.h>
6+
7+
const char *ds_connected_components = R"igl_Qu8mg5v7(
8+
9+
Determine the connected components of a graph described by the input
10+
adjacency matrix (similar to MATLAB's graphconncomp).
11+
12+
Parameters
13+
----------
14+
15+
A #A by #A adjacency matrix (treated as describing an undirected graph)
16+
17+
Returns
18+
-------
19+
Returns number of connected components
20+
C #A list of component indices into [0,#K-1]
21+
K #K list of sizes of each component
22+
23+
See also
24+
--------
25+
26+
27+
Notes
28+
-----
29+
None
30+
31+
Examples
32+
--------
33+
34+
)igl_Qu8mg5v7";
35+
36+
npe_function(connected_components)
37+
npe_doc(ds_connected_components)
38+
39+
npe_arg(a, sparse_int, sparse_long, sparse_longlong)
40+
41+
42+
npe_begin_code()
43+
assert_nonzero_rows(a, "A");
44+
assert_cols_equals(a, a.rows(), "A");
45+
Eigen::SparseMatrix<npe_Scalar_a> a_copy = a;
46+
EigenDense<npe_Scalar_a> c;
47+
EigenDense<npe_Scalar_a> k;
48+
const int comps = igl::connected_components(a_copy, c, k);
49+
return std::make_tuple(comps, npe::move(c), npe::move(k));
50+
51+
npe_end_code()
52+
53+

tests/test_basic.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2018,6 +2018,18 @@ def test_unique_edge_map(self):
20182018
self.assertTrue(uE.shape[1] == 2)
20192019
self.assertTrue(E.shape[0] == self.f1.shape[0]*3)
20202020

2021+
def test_connected_components(self):
2022+
a = igl.adjacency_matrix(self.f)
2023+
comps, c, k = igl.connected_components(a)
2024+
2025+
self.assertTrue(c.flags.c_contiguous)
2026+
self.assertTrue(k.flags.c_contiguous)
2027+
2028+
self.assertTrue(c.dtype == self.f1.dtype)
2029+
self.assertTrue(k.dtype == self.f1.dtype)
2030+
2031+
self.assertTrue(c.shape[0] == a.shape[0])
2032+
20212033

20222034
if __name__ == '__main__':
20232035
unittest.main()

todo/connected_components.cpp

Lines changed: 0 additions & 58 deletions
This file was deleted.

0 commit comments

Comments
 (0)