Skip to content

Commit 144dc00

Browse files
committed
Fix convenience constructors and visual tests
1 parent 328d0c1 commit 144dc00

File tree

4 files changed

+28
-28
lines changed

4 files changed

+28
-28
lines changed

src/convenience-constructors.jl

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# convenience copnstructors for linear / cubic spline interpolations
22
# 1D version
3-
LinearInterpolation(range::T, vs; extrapolation_bc = Interpolations.Throw()) where {T <: AbstractRange} = extrapolate(scale(interpolate(vs, BSpline(Linear()), OnGrid()), range), extrapolation_bc)
4-
LinearInterpolation(range::T, vs; extrapolation_bc = Interpolations.Throw()) where {T <: AbstractArray} = extrapolate(interpolate((range, ), vs, Gridded(Linear())), extrapolation_bc)
5-
CubicSplineInterpolation(range::T, vs; bc = Interpolations.Line(), extrapolation_bc = Interpolations.Throw()) where {T <: AbstractRange} = extrapolate(scale(interpolate(vs, BSpline(Cubic(bc)), OnGrid()), range), extrapolation_bc)
3+
LinearInterpolation(range::T, vs; extrapolation_bc = Throw()) where {T <: AbstractRange} = extrapolate(scale(interpolate(vs, BSpline(Linear())), range), extrapolation_bc)
4+
LinearInterpolation(range::T, vs; extrapolation_bc = Throw()) where {T <: AbstractArray} = extrapolate(interpolate((range, ), vs, Gridded(Linear())), extrapolation_bc)
5+
CubicSplineInterpolation(range::T, vs; bc = Line(OnGrid()), extrapolation_bc = Throw()) where {T <: AbstractRange} = extrapolate(scale(interpolate(vs, BSpline(Cubic(bc))), range), extrapolation_bc)
66

77
# multivariate versions
8-
LinearInterpolation(ranges::NTuple{N,T}, vs; extrapolation_bc = Interpolations.Throw()) where {N,T <: AbstractRange} = extrapolate(scale(interpolate(vs, BSpline(Linear()), OnGrid()), ranges...), extrapolation_bc)
9-
LinearInterpolation(ranges::NTuple{N,T}, vs; extrapolation_bc = Interpolations.Throw()) where {N,T <: AbstractArray} = extrapolate(interpolate(ranges, vs, Gridded(Linear())), extrapolation_bc)
10-
CubicSplineInterpolation(ranges::NTuple{N,T}, vs; bc = Interpolations.Line(), extrapolation_bc = Interpolations.Throw()) where {N,T <: AbstractRange} = extrapolate(scale(interpolate(vs, BSpline(Cubic(bc)), OnGrid()), ranges...), extrapolation_bc)
8+
LinearInterpolation(ranges::NTuple{N,T}, vs; extrapolation_bc = Throw()) where {N,T <: AbstractRange} = extrapolate(scale(interpolate(vs, BSpline(Linear())), ranges...), extrapolation_bc)
9+
LinearInterpolation(ranges::NTuple{N,T}, vs; extrapolation_bc = Throw()) where {N,T <: AbstractArray} = extrapolate(interpolate(ranges, vs, Gridded(Linear())), extrapolation_bc)
10+
CubicSplineInterpolation(ranges::NTuple{N,T}, vs; bc = Line(OnGrid()), extrapolation_bc = Throw()) where {N,T <: AbstractRange} = extrapolate(scale(interpolate(vs, BSpline(Cubic(bc))), ranges...), extrapolation_bc)

test/convenience-constructors.jl

+10-10
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ YLEN = convert(Integer, floor((YMAX - YMIN)/ΔY) + 1)
2020
f(x) = log(x)
2121
A = [f(x) for x in xs]
2222
interp = LinearInterpolation(xs, A) # using convenience constructor
23-
interp_full = extrapolate(scale(interpolate(A, BSpline(Linear()), OnGrid()), xs), Interpolations.Throw()) # using full constructor
23+
interp_full = extrapolate(scale(interpolate(A, BSpline(Linear())), xs), Throw()) # using full constructor
2424

