Numerical quadrature with JAX
Project description
quadax is a library for numerical quadrature and integration using JAX.
vmap-able, jit-able, differentiable.
Scalar or vector valued integrands.
Finite or infinite domains with discontinuities or singularities within the domain of integration.
Globally adaptive Gauss-Konrod and Clenshaw-Curtis quadrature for smooth integrands (similar to scipy.integrate.quad)
Adaptive tanh-sinh quadrature for singular or near singular integrands.
Quadrature from sampled values using trapezoidal and Simpsons methods.
Coming soon:
Custom JVP/VJP rules (currently AD works by differentiating the loop which isn’t the most efficient.)
N-D quadrature (cubature)
QMC methods
Integration with weight functions
Sparse grids (maybe, need to play with data structures and JAX)
Installation
quadax is installable with pip:
pip install quadax
Usage
import jax.numpy as jnp
import numpy as np
from quadax import quadgk
fun = lambda t: t * jnp.log(1 + t)
epsabs = epsrel = 1e-5 # by default jax uses 32 bit, higher accuracy requires going to 64 bit
a, b = 0, 1
y, info = quadgk(fun, [a, b], epsabs=epsabs, epsrel=epsrel)
assert info.err < max(epsabs, epsrel*abs(y))
np.testing.assert_allclose(y, 1/4, rtol=epsrel, atol=epsabs)
For full details of various options see the API documentation
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
Built Distribution
File details
Details for the file quadax-0.2.1.tar.gz
.
File metadata
- Download URL: quadax-0.2.1.tar.gz
- Upload date:
- Size: 32.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0d778db1852797bccdb5989075eed5db595ed626a81ec1699db71dc3ea1b1d8a |
|
MD5 | 39defc1557994565d65b4a0b9f6d6496 |
|
BLAKE2b-256 | ff8d0c0abcb6ab5bc8911a9c05a865e72d1b497a9523e47ecde85bc237d16202 |
Provenance
File details
Details for the file quadax-0.2.1-py3-none-any.whl
.
File metadata
- Download URL: quadax-0.2.1-py3-none-any.whl
- Upload date:
- Size: 29.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1b962f7ed7b55412d49c83d20cb4aa62e0b86c5cccb3d56af66c5d8918cc5c30 |
|
MD5 | 8b234748c27eafb56058cc9a2233345a |
|
BLAKE2b-256 | caf5fc980a83976de378ab5321fa1afb233ee1901cc1e32dbaaa7fe7921a69f1 |