Skip to main content

JIT decorator supporting multiple array API compatible libraries

Project description

array API JIT

CI Status Documentation Status Test coverage percentage

uv Ruff pre-commit

PyPI Version Supported Python versions License


Documentation: https://array-api-jit.readthedocs.io

Source Code: https://github.com/34j/array-api-jit


JIT decorator supporting multiple array API compatible libraries

Installation

Install this via pip (or your favourite package manager):

pip install array-api-jit

Usage

Simply decorate your function with @jit():

from array_api_jit import jit


@jit()
def my_function(x: Any) -> Any:
    xp = array_namespace(x)
    return xp.sin(x) + xp.cos(x)

Advanced Usage

You can specify the decorator, arguments, and keyword arguments for each library.

from array_api_jit import jit
from array_api_compat import array_namespace
from typing import Any
import numba


@jit(
    {"numpy": numba.jit()},  # numba.jit is not used by default because it may not succeed
    decorator_kwargs={
        "jax": {"static_argnames": ["n"]}
    },  # jax requires for-loop variable to be "static_argnames"
    # fail_on_error: bool = False, # do not raise an error if the decorator fails (Default)
    # rerun_on_error: bool = True, # re-run the original function if the wrapped function fails (NOT Default)
)
def sin_n_times(x: Any, n: int) -> Any:
    xp = array_namespace(x)
    for i in range(n):
        x = xp.sin(x)
    return x

Contributors ✨

Thanks goes to these wonderful people (emoji key):

This project follows the all-contributors specification. Contributions of any kind welcome!

Credits

Copier

This package was created with Copier and the browniebroke/pypackage-template project template.

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

array_api_jit-1.0.0.tar.gz (9.0 kB view details)

Uploaded Source

Built Distribution

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

array_api_jit-1.0.0-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file array_api_jit-1.0.0.tar.gz.

File metadata

  • Download URL: array_api_jit-1.0.0.tar.gz
  • Upload date:
  • Size: 9.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for array_api_jit-1.0.0.tar.gz
Algorithm Hash digest
SHA256 a896153e17357f87c31f3fe24303917efe5ade8d61d901760fb12faf40889e93
MD5 26cf5e86a9dd8bb8276c6c7f4dda5da7
BLAKE2b-256 e7955bddfb7e45188c8e3ad8a1c7ebfae0f5f230cbf26539d171a63bd728e9ae

See more details on using hashes here.

Provenance

The following attestation bundles were made for array_api_jit-1.0.0.tar.gz:

Publisher: ci.yml on 34j/array-api-jit

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

File details

Details for the file array_api_jit-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: array_api_jit-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 5.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for array_api_jit-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a60dddcae6ed7f523b0d3cfcbfe3a850d75ec02f07c99ca96869e0ff27027ce9
MD5 c77bca25dc20d851367c523abb741adf
BLAKE2b-256 8fda7dda387073f2044e7e35327cbd89c77ae8e1546d85914a1058b5ca371d23

See more details on using hashes here.

Provenance

The following attestation bundles were made for array_api_jit-1.0.0-py3-none-any.whl:

Publisher: ci.yml on 34j/array-api-jit

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