Skip to content

Commit 95235f2

Browse files
committed
Use instances instead of types when specifying options
This opens up for actually keeping data in the options, even if that data is not of bits types (and thus not possible to include as a type parameter), for example a boundar condition Tangent(k) with an interpolation object that has eltype(itp) <: Array.
1 parent a6d4a32 commit 95235f2

23 files changed

+102
-107
lines changed

README.md

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -99,25 +99,25 @@ B-splines of quadratic or higher degree require solving an equation system to ob
9999
Some examples:
100100
```jl
101101
# Nearest-neighbor interpolation
102-
itp = interpolate(a, BSpline{Constant}, OnCell)
102+
itp = interpolate(a, BSpline(Constant()), OnCell())
103103
v = itp[5.4] # returns a[5]
104104

105105
# (Multi)linear interpolation
106-
itp = interpolate(A, BSpline{Linear}, OnGrid)
106+
itp = interpolate(A, BSpline(Linear()), OnGrid())
107107
v = itp[3.2, 4.1] # returns 0.9*(0.8*A[3,4]+0.2*A[4,4]) + 0.1*(0.8*A[3,5]+0.2*A[4,5])
108108

109109
# Quadratic interpolation with reflecting boundary conditions
110110
# Quadratic is the lowest order that has continuous gradient
111-
itp = interpolate(A, BSpline{Quadratic{Reflect}}, OnCell)
111+
itp = interpolate(A, BSpline(Quadratic(Reflect())), OnCell())
112112

113113
# Linear interpolation in the first dimension, and no interpolation (just lookup) in the second
114-
itp = interpolate(A, Tuple{BSpline{Linear}, BSpline{NoInterp}}, OnGrid)
114+
itp = interpolate(A, (BSpline(Linear()), NoInterp()), OnGrid())
115115
v = itp[3.65, 5] # returns 0.35*A[3,5] + 0.65*A[4,5]
116116
```
117117
There are more options available, for example:
118118
```jl
119119
# In-place interpolation
120-
itp = interpolate!(A, BSpline{Quadratic{InPlace}}, OnCell)
120+
itp = interpolate!(A, BSpline(Quadratic(InPlace())), OnCell())
121121
```
122122
which destroys the input `A` but also does not need to allocate as much memory.
123123

@@ -133,7 +133,7 @@ In 1D
133133
A = rand(20)
134134
A_x = collect(1.:40.)
135135
knots = (a,)
136-
itp = interpolate(knots,A, Gridded{Linear})
136+
itp = interpolate(knots,A, Gridded(Linear()))
137137
itp[2.0]
138138
```
139139

@@ -148,22 +148,22 @@ For example:
148148
```jl
149149
A = rand(8,20)
150150
knots = ([x^2 for x = 1:8], [0.2y for y = 1:20])
151-
itp = interpolate(knots, A, Gridded{Linear})
151+
itp = interpolate(knots, A, Gridded(Linear()))
152152
itp[4,1.2] # approximately A[2,6]
153153
```
154154
One may also mix modes, by specifying a mode vector in the form of an explicit tuple:
155155
```jl
156-
itp = interpolate(knots, A, Tuple{Gridded{Linear},Gridded{Constant}})
156+
itp = interpolate(knots, A, (Gridded(Linear()),Gridded(Constant())))
157157
```
158158

159159

160160
Presently there are only three modes for gridded:
161161
```jl
162-
Gridded{Linear}
162+
Gridded(Linear())
163163
```
164164
whereby a linear interpolation is applied between knots,
165165
```jl
166-
Gridded{Constant}
166+
Gridded(Constant())
167167
```
168168
whereby nearest neighbor interpolation is used on the applied axis,
169169
```jl
@@ -174,11 +174,7 @@ coordinates results in the throwing of an error.
174174

175175
## Extrapolation
176176

