Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ConstantInterpolation Extrapolation #387

Closed

Conversation

SouthEndMusic
Copy link
Member

@SouthEndMusic SouthEndMusic commented Feb 4, 2025

Fixes #378

I started working on this but then I found out this was already fxed by @DaniGlez in #379, but the issue wasn't closed. I did some nitpicking taking into account the dir of the ConstantInterpolation and the edgecase that there is only 1 datapoint.

On a more general note, I see that we use first and last a lot (also in this PR) which only works properly if u is a vector (or at least indexed as such). We also have specialized methods for vector versus matrix u. To ensure consistency and avoid code duplication, should we define custom indexing functions based on the type of u?

@ChrisRackauckas
Copy link
Member

Add a test for this case?

@DaniGlez
Copy link
Contributor

DaniGlez commented Feb 4, 2025

Yeah, it probably makes sense to close the issue, I forgot to use the magic keywords in the PR. Regarding this PR, the only issue I see is that this is consistent with the first / last open interval, but not with evaluation at the edge point, right? Currently, evaluation of a ConstantInterpolation at an edge point always returns the edge value regardless of extrapolation and dir settings.

julia> using DataInterpolations
julia> u = [2, 3];
julia> t = [0.0, 1.0];

julia> ConstantInterpolation(u, t; dir=:left)(t)
2-element Vector{Float64}:
 2.0
 3.0

julia> ConstantInterpolation(u, t; dir=:right)(t)
2-element Vector{Float64}:
 2.0
 3.0

Incidentally I just realized there seems to be another eltype bug with vector inputs:

julia> ConstantInterpolation(u, t; dir=:right)(t)
2-element Vector{Float64}:
 2.0
 3.0

julia> ConstantInterpolation(u, t; dir=:right).(t)
2-element Vector{Int64}:
 2
 3

@SouthEndMusic
Copy link
Member Author

@DaniGlez Thanks for pointing out that boundary evaluation behaviour, I made a wrong assumption about it. Then this PR doesn't make sense.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Broken extrapolation with integer interpolation
3 participants