code: def _test_stitching(device, dim, channel_first, dtype, interp):
      batch_size = 1 if dim == 3 else 10
      pipe = dali.pipeline.Pipeline(
          batch_size=batch_size,
          num_threads=1,
          device_id=0,
          seed=1234,
          prefetch_queue_depth=1,
      )
      with pipe:
          if dim == 2:
              files, labels = dali.fn.readers.caffe(
                  path=db_2d_folder, random_shuffle=True
              )
              images_cpu = dali.fn.decoders.image(files, device="cpu")
          else:
              images_cpu = dali.fn.external_source(
                  source=random_3d_loader(batch_size), layout="DHWC"
              )
  
          images_hwc = (
              images_cpu if device == "cpu" else images_cpu.gpu()
          )
  
          if channel_first:
              images = dali.fn.transpose(
                  images_hwc,
                  perm=[3, 0, 1, 2] if dim == 3 else [2, 0, 1],
                  transpose_layout=True,
              )
          else:
              images = images_hwc
  
          out_size_full = [32, 32, 32] if dim == 3 else [160, 160]
          out_size_half = [x // 2 for x in out_size_full]
  
          roi_start = [0] * dim
          roi_end = [1] * dim
  
          resized = fn.resize(
              images,
              dtype=dtype,
              min_filter=interp,
              mag_filter=interp,
              size=out_size_full,
          )
  
          outputs = [resized]
  
          for z in range(dim - 1):
              if dim == 3:
                  roi_start[0] = z * 0.5
                  roi_end[0] = (z + 1) * 0.5
              for y in [0, 1]:
                  roi_start[-2] = y * 0.5
                  roi_end[-2] = (y + 1) * 0.5
                  for x in [0, 1]:
                      roi_start[-1] = x * 0.5
                      roi_end[-1] = (x + 1) * 0.5
  
                      part = fn.resize(
                          images,
                          dtype=dtype,
                          interp_type=interp,
                          size=out_size_half,
                          roi_start=roi_start,
                          roi_end=roi_end,
                          roi_relative=True,
                      )
                      outputs.append(part)
  
          pipe.set_outputs(*outputs)
  
      pipe.build()
      for iter in range(1):
          out = pipe.run()
          if device == "gpu":
              out = [x.as_cpu() for x in out]
          whole = out[0]
          tiled = []
          for i in range(batch_size):
              slices = []
              for z in range(dim - 1):
                  q00 = out[1 + z * 4 + 0].at(i)
                  q01 = out[1 + z * 4 + 1].at(i)
                  q10 = out[1 + z * 4 + 2].at(i)
                  q11 = out[1 + z * 4 + 3].at(i)
                  if channel_first:
                      slices.append(np.block([[q00, q01], [q10, q11]]))
                  else:
                      slices.append(
                          np.block([[[q00], [q01]], [[q10], [q11]]])
                      )
              if dim == 3:
                  if channel_first:
                      tiled.append(
                          np.block([[[slices[0]]], [[slices[1]]]])
                      )
                  else:
                      tiled.append(
                          np.block([[[[slices[0]]]], [[[slices[1]]]]])
                      )
              else:
                  tiled.append(slices[0])
          max_err = 1e-3 if type == types.FLOAT else 1
          check_batch(
              tiled,
              whole,
              batch_size,
              1e-4,
              max_err,
              compare_layouts=False,
          )
  
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 17 for calling a global function with example usage: _test_stitching(device, dim, channel_first, dtype, interp) without return types