Python elliptic#34
Merged
Merged
Conversation
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.
…Python examples, point to subfolder READMEs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Python package — v4.0.0
First Python release of the elliptic library, now available on PyPI as
elliptic-functions.What's included
Full function parity with MATLAB/Octave
elliptic12,elliptic3ellipj,jacobiEDJ,jacobiThetaEta,theta,theta_primeellipticBDJ,ellipticBDcarlsonRF,carlsonRD,carlsonRJ,carlsonRCcel,cel1,cel2,cel3weierstrassP,weierstrassZeta,weierstrassSigma,weierstrassPPrime,weierstrassInvariantsagm,nomeq,inversenomeq,arclength_ellipseelliptic12i,ellipjiGPU-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:
elliptic3ellipjelliptic12carlsonRFweierstrassPagmCI
Repo restructure
matlab/— all MATLAB/Octave source, tests, benchmarkspython/— Python package