Skip to content

Broken extrapolation with integer interpolation #378

@DaniGlez

Description

@DaniGlez

I'm not sure if integer interpolation is something intended to be supported by the package; i.e. for integer u, you can define a ConstantInterpolation - other interpolations get you a non-integer by definition. If so, this is broken as of 7.0.1

julia> itp = ConstantInterpolation([1, 2], [0.0, 10.0]; extrapolation_right=ExtrapolationType.Constant)
ConstantInterpolation with 2 points, in left direction
┌──────┬─────┐
│ time │   u │
├──────┼─────┤
│  0.0 │ 1.0 │
│ 10.0 │ 2.0 │
└──────┴─────┘


julia> itp(5.0)
1

julia> itp(15.0)
2.0

The reason is that the extrapolation code path (

elseif extrapolation_left == ExtrapolationType.Constant
) does

    elseif extrapolation_right == ExtrapolationType.Constant
        slope = derivative(A, last(A.t))
        last(A.u) + zero(slope * t)

where both terms inside the zero(_) call turn into floats. Is there any drawback to just returning last(A.u) in that branch? Obviously this is fairly niche usage, but maybe there's other legitimate type combinations where analogous issues happen.

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