autoray


Nameautoray JSON
Version 0.7.0 PyPI version JSON
download
home_pageNone
SummaryAbstract your array operations.
upload_time2024-10-22 00:13:21
maintainerNone
docs_urlNone
authorNone
requires_python>=3.9
licenseApache
keywords agnostic array autograd cupy dask dispatch jax numeric numpy tensor tensorflow
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ![autoray-header](https://github.com/jcmgray/autoray/assets/8982598/c5cb89bf-cc16-4345-8796-e0bd98dc2a15)

[![tests](https://github.com/jcmgray/autoray/actions/workflows/tests.yml/badge.svg)](https://github.com/jcmgray/autoray/actions/workflows/tests.yml)
[![codecov](https://codecov.io/gh/jcmgray/autoray/branch/main/graph/badge.svg?token=Q5evNiuT9S)](https://codecov.io/gh/jcmgray/autoray)
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/ba896d74c4954dd58da01df30c7bf326)](https://app.codacy.com/gh/jcmgray/autoray/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)
[![Docs](https://readthedocs.org/projects/autoray/badge/?version=latest)](https://autoray.readthedocs.io)
[![PyPI](https://img.shields.io/pypi/v/autoray?color=teal)](https://pypi.org/project/autoray/)
[![Anaconda-Server Badge](https://anaconda.org/conda-forge/autoray/badges/version.svg)](https://anaconda.org/conda-forge/autoray)

[`autoray`](https://autoray.readthedocs.io/en/latest) is a lightweight python AUTOmatic-arRAY library for
abstracting your tensor operations. Primarily it provides an
[*automatic* dispatch mechanism](https://autoray.readthedocs.io/en/latest/automatic_dispatch.html#)
that means you can write backend agnostic code that works for:

* [numpy](https://github.com/numpy/numpy)
* [pytorch](https://pytorch.org/)
* [jax](https://github.com/google/jax)
* [cupy](https://github.com/cupy/cupy)
* [dask](https://github.com/dask/dask)
* [autograd](https://github.com/HIPS/autograd)
* [tensorflow](https://github.com/tensorflow/tensorflow)
* [sparse](https://sparse.pydata.org/)
* [mars](https://github.com/mars-project/mars)
* ... 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](https://autoray.readthedocs.io/en/latest/automatic_dispatch.html#functions)
  for specific backends*
* *trace through computations [lazily](https://autoray.readthedocs.io/en/latest/lazy_computation.html) without actually
  running them*
* *automatically [share intermediates and fold constants](https://autoray.readthedocs.io/en/latest/lazy_computation.html#sharing-intermediates)
  in computations*
* *compile functions with a [unified interface](https://autoray.readthedocs.io/en/latest/compilation.html) for different
  backends*


## Basic usage

The main function of `autoray` is
[`do`](https://autoray.readthedocs.io/en/latest/autoapi/autoray/autoray/index.html#autoray.autoray.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:

```python
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:

```python
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:

* [`register_backend`](https://autoray.readthedocs.io/en/latest/autoapi/autoray/autoray/index.html#autoray.autoray.register_backend)
* [`register_function`](https://autoray.readthedocs.io/en/latest/autoapi/autoray/autoray/index.html#autoray.autoray.register_function)

The main documentation is available at [autoray.readthedocs.io](https://autoray.readthedocs.io/en/latest/).

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "autoray",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "agnostic, array, autograd, cupy, dask, dispatch, jax, numeric, numpy, tensor, tensorflow",
    "author": null,
    "author_email": "Johnnie Gray <johnniemcgray@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/8e/b7/8ec4ffeca00c9360adb94be177313f711071628b21ea912abe6e246051e1/autoray-0.7.0.tar.gz",
    "platform": null,
    "description": "![autoray-header](https://github.com/jcmgray/autoray/assets/8982598/c5cb89bf-cc16-4345-8796-e0bd98dc2a15)\n\n[![tests](https://github.com/jcmgray/autoray/actions/workflows/tests.yml/badge.svg)](https://github.com/jcmgray/autoray/actions/workflows/tests.yml)\n[![codecov](https://codecov.io/gh/jcmgray/autoray/branch/main/graph/badge.svg?token=Q5evNiuT9S)](https://codecov.io/gh/jcmgray/autoray)\n[![Codacy Badge](https://app.codacy.com/project/badge/Grade/ba896d74c4954dd58da01df30c7bf326)](https://app.codacy.com/gh/jcmgray/autoray/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)\n[![Docs](https://readthedocs.org/projects/autoray/badge/?version=latest)](https://autoray.readthedocs.io)\n[![PyPI](https://img.shields.io/pypi/v/autoray?color=teal)](https://pypi.org/project/autoray/)\n[![Anaconda-Server Badge](https://anaconda.org/conda-forge/autoray/badges/version.svg)](https://anaconda.org/conda-forge/autoray)\n\n[`autoray`](https://autoray.readthedocs.io/en/latest) is a lightweight python AUTOmatic-arRAY library for\nabstracting your tensor operations. Primarily it provides an\n[*automatic* dispatch mechanism](https://autoray.readthedocs.io/en/latest/automatic_dispatch.html#)\nthat means you can write backend agnostic code that works for:\n\n* [numpy](https://github.com/numpy/numpy)\n* [pytorch](https://pytorch.org/)\n* [jax](https://github.com/google/jax)\n* [cupy](https://github.com/cupy/cupy)\n* [dask](https://github.com/dask/dask)\n* [autograd](https://github.com/HIPS/autograd)\n* [tensorflow](https://github.com/tensorflow/tensorflow)\n* [sparse](https://sparse.pydata.org/)\n* [mars](https://github.com/mars-project/mars)\n* ... and indeed **any** library that provides a numpy-*ish* api, even if it\n  knows nothing about `autoray`.\n\nBeyond that, abstracting the array interface allows you to:\n\n* *swap [custom versions of functions](https://autoray.readthedocs.io/en/latest/automatic_dispatch.html#functions)\n  for specific backends*\n* *trace through computations [lazily](https://autoray.readthedocs.io/en/latest/lazy_computation.html) without actually\n  running them*\n* *automatically [share intermediates and fold constants](https://autoray.readthedocs.io/en/latest/lazy_computation.html#sharing-intermediates)\n  in computations*\n* *compile functions with a [unified interface](https://autoray.readthedocs.io/en/latest/compilation.html) for different\n  backends*\n\n\n## Basic usage\n\nThe main function of `autoray` is\n[`do`](https://autoray.readthedocs.io/en/latest/autoapi/autoray/autoray/index.html#autoray.autoray.do),\nwhich takes a function\nname followed by `*args` and `**kwargs`, and automatically looks up (and\ncaches) the correct function to match the equivalent numpy call:\n\n```python\nfrom autoray as ar\n\ndef noised_svd(x):\n    # automatic dispatch based on supplied array\n    U, s, VH = ar.do('linalg.svd', x)\n\n    # automatic dispatch based on different array\n    sn = s + 0.1 * ar.do('random.normal', size=ar.shape(s), like=s)\n\n    # automatic dispatch for multiple arrays for certain functions\n    return ar.do('einsum', 'ij,j,jk->ik', U, sn, VH)\n\n# explicit backend given by string\nx = ar.do('random.uniform', size=(100, 100), like=\"torch\")\n\n# this function now works for any backend\ny = noised_svd(x)\n\n# explicit inference of backend from array\nar.infer_backend(y)\n# 'torch'\n```\n\nIf you don't like the explicit `do` syntax, or simply want a\ndrop-in replacement for existing code, you can also import the `autoray.numpy`\nmodule:\n\n```python\nfrom autoray import numpy as np\n\n# set a temporary default backend\nwith ar.backend_like('cupy'):\n    z = np.ones((3, 4), dtype='float32')\n\nnp.exp(z)\n# array([[2.7182817, 2.7182817, 2.7182817, 2.7182817],\n#        [2.7182817, 2.7182817, 2.7182817, 2.7182817],\n#        [2.7182817, 2.7182817, 2.7182817, 2.7182817]], dtype=float32)\n```\n\nCustom backends and functions can be dynamically registered with:\n\n* [`register_backend`](https://autoray.readthedocs.io/en/latest/autoapi/autoray/autoray/index.html#autoray.autoray.register_backend)\n* [`register_function`](https://autoray.readthedocs.io/en/latest/autoapi/autoray/autoray/index.html#autoray.autoray.register_function)\n\nThe main documentation is available at [autoray.readthedocs.io](https://autoray.readthedocs.io/en/latest/).\n",
    "bugtrack_url": null,
    "license": "Apache",
    "summary": "Abstract your array operations.",
    "version": "0.7.0",
    "project_urls": {
        "Changelog": "https://github.com/jcmgray/autoray/releases",
        "Documentation": "https://autoray.readthedocs.io/",
        "Issues": "https://github.com/jcmgray/autoray/issues",
        "Repository": "https://github.com/jcmgray/autoray/"
    },
    "split_keywords": [
        "agnostic",
        " array",
        " autograd",
        " cupy",
        " dask",
        " dispatch",
        " jax",
        " numeric",
        " numpy",
        " tensor",
        " tensorflow"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e5acd8fb343def8bc5b7f82f5dcf0892e9020a446f21107a2d7de1537ff2fdf3",
                "md5": "1138b68cc62271fc0dd779d2b1023a21",
                "sha256": "03103957df3d1b66b8068158056c2909a72095b19d1b24262261276a714a5d07"
            },
            "downloads": -1,
            "filename": "autoray-0.7.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "1138b68cc62271fc0dd779d2b1023a21",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 930011,
            "upload_time": "2024-10-22T00:13:19",
            "upload_time_iso_8601": "2024-10-22T00:13:19.587125Z",
            "url": "https://files.pythonhosted.org/packages/e5/ac/d8fb343def8bc5b7f82f5dcf0892e9020a446f21107a2d7de1537ff2fdf3/autoray-0.7.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8eb78ec4ffeca00c9360adb94be177313f711071628b21ea912abe6e246051e1",
                "md5": "a4e2a6f5b8346cb68d984b47af853464",
                "sha256": "7829d21258512f87e02f23ce74ae5759af4ce8998069d2cce53468f1d701a219"
            },
            "downloads": -1,
            "filename": "autoray-0.7.0.tar.gz",
            "has_sig": false,
            "md5_digest": "a4e2a6f5b8346cb68d984b47af853464",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 1214555,
            "upload_time": "2024-10-22T00:13:21",
            "upload_time_iso_8601": "2024-10-22T00:13:21.434764Z",
            "url": "https://files.pythonhosted.org/packages/8e/b7/8ec4ffeca00c9360adb94be177313f711071628b21ea912abe6e246051e1/autoray-0.7.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-22 00:13:21",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "jcmgray",
    "github_project": "autoray",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "autoray"
}
        
Elapsed time: 0.72134s