code: def test_ill_affine_transform(self):
      with self.assertRaises(ValueError):  # image too small
          t = np.pi / 3
          affine = [
              [1, 0, 0, 0],
              [0.0, np.cos(t), -np.sin(t), 0],
              [0, np.sin(t), np.cos(t), 0],
              [0, 0, 0, 1],
          ]
          affine = torch.as_tensor(
              affine, device=torch.device("cpu:0"), dtype=torch.float32
          )
          xform = AffineTransform(
              (3, 4, 2),
              padding_mode="border",
              align_corners=False,
              mode="bilinear",
          )
          xform(torch.as_tensor([1.0, 2.0, 3.0]), affine)
  
      with self.assertRaises(ValueError):  # output shape too small
          t = np.pi / 3
          affine = [
              [1, 0, 0, 0],
              [0.0, np.cos(t), -np.sin(t), 0],
              [0, np.sin(t), np.cos(t), 0],
              [0, 0, 0, 1],
          ]
          affine = torch.as_tensor(
              affine, device=torch.device("cpu:0"), dtype=torch.float32
          )
          image = (
              torch.arange(48)
              .view(2, 1, 4, 2, 3)
              .to(device=torch.device("cpu:0"))
          )
          xform = AffineTransform(
              (3, 4),
              padding_mode="border",
              align_corners=False,
              mode="bilinear",
          )
          xform(image, affine)
  
      with self.assertRaises(ValueError):  # incorrect affine
          t = np.pi / 3
          affine = [
              [1, 0, 0, 0],
              [0.0, np.cos(t), -np.sin(t), 0],
              [0, np.sin(t), np.cos(t), 0],
              [0, 0, 0, 1],
          ]
          affine = torch.as_tensor(
              affine, device=torch.device("cpu:0"), dtype=torch.float32
          )
          affine = affine.unsqueeze(0).unsqueeze(0)
          image = (
              torch.arange(48)
              .view(2, 1, 4, 2, 3)
              .to(device=torch.device("cpu:0"))
          )
          xform = AffineTransform(
              (2, 3, 4),
              padding_mode="border",
              align_corners=False,
              mode="bilinear",
          )
          xform(image, affine)
  
      with self.assertRaises(ValueError):  # batch doesn't match
          t = np.pi / 3
          affine = [
              [1, 0, 0, 0],
              [0.0, np.cos(t), -np.sin(t), 0],
              [0, np.sin(t), np.cos(t), 0],
              [0, 0, 0, 1],
          ]
          affine = torch.as_tensor(
              affine, device=torch.device("cpu:0"), dtype=torch.float32
          )
          affine = affine.unsqueeze(0)
          affine = affine.repeat(3, 1, 1)
          image = (
              torch.arange(48)
              .view(2, 1, 4, 2, 3)
              .to(device=torch.device("cpu:0"))
          )
          xform = AffineTransform(
              (2, 3, 4),
              padding_mode="border",
              align_corners=False,
              mode="bilinear",
          )
          xform(image, affine)
  
      with self.assertRaises(
          RuntimeError
      ):  # input grid dtypes different
          t = np.pi / 3
          affine = [
              [1, 0, 0, 0],
              [0.0, np.cos(t), -np.sin(t), 0],
              [0, np.sin(t), np.cos(t), 0],
              [0, 0, 0, 1],
          ]
          affine = torch.as_tensor(
              affine, device=torch.device("cpu:0"), dtype=torch.float32
          )
          affine = affine.unsqueeze(0)
          affine = affine.repeat(2, 1, 1)
          image = (
              torch.arange(48)
              .view(2, 1, 4, 2, 3)
              .to(device=torch.device("cpu:0"), dtype=torch.int32)
          )
          xform = AffineTransform(
              (2, 3, 4),
              padding_mode="border",
              mode="bilinear",
              normalized=True,
          )
          xform(image, affine)
  
      with self.assertRaises(ValueError):  # wrong affine
          affine = torch.as_tensor([[1, 0, 0, 0], [0, 0, 0, 1]])
          image = (
              torch.arange(48)
              .view(2, 1, 4, 2, 3)
              .to(device=torch.device("cpu:0"))
          )
          xform = AffineTransform(
              (2, 3, 4),
              padding_mode="border",
              align_corners=False,
              mode="bilinear",
          )
          xform(image, affine)
  
      with self.assertRaises(RuntimeError):  # dtype doesn't match
          affine = torch.as_tensor(
              [[2.0, 0.0, 0.0], [0.0, 2.0, 0.0]], dtype=torch.float64
          )
          image = (
              torch.arange(1.0, 13.0)
              .view(1, 1, 3, 4)
              .to(device=torch.device("cpu:0"))
          )
          AffineTransform((1, 2))(image, affine)
  
imports: from __future__ import annotations
  import unittest
  import numpy
  import torch
  from parameterized import parameterized
  from monai.networks import normalize_transform, to_norm_affine
  from monai.networks.layers import AffineTransform
  from tests.utils import is_tf32_env
label_desc: Use image node_id 11 for calling the TestAffineTransform obj's underlying member method code with example usage: obj.test_ill_affine_transform() without return types