code: def _interleave(
      lists, cycle_length, block_length, num_parallel_calls=None
  ):
      """Reference implementation of interleave used for testing.
  
      Args:
        lists: a list of lists to interleave
        cycle_length: the length of the interleave cycle
        block_length: the length of the interleave block
        num_parallel_calls: the number of parallel calls
  
      Yields:
        Elements of `lists` interleaved in the order determined by `cycle_length`
        and `block_length`.
      """
      num_open = 0
  
      # `all_iterators` acts as a queue of iterators over each element of `lists`.
      all_iterators = [iter(l) for l in lists]
  
      # `open_iterators` are the iterators whose elements are currently being
      # interleaved.
      open_iterators = []
      if cycle_length is None:
          # The logic here needs to match interleave C++ kernels.
          cpu_count = multiprocessing.cpu_count()
          if hasattr(os, "sched_getaffinity"):
              try:
                  cpu_count = len(os.sched_getaffinity(0))
              except NotImplementedError:
                  pass
          if num_parallel_calls is None:
              cycle_length = cpu_count
          elif num_parallel_calls == dataset_ops.AUTOTUNE:
              cycle_length = (cpu_count + 2) // 3
          else:
              cycle_length = min(num_parallel_calls, cpu_count)
  
      for i in range(cycle_length):
          if all_iterators:
              open_iterators.append(all_iterators.pop(0))
              num_open += 1
          else:
              open_iterators.append(None)
  
      while num_open or all_iterators:
          for i in range(cycle_length):
              if open_iterators[i] is None:
                  if all_iterators:
                      open_iterators[i] = all_iterators.pop(0)
                      num_open += 1
                  else:
                      continue
              for _ in range(block_length):
                  try:
                      yield next(open_iterators[i])
                  except StopIteration:
                      open_iterators[i] = None
                      num_open -= 1
                      break
  
imports: import multiprocessing
  import os
  from absl.testing import parameterized
  import numpy
  from tensorflow.python.data.experimental.ops import testing
  from tensorflow.python.data.kernel_tests import checkpoint_test_base
  from tensorflow.python.data.kernel_tests import test_base
  from tensorflow.python.data.ops import dataset_ops
  from tensorflow.python.data.ops import options
  from tensorflow.python.framework import combinations
  from tensorflow.python.framework import errors
  from tensorflow.python.framework import sparse_tensor
  from tensorflow.python.ops import array_ops
  from tensorflow.python.ops import math_ops
  from tensorflow.python.ops import sparse_ops
  from tensorflow.python.platform import test
label_desc: Use image node_id 1 for calling a global function with example usage: _interleave(lists, cycle_length, block_length, num_parallel_calls) without return types