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.3.tar.gz
.
File metadata
- Download URL: quadax-0.2.3.tar.gz
- Upload date:
- Size: 34.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e88cb984737edcb7755df7e04bfd9642df0d9d49b0b4d76024c8c03dcee76bc4 |
|
MD5 | c75061b3d83bde7642f6cf1a65fc1d35 |
|
BLAKE2b-256 | d076d86f5ce985909299d1382ba7b3b5dfa8d5bc120ce098a74ca4b562be5821 |
Provenance
File details
Details for the file quadax-0.2.3-py3-none-any.whl
.
File metadata
- Download URL: quadax-0.2.3-py3-none-any.whl
- Upload date:
- Size: 31.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6372de788408eb578e59158cf1b40cfff1f1d37d3ccdb852f3a45fb3d79de501 |
|
MD5 | b854feb36b26c38fe90c79991e0ccc76 |
|
BLAKE2b-256 | 0279675c0df5393d6d07087c7caf68cc6a3894886d8dd34cf1a58516543ff89b |