fix: Ensure floating-point accuracy in hist
#22245
Open
+26
−26
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #22234
Two minor adjustments:
When user-supplied bins are provided, the slow path is always taken. This guarantees that the user's bins are always respected. The prior implementation attempted to detect if the bins were uniformly distributed using a heuristic, but that heuristic can be foiled, and we were bound to encounter an issue on this sometime in the future.
In the fast path (now only when
bin_count
is supplied), the index calculation might generate results > 1 ULP of the bin edges in some cases, resulting in an invalid index, as see in the linked issue. There, we have1.0 - 1e-17 == 1.0
:There is now a check to see whether the value should be moved to an adjacent bucket. This check encompasses a prior check, so performance should not be affected.