code: def _test_ND(
      device,
      dim,
      batch_size,
      channel_first,
      mode,
      interp,
      dtype,
      w_input,
      h_input,
      d_input,
      use_size_arg,
      use_size_input,
      use_roi,
  ):
      dali_pipe, pil_pipe = build_pipes(
          device,
          dim,
          batch_size,
          channel_first,
          mode,
          interp,
          dtype,
          w_input,
          h_input,
          d_input,
          use_size_arg,
          use_size_input,
          use_roi,
      )
  
      first_spatial_dim = 1 if channel_first else 0
  
      max_iters = 3
  
      for iter in range(max_iters):
          o = dali_pipe.run()
          output_idx = 0
  
          def get_outputs(n):
              nonlocal output_idx
              start = output_idx
              output_idx += n
              return o[start:output_idx]
  
          def get_output():
              return get_outputs(1)[0]
  
          dali_in, dali_out = get_outputs(2)
          if use_roi:
              roi_start, roi_end = (
                  np.array(x.as_tensor(), dtype=np.float32)
                  for x in get_outputs(2)
              )
          else:
              roi_end = np.stack(
                  [
                      dali_in[i].shape()[
                          first_spatial_dim : first_spatial_dim + dim
                      ]
                      for i in range(batch_size)
                  ]
              ).astype(np.float32)
              roi_start = np.zeros([batch_size, dim], dtype=np.float32)
          if use_size_arg:
              size = np.array(get_output().as_tensor(), np.float32)
          else:
              size = np.stack(
                  [x.as_tensor() for x in get_outputs(dim)], axis=1
              )
  
          roi_size = roi_end - roi_start
  
          dali_out_size = np.stack(
              [
                  dali_out[i].shape()[
                      first_spatial_dim : first_spatial_dim + dim
                  ]
                  for i in range(batch_size)
              ]
          )
  
          for i in range(batch_size):
              ref_size = ref_output_size(
                  mode, size[i], roi_size[i], max_size(dim)
              )
              real_size = dali_out_size[i]
              max_err = np.max(np.abs(ref_size - real_size))
              eps = 0.6  # allow for rounding errors - we'll use _real_ size when resizing with PIL
              if max_err > eps:
                  print("Invalid output size!")
                  print(dali_out[i].shape())
                  print("Got:      ", real_size)
                  print("Expected: ", ref_size)
                  print("RoI", roi_size[i])
                  print("Input size", dali_in[i].shape())
                  print("Requested output", size[i])
                  assert max_err <= eps
  
          ref_in = dali_in
          if isinstance(ref_in, dali.tensors.TensorListGPU):
              ref_in = ref_in.as_cpu()  # suppress warnings
          pil_pipe.feed_input(
              "images", ref_in, layout=layout_str(dim, channel_first)
          )
          pil_pipe.feed_input("size", dali_out_size)
          pil_pipe.feed_input("roi_start", roi_start)
          pil_pipe.feed_input("roi_end", roi_end)
          ref = pil_pipe.run()
  
          dali_resized = o[1]
          if isinstance(dali_resized, dali.tensors.TensorListGPU):
              dali_resized = dali_resized.as_cpu()
          ref_resized = ref[0]
  
          max_avg_err = 0.6 if dim == 3 else 0.4
          max_err = 12 if dim == 3 else 10
          if interp == types.INTERP_LANCZOS3:
              max_err *= 2
  
          dali_interior = [
              interior(x, channel_first) for x in dali_resized
          ]
          ref_interior = [
              interior(x, channel_first) for x in ref_resized
          ]
          check_batch(
              dali_interior,
              ref_interior,
              batch_size,
              max_avg_err,
              max_err,
          )
  
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 11 for calling a global function with example usage: _test_ND(device, dim, batch_size, channel_first, mode, interp, dtype, w_input, h_input, d_input, use_size_arg, use_size_input, use_roi) and returns: o, get_outputs