code: def _apply_to_sample(func, sample, *args, nest_with_sample=0):
      """Apply to a sample traversing the nesting of the data (tuple/list).
  
      Parameters
      ----------
      func : callable
          Function to be applied to every sample data object
      sample : sample object or any nesting of those in tuple/list
          Representation of sample
      nest_with_sample: int
          Specify how many consecutive (additional) arguments have the same level of nesting
          as the sample.
      """
      if isinstance(
          sample,
          (
              tuple,
              list,
          ),
      ):
          # Check that all the samples have common nesting
          for i in range(nest_with_sample):
              assert len(args[i]) == len(sample)
          nest_group = sample, *args[0:nest_with_sample]
          scalar_args = args[nest_with_sample:]
          return type(sample)(
              _apply_to_sample(func, *part, *scalar_args)
              for part in zip(*nest_group)
          )
      else:
          # we unpacked all nesting levels, now is actual data:
          return func(sample, *args)
  
imports: import os
  from nvidia.dali._multiproc import shared_mem
  from nvidia.dali._multiproc.messages import ShmMessageDesc
  from nvidia.dali._utils.external_source_impl import assert_cpu_sample_data_type, sample_to_numpy
  import pickle
label_desc: Use image node_id 8 for calling a global function with example usage: _apply_to_sample(func, sample) and returns: type, func