Skip to content

Commit bfcbae1

Browse files
Merge pull request #396 from SciML/dw/no_output_dim
Remove output dimension type parameter and add `output_dim` to API
2 parents 4a337ac + 1f9b840 commit bfcbae1

10 files changed

+231
-173
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "DataInterpolations"
22
uuid = "82cc6244-b520-54b8-b5a6-8a565e85f1d0"
3-
version = "7.2.0"
3+
version = "8.0.0"
44

55
[deps]
66
EnumX = "4e289a0a-7415-4d19-859d-a7e5c4648b56"

docs/Project.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
[deps]
2-
DataInterpolations = "82cc6244-b520-54b8-b5a6-8a565e85f1d0"
32
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
43
ModelingToolkit = "961ee093-0014-501f-94e3-6117800e7a78"
54
ModelingToolkitStandardLibrary = "16a59e39-deab-5bd0-87e4-056b12336739"
@@ -11,7 +10,6 @@ StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3"
1110
Symbolics = "0c5d862f-8b57-4792-8d23-62f2024744c7"
1211

1312
[compat]
14-
DataInterpolations = "6, 7.0"
1513
Documenter = "1"
1614
ModelingToolkit = "9"
1715
ModelingToolkitStandardLibrary = "2"

docs/src/manual.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ QuinticHermiteSpline
1919

2020
```@docs
2121
DataInterpolations.looks_linear
22+
DataInterpolations.output_dim
2223
```

src/DataInterpolations.jl

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module DataInterpolations
22

33
### Interface Functionality
44

5-
abstract type AbstractInterpolation{T, N} end
5+
abstract type AbstractInterpolation{T} end
66

77
using LinearAlgebra, RecipesBase
88
using PrettyTables
@@ -98,16 +98,28 @@ function Base.showerror(io::IO, ::ExtrapolationNotImplementedError)
9898
print(io, EXTRAPOLATION_NOT_IMPLEMENTED_ERROR)
9999
end
100100

101+
"""
102+
output_dim(x::AbstractInterpolation)
103+
104+
Return the number of dimension `ndims(x(t))` of interpolation `x` evaluated at a single value `t`
105+
if `x(t) isa AbstractArray`, or 0 otherwise.
106+
"""
107+
output_dim(x::AbstractInterpolation) = _output_dim(x.u)
108+
_output_dim(::AbstractVector) = 0 # each value is a scalar
109+
_output_dim(::AbstractVector{<:AbstractArray{<:Any, N}}) where {N} = N # each value is an array but values are not stacked
110+
_output_dim(::AbstractArray{<:Any, N}) where {N} = N - 1 # each value is an array but multiple values are stacked
111+
101112
export LinearInterpolation, QuadraticInterpolation, LagrangeInterpolation,
102113
AkimaInterpolation, ConstantInterpolation, QuadraticSpline, CubicSpline,
103114
BSplineInterpolation, BSplineApprox, CubicHermiteSpline, PCHIPInterpolation,
104115
QuinticHermiteSpline, LinearInterpolationIntInv, ConstantInterpolationIntInv,
105116
ExtrapolationType
117+
export output_dim
106118

