Replace std::random_shuffle with std::shuffle in tests for objdetect#22228
Conversation
| // Use manually constructed RNG and std::shuffle instead. | ||
| std::random_device rand_dev; | ||
| // Use Mersenne Twister RNG. | ||
| std::mt19937 rand_gen {rand_dev()}; |
There was a problem hiding this comment.
OpenCV tests should be reproducible (otherwise we would have random failures which no-one could debug).
So we should not use "true" random input.
We should use pseudo-random generators with reproducible results.
Initial code was incorrect too.
Prefer to reuse cv::randShuffle() over CV_8U data.
There was a problem hiding this comment.
Is manually seeding the PRNG to a fixed initial state acceptable? Shuffling std::string with cv::randShuffle seems to require more obscure code.
There was a problem hiding this comment.
Done. Also manually seeded and tested legacy call to std::random_shuffle (although I don't know if it is the most suitable way to do so).
There was a problem hiding this comment.
Minor mistakes corrected in code; it should work now.
2ec5a41 to
991d116
Compare
- Add conditional compilation directives to replace deprecated std::random_shuffle with new std::shuffle when C++11 is available. - Set random seed to a fixed value before shuffling containers to ensure reproducibility. Resolves opencv#22209.
991d116 to
3135063
Compare
|
@alalek, would you mind re-approving the Actions workflows? The previous run failed due to some typos in my code, which have been fixed already in the latest commit. Thanks! |
|
Thank you for merging this! Could you please close #22209 as well? |
std::random_shufflewith two arguments is deprecated since C++11 and removed since C++17. This PR adds conditional compilation directives to replace it with the recommendedstd::shuffle(together with manually-constructed RNGs) when C++11 is available in the test files forobjdetectmodule.Resolves #22209.
Pull Request Readiness Checklist
Patch to opencv_extra has the same branch name.