Skip to main content

GPU-accelerated hypergeometric functions (2F1, 1F1, 0F1) for Apple MLX

Project description

mlx-hyp2f1

GPU-accelerated hypergeometric functions for Apple MLX.

JAX has hyp2f1 but PyTorch, CuPy, and MLX do not. This package fills the gap for MLX, providing vectorized implementations that run on Apple Silicon GPU.

Features

  • hyp2f1(a, b, c, z) -- Gauss hypergeometric function 2F1
  • hyp1f1(a, b, z) -- Confluent (Kummer) hypergeometric function 1F1
  • hyp0f1(b, z) -- Bessel-related hypergeometric function 0F1
  • Fully vectorized: compute over arrays of parameters simultaneously on GPU
  • Numerically stable via log-gamma Pochhammer symbols
  • Analytic continuation for |z| >= 1 using linear transformation formulas
  • Pure MLX -- no SciPy runtime dependency

Installation

pip install mlx-hyp2f1

Or from source:

git clone https://github.com/akaiHuang/mlx-hyp2f1.git
cd mlx-hyp2f1
pip install -e ".[dev]"

Usage

import mlx.core as mx
from mlx_hyp2f1 import hyp2f1, hyp1f1, hyp0f1

# Scalar
result = hyp2f1(0.5, 1.0, 1.5, 0.3)

# Vectorized over z
z = mx.linspace(0.0, 0.95, 100)
result = hyp2f1(0.5, 1.0, 1.5, z)

# Vectorized over all parameters
a = mx.array([0.5, 1.0, 2.0])
b = mx.array([1.0, 1.5, 0.5])
c = mx.array([1.5, 2.0, 3.0])
z = mx.array([0.3, 0.5, 0.8])
result = hyp2f1(a, b, c, z)

# Confluent hypergeometric (Kummer)
result = hyp1f1(1.0, 2.0, mx.linspace(-5.0, 5.0, 100))

# Bessel-related
result = hyp0f1(1.0, mx.linspace(-10.0, 10.0, 100))

Cosmological growth factor D(a)

import mlx.core as mx
from mlx_hyp2f1 import hyp2f1

def growth_factor(a, omega_m=0.3):
    """Linear growth factor D(a) for flat LCDM."""
    omega_l = 1.0 - omega_m
    x = -omega_l / omega_m * a**3
    return a * hyp2f1(1.0/3.0, 1.0, 11.0/6.0, x)

Benchmark

python -m mlx_hyp2f1.benchmark

Testing

pip install -e ".[dev]"
pytest

Applications

  • Cosmological growth factor D(a)
  • Beta distribution CDF / PDF
  • Angular momentum coupling coefficients
  • Legendre / Jacobi / Gegenbauer polynomials
  • Scattering amplitudes in quantum mechanics

License

MIT -- Sheng-Kai Huang

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_hyp2f1-0.1.0.tar.gz (8.8 kB view details)

Uploaded Source

Built Distribution

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

mlx_hyp2f1-0.1.0-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for mlx_hyp2f1-0.1.0.tar.gz
Algorithm Hash digest
SHA256 238dc3c1e609825a17fdb7381ad4dd5b0dfe6c4d4bd8677ff80d534594f822bd
MD5 d6a274ace62ed72211f6d89842de0545
BLAKE2b-256 238f37578f6d7c8686d61eae43fc3f11bc20eed3775ce8ae2d8aa573fb7ae4c1

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for mlx_hyp2f1-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6a159737bfcf2d2f907d94ec6a663cfe01d2340fca982c4d2e0fa03ecb77d9d0
MD5 ae8b706f952f7a29e85308974bc96a6f
BLAKE2b-256 52b64fb71a984bfdc93f11a7f3f0c3c11943b6968a4fbd9c0713136d0d872b5e

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