code: def test_rand_affined(
      self, input_param, input_data, expected_val, track_meta
  ):
      set_track_meta(track_meta)
      g = RandAffined(**input_param).set_random_state(123)
      call_param = {"data": input_data}
      res = g(**call_param)
      # test lazy
      if track_meta and input_data["img"].ndim in (3, 4):
          if "mode" not in input_param.keys():
              input_param["mode"] = "bilinear"
          if not isinstance(input_param["keys"], str):
              input_param["mode"] = ensure_tuple_rep(
                  input_param["mode"], len(input_param["keys"])
              )
          lazy_init_param = input_param.copy()
          for key, mode in zip(
              input_param["keys"], input_param["mode"]
          ):
              lazy_init_param["keys"], lazy_init_param["mode"] = (
                  key,
                  mode,
              )
              resampler = RandAffined(
                  **lazy_init_param
              ).set_random_state(123)
              expected_output = resampler(**call_param)
              test_resampler_lazy(
                  resampler,
                  expected_output,
                  lazy_init_param,
                  call_param,
                  seed=123,
                  output_key=key,
              )
          resampler.lazy = False
  
      if input_param.get("cache_grid", False):
          self.assertTrue(g.rand_affine._cached_grid is not None)
      for key in res:
          if isinstance(key, str) and key.endswith("_transforms"):
              continue
          result = res[key]
          if track_meta:
              self.assertIsInstance(result, MetaTensor)
              self.assertEqual(len(result.applied_operations), 1)
          expected = (
              expected_val[key]
              if isinstance(expected_val, dict)
              else expected_val
          )
          assert_allclose(
              result, expected, rtol=_rtol, atol=1e-3, type_test=False
          )
  
      g.set_random_state(4)
      res = g(**call_param)
      if not track_meta:
          return
  
      # affine should be tensor because the resampler only supports pytorch backend
      if (
          isinstance(res["img"], MetaTensor)
          and "extra_info" in res["img"].applied_operations[0]
      ):
          if not res["img"].applied_operations[-1]["extra_info"]:
              return
          if not res["img"].applied_operations[-1]["extra_info"][
              "extra_info"
          ]["do_resampling"]:
              return
          affine_img = res["img"].applied_operations[0]["extra_info"][
              "extra_info"
          ]["affine"]
          affine_seg = res["seg"].applied_operations[0]["extra_info"][
              "extra_info"
          ]["affine"]
          assert_allclose(affine_img, affine_seg, rtol=_rtol, atol=1e-3)
  
      res_inv = g.inverse(res)
      for k, v in res_inv.items():
          self.assertIsInstance(v, MetaTensor)
          self.assertEqual(len(v.applied_operations), 0)
          self.assertTupleEqual(v.shape, input_data[k].shape)
  
file_path: MONAI/tests/test_rand_affined.py
imports: from __future__ import annotations
  import itertools
  import unittest
  import numpy
  import torch
  from parameterized import parameterized
  from monai.data import MetaTensor, set_track_meta
  from monai.transforms import RandAffined
  from monai.utils import GridSampleMode, ensure_tuple_rep
  from tests.lazy_transforms_utils import test_resampler_lazy
  from tests.utils import assert_allclose, is_tf32_env
label_desc: Use image node_id 1 for calling the TestRandAffined obj's underlying member method code with example usage: obj.test_rand_affined(input_param, input_data, expected_val, track_meta) without return types