code: def batch_iterator(
      inputs,
      targets=None,
      batch_size=None,
      shuffle=False,
      allow_smaller_batch=False,
      repeat=True,
  ):
      """A generator that provides batches of samples from the provided inputs."""
      if isinstance(inputs, set):
          inputs = np.asarray(list(inputs))
      if not isinstance(inputs, (np.ndarray, list)):
          raise TypeError(
              "Unsupported data type %s encountered." % type(inputs)
          )
      if targets is not None and not isinstance(
          targets, (np.ndarray, list)
      ):
          raise TypeError(
              "Unsupported data type %s encountered." % type(targets)
          )
      num_samples = len(inputs)
      if batch_size is None:
          batch_size = num_samples
      if batch_size > num_samples:
          allow_smaller_batch = True
      keep_going = True
      while keep_going:
          indexes = np.arange(0, num_samples)
          if shuffle:
              np.random.shuffle(indexes)
          shuffled_inputs = inputs[indexes]
          if targets is not None:
              shuffled_targets = targets[indexes]
          for start_index in range(0, num_samples, batch_size):
              if allow_smaller_batch:
                  end_index = min(start_index + batch_size, num_samples)
              else:
                  end_index = start_index + batch_size
                  if end_index > num_samples:
                      break
              batch_inputs = shuffled_inputs[start_index:end_index]
              if targets is None:
                  yield batch_inputs
              else:
                  batch_targets = shuffled_targets[
                      start_index:end_index
                  ]
                  yield batch_inputs, batch_targets
          if not repeat:
              keep_going = False
  
file_path: neural-structured-learning/research/gam/gam/trainer/trainer_base.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import abc
  import numpy
  import tensorflow
label_desc: Use image node_id 1 for calling a global function with example usage: batch_iterator(inputs, targets, batch_size, shuffle, allow_smaller_batch, repeat) without return types