add eval_segbuf and quadgk_segbuf options #108
Merged
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.
This adds a new keyword
eval_segbufs
, which allows you to specify the initial integrand evaluation intervals via an array ofSegments
, e.g. thesegbuf
cache from a previous call toquadgk
.If you also pass
maxevals=0
, this allows you to exactly re-use the quadrature points and weights from a previousquadgk
call, even for a different integrand. This is useful for automatic differentiation as discussed in EnzymeAD/Enzyme.jl#1599.Also adds a new function
quadgk_segbuf(...)
, which is identical toquadgk(...)
but returns a tuple(I, E, segbuf)
with an additionalsegbuf
output: the array of integration segments used for the quadrature. (This saves you from having to callalloc_segbuf
, which required you to know the return value of the integrand and so is painful to use in contexts where the integrand is an arbitrary function.)Another benefit of this API is that it will allow us to support integration over an array of points (rather than an argument list … arrays can be splatted, but this is problematic for large arrays) or even an array of tuples$(a,b)$ representing line segments (which could even be disjoint), both of which can be efficiently converted into a
Vector{Segment{T,Nothing,Nothing}}
for passing viaeval_segbuf
.To do:
Not sure if we need tutorial examples? The new functionality is documented in the docstrings, but the cases where it is useful are pretty technical.