AnswerDotAI / AnswerDotAI/fastprogress
Is there a way to deal with variable sized iterables?
- Lenguaje dominante
- Jupyter Notebook
- Estrellas
- 1.1k
- Forks
- 104
- Merge medio
- 1 min
- PR fusionados (30 d)
- 1
Descripción
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` :(
Guía de contribución
Línea de trabajo
Empieza localizando la implementación de progress_bar y la línea `self.total = len(gen) if total is None else total` descrita en el issue. Reproduce el ejemplo de Timer proporcionado y, después, determina cómo deberían representarse los iterables de tamaño variable o la iteración basada en tiempo; se considera terminado cuando la barra de progreso puede manejar ese caso de uso sin asumir una longitud fija.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- tooling
- Tipo de issue
- Nueva funcionalidad
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 40/100