code: def _rgb_to_hsv(image: torch.Tensor) -> torch.Tensor:
      r, g, _ = image.unbind(dim=-3)
  
      # Implementation is based on
      # https://github.com/python-pillow/Pillow/blob/4174d4267616897df3746d315d5a2d0f82c656ee/src/libImaging/Convert.c#L330
      minc, maxc = torch.aminmax(image, dim=-3)
  
      # The algorithm erases S and H channel where `maxc = minc`. This avoids NaN
      # from happening in the results, because
      #   + S channel has division by `maxc`, which is zero only if `maxc = minc`
      #   + H channel has division by `(maxc - minc)`.
      #
      # Instead of overwriting NaN afterwards, we just prevent it from occurring so
      # we don't need to deal with it in case we save the NaN in a buffer in
      # backprop, if it is ever supported, but it doesn't hurt to do so.
      eqc = maxc == minc
  
      channels_range = maxc - minc
      # Since `eqc => channels_range = 0`, replacing denominator with 1 when `eqc` is fine.
      ones = torch.ones_like(maxc)
      s = channels_range / torch.where(eqc, ones, maxc)
      # Note that `eqc => maxc = minc = r = g = b`. So the following calculation
      # of `h` would reduce to `bc - gc + 2 + rc - bc + 4 + rc - bc = 6` so it
      # would not matter what values `rc`, `gc`, and `bc` have here, and thus
      # replacing denominator with 1 when `eqc` is fine.
      channels_range_divisor = torch.where(
          eqc, ones, channels_range
      ).unsqueeze_(dim=-3)
      rc, gc, bc = (
          (maxc.unsqueeze(dim=-3) - image) / channels_range_divisor
      ).unbind(dim=-3)
  
      mask_maxc_neq_r = maxc != r
      mask_maxc_eq_g = maxc == g
  
      hg = rc.add(2.0).sub_(bc).mul_(mask_maxc_eq_g & mask_maxc_neq_r)
      hr = bc.sub_(gc).mul_(~mask_maxc_neq_r)
      hb = (
          gc.add_(4.0)
          .sub_(rc)
          .mul_(
              mask_maxc_neq_r.logical_and_(
                  mask_maxc_eq_g.logical_not_()
              )
          )
      )
  
      h = hr.add_(hg).add_(hb)
      h = h.mul_(1.0 / 6.0).add_(1.0).fmod_(1.0)
      return torch.stack((h, s, maxc), dim=-3)
  
imports: from typing import List
  import PIL.Image
  import torch
  from torch.nn.functional import conv2d
  from torchvision import tv_tensors
  from torchvision.transforms import _functional_pil
  from torchvision.transforms._functional_tensor import _max_value
  from torchvision.utils import _log_api_usage_once
  from ._misc import _num_value_bits, to_dtype_image
  from ._type_conversion import pil_to_tensor, to_pil_image
  from ._utils import _get_kernel, _register_kernel_internal
label_desc: Use image node_id 20 for calling a global function with example usage: _rgb_to_hsv(image) and returns: torch