raffalib.itertools

Functions

batch_boundaries(total, n_per_batch)

Yield (batchi, start_ix, end_ix) tuples for batches of size n_per_batch.

Module Contents

raffalib.itertools.batch_boundaries(total, n_per_batch)

Yield (batchi, start_ix, end_ix) tuples for batches of size n_per_batch.

Parameters:
  • total (int) – Total number of items to batch.

  • n_per_batch (int) – Number of items per batch.

Returns:

An iterator of (batch_index, start_index, end_index) tuples where indices are 1-based.

Return type:

Iterator[tuple[int, int, int]]

Example:

>>> from raffalib.itertools import batch_boundaries
>>> list(batch_boundaries(20, 3))
[(0, 1, 3), (1, 4, 6), (2, 7, 9), (3, 10, 12), (4, 13, 15), (5, 16, 18), (6, 19, 20)]