AnswerDotAI / AnswerDotAI/fastprogress
Is there a way to deal with variable sized iterables?
- Vorherrschende Sprache
- Jupyter Notebook
- Sterne
- 1.1k
- Forks
- 104
- Ø Merge
- 1 Min.
- Gemergte PRs (30 T.)
- 1
Beschreibung
The problem is this line:
`self.total = len(gen) if total is None else total`
That is executed at the beginning. But `len(gen)` might change throughout the iteration, but progress_bar just assumes it keeps still.
What I really want is to use a timer (so "train for 1 hour" instead of "train for so and so epochs").
```python
import time
class Timer:
def __init__(self, num_seconds):
self.num_seconds = num_seconds
self.i = None
def __len__(self):
if self.i is None: return 1
eps = 1e-7
t = time.time() - self.start
progress = t/num_seconds
return int((num_seconds*self.i)/(progress+eps)) # estimated size. Changes constantly.
def __iter__(self):
self.start = time.time()
self.i, t = 0, 0.0
while t <= self.num_seconds:
t = time.time() - self.start
self.i += 1
yield None
```
With this class, if you write
```python
for t in Timer(3.0):
# do stuff
```
it runs for 3 seconds. But it doesn't work with the `progress_bar` :(
Beitragsleitfaden
Rechercherichtung
Beginne damit, die Implementierung von progress_bar und die im Issue beschriebene Zeile `self.total = len(gen) if total is None else total` zu finden. Reproduziere anschließend das bereitgestellte Timer-Beispiel und ermittle dann, wie Iterables variabler Größe oder zeitbasierte Iteration dargestellt werden sollten; als erledigt gilt die Aufgabe, wenn die Fortschrittsanzeige diesen Anwendungsfall ohne die Annahme einer festen Länge verarbeiten kann.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- tooling
- Issue-Typ
- Feature
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 40/100