Skip to content

Commit 9b2d052

Browse files
committed
Update import logic and error raising
1 parent 79bc349 commit 9b2d052

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed
Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
from scipy.sparse.linalg import splu as scipySuperLU
2-
__all__ = ["scipySuperLU"]
2+
from ....context import ModuleNotAvailableError
3+
34
try:
45
from PyKLU import Klu as KLUSuperLU
5-
__all__.append("KLUSuperLU")
6-
except ImportError:
7-
pass
6+
except (ModuleNotFoundError,ImportError) as e:
7+
def KLUSuperLU(*args, _import_err=e, **kwargs):
8+
raise ModuleNotAvailableError(
9+
"KLUSuperLU is not available. Could not import required backend."
10+
) from _import_err
11+
12+
__all__ = ["scipySuperLU", "KLUSuperLU"]

xobjects/sparse/solvers/CUDA/__init__.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,23 @@
22
try:
33
from ._cuDSSLU import DirectSolverSuperLU as cuDSSSuperLU
44
except (ModuleNotFoundError,ImportError) as e:
5-
def cuDSSSuperLU(*args, **kwargs):
5+
def cuDSSSuperLU(*args, _import_err=e, **kwargs):
66
raise ModuleNotAvailableError(
77
"cuDSSSuperLU is not available. Could not import required backend."
8-
) from e
8+
) from _import_err
99
try:
1010
from ._luLU import luLU as CachedSuperLU
11-
except (ModuleNotFoundError,ImportError):
12-
def CachedSuperLU(*args, **kwargs):
11+
except (ModuleNotFoundError,ImportError) as e:
12+
def CachedSuperLU(*args, _import_err=e, **kwargs):
1313
raise ModuleNotAvailableError(
1414
"CachedSuperLU is not available. Could not import required backend."
15-
) from e
15+
) from _import_err
1616
try:
1717
from cupyx.scipy.sparse.linalg import splu as CupySuperLU
18-
except (ModuleNotFoundError,ImportError):
19-
def CupySuperLU(*args, **kwargs):
18+
except (ModuleNotFoundError,ImportError) as e:
19+
def CupySuperLU(*args, _import_err=e, **kwargs):
2020
raise ModuleNotAvailableError(
2121
"CupySuperLU is not available. Could not import required backend."
22-
) from e
22+
) from _import_err
2323

2424
__all__ = ["cuDSSSuperLU", "CachedSuperLU", "CupySuperLU"]

0 commit comments

Comments
 (0)