MCPcopy Create free account
hub / github.com/pathwaycom/pathway / Graph

Class Graph

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

r""" Basic class representing undirected, unweighted (multi)graph.

Source from the content-addressed store, hash-verified

75
76@dataclass
77class Graph:
78 r"""
79 Basic class representing undirected, unweighted (multi)graph.
80 """
81
82 V: pw.Table[Vertex]
83 E: pw.Table[Edge]
84
85 def contracted_to_unweighted_simple_graph(
86 self,
87 clustering: pw.Table[Clustering],
88 **reducer_expressions: pw.ReducerExpression,
89 ) -> Graph:
90 contracted_graph = self.contracted_to_multi_graph(clustering)
91 contracted_graph.E = contracted_graph.E.groupby(
92 contracted_graph.E.u, contracted_graph.E.v
93 ).reduce(contracted_graph.E.u, contracted_graph.E.v)
94
95 return contracted_graph
96
97 def contracted_to_weighted_simple_graph(
98 self,
99 clustering: pw.Table[Clustering],
100 **reducer_expressions: pw.ReducerExpression,
101 ) -> WeightedGraph:
102 contracted_graph = self.contracted_to_multi_graph(clustering)
103 WE = contracted_graph.E.groupby(
104 contracted_graph.E.u, contracted_graph.E.v
105 ).reduce(contracted_graph.E.u, contracted_graph.E.v, **reducer_expressions)
106
107 return WeightedGraph.from_vertices_and_weighted_edges(contracted_graph.V, WE)
108
109 def contracted_to_multi_graph(
110 self,
111 clustering: pw.Table[Clustering],
112 ) -> Graph:
113 full_clustering = _extended_to_full_clustering(self.V, clustering)
114 return _contract(self.E, full_clustering)
115
116 def without_self_loops(self) -> Graph:
117 return Graph(self.V, self.E.filter(self.E.u != self.E.v))
118
119
120@dataclass

Callers 5

_contractFunction · 0.85
without_self_loopsMethod · 0.85

Calls

no outgoing calls