Repository navigation
FIX adaptive fixed-point scale for weighted float32-only cumsums - #24
Merged
ogrisel merged 1 commit intoAug 28, 2026
Conversation
Choose the micro-unit scale from the mean sample weight (capped by int64 headroom via n * max(weight)) so pre-normalized or uniformly tiny weights do not round to zero under a fixed 1e6 scale, while O(1) weights keep the previous micro-unit resolution. Extend the float32-only large-n regression test to cover those failure modes. Co-authored-by: Olivier Grisel <[email protected]>
ogrisel
marked this pull request as ready for review
August 28, 2026 16:05
ogrisel
merged commit Aug 28, 2026
c6f51d5
into
fix-34813-cmat-weighted-int-scale
45 of 47 checks passed
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.
Follow-up to the weighted float32-only fix on
fix-34813-cmat-weighted-int-scale(upstream scikit-learn#34827), addressing the failure mode discussed in review.Why
A fixed
round(weight * 1e6)scale works for O(1) sample weights but zeros out pre-normalized (sum≈1) or uniformly tiny weights once the mean weight drops below~5e-7(e.g. largen). That is the real mechanism behind the scikit-learn#34827 review concern, even though that review mis-attributed it to an in-functionweight / weight.sum()step that the branch does not perform.Approach
Keep absolute weighted counts (do not normalize then rescale). Choose the micro-unit scale from the mean weight:
scale ≈ 1e6 * n / weight.sum()so the average weight gets ~1e6 integer unitsn * max(weight)For typical O(1) weights this recovers
scale ≈ 1e6. For pre-normalized / tiny weights it raises the scale so values survive rounding.Tests
Extended
test_confusion_matrix_at_thresholds_float32_only_weighted_large_nwithnormalizedandtinykinds, including an assertion that the old fixed1e6scale would quantize all weights to zero. All four parametrizations pass locally onarray_api_strictno_float64.Review focus
sum/maxfor scale selection is acceptable (order-of-magnitude only; counts still come from int64 cumsum)This pull request includes code written with the assistance of AI.
The code has not yet been reviewed by a human.