Skip to content

Commit d7ab993

Browse files
femtocleaner[bot]sglyon
authored andcommitted
Fix deprecations (#176)
1 parent 35bd292 commit d7ab993

31 files changed

+283
-287
lines changed

perf/benchmarks.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ end
1010

1111
# To evaluate at fractional positions without any "unnecessary"
1212
# overhead, safer to use Base.Cartesian
13-
@generated function sumvalues{T,N}(itp::AbstractInterpolation{T,N}, inds)
13+
@generated function sumvalues(itp::AbstractInterpolation{T,N}, inds) where {T,N}
1414
quote
1515
@nexprs $N d->inds_d = inds[d]
1616
s = zero(eltype(itp))
@@ -28,13 +28,13 @@ function sumvalues_indices(itp)
2828
end
2929

3030
strip_prefix(str) = replace(str, "Interpolations.", "")
31-
benchstr{T<:Interpolations.GridType}(::Type{T}) = strip_prefix(string(T))
31+
benchstr(::Type{T}) where {T<:Interpolations.GridType} = strip_prefix(string(T))
3232

3333
benchstr(::Type{Constant}) = "Constant()"
3434
benchstr(::Type{Linear}) = "Linear()"
35-
benchstr{BC<:Interpolations.Flag}(::Type{Quadratic{BC}}) =
35+
benchstr(::Type{Quadratic{BC}}) where {BC<:Interpolations.Flag} =
3636
string("Quadratic(", strip_prefix(string(BC)), "())")
37-
benchstr{BC<:Interpolations.Flag}(::Type{Cubic{BC}}) =
37+
benchstr(::Type{Cubic{BC}}) where {BC<:Interpolations.Flag} =
3838
string("Quadratic(", strip_prefix(string(BC)), "())")
3939

4040
groupstr(::Type{Constant}) = "constant"

perf/run_shootout.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ include(joinpath(JULIA_HOME, "..", "..", "examples", "ndgrid.jl"))
55

66
# For the evaluation points, loop over 2:size(itp,d)-1.
77
# Since some interpolants are fast, we must ensure this call is type-stable.
8-
@generated function iterrange{T,N}(itp::AbstractArray{T,N})
8+
@generated function iterrange(itp::AbstractArray{T,N}) where {T,N}
99
min = ntuple(d->2, N)
1010
maxex = Expr(:tuple, Expr[:(size(itp,$d)-1) for d = 1:N]...)
1111
:(CartesianRange(CartesianIndex($min), CartesianIndex($maxex)))

src/Interpolations.jl

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -47,52 +47,52 @@ if !isdefined(Base, :oneunit)
4747
const oneunit = one
4848
end
4949

50-
@compat abstract type Flag end
51-
@compat abstract type InterpolationType <: Flag end
52-
immutable NoInterp <: InterpolationType end
53-
@compat abstract type GridType <: Flag end
54-
immutable OnGrid <: GridType end
55-
immutable OnCell <: GridType end
56-
57-
@compat const DimSpec{T} = Union{T,Tuple{Vararg{Union{T,NoInterp}}},NoInterp}
58-
59-
@compat abstract type AbstractInterpolation{T,N,IT<:DimSpec{InterpolationType},GT<:DimSpec{GridType}} <: AbstractArray{T,N} end
60-
@compat abstract type AbstractInterpolationWrapper{T,N,ITPT,IT,GT} <: AbstractInterpolation{T,N,IT,GT} end
61-
@compat abstract type AbstractExtrapolation{T,N,ITPT,IT,GT} <: AbstractInterpolationWrapper{T,N,ITPT,IT,GT} end
62-
63-
immutable Throw <: Flag end
64-
immutable Flat <: Flag end
65-
immutable Line <: Flag end
66-
immutable Free <: Flag end
67-
immutable Periodic <: Flag end
68-
immutable Reflect <: Flag end
69-
immutable InPlace <: Flag end
50+
abstract type Flag end
51+
abstract type InterpolationType <: Flag end
52+
struct NoInterp <: InterpolationType end
53+
abstract type GridType <: Flag end
54+
struct OnGrid <: GridType end
55+
struct OnCell <: GridType end
56+
57+
const DimSpec{T} = Union{T,Tuple{Vararg{Union{T,NoInterp}}},NoInterp}
58+
59+
abstract type AbstractInterpolation{T,N,IT<:DimSpec{InterpolationType},GT<:DimSpec{GridType}} <: AbstractArray{T,N} end
60+
abstract type AbstractInterpolationWrapper{T,N,ITPT,IT,GT} <: AbstractInterpolation{T,N,IT,GT} end
61+
abstract type AbstractExtrapolation{T,N,ITPT,IT,GT} <: AbstractInterpolationWrapper{T,N,ITPT,IT,GT} end
62+
63+
struct Throw <: Flag end
64+
struct Flat <: Flag end
65+
struct Line <: Flag end
66+
struct Free <: Flag end
67+
struct Periodic <: Flag end
68+
struct Reflect <: Flag end
69+
struct InPlace <: Flag end
7070
# InPlaceQ is exact for an underlying quadratic. This is nice for ground-truth testing
7171
# of in-place (unpadded) interpolation.
72-
immutable InPlaceQ <: Flag end
72+
struct InPlaceQ <: Flag end
7373
const Natural = Line
7474

75-
@generated size{T, N}(itp::AbstractInterpolation{T,N}) = Expr(:tuple, [:(size(itp, $i)) for i in 1:N]...)
75+
@generated size(itp::AbstractInterpolation{T,N}) where {T, N} = Expr(:tuple, [:(size(itp, $i)) for i in 1:N]...)
7676
size(exp::AbstractExtrapolation, d) = size(exp.itp, d)
77-
bounds{T,N}(itp::AbstractInterpolation{T,N}) = tuple(zip(lbounds(itp), ubounds(itp))...)
78-
bounds{T,N}(itp::AbstractInterpolation{T,N}, d) = (lbound(itp,d),ubound(itp,d))
79-
@generated lbounds{T,N}(itp::AbstractInterpolation{T,N}) = Expr(:tuple, [:(lbound(itp, $i)) for i in 1:N]...)
80-
@generated ubounds{T,N}(itp::AbstractInterpolation{T,N}) = Expr(:tuple, [:(ubound(itp, $i)) for i in 1:N]...)
81-
lbound{T,N}(itp::AbstractInterpolation{T,N}, d) = 1
82-
ubound{T,N}(itp::AbstractInterpolation{T,N}, d) = size(itp, d)
83-
itptype{T,N,IT<:DimSpec{InterpolationType},GT<:DimSpec{GridType}}(::Type{AbstractInterpolation{T,N,IT,GT}}) = IT
84-
itptype{ITP<:AbstractInterpolation}(::Type{ITP}) = itptype(supertype(ITP))
77+
bounds(itp::AbstractInterpolation{T,N}) where {T,N} = tuple(zip(lbounds(itp), ubounds(itp))...)
78+
bounds(itp::AbstractInterpolation{T,N}, d) where {T,N} = (lbound(itp,d),ubound(itp,d))
79+
@generated lbounds(itp::AbstractInterpolation{T,N}) where {T,N} = Expr(:tuple, [:(lbound(itp, $i)) for i in 1:N]...)
80+
@generated ubounds(itp::AbstractInterpolation{T,N}) where {T,N} = Expr(:tuple, [:(ubound(itp, $i)) for i in 1:N]...)
81+
lbound(itp::AbstractInterpolation{T,N}, d) where {T,N} = 1
82+
ubound(itp::AbstractInterpolation{T,N}, d) where {T,N} = size(itp, d)
83+
itptype(::Type{AbstractInterpolation{T,N,IT,GT}}) where {T,N,IT<:DimSpec{InterpolationType},GT<:DimSpec{GridType}} = IT
84+
itptype(::Type{ITP}) where {ITP<:AbstractInterpolation} = itptype(supertype(ITP))
8585
itptype(itp::AbstractInterpolation ) = itptype(typeof(itp))
86-
gridtype{T,N,IT<:DimSpec{InterpolationType},GT<:DimSpec{GridType}}(::Type{AbstractInterpolation{T,N,IT,GT}}) = GT
87-
gridtype{ITP<:AbstractInterpolation}(::Type{ITP}) = gridtype(supertype(ITP))
86+
gridtype(::Type{AbstractInterpolation{T,N,IT,GT}}) where {T,N,IT<:DimSpec{InterpolationType},GT<:DimSpec{GridType}} = GT
87+
gridtype(::Type{ITP}) where {ITP<:AbstractInterpolation} = gridtype(supertype(ITP))
8888
gridtype(itp::AbstractInterpolation) = gridtype(typeof(itp))
89-
ndims{T,N,IT<:DimSpec{InterpolationType},GT<:DimSpec{GridType}}(::Type{AbstractInterpolation{T,N,IT,GT}}) = N
90-
ndims{ITP<:AbstractInterpolation}(::Type{ITP}) = ndims(supertype(ITP))
89+
ndims(::Type{AbstractInterpolation{T,N,IT,GT}}) where {T,N,IT<:DimSpec{InterpolationType},GT<:DimSpec{GridType}} = N
90+
ndims(::Type{ITP}) where {ITP<:AbstractInterpolation} = ndims(supertype(ITP))
9191
ndims(itp::AbstractInterpolation) = ndims(typeof(itp))
92-
eltype{T,N,IT<:DimSpec{InterpolationType},GT<:DimSpec{GridType}}(::Type{AbstractInterpolation{T,N,IT,GT}}) = T
93-
eltype{ITP<:AbstractInterpolation}(::Type{ITP}) = eltype(supertype(ITP))
92+
eltype(::Type{AbstractInterpolation{T,N,IT,GT}}) where {T,N,IT<:DimSpec{InterpolationType},GT<:DimSpec{GridType}} = T
93+
eltype(::Type{ITP}) where {ITP<:AbstractInterpolation} = eltype(supertype(ITP))
9494
eltype(itp::AbstractInterpolation) = eltype(typeof(itp))
95-
count_interp_dims{T<:AbstractInterpolation}(::Type{T}, N) = N
95+
count_interp_dims(::Type{T}, N) where {T<:AbstractInterpolation} = N
9696

9797
include("nointerp/nointerp.jl")
9898
include("b-splines/b-splines.jl")

src/b-splines/b-splines.jl

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@ export
77
Quadratic,
88
Cubic
99

10-
@compat abstract type Degree{N} <: Flag end
10+
abstract type Degree{N} <: Flag end
1111

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}()
1414

