code: def train_test_split_edges(
      edge_index: torch.Tensor,
      edge_attr: _typing.Optional[
          _typing.Union[torch.Tensor, _typing.List[torch.Tensor]]
      ] = None,
      num_nodes: _typing.Optional[int] = ...,
      val_ratio: float = 0.05,
      test_ratio: float = 0.1,
  ):
      r"""Splits the edges of a :class:`torch_geometric.data.Data` object
      into positive and negative train/val/test edges.
      As such, it will replace the :obj:`edge_index` attribute with
      :obj:`train_pos_edge_index`, :obj:`train_pos_neg_adj_mask`,
      :obj:`val_pos_edge_index`, :obj:`val_neg_edge_index` and
      :obj:`test_pos_edge_index` attributes.
      If :obj:`data` has edge features named :obj:`edge_attr`, then
      :obj:`train_pos_edge_attr`, :obj:`val_pos_edge_attr` and
      :obj:`test_pos_edge_attr` will be added as well.
  
      .. warning::
  
          :meth:`~torch_geometric.utils.train_test_split_edges` is deprecated and
          will be removed in a future release.
          Use :class:`torch_geometric.transforms.RandomLinkSplit` instead.
  
      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`)
          val_ratio (float, optional): The ratio of positive validation edges.
              (default: :obj:`0.05`)
          test_ratio (float, optional): The ratio of positive test edges.
              (default: :obj:`0.1`)
      """
      row, col = edge_index
      num_nodes = _maybe_num_nodes(edge_index, num_nodes)
  
      # Return upper triangular portion.
      mask = row < col
      row, col = row[mask], col[mask]
  
      if edge_attr is not None:
          edge_attr = edge_attr[mask]
  
      n_v = int(math.floor(val_ratio * row.size(0)))
      n_t = int(math.floor(test_ratio * row.size(0)))
  
      # Positive edges.
      perm = torch.randperm(row.size(0))
      row, col = row[perm], col[perm]
      if edge_attr is not None:
          edge_attr = edge_attr[perm]
  
      r, c = row[:n_v], col[:n_v]
      val_pos_edge_index = torch.stack([r, c], dim=0)
      if edge_attr is not None:
          val_pos_edge_attr = edge_attr[:n_v]
      else:
          val_pos_edge_attr = None
  
      r, c = row[n_v : n_v + n_t], col[n_v : n_v + n_t]
      test_pos_edge_index = torch.stack([r, c], dim=0)
      if edge_attr is not None:
          test_pos_edge_attr = edge_attr[n_v : n_v + n_t]
      else:
          test_pos_edge_attr = None
  
      r, c = row[n_v + n_t :], col[n_v + n_t :]
      train_pos_edge_index = torch.stack([r, c], dim=0)
      if edge_attr is not None:
          train_pos_edge_index, train_pos_edge_attr = to_undirected(
              train_pos_edge_index, edge_attr[n_v + n_t :]
          )
      else:
          train_pos_edge_index = to_undirected(train_pos_edge_index)
          train_pos_edge_attr = None
  
      # Negative edges.
      neg_adj_mask = torch.ones(num_nodes, num_nodes, dtype=torch.uint8)
      neg_adj_mask = neg_adj_mask.triu(diagonal=1).to(torch.bool)
      neg_adj_mask[row, col] = 0
  
      neg_row, neg_col = neg_adj_mask.nonzero(as_tuple=False).t()
      perm = torch.randperm(neg_row.size(0))[: n_v + n_t]
      neg_row, neg_col = neg_row[perm], neg_col[perm]
  
      neg_adj_mask[neg_row, neg_col] = 0
      train_neg_adj_mask = neg_adj_mask
  
      row, col = neg_row[:n_v], neg_col[:n_v]
      val_neg_edge_index = torch.stack([row, col], dim=0)
  
      row, col = neg_row[n_v : n_v + n_t], neg_col[n_v : n_v + n_t]
      test_neg_edge_index = torch.stack([row, col], dim=0)
  
      return _SplitResult(
          train_pos_edge_index,
          train_pos_edge_attr,
          train_neg_adj_mask,
          val_pos_edge_index,
          val_pos_edge_attr,
          val_neg_edge_index,
          test_pos_edge_index,
          test_pos_edge_attr,
          test_neg_edge_index,
      )
  
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 5 for calling a global function with example usage: train_test_split_edges(edge_index, edge_attr, num_nodes, val_ratio, test_ratio) and returns: _SplitResult