ertk.utils.batch_iterable

ertk.utils.batch_iterable(it: Iterable[T], batch_size: int, return_last: bool = True) Iterable[Tuple[T, ...]]

Batches an iterable into chunks of size batch_size.

Parameters:
it: iterable

The iterable to batch.

batch_size: int

The size of each batch/chunk.

return_last: bool

Whether to yield the last batch if it isn’t full (i.e. batch_size doesn’t divide the iterable length.)

Yields:
tuple

A tuple of length batch_size with successive elements from the original iterable. If return_last == False then the last batch is dropped if it contains less than batch_size items.