@@ -17,27 +17,18 @@ Base.parent(A::FilledExtrapolation) = A.itp
1717"""
1818extrapolate (itp:: AbstractInterpolation{T,N,IT,GT} , fillvalue) where {T,N,IT,GT} = FilledExtrapolation (itp, fillvalue)
1919
20- function getindex_impl (fitp:: Type{FilledExtrapolation{T,N,ITP,IT,GT,FT}} , args) where {T,N,ITP,IT,GT,FT}
21- n = length (args)
22- n == N || return error (" Must index $(N) -dimensional interpolation objects with $(nindexes (N)) " )
23-
24- Tret = FT<: Number ? getindex_return_type (ITP, (T, args... )) : FT
25- meta = Expr (:meta , :inline )
26- quote
27- $ meta
28- # Check to see if we're in the extrapolation region, i.e.,
29- # out-of-bounds in an index
30- inds_etp = indices (fitp)
31- @nexprs $ N d-> ((args[d] < lbound (fitp, d, inds_etp[d]) || args[d] > ubound (fitp, d, inds_etp[d]))) && return convert ($ Tret, fitp. fillvalue):: $Tret
32- # In the interpolation region
33- return convert ($ Tret, getindex (fitp. itp,args... )):: $Tret
34- end
20+ @inline function getindex (fitp:: FilledExtrapolation{T,N,ITP,IT,GT,FT} , args:: Vararg{Number,M} ) where {T,N,ITP,IT,GT,FT,M}
21+ inds, trailing = Base. IteratorsMD. split (args, Val{N})
22+ @boundscheck all (x-> x== 1 , trailing) || Base. throw_boundserror (fitp, args)
23+ Tret = typeof (prod (inds) * zero (T))
24+ checkbounds (Bool, fitp, inds... ) && return convert (Tret, fitp. itp[inds... ])
25+ convert (Tret, fitp. fillvalue)
3526end
3627
37-
38- @generated function getindex (fitp :: FilledExtrapolation{T,N,ITP,IT,GT,FT} , args :: Number... ) where {T,N,ITP,IT,GT,FT}
39- getindex_impl (fitp, args )
40- end
28+ @inline Base . checkbounds ( :: Type{Bool} , A :: FilledExtrapolation , I ... ) = _checkbounds (A, 1 , indices (A), I)
29+ @inline _checkbounds (A, d :: Int , IA :: TT1 , I :: TT2 ) where {TT1,TT2} =
30+ (I[ 1 ] >= lbound (A, d, IA[ 1 ])) & (I[ 1 ] <= ubound (A, d, IA[ 1 ])) & _checkbounds (A, d + 1 , Base . tail (IA), Base . tail (I) )
31+ _checkbounds (A, d :: Int , :: Tuple{} , :: Tuple{} ) = true
4132
4233getindex (fitp:: FilledExtrapolation{T,1} , x:: Number , y:: Int ) where {T} = y == 1 ? fitp[x] : throw (BoundsError ())
4334
0 commit comments