7
7
Quadratic,
8
8
Cubic
9
9
10
- @compat abstract type Degree{N} <: Flag end
10
+ abstract type Degree{N} <: Flag end
11
11
12
- immutable BSpline{D<: Degree } <: InterpolationType end
13
- BSpline {D<:Degree} ( :: D ) = BSpline {D} ()
12
+ struct BSpline{D<: Degree } <: InterpolationType end
13
+ BSpline ( :: D ) where {D<: Degree } = BSpline {D} ()
14
14
15
- bsplinetype {D<:Degree} (:: Type{BSpline{D}} ) = D
15
+ bsplinetype (:: Type{BSpline{D}} ) where {D <: Degree } = D
16
16
17
- immutable BSplineInterpolation{T,N,TCoefs<: AbstractArray ,IT<: DimSpec{BSpline} ,GT<: DimSpec{GridType} ,pad} <: AbstractInterpolation{T,N,IT,GT}
17
+ struct BSplineInterpolation{T,N,TCoefs<: AbstractArray ,IT<: DimSpec{BSpline} ,GT<: DimSpec{GridType} ,pad} <: AbstractInterpolation{T,N,IT,GT}
18
18
coefs:: TCoefs
19
19
end
20
- function BSplineInterpolation {N,Tel,TWeights<:Real,IT<:DimSpec{BSpline},GT<:DimSpec{GridType},pad} (:: Type{TWeights} , A:: AbstractArray{Tel,N} , :: IT , :: GT , :: Val{pad} )
20
+ function BSplineInterpolation (:: Type{TWeights} , A:: AbstractArray{Tel,N} , :: IT , :: GT , :: Val{pad} ) where {N,Tel,TWeights <: Real ,IT <: DimSpec{BSpline} ,GT <: DimSpec{GridType} ,pad}
21
21
isleaftype (IT) || error (" The b-spline type must be a leaf type (was $IT )" )
22
22
isleaftype (typeof (A)) || warn (" For performance reasons, consider using an array of a concrete type (typeof(A) == $(typeof (A)) )" )
23
23
@@ -31,65 +31,65 @@ function BSplineInterpolation{N,Tel,TWeights<:Real,IT<:DimSpec{BSpline},GT<:DimS
31
31
end
32
32
33
33
# Utilities for working either with scalars or tuples/tuple-types
34
- iextract {T<:BSpline} (:: Type{T} , d) = T
34
+ iextract (:: Type{T} , d) where {T <: BSpline } = T
35
35
iextract (t, d) = t. parameters[d]
36
- padding { T,N,TCoefs,IT,GT,pad}( :: Type{BSplineInterpolation{ T,N,TCoefs,IT,GT,pad}} ) = pad
36
+ padding ( :: Type{BSplineInterpolation{ T,N,TCoefs,IT,GT,pad}} ) where { T,N,TCoefs,IT,GT,pad} = pad
37
37
padding (itp:: AbstractInterpolation ) = padding (typeof (itp))
38
38
padextract (pad:: Integer , d) = pad
39
39
padextract (pad:: Tuple{Vararg{Integer}} , d) = pad[d]
40
40
41
- lbound {T,N,TCoefs,IT} (itp:: BSplineInterpolation{T,N,TCoefs,IT,OnGrid} , d:: Integer ) =
41
+ lbound (itp:: BSplineInterpolation{T,N,TCoefs,IT,OnGrid} , d:: Integer ) where {T,N,TCoefs,IT} =
42
42
first (indices (itp, d))
43
- ubound {T,N,TCoefs,IT} (itp:: BSplineInterpolation{T,N,TCoefs,IT,OnGrid} , d:: Integer ) =
43
+ ubound (itp:: BSplineInterpolation{T,N,TCoefs,IT,OnGrid} , d:: Integer ) where {T,N,TCoefs,IT} =
44
44
last (indices (itp, d))
45
- lbound {T,N,TCoefs,IT} (itp:: BSplineInterpolation{T,N,TCoefs,IT,OnCell} , d:: Integer ) =
45
+ lbound (itp:: BSplineInterpolation{T,N,TCoefs,IT,OnCell} , d:: Integer ) where {T,N,TCoefs,IT} =
46
46
first (indices (itp, d)) - 0.5
47
- ubound {T,N,TCoefs,IT} (itp:: BSplineInterpolation{T,N,TCoefs,IT,OnCell} , d:: Integer ) =
47
+ ubound (itp:: BSplineInterpolation{T,N,TCoefs,IT,OnCell} , d:: Integer ) where {T,N,TCoefs,IT} =
48
48
last (indices (itp, d))+ 0.5
49
49
50
- lbound {T,N,TCoefs,IT} (itp:: BSplineInterpolation{T,N,TCoefs,IT,OnGrid} , d, inds) =
50
+ lbound (itp:: BSplineInterpolation{T,N,TCoefs,IT,OnGrid} , d, inds) where {T,N,TCoefs,IT} =
51
51
first (inds)
52
- ubound {T,N,TCoefs,IT} (itp:: BSplineInterpolation{T,N,TCoefs,IT,OnGrid} , d, inds) =
52
+ ubound (itp:: BSplineInterpolation{T,N,TCoefs,IT,OnGrid} , d, inds) where {T,N,TCoefs,IT} =
53
53
last (inds)
54
- lbound {T,N,TCoefs,IT} (itp:: BSplineInterpolation{T,N,TCoefs,IT,OnCell} , d, inds) =
54
+ lbound (itp:: BSplineInterpolation{T,N,TCoefs,IT,OnCell} , d, inds) where {T,N,TCoefs,IT} =
55
55
first (inds) - 0.5
56
- ubound {T,N,TCoefs,IT} (itp:: BSplineInterpolation{T,N,TCoefs,IT,OnCell} , d, inds) =
56
+ ubound (itp:: BSplineInterpolation{T,N,TCoefs,IT,OnCell} , d, inds) where {T,N,TCoefs,IT} =
57
57
last (inds)+ 0.5
58
58
59
- count_interp_dims { T,N,TCoefs,IT<:DimSpec{InterpolationType} ,GT<:DimSpec{GridType} ,pad}( :: Type{BSplineInterpolation{ T,N,TCoefs,IT,GT,pad}} , n) = count_interp_dims (IT, n)
59
+ count_interp_dims ( :: Type{BSplineInterpolation{ T,N,TCoefs,IT,GT,pad}} , n) where { T,N,TCoefs,IT<: DimSpec{InterpolationType} ,GT<: DimSpec{GridType} ,pad} = count_interp_dims (IT, n)
60
60
61
- function size {T,N,TCoefs,IT,GT,pad} (itp :: BSplineInterpolation {T,N,TCoefs,IT,GT,pad}, d)
61
+ function size (itp :: BSplineInterpolation {T,N,TCoefs,IT,GT,pad}, d) where {T,N,TCoefs,IT,GT,pad}
62
62
d <= N ? size (itp. coefs, d) - 2 * padextract (pad, d) : 1
63
63
end
64
64
65
- @inline indices {T,N,TCoefs,IT,GT,pad} (itp :: BSplineInterpolation {T,N,TCoefs,IT,GT,pad}) =
65
+ @inline indices (itp :: BSplineInterpolation {T,N,TCoefs,IT,GT,pad}) where {T,N,TCoefs,IT,GT,pad} =
66
66
map_repeat (indices_removepad, indices (itp. coefs), pad)
67
67
68
- function indices {T,N,TCoefs,IT,GT,pad} (itp :: BSplineInterpolation {T,N,TCoefs,IT,GT,pad}, d)
68
+ function indices (itp :: BSplineInterpolation {T,N,TCoefs,IT,GT,pad}, d) where {T,N,TCoefs,IT,GT,pad}
69
69
d <= N ? indices_removepad (indices (itp. coefs, d), padextract (pad, d)) : indices (itp. coefs, d)
70
70
end
71
71
72
- function interpolate {TWeights,TC,IT<:DimSpec{BSpline},GT<:DimSpec{GridType}} (:: Type{TWeights} , :: Type{TC} , A, it:: IT , gt:: GT )
72
+ function interpolate (:: Type{TWeights} , :: Type{TC} , A, it:: IT , gt:: GT ) where {TWeights,TC,IT <: DimSpec{BSpline} ,GT <: DimSpec{GridType} }
73
73
Apad, Pad = prefilter (TWeights, TC, A, IT, GT)
74
74
BSplineInterpolation (TWeights, Apad, it, gt, Pad)
75
75
end
76
- function interpolate {IT<:DimSpec{BSpline},GT<:DimSpec{GridType}} (A:: AbstractArray , it:: IT , gt:: GT )
76
+ function interpolate (A:: AbstractArray , it:: IT , gt:: GT ) where {IT <: DimSpec{BSpline} ,GT <: DimSpec{GridType} }
77
77
interpolate (tweight (A), tcoef (A), A, it, gt)
78
78
end
79
79
80
80
# We can't just return a tuple-of-types due to julia #12500
81
81
tweight (A:: AbstractArray ) = Float64
82
82
tweight (A:: AbstractArray{Float32} ) = Float32
83
83
tweight (A:: AbstractArray{Rational{Int}} ) = Rational{Int}
84
- tweight {T<:Integer} (A:: AbstractArray{T} ) = typeof (float (zero (T)))
84
+ tweight (A:: AbstractArray{T} ) where {T <: Integer } = typeof (float (zero (T)))
85
85
86
86
tcoef (A:: AbstractArray ) = eltype (A)
87
87
tcoef (A:: AbstractArray{Float32} ) = Float32
88
88
tcoef (A:: AbstractArray{Rational{Int}} ) = Rational{Int}
89
- tcoef {T<:Integer} (A:: AbstractArray{T} ) = typeof (float (zero (T)))
89
+ tcoef (A:: AbstractArray{T} ) where {T <: Integer } = typeof (float (zero (T)))
90
90
91
- interpolate! {TWeights,IT<:DimSpec{BSpline},GT<:DimSpec{GridType}} (:: Type{TWeights} , A, it:: IT , gt:: GT ) = BSplineInterpolation (TWeights, prefilter! (TWeights, A, IT, GT), it, gt, Val {0} ())
92
- function interpolate! {IT<:DimSpec{BSpline},GT<:DimSpec{GridType}} (A:: AbstractArray , it:: IT , gt:: GT )
91
+ interpolate! (:: Type{TWeights} , A, it:: IT , gt:: GT ) where {TWeights,IT <: DimSpec{BSpline} ,GT <: DimSpec{GridType} } = BSplineInterpolation (TWeights, prefilter! (TWeights, A, IT, GT), it, gt, Val {0} ())
92
+ function interpolate! (A:: AbstractArray , it:: IT , gt:: GT ) where {IT <: DimSpec{BSpline} ,GT <: DimSpec{GridType} }
93
93
interpolate! (tweight (A), A, it, gt)
94
94
end
95
95
@@ -113,14 +113,14 @@ Equivalent to `(f(a[1], b[1]), f(a[2], b[2]), ...)` if `a` and `b` are
113
113
tuples of the same lengths, or `(f(a[1], b), f(a[2], b), ...)` if `b`
114
114
is a scalar.
115
115
"""
116
- @generated function map_repeat {N} (f, a:: NTuple{N,Any} , b:: NTuple{N,Any} )
116
+ @generated function map_repeat (f, a:: NTuple{N,Any} , b:: NTuple{N,Any} ) where N
117
117
ex = [:(f (a[$ i], b[$ i])) for i = 1 : N]
118
118
quote
119
119
$ (Expr (:meta , :inline ))
120
120
($ (ex... ),)
121
121
end
122
122
end
123
- @generated function map_repeat {N} (f, a:: NTuple{N,Any} , b)
123
+ @generated function map_repeat (f, a:: NTuple{N,Any} , b) where N
124
124
ex = [:(f (a[$ i], b)) for i = 1 : N]
125
125
quote
126
126
$ (Expr (:meta , :inline ))
@@ -136,5 +136,5 @@ include("indexing.jl")
136
136
include (" prefiltering.jl" )
137
137
include (" ../filter1d.jl" )
138
138
139
- Base. parent {T,N,TCoefs,UT<:Union{BSpline{Linear},BSpline{Constant}}} (A :: BSplineInterpolation{T,N,TCoefs,UT} ) = A. coefs
140
- Base. parent {T,N,TCoefs,UT} (A :: BSplineInterpolation {T,N,TCoefs,UT}) = 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." ))
139
+ Base. parent (A :: BSplineInterpolation {T,N,TCoefs,UT} ) where {T,N,TCoefs,UT <: Union{BSpline{Linear},BSpline{Constant}} } = A. coefs
140
+ Base. parent (A :: BSplineInterpolation {T,N,TCoefs,UT}) where {T,N,TCoefs,UT} = 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