2525
@test typeof(interp) == typeof(interp_full)
2626
@test interp(XMIN) f(XMIN)
@@ -37,7 +37,7 @@ YLEN = convert(Integer, floor((YMAX - YMIN)/ΔY) + 1)
3737
f(x) = log(x)
3838
A = [f(x) for x in xs]
3939
interp = CubicSplineInterpolation(xs, A)
40-
interp_full = extrapolate(scale(interpolate(A, BSpline(Cubic(Line())), OnGrid()), xs), Interpolations.Throw())
40+
interp_full = extrapolate(scale(interpolate(A, BSpline(Cubic(Line(OnGrid())))), xs), Throw())
4141

4242
@test typeof(interp) == typeof(interp_full)
4343
@test interp(XMIN) f(XMIN)
@@ -56,7 +56,7 @@ YLEN = convert(Integer, floor((YMAX - YMIN)/ΔY) + 1)
5656
f(x) = log(x)
5757
A = [f(x) for x in xs]
5858
interp = LinearInterpolation(xs, A)
59-
interp_full = extrapolate(interpolate((xs, ), A, Gridded(Linear())), Interpolations.Throw())
59+
interp_full = extrapolate(interpolate((xs, ), A, Gridded(Linear())), Throw())
6060

6161
@test typeof(interp) == typeof(interp_full)
6262
@test interp(xmin) f(xmin)
@@ -76,8 +76,8 @@ YLEN = convert(Integer, floor((YMAX - YMIN)/ΔY) + 1)
7676
x_lower = XMIN - ΔX
7777
x_higher = XMAX + ΔX
7878

79-
extrap = LinearInterpolation(xs, A, extrapolation_bc = Interpolations.Linear())
80-
extrap_full = extrapolate(scale(interpolate(A, BSpline(Linear()), OnGrid()), xs), Interpolations.Linear())
79+
extrap = LinearInterpolation(xs, A, extrapolation_bc = Line())
80+
extrap_full = extrapolate(scale(interpolate(A, BSpline(Linear())), xs), Line())
8181

8282
@test typeof(extrap) == typeof(extrap_full)
8383
@test extrap(x_lower) A[1] - ΔA_l
@@ -92,7 +92,7 @@ end
9292
f(x, y) = log(x+y)
9393
A = [f(x,y) for x in xs, y in ys]
9494
interp = LinearInterpolation((xs, ys), A)
95-
interp_full = extrapolate(scale(interpolate(A, BSpline(Linear()), OnGrid()), xs, ys), Interpolations.Throw())
95+
interp_full = extrapolate(scale(interpolate(A, BSpline(Linear())), xs, ys), Throw())
9696

9797
@test typeof(interp) == typeof(interp_full)
9898
@test interp(XMIN,YMIN) f(XMIN,YMIN)
@@ -115,7 +115,7 @@ end
115115
f(x, y) = log(x+y)
116116
A = [f(x,y) for x in xs, y in ys]
117117
interp = CubicSplineInterpolation((xs, ys), A)
118-
interp_full = extrapolate(scale(interpolate(A, BSpline(Cubic(Line())), OnGrid()), xs, ys), Interpolations.Throw())
118+
interp_full = extrapolate(scale(interpolate(A, BSpline(Cubic(Line(OnGrid())))), xs, ys), Throw())
119119

120120
@test typeof(interp) == typeof(interp_full)
121121
@test interp(XMIN,YMIN) f(XMIN,YMIN)
@@ -142,7 +142,7 @@ end
142142
f(x, y) = log(x+y)
143143
A = [f(x,y) for x in xs, y in ys]
144144
interp = LinearInterpolation((xs, ys), A)
145-
interp_full = extrapolate(interpolate((xs, ys), A, Gridded(Linear())), Interpolations.Throw())
145+
interp_full = extrapolate(interpolate((xs, ys), A, Gridded(Linear())), Throw())
146146