177-
The call to `extrapolate` defines what happens if you try to index into the interpolation object with coordinates outside of `[1, size(data,d)]` in any dimension `d`. The implemented boundary conditions are `Throw` and `Flat`, with more options planned.
178-
179-
## More examples
180-
181-
There's an [IJulia notebook](http://nbviewer.ipython.org/github/tlycken/Interpolations.jl/blob/master/doc/Interpolations.jl.ipynb) that shows off some of the current functionality, and outlines where we're headed. I try to keep it up to date when I make any significant improvements and/or breaking changes, but if it's not, do file a PR.
177+
The call to `extrapolate` defines what happens if you try to index into the interpolation object with coordinates outside of `[1, size(data,d)]` in any dimension `d`. The implemented boundary conditions are `Throw`, `Flat`, `Linear`, `Periodic` and `Reflect`, with more options planned. `Periodic` and `Reflect` require that there is a method of `Base.mod` that can handle the indices used.
182178

183179
## Performance shootout
184180

doc/devdocs.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ First let's create an interpolation object:
1818
0.134746
1919
0.430876
2020

21-
julia> yitp = interpolate(A, BSpline{Linear}, OnGrid)
21+
julia> yitp = interpolate(A, BSpline(Linear()), OnGrid())
2222
5-element Interpolations.BSplineInterpolation{Float64,1,Float64,Interpolations.BSpline{Interpolations.Linear},Interpolations.OnGrid}:
2323
0.74838
2424
0.995383

src/b-splines/b-splines.jl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ export
99
abstract Degree{N}
1010

1111
immutable BSpline{D<:Degree} <: InterpolationType end
12-
BSpline{D<:Degree}(::Type{D}) = BSpline{D}
12+
BSpline{D<:Degree}(::D) = BSpline{D}()
1313

1414
bsplinetype{D<:Degree}(::Type{BSpline{D}}) = D
1515

1616
immutable BSplineInterpolation{T,N,TCoefs,IT<:DimSpec{BSpline},GT<:DimSpec{GridType},pad} <: AbstractInterpolation{T,N,IT,GT}
1717
coefs::Array{TCoefs,N}
1818
end
19-
function BSplineInterpolation{N,TCoefs,TWeights<:Real,IT<:DimSpec{BSpline},GT<:DimSpec{GridType},pad}(::Type{TWeights}, A::AbstractArray{TCoefs,N}, ::Type{IT}, ::Type{GT}, ::Val{pad})
19+
function BSplineInterpolation{N,TCoefs,TWeights<:Real,IT<:DimSpec{BSpline},GT<:DimSpec{GridType},pad}(::Type{TWeights}, A::AbstractArray{TCoefs,N}, ::IT, ::GT, ::Val{pad})
2020
isleaftype(IT) || error("The b-spline type must be a leaf type (was $IT)")
2121
isleaftype(TCoefs) || warn("For performance reasons, consider using an array of a concrete type (eltype(A) == $(eltype(A)))")
2222

