Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Single dim domain bounds as arrays #14

Closed
agerlach opened this issue Jun 1, 2020 · 4 comments · Fixed by #200
Closed

Single dim domain bounds as arrays #14

agerlach opened this issue Jun 1, 2020 · 4 comments · Fixed by #200

Comments

@agerlach
Copy link
Collaborator

agerlach commented Jun 1, 2020

Single dim algorithms error when integration bounds are single element arrays.

using Quadrature, Cubature, Cuba

cost(x,p) = sin.(x)

qprob = QuadratureProblem(cost,0,π; nout=1, batch=0)
sol = solve(qprob, QuadGKJL(), reltol=1e-3,abstol=1e-3)

qprob2 = QuadratureProblem(cost,[0],[π]; nout=1, batch=0)
sol2 = solve(qprob2, QuadGKJL(), reltol=1e-3,abstol=1e-3)
QuadGKJL only accepts one-dimensional quadrature problems.
error(::String) at error.jl:33
solve(::QuadratureProblem{false,DiffEqBase.NullParameters,typeof(cost),Array{Int64,1},Array{Irrational{:π},1},Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}}, ::QuadGKJL; reltol::Float64, abstol::Float64, maxiters::Int64, kwargs::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at Quadrature.jl:46
(::DiffEqBase.var"#solve##kw")(::NamedTuple{(:reltol, :abstol),Tuple{Float64,Float64}}, ::typeof(solve), ::QuadratureProblem{false,DiffEqBase.NullParameters,typeof(cost),Array{Int64,1},Array{Irrational{:π},1},Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}}, ::QuadGKJL) at Quadrature.jl:45
top-level scope at singledim_arraybounds.jl:9
@agerlach
Copy link
Collaborator Author

agerlach commented Jun 1, 2020

CubatureJLh() and CubatureJLp() have the same issues

using Quadrature, Cubature
qprob = QuadratureProblem((x,p)->sin.(x),0,π; nout=1, batch=0)
sol = solve(qprob, CubatureJLh(), reltol=1e-3,abstol=1e-3)

qprob = QuadratureProblem((x,p)->sin.(x),[0],[π]; nout=1, batch=0)
sol = solve(qprob, CubatureJLh(), reltol=1e-3,abstol=1e-3)

qprob = QuadratureProblem((x,p)->sin.(x),0,π; nout=1, batch=0)
sol = solve(qprob, CubatureJLp(), reltol=1e-3,abstol=1e-3)

qprob = QuadratureProblem((x,p)->sin.(x),[0],[π]; nout=1, batch=0)
sol = solve(qprob, CubatureJLp(), reltol=1e-3,abstol=1e-3)
MethodError: Cannot `convert` an object of type Array{Float64,1} to an object of type Float64
Closest candidates are:
  convert(::Type{T}, !Matched::T) where T<:Number at number.jl:6
  convert(::Type{T}, !Matched::Number) where T<:Number at number.jl:7
  convert(::Type{T}, !Matched::Base.TwicePrecision) where T<:Number at twiceprecision.jl:250
  ...
#17 at Cubature.jl:215 [inlined]
disable_sigint(::Cubature.var"#17#18"{Bool,Bool,Int64,Float64,Float64,Int64,Int32,Int64,Array{Float64,1},Array{Float64,1},Array{Float64,1},Array{Float64,1},Cubature.IntegrandData{Quadrature.var"#51#59"{QuadratureProblem{false,DiffEqBase.NullParameters,var"#60#61",Array{Int64,1},Array{Irrational{:π},1},Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}}}},Ptr{Nothing}}) at c.jl:446
cubature(::Bool, ::Bool, ::Bool, ::Bool, ::Int64, ::Quadrature.var"#51#59"{QuadratureProblem{false,DiffEqBase.NullParameters,var"#60#61",Array{Int64,1},Array{Irrational{:π},1},Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}}}, ::Array{Int64,1}, ::Array{Irrational{:π},1}, ::Float64, ::Float64, ::Int64, ::Int32) at Cubature.jl:169
#pcubature#26 at Cubature.jl:230 [inlined]
pcubature at Cubature.jl:230 [inlined]
solve(::QuadratureProblem{false,DiffEqBase.NullParameters,var"#60#61",Array{Int64,1},Array{Irrational{:π},1},Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}}, ::CubatureJLp; reltol::Float64, abstol::Float64, maxiters::Int64, kwargs::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at Quadrature.jl:142
(::DiffEqBase.var"#solve##kw")(::NamedTuple{(:reltol, :abstol),Tuple{Float64,Float64}}, ::typeof(solve), ::QuadratureProblem{false,DiffEqBase.NullParameters,var"#60#61",Array{Int64,1},Array{Irrational{:π},1},Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}}, ::CubatureJLp) at Quadrature.jl:117
top-level scope at cuba_vegas.jl:26

@ChrisRackauckas
Copy link
Member

Yes, all of the methods are made in such a way that scalar values are kept different from array values, where that's the difference between 1 dimensional and N-dimensional. We can definitely relax that a bit by checking if size is 1

@agerlach
Copy link
Collaborator Author

agerlach commented Jun 2, 2020

I understand that you may want to treat them different, however, both should work.

@ArnoStrouwen
Copy link
Member

I think we should get rid of the nout keyword. For oop it can be determined automatically, and for iip I think we should make the user pass a prototype of the container, currently Vector{Float64} is assumed.
But it gets complicated in the batched form, if we want to allow integration over e.g. matrix valued functions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants