Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions test/gaussian_quadrature_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ alg = GaussLegendre(nodes = nd, weights = wt, subintervals = 20)
@test alg.subintervals == 20

f = (x, p) -> 5x + sin(x) - p * exp(x)
prob = IntegralProblem(f, -5, 3, 3.3)
prob = IntegralProblem(f, (-5, 3), 3.3)
alg = GaussLegendre()
sol = solve(prob, alg)
@test isnothing(sol.chi)
Expand All @@ -60,7 +60,7 @@ sol = solve(prob, alg)
@test sol.u ≈ -exp(3) * 3.3 + 3.3 / exp(5) - 40 + cos(5) - cos(3)

f = (x, p) -> exp(-x^2)
prob = IntegralProblem(f, 0.0, Inf)
prob = IntegralProblem(f, (0.0, Inf))
alg = GaussLegendre()
sol = solve(prob, alg)
@test sol.u ≈ sqrt(π) / 2
Expand All @@ -69,7 +69,7 @@ alg = GaussLegendre(subintervals = 1)
alg = GaussLegendre(subintervals = 17)
@test sol.u ≈ sqrt(π) / 2

prob = IntegralProblem(f, -Inf, Inf)
prob = IntegralProblem(f, (-Inf, Inf))
alg = GaussLegendre()
sol = solve(prob, alg)
@test sol.u ≈ sqrt(π)
Expand All @@ -78,7 +78,7 @@ alg = GaussLegendre(subintervals = 1)
alg = GaussLegendre(subintervals = 17)
@test sol.u ≈ sqrt(π)

