Skip to content
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

remove out of core median #3379

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/release-notes/3379.performance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
In `pp.normalize_total`, the median is now computed in-memory when using Dask {smaller}`S Dicks`
16 changes: 3 additions & 13 deletions src/scanpy/preprocessing/_normalization.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,9 @@
X = X.astype(np.float32) # TODO: Check if float64 should be used
if after is None:
if isinstance(counts, DaskArray):

def nonzero_median(x):
return np.ma.median(np.ma.masked_array(x, x == 0)).item()

after = da.from_delayed(
dask.delayed(nonzero_median)(counts),
shape=(),
meta=counts._meta,
dtype=counts.dtype,
)
else:
counts_greater_than_zero = counts[counts > 0]
after = np.median(counts_greater_than_zero, axis=0)
counts = counts.compute()

Check warning on line 35 in src/scanpy/preprocessing/_normalization.py

View check run for this annotation

Codecov / codecov/patch

src/scanpy/preprocessing/_normalization.py#L35

Added line #L35 was not covered by tests
counts_greater_than_zero = counts[counts > 0]
after = np.median(counts_greater_than_zero, axis=0)
counts = counts / after
return axis_mul_or_truediv(
X,
Expand Down