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

Uploaded Python 3

File details

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

File metadata

  • Download URL: jaxtyping-0.2.5.tar.gz
  • Upload date:
  • Size: 13.6 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.5.tar.gz
Algorithm Hash digest
SHA256 8af4212eebbb40d6e26832b0bb9bd32a407105326f1ad13359204c9aea82124b
MD5 f05477ed2b54f2b9c21cfb08b230975e
BLAKE2b-256 4d7541723c448f6f996787b5f57ccc163ebf2d1e98da7a6e71ed200e625d533f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jaxtyping-0.2.5-py3-none-any.whl
  • Upload date:
  • Size: 17.5 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.5-py3-none-any.whl
Algorithm Hash digest
SHA256 6f3652ab67a447d37f208e373d9b2975e60308a7fbbc7ab8100dfe7a6e8d0434
MD5 a0fefe388068069f4292667d6de8c6a7
BLAKE2b-256 bc8ad422c8736e1c6433b9123824eb7b661525dcb4e4b35f26b07395cd0b9248

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