prob = IntegralProblem(f, -Inf, 0.0)
prob = IntegralProblem(f, (-Inf, 0.0))
alg = GaussLegendre()
sol = solve(prob, alg)
@test sol.u ≈ sqrt(π) / 2
Expand All @@ -90,7 +90,7 @@ alg = GaussLegendre(subintervals = 17)
# Make sure broadcasting correctly handles the argument p
f = (x, p) -> 1 + x + x^p[1] - cos(x * p[2]) + exp(x) * p[3]
p = [0.3, 1.3, -0.5]
prob = IntegralProblem(f, 2.0, 6.3, p)
prob = IntegralProblem(f, (2.0, 6.3), p)
alg = GaussLegendre()
sol = solve(prob, alg)
@test sol.u ≈ -240.25235266303063249920743158729
Expand Down
48 changes: 22 additions & 26 deletions test/interface_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ end
continue
end
for i in 1:length(integrands)
prob = IntegralProblem(integrands[i], lb, ub)
prob = IntegralProblem(integrands[i], (lb, ub))
@info "Alg = $(nameof(typeof(alg))), Integrand = $i, Dimension = $dim, Output Dimension = $nout"
sol = @inferred solve(prob, alg, reltol = reltol, abstol = abstol)
@test sol.alg == alg
Expand All @@ -118,7 +118,7 @@ end
for i in 1:length(integrands)
for dim in 1:max_dim_test
lb, ub = (ones(dim), 3ones(dim))
prob = IntegralProblem(integrands[i], lb, ub)
prob = IntegralProblem(integrands[i], (lb, ub))
if dim > req.max_dim || dim < req.min_dim
continue
end
Expand All @@ -137,7 +137,7 @@ end
for i in 1:length(iip_integrands)
for dim in 1:max_dim_test
lb, ub = (ones(dim), 3ones(dim))
prob = IntegralProblem(iip_integrands[i], lb, ub)
prob = IntegralProblem(iip_integrands[i], (lb, ub))
if dim > req.max_dim || dim < req.min_dim || !req.allows_iip
continue
end
Expand All @@ -159,7 +159,7 @@ end
(dim, nout) = (1, 1)
for (alg, req) in pairs(alg_req)
for i in 1:length(integrands)
prob = IntegralProblem(batch_f(integrands[i]), lb, ub, batch = 1000)
prob = IntegralProblem(BatchIntegralFunction(batch_f(integrands[i])), (lb, ub))
if req.min_dim > 1 || !req.allows_batch
continue
end
Expand All @@ -177,7 +177,7 @@ end
for i in 1:length(integrands)
for dim in 1:max_dim_test
(lb, ub) = (ones(dim), 3ones(dim))
prob = IntegralProblem(batch_f(integrands[i]), lb, ub, batch = 1000)
prob = IntegralProblem(BatchIntegralFunction(batch_f(integrands[i])), (lb, ub))
if dim > req.max_dim || dim < req.min_dim || !req.allows_batch
continue
end
Expand All @@ -200,7 +200,7 @@ end
for i in 1:length(iip_integrands)
for dim in 1:max_dim_test
(lb, ub) = (ones(dim), 3ones(dim))
prob = IntegralProblem(batch_iip_f(integrands[i]), lb, ub, batch = 1000)
prob = IntegralProblem(BatchIntegralFunction(batch_iip_f(integrands[i]), zeros(0)), (lb, ub))
if dim > req.max_dim || dim < req.min_dim || !req.allows_batch ||
!req.allows_iip
continue
Expand All @@ -225,10 +225,10 @@ end
for (alg, req) in pairs(alg_req)
for i in 1:length(integrands_v)
for nout in 1:max_nout_test
prob = IntegralProblem(let f = integrands_v[i], nout = nout
(x, p) -> f(x, p, nout)
end, lb, ub,
nout = nout)
integrand_f = let f = integrands_v[i], nout = nout
IntegralFunction((x, p) -> f(x, p, nout), zeros(nout))
end
prob = IntegralProblem(integrand_f, (lb, ub))
if req.min_dim > 1 || req.nout < nout
continue
end
Expand All @@ -254,10 +254,10 @@ end
if dim > req.max_dim || dim < req.min_dim || req.nout < nout
continue
end
prob = IntegralProblem(let f = integrands_v[i], nout = nout
(x, p) -> f(x, p, nout)
end, lb, ub,
nout = nout)
integrand_f = let f = integrands_v[i], nout = nout
IntegralFunction((x, p) -> f(x, p, nout), zeros(nout))
end
prob = IntegralProblem(integrand_f, (lb, ub))
@info "Alg = $(nameof(typeof(alg))), Integrand = $i, Dimension = $dim, Output Dimension = $nout"
sol = @inferred solve(prob, alg, reltol = reltol, abstol = abstol)
@test sol.alg == alg
Expand All @@ -278,10 +278,10 @@ end
for dim in 1:max_dim_test
lb, ub = (ones(dim), 3ones(dim))
for nout in 1:max_nout_test
prob = IntegralProblem(let f = iip_integrands_v[i]
(dx, x, p) -> f(dx, x, p, nout)
end,
lb, ub, nout = nout)
integrand_f = let f = iip_integrands_v[i]
IntegralFunction((dx, x, p) -> f(dx, x, p, nout), zeros(nout))
end
prob = IntegralProblem(integrand_f, (lb, ub))
if dim > req.max_dim || dim < req.min_dim || req.nout < nout ||
!req.allows_iip
continue
Expand All @@ -305,8 +305,7 @@ end
(dim, nout) = (1, 2)
for (alg, req) in pairs(alg_req)
for i in 1:length(integrands_v)
prob = IntegralProblem(batch_f_v(integrands_v[i], nout), lb, ub, batch = 1000,
nout = nout)
prob = IntegralProblem(BatchIntegralFunction(batch_f_v(integrands_v[i], nout)), (lb, ub))
if req.min_dim > 1 || !req.allows_batch || req.nout < nout
continue
end
Expand All @@ -324,9 +323,7 @@ end
for i in 1:length(integrands_v)
for dim in 1:max_dim_test
(lb, ub) = (ones(dim), 3ones(dim))
prob = IntegralProblem(batch_f_v(integrands_v[i], nout), lb, ub,
batch = 1000,
nout = nout)
prob = IntegralProblem(BatchIntegralFunction(batch_f_v(integrands_v[i], nout)), (lb, ub))
if dim > req.max_dim || dim < req.min_dim || !req.allows_batch ||
req.nout < nout
continue
Expand All @@ -346,8 +343,7 @@ end
for i in 1:length(iip_integrands_v)
for dim in 1:max_dim_test
(lb, ub) = (ones(dim), 3ones(dim))
prob = IntegralProblem(batch_iip_f_v(integrands_v[i], nout), lb, ub,
batch = 10, nout = nout)
prob = IntegralProblem(BatchIntegralFunction(batch_iip_f_v(integrands_v[i], nout), zeros(nout, 0)), (lb, ub))
if dim > req.max_dim || dim < req.min_dim || !req.allows_batch ||
!req.allows_iip || req.nout < nout
continue
Expand Down Expand Up @@ -381,7 +377,7 @@ end
continue
end
for i in 1:length(integrands)
prob = IntegralProblem(integrands[i], lb, ub, p)
prob = IntegralProblem(integrands[i], (lb, ub), p)
cache = init(prob, alg, reltol = reltol, abstol = abstol)
@test solve!(cache).u≈exact_sol[i](dim, nout, lb, ub) rtol=1e-2
cache.lb = lb = 0.5
Expand Down
8 changes: 4 additions & 4 deletions test/nested_ad_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ using Integrals, FiniteDiff, ForwardDiff, Cubature, Cuba, Zygote, Test
my_parameters = [1.0, 2.0]
my_function(x, p) = x^2 + p[1]^3 * x + p[2]^2
function my_integration(p)
my_problem = IntegralProblem(my_function, -1.0, 1.0, p)
my_problem = IntegralProblem(my_function, (-1.0, 1.0), p)
# return solve(my_problem, HCubatureJL(), reltol=1e-3, abstol=1e-3) # Works
return solve(my_problem, CubatureJLh(), reltol = 1e-3, abstol = 1e-3) # Errors
end
Expand All @@ -19,7 +19,7 @@ ub = 3ones(2)
p = [1.5, 2.0]

