# Numerical integration over 3D domain of vector-valued function

**URL:** <https://discourse.julialang.org/t/numerical-integration-over-3d-domain-of-vector-valued-function/112284>\
**Category:** General Usage\
**Tags:** integral\
**Created:** [March 29, 2024, 12:27pm UTC](https://discourse.julialang.org/t/numerical-integration-over-3d-domain-of-vector-valued-function/112284 "2024-03-29T12:27:23Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![lxvm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lxvm/32/50010_2.png) [@lxvm](https://discourse.julialang.org/u/lxvm)\
**Post date:** [March 29, 2024, 1:41pm UTC](https://discourse.julialang.org/t/numerical-integration-over-3d-domain-of-vector-valued-function/112284/8 "2024-03-29T13:41:42Z")

</div>

There are probably two reasons why nested quadgk allocates:

1. 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
2. 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](https://discourse.julialang.org/t/make-julia-complete-the-inference-of-some-recursive-code/111449)

How does AutoBZCore.jl address these issues?

1. AutoBZCore.jl will automatically pre-allocate the intermediate `segbuf`s for you
2. AutoBZCore.jl will wrap your inner integrals using FunctionWrappers.jl to stop inference from taking so long

---

_[View the full topic](https://discourse.julialang.org/t/numerical-integration-over-3d-domain-of-vector-valued-function/112284)._
