Skip to main content

Rextio plugin that lowers eligible NumPy code to native Rust (plugin API 1.1: claim/lower, annotation vocabulary, pinned crate injection).

Project description

rextio-numpy

Rextio plugin that lowers eligible NumPy code to native Rust.

The first-party Rextio plugin for NumPy. It implements Rextio plugin protocol v2 (rextio.plugins.api): the plugin self-describes, as machine-readable rule records, which NumPy usage lowers to Rust (via the ndarray crate) and which stays on the Python fallback — following Rextio's core contract (CPython-equivalent semantics or fall back).

Status: lowering implemented for the initial surface

The plugin now implements plugin API 1.1 end to end: the annotation vocabulary (rextio_numpy.types.F64Arr1), the deterministic claim pass, lower() emission to Rust via the ndarray crate, and pinned crate injection (rust-numpy numpy =0.29.0; ndarray via its re-export). The implemented lowering surface, certified against CPython NumPy with the core plugin certification kit (rextio.plugins.testing):

  • Element-wise + - * / on float64 1-D arrays — array-array, array-scalar, and scalar-array forms (RXTP-NUMPY-001, verified)
  • numpy.dot(a, b) on float64 1-D arrays (RXTP-NUMPY-002, verified)
  • Whole-array numpy.sum / numpy.mean reductions (RXTP-NUMPY-003, verified)

Shape/length mismatches raise ValueError with NumPy's exact messages. Documented divergences (per rule constraint): dot/sum/mean float summation order may differ from NumPy's pairwise summation, and the native mean of an empty array returns nan without NumPy's RuntimeWarning.

Full rule surface (all experimental, codes RXTP-NUMPY-NNN):

Rule Outcome Code
Element-wise + - * / on 1-D float64 arrays (array-array incl. length-1 broadcasting, array-scalar, scalar-array) native (verified) RXTP-NUMPY-001
numpy.dot(a, b) on 1-D float64 arrays (module-call form) native (verified) RXTP-NUMPY-002
Whole-array numpy.sum / numpy.mean on 1-D float64 (module-call form) native (verified) RXTP-NUMPY-003
Non-float64 dtypes / unsupported operand types fallback RXTP-NUMPY-010
Rank > 1 or unknown rank fallback RXTP-NUMPY-011
Mutating aliased views fallback RXTP-NUMPY-012
Any other NumPy API fallback RXTP-NUMPY-019

Codes RXTP-NUMPY-011/012/019 are declarative-only: they document fallback boundaries in the rule records but are never attached to diagnostics — uncovered sites surface as core's RXT030 instead. Only RXTP-NUMPY-010 is actively emitted.

NumPy itself is deliberately not a dependency of the plugin — only the user-facing rextio_numpy.types vocabulary module imports it, in the user's project. A @numba.*-decorated function is always respected as the user's opt-in to Numba's semantics and is never lowered by this plugin.

Usage

# rextio.toml
[rust]
build_tool = "cargo"

[plugins]
enabled = ["rextio-numpy"]
import numpy as np
from rextio_numpy.types import F64Arr1  # plain runtime alias of numpy.ndarray

def dot(a: F64Arr1, b: F64Arr1) -> float:
    return np.dot(a, b)
pip install rextio-numpy   # requires rextio >= 0.1.1 (unreleased yet)
rextio capabilities --format json   # numpy rules appear under "rules"
rextio build .                      # lowered kernels compile via cargo

Development

rextio 0.1.1 is not on PyPI yet, so install core from a checkout first and this package without dependency resolution:

uv venv --python 3.11 .venv
uv pip install --python .venv/bin/python -e path/to/rextio
uv pip install --python .venv/bin/python --no-deps -e .
uv pip install --python .venv/bin/python pytest ruff mypy
.venv/bin/python -m pytest

License

MIT

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

rextio_numpy-0.1.0.tar.gz (21.7 kB view details)

Uploaded Source

Built Distribution

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

rextio_numpy-0.1.0-py3-none-any.whl (14.1 kB view details)

Uploaded Python 3

File details

Details for the file rextio_numpy-0.1.0.tar.gz.

File metadata

  • Download URL: rextio_numpy-0.1.0.tar.gz
  • Upload date:
  • Size: 21.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for rextio_numpy-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f3919cf1f1df1293e9fa2a4dcb151b53d077d16b638493ae0f1bc2ac20393ab8
MD5 e80d2362f14cdc779e671f086fbf96ff
BLAKE2b-256 7ce951414694e48a51db30b181a7ae6dba559031916a61402bfafa1a93dd94aa

See more details on using hashes here.

File details

Details for the file rextio_numpy-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: rextio_numpy-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 14.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for rextio_numpy-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cb2fec0074b595ee9e28c759dc12c5286e31dbe9c57c97e5ed37643f3520ad83
MD5 323acae2ab95d67c6923c8d81a8bf61b
BLAKE2b-256 13697dda0404dad2023bbe4a8e6a35162dc52944f520e13a941014d7edc46c7a

See more details on using hashes here.

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