code: def test_inverse(self, device, recompute, align, scale_extent):
      img_t = torch.rand(
          (1, 10, 9, 8), dtype=torch.float32, device=device
      )
      affine = torch.tensor(
          [[0, 0, -1, 0], [1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 0, 1]],
          dtype=torch.float32,
          device="cpu",
      )
      meta = {"fname": "somewhere"}
      img = MetaTensor(img_t, affine=affine, meta=meta)
      tr = Spacing(
          pixdim=[1.1, 1.2, 0.9],
          recompute_affine=recompute,
          align_corners=align,
          scale_extent=scale_extent,
      )
      # check that image and affine have changed
      img = tr(img)
      self.assertNotEqual(img.shape, img_t.shape)
      l2_norm_affine = ((affine - img.affine) ** 2).sum() ** 0.5
      self.assertGreater(l2_norm_affine, 5e-2)
      # check that with inverse, image affine are back to how they were
      img = tr.inverse(img)
      self.assertEqual(img.applied_operations, [])
      self.assertEqual(img.shape, img_t.shape)
      l2_norm_affine = ((affine - img.affine) ** 2).sum() ** 0.5
      self.assertLess(l2_norm_affine, 5e-2)
  
file_path: MONAI/tests/test_spacing.py
imports: from __future__ import annotations
  import unittest
  import numpy
  import torch
  from parameterized import parameterized
  from monai.config import USE_COMPILED
  from monai.data.meta_obj import set_track_meta
  from monai.data.meta_tensor import MetaTensor
  from monai.data.utils import affine_to_spacing
  from monai.transforms import Spacing
  from monai.utils import fall_back_tuple
  from tests.lazy_transforms_utils import test_resampler_lazy
  from tests.utils import TEST_DEVICES, TEST_NDARRAYS_ALL, assert_allclose, skip_if_quick
label_desc: Use image node_id 3 for calling the TestSpacingCase obj's underlying member method code with example usage: obj.test_inverse(device, recompute, align, scale_extent) without return types