Skip to content

Commit

Permalink
Throw an error when maxevals > typemax(Int64)÷2 in suave (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
giordano authored Dec 31, 2023
1 parent 12795df commit 0e80be4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,12 @@ julia> typemax(Int64)
9223372036854775807
```

!!! warning "`maxevals` in Suave"

Due to an [upstream bug](https://github.com/giordano/Cuba.jl/issues/27),
the `suave` routine cannot handle `maxevals` larger than 4611686018427387903
(== `typemax(Int) ÷ 2`).

There is no way to overcome this limit. See the following sections for
the meaning of each argument.

Expand Down
3 changes: 3 additions & 0 deletions src/suave.jl
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ function suave(integrand::T, ndim::Integer=1, ncomp::Integer=1;
statefile::AbstractString=STATEFILE, spin::Ptr{Cvoid}=SPIN,
reltol=missing, abstol=missing, userdata=missing) where {T}
atol_,rtol_ = tols(atol,rtol,abstol,reltol)
# See <https://github.com/giordano/Cuba.jl/issues/27>.
max_maxevals = typemax(Int64) ÷ 2
maxevals > max_maxevals && throw(ArgumentError("`maxevals` can't be larger than $(max_maxevals) in `suave`, found $(maxevals)"))
return dointegrate(Suave(integrand, userdata, ndim, ncomp, Int64(nvec), Cdouble(rtol_),
Cdouble(atol_), flags, seed, trunc(Int64, minevals),
trunc(Int64, maxevals), Int64(nnew), Int64(nmin),
Expand Down
4 changes: 4 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ end
Cuba.KEY, Cuba.STATEFILE, Cuba.SPIN))))
end

@testset "Misc" begin
# https://github.com/giordano/Cuba.jl/issues/27
@test_throws ArgumentError suave((x,f) -> f[1] = 1; maxevals=typemax(Int64)÷2 + 1)
end

# Make sure these functions don't crash.
Cuba.init(C_NULL, C_NULL)
Expand Down

0 comments on commit 0e80be4

Please sign in to comment.