Skip to content

Commit

Permalink
Rename FilledInterpolation to FilledExtrapolation
Browse files Browse the repository at this point in the history
This change might have been better suited for its own PR, but I stumbled
over it now and had to change some related things anyway (indexing into
it, see next commit in #47).

@timholy, please protest if you have any objections.
  • Loading branch information
tomasaschan committed Sep 18, 2015
1 parent 0610e7e commit 02866a4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/extrapolation/extrapolation.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export Throw,
FilledInterpolation # for direct control over typeof(fillvalue)
FilledExtrapolation # for direct control over typeof(fillvalue)

include("error.jl")

Expand Down
14 changes: 7 additions & 7 deletions src/extrapolation/filled.jl
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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())
2 changes: 1 addition & 1 deletion test/extrapolation/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down

2 comments on commit 02866a4

@timholy
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine with me, makes more sense this way.

@timholy
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Terminology was actually from #27, which I just rebased and extended.

Please sign in to comment.