r"""Construct the hypergraph from the graph. Each edge in the graph is treated as a hyperedge in the constructed hypergraph. .. note:: The construsted hypergraph is a 2-uniform hypergraph, and has the same number of vertices and edges/hyperedges as the graph. Args:
(graph, device: torch.device = torch.device("cpu"))
| 207 | |
| 208 | @staticmethod |
| 209 | def from_graph(graph, device: torch.device = torch.device("cpu")) -> "Hypergraph": |
| 210 | r"""Construct the hypergraph from the graph. Each edge in the graph is treated as a hyperedge in the constructed hypergraph. |
| 211 | |
| 212 | .. note:: |
| 213 | The construsted hypergraph is a 2-uniform hypergraph, and has the same number of vertices and edges/hyperedges as the graph. |
| 214 | |
| 215 | Args: |
| 216 | ``graph`` (``eg.Graph``): The graph to construct the hypergraph. |
| 217 | ``device`` (``torch.device``, optional): The device to store the hypergraph. Defaults to ``torch.device('cpu')``. |
| 218 | """ |
| 219 | e_list, e_weight = graph.e |
| 220 | hg = Hypergraph(len(graph.nodes), e_list, e_weight=e_weight, device=device) |
| 221 | return hg |
| 222 | |
| 223 | @staticmethod |
| 224 | def _e_list_from_graph_kHop( |