jaxtyping  by patrick-kidger

Typing library for array shapes/dtypes

created 3 years ago
1,492 stars

Top 28.2% on sourcepulse

GitHubView on GitHub
Project Summary

jaxtyping provides type annotations and runtime checking for the shape and dtype of arrays from JAX, PyTorch, NumPy, MLX, and TensorFlow, as well as PyTrees. It enables developers to enforce array dimensions and data types at runtime, improving code robustness and maintainability for machine learning and scientific computing tasks.

How It Works

The library uses a novel annotation system where array types are specified with a base type (e.g., Float, Int) followed by shape and dtype constraints within square brackets (e.g., Float[Array, "batch height width"]). This allows for precise specification of array structures, which can then be validated at runtime by compatible type-checking libraries like typeguard or beartype. This approach offers a declarative way to ensure array integrity without manual checks.

Quick Start & Requirements

  • Install via pip: pip install jaxtyping
  • Requires Python 3.10+. JAX is an optional dependency.
  • Compatible with typeguard or beartype for runtime checking.
  • Documentation: https://docs.kidger.site/jaxtyping/

Highlighted Details

  • Supports JAX, PyTorch, NumPy, MLX, and TensorFlow arrays.
  • Enables type checking for PyTrees containing primitive types or arrays.
  • Annotations are compatible with popular runtime type checkers.
  • Offers a clear, declarative syntax for array shape and dtype specification.

Maintenance & Community

  • Developed by Patrick Kidger.
  • Further details on community and roadmap are not explicitly provided in the README.

Licensing & Compatibility

  • License: MIT.
  • Compatible with commercial and closed-source projects.

Limitations & Caveats

The library is primarily focused on static analysis and runtime checking of array shapes and dtypes; it does not perform numerical computations itself. JAX-specific types are unavailable if JAX is not installed.

Health Check
Last commit

3 months ago

Responsiveness

1 day

Pull Requests (30d)
0
Issues (30d)
3
Star History
102 stars in the last 90 days

Explore Similar Projects

Feedback? Help us improve.