Conversation
This branch has not been deployed
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.
Summary
Clustering1D::train_exact()can lose precision in two intermediate calculations:double, butx * xis evaluated asfloatfirst. The rounded squared values can change the partition selected by the dynamic program when the input has a large common offset.float. For example, a single cluster of 128 identical1000001.0fvalues currently returns1000000.125finstead of1000001.0f.Promote each value before squaring and accumulate the cluster sum in
double. Centroids remainfloat; the SMAWK recurrence, cost-table types, public API, and asymptotic complexity are unchanged. Numerical results are not bit-identical: removing intermediate float rounding can change centroids even on well-conditioned inputs, and can also change the selected partition.The regression tests use the public
Clustering1D::train_exact()path. They cover a known eight-cluster partition before and after exactly representable positive/negative offsets, including float output rounding, and constant-valued clusters. This is a targeted precision fix: the cost table still uses float, and prefix-sum subtraction remains subject to cancellation.Validation
faiss_testtarget on Linux against main6bbb068ad8dab612b84304400846da1b14539085.git diff --checkpass.tests/test_clustering.py), GPU tests, or Meta-internal tests were run.