diff --git a/src/convenience-constructors.jl b/src/convenience-constructors.jl index 487023c1..61123911 100644 --- a/src/convenience-constructors.jl +++ b/src/convenience-constructors.jl @@ -1,10 +1,10 @@ # convenience copnstructors for linear / cubic spline interpolations # 1D version -LinearInterpolation(range::T, vs; extrapolation_bc = Interpolations.Throw()) where {T <: AbstractRange} = extrapolate(scale(interpolate(vs, BSpline(Linear()), OnGrid()), range), extrapolation_bc) -LinearInterpolation(range::T, vs; extrapolation_bc = Interpolations.Throw()) where {T <: AbstractArray} = extrapolate(interpolate((range, ), vs, Gridded(Linear())), extrapolation_bc) -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) +LinearInterpolation(range::T, vs; extrapolation_bc = Throw()) where {T <: AbstractRange} = extrapolate(scale(interpolate(vs, BSpline(Linear())), range), extrapolation_bc) +LinearInterpolation(range::T, vs; extrapolation_bc = Throw()) where {T <: AbstractArray} = extrapolate(interpolate((range, ), vs, Gridded(Linear())), extrapolation_bc) +CubicSplineInterpolation(range::T, vs; bc = Line(OnGrid()), extrapolation_bc = Throw()) where {T <: AbstractRange} = extrapolate(scale(interpolate(vs, BSpline(Cubic(bc))), range), extrapolation_bc) # multivariate versions -LinearInterpolation(ranges::NTuple{N,T}, vs; extrapolation_bc = Interpolations.Throw()) where {N,T <: AbstractRange} = extrapolate(scale(interpolate(vs, BSpline(Linear()), OnGrid()), ranges...), extrapolation_bc) -LinearInterpolation(ranges::NTuple{N,T}, vs; extrapolation_bc = Interpolations.Throw()) where {N,T <: AbstractArray} = extrapolate(interpolate(ranges, vs, Gridded(Linear())), extrapolation_bc) -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) +LinearInterpolation(ranges::NTuple{N,T}, vs; extrapolation_bc = Throw()) where {N,T <: AbstractRange} = extrapolate(scale(interpolate(vs, BSpline(Linear())), ranges...), extrapolation_bc) +LinearInterpolation(ranges::NTuple{N,T}, vs; extrapolation_bc = Throw()) where {N,T <: AbstractArray} = extrapolate(interpolate(ranges, vs, Gridded(Linear())), extrapolation_bc) +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) diff --git a/test/convenience-constructors.jl b/test/convenience-constructors.jl index 84fc850d..70a30107 100644 --- a/test/convenience-constructors.jl +++ b/test/convenience-constructors.jl @@ -20,7 +20,7 @@ YLEN = convert(Integer, floor((YMAX - YMIN)/ΔY) + 1) f(x) = log(x) A = [f(x) for x in xs] interp = LinearInterpolation(xs, A) # using convenience constructor - interp_full = extrapolate(scale(interpolate(A, BSpline(Linear()), OnGrid()), xs), Interpolations.Throw()) # using full constructor + interp_full = extrapolate(scale(interpolate(A, BSpline(Linear())), xs), Throw()) # using full constructor @test typeof(interp) == typeof(interp_full) @test interp(XMIN) ≈ f(XMIN) @@ -37,7 +37,7 @@ YLEN = convert(Integer, floor((YMAX - YMIN)/ΔY) + 1) f(x) = log(x) A = [f(x) for x in xs] interp = CubicSplineInterpolation(xs, A) - interp_full = extrapolate(scale(interpolate(A, BSpline(Cubic(Line())), OnGrid()), xs), Interpolations.Throw()) + interp_full = extrapolate(scale(interpolate(A, BSpline(Cubic(Line(OnGrid())))), xs), Throw()) @test typeof(interp) == typeof(interp_full) @test interp(XMIN) ≈ f(XMIN) @@ -56,7 +56,7 @@ YLEN = convert(Integer, floor((YMAX - YMIN)/ΔY) + 1) f(x) = log(x) A = [f(x) for x in xs] interp = LinearInterpolation(xs, A) - interp_full = extrapolate(interpolate((xs, ), A, Gridded(Linear())), Interpolations.Throw()) + interp_full = extrapolate(interpolate((xs, ), A, Gridded(Linear())), Throw()) @test typeof(interp) == typeof(interp_full) @test interp(xmin) ≈ f(xmin) @@ -76,8 +76,8 @@ YLEN = convert(Integer, floor((YMAX - YMIN)/ΔY) + 1) x_lower = XMIN - ΔX x_higher = XMAX + ΔX - extrap = LinearInterpolation(xs, A, extrapolation_bc = Interpolations.Linear()) - extrap_full = extrapolate(scale(interpolate(A, BSpline(Linear()), OnGrid()), xs), Interpolations.Linear()) + extrap = LinearInterpolation(xs, A, extrapolation_bc = Line()) + extrap_full = extrapolate(scale(interpolate(A, BSpline(Linear())), xs), Line()) @test typeof(extrap) == typeof(extrap_full) @test extrap(x_lower) ≈ A[1] - ΔA_l @@ -92,7 +92,7 @@ end f(x, y) = log(x+y) A = [f(x,y) for x in xs, y in ys] interp = LinearInterpolation((xs, ys), A) - interp_full = extrapolate(scale(interpolate(A, BSpline(Linear()), OnGrid()), xs, ys), Interpolations.Throw()) + interp_full = extrapolate(scale(interpolate(A, BSpline(Linear())), xs, ys), Throw()) @test typeof(interp) == typeof(interp_full) @test interp(XMIN,YMIN) ≈ f(XMIN,YMIN) @@ -115,7 +115,7 @@ end f(x, y) = log(x+y) A = [f(x,y) for x in xs, y in ys] interp = CubicSplineInterpolation((xs, ys), A) - interp_full = extrapolate(scale(interpolate(A, BSpline(Cubic(Line())), OnGrid()), xs, ys), Interpolations.Throw()) + interp_full = extrapolate(scale(interpolate(A, BSpline(Cubic(Line(OnGrid())))), xs, ys), Throw()) @test typeof(interp) == typeof(interp_full) @test interp(XMIN,YMIN) ≈ f(XMIN,YMIN) @@ -142,7 +142,7 @@ end f(x, y) = log(x+y) A = [f(x,y) for x in xs, y in ys] interp = LinearInterpolation((xs, ys), A) - interp_full = extrapolate(interpolate((xs, ys), A, Gridded(Linear())), Interpolations.Throw()) + interp_full = extrapolate(interpolate((xs, ys), A, Gridded(Linear())), Throw()) @test typeof(interp) == typeof(interp_full) @test interp(xmin,ymin) ≈ f(xmin,ymin) @@ -171,8 +171,8 @@ end y_lower = YMIN - ΔY y_higher = YMAX + ΔY - extrap = LinearInterpolation((xs, ys), A, extrapolation_bc = (Interpolations.Linear(), Interpolations.Flat())) - extrap_full = extrapolate(scale(interpolate(A, BSpline(Linear()), OnGrid()), xs, ys), (Interpolations.Linear(), Interpolations.Flat())) + extrap = LinearInterpolation((xs, ys), A, extrapolation_bc = (Line(), Flat())) + extrap_full = extrapolate(scale(interpolate(A, BSpline(Linear())), xs, ys), (Line(), Flat())) @test typeof(extrap) == typeof(extrap_full) @test extrap(x_lower, y_lower) ≈ A[1, 1] - ΔA_l diff --git a/test/runtests.jl b/test/runtests.jl index bf49f225..9e861742 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -36,7 +36,7 @@ using Interpolations include("issues/runtests.jl") include("io.jl") - # include("convenience-constructors.jl") + include("convenience-constructors.jl") include("readme-examples.jl") end diff --git a/test/visual.jl b/test/visual.jl index 5d4d4289..f103b2c2 100644 --- a/test/visual.jl +++ b/test/visual.jl @@ -14,22 +14,22 @@ p = plot() if true Btypes = (Periodic, Flat, Line, Free, Reflect) -Itypes = ( - Constant, Linear, - [Quadratic{T} for T in Btypes]..., - [Cubic{T} for T in Btypes[1:end-1]]..., # no Reflect for Cubic -) -Etypes = (Flat, Linear, Reflect, Periodic) Gtypes = (OnCell, OnGrid) +degrees = ( + Constant(), Linear(), + [Quadratic(T(G())) for T in Btypes, G in Gtypes]..., + [Cubic(T(G())) for T in Btypes[1:end-1], G in Gtypes]..., # no Reflect for Cubic +) +Etypes = (Flat, Line, Reflect, Periodic) -for IT in Itypes, GT in Gtypes, ET in Etypes - itp = extrapolate(interpolate(y1, BSpline(IT()), GT()), ET()) +for deg in degrees, ET in Etypes + itp = extrapolate(interpolate(y1, BSpline(deg)), ET()) stuff = Any[] push!(stuff, layer(x=xg,y=y1,Geom.point,Theme(default_color=colorant"green"))) push!(stuff, layer(x=xf,y=[itp[x] for x in xf],Geom.path,Theme(point_size=2px))) - title = "$(IT.name.name){$(join(map(t -> t.name.name, IT.parameters), ','))}, $(ET.name.name)" + title = "$deg, $(ET.name.name)" push!(stuff, Guide.title(title)) display(plot(stuff...)) end @@ -45,11 +45,11 @@ zg = f2.(xg, yg') xf = -1:.1:nx+1 yf = -1:.1:ny+1 -itp2 = extrapolate(interpolate(zg, BSpline(Quadratic{Flat}()), OnCell()), Linear()) +itp2 = extrapolate(interpolate(zg, BSpline(Quadratic(Flat(OnCell()))), Line()) display(plot( layer(x=xf,y=yf,z=[itp2[x,y] for x in xf, y in yf], Geom.contour), - Guide.title("Quadratic{Flat}, Oncell, Linear") + Guide.title("Quadratic(Flat(OnCell)), Line") )) end