spdl.source.utils.embed_shuffle

embed_shuffle(src: IterableWithShuffle[T], /, *, shuffle_last: bool = False, epoch: int = 0) Iterable[T][source]

[Experimental] Convert IterableWithShuffle to Iterable by embedding the shuffle() call into __iter__().

Roughly equivalent to the following code snippet.

while True:
     if not shuffle_last:
         src.shuffle(seed=epoch)

     yield from src
     epoch += 1

     if shuffle_last:
         src.shuffle(seed=epoch)
Parameters:
  • src – The original iterable with shuffle method.

  • shuffle_last – If False (default), then shuffle is called before the iteration. Other wise shuffle is called at the end of iteration.

  • epoch – The initial seed value passed to shuffle().