Metadata-Version: 2.4
Name: numba-bessel
Version: 1.3.0
Summary: Bessel functions in numba / numba-cuda-mlir
Author: 34j
License-Expression: MIT
Project-URL: Bug Tracker, https://github.com/34j/numba-bessel/issues
Project-URL: Changelog, https://github.com/34j/numba-bessel/blob/main/CHANGELOG.md
Project-URL: documentation, https://numba-bessel.readthedocs.io
Project-URL: repository, https://github.com/34j/numba-bessel
Classifier: Development Status :: 2 - Pre-Alpha
Classifier: Intended Audience :: Developers
Classifier: Natural Language :: English
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Software Development :: Libraries
Requires-Python: >=3.12
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: array-api-compat>=1.13
Requires-Dist: numba>=0.63
Requires-Dist: numpy>=1.22
Provides-Extra: cuda
Requires-Dist: numba-cuda-mlir[cu13]>=0.6.1; ((platform_machine == "aarch64" and sys_platform == "linux") or (platform_machine == "x86_64" and sys_platform == "linux") or (platform_machine == "AMD64" and sys_platform == "win32") or (platform_machine == "ARM64" and sys_platform == "win32")) and extra == "cuda"
Requires-Dist: numba-cuda-mlir[cu13]>=0.6.1; (platform_machine == "x86_64" and sys_platform == "linux") and extra == "cuda"
Dynamic: license-file

# numba-bessel

<p align="center">
  <a href="https://github.com/34j/numba-bessel/actions/workflows/ci.yml?query=branch%3Amain">
    <img src="https://img.shields.io/github/actions/workflow/status/34j/numba-bessel/ci.yml?branch=main&label=CI&logo=github&style=flat-square" alt="CI Status" >
  </a>
  <a href="https://numba-bessel.readthedocs.io">
    <img src="https://img.shields.io/readthedocs/numba-bessel.svg?logo=read-the-docs&logoColor=fff&style=flat-square" alt="Documentation Status">
  </a>
</p>
<p align="center">
  <a href="https://codecov.io/gh/34j/numba-bessel">
    <img src="https://img.shields.io/codecov/c/github/34j/numba-bessel.svg?logo=codecov&logoColor=fff&style=flat-square" alt="Test coverage percentage">
  </a>
  <a href="https://github.com/astral-sh/uv">
    <img src="https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/uv/main/assets/badge/v0.json" alt="uv">
  </a>
  <a href="https://github.com/astral-sh/ruff">
    <img src="https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json" alt="Ruff">
  </a>
  <a href="https://github.com/j178/prek">
    <img src="https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/j178/prek/master/docs/assets/badge-v0.json" alt="prek">
  </a>
</p>
<p align="center">
  <a href="https://pypi.org/project/numba-bessel/">
    <img src="https://img.shields.io/pypi/v/numba-bessel.svg?logo=python&logoColor=fff&style=flat-square" alt="PyPI Version">
  </a>
  <img src="https://img.shields.io/pypi/pyversions/numba-bessel.svg?style=flat-square&logo=python&amp;logoColor=fff" alt="Supported Python versions">
  <img src="https://img.shields.io/pypi/l/numba-bessel.svg?style=flat-square" alt="License">
</p>

---

**Documentation**: <a href="https://numba-bessel.readthedocs.io" target="_blank">https://numba-bessel.readthedocs.io</a>

**Source Code**: <a href="https://github.com/34j/numba-bessel" target="_blank">https://github.com/34j/numba-bessel</a>

---

Compute principal-sheet complex Bessel functions (`J`, `Y`, `I`, `K`) across all
finite `binary64` arguments and real orders `|nu| < 2^53` on CPU (Numba / NumPy /
Array API / `@njit`) and CUDA (PyTorch / CuPy / `numba-cuda-mlir`) through a
single unified API with recurrence-accelerated sequences (`*_all`).

## Installation

```shell
pip install numba-bessel
```

For GPU execution via `numba-cuda-mlir`:

```shell
pip install "numba-bessel[cuda]"
```

## Usage

### CPU (NumPy, scalars, and inside `@njit`)

```python
import numpy as np
from numba import njit
from numba_bessel import OK, besselj, besselj_all, besselk

# Arbitrary real orders |nu| < 2^53 (positive and negative)
nu = np.array([2.3, -1.5])
z = np.array([1.2 + 0.4j, complex(-2.0, -0.0)])  # negative-real cut lips use ±0.0
vals = besselj(nu, z)
assert vals.shape == (2,) and np.isfinite(vals).all()

# Recurrence-accelerated sequence nu, nu+1, ..., nu+n_end-1
seq, status = besselj_all(-1.3, z, n_end=4, return_status=True)
assert seq.shape == (2, 4) and np.all(status == OK)

# Failed evaluations return nan+nanj and diagnostic status codes
bad_val, bad_status = besselk(0.0, 0.0j, return_status=True)
assert np.isnan(bad_val) and bad_status != OK

# Direct use inside @njit (scalar inputs and return_status)
@njit(fastmath=False)
def eval_inside_njit(nu_s: float, z_s: complex) -> complex:
    return besselj(nu_s, z_s)

assert np.isfinite(eval_inside_njit(3.3, 1.5 + 0.25j))
```

### GPU (PyTorch CUDA, CuPy, or any CUDA Array API)

The same functions dispatch to CUDA automatically when given GPU arrays via
[`array-api-compat`](https://data-apis.org/array-api-compat/):

<!-- skip: next -->

```python
import torch
from numba_bessel import besselj, besselj_all

torch.set_default_device("cuda")
nu = torch.tensor([2.3, -1.5], dtype=torch.float64)
z = torch.tensor([1.2 + 0.4j, complex(-2.0, -0.0)], dtype=torch.complex128)

vals = besselj(nu, z)
seq = besselj_all(-1.3, z, n_end=4)  # shape: (2, 4) on cuda:0
```

See the [algorithm reference](docs/algorithm.md) for the mathematical proofs,
regional numerical portfolio, recurrence architecture, and qualification results.
