-
Notifications
You must be signed in to change notification settings - Fork 1
fix: improve variance precision #127
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
Merged
Conversation
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
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #127 +/- ##
==========================================
+ Coverage 98.32% 98.33% +0.01%
==========================================
Files 17 17
Lines 418 421 +3
==========================================
+ Hits 411 414 +3
Misses 7 7 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
for more information, see https://pre-commit.ci
**2ing them
**2ing them
This was referenced Oct 17, 2025
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.
Fixes scverse/scanpy#3740
Turns out precision doesn’t matter if you only use numbers that are perfectly representable as floats.
Long story short: doing the
poweroperation in float32 led to imprecise exponentiated values. Dask’s scheduling led to errors accumulating in summing them up. Storing exponentiation results in float64 fixes this, but of course slows things down.Details
Something’s really off here, sparse-in-dask usually succeeds, but occasionally can fail enormously:
FAILED tests/test_stats.py::test_mean_var_pbmc_dask[dask.array.Array[scipy.sparse.csr_matrix]-2d-ax0] - AssertionError: Arrays are not almost equal to 6 decimals Mismatched elements: 761 / 765 (99.5%) Max absolute difference among violations: 7.88906984 Max relative difference among violations: 10.68116412 ACTUAL: array([4.081325e-01, 8.858602e-02, 4.668730e-01, 5.370092e-01, 9.700749e-02, 5.163984e-01, 3.209537e-01, 4.335481e-01, 4.517616e-01, 4.680808e-01, 4.769589e-01, 3.681803e-01,... DESIRED: array([0.42406 , 0.090823, 0.646268, 0.790074, 0.097231, 0.575962, 0.362582, 0.469195, 0.462772, 0.486282, 0.502374, 0.383135, 0.979183, 0.451647, 0.542628, 0.059287, 0.815319, 1.323111,...going into
mean_varand re-executing the same expression shows how completely nondeterministic it is:the nondeterminism seems to come from this line:
fast-array-utils/src/fast_array_utils/stats/_mean_var.py
Line 41 in 92483a4