class_docstr: Performs an edge-level random split into training, validation and test
  sets of a :class:`~torch_geometric.data.Data` or a
  :class:`~torch_geometric.data.HeteroData` object
  (functional name: :obj:`random_link_split`).
  The split is performed such that the training split does not include edges
  in validation and test splits; and the validation split does not include
  edges in the test split.
  
  .. code-block::
  
      from torch_geometric.transforms import RandomLinkSplit
  
      transform = RandomLinkSplit(is_undirected=True)
      train_data, val_data, test_data = transform(data)
  
  Args:
      num_val (int or float, optional): The number of validation edges.
          If set to a floating-point value in :math:`[0, 1]`, it represents
          the ratio of edges to include in the validation set.
          (default: :obj:`0.1`)
      num_test (int or float, optional): The number of test edges.
          If set to a floating-point value in :math:`[0, 1]`, it represents
          the ratio of edges to include in the test set.
          (default: :obj:`0.2`)
      is_undirected (bool): If set to :obj:`True`, the graph is assumed to be
          undirected, and positive and negative samples will not leak
          (reverse) edge connectivity across different splits. This only
          affects the graph split, label data will not be returned
          undirected. This option is ignored for bipartite edge types or
          whenever :obj:`edge_type != rev_edge_type`. (default: :obj:`False`)
      key (str, optional): The name of the attribute holding
          ground-truth labels.
          If :obj:`data[key]` does not exist, it will be automatically
          created and represents a binary classification task
          (:obj:`1` = edge, :obj:`0` = no edge).
          If :obj:`data[key]` exists, it has to be a categorical label from
          :obj:`0` to :obj:`num_classes - 1`.
          After negative sampling, label :obj:`0` represents negative edges,
          and labels :obj:`1` to :obj:`num_classes` represent the labels of
          positive edges. (default: :obj:`"edge_label"`)
      split_labels (bool, optional): If set to :obj:`True`, will split
          positive and negative labels and save them in distinct attributes
          :obj:`"pos_edge_label"` and :obj:`"neg_edge_label"`, respectively.
          (default: :obj:`False`)
      add_negative_train_samples (bool, optional): Whether to add negative
          training samples for link prediction.
          If the model already performs negative sampling, then the option
          should be set to :obj:`False`.
          Otherwise, the added negative samples will be the same across
          training iterations unless negative sampling is performed again.
          (default: :obj:`True`)
      neg_sampling_ratio (float, optional): The ratio of sampled negative
          edges to the number of positive edges. (default: :obj:`1.0`)
      disjoint_train_ratio (int or float, optional): If set to a value
          greater than :obj:`0.0`, training edges will not be shared for
          message passing and supervision. Instead,
          :obj:`disjoint_train_ratio` edges are used as ground-truth labels
          for supervision during training. (default: :obj:`0.0`)
      edge_types (Tuple[EdgeType] or List[EdgeType], optional): The edge
          types used for performing edge-level splitting in case of
          operating on :class:`~torch_geometric.data.HeteroData` objects.
          (default: :obj:`None`)
      rev_edge_types (Tuple[EdgeType] or List[Tuple[EdgeType]], optional):
          The reverse edge types of :obj:`edge_types` in case of operating
          on :class:`~torch_geometric.data.HeteroData` objects.
          This will ensure that edges of the reverse direction will be
          split accordingly to prevent any data leakage.
          Can be :obj:`None` in case no reverse connection exists.
          (default: :obj:`None`)
