MCPcopy Index your code
hub / github.com/pathwaycom/pathway / _contract

Function _contract

python/pathway/stdlib/graphs/graph.py:13–33  ·  view source on GitHub ↗

r""" This function contracts the clusters of the graph, under the assumption that it was given a full clustering, i.e., all vertices have exactly one cluster in clustering Returns: a graph in which: - each vertex is a cluster from the clustering, - each origi

(edges: pw.Table[Edge], clustering: pw.Table[Clustering])

Source from the content-addressed store, hash-verified

11
12
13def _contract(edges: pw.Table[Edge], clustering: pw.Table[Clustering]) -> Graph:
14 r"""
15 This function contracts the clusters of the graph,
16 under the assumption that it was given a full clustering,
17 i.e., all vertices have exactly one cluster in clustering
18
19 Returns:
20 a graph in which:
21 - each vertex is a cluster from the clustering,
22 - each original edge now points to clusters containing the original endpoints
23
24 """
25
26 new_vertices = (
27 clustering.groupby(clustering.c)
28 .reduce(v=clustering.c)
29 .with_id(pw.this.v)
30 .select()
31 )
32 new_edges = edges.select(u=clustering.ix(edges.u).c, v=clustering.ix(edges.v).c)
33 return Graph(new_vertices, new_edges)
34
35
36def _contract_weighted(

Callers 1

Calls 6

GraphClass · 0.85
with_idMethod · 0.80
selectMethod · 0.45
reduceMethod · 0.45
groupbyMethod · 0.45
ixMethod · 0.45

Tested by

no test coverage detected