Skip to main content

spexial

scipy.special in JAX

PyPI version PyPI platforms Actions Status codecov Documentation

spexial provides special functions for JAX, following the scipy.special API. The implementations are written in terms of JAX primitives, so they compose with jit, grad and vmap, and run on CPU, GPU and TPU.

It exists to fill gaps in jax.scipy.special: zeta accepts negative integers where JAX returns nan, spence accepts complex arguments where JAX is real-only, and the modified Bessel K, Gegenbauer and polylogarithm functions have no JAX counterpart at any version. Where SciPy already covers a case, spexial matches it rather than claiming to exceed it.

Installation

pip install spexial

or

uv add spexial

Example

>>> import jax
>>> jax.config.update("jax_enable_x64", True)

>>> import jax.numpy as jnp
>>> import spexial as sp

>>> # Gegenbauer polynomial C_n^alpha(x), matching scipy.special.eval_gegenbauer
>>> sp.eval_gegenbauer(3, 0.5, 0.25)
Array(-0.3359375, dtype=float64, weak_type=True)

Everything is vectorisable and differentiable in the usual way:

>>> xs = jnp.linspace(-1.0, 1.0, 5)
>>> jax.vmap(lambda x: sp.eval_gegenbauer(3, 0.5, x))(xs)
Array([-1.    ,  0.4375, -0.    , -0.4375,  1.    ], dtype=float64)

What is here

Function scipy.special counterpart
comb comb (the exact=False variant)
gamma gamma — JAX's value, plus an analytic derivative
eval_gegenbauer eval_gegenbauer
eval_gegenbauers -- returns every order up to n
incomplete_beta -- the unregularized B(a, b, z); betainc is the regularized form
k0, k1, k2 k0, k1, kn
k0e, k1e, k2e k0e, k1e, kve — scaled by e^z, no upper limit
polylog -- the polylogarithm
spence spence — complex too, which JAX rejects
sph_legendre_p sph_legendre_p — absent from JAX at any version
sph_harm_y sph_harm_y — JAX's returns incorrect values for array degrees
sph_harm_y_cart -- from a Cartesian direction; correct gradients on the z-axis
sph_harm_y_cart_all sph_harm_y_all (layout only) — the whole (l, m) table in one pass
sph_harm_y_cart_all_terms -- as above, returned as separate arrays so reductions stay fused
zeta zeta — negative integers, which JAX gives as nan

Read Accuracy and domains before relying on any of these. It records, per function, the domain each is tested over and the tolerance it actually meets. Some are not machine-precision — the modified Bessel functions are accurate to about 1e-7, and zeta does not implement the critical strip.

Documentation

https://jaxtronomy.github.io/spexial

Development

We welcome contributions! See CONTRIBUTING.md.

uv sync --group dev
uv run nox -s all      # lint -> test -> docs

Citation

If you use spexial in work you publish, please cite it — see CITATION.cff. Several routines originate in the LINX code.

License

MIT. See LICENSE.

Metadata

Release files for spexial 0.2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for spexial 0.2.2
File Size Uploaded Provenance Actions
spexial-0.2.2.tar.gz 206.3 kB With provenance Details for spexial-0.2.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for spexial 0.2.2
File Interpreter ABI Platform Actions
spexial-0.2.2-py3-none-any.whl Python 3 none any Details for spexial-0.2.2-py3-none-any.whl

Total release size: 287.8 kB

Release files / spexial-0.2.2.tar.gz

Download URL spexial-0.2.2.tar.gz
Size 206.3 kB
Tags Source
SHA-256 checksum
How to use checksums
2ac0fdc0c6548b3380e3a417b7e769ed82ec5e37e465ff352bf24742ea7b4fcb
BLAKE2b-256 checksum
How to use checksums
278ff4899e9cb0aa710ecbdbc304358dc03a4d9b1ae04241c6bf127da5992f5f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 19, 2026.

Transparency log

Release files / spexial-0.2.2-py3-none-any.whl

Download URL spexial-0.2.2-py3-none-any.whl
Size 81.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8c9cd71088451e315225950d043b8936ae4d1d88977f3574e24c8e14f1341050
BLAKE2b-256 checksum
How to use checksums
040b63a5010720e9a04153b61fb11f7d81ae23ea8bf0927f5863874ea17fd03d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 19, 2026.

Transparency log

Security for spexial 0.2.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for spexial-0.2.2.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 19, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page