code: def ref_output_size(mode, requested_size, roi_size, max_size=None):
      """Returns ideal (non-rounded) output size that would result from the parameters.
      The result is not rounded, so we can check the real, rounded, value against this one and find
      rounding errors by setting epsilon <1."""
      roi_size = list(roi_size)
      dim = len(roi_size)
      if max_size is None:
          max_size = [math.inf] * dim
      elif not isinstance(max_size, (list, tuple, np.ndarray)):
          max_size = [max_size] * dim
      elif isinstance(max_size, np.ndarray) and max_size.shape == []:
          max_size = [float(max_size)] * dim
  
      if not isinstance(requested_size, (list, tuple, np.ndarray)):
          requested_size = [requested_size] * dim
      elif (
          isinstance(requested_size, np.ndarray)
          and requested_size.shape == []
      ):
          requested_size = [float(requested_size)] * dim
  
      requested_size = [abs(x) if x else None for x in requested_size]
      roi_size = [abs(x) for x in roi_size]
  
      if not any(requested_size):
          return roi_size
  
      if mode == "stretch":
          return [
              min(m, o or i)
              for o, i, m in zip(requested_size, roi_size, max_size)
          ]
      elif mode == "not_smaller":
          max_scale = 0
          for o, i in zip(requested_size, roi_size):
              if not o:
                  continue
              max_scale = max(max_scale, abs(o / i))
  
          for i in range(len(roi_size)):
              max_scale = min(max_scale, max_size[i] / abs(roi_size[i]))
  
          return [x * max_scale for x in roi_size]
      elif mode == "not_larger":
          min_scale = math.inf
          for o, i, m in zip(requested_size, roi_size, max_size):
              if not o:
                  min_scale = min(min_scale, m / i)
                  continue
              min_scale = min(min_scale, abs(min(m, o) / i))
  
          return [x * min_scale for x in roi_size]
      elif mode == "default" or mode is None:
          avg_scale = 1
          power = 0
          for o, i in zip(requested_size, roi_size):
              if o:
                  avg_scale *= abs(o / i)
                  power += 1
          if power == len(requested_size):
              return [
                  min(o, m) for o, m in zip(requested_size, max_size)
              ]
          if power > 1:
              avg_scale = math.pow(avg_scale, 1 / power)
          out = [
              min(m, o or avg_scale * i)
              for o, i, m in zip(requested_size, roi_size, max_size)
          ]
          return out
      else:
          raise ValueError("Invalid mode '{}'".format(mode))
  
imports: import cv2
  import functools
  import math
  import numpy
  import nvidia.dali
  import nvidia.dali.fn
  import nvidia.dali.types
  import os.path
  from nvidia.dali import Pipeline, pipeline_def
  from nvidia.dali.data_node import DataNode
  from test_utils import check_batch, get_dali_extra_path, as_array
  import PIL.Image
label_desc: Use image node_id 6 for calling a global function with example usage: ref_output_size(mode, requested_size, roi_size, max_size) and returns: roi_size, unknown, unknown, unknown, out, unknown