15-
bsplinetype{D<:Degree}(::Type{BSpline{D}}) = D
15+
bsplinetype(::Type{BSpline{D}}) where {D<:Degree} = D
1616

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}
1818
coefs::TCoefs
1919
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}
2121
isleaftype(IT) || error("The b-spline type must be a leaf type (was $IT)")
2222
isleaftype(typeof(A)) || warn("For performance reasons, consider using an array of a concrete type (typeof(A) == $(typeof(A)))")
2323

@@ -31,65 +31,65 @@ function BSplineInterpolation{N,Tel,TWeights<:Real,IT<:DimSpec{BSpline},GT<:DimS
3131
end
3232

3333
# 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
3535
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
3737
padding(itp::AbstractInterpolation) = padding(typeof(itp))
3838
padextract(pad::Integer, d) = pad
3939
padextract(pad::Tuple{Vararg{Integer}}, d) = pad[d]
4040

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} =
4242
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} =
4444
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} =
4646
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} =
4848
last(indices(itp, d))+0.5
4949

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} =
5151
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} =
5353
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} =
5555
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} =
5757
last(inds)+0.5
5858

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)
6060

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}
6262
d <= N ? size(itp.coefs, d) - 2*padextract(pad, d) : 1
6363
end
6464

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} =
6666
map_repeat(indices_removepad, indices(itp.coefs), pad)
6767

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}
6969
d <= N ? indices_removepad(indices(itp.coefs, d), padextract(pad, d)) : indices(itp.coefs, d)
7070
end
7171

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}}
7373
Apad, Pad = prefilter(TWeights, TC, A, IT, GT)
7474
BSplineInterpolation(TWeights, Apad, it, gt, Pad)
7575
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}}
7777
interpolate(tweight(A), tcoef(A), A, it, gt)
7878
end
7979

