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
LinearInterpolation handles collect(x) but not CubicSplineInterplation #383
Comments
The difficulty appears to be in
Also providing |
New maintainer here. Part of the reason for this is that Now we might be able to do something where we check to see if your I just want to be clear on your needs though. Is the |
Speaking for myself, it is almost certain that AbstractVector will be irregular (nonuniformly spaced) some of the time. [glad to see you picking this up ⛵ ] |
If it is irregular, then it is not immediately clear what to do. In that case, this is a duplicate of #131 . |
@mkitti thanks for picking this up. For now, my AbstractVector is from an AbstractRange. |
Here is the function to convert an using Statistics
function vector2range(r::AbstractVector)
r_diff = @view(r[2:end]) .- @view(r[1:end-1])
r_diff_mean = mean(r_diff)
@assert all( r_diff .≈ r_diff_mean ) "Step between vector elements must be consistent"
return range(r[1], step = r_diff_mean, stop = r[end])
end Here's the usage: julia> vector2range( [1, 2, 5, 9] )
ERROR: AssertionError: Step between vector elements must be consistent
Stacktrace:
[1] vector2range(::Array{Int64,1}) at .\REPL[142]:4
[2] top-level scope at REPL[143]:1
julia> vector2range( collect(3:0.5:353) )
3.0:0.5:353.0 |
Awesome! I was looking for something like this. Works great. Alternatively, |
Here are the extended methods: julia> using Interpolations
julia> import Interpolations: CubicSplineInterpolation
julia> CubicSplineInterpolation(range::AbstractVector, vs::AbstractVector; kwargs...) =
CubicSplineInterpolation(vector2range(range), vs ; kwargs...)
CubicSplineInterpolation (generic function with 4 methods)
julia> CubicSplineInterpolation(ranges::NTuple{N,AbstractVector}, vs::AbstractArray{T,N}; kwargs...) where {N,T} =
CubicSplineInterpolation(vector2range.(ranges), vs ; kwargs...)
CubicSplineInterpolation (generic function with 4 methods) and the usage: julia> v = 1:0.1:10
1.0:0.1:10.0
julia> cv = collect(v);
julia> CubicSplineInterpolation( v, v .+ 1);
julia> CubicSplineInterpolation( cv, v .+ 1);
julia> CubicSplineInterpolation( (v,v) , v*v' );
julia> CubicSplineInterpolation( (cv,cv) , v*v' ); |
CubicSplineInterpolation does not handle collect(), Yet LinearInterpolation does --- see minimal example below. Any suggestions on how to address this?
The text was updated successfully, but these errors were encountered: