scijit.integrate.romb

scijit.integrate.romb(y, dx=1.0, axis=-1, show=False)

Romberg integration of equally-spaced samples.

Repeated Richardson extrapolation of the trapezoid rule. Very accurate on smooth data, but the sample count is constrained.

Takes NO callback of either style: it integrates samples.

Parameters:
yarray_like

Samples on an equally-spaced grid. The length along axis must be one plus a non-negative power of two, otherwise ValueError.

dxfloat, optional

Sample spacing, a scalar. Default 1.0.

axisint, optional

Axis to integrate along. Default -1, the last axis.

showbool or sequence, optional

Print the Richardson extrapolation table. Default False. A sequence supplies (precision, width), defaulting to 5 and 8. Only a single data set is printed; an y of rank 2 or more prints a notice instead. Inside @njit it must be a compile-time constant, since it selects whether the table is built at all.

Returns:
totalfloat or ndarray

The integral, the top-right corner of the Romberg table. A scalar for a 1-D y, otherwise an array of y’s rank less one.

Raises:
IndexError

axis outside y’s rank.

ValueError

The number of samples along axis is not one plus a non-negative power of two.

See also

scipy.integrate.romb

The scipy routine this mirrors.

Notes

scipy.integrate.romb documents show as a bool but reads (precision, width) from a sequence when one is passed; a sequence is accepted here as well.

Pure @njit, no state, so prange-safe. Printing the table takes the GIL for the duration, so it serializes a prange loop.

Examples

>>> import numpy as np
>>> from numba import njit
>>> import scijit.integrate as si
>>> x = np.linspace(0.0, np.pi, 65)
>>> @njit
... def run(x):
...     return si.romb(np.sin(x), x[1] - x[0])
>>> run(x)
1.9999999999999996