4
4
@boundscheck (checkbounds (Bool, itp, x... ) || Base. throw_boundserror (itp, x))
5
5
expand_value (itp, x)
6
6
end
7
- # @inline function (itp::BSplineInterpolation{T,1})(x::Integer, y::Integer) where T
8
- # @boundscheck (y == 1 || Base.throw_boundserror(itp, (x,y)))
9
- # expand_value(itp, (x,))
10
- # end
7
+ @propagate_inbounds function (itp:: BSplineInterpolation{T,N} )(x:: Vararg{Number,M} ) where {T,M,N}
8
+ inds, trailing = split_trailing (itp, x)
9
+ @boundscheck (check1 (trailing) || Base. throw_boundserror (itp, x))
10
+ @assert length (inds) == N
11
+ itp (inds... )
12
+ end
11
13
12
14
@inline function gradient (itp:: BSplineInterpolation{T,N} , x:: Vararg{Number,N} ) where {T,N}
13
15
@boundscheck checkbounds (Bool, itp, x... ) || Base. throw_boundserror (itp, x)
@@ -46,7 +48,7 @@ Interpolate `itp` at `x`.
46
48
function expand_value (itp:: AbstractInterpolation , x:: Tuple )
47
49
coefs = coefficients (itp)
48
50
degree = interpdegree (itp)
49
- ixs, rxs = expand_indices_resid (degree, bounds (itp), x)
51
+ ixs, rxs = splitgrouped ( expand_indices_resid (degree, axes (itp), x) )
50
52
cxs = expand_weights (value_weights, degree, rxs)
51
53
expand (coefs, cxs, ixs)
52
54
end
@@ -59,7 +61,7 @@ Calculate the interpolated gradient of `itp` at `x`.
59
61
function expand_gradient (itp:: AbstractInterpolation , x:: Tuple )
60
62
coefs = coefficients (itp)
61
63
degree = interpdegree (itp)
62
- ixs, rxs = expand_indices_resid (degree, bounds (itp), x)
64
+ ixs, rxs = splitgrouped ( expand_indices_resid (degree, axes (itp), x) )
63
65
cxs = expand_weights (value_weights, degree, rxs)
64
66
gxs = expand_weights (gradient_weights, degree, rxs)
65
67
expand (coefs, (cxs, gxs), ixs)
68
70
function expand_gradient! (dest, itp:: AbstractInterpolation , x:: Tuple )
69
71
coefs = coefficients (itp)
70
72
degree = interpdegree (itp)
71
- ixs, rxs = expand_indices_resid (degree, bounds (itp), x)
73
+ ixs, rxs = splitgrouped ( expand_indices_resid (degree, axes (itp), x) )
72
74
cxs = expand_weights (value_weights, degree, rxs)
73
75
gxs = expand_weights (gradient_weights, degree, rxs)
74
76
expand! (dest, coefs, (cxs, gxs), ixs)
@@ -82,7 +84,7 @@ Calculate the interpolated hessian of `itp` at `x`.
82
84
function expand_hessian (itp:: AbstractInterpolation , x:: Tuple )
83
85
coefs = coefficients (itp)
84
86
degree = interpdegree (itp)
85
- ixs, rxs = expand_indices_resid (degree, bounds (itp), x)
87
+ ixs, rxs = splitgrouped ( expand_indices_resid (degree, axes (itp), x) )
86
88
cxs = expand_weights (value_weights, degree, rxs)
87
89
gxs = expand_weights (gradient_weights, degree, rxs)
88
90
hxs = expand_weights (hessian_weights, degree, rxs)
@@ -271,17 +273,16 @@ function expand!(dest, coefs, (vweights, gweights, hweights)::NTuple{3,HasNoInte
271
273
dest
272
274
end
273
275
274
- function expand_indices_resid (degree, bounds , x)
275
- ixbase, δxs = splitpaired ( _base_rem (degree, bounds , x) )
276
- expand_indices (degree, ixbase, bounds, δxs ), δxs
276
+ function expand_indices_resid (degree, axs , x)
277
+ item = expand_index_resid ( getfirst (degree), axs[ 1 ] , x[ 1 ] )
278
+ (item, expand_indices_resid ( getrest (degree), Base . tail (axs ), Base . tail (x)) ... )
277
279
end
280
+ expand_indices_resid (degree, :: Tuple{} , :: Tuple{} ) = ()
278
281
279
- @inline _base_rem (degree:: Union{Degree,NoInterp} , bounds, x) =
280
- (base_rem (degree, bounds[1 ], x[1 ]), _base_rem (degree, Base. tail (bounds), Base. tail (x))... )
281
- @inline _base_rem (degree:: Union{Degree,NoInterp} , :: Tuple{} , :: Tuple{} ) = ()
282
- @inline _base_rem (degree:: Tuple{Vararg{Union{Degree,NoInterp},N}} , bounds:: Tuple{Vararg{Any,N}} , x:: Tuple{Vararg{Number,N}} ) where N =
283
- (base_rem (degree[1 ], bounds[1 ], x[1 ]), _base_rem (Base. tail (degree), Base. tail (bounds), Base. tail (x))... )
284
- @inline _base_rem (:: Tuple{} , :: Tuple{} , :: Tuple{} ) = ()
282
+ function expand_index_resid (degree, ax, x:: Number )
283
+ ix, δx = base_rem (degree, ax, x)
284
+ expand_index (degree, ix, ax, δx), δx
285
+ end
285
286
286
287
expand_weights (f, degree:: Union{Degree,NoInterp} , ixs) =
287
288
(f (degree, ixs[1 ]), expand_weights (f, degree, Base. tail (ixs))... )
@@ -290,14 +291,14 @@ expand_weights(f, degree::Union{Degree,NoInterp}, ::Tuple{}) = ()
290
291
expand_weights (f, degree:: Tuple{Vararg{Union{Degree,NoInterp},N}} , ixs:: NTuple{N,Number} ) where N =
291
292
f .(degree, ixs)
292
293
293
- expand_indices (degree:: Union{Degree,NoInterp} , ixs, axs, δxs) =
294
- (expand_index (degree, ixs[1 ], axs[1 ], δxs[1 ]), expand_indices (degree, Base. tail (ixs), Base. tail (axs), Base. tail (δxs))... )
295
- expand_indices (degree:: Union{Degree,NoInterp} , :: Tuple{} , :: Tuple{} , :: Tuple{} ) = ()
294
+ # expand_indices(degree::Union{Degree,NoInterp}, ixs, axs, δxs) =
295
+ # (expand_index(degree, ixs[1], axs[1], δxs[1]), expand_indices(degree, Base.tail(ixs), Base.tail(axs), Base.tail(δxs))...)
296
+ # expand_indices(degree::Union{Degree,NoInterp}, ::Tuple{}, ::Tuple{}, ::Tuple{}) = ()
296
297
297
- expand_indices (degree:: Tuple{Vararg{Union{Degree,NoInterp},N}} , ixs:: NTuple{N,Number} , axs:: NTuple{N,Tuple{Real,Real}} , δxs:: NTuple{N,Number} ) where N =
298
- expand_index .(degree, ixs, axs, δxs)
298
+ # expand_indices(degree::Tuple{Vararg{Union{Degree,NoInterp},N}}, ixs::NTuple{N,Number}, axs::NTuple{N,Tuple{Real,Real}}, δxs::NTuple{N,Number}) where N =
299
+ # expand_index.(degree, ixs, axs, δxs)
299
300
300
- expand_index (degree, ixs, bounds:: Tuple{Real,Real} , δxs) = expand_index (degree, ixs, axfrombounds (bounds), δxs)
301
+ # expand_index(degree, ixs, bounds::Tuple{Real,Real}, δxs) = expand_index(degree, ixs, axfrombounds(bounds), δxs)
301
302
302
303
checklubounds (ls, us, xs) = _checklubounds (true , ls, us, xs)
303
304
_checklubounds (tf:: Bool , ls, us, xs) = _checklubounds (tf & (ls[1 ] <= xs[1 ] <= us[1 ]),
@@ -318,14 +319,19 @@ function getindex_return_type(::Type{BSplineInterpolation{T,N,TCoefs,IT,GT,Pad}}
318
319
end
319
320
320
321
# This handles round-towards-the-middle for points on half-integer edges
321
- roundbounds (x, bounds:: Tuple{Integer,Integer} ) = round (x)
322
- roundbounds (x, (l, u)) = ifelse (x == l, ceil (l), ifelse (x == u, floor (u), round (x)))
322
+ roundbounds (x:: Integer , bounds) = x
323
+ function roundbounds (x, bounds)
324
+ l, u = first (bounds), last (bounds)
325
+ h = half (x)
326
+ xh = x+ h
327
+ ifelse (x < u+ half (u), floor (xh), ceil (xh)- 1 )
328
+ end
323
329
324
- floorbounds (x, bounds:: Tuple{Integer,Integer} ) = floor (x)
325
- function floorbounds (x, (l, u):: Tuple{Real,Real} )
326
- ceill = ceil (l)
327
- ifelse (l <= x <= ceill, ceill, floor (x))
330
+ floorbounds (x:: Integer , ax) = x
331
+ function floorbounds (x, ax)
332
+ l = first (ax)
333
+ h = half (x)
334
+ ifelse (x < l, floor (x+ h), floor (x+ zero (h)))
328
335
end
329
336
330
- axfrombounds ((l, u):: Tuple{Integer,Integer} ) = UnitRange (l, u)
331
- axfrombounds ((l, u)) = UnitRange (ceil (Int, l), floor (Int, u))
337
+ half (x) = oneunit (x)/ 2
0 commit comments