code: def to_undirected(
      edge_index: torch.Tensor,
      edge_attr: _typing.Optional[
          _typing.Union[torch.Tensor, _typing.List[torch.Tensor]]
      ] = None,
      num_nodes: _typing.Optional[int] = ...,
      __reduce: str = "add",
  ) -> _typing.Union[
      torch.Tensor,
      _typing.Tuple[torch.Tensor, torch.Tensor],
      _typing.Tuple[torch.Tensor, _typing.List[torch.Tensor]],
  ]:
      r"""Converts the graph given by :attr:`edge_index` to an undirected graph
      such that :math:`(j,i) \in \mathcal{E}` for every edge :math:`(i,j) \in
      \mathcal{E}`.
  
      Args:
          edge_index (LongTensor): The edge indices.
          edge_attr (Tensor or List[Tensor], optional): Edge weights or multi-
              dimensional edge features.
              If given as a list, will remove duplicates for all its entries.
              (default: :obj:`None`)
          num_nodes (int, optional): The number of nodes, *i.e.*
              :obj:`max_val + 1` of :attr:`edge_index`. (default: :obj:`None`)
          __reduce (string, optional): The reduce operation to use for merging edge
              features (:obj:`"add"`, :obj:`"mean"`, :obj:`"min"`, :obj:`"max"`,
              :obj:`"mul"`). (default: :obj:`"add"`)
  
      :rtype: :class:`LongTensor` if :attr:`edge_attr` is :obj:`None`, else
          (:class:`LongTensor`, :obj:`Tensor` or :obj:`List[Tensor]]`)
      """
      # Maintain backward compatibility to `to_undirected(edge_index, num_nodes)`
      if isinstance(edge_attr, int):
          edge_attr = None
          num_nodes = edge_attr
  
      row, col = edge_index
      row, col = torch.cat([row, col], dim=0), torch.cat(
          [col, row], dim=0
      )
      edge_index = torch.stack([row, col], dim=0)
  
      if edge_attr is not None and isinstance(edge_attr, torch.Tensor):
          edge_attr = torch.cat([edge_attr, edge_attr], dim=0)
      elif edge_attr is not None:
          edge_attr = [torch.cat([e, e], dim=0) for e in edge_attr]
  
      return coalesce(edge_index, edge_attr, num_nodes)
  
file_path: AutoGL/autogl/datasets/utils/_split_edges/train_test_split_edges.py
imports: import math
  import torch
  import typing
label_desc: Use image node_id 4 for calling a global function with example usage: to_undirected(edge_index, edge_attr, num_nodes, __reduce) and returns: coalesce