107119
# added for RegularizationSmooth, JJS 11/27/21
108120
### Regularization data smoothing and interpolation
109-
struct RegularizationSmooth{uType, tType, T, T2, N, ITP <: AbstractInterpolation{T, N}} <:
110-
AbstractInterpolation{T, N}
121+
struct RegularizationSmooth{uType, tType, T, T2, ITP <: AbstractInterpolation{T}} <:
122+
AbstractInterpolation{T}
111123
u::uType
112124
::uType
113125
t::tType
@@ -132,8 +144,7 @@ struct RegularizationSmooth{uType, tType, T, T2, N, ITP <: AbstractInterpolation
132144
Aitp,
133145
extrapolation_left,
134146
extrapolation_right)
135-
N = get_output_dim(u)
136-
new{typeof(u), typeof(t), eltype(u), typeof(λ), N, typeof(Aitp)}(
147+
new{typeof(u), typeof(t), eltype(u), typeof(λ), typeof(Aitp)}(
137148
u,
138149
û,
139150
t,
@@ -161,9 +172,8 @@ struct CurvefitCache{
161172
lbType,
162173
algType,
163174
pminType,
164-
T,
165-
N
166-
} <: AbstractInterpolation{T, N}
175+
T
176+
} <: AbstractInterpolation{T}
167177
u::uType
168178
t::tType
169179
m::mType # model type
@@ -174,10 +184,9 @@ struct CurvefitCache{
174184
pmin::pminType # optimized params
175185
extrapolate::Bool
176186
function CurvefitCache(u, t, m, p0, ub, lb, alg, pmin, extrapolate)
177-
N = get_output_dim(u)
178187
new{typeof(u), typeof(t), typeof(m),
179188
typeof(p0), typeof(ub), typeof(lb),
180-
typeof(alg), typeof(pmin), eltype(u), N}(u,
189+
typeof(alg), typeof(pmin), eltype(u)}(u,
181190
t,
182191
m,
183192
p0,

src/derivatives.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ function _derivative(A::BSplineInterpolation{<:AbstractVector{<:Number}}, t::Num
209209
end
210210

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

256256
function _derivative(
257-
A::BSplineApprox{<:AbstractArray{<:Number, N}}, t::Number, iguess) where {N}
257+
A::BSplineApprox{<:AbstractArray{<:Number}}, t::Number, iguess)
258258
# change t into param [0 1]
259259
ax_u = axes(A.u)[1:(end - 1)]
260260
t < A.t[1] && return zeros(size(A.u)[1:(end - 1)]...)

src/integral_inverses.jl

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
abstract type AbstractIntegralInverseInterpolation{T, N} <: AbstractInterpolation{T, N} end
1+
abstract type AbstractIntegralInverseInterpolation{T} <: AbstractInterpolation{T} end
22

33
"""
44
invert_integral(A::AbstractInterpolation)::AbstractIntegralInverseInterpolation
@@ -33,17 +33,16 @@ Can be easily constructed with `invert_integral(A::LinearInterpolation{<:Abstrac
3333
- `t` : Given by `A.I` (the cumulative integral of `A`)
3434
- `A` : The `LinearInterpolation` object
3535
"""
36-
struct LinearInterpolationIntInv{uType, tType, itpType, T, N} <:
37-
AbstractIntegralInverseInterpolation{T, N}
36+
struct LinearInterpolationIntInv{uType, tType, itpType, T} <:
37+
AbstractIntegralInverseInterpolation{T}
3838
u::uType
3939
t::tType
4040
extrapolation_left::ExtrapolationType.T
4141
extrapolation_right::ExtrapolationType.T
4242
iguesser::Guesser{tType}
4343
itp::itpType
4444
function LinearInterpolationIntInv(u, t, A)
45-
N = get_output_dim(u)
46-
new{typeof(u), typeof(t), typeof(A), eltype(u), N}(
45+
new{typeof(u), typeof(t), typeof(A), eltype(u)}(
4746
u, t, A.extrapolation_left, A.extrapolation_right, Guesser(t), A)
4847
end
4948
end
@@ -85,17 +84,16 @@ Can be easily constructed with `invert_integral(A::ConstantInterpolation{<:Abstr
8584
- `t` : Given by `A.I` (the cumulative integral of `A`)
8685
- `A` : The `ConstantInterpolation` object
8786
"""
88-
struct ConstantInterpolationIntInv{uType, tType, itpType, T, N} <:
89-
AbstractIntegralInverseInterpolation{T, N}
87+
struct ConstantInterpolationIntInv{uType, tType, itpType, T} <:
88+
AbstractIntegralInverseInterpolation{T}
9089
u::uType
9190
t::tType
9291
extrapolation_left::ExtrapolationType.T
9392
extrapolation_right::ExtrapolationType.T
9493
iguesser::Guesser{tType}
9594
itp::itpType
9695
function ConstantInterpolationIntInv(u, t, A)
97-
N = get_output_dim(u)
98-
new{typeof(u), typeof(t), typeof(A), eltype(u), N}(
96+
new{typeof(u), typeof(t), typeof(A), eltype(u)}(
9997
u, t, A.extrapolation_left, A.extrapolation_right, Guesser(t), A
10098
)
10199
end

0 commit comments

Comments
 (0)