code: def test_perspective_pil_vs_tensor(
      device, dims_and_points, dt, fill, fn
  ):
      if dt == torch.float16 and device == "cpu":
          # skip float16 on CPU case
          return
  
      data_dims, (spoints, epoints) = dims_and_points
  
      tensor, pil_img = _create_data(*data_dims, device=device)
      if dt is not None:
          tensor = tensor.to(dtype=dt)
  
      interpolation = NEAREST
      fill_pil = (
          int(fill[0]) if fill is not None and len(fill) == 1 else fill
      )
      out_pil_img = F.perspective(
          pil_img,
          startpoints=spoints,
          endpoints=epoints,
          interpolation=interpolation,
          fill=fill_pil,
      )
      out_pil_tensor = torch.from_numpy(
          np.array(out_pil_img).transpose((2, 0, 1))
      )
      out_tensor = fn(
          tensor,
          startpoints=spoints,
          endpoints=epoints,
          interpolation=interpolation,
          fill=fill,
      ).cpu()
  
      if out_tensor.dtype != torch.uint8:
          out_tensor = out_tensor.to(torch.uint8)
  
      num_diff_pixels = (
          out_tensor != out_pil_tensor
      ).sum().item() / 3.0
      ratio_diff_pixels = (
          num_diff_pixels / out_tensor.shape[-1] / out_tensor.shape[-2]
      )
      # Tolerance : less than 5% of different pixels
      assert ratio_diff_pixels < 0.05
  
imports: import colorsys
  import itertools
  import math
  import os
  from functools import partial
  from typing import Sequence
  import numpy
  import PIL.Image
  import pytest
  import torch
  import torchvision.transforms
  import torchvision.transforms._functional_pil
  import torchvision.transforms._functional_tensor
  import torchvision.transforms.functional
  from common_utils import _assert_approx_equal_tensor_to_pil, _assert_equal_tensor_to_pil, _create_data, _create_data_batch, _test_fn_on_batch, assert_equal, cpu_and_cuda, needs_cuda
  from torchvision.transforms import InterpolationMode
label_desc: Use image node_id 4 for calling a global function with example usage: test_perspective_pil_vs_tensor(device, dims_and_points, dt, fill, fn) without return types