code: def test_dataloader_with_imbalanced_sampler():
      data_list: List[Data] = []
      for _ in range(10):
          data_list.append(Data(num_nodes=10, y=0))
      for _ in range(90):
          data_list.append(Data(num_nodes=10, y=1))
  
      torch.manual_seed(12345)
      sampler = ImbalancedSampler(data_list)
      loader = DataLoader(data_list, batch_size=10, sampler=sampler)
  
      y = torch.cat([batch.y for batch in loader])
  
      histogram = y.bincount()
      prob = histogram / histogram.sum()
  
      assert histogram.sum() == len(data_list)
      assert prob.min() > 0.4 and prob.max() < 0.6
  
      # Test with label tensor as input:
      torch.manual_seed(12345)
      sampler = ImbalancedSampler(
          torch.tensor([data.y for data in data_list])
      )
      loader = DataLoader(data_list, batch_size=10, sampler=sampler)
  
      assert torch.allclose(y, torch.cat([batch.y for batch in loader]))
  
      # Test with list of data objects as input where each y is a tensor:
      torch.manual_seed(12345)
      for data in data_list:
          data.y = torch.tensor([data.y])
      sampler = ImbalancedSampler(data_list)
      loader = DataLoader(data_list, batch_size=100, sampler=sampler)
  
      assert torch.allclose(y, torch.cat([batch.y for batch in loader]))
  
file_path: pytorch_geometric/test/loader/test_imbalanced_sampler.py
imports: from typing import List
  import torch
  from torch_geometric.data import Data
  from torch_geometric.datasets import FakeDataset, FakeHeteroDataset
  from torch_geometric.loader import DataLoader, ImbalancedSampler, NeighborLoader
  from torch_geometric.testing import onlyNeighborSampler
label_desc: Use image node_id 1 for calling a global function with example usage: test_dataloader_with_imbalanced_sampler() without return types