Skip to main content

Abstract your array operations.

Project description

autoray-header

tests codecov Docs PyPI Anaconda-Server Badge Pixi Badge

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:

Beyond that, abstracting the array interface allows you to:

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.

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

autoray-0.8.11.tar.gz (1.3 MB view details)

Uploaded Source

Built Distribution

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

autoray-0.8.11-py3-none-any.whl (941.6 kB view details)

Uploaded Python 3

File details

Details for the file autoray-0.8.11.tar.gz.

File metadata

  • Download URL: autoray-0.8.11.tar.gz
  • Upload date:
  • Size: 1.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for autoray-0.8.11.tar.gz
Algorithm Hash digest
SHA256 3e994ea6813916b4e5471853f5332d69224fd67a5f057d602d20df47dcf63fe4
MD5 1018acd3749438871d00a5e04b6d9d7b
BLAKE2b-256 55ef3f4c83009e9825f3a8565bd71759be63de06de37768db31f9bf56a4075ce

See more details on using hashes here.

Provenance

The following attestation bundles were made for autoray-0.8.11.tar.gz:

Publisher: pypi-release.yml on jcmgray/autoray

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file autoray-0.8.11-py3-none-any.whl.

File metadata

  • Download URL: autoray-0.8.11-py3-none-any.whl
  • Upload date:
  • Size: 941.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for autoray-0.8.11-py3-none-any.whl
Algorithm Hash digest
SHA256 336d51cde75232585e965cac51e74e953d88c48405c8c199946514458ccbcfba
MD5 18b4a43267dfbc088508ec3609c04b87
BLAKE2b-256 9fbef0352174093c8beed98e85e37f9190cc7da8f26330b9853f5153a9514a0a

See more details on using hashes here.

Provenance

The following attestation bundles were made for autoray-0.8.11-py3-none-any.whl:

Publisher: pypi-release.yml on jcmgray/autoray

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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