code: def KORNIA_CHECK_TYPE(
      x: object,
      typ: T | tuple[T, ...],
      msg: Optional[str] = None,
      raises: bool = True,
  ) -> TypeGuard[T]:
      """Check the type of an aribratry variable.
  
      Args:
          x: any input variable.
          typ: the expected type of the variable.
          msg: message to show in the exception.
          raises: bool indicating whether an exception should be raised upon failure.
  
      Raises:
          TypeException: if the input variable does not match with the expected and raises is True.
  
      Example:
          >>> KORNIA_CHECK_TYPE("foo", str, "Invalid string")
          True
      """
      # TODO: Move to use typeguard here dropping support for JIT
      if not isinstance(x, typ):
          if raises:
              raise TypeError(f"Invalid type: {type(x)}.\n{msg}")
          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 4 for calling a global function with example usage: KORNIA_CHECK_TYPE(x, typ, msg, raises) and returns: True, False