def new_epoch(batch_index, batch_size, num_examples):
  """Returns true if a new epoch occurs during batch number batch_index."""
  min_batch_index = batch_index * batch_size
  max_batch_index = (batch_index + 1) * batch_size - 1
  return ((min_batch_index %
           num_examples) == 0) or ((min_batch_index % num_examples) >
                                   (max_batch_index % num_examples))