code: def checked_cast_to_tuple(typ: Tuple[Type[V], ...], val: V) -> T:
      """
      Cast a value to a union of multiple types (with a runtime safety check).
      This function is similar to `checked_cast`, but allows for the type to be
      defined as a tuple of types, in which case the value is cast as a union of
      the types in the tuple.
  
      Args:
          typ: the tuple of types to cast to
          val: the value that we are casting
      Returns:
          the ``val`` argument, unchanged
      """
      if not isinstance(val, typ):
          raise ValueError(f"Value was not of type {type!r}:\n{val!r}")
      # pyre-fixme[7]: Expected `T` but got `V`.
      return val
  
file_path: Ax/ax/utils/common/typeutils.py
imports: from inspect import signature
  from typing import Any, Dict, List, Optional, Tuple, Type, TypeVar
  import numpy
  from typeguard import check_type
label_desc: Use image node_id 6 for calling a global function with example usage: checked_cast_to_tuple(typ, val) and returns: val