class_docstr_tok: ["Performs","an","edge-level","random","split","into","training",",","validation","and","test","sets","of","a",":","class",":","`","~torch_geometric.data.Data","`","or","a",":","class",":","`","~torch_geometric.data.HeteroData","`","object","(","functional","name",":",":","obj",":","`","random_link_split","`",")",".","The","split","is","performed","such","that","the","training","split","does","not","include","edges","in","validation","and","test","splits",";","and","the","validation","split","does","not","include","edges","in","the","test","split",".","..","code-block",":",":","from","torch_geometric.transforms","import","RandomLinkSplit","transform","=","RandomLinkSplit","(","is_undirected=True",")","train_data",",","val_data",",","test_data","=","transform","(","data",")","Args",":","num_val","(","int","or","float",",","optional",")",":","The","number","of","validation","edges",".","If","set","to","a","floating-point","value","in",":","math",":","`","[","0",",","1","]","`",",","it","represents","the","ratio","of","edges","to","include","in","the","validation","set",".","(","default",":",":","obj",":","`","0.1","`",")","num_test","(","int","or","float",",","optional",")",":","The","number","of","test","edges",".","If","set","to","a","floating-point","value","in",":","math",":","`","[","0",",","1","]","`",",","it","represents","the","ratio","of","edges","to","include","in","the","test","set",".","(","default",":",":","obj",":","`","0.2","`",")","is_undirected","(","bool",")",":","If","set","to",":","obj",":","`","True","`",",","the","graph","is","assumed","to","be","undirected",",","and","positive","and","negative","samples","will","not","leak","(","reverse",")","edge","connectivity","across","different","splits",".","This","only","affects","the","graph","split",",","label","data","will","not","be","returned","undirected",".","This","option","is","ignored","for","bipartite","edge","types","or","whenever",":","obj",":","`","edge_type","!","=","rev_edge_type","`",".","(","default",":",":","obj",":","`","False","`",")","key","(","str",",","optional",")",":","The","name","of","the","attribute","holding","ground-truth","labels",".","If",":","obj",":","`","data","[","key","]","`","does","not","exist",",","it","will","be","automatically","created","and","represents","a","binary","classification","task","(",":","obj",":","`","1","`","=","edge",",",":","obj",":","`","0","`","=","no","edge",")",".","If",":","obj",":","`","data","[","key","]","`","exists",",","it","has","to","be","a","categorical","label","from",":","obj",":","`","0","`","to",":","obj",":","`","num_classes","-","1","`",".","After","negative","sampling",",","label",":","obj",":","`","0","`","represents","negative","edges",",","and","labels",":","obj",":","`","1","`","to",":","obj",":","`","num_classes","`","represent","the","labels","of","positive","edges",".","(","default",":",":","obj",":","`","``","edge_label","''","`",")","split_labels","(","bool",",","optional",")",":","If","set","to",":","obj",":","`","True","`",",","will","split","positive","and","negative","labels","and","save","them","in","distinct","attributes",":","obj",":","`","``","pos_edge_label","''","`","and",":","obj",":","`","``","neg_edge_label","''","`",",","respectively",".","(","default",":",":","obj",":","`","False","`",")","add_negative_train_samples","(","bool",",","optional",")",":","Whether","to","add","negative","training","samples","for","link","prediction",".","If","the","model","already","performs","negative","sampling",",","then","the","option","should","be","set","to",":","obj",":","`","False","`",".","Otherwise",",","the","added","negative","samples","will","be","the","same","across","training","iterations","unless","negative","sampling","is","performed","again",".","(","default",":",":","obj",":","`","True","`",")","neg_sampling_ratio","(","float",",","optional",")",":","The","ratio","of","sampled","negative","edges","to","the","number","of","positive","edges",".","(","default",":",":","obj",":","`","1.0","`",")","disjoint_train_ratio","(","int","or","float",",","optional",")",":","If","set","to","a","value","greater","than",":","obj",":","`","0.0","`",",","training","edges","will","not","be","shared","for","message","passing","and","supervision",".","Instead",",",":","obj",":","`","disjoint_train_ratio","`","edges","are","used","as","ground-truth","labels","for","supervision","during","training",".","(","default",":",":","obj",":","`","0.0","`",")","edge_types","(","Tuple","[","EdgeType","]","or","List","[","EdgeType","]",",","optional",")",":","The","edge","types","used","for","performing","edge-level","splitting","in","case","of","operating","on",":","class",":","`","~torch_geometric.data.HeteroData","`","objects",".","(","default",":",":","obj",":","`","None","`",")","rev_edge_types","(","Tuple","[","EdgeType","]","or","List","[","Tuple","[","EdgeType","]","]",",","optional",")",":","The","reverse","edge","types","of",":","obj",":","`","edge_types","`","in","case","of","operating","on",":","class",":","`","~torch_geometric.data.HeteroData","`","objects",".","This","will","ensure","that","edges","of","the","reverse","direction","will","be","split","accordingly","to","prevent","any","data","leakage",".","Can","be",":","obj",":","`","None","`","in","case","no","reverse","connection","exists",".","(","default",":",":","obj",":","`","None","`",")"]
code: def _create_label(
      self,
      store: EdgeStorage,
      index: Tensor,
      neg_edge_index: Tensor,
      out: EdgeStorage,
  ) -> EdgeStorage:
      edge_index = store.edge_index[:, index]
  
      if hasattr(store, self.key):
          edge_label = store[self.key]
          edge_label = edge_label[index]
          # Increment labels by one. Note that there is no need to increment
          # in case no negative edges are added.
          if neg_edge_index.numel() > 0:
              assert edge_label.dtype == torch.long
              assert edge_label.size(0) == edge_index.size(1)
              edge_label.add_(1)
          if hasattr(out, self.key):
              delattr(out, self.key)
      else:
          edge_label = torch.ones(index.numel(), device=index.device)
  
      if neg_edge_index.numel() > 0:
          neg_edge_label = edge_label.new_zeros(
              (neg_edge_index.size(1),) + edge_label.size()[1:]
          )
  
      if self.split_labels:
          out[f"pos_{self.key}"] = edge_label
          out[f"pos_{self.key}_index"] = edge_index
          if neg_edge_index.numel() > 0:
              out[f"neg_{self.key}"] = neg_edge_label
              out[f"neg_{self.key}_index"] = neg_edge_index
  
      else:
          if neg_edge_index.numel() > 0:
              edge_label = torch.cat(
                  [edge_label, neg_edge_label], dim=0
              )
              edge_index = torch.cat(
                  [edge_index, neg_edge_index], dim=-1
              )
          out[self.key] = edge_label
          out[f"{self.key}_index"] = edge_index
  
      return out
  
file_path: pytorch_geometric/torch_geometric/transforms/random_link_split.py
imports: import copy
  import warnings
  from typing import List, Optional, Tuple, Union
  import torch
  from torch import Tensor
  from torch_geometric.data import Data, HeteroData
  from torch_geometric.data.datapipes import functional_transform
  from torch_geometric.data.storage import EdgeStorage
  from torch_geometric.transforms import BaseTransform
  from torch_geometric.typing import EdgeType
  from torch_geometric.utils import negative_sampling
label_desc: Use image node_id 4 for calling the RandomLinkSplit obj's underlying member method code with example usage: obj._create_label(store, index, neg_edge_index, out) and returns: out