Skip to content

perf: chan's parallel mean-var algorithm for dask-backed arrays (sparse/dense)#4143

Open
ilan-gold wants to merge 48 commits into
mainfrom
ig/chan_mean_var_main
Open

perf: chan's parallel mean-var algorithm for dask-backed arrays (sparse/dense)#4143
ilan-gold wants to merge 48 commits into
mainfrom
ig/chan_mean_var_main

Conversation

@ilan-gold

@ilan-gold ilan-gold commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

See https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance#Parallel_algorithm

Based on a #4118 (comment) with @zboldyga

This has two benefits - it allows us to calculate mean/var in one pass instead of effectively two (square sum and sum squared) and gets rid of a numerical instability issue that @zboldyga found the solution to (see removed comment)

  • Closes #
  • Tests included or not required because:

@ilan-gold ilan-gold added this to the 1.12.2 milestone Jun 5, 2026
@codecov

codecov Bot commented Jun 5, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.71%. Comparing base (62d4c97) to head (6ddd745).
⚠️ Report is 1 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/scanpy/get/_aggregated.py 96.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4143      +/-   ##
==========================================
+ Coverage   79.68%   79.71%   +0.02%     
==========================================
  Files         120      120              
  Lines       12801    12832      +31     
==========================================
+ Hits        10201    10229      +28     
- Misses       2600     2603       +3     
Flag Coverage Δ
hatch-test.low-vers 78.74% <42.00%> (-0.20%) ⬇️
hatch-test.pre 79.58% <96.00%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/scanpy/get/_kernels.py 100.00% <ø> (ø)
src/scanpy/get/_aggregated.py 92.94% <96.00%> (-0.37%) ⬇️

@ilan-gold ilan-gold marked this pull request as ready for review June 5, 2026 15:08
@ilan-gold ilan-gold changed the title perf: chan's parallel mean-var algorithm for dask perf: chan's parallel mean-var algorithm for dask-backed arrays (sparse/dense) Jun 8, 2026
@zboldyga

zboldyga commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

@ilan-gold I added njit support, see: #4153 . This enables rank_gene_groups to use njit.

I integrated this to the rank_gene_groups PR and benchmarked there as well as here and it gives a speedup on both at normal group x gene sizes.

@ilan-gold

Copy link
Copy Markdown
Contributor Author

Nice commented there about something, but once you got the pre-commit fixed as well, I'll merge into this

Co-authored-by: Ilan Gold <ilanbassgold@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
@ilan-gold ilan-gold requested a review from flying-sheep June 17, 2026 13:23
Base automatically changed from ig/welford to main June 23, 2026 13:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants