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

Remove output dimension type parameter and add output_dim to API #396

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "DataInterpolations"
uuid = "82cc6244-b520-54b8-b5a6-8a565e85f1d0"
version = "7.2.0"
version = "8.0.0"

[deps]
EnumX = "4e289a0a-7415-4d19-859d-a7e5c4648b56"
Expand Down
2 changes: 0 additions & 2 deletions docs/Project.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
[deps]
DataInterpolations = "82cc6244-b520-54b8-b5a6-8a565e85f1d0"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
ModelingToolkit = "961ee093-0014-501f-94e3-6117800e7a78"
ModelingToolkitStandardLibrary = "16a59e39-deab-5bd0-87e4-056b12336739"
Expand All @@ -11,7 +10,6 @@ StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3"
Symbolics = "0c5d862f-8b57-4792-8d23-62f2024744c7"

[compat]
DataInterpolations = "6, 7.0"
Documenter = "1"
ModelingToolkit = "9"
ModelingToolkitStandardLibrary = "2"
Expand Down
1 change: 1 addition & 0 deletions docs/src/manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ QuinticHermiteSpline

```@docs
DataInterpolations.looks_linear
DataInterpolations.output_dim
```
29 changes: 19 additions & 10 deletions src/DataInterpolations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module DataInterpolations

### Interface Functionality

abstract type AbstractInterpolation{T, N} end
abstract type AbstractInterpolation{T} end

using LinearAlgebra, RecipesBase
using PrettyTables
Expand Down Expand Up @@ -98,16 +98,28 @@ function Base.showerror(io::IO, ::ExtrapolationNotImplementedError)
print(io, EXTRAPOLATION_NOT_IMPLEMENTED_ERROR)
end

"""
output_dim(x::AbstractInterpolation)

Return the number of dimension `ndims(x(t))` of interpolation `x` evaluated at a single value `t`
if `x(t) isa AbstractArray`, or 0 otherwise.
"""
output_dim(x::AbstractInterpolation) = _output_dim(x.u)
_output_dim(::AbstractVector) = 0 # each value is a scalar
_output_dim(::AbstractVector{<:AbstractArray{<:Any, N}}) where {N} = N # each value is an array but values are not stacked
_output_dim(::AbstractArray{<:Any, N}) where {N} = N - 1 # each value is an array but multiple values are stacked

export LinearInterpolation, QuadraticInterpolation, LagrangeInterpolation,
AkimaInterpolation, ConstantInterpolation, QuadraticSpline, CubicSpline,
BSplineInterpolation, BSplineApprox, CubicHermiteSpline, PCHIPInterpolation,
QuinticHermiteSpline, LinearInterpolationIntInv, ConstantInterpolationIntInv,
ExtrapolationType
export output_dim

