code: def F_affine2d(x, matrix, center=True):
      """
      2D Affine image transform on torch Tensor
      """
      if matrix.dim() == 2:
          matrix = matrix.view(-1, 2, 3)
  
      A_batch = matrix[:, :, :2]
      if A_batch.size(0) != x.size(0):
          A_batch = A_batch.repeat(x.size(0), 1, 1)
      b_batch = matrix[:, :, 2].unsqueeze(1)
  
      # make a meshgrid of normal coordinates
      _coords = th_iterproduct(x.size(1), x.size(2))
      with torch.no_grad:
          coords = _coords.unsqueeze(0).repeat(x.size(0), 1, 1).float()
      if center:
          # shift the coordinates so center is the origin
          coords[:, :, 0] = coords[:, :, 0] - (x.size(1) / 2.0 + 0.5)
          coords[:, :, 1] = coords[:, :, 1] - (x.size(2) / 2.0 + 0.5)
  
      # apply the coordinate transformation
      new_coords = coords.bmm(
          A_batch.transpose(1, 2)
      ) + b_batch.expand_as(coords)
  
      if center:
          # shift the coordinates back so origin is origin
          new_coords[:, :, 0] = new_coords[:, :, 0] + (
              x.size(1) / 2.0 + 0.5
          )
          new_coords[:, :, 1] = new_coords[:, :, 1] + (
              x.size(2) / 2.0 + 0.5
          )
  
      # map new coordinates using bilinear interpolation
      x_transformed = F_bilinear_interp2d(x, new_coords)
  
      return x_transformed
  
file_path: pywick/pywick/functions/affine.py
imports: import torch
  import torch.nn.functional
  from ..utils import th_iterproduct, th_flatten
label_desc: Use image node_id 1 for calling a global function with example usage: F_affine2d(x, matrix, center) and returns: x_transformed