code: def to_undirected(
      edge_index: torch.Tensor,
      edge_attr: _typing.Optional[torch.Tensor] = None,
  ) -> _typing.Union[
      torch.Tensor, _typing.Tuple[torch.Tensor, 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, optional): Edge weights or multi-dimensional
              edge features. (default: :obj:`None`)
          num_nodes (int, optional): The number of nodes, *i.e.*
              :obj:`max_val + 1` of :attr:`edge_index`. (default: :obj:`None`)
  
      :rtype: :class:`LongTensor` if :attr:`edge_attr` is :obj:`None`, else
          (:class:`LongTensor`, :class:`Tensor`)
      """
  
      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:
          edge_attr = torch.cat([edge_attr, edge_attr], dim=0)
  
      if edge_attr is None:
          return edge_index
      else:
          return edge_index, edge_attr
  
imports: import math
  import torch
  import typing
label_desc: Use image node_id 1 for calling a global function with example usage: to_undirected(edge_index, edge_attr) and returns: edge_index, edge_index,  edge_attr