-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Uniformize Interface of Random Generators in Math #12410
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
base: master
Are you sure you want to change the base?
Conversation
Can one of the admins verify this patch? |
@phsft-bot build |
Starting build on |
DO not understand clang-format failure. |
Build failed on mac12/noimt. Warnings:
|
did the mac build fail because of the warnings? |
Build failed on windows10/cxx14. Errors:
|
Build failed on ROOT-debian10-i386/soversion. Warnings:
|
My 2 cents: |
#ifdef _WIN64 | ||
static constexpr uint64_t kNumberOfBits = _popcount64(Generator::max()); | ||
#else | ||
static constexpr uint64_t kNumberOfBits = __builtin_popcountll(Generator::max()); | ||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not particularly happy about using builtins in the header. Is there no other way to get this information from the C++ type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in c++20 there is a std:;popcount.
There are generators that return 48 or 61 bits. so it is not just numeric_limits<Return_type>::bits()
p.s. I agree that mixing clang-format and changes is not ideal and I do try to avoid it.
I did not expect it to make so many changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We may argue that kNumberOfBits
is redundant and could be defined in the user code (if needed)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fine with me. Also, there may be generators that don't have a max()
that falls on a power-of-two (LCGs come to mind)
#ifdef _WIN64 | ||
static_assert(Engine::kNumberOfBits == _popcount64(Engine::MaxInt()), "MaxInt inconsistent with kNumberOfBits"); | ||
#else | ||
static_assert(Engine::kNumberOfBits == __builtin_popcountll(Engine::MaxInt()), | ||
"MaxInt inconsistent with kNumberOfBits"); | ||
static_assert(64 - Engine::kNumberOfBits == __builtin_clzll(Engine::MaxInt()), | ||
"MaxInt inconsistent with kNumberOfBits"); | ||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do these tests provide additional coverage? You're already testing above that (~0ULL) >> (64 - Engine::kNumberOfBits) == Engine::MaxInt()
. Counting that there are exactly Engine::kNumberOfBits
set is a weaker check, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just verify that the expression is indeed constexpr.
Build failed on mac11/cxx14. Warnings:
|
Changes or fixes:
added/modified MinInt, MaxInt, IntRndm.
added test of Integer interface
Checklist: