Skip to content

Hidden bounds error when interacting with ForwardDiff #645

@mchitre

Description

@mchitre

Here's a MWE:

using Interpolations
using ForwardDiff

x = Float64[-3000, -2500, -2000, -1500, -1250, -1000, -900, -700, -500, -450, -370, -300, -250, -215, -200, -170, -160, -140, -100, -70, -50, -38, -35, -30, -25, -20, -15, -10, -5, 0]
y = randn(length(x))
f = linear_interpolation(x, y; extrapolation_bc=Flat())
ForwardDiff.derivative(f, 0.0)

Under normal REPL conditions, this will return:

0.2188370465131081

but when run with julia --check-bounds yes, this will throw:

ERROR: BoundsError: attempt to access 30-element interpolate((::Vector{Float64},), ::Vector{Float64}, Gridded(Linear())) with element type Float64 at index [Dual{ForwardDiff.Tag{Interpolations.Extrapolation{Float64, 1, Interpolations.GriddedInterpolation{Float64, 1, Vector{Float64}, Gridded{Linear{Throw{OnGrid}}}, Tuple{Vector{Float64}}}, Gridded{Linear{Throw{OnGrid}}}, Flat{Nothing}}, Float64}}(0.0,1.0)]
Stacktrace:
 [1] throw_boundserror(A::Interpolations.GriddedInterpolation{…}, I::Tuple{…})
   @ Base ./essentials.jl:15
 [2] GriddedInterpolation
   @ ~/.julia/packages/Interpolations/dR5oF/src/gridded/indexing.jl:3 [inlined]
 [3] Extrapolation
   @ ~/.julia/packages/Interpolations/dR5oF/src/extrapolation/extrapolation.jl:54 [inlined]
 [4] derivative(f::Interpolations.Extrapolation{…}, x::Float64)
   @ ForwardDiff ~/.julia/packages/ForwardDiff/z3jRk/src/derivative.jl:14

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions