5 ms·
How would it know how long a loop is ahead of time? Is this solving the halting problem?
by mrfusion 5y ago
How would it know how long a loop is ahead of time? Is this solving the halting problem?
- nostoc 5y agoHave you ever used a for loop? You don't know how long it'll take, but you know how many iterations, and at any given point you can know how long past iterations have taken. Extrapolation is not hard, even if not always accurate.
- cowsandmilk 5y agoThere are plenty of for loops in which you don’t know how many iterations you will have. With a generator, it can even be infinite.
- berkes 5y agoIn which case the visualisation will adjust and show this fact. E.g. passing an unbounded range will jus show some info about the past iterations.
- formerly_proven 5y agoThis is not how for loops work in Python, which does not have ranged loops. The example works because range objects implement __len__ which is where tqdm will get it's total/count information from.
- wedn3sday 5y agoFor things with a fixed length, it looks it up ahead of time (i.e. things that return things when you call len() on them). For other things such as generators, you can supply a total=N value when you create the progress bar. If you dont know the total ahead of time, it doesnt give you a percent completion, but still tells you thinks like number of iterations per second and number of iterations finished.
- geofft 5y agoThe halting problem is easy to solve most of the time. For instance, you can easily tell whether the following two programs halt: while True: pass while False: pass What's impossible is solving the halting problem 100% of the time with 100% accuracy. Most people don't need to do that. Solving the halting problem most of the time and then saying "I don't know, that's too hard" the rest of the time is of immense practical value, and many practical systems (the kernel's eBPF verifier, the thing in your browser that detects stuck pages, etc.) do exactly that. In this particular case, tqdm solves the halting problem in cases where it's easy: https://tqdm.github.io/docs/tqdm/#__init__ https://tqdm.github.io/docs/tqdm/#__init__ > total: int or float, optional > The number of expected iterations. If unspecified, len(iterable) is used if possible. If float("inf") or as a last resort, only basic progress statistics are displayed (no ETA, no progressbar).
- deleted 5y ago[deleted]