Skip to content

Python elliptic#34

Merged
moiseevigor merged 12 commits into
masterfrom
python-elliptic
Apr 19, 2026
Merged

Python elliptic#34
moiseevigor merged 12 commits into
masterfrom
python-elliptic

Conversation

@moiseevigor

@moiseevigor moiseevigor commented Apr 18, 2026

Copy link
Copy Markdown
Owner

Python package — v4.0.0

First Python release of the elliptic library, now available on PyPI as elliptic-functions.

pip install elliptic-functions
pip install "elliptic-functions[torch]"   # + PyTorch (CPU and CUDA)
pip install "elliptic-functions[jax]"     # + JAX (jit / vmap / TPU)

What's included

Full function parity with MATLAB/Octave

Group Functions
Incomplete integrals elliptic12, elliptic3
Jacobi functions ellipj, jacobiEDJ, jacobiThetaEta, theta, theta_prime
Associate integrals ellipticBDJ, ellipticBD
Carlson symmetric forms carlsonRF, carlsonRD, carlsonRJ, carlsonRC
Bulirsch cel, cel1, cel2, cel3
Weierstrass weierstrassP, weierstrassZeta, weierstrassSigma, weierstrassPPrime, weierstrassInvariants
Utilities agm, nomeq, inversenomeq, arclength_ellipse
Complex argument elliptic12i, ellipji

GPU-native — beats MATLAB on every benchmark

All functions are array-API-native: passing a PyTorch CUDA tensor or JAX array runs the entire computation on GPU, no CPU roundtrip. With torch.compile, Python loops are fused into single CUDA kernels.

Benchmarks at 1M elements on GTX 1080 Ti:

Function MATLAB GPU Python GPU Speedup
elliptic3 17.7 Melem/s 64 Melem/s 3.6×
ellipj 3.5 Melem/s 46 Melem/s 13×
elliptic12 3.6 Melem/s 8.8 Melem/s 2.5×
carlsonRF 58 Melem/s new
weierstrassP 46 Melem/s new
agm 183 Melem/s new
import torch, elliptic

phi = torch.linspace(0, torch.pi/2, 1_000_000, device="cuda")
F, E, Z = elliptic.elliptic12(phi, 0.7)   # runs entirely on GPU

CI

  • 126 tests, Python 3.10–3.13, Ubuntu + macOS
  • Backends: NumPy, PyTorch, JAX
  • Auto-publish to PyPI on release via OIDC trusted publisher

Repo restructure

  • matlab/ — all MATLAB/Octave source, tests, benchmarks
  • python/ — Python package
  • Root README rewritten as unified dual-language landing page

Add python/ subdirectory with standalone elliptic package:
- elliptic12: F(phi,m), E(phi,m), Z(phi,m) via Carlson RF/RD
- ellipj:     sn, cn, dn, am via AGM + descending Landen
- elliptic3:  Pi(phi,m,n) via 10-pt Gauss-Legendre
- ellipticBDJ/BD: associate integrals B, D, J, S via Carlson
- jacobiEDJ:  Jacobi-argument Eu, Du, Ju
- carlson:    RF, RD, RJ, RC via Carlson duplication
- bulirsch:   cel, cel1, cel2, cel3 generalised complete integrals
- weierstrass: P, Zeta, Sigma

Multi-backend: numpy (default), torch, jax via array_namespace().
Fixed iteration counts (AGM=25, Carlson=30) make loops JAX-traceable.
All 33 tests pass at 1e-12 tolerance vs scipy.special reference.
- bench.py: timing table for all functions at 10k/100k/1M elements
- README.md: quickstart, GPU/JAX examples, scipy comparison table
- .github/workflows/test.yml: matrix CI (Python 3.10-3.13, ubuntu+macos, numpy/torch/jax)
…Python CI to root .github/

- matlab/src/      ← was src/
- matlab/tests/    ← was tests/
- matlab/bench/    ← bench.m, bench_gpu.m, bench_gpu_results.csv
- matlab/setup.m   ← setup.m (path unchanged, already relative to itself)
- matlab/README.md ← new MATLAB-specific README
- docs/wiki/       ← was wiki/
- .github/workflows/python.yml ← was python/.github/workflows/test.yml
- .circleci/config.yml updated for new matlab/ paths
- README.md rewritten as unified landing page (MATLAB + Python)
…nguage tests, examples

New functions (agm, nome, inverse, theta, complex, Weierstrass, applications):
- agm(a, b)                    — arithmetic-geometric mean
- nomeq(m), inversenomeq(q)    — nome and its inverse
- inverselliptic2(E, m)        — inverse incomplete E via Boyd Newton method
- jacobiThetaEta(u, m)         — Jacobi Θ and H (AGM-equivalent via nome series)
- theta(j, v, m), theta_prime  — four theta functions and their derivatives
- elliptic12i(u, m)            — F, E, Z for complex argument (A&S 17.4)
- ellipji(u, m)                — sn, cn, dn for complex argument (A&S addition formulae)
- weierstrassInvariants(e1,e2,e3) — g2, g3, Delta from roots
- weierstrassPPrime(z,e1,e2,e3) — P-function derivative via sn/cn/dn
- arclength_ellipse(a, b)      — ellipse arc length via E(phi|m)

Tests (126 total, all pass):
- test_parity.py: 43 new tests for all parity functions
- test_reference_tables.py: exact cross-language fixtures from matlab/tests/*.m
- test_associate.py: derivative tests, Carlson symmetry, extended Bulirsch coverage
- elliptic12 period reduction fix: F(phi+k*pi)=F(phi)+2kK, E, Z now correct for large arguments

README updates:
- Root README: unified feature table, 4-domain examples section (celestial mechanics,
  pendulum, rigid body, geometry, signal processing, lattice/number theory) with
  runnable code snippets and links to interactive example page
- python/README.md: full API list with all 29 public functions, updated scipy comparison table
Rewrites all core modules to use array-API-native ops throughout:
- _xputils.py: get_xp() detects backend (NumPy/PyTorch/JAX) from inputs
- carlson.py: RF/RD/RJ/RC — fixed-iteration loops, fully xp-native
- ellipj.py: AGM ratio method, 25 fixed iterations, no per-element masking
- elliptic12.py, elliptic3.py, ellipticBD.py, ellipticBDJ.py: xp.where everywhere
- agm.py, bulirsch.py, weierstrass.py: same pattern

bench.py: run_torch_cuda now passes CUDA tensors directly (no CPU roundtrip)
and applies torch.compile for kernel fusion.

Results at 1M elements on GTX 1080 Ti vs MATLAB GPU (same card):
  elliptic3:  64 Melem/s Python vs 17.7 Melem/s MATLAB  (3.6×)
  ellipj:     46 Melem/s Python vs  3.5 Melem/s MATLAB (13.1×)
  elliptic12:  8.8 Melem/s Python vs 3.6 Melem/s MATLAB  (2.5×)
  carlsonRF:  58 Melem/s, weierstrassP: 46 Melem/s, agm: 183 Melem/s

All 126 tests pass.
@moiseevigor
moiseevigor merged commit 56ed16e into master Apr 19, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant