code: def _run_test_stack(num_inputs, layout, ndim, axis, axis_name):
      num_iter = 3
      batch_size = 4
      if ndim is None:
          ndim = len(layout)
  
      ref_axis = axis if axis is not None else 0
      assert ref_axis >= -ndim and ref_axis <= ndim
  
      if axis_name:
          axis_pos = axis + ndim + 1 if axis < 0 else axis
          ref_layout = (
              layout[:axis_pos] + axis_name + layout[axis_pos:]
              if layout
              else axis_name
          )
      else:
          ref_layout = ""
  
      pipe = dali.pipeline.Pipeline(
          batch_size=batch_size, num_threads=3, device_id=0
      )
      with pipe:
          inputs = fn.external_source(
              input_generator(num_inputs, batch_size, ndim),
              num_outputs=num_inputs,
              layout=layout,
          )
          out_cpu = fn.stack(*inputs, axis=axis, axis_name=axis_name)
          out_gpu = fn.stack(
              *(x.gpu() for x in inputs), axis=axis, axis_name=axis_name
          )
          pipe.set_outputs(out_cpu, out_gpu, *inputs)
      pipe.build()
  
      for _ in range(num_iter):
          o_cpu, o_gpu, *inputs = pipe.run()
          ref = ref_stack(inputs, ref_axis)
          check_batch(
              o_cpu, ref, batch_size, eps=0, expected_layout=ref_layout
          )
          check_batch(
              o_gpu, ref, batch_size, eps=0, expected_layout=ref_layout
          )
  
file_path: DALI/dali/test/python/operator_1/test_join.py
imports: import nvidia.dali
  import nvidia.dali.fn
  import numpy
  import math
  from test_utils import check_batch
label_desc: Use image node_id 8 for calling a global function with example usage: _run_test_stack(num_inputs, layout, ndim, axis, axis_name) without return types