spdl.source.utils.repeat_source

repeat_source(src: Iterable[T] | IterableWithShuffle[T], /, epoch: int = 0) → Iterator[T][source]

Convert an iterable into an infinite iterator with optional shuffling.

Roughly equivalent to the following code snippet.

while True:
    if isinstance(src, IterableWithShuffle):
        src.shuffle(seed=epoch)
    yield from src
    epoch += 1
Parameters:
  • src – The source to repeat.

  • epoch – The epoch number to start with.

Changed in version 0.7.0: epoch now also controls the first shuffle seed.