8080
# We can't just return a tuple-of-types due to julia #12500
8181
tweight(A::AbstractArray) = Float64
8282
tweight(A::AbstractArray{Float32}) = Float32
8383
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)))
8585

8686
tcoef(A::AbstractArray) = eltype(A)
8787
tcoef(A::AbstractArray{Float32}) = Float32
8888
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)))
9090

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}}
9393
interpolate!(tweight(A), A, it, gt)
9494
end
9595

@@ -113,14 +113,14 @@ Equivalent to `(f(a[1], b[1]), f(a[2], b[2]), ...)` if `a` and `b` are
113113
tuples of the same lengths, or `(f(a[1], b), f(a[2], b), ...)` if `b`
114114
is a scalar.
115115
"""
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
117117
ex = [:(f(a[$i], b[$i])) for i = 1:N]
118118
quote
119119
$(Expr(:meta, :inline))
120120
($(ex...),)
121121
end
122122
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
124124
ex = [:(f(a[$i], b)) for i = 1:N]
125125
quote
126126
$(Expr(:meta, :inline))
@@ -136,5 +136,5 @@ include("indexing.jl")
136136
include("prefiltering.jl")
137137
include("../filter1d.jl")
138138

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."))

src/b-splines/constant.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
immutable Constant <: Degree{0} end
1+
struct Constant <: Degree{0} end
22

33
"""
44
Constant b-splines are *nearest-neighbor* interpolations, and effectively
@@ -41,7 +41,7 @@ function hessian_coefficients(::Type{BSpline{Constant}}, d)
4141
:($sym = 0)
4242
end
4343

44-
function index_gen{IT<:DimSpec{BSpline}}(::Type{BSpline{Constant}}, ::Type{IT}, N::Integer, offsets...)
44+
function index_gen(::Type{BSpline{Constant}}, ::Type{IT}, N::Integer, offsets...) where IT<:DimSpec{BSpline}
4545
if (length(offsets) < N)
4646
d = length(offsets)+1
4747
sym = Symbol("c_", d)

0 commit comments

Comments
 (0)