-
Notifications
You must be signed in to change notification settings - Fork 30
add score_genes support for Dask #408
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
from __future__ import annotations | ||
|
||
import cupy as cp | ||
import pytest | ||
from scanpy.datasets import pbmc3k, pbmc68k_reduced | ||
|
||
import rapids_singlecell as rsc | ||
from rapids_singlecell._testing import ( | ||
as_dense_cupy_dask_array, | ||
as_sparse_cupy_dask_array, | ||
) | ||
from rapids_singlecell.preprocessing._utils import _get_mean_var | ||
|
||
from ..test_score_genes import _create_sparse_nan_matrix # noqa: TID252 | ||
|
||
|
||
@pytest.mark.parametrize("data_kind", ["sparse", "dense"]) | ||
@pytest.mark.parametrize("axis", [0, 1]) | ||
@pytest.mark.parametrize("dtype", [cp.float32, cp.float64]) | ||
def test_mean_var(client, data_kind, axis, dtype): | ||
if data_kind == "dense": | ||
adata = pbmc68k_reduced() | ||
adata.X = adata.X.astype(dtype) | ||
dask_data = adata.copy() | ||
dask_data.X = as_dense_cupy_dask_array(dask_data.X).persist() | ||
rsc.get.anndata_to_GPU(adata) | ||
elif data_kind == "sparse": | ||
adata = pbmc3k() | ||
adata.X = adata.X.astype(dtype) | ||
dask_data = adata.copy() | ||
dask_data.X = as_sparse_cupy_dask_array(dask_data.X).persist() | ||
rsc.get.anndata_to_GPU(adata) | ||
|
||
mean, var = _get_mean_var(adata.X, axis=axis) | ||
dask_mean, dask_var = _get_mean_var(dask_data.X, axis=axis) | ||
dask_mean, dask_var = dask_mean.compute(), dask_var.compute() | ||
|
||
cp.testing.assert_allclose(mean, dask_mean) | ||
cp.testing.assert_allclose(var, dask_var) | ||
|
||
|
||
@pytest.mark.parametrize("array_type", ["csr", "dense"]) | ||
@pytest.mark.parametrize("percent_nan", [0, 0.3]) | ||
def test_sparse_nanmean(client, array_type, percent_nan): | ||
"""Needs to be fixed""" | ||
from rapids_singlecell.tools._utils import _nan_mean | ||
|
||
R, C = 100, 50 | ||
|
||
# sparse matrix with nan | ||
S = _create_sparse_nan_matrix(R, C, percent_zero=0.3, percent_nan=percent_nan) | ||
S = S.astype(cp.float64) | ||
A = S.toarray() | ||
A = rsc.get.X_to_GPU(A) | ||
|
||
if array_type == "dense": | ||
S = as_dense_cupy_dask_array(A).persist() | ||
else: | ||
S = as_sparse_cupy_dask_array(S).persist() | ||
|
||
cp.testing.assert_allclose( | ||
_nan_mean(A, 1).ravel(), (_nan_mean(S, 1)).ravel().compute() | ||
) | ||
cp.testing.assert_allclose( | ||
_nan_mean(A, 0).ravel(), (_nan_mean(S, 0)).ravel().compute() | ||
) |
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’m curious: why the axis switch? is this more local?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this works the other for some reason doesn't