gammagl.utils.to_undirected

class to_undirected(edge_index, edge_attr=None, num_nodes=None, reduce: str = 'add')[source]

Converts the graph given by edge_index to an undirected graph such that \((j,i) \in \mathcal{E}\) for every edge \((i,j) \in \mathcal{E}\).

Parameters:
  • edge_index (tensor) – The edge indices.

  • edge_attr (tensor, list[tensor], optional) – Edge weights or multi- dimensional edge features. If given as a list, will remove duplicates for all its entries. (default: None)

  • num_nodes (int, optional) – The number of nodes, i.e. max_val + 1 of edge_index. (default: None)

  • reduce (str, optional) – The reduce operation to use for merging edge features ("add", "mean", "min", "max", "mul"). (default: "add")

Return type:

LongTensor if edge_attr is None, else (LongTensor, Tensor or List[Tensor]])