code: def _test_external_source_callback(
      use_fn_api, batch, as_tensor, device
  ):
      iter_num = 5
      batch_size = 9
      pipe = Pipeline(batch_size, 3, 0)
  
      # this should produce a single Tensor / TensorList per batch,
      # not wrapped in additional list
      source = TestIterator(iter_num, batch_size, 4, device == "gpu")
  
      iter_in = (
          iter(source) if batch else iter(SampleIterator(iter(source)))
      )
  
      if use_fn_api:
          input = fn.external_source(
              lambda: next(iter_in), device=device, batch=batch
          )
      else:
          ext_source = ops.ExternalSource(
              lambda: next(iter_in), device=device, batch=batch
          )
          input = ext_source()
      pipe.set_outputs(input)
      pipe.build()
  
      run_and_check(pipe, source)
  
imports: import functools
  import numpy
  import nvidia.dali.fn
  import nvidia.dali.ops
  from nvidia.dali import Pipeline
  from nose_utils import assert_raises
  from test_utils import check_output
label_desc: Use image node_id 9 for calling a global function with example usage: _test_external_source_callback(use_fn_api, batch, as_tensor, device) without return types