-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix MERGE_M2 for extreme finite partial means #22393
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
Merged
+177
−5
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c12348e
Fix merge M2 with extreme finite partial means
wjxiz1992 8b781d9
Test: parametrize extreme-finite cases over count type and assert ful…
wjxiz1992 c331016
Merge branch 'main' into fix/14681-merge-m2-extreme
wjxiz1992 071266d
Test: pin identity-branch behavior for NaN and +Inf partial means
wjxiz1992 f49c069
Merge branch 'main' into fix/14681-merge-m2-extreme
wjxiz1992 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
yes but what if the input mean is literally infinity? or it's a NaN? then it should return NaN right? You should also check std::isfinite() here. Or am I misunderstanding what merge m2 is trying to do.
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.
Walking through the cases:
partial_avg = +Inf(withpartial_n > 0): the identity branch propagatesavg = +Inf,m2 = partial_m2as-is. The old generic path produced NaN here viadelta * delta_n * n * partial_n = +Inf * +Inf * 0 * partial_n = inf*0— sameinf*0=NaNside effect this PR is fixing. Propagating +Inf preserves the upstream "overflowed" signal; coercing to NaN would discard it.partial_avg = NaN: identity setsavg = NaN; any subsequent merge step propagates NaN through the generic formula (NaN ⊕ anything = NaN). Final result is NaN regardless of partial position, as expected.In practice Spark's
CentralMomentAggdoesn't emit(count, +Inf, m2_finite)partials — Welford hits+Inf - +Inf = NaNon the first overflowing row, so the partial becomes(count, NaN, NaN). So the "+Inf avg" case really only shows up for direct callers ofMERGE_M2with hand-crafted partials, and for those propagation is strictly more informative than coercion.I pushed 5d917711 (now 071266d after rebase) with regression tests pinning these semantics:
NanMeanFirstPartial,InfMeanFirstPartial, andNanMeanMergedWithFinitefor both INT64 and FLOAT64 count types. Let me know if there's a Spark scenario where NaN coercion is actually wanted — I'm not seeing one.