code: def KORNIA_CHECK_SHAPE(
      x: Tensor, shape: list[str], raises: bool = True
  ) -> bool:
      """Check whether a tensor has a specified shape.
  
      The shape can be specified with a implicit or explicit list of strings.
      The guard also check whether the variable is a type `Tensor`.
  
      Args:
          x: the tensor to evaluate.
          shape: a list with strings with the expected shape.
          raises: bool indicating whether an exception should be raised upon failure.
  
      Raises:
          Exception: if the input tensor is has not the expected shape and raises is True.
  
      Example:
          >>> x = torch.rand(2, 3, 4, 4)
          >>> KORNIA_CHECK_SHAPE(x, ["B", "C", "H", "W"])  # implicit
          True
  
          >>> x = torch.rand(2, 3, 4, 4)
          >>> KORNIA_CHECK_SHAPE(x, ["2", "3", "H", "W"])  # explicit
          True
      """
      if "*" == shape[0]:
          shape_to_check = shape[1:]
          x_shape_to_check = x.shape[-len(shape) + 1 :]
      elif "*" == shape[-1]:
          shape_to_check = shape[:-1]
          x_shape_to_check = x.shape[: len(shape) - 1]
      else:
          shape_to_check = shape
          x_shape_to_check = x.shape
  
      if len(x_shape_to_check) != len(shape_to_check):
          if raises:
              raise TypeError(
                  f"{x} shape must be [{shape}]. Got {x.shape}"
              )
          else:
              return False
  
      for i in range(len(x_shape_to_check)):
          # The voodoo below is because torchscript does not like
          # that dim can be both int and str
          dim_: str = shape_to_check[i]
          if not dim_.isnumeric():
              continue
          dim = int(dim_)
          if x_shape_to_check[i] != dim:
              if raises:
                  raise TypeError(
                      f"{x} shape must be [{shape}]. Got {x.shape}"
                  )
              else:
                  return False
      return True
  
imports: from __future__ import annotations
  from typing import Any, Optional, Sequence, TypeVar, cast
  from torch import float16, float32, float64
  from typing_extensions import TypeGuard
  from kornia.core import Tensor
label_desc: Use image node_id 1 for calling a global function with example usage: KORNIA_CHECK_SHAPE(x, shape, raises) and returns: True, False, False