diff --git a/docs/release-notes/0.10.0.md b/docs/release-notes/0.10.0.md index 91e16a5c..c9dd78c3 100644 --- a/docs/release-notes/0.10.0.md +++ b/docs/release-notes/0.10.0.md @@ -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 ``` diff --git a/src/rapids_singlecell/get/_anndata.py b/src/rapids_singlecell/get/_anndata.py index 9c0ab425..0cd350e7 100644 --- a/src/rapids_singlecell/get/_anndata.py +++ b/src/rapids_singlecell/get/_anndata.py @@ -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 @@ -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: @@ -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 @@ -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: @@ -96,3 +115,6 @@ def anndata_to_CPU( pass _set_obs_rep(adata, X, layer=layer) + + if copy: + return adata