Skip to content

Commit 86b2911

Browse files
Merge pull request #264 from kishore-nori/array-gl-fix
Small fix for composite Gauss-Legendre quadrature with array-valued integrands
2 parents 7927a46 + 6b4b031 commit 86b2911

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

ext/IntegralsFastGaussQuadratureExt.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ function gauss_legendre(f::F, p, lb, ub, nodes, weights) where {F}
2626
end
2727
function composite_gauss_legendre(f::F, p, lb, ub, nodes, weights, subintervals) where {F}
2828
h = (ub - lb) / subintervals
29-
I = zero(h)
30-
for i in 1:subintervals
31-
_lb = lb + (i - 1) * h
29+
I = gauss_legendre(f, p, lb, lb + h, nodes, weights)
30+
for i in 1:subintervals-1
31+
_lb = lb + i * h
3232
_ub = _lb + h
3333
I += gauss_legendre(f, p, _lb, _ub, nodes, weights)
3434
end

test/derivative_tests.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ alg_req = Dict(
1515
allows_iip = false),
1616
GaussLegendre(n = 50) => (nout = Inf, min_dim = 1, max_dim = 1, allows_batch = false,
1717
allows_iip = false),
18+
GaussLegendre(n = 50, subintervals=3) => (nout = Inf, min_dim = 1, max_dim = 1, allows_batch = false,
19+
allows_iip = false),
1820
QuadGKJL() => (nout = Inf, allows_batch = true, min_dim = 1, max_dim = 1,
1921
allows_iip = true),
2022
HCubatureJL() => (nout = Inf, allows_batch = false, min_dim = 1,

test/gaussian_quadrature_tests.jl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,21 @@ sol = solve(prob, alg)
9797
alg = GaussLegendre(n = 500, subintervals = 17)
9898
sol = solve(prob, alg)
9999
@test sol.u -240.25235266303063249920743158729
100+
101+
# Gauss-Legendre with array-valued integrands
102+
prob = IntegralProblem((x,p)->[1,2], (-1,1))
103+
sol = solve(prob, GaussLegendre(;n=5))
104+
@test sol.u 2*[1,2]
105+
106+
prob = IntegralProblem((x,p)->[1 2; 3 4], (-1,1))
107+
sol = solve(prob, GaussLegendre(;n=5))
108+
@test sol.u 2*[1 2; 3 4]
109+
110+
# Composite Gauss-Legendre with array-valued integrands
111+
prob = IntegralProblem((x,p)->[1,2], (-1,1))
112+
sol = solve(prob, GaussLegendre(;n=5, subintervals=5))
113+
@test sol.u 2*[1,2]
114+
115+
prob = IntegralProblem((x,p)->[1 2; 3 4], (-1,1))
116+
sol = solve(prob, GaussLegendre(;n=5, subintervals=5))
117+
@test sol.u 2*[1 2; 3 4]

0 commit comments

Comments
 (0)