@@ -161,6 +161,11 @@ function interpolate(::Type{TWeights}, ::Type{TC}, A, it::IT) where {TWeights,TC
161161 BSplineInterpolation (TWeights, Apad, it, axes (A))
162162end
163163
164+ function interpolate (:: Type{TWeights} , :: Type{TC} , A, it:: IT , λ:: Real , k:: Int ) where {TWeights,TC,IT<: DimSpec{BSpline} }
165+ Apad = prefilter (TWeights, TC, A, it, λ, k)
166+ BSplineInterpolation (TWeights, Apad, it, axes (A))
167+ end
168+
164169"""
165170 itp = interpolate(A, interpmode)
166171
@@ -179,6 +184,33 @@ function interpolate(A::AbstractArray, it::IT) where {IT<:DimSpec{BSpline}}
179184 interpolate (tweight (A), tcoef (A), A, it)
180185end
181186
187+ """
188+ itp = interpolate(A, interpmode, gridstyle, λ, k)
189+
190+ Interpolate an array `A` in the mode determined by `interpmode` and `gridstyle`
191+ with regularization following [1], of order `k` and constant `λ`.
192+ `interpmode` may be one of
193+
194+ - `BSpline(NoInterp())`
195+ - `BSpline(Linear())`
196+ - `BSpline(Quadratic(BC()))` (see [`BoundaryCondition`](@ref))
197+ - `BSpline(Cubic(BC()))`
198+
199+ It may also be a tuple of such values, if you want to use different interpolation schemes along each axis.
200+
201+ `gridstyle` should be one of `OnGrid()` or `OnCell()`.
202+
203+ `k` corresponds to the derivative to penalize. In the limit λ->∞, the interpolation function is
204+ a polynomial of order `k-1`. A value of 2 is the most common.
205+
206+ `λ` is non-negative. If its value is zero, it falls back to non-regularized interpolation.
207+
208+ [1] https://projecteuclid.org/euclid.ss/1038425655.
209+ """
210+ function interpolate (A:: AbstractArray , it:: IT , λ:: Real , k:: Int ) where {IT<: DimSpec{BSpline} }
211+ interpolate (tweight (A), tcoef (A), A, it, λ, k)
212+ end
213+
182214# We can't just return a tuple-of-types due to julia #12500
183215tweight (A:: AbstractArray ) = Float64
184216tweight (A:: AbstractArray{T} ) where T<: AbstractFloat = T
@@ -201,6 +233,16 @@ function interpolate!(A::AbstractArray, it::IT) where {IT<:DimSpec{BSpline}}
201233 interpolate! (tweight (A), A, it)
202234end
203235
236+ function interpolate! (:: Type{TWeights} , A:: AbstractArray , it:: IT , λ:: Real , k:: Int ) where {TWeights,IT<: DimSpec{BSpline} }
237+ # Set the bounds of the interpolant inward, if necessary
238+ axsA = axes (A)
239+ axspad = padded_axes (axsA, it)
240+ BSplineInterpolation (TWeights, prefilter! (TWeights, A, it, λ, k), it, fix_axis .(padinset .(axsA, axspad)))
241+ end
242+ function interpolate! (A:: AbstractArray , it:: IT , λ:: Real , k:: Int ) where {IT<: DimSpec{BSpline} }
243+ interpolate! (tweight (A), A, it, λ, k)
244+ end
245+
204246lut! (dl, d, du) = lu! (Tridiagonal (dl, d, du), Val (false ))
205247
206248include (" constant.jl" )
@@ -211,6 +253,6 @@ include("indexing.jl")
211253include (" prefiltering.jl" )
212254include (" ../filter1d.jl" )
213255
214- Base. parent (A:: BSplineInterpolation{T,N,TCoefs,UT} ) where {T,N,TCoefs,UT<: Union{BSpline{Linear},BSpline{Constant}} } = A. coefs
256+ Base. parent (A:: BSplineInterpolation{T,N,TCoefs,UT} ) where {T,N,TCoefs,UT<: Union{BSpline{Linear},BSpline{<: Constant}} } = A. coefs
215257Base. parent (A:: BSplineInterpolation{T,N,TCoefs,UT} ) where {T,N,TCoefs,UT} =
216258 throw (ArgumentError (" The given BSplineInterpolation does not serve as a \" view\" for a parent array. This would only be true for Constant and Linear b-splines." ))
0 commit comments