clitic / kdam

A console progress bar library for Rust. (inspired by tqdm & rich.progress)
https://docs.rs/kdam
Apache License 2.0
196 stars 6 forks source link

Feature request: support rayon parallel iterators #10

Closed AlienKevin closed 1 year ago

AlienKevin commented 1 year ago

Thanks for developing this awesome crate! I tried it out in one of my projects and it worked out great. However, after I changed the iterator to be a Rayon parallel iterator, things doesn't work any more. I would like to discuss the possibility of introducing support for rayon parallel iterators in kdam.

Rayon, as you may know, is one of the most widely used solutions for data parallelism in Rust. Given its popularity and functionality, I believe it could significantly improve Kdam's utility. The parallel processing potential offered by rayon could greatly enhance the efficiency of tasks in Kdam, and thus extend its use-cases.

In addition, I noticed that the Python library tqdm provides the process_map and thread_map functions, and I was wondering if a similar implementation would be feasible in Kdam.

Taking advantage of Rust's traits system, could it be possible to add support for rayon via the existing macro syntax of tqdm! in kdam? Alternatively, would it be viable to create a new par_tqdm! macro that accepts a parallel iterator as an argument? Thanks.

clitic commented 1 year ago

Based on your suggestion I have added support for rayon parallel iterators. See, this example (requires rayon feature). I have also added par_tqdm macro. I think we don't require functions like process_map and thread_map because rayon will do that.