code: def nested_map(
      fn: Callable,
      x: Union[ivy.Array, ivy.NativeArray, Iterable],
      /,
      include_derived: Optional[Union[Dict[str, bool], bool]] = None,
      to_ignore: Optional[Union[type, Tuple[type]]] = None,
      to_mutable: bool = False,
      _tuple_check_fn: Optional[Callable] = None,
      _list_check_fn: Optional[Callable] = None,
      _dict_check_fn: Optional[Callable] = None,
      shallow: bool = True,
  ) -> Union[ivy.Array, ivy.NativeArray, Iterable, Dict]:
      """Apply a function on x in a nested manner, whereby all dicts, lists and
      tuples are traversed to their lowest leaves before applying the method and
      returning x. If x is not nested, the method is applied to x directly.
  
      Parameters
      ----------
      fn
          The function to map onto x.
      x
          The item to apply the mapped function to.
      include_derived
          Whether to also recursive for classes derived from tuple, list and dict.
          Default is ``False``.
      to_ignore
          Types to ignore when deciding whether to go deeper into the nest or not
      to_mutable
          Whether to convert the nest to a mutable form, changing all tuples to lists.
          Default is ``False``.
      _tuple_check_fn
          Placeholder for the tuple check function, do not set this parameter.
      _list_check_fn
          Placeholder for the list check function, do not set this parameter.
      _dict_check_fn
          Placeholder for the dict check function, do not set this parameter.
      shallow
          Whether to inplace update the input nest or not
          Only works if nest is a mutable type. Default is ``True``.
  
      Returns
      -------
      ret
          x following the application of fn to it's nested leaves, or x itself if x is not
          nested.
  
      Examples
      --------
      With :class:`Tuple` inputs:
  
      >>> x = ([[1., 2.], [3., 4.]])
      >>> function = lambda a : a * 2
      >>> ivy.nested_map(function, x)
      [[2.0, 4.0], [6.0, 8.0]]
      >>> print(x)
      [[2.0, 4.0], [6.0, 8.0]]
  
      With :code:`Dict` input:
  
      >>> x = {1 : [1, [2, 3]], 2: (4, 5)}
      >>> function = lambda a : a + 1
      >>> ivy.nested_map(function, x)
      {1 : [2, [3, 4]], 2: (5, 6)}
      >>> print(x)
      {1 : [2, [3, 4]], 2: (5, 6)}
  
      With :code:`List` inputs:
  
      >>> x = [['a', 'b', 'c'],
      ...      ['d', 'e', 'f'],
      ...      ['g', ['h', 'i']]]
      >>> function = lambda a: a + 'H'
      >>> ivy.nested_map(function, x)
      [['aH','bH','cH'],['dH','eH','fH'],['gH',['hH','iH']]]
      >>> print(x)
      [['aH','bH','cH'],['dH','eH','fH'],['gH',['hH','iH']]]
  
      With :class:`ivy.Container` input:
  
      >>> x = ivy.Container(
      ...   a=ivy.array([[1, 2, 3], [9, 8, 7]]) , b=ivy.array([[4, 5, 6], [12, 13, 14]])
      ... )
      >>> function = lambda a : a  + 1
      >>> ivy.nested_map(function, x)
      {
          a: ivy.array([[2, 3, 4],
                        [10, 9, 8]]),
          b: ivy.array([[5, 6, 7],
                        [13, 14, 15]])
      }
      >>> print(x)
      {
          a: ivy.array([[2, 3, 4],
                        [10, 9, 8]]),
          b: ivy.array([[5, 6, 7],
                        [13, 14, 15]])
      }
  
      >>> nest = ([1, 2], [3, 4], [5, 6], {"a": 1, "b": 2, "c": 3})
      >>> function = lambda a :  a * 2
      >>> ivy.nested_map(function, nest, to_ignore=list)
      ([1, 2, 1, 2], [3, 4, 3, 4], [5, 6, 5, 6], {'a': 2, 'b': 4, 'c': 6})
  
      >>> nest = ([23, 25, 1337], [63, 98, 6])
      >>> function = lambda a :  a + 1
      >>> ivy.nested_map(function, nest, to_mutable=True)
      [[24, 25, 1338], [64, 99, 7]]
      """
      to_ignore = ivy.default(to_ignore, ())
      if include_derived is True:
          include_derived = {"tuple": True, "list": True, "dict": True}
      elif not include_derived:
          include_derived = {}
      for t in ("tuple", "list", "dict"):
          if t not in include_derived:
              include_derived[t] = False
      class_instance = type(x)
      # TODO: Fixes iterating over tracked instances from the graph
      # during transpilation. However, there might be a better fix
      # than this. Remove the check below if that's the case
      if (
          hasattr(x, "is_tracked_proxy")
          and hasattr(class_instance, "__bases__")
          and not set(class_instance.__bases__).intersection(
              set(to_ignore)
          )
      ):
          to_ignore += (class_instance,)
      tuple_check_fn = ivy.default(
          _tuple_check_fn,
          (
              (lambda x_, t_: isinstance(x_, t_))
              if include_derived["tuple"]
              else (lambda x_, t_: type(x_) is t_)
          ),
      )
      list_check_fn = ivy.default(
          _list_check_fn,
          (
              (lambda x_, t_: isinstance(x_, t_))
              if include_derived["list"]
              else (lambda x_, t_: type(x_) is t_)
          ),
      )
      dict_check_fn = ivy.default(
          _dict_check_fn,
          (
              (lambda x_, t_: isinstance(x_, t_))
              if include_derived["dict"]
              else (lambda x_, t_: type(x_) is t_)
          ),
      )
      if tuple_check_fn(x, tuple) and not isinstance(x, to_ignore):
          ret_list = [
              nested_map(
                  fn,
                  i,
                  include_derived,
                  to_ignore,
                  to_mutable,
                  tuple_check_fn,
                  list_check_fn,
                  dict_check_fn,
                  shallow,
              )
              for i in x
          ]
          if to_mutable:
              return ret_list
          elif hasattr(x, "_fields"):
              # noinspection PyProtectedMember
              return class_instance(**dict(zip(x._fields, ret_list)))
          else:
              return class_instance(ret_list)
      elif list_check_fn(x, list) and not isinstance(x, to_ignore):
          ret_list = [
              nested_map(
                  fn,
                  i,
                  include_derived,
                  to_ignore,
                  to_mutable,
                  tuple_check_fn,
                  list_check_fn,
                  dict_check_fn,
                  shallow,
              )
              for i in x
          ]
          if shallow:
              x[:] = ret_list[:]
              return x
          return class_instance(ret_list)
      elif (
          dict_check_fn(x, dict) or isinstance(x, UserDict)
      ) and not isinstance(x, to_ignore):
          class_instance = type(x)
          ret = {
              k: nested_map(
                  fn,
                  v,
                  include_derived,
                  to_ignore,
                  to_mutable,
                  tuple_check_fn,
                  list_check_fn,
                  dict_check_fn,
                  shallow,
              )
              for k, v in x.items()
          }
          if shallow:
              x.update(ret)
              return x
          return class_instance(ret)
      elif isinstance(x, slice):
          # TODO: add tests for this
          return slice(*nested_map(fn, [x.start, x.stop, x.step]))
      return fn(x)
  
imports: from builtins import map
  from typing import Callable, Any, Union, List, Tuple, Optional, Dict, Iterable, Sequence
  from collections import UserDict, OrderedDict
  import ivy
  from ivy.utils.exceptions import handle_exceptions
label_desc: Use image node_id 14 for calling a global function with example usage: nested_map(include_derived, to_ignore, to_mutable, _tuple_check_fn, _list_check_fn, _dict_check_fn, shallow) and returns: fn, ret_list, class_instance, class_instance, class_instance, x, class_instance, x, slice