def test_connected_component_labeling() -> None:
    """Tests if the connected component labeling algorithms on cpu and gpu yield the same result.

    Note: This test will only run on a GPU-enabled device.
    """
    # 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, ...] = generate_perlin_noise(256, 256, scale=(4, 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())
Tests if the connected component labeling algorithms on cpu and gpu yield the same result.

    Note: This test will only run on a GPU-enabled device.
    
tests/unit/metrics/test_pro.py