code: def test_homo_link_neighbor_loader_basic(
      device, subgraph_type, neg_sampling_ratio, filter_per_worker
  ):
      pos_edge_index = get_random_edge_index(50, 50, 500, device=device)
      neg_edge_index = get_random_edge_index(50, 50, 500, device=device)
      neg_edge_index += 50
  
      input_edges = torch.cat([pos_edge_index, neg_edge_index], dim=-1)
      edge_label = torch.cat(
          [
              torch.ones(500, device=device),
              torch.zeros(500, device=device),
          ],
          dim=0,
      )
  
      data = Data()
  
      data.edge_index = pos_edge_index
      data.x = torch.arange(100, device=device)
      data.edge_attr = torch.arange(500, device=device)
  
      loader = LinkNeighborLoader(
          data,
          num_neighbors=[-1] * 2,
          batch_size=20,
          edge_label_index=input_edges,
          edge_label=edge_label if neg_sampling_ratio is None else None,
          subgraph_type=subgraph_type,
          neg_sampling_ratio=neg_sampling_ratio,
          shuffle=True,
          filter_per_worker=filter_per_worker,
      )
  
      assert str(loader) == "LinkNeighborLoader()"
      assert len(loader) == 1000 / 20
  
      batch = loader([0])
      assert isinstance(batch, Data)
      assert int(input_edges[0, 0]) in batch.n_id.tolist()
      assert int(input_edges[1, 0]) in batch.n_id.tolist()
  
      for batch in loader:
          assert isinstance(batch, Data)
  
          assert batch.n_id.size() == (batch.num_nodes,)
          assert batch.e_id.size() == (batch.num_edges,)
          assert batch.x.device == device
          assert batch.x.size(0) <= 100
          assert batch.x.min() >= 0 and batch.x.max() < 100
          assert batch.input_id.numel() == 20
          assert batch.edge_index.device == device
          assert batch.edge_index.min() >= 0
          assert batch.edge_index.max() < batch.num_nodes
          assert batch.edge_attr.device == device
          assert batch.edge_attr.min() >= 0
          assert batch.edge_attr.max() < 500
  
          if neg_sampling_ratio is None:
              assert batch.edge_label_index.size(1) == 20
  
              # Assert positive samples are present in the original graph:
              edge_index = unique_edge_pairs(batch.edge_index)
              edge_label_index = batch.edge_label_index[
                  :, batch.edge_label == 1
              ]
              edge_label_index = unique_edge_pairs(edge_label_index)
              assert len(edge_index | edge_label_index) == len(
                  edge_index
              )
  
              # Assert negative samples are not present in the original graph:
              edge_index = unique_edge_pairs(batch.edge_index)
              edge_label_index = batch.edge_label_index[
                  :, batch.edge_label == 0
              ]
              edge_label_index = unique_edge_pairs(edge_label_index)
              assert len(edge_index & edge_label_index) == 0
  
          else:
              assert batch.edge_label_index.size(1) == 40
              assert torch.all(batch.edge_label[:20] == 1)
              assert torch.all(batch.edge_label[20:] == 0)
  
          # Ensure local `edge_label_index` correctly maps to input edges.
          global_edge_label_index = batch.n_id[batch.edge_label_index]
          global_edge_label_index = global_edge_label_index[
              :, batch.edge_label >= 1
          ]
          global_edge_label_index = unique_edge_pairs(
              global_edge_label_index
          )
          assert len(
              global_edge_label_index & unique_edge_pairs(input_edges)
          ) == len(global_edge_label_index)
  
file_path: pytorch_geometric/test/loader/test_link_neighbor_loader.py
imports: import pytest
  import torch
  from torch_geometric.data import Data, HeteroData
  from torch_geometric.loader import LinkNeighborLoader
  from torch_geometric.testing import MyFeatureStore, MyGraphStore, get_random_edge_index, onlyNeighborSampler, withCUDA, withPackage
label_desc: Use image node_id 2 for calling a global function with example usage: test_homo_link_neighbor_loader_basic(device, subgraph_type, neg_sampling_ratio, filter_per_worker) without return types