Skip to content

Commit 834bbc7

Browse files
committed
More robust cupy import
1 parent a59f36c commit 834bbc7

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

src/cunumpy/xp.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ def __init__(
2727

2828
def _load_backend(self, backend: BackendType, verbose: bool = False) -> ModuleType:
2929
if backend == "cupy":
30-
try:
30+
if has_cupy():
3131
import cupy as cp
3232

3333
return cp
34-
except ImportError:
34+
else:
3535
if verbose:
36-
print("CuPy not available.")
36+
print("CuPy not available or not functional.")
3737
return np
3838
import numpy as np_mod
3939

@@ -163,7 +163,7 @@ def to_cupy(array: Any) -> Any:
163163

164164
def to_cunumpy(array: Any) -> Any:
165165
"""Convert an array to the currently active backend."""
166-
if array_backend.backend == "cupy":
166+
if array_backend.backend == "cupy" and has_cupy():
167167
return to_cupy(array)
168168
return to_numpy(array)
169169

0 commit comments

Comments
 (0)