@@ -49,12 +49,12 @@ count_interp_dims{T,N,TCoefs,IT<:DimSpec{InterpolationType},GT<:DimSpec{GridType
4949
end
5050
end
5151

52-
function interpolate{TWeights,TCoefs,IT<:DimSpec{BSpline},GT<:DimSpec{GridType}}(::Type{TWeights}, ::Type{TCoefs}, A, ::Type{IT}, ::Type{GT})
52+
function interpolate{TWeights,TCoefs,IT<:DimSpec{BSpline},GT<:DimSpec{GridType}}(::Type{TWeights}, ::Type{TCoefs}, A, it::IT, gt::GT)
5353
Apad, Pad = prefilter(TWeights, TCoefs, A, IT, GT)
54-
BSplineInterpolation(TWeights, Apad, IT, GT, Pad)
54+
BSplineInterpolation(TWeights, Apad, it, gt, Pad)
5555
end
56-
function interpolate{IT<:DimSpec{BSpline},GT<:DimSpec{GridType}}(A::AbstractArray, ::Type{IT}, ::Type{GT})
57-
interpolate(tweight(A), tcoef(A), A, IT, GT)
56+
function interpolate{IT<:DimSpec{BSpline},GT<:DimSpec{GridType}}(A::AbstractArray, it::IT, gt::GT)
57+
interpolate(tweight(A), tcoef(A), A, it, gt)
5858
end
5959

6060
# We can't just return a tuple-of-types due to julia #12500
@@ -68,9 +68,9 @@ tcoef(A::AbstractArray{Float32}) = Float32
6868
tcoef(A::AbstractArray{Rational{Int}}) = Rational{Int}
6969
tcoef{T<:Integer}(A::AbstractArray{T}) = typeof(float(zero(T)))
7070

71-
interpolate!{TWeights,IT<:DimSpec{BSpline},GT<:DimSpec{GridType}}(::Type{TWeights}, A, ::Type{IT}, ::Type{GT}) = BSplineInterpolation(TWeights, prefilter!(TWeights, A, IT, GT), IT, GT, Val{0}())
72-
function interpolate!{IT<:DimSpec{BSpline},GT<:DimSpec{GridType}}(A::AbstractArray, ::Type{IT}, ::Type{GT})
73-
interpolate!(tweight(A), A, IT, GT)
71+
interpolate!{TWeights,IT<:DimSpec{BSpline},GT<:DimSpec{GridType}}(::Type{TWeights}, A, it::IT, gt::GT) = BSplineInterpolation(TWeights, prefilter!(TWeights, A, IT, GT), it, gt, Val{0}())
72+
function interpolate!{IT<:DimSpec{BSpline},GT<:DimSpec{GridType}}(A::AbstractArray, it::IT, gt::GT)
73+
interpolate!(tweight(A), A, it, gt)
7474
end
7575

7676
include("constant.jl")

src/b-splines/quadratic.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
immutable Quadratic{BC<:BoundaryCondition} <: Degree{2} end
2-
Quadratic{BC<:BoundaryCondition}(::Type{BC}) = Quadratic{BC}
2+
Quadratic{BC<:BoundaryCondition}(::BC) = Quadratic{BC}()
33

44
function define_indices_d{BC}(::Type{BSpline{Quadratic{BC}}}, d, pad)
55
symix, symixm, symixp = symbol("ix_",d), symbol("ixm_",d), symbol("ixp_",d)

src/extrapolation/extrapolation.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ export Throw
33
type Extrapolation{T,N,ITPT,IT,GT,ET} <: AbstractInterpolationWrapper{T,N,ITPT,IT,GT}
44
itp::ITPT
55
end
6-
Extrapolation{T,ITPT,IT,GT,ET}(::Type{T}, N, itp::ITPT, ::Type{IT}, ::Type{GT}, ::Type{ET}) =
6+
Extrapolation{T,ITPT,IT,GT,ET}(::Type{T}, N, itp::ITPT, ::Type{IT}, ::Type{GT}, et::ET) =
77
Extrapolation{T,N,ITPT,IT,GT,ET}(itp)
88

99
"""
@@ -14,15 +14,15 @@ The scheme can take any of these values:
1414
* `Throw` - throws a BoundsError for out-of-bounds indices
1515
* `Flat` - for constant extrapolation, taking the closest in-bounds value
1616
* `Linear` - linear extrapolation (the wrapped interpolation object must support gradient)
17-
* `Reflect` - reflecting extrapolation
18-
* `Periodic` - periodic extrapolation
17+
* `Reflect` - reflecting extrapolation (indices must support `mod`)
18+
* `Periodic` - periodic extrapolation (indices must support `mod`)
1919
20-
You can also combine schemes in tuples. For example, the scheme `Tuple{Linear, Flat}` will use linear extrapolation in the first dimension, and constant in the second.
20+
You can also combine schemes in tuples. For example, the scheme `(Linear(), Flat())` will use linear extrapolation in the first dimension, and constant in the second.
2121
22-
Finally, you can specify different extrapolation behavior in different direction. `Tuple{Tuple{Linear,Flat}, Flat}` will extrapolate linearly in the first dimension if the index is too small, but use constant etrapolation if it is too large, and always use constant extrapolation in the second dimension.
22+
Finally, you can specify different extrapolation behavior in different direction. `((Linear(),Flat()), Flat())` will extrapolate linearly in the first dimension if the index is too small, but use constant etrapolation if it is too large, and always use constant extrapolation in the second dimension.
2323
"""
24-
extrapolate{T,N,IT,GT,ET}(itp::AbstractInterpolation{T,N,IT,GT}, ::Type{ET}) =
25-
Extrapolation(T,N,itp,IT,GT,ET)
24+
extrapolate{T,N,IT,GT}(itp::AbstractInterpolation{T,N,IT,GT}, et) =
25+
Extrapolation(T,N,itp,IT,GT,et)
2626

2727
include("throw.jl")
2828
include("flat.jl")

src/extrapolation/filled.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
nindexes(N::Int) = N == 1 ? "1 index" : "$N indexes"
22

3-
43
type FilledExtrapolation{T,N,ITP<:AbstractInterpolation,IT,GT,FT} <: AbstractExtrapolation{T,N,ITP,IT,GT}
54
itp::ITP
65
fillvalue::FT

src/gridded/gridded.jl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export Gridded
22

33
immutable Gridded{D<:Degree} <: InterpolationType end
4-
Gridded{D<:Degree}(::Type{D}) = Gridded{D}
4+
Gridded{D<:Degree}(::D) = Gridded{D}()
55

66
griddedtype{D<:Degree}(::Type{Gridded{D}}) = D
77

@@ -13,7 +13,7 @@ immutable GriddedInterpolation{T,N,TCoefs,IT<:DimSpec{Gridded},K<:Tuple{Vararg{V
1313
knots::K
1414
coefs::Array{TCoefs,N}
1515
end
16-
function GriddedInterpolation{N,TCoefs,TWeights<:Real,IT<:DimSpec{Gridded},pad}(::Type{TWeights}, knots::NTuple{N,GridIndex}, A::AbstractArray{TCoefs,N}, ::Type{IT}, ::Val{pad})
16+
function GriddedInterpolation{N,TCoefs,TWeights<:Real,IT<:DimSpec{Gridded},pad}(::Type{TWeights}, knots::NTuple{N,GridIndex}, A::AbstractArray{TCoefs,N}, ::IT, ::Val{pad})
1717
isleaftype(IT) || error("The b-spline type must be a leaf type (was $IT)")
1818
isleaftype(TCoefs) || warn("For performance reasons, consider using an array of a concrete type (eltype(A) == $(eltype(A)))")
1919

@@ -48,16 +48,16 @@ iextract{T<:GridType}(::Type{T}, d) = T
4848
end
4949
end
5050

51-
function interpolate{TWeights,TCoefs,Tel,N,IT<:DimSpec{Gridded}}(::Type{TWeights}, ::Type{TCoefs}, knots::NTuple{N,GridIndex}, A::AbstractArray{Tel,N}, ::Type{IT})
52-
GriddedInterpolation(TWeights, knots, A, IT, Val{0}())
51+
function interpolate{TWeights,TCoefs,Tel,N,IT<:DimSpec{Gridded}}(::Type{TWeights}, ::Type{TCoefs}, knots::NTuple{N,GridIndex}, A::AbstractArray{Tel,N}, it::IT)
52+
GriddedInterpolation(TWeights, knots, A, it, Val{0}())
5353
end
54-
function interpolate{Tel,N,IT<:DimSpec{Gridded}}(knots::NTuple{N,GridIndex}, A::AbstractArray{Tel,N}, ::Type{IT})
55-
interpolate(tweight(A), tcoef(A), knots, A, IT)
54+
function interpolate{Tel,N,IT<:DimSpec{Gridded}}(knots::NTuple{N,GridIndex}, A::AbstractArray{Tel,N}, it::IT)
55+
interpolate(tweight(A), tcoef(A), knots, A, it)
5656
end
5757

58-
interpolate!{TWeights,Tel,N,IT<:DimSpec{Gridded}}(::Type{TWeights}, knots::NTuple{N,GridIndex}, A::AbstractArray{Tel,N}, ::Type{IT}) = GriddedInterpolation(TWeights, knots, A, IT, Val{0}())
59-
function interpolate!{Tel,N,IT<:DimSpec{Gridded}}(knots::NTuple{N,GridIndex}, A::AbstractArray{Tel,N}, ::Type{IT})
60-
interpolate!(tweight(A), tcoef(A), knots, A, IT)
58+
interpolate!{TWeights,Tel,N,IT<:DimSpec{Gridded}}(::Type{TWeights}, knots::NTuple{N,GridIndex}, A::AbstractArray{Tel,N}, it::IT) = GriddedInterpolation(TWeights, knots, A, it, Val{0}())
59+
function interpolate!{Tel,N,IT<:DimSpec{Gridded}}(knots::NTuple{N,GridIndex}, A::AbstractArray{Tel,N}, it::IT)
60+
interpolate!(tweight(A), tcoef(A), knots, A, it)
6161
end
6262

6363
include("constant.jl")

test/b-splines/constant.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ A2 = rand(Float64, N1, N1) * 100
1010
A3 = rand(Float64, N1, N1, N1) * 100
1111

1212
for (constructor, copier) in ((interpolate, x->x), (interpolate!, copy))
13-
itp1c = @inferred(constructor(copier(A1), BSpline(Constant), OnCell))
14-
itp1g = @inferred(constructor(copier(A1), BSpline(Constant), OnGrid))
15-
itp2c = @inferred(constructor(copier(A2), BSpline(Constant), OnCell))
16-
itp2g = @inferred(constructor(copier(A2), BSpline(Constant), OnGrid))
17-
itp3c = @inferred(constructor(copier(A3), BSpline(Constant), OnCell))
18-
itp3g = @inferred(constructor(copier(A3), BSpline(Constant), OnGrid))
13+
itp1c = @inferred(constructor(copier(A1), BSpline(Constant()), OnCell()))
14+
itp1g = @inferred(constructor(copier(A1), BSpline(Constant()), OnGrid()))
15+
itp2c = @inferred(constructor(copier(A2), BSpline(Constant()), OnCell()))
16+
itp2g = @inferred(constructor(copier(A2), BSpline(Constant()), OnGrid()))
17+
itp3c = @inferred(constructor(copier(A3), BSpline(Constant()), OnCell()))
18+
itp3g = @inferred(constructor(copier(A3), BSpline(Constant()), OnGrid()))
1919

2020
# Evaluation on provided data points
2121
# 1D

test/b-splines/linear.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ f(x) = g1(x)
1010
A1 = Float64[f(x) for x in 1:xmax]
1111

1212
for (constructor, copier) in ((interpolate, x->x), (interpolate!, copy))
13-
itp1c = @inferred(constructor(copier(A1), BSpline(Linear), OnCell))
13+
itp1c = @inferred(constructor(copier(A1), BSpline(Linear()), OnCell()))
1414

1515
# Just interpolation
1616
for x in 1:.2:xmax
@@ -20,7 +20,7 @@ for (constructor, copier) in ((interpolate, x->x), (interpolate!, copy))
2020
# Rational element types
2121
fr(x) = (x^2) // 40 + 2
2222
A1R = Rational{Int}[fr(x) for x in 1:10]
23-
itp1r = @inferred(constructor(copier(A1R), BSpline(Linear), OnGrid))
23+
itp1r = @inferred(constructor(copier(A1R), BSpline(Linear()), OnGrid()))
2424
@test @inferred(size(itp1r)) == size(A1R)
2525
@test_approx_eq_eps itp1r[23//10] fr(23//10) abs(.1*fr(23//10))
2626
@test typeof(itp1r[23//10]) == Rational{Int}
@@ -31,7 +31,7 @@ for (constructor, copier) in ((interpolate, x->x), (interpolate!, copy))
3131
f(x,y) = g1(x)*g2(y)
3232
ymax = 10
3333
A2 = Float64[f(x,y) for x in 1:xmax, y in 1:ymax]
34-
itp2 = @inferred(constructor(copier(A2), BSpline(Linear), OnGrid))
34+
itp2 = @inferred(constructor(copier(A2), BSpline(Linear()), OnGrid()))
3535
@test @inferred(size(itp2)) == size(A2)
3636

3737
for x in 2.1:.2:xmax-1, y in 1.9:.2:ymax-.9

test/b-splines/mixed.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ N = 10
77
for (constructor, copier) in ((interpolate, x->x), (interpolate!, copy))
88
A2 = rand(Float64, N, N) * 100
99
for BC in (Flat,Line,Free,Periodic,Reflect,Natural), GT in (OnGrid, OnCell)
10-
itp_a = @inferred(constructor(copier(A2), Tuple{BSpline(Linear), BSpline(Quadratic(BC))}, GT))
11-
itp_b = @inferred(constructor(copier(A2), Tuple{BSpline(Quadratic(BC)), BSpline(Linear)}, GT))
10+
itp_a = @inferred(constructor(copier(A2), (BSpline(Linear()), BSpline(Quadratic(BC()))), GT()))
11+
itp_b = @inferred(constructor(copier(A2), (BSpline(Quadratic(BC())), BSpline(Linear())), GT()))
1212
@test @inferred(size(itp_a)) == size(A2)
1313
@test @inferred(size(itp_b)) == size(A2)
1414

test/b-splines/multivalued.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,20 @@ Base.promote_rule{T1,T2<:Number}(::Type{MyPair{T1}}, ::Type{T2}) = MyPair{promot
2323

2424
# 1d
2525
A = reinterpret(MyPair{Float64}, rand(2, 10), (10,))
26-
itp = interpolate(A, BSpline(Constant), OnGrid)
26+
itp = interpolate(A, BSpline(Constant()), OnGrid())
2727
itp[3.2]
28-
itp = interpolate(A, BSpline(Linear), OnGrid)
28+
itp = interpolate(A, BSpline(Linear()), OnGrid())
2929
itp[3.2]
30-
itp = interpolate(A, BSpline(Quadratic(Flat)), OnGrid)
30+
itp = interpolate(A, BSpline(Quadratic(Flat())), OnGrid())
3131
itp[3.2]
3232

3333
# 2d
3434
A = reinterpret(MyPair{Float64}, rand(2, 10, 5), (10,5))
35-
itp = interpolate(A, BSpline(Constant), OnGrid)
35+
itp = interpolate(A, BSpline(Constant()), OnGrid())
3636
itp[3.2,1.8]
37-
itp = interpolate(A, BSpline(Linear), OnGrid)
37+
itp = interpolate(A, BSpline(Linear()), OnGrid())
3838
itp[3.2,1.8]
39-
itp = interpolate(A, BSpline(Quadratic(Flat)), OnGrid)
39+
itp = interpolate(A, BSpline(Quadratic(Flat())), OnGrid())
4040
itp[3.2,1.8]
4141

4242
end

test/b-splines/quadratic.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ for (constructor, copier) in ((interpolate, x->x), (interpolate!, copy))
77
xmax = 10
88
A = Float64[f(x) for x in 1:xmax]
99
for BC in (Flat,Line,Free,Periodic,Reflect,Natural), GT in (OnGrid, OnCell)
10-
itp1 = @inferred(constructor(copier(A), BSpline(Quadratic(BC)), GT))
10+
itp1 = @inferred(constructor(copier(A), BSpline(Quadratic(BC())), GT()))
1111
@test @inferred(size(itp1)) == size(A)
1212

1313
# test that inner region is close to data
@@ -37,7 +37,7 @@ for (constructor, copier) in ((interpolate, x->x), (interpolate!, copy))
3737

3838
# test that inner region is close to data
3939
for BC in (Flat,Line,Free,Periodic,Reflect,Natural), GT in (OnGrid, OnCell)
40-
itp2 = @inferred(constructor(copier(A), BSpline(Quadratic(BC)), GT))
40+
itp2 = @inferred(constructor(copier(A), BSpline(Quadratic(BC())), GT()))
4141
@test @inferred(size(itp2)) == size(A)
4242

4343
for x in 3.1:.2:xmax-3, y in 3.1:2:ymax-3
@@ -50,15 +50,15 @@ let
5050
f(x) = sin((x-3)*2pi/9 - 1)
5151
xmax = 10
5252
A = Float64[f(x) for x in 1:xmax]
53-
itp1 = interpolate!(copy(A), BSpline(Quadratic(InPlace)), OnCell)
53+
itp1 = interpolate!(copy(A), BSpline(Quadratic(InPlace())), OnCell())
5454
for i = 1:xmax
5555
@test_approx_eq itp1[i] A[i]
5656
end
5757

5858
f(x,y) = sin(x/10)*cos(y/6)
5959
xmax, ymax = 30,10
6060
A = Float64[f(x,y) for x in 1:xmax, y in 1:ymax]
61-
itp2 = interpolate!(copy(A), BSpline(Quadratic(InPlace)), OnCell)
61+
itp2 = interpolate!(copy(A), BSpline(Quadratic(InPlace())), OnCell())
6262
for j = 1:ymax, i = 1:xmax
6363
@test_approx_eq itp2[i,j] A[i,j]
6464
end

test/extrapolation/runtests.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ f(x) = sin((x-3)*2pi/9 - 1)
77
xmax = 10
88
A = Float64[f(x) for x in 1:xmax]
99

10-
itpg = interpolate(A, BSpline(Linear), OnGrid)
10+
itpg = interpolate(A, BSpline(Linear()), OnGrid())
1111

12-
etpg = extrapolate(itpg, Flat)
12+
etpg = extrapolate(itpg, Flat())
1313

1414
@test etpg[-3] == etpg[-4.5] == etpg[0.9] == etpg[1.0] == A[1]
1515
@test etpg[10.1] == etpg[11] == etpg[148.298452] == A[end]
1616

17-
etpf = @inferred(extrapolate(itpg, NaN))
17+
etpf = @inferred(extrapolate(itpg, FillValue(NaN)))
1818

1919
@test @inferred(size(etpf)) == (xmax,)
2020
@test isnan(@inferred(getindex(etpf, -2.5)))
@@ -29,7 +29,7 @@ etpf = @inferred(extrapolate(itpg, NaN))
2929

3030
@test isa(@inferred(getindex(etpf, dual(-2.5,1))), Dual)
3131

32-
etpl = extrapolate(itpg, Linear)
32+
etpl = extrapolate(itpg, Linear())
3333
k_lo = A[2] - A[1]
3434
x_lo = -3.2
3535
@test_approx_eq etpl[x_lo] A[1]+k_lo*(x_lo-1)
@@ -41,19 +41,19 @@ x_hi = xmax + 5.7
4141
xmax, ymax = 8,8
4242
g(x, y) = (x^2 + 3x - 8) * (-2y^2 + y + 1)
4343

44-
itp2g = interpolate(Float64[g(x,y) for x in 1:xmax, y in 1:ymax], Tuple{BSpline(Quadratic(Free)), BSpline(Linear)}, OnGrid)
45-
etp2g = extrapolate(itp2g, Tuple{Linear, Flat})
44+
itp2g = interpolate(Float64[g(x,y) for x in 1:xmax, y in 1:ymax], (BSpline(Quadratic(Free())), BSpline(Linear())), OnGrid())
45+
etp2g = extrapolate(itp2g, (Linear(), Flat()))
4646

4747
@test_approx_eq @inferred(getindex(etp2g, -.5, 4)) itp2g[1,4]-1.5*epsilon(etp2g[dual(1,1),4])
4848
@test_approx_eq @inferred(getindex(etp2g, 5, 100)) itp2g[5,ymax]
4949

50-
etp2ud = extrapolate(itp2g, Tuple{Tuple{Linear, Flat}, Flat})
50+
etp2ud = extrapolate(itp2g, ((Linear(), Flat()), Flat()))
5151
@test_approx_eq @inferred(getindex(etp2ud, -.5, 4)) itp2g[1,4] - 1.5*epsilon(etp2g[dual(1,1),4])
5252
@test @inferred(getindex(etp2ud, 5, -4)) == etp2ud[5,1]
5353
@test @inferred(getindex(etp2ud, 100, 4)) == etp2ud[8,4]
5454
@test @inferred(getindex(etp2ud, -.5, 100)) == itp2g[1,8] - 1.5 * epsilon(etp2g[dual(1,1),8])
5555

56-
etp2ll = extrapolate(itp2g, Linear)
56+
etp2ll = extrapolate(itp2g, Linear())
5757
@test_approx_eq @inferred(getindex(etp2ll, -.5, 100)) itp2g[1,8]-1.5*epsilon(etp2ll[dual(1,1),8]) + (100-8) * epsilon(etp2ll[1,dual(8,1)])
5858

5959

0 commit comments

Comments
 (0)