code: def test_random_link_split_on_hetero_data():
      data = HeteroData()
  
      data["p"].x = torch.arange(100)
      data["a"].x = torch.arange(100, 300)
  
      data["p", "p"].edge_index = get_random_edge_index(100, 100, 500)
      data["p", "p"].edge_index = to_undirected(
          data["p", "p"].edge_index
      )
      data["p", "p"].edge_attr = torch.arange(data["p", "p"].num_edges)
      data["p", "a"].edge_index = get_random_edge_index(100, 200, 1000)
      data["p", "a"].edge_attr = torch.arange(500, 1500)
      data["a", "p"].edge_index = data["p", "a"].edge_index.flip([0])
      data["a", "p"].edge_attr = torch.arange(1500, 2500)
  
      transform = RandomLinkSplit(
          num_val=0.2,
          num_test=0.2,
          is_undirected=True,
          edge_types=("p", "p"),
      )
      train_data, val_data, test_data = transform(data)
  
      assert len(train_data["p"]) == 1
      assert len(train_data["a"]) == 1
      assert len(train_data["p", "p"]) == 4
      assert len(train_data["p", "a"]) == 2
      assert len(train_data["a", "p"]) == 2
  
      assert is_undirected(
          train_data["p", "p"].edge_index,
          train_data["p", "p"].edge_attr,
      )
      assert is_undirected(
          val_data["p", "p"].edge_index, val_data["p", "p"].edge_attr
      )
      assert is_undirected(
          test_data["p", "p"].edge_index, test_data["p", "p"].edge_attr
      )
  
      transform = RandomLinkSplit(
          num_val=0.2,
          num_test=0.2,
          edge_types=("p", "a"),
          rev_edge_types=("a", "p"),
      )
      train_data, val_data, test_data = transform(data)
  
      assert len(train_data["p"]) == 1
      assert len(train_data["a"]) == 1
      assert len(train_data["p", "p"]) == 2
      assert len(train_data["p", "a"]) == 4
      assert len(train_data["a", "p"]) == 2
  
      assert train_data["p", "a"].edge_index.size() == (2, 600)
      assert train_data["p", "a"].edge_attr.size() == (600,)
      assert train_data["p", "a"].edge_attr.min() >= 500
      assert train_data["p", "a"].edge_attr.max() <= 1500
      assert train_data["a", "p"].edge_index.size() == (2, 600)
      assert train_data["a", "p"].edge_attr.size() == (600,)
      assert train_data["a", "p"].edge_attr.min() >= 500
      assert train_data["a", "p"].edge_attr.max() <= 1500
      assert train_data["p", "a"].edge_label_index.size() == (2, 1200)
      assert train_data["p", "a"].edge_label.size() == (1200,)
  
      assert val_data["p", "a"].edge_index.size() == (2, 600)
      assert val_data["p", "a"].edge_attr.size() == (600,)
      assert val_data["p", "a"].edge_attr.min() >= 500
      assert val_data["p", "a"].edge_attr.max() <= 1500
      assert val_data["a", "p"].edge_index.size() == (2, 600)
      assert val_data["a", "p"].edge_attr.size() == (600,)
      assert val_data["a", "p"].edge_attr.min() >= 500
      assert val_data["a", "p"].edge_attr.max() <= 1500
      assert val_data["p", "a"].edge_label_index.size() == (2, 400)
      assert val_data["p", "a"].edge_label.size() == (400,)
  
      assert test_data["p", "a"].edge_index.size() == (2, 800)
      assert test_data["p", "a"].edge_attr.size() == (800,)
      assert test_data["p", "a"].edge_attr.min() >= 500
      assert test_data["p", "a"].edge_attr.max() <= 1500
      assert test_data["a", "p"].edge_index.size() == (2, 800)
      assert test_data["a", "p"].edge_attr.size() == (800,)
      assert test_data["a", "p"].edge_attr.min() >= 500
      assert test_data["a", "p"].edge_attr.max() <= 1500
      assert test_data["p", "a"].edge_label_index.size() == (2, 400)
      assert test_data["p", "a"].edge_label.size() == (400,)
  
      transform = RandomLinkSplit(
          num_val=0.2,
          num_test=0.2,
          is_undirected=True,
          edge_types=[("p", "p"), ("p", "a")],
          rev_edge_types=[None, ("a", "p")],
      )
      train_data, val_data, test_data = transform(data)
  
      assert len(train_data["p"]) == 1
      assert len(train_data["a"]) == 1
      assert len(train_data["p", "p"]) == 4
      assert len(train_data["p", "a"]) == 4
      assert len(train_data["a", "p"]) == 2
  
      assert is_undirected(
          train_data["p", "p"].edge_index,
          train_data["p", "p"].edge_attr,
      )
      assert train_data["p", "a"].edge_index.size() == (2, 600)
      assert train_data["a", "p"].edge_index.size() == (2, 600)
  
      # No reverse edge types specified:
      transform = RandomLinkSplit(edge_types=[("p", "p"), ("p", "a")])
      train_data, val_data, test_data = transform(data)
      assert train_data["p", "p"].num_edges < data["p", "p"].num_edges
      assert train_data["p", "a"].num_edges < data["p", "a"].num_edges
      assert train_data["a", "p"].num_edges == data["a", "p"].num_edges
  
file_path: pytorch_geometric/test/transforms/test_random_link_split.py
imports: import pytest
  import torch
  from torch_geometric.data import Data, HeteroData
  from torch_geometric.testing import get_random_edge_index, onlyFullTest, onlyOnline
  from torch_geometric.transforms import RandomLinkSplit
  from torch_geometric.utils import is_undirected, to_undirected
label_desc: Use image node_id 4 for calling a global function with example usage: test_random_link_split_on_hetero_data() without return types