Repository navigation
Fix histogram producing wrong results for small unsorted inputs - #105548
Conversation
`compress` had an early return (`size <= max_bins`) before sorting, introduced in #85760. This meant `unique`, which assumes sorted data, operated on unsorted points when the number of values was within the bin limit, incorrectly merging non-adjacent bins. Move the sort block before the early return so data is always sorted before `unique` runs, matching the original behavior. Closes #103109 Co-Authored-By: Claude Opus 4.6 <[email protected]>
|
Workflow [PR], commit [4455091] Summary: ✅ AI ReviewSummaryThis PR fixes Final Verdict
|
`sorted_prefix` was updated before the early return (`size <= max_bins`), but `last_inserted` was not. This left `last_inserted` stale after sorting, which could cause a subsequent `add` to incorrectly increment `sorted_prefix` (because `last_inserted <= value` would hold for a value that is not actually greater than the new last element of the sorted array). A later `compress` would then rely on a wrong `sorted_prefix` and skip sorting or use invalid `inplace_merge` assumptions, producing wrong histogram bins. Co-Authored-By: Claude Opus 4.6 <[email protected]>
LLVM Coverage Report
Changed lines: 100.00% (9/9) | lost baseline coverage: 1 line(s) · Uncovered code |
|
Hi — could this be a backport candidate for Affected code: Why this might apply: The bug exists in 26.1+ where the sorted_prefix optimization was introduced. Verified by checking upstream/26.2, upstream/26.3, upstream/26.4 - all have the early return before sorting. Branch 25.8 is NOT affected (it calls sort() before the early return check). This is a wrong results bug affecting a commonly used aggregate function. Other supported branches ( Caveat: I verified that the modified code exists in those branches, but not whether the bug is actually reachable there — a new caller in master may be what makes this newly observable. If older branches can't reach the affected path, please ignore this; otherwise consider |
|
Hi @Avogar @alexey-milovidov — a couple of suggestions to make this PR easier for reviewers and the changelog reader. Description (currently
Ignore this if the current title/body is intentional. |
…sorted-input Fix `histogram` producing wrong results for small unsorted inputs
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix
histogramproducing wrong results for small unsorted inputs. Closes #103109