code: def test_connected_component_labeling():
      """Tests if the connected component labeling algorithms on cpu and gpu yield the same result."""
  
      # generate batch of random binary images using perlin noise
      batch = torch.zeros((32, 1, 256, 256))
      for i in range(batch.shape[0]):
          batch[i, ...] = (
              random_2d_perlin(
                  (256, 256), (torch.tensor(4), torch.tensor(4))
              )
              > 0.5
          )
  
      # get connected component results on both cpu and gpu
      cc_cpu = connected_components_cpu(batch.cpu())
      cc_gpu = connected_components_gpu(batch.cuda())
  
      # check if comps are ordered from 0 to N
      assert len(cc_cpu.unique()) == cc_cpu.unique().max() + 1
      assert len(cc_gpu.unique()) == cc_gpu.unique().max() + 1
      # check if same number of comps found between cpu and gpu
      assert len(cc_cpu.unique()) == len(cc_gpu.unique())
  
file_path: anomalib/tests/pre_merge/utils/metrics/test_pro.py
imports: import torch
  from torch import Tensor
  from torchvision.transforms import RandomAffine
  from anomalib.data.utils import random_2d_perlin
  from anomalib.utils.metrics.pro import PRO, connected_components_cpu, connected_components_gpu
label_desc: Use image node_id 3 for calling a global function with example usage: test_connected_component_labeling() without return types