code: def apply_to_type(
      x: Union[
          Any, collections.Sequence, collections.Mapping, str, bytes
      ],
      input_type: Union[Type, Tuple[Type[Any], Any]],
      func: Callable,
  ) -> Union[
      Any, collections.Sequence, collections.Mapping, str, bytes
  ]:
      """Apply a function on an object of `input_type` or mapping, or sequence of objects of `input_type`.
  
      Args:
          x: object or mapping or sequence.
          input_type: data type of ``x``.
          func: the function to apply on ``x``.
      """
      if isinstance(x, input_type):
          return func(x)
      if isinstance(x, (str, bytes)):
          return x
      if isinstance(x, collections.Mapping):
          return cast(Callable, type(x))(
              {
                  k: apply_to_type(sample, input_type, func)
                  for k, sample in x.items()
              }
          )
      if isinstance(x, tuple) and hasattr(x, "_fields"):  # namedtuple
          return cast(Callable, type(x))(
              *(apply_to_type(sample, input_type, func) for sample in x)
          )
      if isinstance(x, collections.Sequence):
          return cast(Callable, type(x))(
              [apply_to_type(sample, input_type, func) for sample in x]
          )
      raise TypeError(
          (
              f"x must contain {input_type}, dicts or lists; found {type(x)}"
          )
      )
  
imports: import collections.abc
  import functools
  import hashlib
  import logging
  import random
  import shutil
  import warnings
  from pathlib import Path
  from typing import Any, Callable, cast, Dict, List, Optional, TextIO, Tuple, Type, TypeVar, Union
  import torch
label_desc: Use image node_id 3 for calling a global function with example usage: apply_to_type(x, input_type, func) and returns: func, x, cast, cast, cast