code: def test_decode_png(img_path, pil_mode, mode):
      with Image.open(img_path) as img:
          if pil_mode is not None:
              img = img.convert(pil_mode)
          img_pil = torch.from_numpy(np.array(img))
  
      img_pil = normalize_dimensions(img_pil)
  
      if img_path.endswith("16.png"):
          # 16 bits image decoding is supported, but only as a private API
          # FIXME: see https://github.com/pytorch/vision/issues/4731 for potential solutions to making it public
          with pytest.raises(
              RuntimeError,
              match="At most 8-bit PNG images are supported",
          ):
              data = read_file(img_path)
              img_lpng = decode_image(data, mode=mode)
  
          img_lpng = _read_png_16(img_path, mode=mode)
          assert img_lpng.dtype == torch.int32
          # PIL converts 16 bits pngs in uint8
          img_lpng = torch.round(img_lpng / (2**16 - 1) * 255).to(
              torch.uint8
          )
      else:
          data = read_file(img_path)
          img_lpng = decode_image(data, mode=mode)
  
      tol = 0 if pil_mode is None else 1
  
      if PILLOW_VERSION >= (8, 3) and pil_mode == "LA":
          # Avoid checking the transparency channel until
          # https://github.com/python-pillow/Pillow/issues/5593#issuecomment-878244910
          # is fixed.
          # TODO: remove once fix is released in PIL. Should be > 8.3.1.
          img_lpng, img_pil = img_lpng[0], img_pil[0]
  
      torch.testing.assert_close(img_lpng, img_pil, atol=tol, rtol=0)
  
imports: import glob
  import io
  import os
  import sys
  from pathlib import Path
  import numpy
  import pytest
  import torch
  import torchvision.transforms.functional
  from common_utils import assert_equal, needs_cuda
  from PIL import __version__, Image
  from torchvision.io.image import _read_png_16, decode_image, decode_jpeg, decode_png, encode_jpeg, encode_png, ImageReadMode, read_file, read_image, write_file, write_jpeg, write_png
label_desc: Use image node_id 9 for calling a global function with example usage: test_decode_png(img_path, pil_mode, mode) without return types