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.7.tar.gz (14.0 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.7-py3-none-any.whl (17.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: jaxtyping-0.2.7.tar.gz
  • Upload date:
  • Size: 14.0 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.7.tar.gz
Algorithm Hash digest
SHA256 3faa40490182fc2ae308a7301faed85765e0641865a41e20db719f0b7d5444da
MD5 f54dbf2b5f4dd9592dc48f417d277898
BLAKE2b-256 e583cd2d726339798196965e9366311a71425c84c3c08e8d57f6751cb0caef68

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jaxtyping-0.2.7-py3-none-any.whl
  • Upload date:
  • Size: 17.9 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.7-py3-none-any.whl
Algorithm Hash digest
SHA256 bcd9f1f6a5424e53f821690e03b3f01ce29c17d6e431b5ceb5b470873b62e38b
MD5 cb515d1d2dc9a4faaf7408107b9e6a0f
BLAKE2b-256 f55729702780007f9055593de4e654d2eac54d7d5814a0101a75c1dbedb143ea

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