code: def _get_required_native_variables(xs, xs_grad_idxs):
      """Extract all required native variables from a nested structure."""
      # To make sure that only the required arrays are converted to native arrays
      xs = ivy.nested_map(
          ivy.to_ivy, xs, include_derived=True, shallow=False
      )
      if xs_grad_idxs is not None:
          xs_required = ivy.multi_index_nest(xs, xs_grad_idxs)
          ivy.nested_map(
              ivy.to_native, xs_required, include_derived=True
          )
          ivy.set_nest_at_indices(xs, xs_grad_idxs, xs_required)
      else:
          xs = ivy.nested_map(
              ivy.to_native, xs, include_derived=True, shallow=False
          )
  
      def map_fn(x):
          if ivy.is_native_array(x):
              return x
          return None
  
      # Extract all those required native arrays and None for all others
      xs = ivy.nested_map(
          map_fn,
          xs,
          include_derived=True,
          to_mutable=True,
          shallow=False,
      )
  
      # Prune all None values
      none_idxs = ivy.nested_argwhere(xs, lambda x: x is None)
      not _check_if_empty(none_idxs) and ivy.prune_nest_at_indices(
          xs, list(reversed(none_idxs))
      )
      xs = (
          xs
          if ivy.is_array(xs)
          else (
              xs.cont_prune_empty()
              if isinstance(xs, ivy.Container)
              else ivy.prune_empty(xs)
          )
      )
  
      # return a single array instead of a list if possible, otherwise return the nest
      if isinstance(xs, list) and len(xs) == 1:
          return xs[0]
      return xs
  
imports: from typing import Sequence, Union, Optional, Tuple, Callable
  import numpy
  import itertools
  import ivy
  from ivy.utils.backend import current_backend
  from ivy.func_wrapper import handle_array_function, inputs_to_ivy_arrays, to_native_arrays_and_back, handle_out_argument, handle_nestable, handle_array_like_without_promotion, handle_device, handle_backend_invalid
  from ivy.utils.exceptions import handle_exceptions
label_desc: Use image node_id 3 for calling a global function with example usage: _get_required_native_variables(xs, xs_grad_idxs) and returns: xs, None, xs, x