giordano / Cuba.jl

Library for multidimensional numerical integration with four independent algorithms: Vegas, Suave, Divonne, and Cuhre.
https://giordano.github.io/Cuba.jl/stable
MIT License
75 stars 9 forks source link

divonne and cuhre pass vector of length 2 for one-dimensional integration #14

Closed oschulz closed 6 years ago

oschulz commented 6 years ago

When integrating in one dimension, vegas and suave call the integrand with a vectir of length 1 (as expected), but divonne and cuhre pass a vector of length 2:

julia> vegas((x, f) -> ((@assert length(x) == 1); f[1] = norm(x)), 1)
...

julia> suave((x, f) -> ((@assert length(x) == 1); f[1] = norm(x)), 1)
...

julia> divonne((x, f) -> ((@assert length(x) == 1); f[1] = norm(x)), 1)
ERROR: AssertionError: length(x) == 1
julia> divonne((x, f) -> ((@assert length(x) == 2); f[1] = norm(x)), 1)
...

julia> cuhre((x, f) -> ((@assert length(x) == 1); f[1] = norm(x)), 1)
ERROR: AssertionError: length(x) == 1
julia> cuhre((x, f) -> ((@assert length(x) == 2); f[1] = norm(x)), 1)
...
giordano commented 6 years ago

Hi Oliver. That's correct, those methods require ndim to be at least 2. Did you run into some issues because of this?

oschulz commented 6 years ago

Hi, thanks - should have looked into the Cuba docs. :-) I did run into issues, but it was only in a toy case. But maybe divonne and cuhre should throw an ArgumentError if run for one dimension, just in case?

giordano commented 6 years ago

Currently I forcibly set ndim = 2 if it's equal to 1: https://github.com/giordano/Cuba.jl/blob/9d0354a19a3968d8f02c72d1291808cce8798908/src/cuhre.jl#L94 I thought that this would have been quite harmless, but I see that using something like norm can lead to unexpected results.

I will change the default value of ndim for cuhre and divonne to 2, throw an error for lower values, better document this.

oschulz commented 6 years ago

grazie!

giordano commented 6 years ago

Bitte ;-) I've merged PR #15, do let me know if you need a tagged version of this package.

oschulz commented 6 years ago

Thanks, no, I don't need an urgent tag on this.