fix(tdigest): return max when the last centroid has weight 2 - #188
Open
jaideeppyne wants to merge 1 commit into
Open
jaideeppyne wants to merge 1 commit into
jaideeppyne wants to merge 1 commit into
Conversation
The right-tail division is 0/0 for that weight. Round the rank weight before subtracting it so arm64 does not fuse the multiply and skip the tail.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Quantile's right tail divides bylastWeight/2 - 1. That denominator is zero when the last centroid weighs 2, and the only rank that reaches the branch (one unit of weight below the total) has a zero numerator as well, so the result is NaN.Java and Rust already return the stored maximum in this case. This does the same.
The rank weight is also rounded before it is subtracted from the total. On arm64 the compiler otherwise fuses that multiply and subtract, skips the right tail, and returns a value past the maximum (40 for a sketch whose maximum is 20).
Tests:
go test ./tdigest/. The new case builds centroids of weight 10 and 2 and checksQuantile(11/12)is the maximum.