-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
<random>: std::piecewise_linear_distribution incorrectly normalizes densities #1084
Comments
Hi @Cory-Kramer ! Thank you for your report! The bug will be fixed soon! I tried your code with applied the pull request: #1032 |
I've linked this to the PR (we can just keep this open until it's merged, instead of closing as @statementreply's PR is one of a few that I want to prioritize for review and merging for VS 2019 16.8 Preview 3. |
Any chance this bug fix will be merged into a 15.9.x patch release too? |
That seems extremely unlikely. From what I can tell, 15.9.x is receiving a small but steady stream of compiler backend fixes for silent bad codegen - such bugs are often regressions, sometimes hard to work around, and usually extremely hard to notice what situations might trigger them. While the behavior of the distribution here is incorrect at runtime (and thus this qualifies as silent bad codegen too), it's not a regression (the library has misbehaved for 10 years) and it is possible to notice when code is affected (grep for the identifier) and work around (e.g. use Boost.Random). For this reason, we haven't backported any library fixes to 15.9.x, although it isn't completely impossible. Basically if we tried to backport this, we'd have to (conceptually) stand in front of a panel of mega-bosses and explain to them why this is suddenly so bad that we need to risk destabilizing the product with a fix that might have unintended side effects - and for this bug the answer would be no. |
Describe the bug
A std::piecewise_linear_distribution is described as accepting discrete pairs of values and densities. The densities are normalized such that the distribution becomes valid (specifically the distribution integrates to 1.0).
Command-line test case
Expected behavior
In the above example Visual Studio will (incorrectly) output
whereas Clang and GCC will (correctly) output
In this example you can verify the distribution simply makes a triangle of area 1.0, which since the width is 5.0 (10.0 - 5.0) the second density value must be 0.4 for the area to sum to 1.0.
STL version
Microsoft Visual Studio Enterprise 2019
Version 16.6.5
Additional context
This bug was also reported to the Visual Studio Developer Community: https://developercommunity.visualstudio.com/content/problem/1125176/stdpiecewise-linear-distribution-incorrectly-norma.html
For context here is the relevant MSVC implementation related to this bug:
https://github.com/microsoft/STL/blob/master/stl/inc/random#L4829-L4854
and Clang's implementation:
https://github.com/llvm/llvm-project/blob/master/libcxx/include/random#L6568-L6590
The text was updated successfully, but these errors were encountered: