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

adds a return option to data moving #134

Merged
merged 2 commits into from
Mar 13, 2024
Merged
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
3 changes: 2 additions & 1 deletion docs/release-notes/0.10.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
```

* added `get` module {pr}`100` {smaller}`S Dicks`
* switch `utils` functions to get {pr}`100` {smaller}`S Dicks`
* switch `utils` functions to `get` {pr}`100` {smaller}`S Dicks`
* added `get.aggregated` to create condensed `anndata` objects {pr}`100` {smaller}`S Dicks`
* added `pp.scrublet` and `pp.scrublet_simulate_doublets` {pr}`129` {smaller}`S Dicks`
* adds the option to return a copyed `AnnData` for `get.anndata_to_CPU` & `get.anndata_to_GPU` {pr}`134` {smaller}`S Dicks`

```{rubric} Bug fixes
```
Expand Down
30 changes: 26 additions & 4 deletions src/rapids_singlecell/get/_anndata.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ def anndata_to_GPU(
adata: AnnData,
layer: Optional[str] = None,
convert_all: bool = False,
) -> None:
copy: bool = False,
) -> Optional[AnnData]:
"""
Transfers matrices and arrays to the GPU

Expand All @@ -32,10 +33,17 @@ def anndata_to_GPU(
convert_all
If True, move all supported arrays and matrices on the GPU

copy
Whether to return a copy or update `adata`.

Returns
-------
Updates `adata` inplace
Updates `adata` inplace or returns an updated copy
"""

if copy:
adata = adata.copy()

if convert_all:
anndata_to_GPU(adata)
if adata.layers:
Expand All @@ -55,12 +63,16 @@ def anndata_to_GPU(

_set_obs_rep(adata, X, layer=layer)

if copy:
return adata


def anndata_to_CPU(
adata: AnnData,
layer: Optional[str] = None,
convert_all: bool = False,
) -> None:
copy: bool = False,
) -> Optional[AnnData]:
"""
Transfers matrices and arrays from the GPU

Expand All @@ -75,10 +87,17 @@ def anndata_to_CPU(
convert_all
If True, move all GPU based arrays and matrices to the host memory

copy
Whether to return a copy or update `adata`.

Returns
-------
Updates `adata` inplace
Updates `adata` inplace or returns an updated copy
"""

if copy:
adata = adata.copy()

if convert_all:
anndata_to_CPU(adata)
if adata.layers:
Expand All @@ -96,3 +115,6 @@ def anndata_to_CPU(
pass

_set_obs_rep(adata, X, layer=layer)

if copy:
return adata
Loading