Skip to content

Commit

Permalink
Backport PR #1754 on branch 0.11.x ((fix): resolve cupy import error …
Browse files Browse the repository at this point in the history
…on `cupy-cuda12x<0.13`) (#1755)

Co-authored-by: Ilan Gold <[email protected]>
  • Loading branch information
meeseeksmachine and ilan-gold authored Nov 11, 2024
1 parent cb8b760 commit 12b6478
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/release-notes/1754.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix `cupy<0.13` imports in non-gpu environments {user}`ilan-gold`
11 changes: 10 additions & 1 deletion src/anndata/compat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,16 @@ def __repr__():
return "mock dask.array.core.Array"


if find_spec("cupy") or TYPE_CHECKING:
# https://github.com/scverse/anndata/issues/1749
def is_cupy_importable() -> bool:
try:
import cupy # noqa: F401
except ImportError:
return False
return True


if is_cupy_importable() or TYPE_CHECKING:
from cupy import ndarray as CupyArray
from cupyx.scipy.sparse import csc_matrix as CupyCSCMatrix
from cupyx.scipy.sparse import csr_matrix as CupyCSRMatrix
Expand Down

0 comments on commit 12b6478

Please sign in to comment.