JuliaMath / HCubature.jl

pure-Julia multidimensional h-adaptive integration
Other
148 stars 23 forks source link

Promotion of endpoints to a common type? #20

Closed jverzani closed 5 years ago

jverzani commented 5 years ago

I was a bit surprised that this failed:

 hcubature(x -> 2.0, (0,0), (2pi, pi))

(Forcing pi to a float through 1pi works, or course.)

Something similar happens with hcubature(x -> 2.0, (0,0), (2, 2.0)). Would there be any drawbacks to promoting the endpoints to a common type? I see this "T is a floating-point type determined by promoting the endpoint a and b coordinates to a floating-point type" in the README, which suggests that should happen, right?

stevengj commented 5 years ago

It already does do promotion, but I must have missed something?

jverzani commented 5 years ago

It comes from dispatch, as

julia> isa((pi, 2pi), NTuple{2,<:Real}) # n = 2
false

Not sure you want to relax that. Please close this issue if not.

stevengj commented 5 years ago

Ah, I see. I guess we could replace the current NTuple method with something like:

hcubature_(f, a::Tuple, b::Tuple, norm, rtol, atol, maxevals, initdiv) =
    hcubature_(f, SVector(a), SVector(b), norm, rtol, atol, maxevals, initdiv)

since it looks like the SVector(::Tuple) constructor knows how to do promotion.

jverzani commented 5 years ago

Very nice, thanks!