Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal for new class #36

Open
CrazyPython opened this issue Aug 19, 2016 · 4 comments
Open

Proposal for new class #36

CrazyPython opened this issue Aug 19, 2016 · 4 comments
Assignees

Comments

@CrazyPython
Copy link
Collaborator

CrazyPython commented Aug 19, 2016

This idea might be crazy, maybe, I don't know.

Currently, in order to add a progress bar to a classic for loop, they'd have to change something like this:

for (int i = 0; i < 10; ++i) {
    // ...
}

into this:

for (int i : trange(10)) {
    // ...
}

That might be a little bit of a hassle and might ruin the code's style in the eye of the user. So I propose a small class that lets you replace it with this:

for (tqdm::whatever i = 0; i < 10; ++i) {
    // ...
}

I wrote a little bit of code to this effect:

class twhatever {
    tqdm foo;
    int value;
 public:
    inline twhatever(int initial) {
        value = initial;
        foo = tqdm(initial);  // or whatever intialization
    }
    inline operator int() const {return value;}
    twhatever inline operator++ () {
        value++;
        foo.update(1);
        return *this;
    }
};

It implicitly converts to an integer (not usually good, but great in this case) and the ++ operator updates the bar. Add the other postfix/prefix decrement/increment, and it's good to go.

It would make implementing progress bars just that little bit easier.

My writing is a bit sloppy and came out in reverse. I think it's a good idea.

What do you guys think? And I can implement this myself if it is decided as such, it's a pretty simple task.

@CrazyPython CrazyPython self-assigned this Aug 19, 2016
@CrazyPython CrazyPython changed the title Idea on new class Proposal for new class Aug 19, 2016
@CrazyPython
Copy link
Collaborator Author

@o11c thoughts?

@CrazyPython
Copy link
Collaborator Author

I think this is a substantial improvement.

@CrazyPython
Copy link
Collaborator Author

@casperdcl ...

@casperdcl
Copy link
Sponsor Member

The problem with this is you don't give tqdm a total even though one is clearly available. That means no bar and eta

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants