code: def keypoint_flip(
      keypoint: KeypointInternalType, d: int, rows: int, cols: int
  ) -> KeypointInternalType:
      """Flip a keypoint either vertically, horizontally or both depending on the value of `d`.
  
      Args:
          keypoint: A keypoint `(x, y, angle, scale)`.
          d: Number of flip. Must be -1, 0 or 1:
              * 0 - vertical flip,
              * 1 - horizontal flip,
              * -1 - vertical and horizontal flip.
          rows: Image height.
          cols: Image width.
  
      Returns:
          A keypoint `(x, y, angle, scale)`.
  
      Raises:
          ValueError: if value of `d` is not -1, 0 or 1.
  
      """
      if d == 0:
          keypoint = keypoint_vflip(keypoint, rows, cols)
      elif d == 1:
          keypoint = keypoint_hflip(keypoint, rows, cols)
      elif d == -1:
          keypoint = keypoint_hflip(keypoint, rows, cols)
          keypoint = keypoint_vflip(keypoint, rows, cols)
      else:
          raise ValueError(
              f"Invalid d value {d}. Valid values are -1, 0 and 1"
          )
      return keypoint
  
imports: import math
  from typing import List, Optional, Sequence, Tuple, Union
  import cv2
  import numpy
  import skimage.transform
  from scipy.ndimage import gaussian_filter
  from albumentations.augmentations.utils import _maybe_process_in_chunks, angle_2pi_range, clipped, preserve_channel_dim, preserve_shape
  from ...None import random_utils
  from ...core.bbox_utils import denormalize_bbox, normalize_bbox
  from ...core.transforms_interface import BoxInternalType, FillValueType, ImageColorType, KeypointInternalType
label_desc: Use image node_id 45 for calling a global function with example usage: keypoint_flip(keypoint, d, rows, cols) and returns: keypoint