jaxtyping provides type annotations and optional runtime checking for the shape and data type (dtype) of array-like objects across various numerical libraries such as JAX, NumPy, and PyTorch. It extends Python's type hinting system to express array dimensions, allowing for robust static analysis and helping to catch shape-related errors early. The current version is 0.3.9, and it maintains an active development pace with frequent updates.
pip install jaxtypingVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to use `jaxtyping` to annotate JAX arrays with shape and dtype information. It defines functions that perform matrix multiplication and array summation, using `Float` and `Int` types with string literal shapes. Crucially, it shows how to enable runtime checking with `set_array_typecheck_enabled(True)` to enforce these annotations, catching shape mismatches at runtime rather than relying solely on static analysis.
Add `from jaxtyping import set_array_typecheck_enabled; set_array_typecheck_enabled(True)` to your application's entry point if you desire runtime validation.
Replace `DType` annotations with direct Python type hints like `float`, `int`, or JAX/NumPy dtypes (e.g., `jnp.float32`) within the `Array` type, e.g., `Array[float, '...']` instead of `Array[DType[float], '...']`.
Update calls from `jaxtyping.set_active(True/False)` to `jaxtyping.set_array_typecheck_enabled(True/False)`.