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

Function _contract_weighted

python/pathway/stdlib/graphs/graph.py:36–58  ·  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 | Weight], clustering: pw.Table[Clustering]
)

Source from the content-addressed store, hash-verified

34
35
36def _contract_weighted(
37 edges: pw.Table[Edge | Weight], clustering: pw.Table[Clustering]
38) -> WeightedGraph:
39 r"""
40 This function contracts the clusters of the graph,
41 under the assumption that it was given a full clustering,
42 i.e., all vertices have exactly one cluster in clustering
43
44 Returns:
45 a graph in which:
46 - each vertex is a cluster from the clustering,
47 - each original edge now points to clusters containing the original endpoints
48
49 """
50
51 new_vertices = (
52 clustering.groupby(clustering.c)
53 .reduce(v=clustering.c)
54 .with_id(pw.this.v)
55 .select()
56 )
57 new_edges = edges.select(u=clustering.ix(edges.u).c, v=clustering.ix(edges.v).c)
58 return WeightedGraph.from_vertices_and_weighted_edges(new_vertices, new_edges)
59
60
61def _extended_to_full_clustering(

Callers 1

Calls 6

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

Tested by

no test coverage detected