diff --git a/src/extrapolation/extrapolation.jl b/src/extrapolation/extrapolation.jl index 68bcc1db..61e0e9ad 100644 --- a/src/extrapolation/extrapolation.jl +++ b/src/extrapolation/extrapolation.jl @@ -1,5 +1,5 @@ export Throw, - FilledInterpolation # for direct control over typeof(fillvalue) + FilledExtrapolation # for direct control over typeof(fillvalue) include("error.jl") diff --git a/src/extrapolation/filled.jl b/src/extrapolation/filled.jl index b6d18908..4c4e2a6e 100644 --- a/src/extrapolation/filled.jl +++ b/src/extrapolation/filled.jl @@ -1,25 +1,25 @@ nindexes(N::Int) = N == 1 ? "1 index" : "$N indexes" -type FilledInterpolation{T,N,ITP<:AbstractInterpolation,IT,GT,FT} <: AbstractExtrapolation{T,N,ITP,IT,GT} +type FilledExtrapolation{T,N,ITP<:AbstractInterpolation,IT,GT,FT} <: AbstractExtrapolation{T,N,ITP,IT,GT} itp::ITP fillvalue::FT end @doc """ -`FilledInterpolation(itp, fillvalue)` creates an extrapolation object that returns the `fillvalue` any time the indexes in `itp[x1,x2,...]` are out-of-bounds. +`FilledExtrapolation(itp, fillvalue)` creates an extrapolation object that returns the `fillvalue` any time the indexes in `itp[x1,x2,...]` are out-of-bounds. By comparison with `extrapolate`, this version lets you control the `fillvalue`'s type directly. It's important for the `fillvalue` to be of the same type as returned by `itp[x1,x2,...]` for in-bounds regions for the index types you are using; otherwise, indexing will be type-unstable (and slow). """ -> -function FilledInterpolation{T,N,IT,GT}(itp::AbstractInterpolation{T,N,IT,GT}, fillvalue) - FilledInterpolation{T,N,typeof(itp),IT,GT,typeof(fillvalue)}(itp, fillvalue) +function FilledExtrapolation{T,N,IT,GT}(itp::AbstractInterpolation{T,N,IT,GT}, fillvalue) + FilledExtrapolation{T,N,typeof(itp),IT,GT,typeof(fillvalue)}(itp, fillvalue) end @doc """ `extrapolate(itp, fillvalue)` creates an extrapolation object that returns the `fillvalue` any time the indexes in `itp[x1,x2,...]` are out-of-bounds. """ -> -extrapolate{T,N,IT,GT}(itp::AbstractInterpolation{T,N,IT,GT}, fillvalue) = FilledInterpolation(itp, convert(eltype(itp), fillvalue)) +extrapolate{T,N,IT,GT}(itp::AbstractInterpolation{T,N,IT,GT}, fillvalue) = FilledExtrapolation(itp, convert(eltype(itp), fillvalue)) -@generated function getindex{T,N}(fitp::FilledInterpolation{T,N}, args::Number...) +@generated function getindex{T,N}(fitp::FilledExtrapolation{T,N}, args::Number...) n = length(args) n == N || return error("Must index $(N)-dimensional interpolation objects with $(nindexes(N))") meta = Expr(:meta, :inline) @@ -33,4 +33,4 @@ extrapolate{T,N,IT,GT}(itp::AbstractInterpolation{T,N,IT,GT}, fillvalue) = Fille end end -getindex{T}(fitp::FilledInterpolation{T,1}, x::Number, y::Int) = y == 1 ? fitp[x] : throw(BoundsError()) +getindex{T}(fitp::FilledExtrapolation{T,1}, x::Number, y::Int) = y == 1 ? fitp[x] : throw(BoundsError()) diff --git a/test/extrapolation/runtests.jl b/test/extrapolation/runtests.jl index 309f8b67..b54aaddc 100644 --- a/test/extrapolation/runtests.jl +++ b/test/extrapolation/runtests.jl @@ -27,7 +27,7 @@ etpf = @inferred(extrapolate(itpg, NaN)) @test_throws BoundsError etpf[2.5,2] @test_throws ErrorException etpf[2.5,2,1] # this will probably become a BoundsError someday -etpf = @inferred(FilledInterpolation(itpg, 'x')) +etpf = @inferred(FilledExtrapolation(itpg, 'x')) @test_approx_eq etpf[2] f(2) @test etpf[-1.5] == 'x'