mirror of
https://github.com/wassname/jaxtyping.git
synced 2026-09-09 11:24:55 +08:00
Better suppotr for incomplete JAX installations. Supersedes #105.
This commit is contained in:
@@ -20,20 +20,12 @@
|
||||
import importlib.metadata
|
||||
import typing
|
||||
|
||||
|
||||
try:
|
||||
import jax
|
||||
except ImportError:
|
||||
has_jax = False
|
||||
else:
|
||||
has_jax = True
|
||||
del jax
|
||||
|
||||
# First import some things as normal
|
||||
from ._array_types import (
|
||||
AbstractArray as AbstractArray,
|
||||
AbstractDtype as AbstractDtype,
|
||||
get_array_name_format as get_array_name_format,
|
||||
has_jax,
|
||||
set_array_name_format as set_array_name_format,
|
||||
)
|
||||
from ._decorator import jaxtyped as jaxtyped
|
||||
|
||||
@@ -32,7 +32,11 @@ from ._decorator import storage
|
||||
|
||||
try:
|
||||
import jax
|
||||
except ImportError:
|
||||
except (ImportError, RuntimeError, AttributeError):
|
||||
# We catch `RuntimeError` as JAX will throw this if it's present, but unable to run
|
||||
# on the current machine. This fails with this error.
|
||||
# We catch `AttributeError` as the above then leaves the module in a partially
|
||||
# initialised state, which causes subsequent imports to fail with this error.
|
||||
has_jax = False
|
||||
else:
|
||||
has_jax = True
|
||||
|
||||
Reference in New Issue
Block a user