class_docstr: Test collation for of random transformations with prob == 0 and 1.
docstr: transform, collate_fn, ndim
docstr_tok: ["transform",",","collate_fn",",","ndim"]
code: def test_collation(self, _, transform, collate_fn, ndim):
      """transform, collate_fn, ndim"""
      data = self.data_3d if ndim == 3 else self.data_2d
      if collate_fn:
          modified_transform = transform
      else:
          modified_transform = Compose(
              [transform, ResizeWithPadOrCropd(KEYS, 100)]
          )
  
      # num workers = 0 for mac or gpu transforms
      num_workers = (
          0
          if sys.platform != "linux" or torch.cuda.is_available()
          else 2
      )
  
      dataset = CacheDataset(
          data, transform=modified_transform, progress=False
      )
      loader = DataLoader(
          dataset,
          num_workers,
          batch_size=self.batch_size,
          collate_fn=collate_fn,
      )
  
      for item in loader:
          if isinstance(item, dict):
              np.testing.assert_array_equal(
                  item["image"].shape, item["label"].shape
              )
              continue
          d = decollate_batch(item)
          self.assertTrue(len(d) <= self.batch_size)
          for b in d:
              self.assertTrue(isinstance(b["image"], MetaTensor))
              np.testing.assert_array_equal(
                  b["image"].applied_operations[-1]["orig_size"],
                  b["label"].applied_operations[-1]["orig_size"],
              )
              np.testing.assert_array_equal(
                  b["image"]
                  .applied_operations[-1]
                  .get("_do_transform"),
                  b["label"]
                  .applied_operations[-1]
                  .get("_do_transform"),
              )
  
file_path: MONAI/tests/test_inverse_collation.py
imports: from __future__ import annotations
  import sys
  import unittest
  from typing import TYPE_CHECKING
  import numpy
  import torch
  from parameterized import parameterized
  from monai.data import CacheDataset, DataLoader, MetaTensor, create_test_image_2d, create_test_image_3d, decollate_batch, pad_list_data_collate
  from monai.transforms import Compose, EnsureChannelFirstd, Flipd, LoadImaged, RandAffined, RandAxisFlipd, RandFlipd, RandRotate90d, RandRotated, RandZoomd, ResizeWithPadOrCropd, Rotated
  from monai.utils import optional_import, set_determinism
  from tests.utils import make_nifti_image
label_desc: Use image node_id 3 for calling the TestInverseCollation obj's underlying member method code with example usage: obj.test_collation(_, transform, collate_fn, ndim) without return types