Skip to content

Commit

Permalink
(fix): resolve cupy import error on cupy-cuda12x<0.13 (#1754)
Browse files Browse the repository at this point in the history
* (fix): resolve cupy import error on `cupy-cuda12x<0.13`

* (chore): release note
  • Loading branch information
ilan-gold authored Nov 11, 2024
1 parent 7894073 commit 17b03a7
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 17b03a7

Please sign in to comment.