mirror of
https://github.com/ROCm/jax.git
synced 2025-04-18 21:06:06 +00:00
jax.typing: recommend instance check in Python 3.10 or newer
This commit is contained in:
parent
40fb646e35
commit
ed9fa1342b
@ -41,7 +41,10 @@ For example, your function might look like this::
|
||||
from jax.typing import ArrayLike
|
||||
|
||||
def my_function(x: ArrayLike) -> Array:
|
||||
# Runtime type validation:
|
||||
# Runtime type validation, Python 3.10 or newer:
|
||||
if not isinstance(x, ArrayLike):
|
||||
raise TypeError(f"Expected arraylike input; got {x}")
|
||||
# Runtime type validation, any Python version:
|
||||
if not (isinstance(x, (np.ndarray, Array)) or np.isscalar(x)):
|
||||
raise TypeError(f"Expected arraylike input; got {x}")
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user