# Slow cubature

**URL:** https://discourse.julialang.org/t/slow-cubature/116120
**Category:** Numerics
**Tags:** performance, quadrature, hcubature
**Created:** [June 23, 2024, 8:27pm UTC](https://discourse.julialang.org/t/slow-cubature/116120 "2024-06-23T20:27:13Z")
**Posts on this page:** 1
**Showing post:** 4

<div class="post-metadata">

### Author: ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)
#### Post date: [June 23, 2024, 9:43pm UTC](https://discourse.julialang.org/t/slow-cubature/116120/4 "2024-06-23T21:43:32Z")

</div>

> [@e3c6](#):
>
> Do the singularities lead to a larger amount of function evaluations and thus slow things down?

Yes. The convergence rate of quadrature schemes is usually limited by the largest singularity that you haven’t accounted for analytically in the method. See e.g. [Hcubature\_count? - #6 by stevengj](https://discourse.julialang.org/t/hcubature-count/115878/6)

> [@e3c6](#):
>
> I haven’t found any implementation of N-d spherical coordinates in Julia … It seems a bit heavy to implement generically

How many values of N do you actually need? Since in practice you probably only have a few cases, you could easily just implement them by hand and dispatch on the dimensionality `N`, which is part of the argument types, via StaticArrays. i.e. implement a function

```julia
z, jacobian = spherical_coords(t)

```

(Though I think it wouldn’t actually be too much work to implement this generically for arbitrary N, in a way that unrolls all the loops statically, if you are careful, even without using fancy tricks like generated functions.)

---

_[View the full topic](https://discourse.julialang.org/t/slow-cubature/116120)._
