Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into dask_mg_support
Browse files Browse the repository at this point in the history
Intron7 authored Nov 26, 2024
2 parents c65585d + 45c5054 commit b7974f9
Showing 7 changed files with 33 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.7.4
rev: v0.8.0
hooks:
- id: ruff
types_or: [python, pyi, jupyter]
11 changes: 11 additions & 0 deletions docs/release-notes/0.10.12.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
### 0.10.12 {small}`the-future`

```{rubric} Features
```
```{rubric} Performance
```
```{rubric} Bug fixes
```
```{rubric} Misc
```
* Update `get_random_state` for `scrublet `{pr}`301` {smaller}`S Dicks`
2 changes: 2 additions & 0 deletions docs/release-notes/index.md
Original file line number Diff line number Diff line change
@@ -7,6 +7,8 @@
```

## Version 0.10.0
```{include} /release-notes/0.10.12.md
```
```{include} /release-notes/0.10.11.md
```
```{include} /release-notes/0.10.10.md
3 changes: 2 additions & 1 deletion src/rapids_singlecell/preprocessing/_scrublet/core.py
Original file line number Diff line number Diff line change
@@ -9,9 +9,10 @@
from anndata import AnnData, concat
from cuml.neighbors import NearestNeighbors
from cupyx.scipy import sparse
from scanpy._utils import get_random_state
from scanpy.preprocessing._utils import sample_comb

from rapids_singlecell.preprocessing._utils import get_random_state

from .sparse_utils import subsample_counts

if TYPE_CHECKING:
12 changes: 6 additions & 6 deletions src/rapids_singlecell/preprocessing/_scrublet/pipeline.py
Original file line number Diff line number Diff line change
@@ -3,10 +3,9 @@
from typing import TYPE_CHECKING, Literal

import cupy as cp
from cupyx import cusparse
from cupyx.scipy import sparse

from rapids_singlecell.preprocessing._utils import _get_mean_var
from rapids_singlecell.preprocessing._utils import _get_mean_var, _sparse_to_dense

from .sparse_utils import sparse_multiply, sparse_zscore

@@ -59,10 +58,10 @@ def truncated_svd(

self._counts_obs_norm = self._counts_obs_norm.astype(cp.float32)
self._counts_sim_norm = self._counts_sim_norm.astype(cp.float32)
X_obs = cusparse.sparseToDense(self._counts_obs_norm)
X_obs = _sparse_to_dense(self._counts_obs_norm)
svd = TruncatedSVD(n_components=n_prin_comps, random_state=random_state).fit(X_obs)
X_obs = svd.transform(X_obs)
X_sim = svd.transform(cusparse.sparseToDense(self._counts_sim_norm))
X_sim = svd.transform(_sparse_to_dense(self._counts_sim_norm))
self.set_manifold(X_obs, X_sim)


@@ -79,8 +78,9 @@ def pca(

self._counts_obs_norm = self._counts_obs_norm.astype(cp.float32)
self._counts_sim_norm = self._counts_sim_norm.astype(cp.float32)
X_obs = cusparse.sparseToDense(self._counts_obs_norm)
X_obs = _sparse_to_dense(self._counts_obs_norm)

pca = PCA(n_components=n_prin_comps, random_state=random_state).fit(X_obs)
X_obs = pca.transform(X_obs)
X_sim = pca.transform(cusparse.sparseToDense(self._counts_sim_norm))
X_sim = pca.transform(_sparse_to_dense(self._counts_sim_norm))
self.set_manifold(X_obs, X_sim)
Original file line number Diff line number Diff line change
@@ -5,9 +5,8 @@
import cupy as cp
import numpy as np
from cupyx.scipy import sparse
from scanpy._utils import get_random_state

from rapids_singlecell.preprocessing._utils import _get_mean_var
from rapids_singlecell.preprocessing._utils import _get_mean_var, get_random_state

if TYPE_CHECKING:
from numpy.typing import NDArray
10 changes: 10 additions & 0 deletions src/rapids_singlecell/preprocessing/_utils.py
Original file line number Diff line number Diff line change
@@ -4,14 +4,18 @@
from typing import TYPE_CHECKING, Literal

import cupy as cp

from cuml.internals.memory_utils import with_cupy_rmm
import numpy as np
from cupyx.scipy.sparse import issparse, isspmatrix_csc, isspmatrix_csr, spmatrix

from rapids_singlecell._compat import DaskArray

if TYPE_CHECKING:
from anndata import AnnData

from rapids_singlecell._utils import AnyRandom


def _sparse_to_dense(X: spmatrix, order: Literal["C", "F"] | None = None) -> cp.ndarray:
if order is None:
@@ -306,3 +310,9 @@ def _check_use_raw(adata: AnnData, use_raw: None | bool, layer: str | None) -> b
if layer is not None:
return False
return adata.raw is not None


def get_random_state(seed: AnyRandom) -> np.random.RandomState:
if isinstance(seed, np.random.RandomState):
return seed
return np.random.RandomState(seed)

0 comments on commit b7974f9

Please sign in to comment.