mirror of
https://github.com/open-thought/reasoning-gym.git
synced 2026-04-23 16:55:05 +00:00
feat: Add iterator support to ChainSum with size-respecting iteration
This commit is contained in:
parent
cfba2cb0d5
commit
7cce205c5d
2 changed files with 39 additions and 0 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue