Skip to main content

GPU-accelerated Airy functions for Apple Silicon using MLX

Project description

mlx-airy

GPU-accelerated Airy functions for Apple Silicon using MLX.

Neither MLX nor JAX currently provide Airy functions (see JAX issue #25244). This package fills that gap for the MLX ecosystem.

What are Airy functions?

Airy functions Ai(x) and Bi(x) are the two linearly independent solutions to the Airy differential equation:

y'' - x y = 0

They appear throughout physics and engineering:

  • Quantum mechanics -- WKB connection formulas, tunneling through linear potentials
  • Optics -- diffraction near caustics, rainbow scattering
  • Fluid dynamics -- boundary layers, Stokes phenomena
  • Astrophysics -- gravitational lensing near fold caustics

Installation

pip install -e ".[test,benchmark]"

Requires Python >= 3.10 and Apple Silicon (MLX).

Usage

import mlx.core as mx
from mlx_airy import airy

x = mx.linspace(-15.0, 15.0, 10000)
ai, aip, bi, bip = airy(x)  # Ai(x), Ai'(x), Bi(x), Bi'(x)

All four functions are returned in a single call, matching the scipy.special.airy convention.

Implementation

Region Method Reference
|x| < 5 Taylor series (50 terms, Horner) DLMF 9.4
x >= 5 Asymptotic expansion DLMF 9.7.5--9.7.8
x <= -5 Oscillatory asymptotic DLMF 9.7.9--9.7.12

Computation is float32 throughout, running entirely on the Apple GPU.

Tests

pytest tests/ -v

Benchmark

python -m mlx_airy.benchmark

Compares accuracy and throughput against scipy.special.airy.

Measured on Apple M1 Max (MLX 0.31.1, SciPy 1.16.2, float32), x in [-15, 15], all four outputs (Ai, Ai', Bi, Bi'):

N scipy (ms) mlx (ms) Speedup
1,000 3.30 32.07 0.1x
10,000 15.76 31.65 0.5x
100,000 147.69 35.55 4.2x
1,000,000 1393.08 209.09 6.7x

mlx-airy wins above ~30-50k points, where the Metal dispatch cost is amortised; below that, scipy's vectorised C path is faster. Worst-case float32 relative error is ~3e-4. Full numbers in benchmark_results.md.

Author

Sheng-Kai Huang (akai@fawstudio.com)

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

mlx_airy-0.1.1.tar.gz (21.5 kB view details)

Uploaded Source

Built Distribution

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

mlx_airy-0.1.1-py3-none-any.whl (18.9 kB view details)

Uploaded Python 3

File details

Details for the file mlx_airy-0.1.1.tar.gz.

File metadata

  • Download URL: mlx_airy-0.1.1.tar.gz
  • Upload date:
  • Size: 21.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for mlx_airy-0.1.1.tar.gz
Algorithm Hash digest
SHA256 1ace8a3a2b597e081b0ef3e82925cf5a30d82bf1bf609d4fd979fcdae367b3cc
MD5 844fb834e48a7364fc9c52295ae98d7d
BLAKE2b-256 d28d6757fcbed4b148cf578577b5b16731b8c6718a10af65d2fa0d91eac1ced6

See more details on using hashes here.

File details

Details for the file mlx_airy-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: mlx_airy-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 18.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for mlx_airy-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 491de84214f17a0d362ca74056450db0a937eb060d2c48066439206c96309db1
MD5 e6637bc2fec36a31ffe94708f5dc1a59
BLAKE2b-256 047d69841570a2639b38f4f9f10096da1d0f231a7291338aa2ba032954568fec

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