JuliaMath / QuadGK.jl

adaptive 1d numerical Gauss–Kronrod integration in Julia
MIT License
268 stars 37 forks source link

Regression with QuadGK@2.9 #89

Closed sathvikbhagavan closed 11 months ago

sathvikbhagavan commented 11 months ago

An issue was caught in https://github.com/SciML/DataInterpolations.jl/pull/178 where tests started failing with QuadGK@2.9

I have made a MWE to illustrate the issue (using a simple LinearInterpolation from DataInterpolations):

u = collect(0:10)
t = collect(0:10)
A = LinearInterpolation(u,t)
qint, err = quadgk(A, 0.0, 10.0)

It is a straight line with slope 1. So the integral should be 50.0.

image

with QuadGK@2.8

julia> qint, err = quadgk(A, 0.0, 10.0)
(50.0, 0.0)

with QuadGK@2.9

julia> qint, err = quadgk(A, 0.0, 10.0)
(51.76911234248546, 4.274582013885939)
stevengj commented 11 months ago

cc @lxvm

stevengj commented 11 months ago

Seems to be a dispatch problem, since passing the argument as a function works:

julia> quadgk(A, 0.0, 10.0)
(51.76911234248546, 4.274582013885939)

julia> quadgk(t -> A(t), 0.0, 10.0)
(50.0, 0.0)
stevengj commented 11 months ago

Okay, the problem is that LinearInterpolation is a subtype of AbstractVector, so it is calling the wrong method of QuadGK.evalrule.

lxvm commented 11 months ago

Right, I can rename evalrule(::AbstractVector,...) to batchevalrule to fix the issue

stevengj commented 11 months ago

Should be fixed by #90. Will merge and tag when green.

lxvm commented 11 months ago

Thanks!