There are probably two reasons why nested quadgk allocates:
- The quadgk algorithm may allocate a heap to perform adaptive refinement via the
segbuf
keyword. If you don’t pre-allocate and reuse it then it may be allocated once per inner integrand - The Julia compiler gives up on recursive code such as nested quadgk. The compilation time for triply-nested quadgk can take up to a minute in my experience. For a related discussion see Make Julia complete the inference of some recursive code
How does AutoBZCore.jl address these issues?
- AutoBZCore.jl will automatically pre-allocate the intermediate
segbuf
s for you - AutoBZCore.jl will wrap your inner integrals using FunctionWrappers.jl to stop inference from taking so long