feat: Add iterator support to ChainSum with size-respecting iteration

This commit is contained in:
Andreas Koepf (aider) 2025-01-23 12:23:35 +01:00
parent cfba2cb0d5
commit 7cce205c5d
2 changed files with 39 additions and 0 deletions

View file

@ -72,6 +72,19 @@ class ChainSum:
}
}
def __iter__(self):
"""Make the dataset iterable"""
self._current_idx = 0
return self
def __next__(self):
"""Get next item in iteration"""
if self._current_idx >= self.config.size:
raise StopIteration
item = self[self._current_idx]
self._current_idx += 1
return item
def _generate_task(self, rng: random.Random, num_terms: int, min_value: int, max_value: int) -> tuple[str, int]:
"""Generate a chain sum task