Skip to content

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

Open
ilan-gold wants to merge 10 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 10 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.65%. Comparing base (a5256e9) to head (471b989).
✅ 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.61%   79.65%   +0.04%     
==========================================
  Files         120      120              
  Lines       12786    12826      +40     
==========================================
+ Hits        10180    10217      +37     
- Misses       2606     2609       +3     
Flag Coverage Δ
hatch-test.low-vers 78.67% <36.00%> (-0.19%) ⬇️
hatch-test.pre 79.51% <96.00%> (+0.06%) ⬆️

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

Files with missing lines Coverage Δ
src/scanpy/get/_aggregated.py 93.56% <96.00%> (+0.25%) ⬆️

... and 1 file with indirect coverage changes

@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 11, 2026 19:01
return out


@numba.njit(inline="always") # noqa: TID251

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ilan-gold I think I had forgotten to add these noqa's. But I have the precommit hook setup now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants