MCPcopy Create free account
hub / github.com/Pints-AI/1.5-Pints / CycleIterator

Class CycleIterator

lit_gpt/utils.py:413–441  ·  view source on GitHub ↗

An iterator that cycles through an iterable indefinitely. Example: >>> iterator = CycleIterator([1, 2, 3]) >>> [next(iterator) for _ in range(5)] [1, 2, 3, 1, 2] Note: Unlike ``itertools.cycle``, this iterator does not cache the values of the iterable.

Source from the content-addressed store, hash-verified

411
412
413class CycleIterator:
414 """An iterator that cycles through an iterable indefinitely.
415
416 Example:
417 >>> iterator = CycleIterator([1, 2, 3])
418 >>> [next(iterator) for _ in range(5)]
419 [1, 2, 3, 1, 2]
420
421 Note:
422 Unlike ``itertools.cycle``, this iterator does not cache the values of the iterable.
423 """
424
425 def __init__(self, iterable: Iterable) -> None:
426 self.iterable = iterable
427 self.epoch = 0
428 self._iterator = None
429
430 def __next__(self) -> Any:
431 if self._iterator is None:
432 self._iterator = iter(self.iterable)
433 try:
434 return next(self._iterator)
435 except StopIteration:
436 self._iterator = iter(self.iterable)
437 self.epoch += 1
438 return next(self._iterator)
439
440 def __iter__(self) -> Self:
441 return self
442
443
444def copy_config_files(source_dir: Path, out_dir: Path) -> None:

Callers 5

test_deita_e2eFunction · 0.90
test_slim_orca_idk_e2eFunction · 0.90
test_metamath_e2eFunction · 0.90
fitFunction · 0.90
trainFunction · 0.90

Calls

no outgoing calls

Tested by 3

test_deita_e2eFunction · 0.72
test_slim_orca_idk_e2eFunction · 0.72
test_metamath_e2eFunction · 0.72