code: def _perspective_grid(
      coeffs: List[float],
      ow: int,
      oh: int,
      dtype: torch.dtype,
      device: torch.device,
  ) -> Tensor:
      # https://github.com/python-pillow/Pillow/blob/4634eafe3c695a014267eefdce830b4a825beed7/
      # src/libImaging/Geometry.c#L394
  
      #
      # x_out = (coeffs[0] * x + coeffs[1] * y + coeffs[2]) / (coeffs[6] * x + coeffs[7] * y + 1)
      # y_out = (coeffs[3] * x + coeffs[4] * y + coeffs[5]) / (coeffs[6] * x + coeffs[7] * y + 1)
      #
      theta1 = torch.tensor(
          [
              [
                  [coeffs[0], coeffs[1], coeffs[2]],
                  [coeffs[3], coeffs[4], coeffs[5]],
              ]
          ],
          dtype=dtype,
          device=device,
      )
      theta2 = torch.tensor(
          [[[coeffs[6], coeffs[7], 1.0], [coeffs[6], coeffs[7], 1.0]]],
          dtype=dtype,
          device=device,
      )
  
      d = 0.5
      base_grid = torch.empty(1, oh, ow, 3, dtype=dtype, device=device)
      x_grid = torch.linspace(
          d, ow * 1.0 + d - 1.0, steps=ow, device=device
      )
      base_grid[..., 0].copy_(x_grid)
      y_grid = torch.linspace(
          d, oh * 1.0 + d - 1.0, steps=oh, device=device
      ).unsqueeze_(-1)
      base_grid[..., 1].copy_(y_grid)
      base_grid[..., 2].fill_(1)
  
      rescaled_theta1 = theta1.transpose(1, 2) / torch.tensor(
          [0.5 * ow, 0.5 * oh], dtype=dtype, device=device
      )
      output_grid1 = base_grid.view(1, oh * ow, 3).bmm(rescaled_theta1)
      output_grid2 = base_grid.view(1, oh * ow, 3).bmm(
          theta2.transpose(1, 2)
      )
  
      output_grid = output_grid1 / output_grid2 - 1.0
      return output_grid.view(1, oh, ow, 2)
  
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 33 for calling a global function with example usage: _perspective_grid(coeffs, ow, oh, dtype, device) and returns: output_grid