# added for RegularizationSmooth, JJS 11/27/21
### Regularization data smoothing and interpolation
struct RegularizationSmooth{uType, tType, T, T2, N, ITP <: AbstractInterpolation{T, N}} <:
AbstractInterpolation{T, N}
struct RegularizationSmooth{uType, tType, T, T2, ITP <: AbstractInterpolation{T}} <:
AbstractInterpolation{T}
u::uType
û::uType
t::tType
Expand All @@ -132,8 +144,7 @@ struct RegularizationSmooth{uType, tType, T, T2, N, ITP <: AbstractInterpolation
Aitp,
extrapolation_left,
extrapolation_right)
N = get_output_dim(u)
new{typeof(u), typeof(t), eltype(u), typeof(λ), N, typeof(Aitp)}(
new{typeof(u), typeof(t), eltype(u), typeof(λ), typeof(Aitp)}(
u,
û,
t,
Expand Down Expand Up @@ -161,9 +172,8 @@ struct CurvefitCache{
lbType,
algType,
pminType,
T,
N
} <: AbstractInterpolation{T, N}
T
} <: AbstractInterpolation{T}
u::uType
t::tType
m::mType # model type
Expand All @@ -174,10 +184,9 @@ struct CurvefitCache{
pmin::pminType # optimized params
extrapolate::Bool
function CurvefitCache(u, t, m, p0, ub, lb, alg, pmin, extrapolate)
N = get_output_dim(u)
new{typeof(u), typeof(t), typeof(m),
typeof(p0), typeof(ub), typeof(lb),
typeof(alg), typeof(pmin), eltype(u), N}(u,
typeof(alg), typeof(pmin), eltype(u)}(u,
t,
m,
p0,
Expand Down
4 changes: 2 additions & 2 deletions src/derivatives.jl
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ function _derivative(A::BSplineInterpolation{<:AbstractVector{<:Number}}, t::Num
end

function _derivative(
A::BSplineInterpolation{<:AbstractArray{<:Number, N}}, t::Number, iguess) where {N}
A::BSplineInterpolation{<:AbstractArray{<:Number}}, t::Number, iguess)
# change t into param [0 1]
ax_u = axes(A.u)[1:(end - 1)]
t < A.t[1] && return zeros(size(A.u)[1:(end - 1)]...)
Expand Down Expand Up @@ -254,7 +254,7 @@ function _derivative(A::BSplineApprox{<:AbstractVector{<:Number}}, t::Number, ig
end

function _derivative(
A::BSplineApprox{<:AbstractArray{<:Number, N}}, t::Number, iguess) where {N}
A::BSplineApprox{<:AbstractArray{<:Number}}, t::Number, iguess)
# change t into param [0 1]
ax_u = axes(A.u)[1:(end - 1)]
t < A.t[1] && return zeros(size(A.u)[1:(end - 1)]...)
Expand Down
16 changes: 7 additions & 9 deletions src/integral_inverses.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
abstract type AbstractIntegralInverseInterpolation{T, N} <: AbstractInterpolation{T, N} end
abstract type AbstractIntegralInverseInterpolation{T} <: AbstractInterpolation{T} end

"""
invert_integral(A::AbstractInterpolation)::AbstractIntegralInverseInterpolation
Expand Down Expand Up @@ -33,17 +33,16 @@ Can be easily constructed with `invert_integral(A::LinearInterpolation{<:Abstrac
- `t` : Given by `A.I` (the cumulative integral of `A`)
- `A` : The `LinearInterpolation` object
"""
struct LinearInterpolationIntInv{uType, tType, itpType, T, N} <:
AbstractIntegralInverseInterpolation{T, N}
struct LinearInterpolationIntInv{uType, tType, itpType, T} <:
AbstractIntegralInverseInterpolation{T}
u::uType
t::tType
extrapolation_left::ExtrapolationType.T
extrapolation_right::ExtrapolationType.T
iguesser::Guesser{tType}
itp::itpType
function LinearInterpolationIntInv(u, t, A)
N = get_output_dim(u)
new{typeof(u), typeof(t), typeof(A), eltype(u), N}(
new{typeof(u), typeof(t), typeof(A), eltype(u)}(
u, t, A.extrapolation_left, A.extrapolation_right, Guesser(t), A)
end
end
Expand Down Expand Up @@ -85,17 +84,16 @@ Can be easily constructed with `invert_integral(A::ConstantInterpolation{<:Abstr
- `t` : Given by `A.I` (the cumulative integral of `A`)
- `A` : The `ConstantInterpolation` object
"""
struct ConstantInterpolationIntInv{uType, tType, itpType, T, N} <:
AbstractIntegralInverseInterpolation{T, N}
struct ConstantInterpolationIntInv{uType, tType, itpType, T} <:
AbstractIntegralInverseInterpolation{T}
u::uType
t::tType
extrapolation_left::ExtrapolationType.T
extrapolation_right::ExtrapolationType.T
iguesser::Guesser{tType}
itp::itpType
function ConstantInterpolationIntInv(u, t, A)
N = get_output_dim(u)
new{typeof(u), typeof(t), typeof(A), eltype(u), N}(
new{typeof(u), typeof(t), typeof(A), eltype(u)}(
u, t, A.extrapolation_left, A.extrapolation_right, Guesser(t), A
)
end
Expand Down
Loading
Loading