Integrals.jl icon indicating copy to clipboard operation
Integrals.jl copied to clipboard

`transformation_if_inf` is not type stable

Open agerlach opened this issue 4 years ago • 8 comments

Updatingtransformation_if_inf is sufficient to make HCubatureJL() type stable. Other methods are still type unstable.

agerlach avatar May 07 '21 18:05 agerlach

Do you have an MWE?

YingboMa avatar May 16 '22 16:05 YingboMa

Since transformation_if_inf is kind of a f->g function. It's either going to be type unstable, or we need to introduce the extra overhead for every function call. We should add an argument like do_inf_transformation=Val{true}().

YingboMa avatar May 16 '22 17:05 YingboMa

I don't recall what exactly I meant by "updating". Here is a MWE I just put together, I'm not sure if it captures the same problem I had in the OP.

using Quadrature , Distributions , Test

μ = [0.00 , 0.00]
Σ = [0.4 0.0 ; 0.00 0.4]
d = MvNormal(μ , Σ)
m(x , p) = pdf(d, x)
prob = QuadratureProblem{false}(m, [-Inf , -Inf] , [Inf , Inf])
sol = solve(prob,HCubatureJL(),reltol=1e-3,abstol=1e-3)

agerlach avatar May 16 '22 19:05 agerlach

It's either going to be type unstable, or we need to introduce the extra overhead for every function call. We should add an argument like do_inf_transformation=Val{true}().

Could it not use a function barrier or something?

ChrisRackauckas avatar May 20 '22 17:05 ChrisRackauckas

Not really, because it's a higher order function.

YingboMa avatar May 20 '22 17:05 YingboMa

There must be something, we can chat about this at the summit.

ChrisRackauckas avatar May 20 '22 18:05 ChrisRackauckas

I mean transformation_if_inf is kind of like a function barrier, and it's type unstable. The actual integration is type stable.

YingboMa avatar May 20 '22 18:05 YingboMa

  • Solving this doesn't seem to be sufficient to make HCubatureJL() typestable. See https://github.com/JuliaMath/HCubature.jl/issues/42

sharanry avatar Jun 23 '22 15:06 sharanry

I've addressed this issue in #241 by making sure with tests that all solves in the package are type-stable. I also deprecated do_inf_transformation and opted to transform all problems at solve time instead of init time. Note this does not guarantee type-groundedness, e.g. HCubatureJL is only type grounded when the limits of integration are vectors with static length.

lxvm avatar Mar 03 '24 19:03 lxvm