code: def affine(
      img: Tensor,
      matrix: List[float],
      interpolation: str = "nearest",
      fill: Optional[Union[int, float, List[float]]] = None,
  ) -> Tensor:
      _assert_grid_transform_inputs(
          img, matrix, interpolation, fill, ["nearest", "bilinear"]
      )
  
      dtype = (
          img.dtype if torch.is_floating_point(img) else torch.float32
      )
      theta = torch.tensor(
          matrix, dtype=dtype, device=img.device
      ).reshape(1, 2, 3)
      shape = img.shape
      # grid will be generated on the same device as theta and img
      grid = _gen_affine_grid(
          theta, w=shape[-1], h=shape[-2], ow=shape[-1], oh=shape[-2]
      )
      return _apply_grid_transform(img, grid, interpolation, fill=fill)
  
imports: import warnings
  from typing import List, Optional, Tuple, Union
  import torch
  from torch import Tensor
  from torch.nn.functional import conv2d, grid_sample, interpolate, pad
label_desc: Use image node_id 30 for calling a global function with example usage: affine(img, matrix, interpolation, fill) and returns: _apply_grid_transform