code: def test_device_consistency():
      """Test if the pro metric yields the same results between cpu and gpu."""
  
      transform = RandomAffine(5, None, (0.95, 1.05), 5)
  
      batch = torch.zeros((32, 256, 256))
      for i in range(batch.shape[0]):
          batch[i, ...] = (
              random_2d_perlin(
                  (256, 256), (torch.tensor(4), torch.tensor(4))
              )
              > 0.5
          )
      # ground truth mask is int type
      batch = batch.type(torch.int32)
  
      preds = transform(batch)
  
      pro_cpu = PRO()
      pro_gpu = PRO()
  
      pro_cpu.update(preds.cpu(), batch.cpu())
      pro_gpu.update(preds.cuda(), batch.cuda())
  
      assert torch.isclose(pro_cpu.compute(), pro_gpu.compute().cpu())
  
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 2 for calling a global function with example usage: test_device_consistency() without return types