Skip to main content

Type annotations and runtime checking for shape and dtype of JAX arrays, and PyTrees.

Project description

jaxtyping

Type annotations and runtime checking for:

  1. shape and dtype of JAX arrays;
  2. PyTrees.

For example:

from jaxtyping import Array, Float, PyTree

# Accepts floating-point 2D arrays with matching dimensions
def matrix_multiply(x: Float[Array, "dim1 dim2"],
                    y: Float[Array, "dim2 dim3"]
                  ) -> Float[Array, "dim1 dim3"]:
    ...

def accepts_pytree_of_ints(x: PyTree[int]):
    ...

def accepts_pytree_of_arrays(x: PyTree[Float[Array, "batch c1 c2"]]):
    ...

Installation

pip install jaxtyping

Requires JAX 0.3.4+.

Also install your favourite runtime type-checking package. The two most popular are typeguard (which exhaustively checks every argument) and beartype (which checks random pieces of arguments).

Documentation

Full API reference

FAQ (static type checking, flake8, etc.)

Finally

See also: other tools in the JAX ecosystem

Neural networks: Equinox.

Numerical differential equation solvers: Diffrax.

SymPy<->JAX conversion; train symbolic expressions via gradient descent: sympy2jax.

Acknowledgements

Shape annotations + runtime type checking is inspired by TorchTyping.

The concise syntax is partially inspired by etils.array_types.

Disclaimer

This is not an official Google product.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jaxtyping-0.2.6.tar.gz (13.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

jaxtyping-0.2.6-py3-none-any.whl (17.6 kB view details)

Uploaded Python 3

File details

Details for the file jaxtyping-0.2.6.tar.gz.

File metadata

  • Download URL: jaxtyping-0.2.6.tar.gz
  • Upload date:
  • Size: 13.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.14

File hashes

Hashes for jaxtyping-0.2.6.tar.gz
Algorithm Hash digest
SHA256 16e6763e0d869d11a2b2f2d3a1db250d3173476fb2c0b470598f331badd7ca57
MD5 b049ed126086e34b06ea5c7800e2bf5c
BLAKE2b-256 d373897d81ad327b3d7ae65f7539cd124855c5e134d20269b8b54bc33de99be7

See more details on using hashes here.

File details

Details for the file jaxtyping-0.2.6-py3-none-any.whl.

File metadata

  • Download URL: jaxtyping-0.2.6-py3-none-any.whl
  • Upload date:
  • Size: 17.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.14

File hashes

Hashes for jaxtyping-0.2.6-py3-none-any.whl
Algorithm Hash digest
SHA256 41cc38ae665ac557196d56e2f271e9a95010fc5953cb5cdbeeed2bed5bf08d78
MD5 a825a2daf37ee8a96218355800ab06d9
BLAKE2b-256 3f98578c1459c56d5656dfa8c93e7f03d37b40389eb077ffd6ff9539d5d2fa87

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page