Skip to main content

Abstract your array operations.

Project description

autoray-header

tests codecov Codacy Badge PyPI Anaconda-Server 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:

from 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)

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.6.7.tar.gz (1.2 MB view details)

Uploaded Source

Built Distribution

autoray-0.6.7-py3-none-any.whl (49.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: autoray-0.6.7.tar.gz
  • Upload date:
  • Size: 1.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for autoray-0.6.7.tar.gz
Algorithm Hash digest
SHA256 8945cfdf3aa8a35f9fe1abc03d84925db61f58bbd386623206dd8e9ba1d9e377
MD5 0693a213079311bec590c3143fcb0072
BLAKE2b-256 f580aeef635b619f04843a11f3928e73fa9d0e0d48d2108329ce7d07b18e80a3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: autoray-0.6.7-py3-none-any.whl
  • Upload date:
  • Size: 49.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for autoray-0.6.7-py3-none-any.whl
Algorithm Hash digest
SHA256 7372d416b018c49a62d23e1e2566dee7fa5aa59a1b43fa7501d7d071b50ae481
MD5 e9ef91c411994a88d048fc28215b4afa
BLAKE2b-256 ad93c274651e4b9994edf77ab0af094c858c6a949c372f8d459920b1818f570e

See more details on using hashes here.

Supported by

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