code: def stream_shuffle_generator(
      generator, batch_size, shuffle_size=20000
  ):
      """
      Args:
          generator: iterable dataset
  
          batch_size: int
  
          shuffle_size: int
  
      """
      buffer_list = []
      batch_data = []
      for examples in generator():
          if not isinstance(examples, list):
              examples = [examples]
  
          for data in examples:
              if len(buffer_list) < shuffle_size:
                  buffer_list.append(data)
              else:
                  idx = np.random.randint(0, len(buffer_list))
                  batch_data.append(buffer_list[idx])
                  buffer_list[idx] = data
  
                  if len(batch_data) >= batch_size:
                      yield batch_data
                      batch_data = []
  
      if len(batch_data) > 0:
          yield batch_data
  
      if len(buffer_list) > 0:
          np.random.shuffle(buffer_list)
          start = 0
          while True:
              batch_data = buffer_list[start : (start + batch_size)]
              start += batch_size
              if len(batch_data) > 0:
                  yield batch_data
              else:
                  break
  
file_path: PGL/apps/Graph4Rec/env_run/src/datasets/helper.py
imports: import os
  import sys
  import time
  import warnings
  import queue
  import numpy
  import threading
  import collections
label_desc: Use image node_id 1 for calling a global function with example usage: stream_shuffle_generator(generator, batch_size, shuffle_size) without return types