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
6 changes: 3 additions & 3 deletions ext/IntegralsFastGaussQuadratureExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ function gauss_legendre(f::F, p, lb, ub, nodes, weights) where {F}
end
function composite_gauss_legendre(f::F, p, lb, ub, nodes, weights, subintervals) where {F}
h = (ub - lb) / subintervals
I = zero(h)
for i in 1:subintervals
_lb = lb + (i - 1) * h
I = gauss_legendre(f, p, lb, lb + h, nodes, weights)
for i in 1:subintervals-1
_lb = lb + i * h
_ub = _lb + h
I += gauss_legendre(f, p, _lb, _ub, nodes, weights)
end
Expand Down
2 changes: 2 additions & 0 deletions test/derivative_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ alg_req = Dict(
allows_iip = false),
GaussLegendre(n = 50) => (nout = Inf, min_dim = 1, max_dim = 1, allows_batch = false,
allows_iip = false),
GaussLegendre(n = 50, subintervals=3) => (nout = Inf, min_dim = 1, max_dim = 1, allows_batch = false,
allows_iip = false),
QuadGKJL() => (nout = Inf, allows_batch = true, min_dim = 1, max_dim = 1,
allows_iip = true),
HCubatureJL() => (nout = Inf, allows_batch = false, min_dim = 1,
Expand Down
18 changes: 18 additions & 0 deletions test/gaussian_quadrature_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,21 @@ sol = solve(prob, alg)
alg = GaussLegendre(n = 500, subintervals = 17)
sol = solve(prob, alg)
@test sol.u ≈ -240.25235266303063249920743158729

# Gauss-Legendre with array-valued integrands
prob = IntegralProblem((x,p)->[1,2], (-1,1))
sol = solve(prob, GaussLegendre(;n=5))
@test sol.u ≈ 2*[1,2]

prob = IntegralProblem((x,p)->[1 2; 3 4], (-1,1))
sol = solve(prob, GaussLegendre(;n=5))
@test sol.u ≈ 2*[1 2; 3 4]

# Composite Gauss-Legendre with array-valued integrands
prob = IntegralProblem((x,p)->[1,2], (-1,1))
sol = solve(prob, GaussLegendre(;n=5, subintervals=5))
@test sol.u ≈ 2*[1,2]

prob = IntegralProblem((x,p)->[1 2; 3 4], (-1,1))
sol = solve(prob, GaussLegendre(;n=5, subintervals=5))
@test sol.u ≈ 2*[1 2; 3 4]