autoray is a lightweight python AUTOmatic-arRAY library for
abstracting your tensor operations. Primarily it provides an
automatic dispatch mechanism
that means you can write backend agnostic code that works for:
- numpy
- pytorch
- jax
- cupy
- mlx
- dask
- autograd
- tensorflow
- sparse
- paddle
- ... and indeed any library that provides a numpy-ish api, even if it
knows nothing about
autoray.
Beyond that, abstracting the array interface allows you to:
- swap custom versions of functions for specific backends
- trace through computations lazily without actually running them
- automatically share intermediates and fold constants in computations
- compile functions with a unified interface for different backends
Basic usage
The main function of autoray is
do,
which takes a function
name followed by *args and **kwargs, and automatically looks up (and
caches) the correct function to match the equivalent numpy call:
import autoray as ar
def noised_svd(x):
# automatic dispatch based on supplied array
U, s, VH = ar.do("linalg.svd", x)
# automatic dispatch based on different array
sn = s + 0.1 * ar.do("random.normal", size=ar.shape(s), like=s)
# automatic dispatch for multiple arrays for certain functions
return ar.do("einsum", "ij,j,jk->ik", U, sn, VH)
# explicit backend given by string
x = ar.do("random.uniform", size=(100, 100), like="torch")
# this function now works for any backend
y = noised_svd(x)
# explicit inference of backend from array
ar.infer_backend(y)
# 'torch'
If you don't like the explicit do syntax, or simply want a
drop-in replacement for existing code, you can also import the autoray.numpy
module:
from autoray import numpy as np
# set a temporary default backend
with ar.backend_like("cupy"):
z = np.ones((3, 4), dtype="float32")
np.exp(z)
# array([[2.7182817, 2.7182817, 2.7182817, 2.7182817],
# [2.7182817, 2.7182817, 2.7182817, 2.7182817],
# [2.7182817, 2.7182817, 2.7182817, 2.7182817]], dtype=float32)
Alternatively you can use
autoray.get_namespace
to get a backend specific (with optional default device and dtype) namespace
object, (c.f. the Python Array Api):
xp = ar.get_namespace(z)
xp.einsum("ii->i", z)
Custom backends and functions can be dynamically registered with:
The main documentation is available at autoray.readthedocs.io.
Release files for autoray 0.11.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| autoray-0.11.0.tar.gz | 1.4 MB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| autoray-0.11.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 2.3 MB
Release files / autoray-0.11.0.tar.gz
| Download URL | autoray-0.11.0.tar.gz |
|---|---|
| Size | 1.4 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ef9c23d8307f2e5030d10dd222d304401450157172a6fcc6f7456b6e82681bf4
|
|
BLAKE2b-256 checksum How to use checksums |
cd330a894071f0635b9f9a208ba4eabc3af80b5316e51ec7de7ada89a2bf097e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 22, 2026.
Transparency logRelease files / autoray-0.11.0-py3-none-any.whl
| Download URL | autoray-0.11.0-py3-none-any.whl |
|---|---|
| Size | 952.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2e9ca95070834574e054162ee02946d2414f7821f65960308b95f49d08ee9227
|
|
BLAKE2b-256 checksum How to use checksums |
58a17e82580da9ad8a2ed06306856d25bc9ebc737db9331f566590ee15b0d4ff
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 22, 2026.
Transparency log