code: def copy_nest(
      nest: Union[ivy.Array, ivy.NativeArray, Iterable],
      /,
      include_derived: bool = False,
      to_mutable: bool = False,
  ) -> Union[ivy.Array, ivy.NativeArray, Iterable]:
      """Copy a nest deeply, but without copying leaves of the nest, only the
      nest lists, tuples and dicts are copied.
  
      Parameters
      ----------
      nest
          The nest to copy.
      include_derived
          Whether to also recursive for classes derived from tuple, list and dict.
          Default is ``False``.
      to_mutable
          Whether to convert the nest to a mutable form, changing all tuples to lists.
          Default is ``False``.
  
      Returns
      -------
      ret
          The copied nest.
  
      Examples
      --------
      With :class:`ivy.Array` input:
  
      >>> nest = ivy.array([[1.,2.,3.],[7.,8.,9.]])
      >>> copied_nest = ivy.copy_nest(nest)
      >>> print(copied_nest)
      ivy.array([[1., 2., 3.],
              [7., 8., 9.]])
  
      With :code:`Iterable` input:
  
      >>> nest = [[1, 2, 3, 4, 5], [23, 24, 25, 26, 27]]
      >>> copied_nest = ivy.copy_nest(nest, include_derived = True)
      >>> print(copied_nest)
      [[1, 2, 3, 4, 5], [23, 24, 25, 26, 27]]
  
      >>> nest = ([23, 25, 1337], [63, 98, 6])
      >>> copied_nest = ivy.copy_nest(nest, to_mutable = True)
      >>> print(copied_nest)
      [[23, 25, 1337], [63, 98, 6]]
  
      >>> nest = {'first': [23., 24., 25], 'second': [46., 48., 50]}
      >>> copied_nest = ivy.copy_nest(nest)
      >>> print(copied_nest)
      {'first': [23.0, 24.0, 25], 'second': [46.0, 48.0, 50]}
      """
      class_instance = type(nest)
      check_fn = (
          (lambda x_, t: isinstance(nest, t))
          if include_derived
          else (lambda x_, t: type(nest) is t)
      )
      if check_fn(nest, tuple):
          ret_list = [
              copy_nest(
                  i,
                  include_derived=include_derived,
                  to_mutable=to_mutable,
              )
              for i in nest
          ]
          if to_mutable:
              return ret_list
          if hasattr(nest, "_fields"):
              return class_instance(**dict(zip(nest._fields, ret_list)))
          return class_instance(tuple(ret_list))
      elif check_fn(nest, list):
          return class_instance(
              [
                  copy_nest(
                      i,
                      include_derived=include_derived,
                      to_mutable=to_mutable,
                  )
                  for i in nest
              ]
          )
      elif check_fn(nest, dict):
          class_instance = type(nest)
          dict_ = {
              k: copy_nest(
                  v,
                  include_derived=include_derived,
                  to_mutable=to_mutable,
              )
              for k, v in nest.items()
          }
          if isinstance(nest, OrderedDict):
              return class_instance(**dict_)
          return class_instance(dict_)
      return nest
  
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 16 for calling a global function with example usage: copy_nest(include_derived, to_mutable) and returns: nest, class_instance, ret_list, class_instance, class_instance, class_instance, class_instance