147147
@test typeof(interp) == typeof(interp_full)
148148
@test interp(xmin,ymin) f(xmin,ymin)
@@ -171,8 +171,8 @@ end
171171
y_lower = YMIN - ΔY
172172
y_higher = YMAX + ΔY
173173

174-
extrap = LinearInterpolation((xs, ys), A, extrapolation_bc = (Interpolations.Linear(), Interpolations.Flat()))
175-
extrap_full = extrapolate(scale(interpolate(A, BSpline(Linear()), OnGrid()), xs, ys), (Interpolations.Linear(), Interpolations.Flat()))
174+
extrap = LinearInterpolation((xs, ys), A, extrapolation_bc = (Line(), Flat()))
175+
extrap_full = extrapolate(scale(interpolate(A, BSpline(Linear())), xs, ys), (Line(), Flat()))
176176

177177
@test typeof(extrap) == typeof(extrap_full)
178178
@test extrap(x_lower, y_lower) A[1, 1] - ΔA_l

test/runtests.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ using Interpolations
3636
include("issues/runtests.jl")
3737

3838
include("io.jl")
39-
# include("convenience-constructors.jl")
39+
include("convenience-constructors.jl")
4040
include("readme-examples.jl")
4141

4242
end

test/visual.jl

+11-11
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,22 @@ p = plot()
1414
if true
1515

1616
Btypes = (Periodic, Flat, Line, Free, Reflect)
17-
Itypes = (
18-
Constant, Linear,
19-
[Quadratic{T} for T in Btypes]...,
20-
[Cubic{T} for T in Btypes[1:end-1]]..., # no Reflect for Cubic
21-
)
22-
Etypes = (Flat, Linear, Reflect, Periodic)
2317
Gtypes = (OnCell, OnGrid)
18+
degrees = (
19+
Constant(), Linear(),
20+
[Quadratic(T(G())) for T in Btypes, G in Gtypes]...,
21+
[Cubic(T(G())) for T in Btypes[1:end-1], G in Gtypes]..., # no Reflect for Cubic
22+
)
23+
Etypes = (Flat, Line, Reflect, Periodic)
2424

25-
for IT in Itypes, GT in Gtypes, ET in Etypes
26-
itp = extrapolate(interpolate(y1, BSpline(IT()), GT()), ET())
25+
for deg in degrees, ET in Etypes
26+
itp = extrapolate(interpolate(y1, BSpline(deg)), ET())
2727

2828
stuff = Any[]
2929

3030
push!(stuff, layer(x=xg,y=y1,Geom.point,Theme(default_color=colorant"green")))
3131
push!(stuff, layer(x=xf,y=[itp[x] for x in xf],Geom.path,Theme(point_size=2px)))
32-
title = "$(IT.name.name){$(join(map(t -> t.name.name, IT.parameters), ','))}, $(ET.name.name)"
32+
title = "$deg, $(ET.name.name)"
3333
push!(stuff, Guide.title(title))
3434
display(plot(stuff...))
3535
end
@@ -45,11 +45,11 @@ zg = f2.(xg, yg')
4545
xf = -1:.1:nx+1
4646
yf = -1:.1:ny+1
4747

48-
itp2 = extrapolate(interpolate(zg, BSpline(Quadratic{Flat}()), OnCell()), Linear())
48+
itp2 = extrapolate(interpolate(zg, BSpline(Quadratic(Flat(OnCell()))), Line())
4949

5050
display(plot(
5151
layer(x=xf,y=yf,z=[itp2[x,y] for x in xf, y in yf], Geom.contour),
52-
Guide.title("Quadratic{Flat}, Oncell, Linear")
52+
Guide.title("Quadratic(Flat(OnCell)), Line")
5353
))
5454

5555
end

0 commit comments

Comments
 (0)