Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/DataInterpolations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ struct RegularizationSmooth{uType, tType, T, T2, N, ITP <: AbstractInterpolation
Aitp,
extrapolation_left,
extrapolation_right)
N = get_output_dim(u)
N = output_ndims(u)
new{typeof(u), typeof(t), eltype(u), typeof(λ), N, typeof(Aitp)}(
u,
û,
Expand Down Expand Up @@ -174,7 +174,7 @@ struct CurvefitCache{
pmin::pminType # optimized params
extrapolate::Bool
function CurvefitCache(u, t, m, p0, ub, lb, alg, pmin, extrapolate)
N = get_output_dim(u)
N = output_ndims(u)
new{typeof(u), typeof(t), typeof(m),
typeof(p0), typeof(ub), typeof(lb),
typeof(alg), typeof(pmin), eltype(u), N}(u,
Expand Down
4 changes: 2 additions & 2 deletions src/integral_inverses.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ struct LinearInterpolationIntInv{uType, tType, itpType, T, N} <:
iguesser::Guesser{tType}
itp::itpType
function LinearInterpolationIntInv(u, t, A)
N = get_output_dim(u)
N = output_ndims(u)
new{typeof(u), typeof(t), typeof(A), eltype(u), N}(
u, t, A.extrapolation_left, A.extrapolation_right, Guesser(t), A)
end
Expand Down Expand Up @@ -94,7 +94,7 @@ struct ConstantInterpolationIntInv{uType, tType, itpType, T, N} <:
iguesser::Guesser{tType}
itp::itpType
function ConstantInterpolationIntInv(u, t, A)
N = get_output_dim(u)
N = output_ndims(u)
new{typeof(u), typeof(t), typeof(A), eltype(u), N}(
u, t, A.extrapolation_left, A.extrapolation_right, Guesser(t), A
)
Expand Down
22 changes: 11 additions & 11 deletions src/interpolation_caches.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ struct LinearInterpolation{uType, tType, IType, pType, T, N} <: AbstractInterpol
function LinearInterpolation(u, t, I, p, extrapolation_left, extrapolation_right,
cache_parameters, assume_linear_t)
linear_lookup = seems_linear(assume_linear_t, t)
N = get_output_dim(u)
N = output_ndims(u)
new{typeof(u), typeof(t), typeof(I), typeof(p.slope), eltype(u), N}(
u, t, I, p, extrapolation_left, extrapolation_right,
Guesser(t), cache_parameters, linear_lookup)
Expand Down Expand Up @@ -111,7 +111,7 @@ struct QuadraticInterpolation{uType, tType, IType, pType, T, N} <:
mode ∈ (:Forward, :Backward) ||
error("mode should be :Forward or :Backward for QuadraticInterpolation")
linear_lookup = seems_linear(assume_linear_t, t)
N = get_output_dim(u)
N = output_ndims(u)
new{typeof(u), typeof(t), typeof(I), typeof(p.α), eltype(u), N}(
u, t, I, p, mode, extrapolation_left, extrapolation_right,
Guesser(t), cache_parameters, linear_lookup)
Expand Down Expand Up @@ -175,7 +175,7 @@ struct LagrangeInterpolation{uType, tType, T, bcacheType, N} <:
bcache = zeros(eltype(u[1]), n + 1)
idxs = zeros(Int, n + 1)
fill!(bcache, NaN)
N = get_output_dim(u)
N = output_ndims(u)
new{typeof(u), typeof(t), eltype(u), typeof(bcache), N}(u,
t,
n,
Expand Down Expand Up @@ -246,7 +246,7 @@ struct AkimaInterpolation{uType, tType, IType, bType, cType, dType, T, N} <:
u, t, I, b, c, d, extrapolation_left,
extrapolation_right, cache_parameters, assume_linear_t)
linear_lookup = seems_linear(assume_linear_t, t)
N = get_output_dim(u)
N = output_ndims(u)
new{typeof(u), typeof(t), typeof(I), typeof(b), typeof(c),
typeof(d), eltype(u), N}(u,
t,
Expand Down Expand Up @@ -343,7 +343,7 @@ struct ConstantInterpolation{uType, tType, IType, T, N} <: AbstractInterpolation
u, t, I, dir, extrapolation_left, extrapolation_right,
cache_parameters, assume_linear_t)
linear_lookup = seems_linear(assume_linear_t, t)
N = get_output_dim(u)
N = output_ndims(u)
new{typeof(u), typeof(t), typeof(I), eltype(u), N}(
u, t, I, nothing, dir, extrapolation_left, extrapolation_right,
Guesser(t), cache_parameters, linear_lookup)
Expand Down Expand Up @@ -411,7 +411,7 @@ struct QuadraticSpline{uType, tType, IType, pType, kType, cType, scType, T, N} <
u, t, I, p, k, c, sc, extrapolation_left,
extrapolation_right, cache_parameters, assume_linear_t)
linear_lookup = seems_linear(assume_linear_t, t)
N = get_output_dim(u)
N = output_ndims(u)
new{typeof(u), typeof(t), typeof(I), typeof(p.α), typeof(k),
typeof(c), typeof(sc), eltype(u), N}(u,
t,
Expand Down Expand Up @@ -532,7 +532,7 @@ struct CubicSpline{uType, tType, IType, pType, hType, zType, T, N} <:
function CubicSpline(u, t, I, p, h, z, extrapolation_left,
extrapolation_right, cache_parameters, assume_linear_t)
linear_lookup = seems_linear(assume_linear_t, t)
N = get_output_dim(u)
N = output_ndims(u)
new{typeof(u), typeof(t), typeof(I), typeof(p.c₁),
typeof(h), typeof(z), eltype(u), N}(
u,
Expand Down Expand Up @@ -713,7 +713,7 @@ struct BSplineInterpolation{uType, tType, pType, kType, cType, scType, T, N} <:
extrapolation_right,
assume_linear_t)
linear_lookup = seems_linear(assume_linear_t, t)
N = get_output_dim(u)
N = output_ndims(u)
new{typeof(u), typeof(t), typeof(p), typeof(k), typeof(c), typeof(sc), eltype(u), N}(
u,
t,
Expand Down Expand Up @@ -948,7 +948,7 @@ struct BSplineApprox{uType, tType, pType, kType, cType, scType, T, N} <:
assume_linear_t
)
linear_lookup = seems_linear(assume_linear_t, t)
N = get_output_dim(u)
N = output_ndims(u)
new{typeof(u), typeof(t), typeof(p), typeof(k), typeof(c), typeof(sc), eltype(u), N}(
u,
t,
Expand Down Expand Up @@ -1208,7 +1208,7 @@ struct CubicHermiteSpline{uType, tType, IType, duType, pType, T, N} <:
du, u, t, I, p, extrapolation_left, extrapolation_right,
cache_parameters, assume_linear_t)
linear_lookup = seems_linear(assume_linear_t, t)
N = get_output_dim(u)
N = output_ndims(u)
new{typeof(u), typeof(t), typeof(I), typeof(du), typeof(p.c₁), eltype(u), N}(
du, u, t, I, p, extrapolation_left, extrapolation_right,
Guesser(t), cache_parameters, linear_lookup)
Expand Down Expand Up @@ -1312,7 +1312,7 @@ struct QuinticHermiteSpline{uType, tType, IType, duType, dduType, pType, T, N} <
ddu, du, u, t, I, p, extrapolation_left,
extrapolation_right, cache_parameters, assume_linear_t)
linear_lookup = seems_linear(assume_linear_t, t)
N = get_output_dim(u)
N = output_ndims(u)
new{typeof(u), typeof(t), typeof(I), typeof(du),
typeof(ddu), typeof(p.c₁), eltype(u), N}(
ddu, du, u, t, I, p, extrapolation_left, extrapolation_right,
Expand Down
17 changes: 5 additions & 12 deletions src/interpolation_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,11 @@ function spline_coefficients!(N, d, k, u::AbstractVector)
return nothing
end

# Get Output Dimension for parameterizing AbstractInterpolations
function get_output_dim(u::AbstractVector{<:Number})
return (1,)
end

function get_output_dim(u::AbstractVector)
return (length(first(u)),)
end

function get_output_dim(u::AbstractArray)
return size(u)[1:(end - 1)]
end
# Get the number of dimensions `ndims(interp(x))` of the interpolation `interp` evaluated at a single input `x`
# It is derived from the set of values `u` at the interpolation nodes
output_ndims(::AbstractVector) = 0 # each value is a scalar
output_ndims(::AbstractVector{<:AbstractArray{<:Any, N}}) where {N} = N # each value is an array but values are not stacked
output_ndims(::AbstractArray{<:Any, N}) where {N} = N - 1 # each value is an array but multiple values are stacked

function quadratic_spline_params(t::AbstractVector, sc::AbstractVector)

Expand Down
Loading
Loading