function testf(p)
prob = IntegralProblem(ff, lb, ub, p)
prob = IntegralProblem(ff, (lb, ub), p)
sin(solve(prob, CubaCuhre(), reltol = 1e-6, abstol = 1e-6)[1])
end

Expand All @@ -32,10 +32,10 @@ lb = 1.0
ub = 3.0
p = [2.0, 3.0, 4.0]
_ff3 = BatchIntegralFunction(ff2)
prob = IntegralProblem(_ff3, lb, ub, p)
prob = IntegralProblem(_ff3, (lb, ub), p)

function testf3(lb, ub, p; f = _ff3)
prob = IntegralProblem(_ff3, lb, ub, p)
prob = IntegralProblem(_ff3, (lb, ub), p)
solve(prob, CubatureJLh(); reltol = 1e-3, abstol = 1e-3)[1]
end

Expand Down
10 changes: 5 additions & 5 deletions test/quadrule_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ lb = -1.2
ub = 3.5
p = 2.0

prob = IntegralProblem(f, lb, ub, p)
prob = IntegralProblem(f, (lb, ub), p)
u = solve(prob, alg).u

@test u≈exact_f(lb, ub, p) rtol=1e-3
Expand All @@ -49,7 +49,7 @@ lb = SVector(-1.2, -1.0)
ub = SVector(3.5, 3.7)
p = 1.2

prob = IntegralProblem(f, lb, ub, p)
prob = IntegralProblem(f, (lb, ub), p)
u = solve(prob, alg).u

@test u≈exact_f(lb, ub, p) rtol=1e-3
Expand All @@ -64,7 +64,7 @@ lb = -Inf
ub = Inf
p = 1.0

prob = IntegralProblem(g, lb, ub, p)
prob = IntegralProblem(g, (lb, ub), p)

@test solve(prob, alg).u≈pi rtol=1e-4

Expand All @@ -78,7 +78,7 @@ lb = -Inf
ub = Inf
p = (1.0, 1.3)

prob = IntegralProblem(g2, lb, ub, p)
prob = IntegralProblem(g2, (lb, ub), p)

@test solve(prob, alg).u≈[pi, pi] rtol=1e-4

Expand All @@ -87,7 +87,7 @@ prob = IntegralProblem(g2, lb, ub, p)
using Zygote

function testf(lb, ub, p, f = f)
prob = IntegralProblem(f, lb, ub, p)
prob = IntegralProblem(f, (lb, ub), p)
solve(prob, QuadratureRule(trapz, n=200))[1]
end

Expand Down
Loading