code: def default_device(
      device: Optional[Union[ivy.Device, ivy.NativeDevice]] = None,
      /,
      *,
      item: Optional[
          Union[list, tuple, dict, ivy.Array, ivy.NativeArray]
      ] = None,
      as_native: Optional[bool] = None,
  ) -> Union[ivy.Device, ivy.NativeDevice]:
      """Return the input device or the default device. If the as_native flag is
      set, the device will be converted to a native device. If the item is
      provided, the item's device is returned. If the device is not provided, the
      last default device is returned. If a default device has not been set, the
      first gpu is returned if available, otherwise the cpu is returned.
  
      Parameters
      ----------
      device
          The device to be returned or converted.
      item
          The item to get the device from.
      as_native
          Whether to convert the device to a native device.
  
      Returns
      -------
      ret
          Device handle or string.
  
      Examples
      --------
      >>> ivy.default_device()
      device(type='cpu')
  
      >>> ivy.default_device("gpu:0")
      'gpu:0'
  
      >>> ivy.default_device(item=[], as_native=False)
      'cpu'
  
      >>> ivy.default_device(item=(), as_native=True)
      device(type='cpu')
  
      >>> ivy.default_device(item={"a": 1}, as_native=True)
      device(type='cpu')
  
      >>> x = ivy.array([1., 2., 3.])
      >>> x = ivy.to_device(x, 'gpu:0')
      >>> ivy.default_device(item=x, as_native=True)
      device(type='gpu', id=0)
      """
      if ivy.exists(device):
          if as_native is True:
              return ivy.as_native_dev(device)
          elif as_native is False:
              return ivy.as_ivy_dev(device)
          return device
      as_native = ivy.default(as_native, False)
      if ivy.exists(item):
          if isinstance(item, (list, tuple, dict)) and len(item) == 0:
              pass
          elif ivy.is_array(item):
              return ivy.dev(item, as_native=as_native)
      global default_device_stack
      if not default_device_stack:
          ret = "cpu"
      else:
          ret = default_device_stack[-1]
      if as_native:
          return ivy.as_native_dev(ret)
      return ivy.as_ivy_dev(ret)
  
imports: import os
  import gc
  import abc
  import math
  import psutil
  import warnings
  import types
  from typing import Type, Optional, Tuple
  from typing import Union, Callable, Iterable, Any
  import ivy
  from ivy.func_wrapper import handle_out_argument, to_native_arrays_and_back, inputs_to_native_arrays, handle_nestable, handle_array_like_without_promotion, handle_backend_invalid
  from ivy.utils.exceptions import handle_exceptions
label_desc: Use image node_id 21 for calling a global function with example usage: default_device() and returns: ivy, device, ivy, ivy, ivy, ivy