Skip to content

Commit f7b7b54

Browse files
femtocleaner[bot]sglyon
authored andcommitted
Fix deprecations (#39)
* Fix deprecations * BUG: clean up test that should have been changed in last PR
1 parent 75f93a5 commit f7b7b54

File tree

14 files changed

+205
-219
lines changed

14 files changed

+205
-219
lines changed

src/BasisMatrices.jl

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -42,25 +42,21 @@ export nodes, get_coefs, funfitxy, funfitf, funeval, evalbase,
4242
#re-exports
4343
export gridmake, gridmake!, ckron
4444

45-
@compat abstract type BasisFamily end
46-
@compat abstract type BasisParams end
45+
abstract type BasisFamily end
46+
abstract type BasisParams end
4747
const IntSorV = Union{Int, AbstractVector{Int}}
48-
@static if VERSION >= v"0.6.0-dev.2123"
49-
const TensorX = Union{Tuple{Vararg{AbstractVector}},AbstractVector{<:AbstractVector}}
50-
else
51-
const TensorX = Union{Tuple{Vararg{AbstractVector}},AbstractVector{TypeVar(:TV,AbstractVector)}}
52-
end
48+
const TensorX = Union{Tuple{Vararg{AbstractVector}},AbstractVector{<:AbstractVector}}
5349

5450
include("util.jl")
5551
include("spline_sparse.jl")
5652

5753
# include the families
5854

5955
# BasisParams interface
60-
Base.issparse{T<:BasisParams}(::Type{T}) = false
56+
Base.issparse(::Type{T}) where {T<:BasisParams} = false
6157
Base.ndims(::BasisParams) = 1
6258
for f in [:family, :family_name, :(Base.issparse), :(Base.eltype)]
63-
@eval $(f){T<:BasisParams}(::T) = $(f)(T)
59+
@eval $(f)(::T) where {T<:BasisParams} = $(f)(T)
6460
end
6561
include("cheb.jl")
6662
include("lin.jl")
@@ -72,8 +68,8 @@ evalbase(p::BasisParams, x::Number, args...) = evalbase(p, [x], args...)
7268

7369
# now some more interface methods that only make sense once we have defined
7470
# the subtypes
75-
basis_eltype{TP<:BasisParams}(::TP, x) = promote_type(eltype(TP), eltype(x))
76-
basis_eltype{TP<:BasisParams}(::Type{TP}, x) = promote_type(eltype(TP), eltype(x))
71+
basis_eltype(::TP, x) where {TP<:BasisParams} = promote_type(eltype(TP), eltype(x))
72+
basis_eltype(::Type{TP}, x) where {TP<:BasisParams} = promote_type(eltype(TP), eltype(x))
7773
"""
7874
basis_eltype(p::Union{BasisParams,Type{<:BasisParams}, x)
7975
@@ -88,31 +84,31 @@ basis_eltype
8884
# the default is just a dense matrix
8985
# because there is only one dense version, we will start with the sparse
9086
# case and overload for Cheb
91-
bmat_type{TP<:BasisParams}(::Type{TP}, x) = SparseMatrixCSC{basis_eltype(TP, x),Int}
92-
bmat_type{TP<:BasisParams,T2}(::Type{T2}, ::Type{TP}, x) = bmat_type(TP, x)
93-
function bmat_type{TP<:BasisParams,T2<:SplineSparse}(::Type{T2}, ::Type{TP}, x)
87+
bmat_type(::Type{TP}, x) where {TP<:BasisParams} = SparseMatrixCSC{basis_eltype(TP, x),Int}
88+
bmat_type(::Type{T2}, ::Type{TP}, x) where {TP<:BasisParams,T2} = bmat_type(TP, x)
89+
function bmat_type(::Type{T2}, ::Type{TP}, x) where {TP<:BasisParams,T2<:SplineSparse}
9490
SplineSparse{basis_eltype(TP, x),Int}
9591
end
9692

97-
bmat_type{T<:ChebParams}(::Type{T}, x) = Matrix{basis_eltype(T, x)}
98-
function bmat_type{TP<:ChebParams,T2<:SplineSparse}(::Type{T2}, ::Type{TP}, x)
93+
bmat_type(::Type{T}, x) where {T<:ChebParams} = Matrix{basis_eltype(T, x)}
94+
function bmat_type(::Type{T2}, ::Type{TP}, x) where {TP<:ChebParams,T2<:SplineSparse}
9995
bmat_type(TP, x)
10096
end
10197

10298
# version where there isn't an x passed
103-
bmat_type{TP<:BasisParams}(::Type{TP}) = bmat_type(TP, one(eltype(TP)))
104-
function bmat_type{TP<:BasisParams,T2}(::Type{T2}, ::Type{TP})
99+
bmat_type(::Type{TP}) where {TP<:BasisParams} = bmat_type(TP, one(eltype(TP)))
100+
function bmat_type(::Type{T2}, ::Type{TP}) where {TP<:BasisParams,T2}
105101
bmat_type(T2, TP, one(eltype(TP)))
106102
end
107103

108104
# add methods to instances
109-
bmat_type{T<:BasisParams}(::T) = bmat_type(T)
110-
bmat_type{TF<:BasisParams,T2}(ss::Type{T2}, ::TF) = bmat_type(T2, TF)
111-
bmat_type{TF<:BasisParams,T2}(ss::Type{T2}, ::TF, x) = bmat_type(T2, TF, x)
105+
bmat_type(::T) where {T<:BasisParams} = bmat_type(T)
106+
bmat_type(ss::Type{T2}, ::TF) where {TF<:BasisParams,T2} = bmat_type(T2, TF)
107+
bmat_type(ss::Type{T2}, ::TF, x) where {TF<:BasisParams,T2} = bmat_type(T2, TF, x)
112108

113109
# default method for evalbase with extra type hint is to just ignore the extra
114110
# type hint
115-
evalbase{T}(::Type{T}, bp::BasisParams, x, order) = evalbase(bp, x, order)
111+
evalbase(::Type{T}, bp::BasisParams, x, order) where {T} = evalbase(bp, x, order)
116112

117113

118114
# include other

src/basis.jl

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,29 @@ for (T, TP) in [(Cheb, ChebParams), (Lin, LinParams), (Spline, SplineParams)]
44
end
55

66
# params of same type are equal if all their fields are equal
7-
=={T<:BasisParams}(p1::T, p2::T) =
7+
==(p1::T, p2::T) where {T<:BasisParams} =
88
all(map(nm->getfield(p1, nm) == getfield(p2, nm), fieldnames(p1)))::Bool
99

1010
# Bases of different dimension can't be equal
11-
=={T1<:BasisParams,T2<:BasisParams}(::T1, ::T2) = false
11+
==(::T1, ::T2) where {T1<:BasisParams,T2<:BasisParams} = false
1212

1313
# ---------- #
1414
# Basis Type #
1515
# ---------- #
1616

17-
type Basis{N,TP<:Tuple}
17+
mutable struct Basis{N,TP<:Tuple}
1818
params::TP # params to construct basis
1919
end
2020

2121
Base.min(b::Basis) = min.(b.params)
2222
Base.max(b::Basis) = max.(b.params)
23-
Base.ndims{N}(::Basis{N}) = N
24-
Base.ndims{N,TP}(::Type{Basis{N,TP}}) = N
23+
Base.ndims(::Basis{N}) where {N} = N
24+
Base.ndims(::Type{Basis{N,TP}}) where {N,TP} = N
2525

26-
_get_TP{N,TP}(::Basis{N,TP}) = TP
27-
_get_TP{N,TP}(::Type{Basis{N,TP}}) = TP
26+
_get_TP(::Basis{N,TP}) where {N,TP} = TP
27+
_get_TP(::Type{Basis{N,TP}}) where {N,TP} = TP
2828

29-
function Base.show{N}(io::IO, b::Basis{N})
29+
function Base.show(io::IO, b::Basis{N}) where N
3030
m = """
3131
$N dimensional Basis on the hypercube formed by $(min(b)) × $(max(b)).
3232
Basis families are $(join(string.(family_name.(b.params)), " × "))
@@ -75,9 +75,9 @@ end
7575
# fundefn type method
7676
Basis(bt::BasisFamily, n::Int, a, b) = Basis(_param(bt)(n, a, b))
7777

78-
Basis{T<:BasisFamily}(::Type{T}, n::Int, a, b) = Basis(T(), n, a, b)
78+
Basis(::Type{T}, n::Int, a, b) where {T<:BasisFamily} = Basis(T(), n, a, b)
7979

80-
Basis{T<:BasisFamily}(bt::T, n::Vector, a::Vector, b::Vector) =
80+
Basis(bt::T, n::Vector, a::Vector, b::Vector) where {T<:BasisFamily} =
8181
Basis(map(_param(T), n, a, b)...)
8282

8383
# special method for Spline that adds `k` argument
@@ -90,23 +90,23 @@ Basis(::Spline, n::Vector, a::Vector, b::Vector, k::Vector=ones(Int, length(n)))
9090
# ----------------- #
9191

9292
# separating Basis -- just re construct it from the nth set of params
93-
function Base.getindex{N}(basis::Basis{N}, n::Int)
93+
function Base.getindex(basis::Basis{N}, n::Int) where N
9494
n < 0 || n > N && error("n must be between 1 and $N")
9595
Basis(basis.params[n])::Basis{1}
9696
end
9797

98-
_all_sparse{N,TP}(b::Basis{N,TP}) = all(issparse, TP.parameters)
98+
_all_sparse(b::Basis{N,TP}) where {N,TP} = all(issparse, TP.parameters)
9999

100100
# other AbstractArray like methods for Basis
101101
Base.length(b::Basis) = prod(length, b.params)
102102
Base.size(b::Basis, i::Int) = length(b[i]) # uses method on previous line
103-
Base.size{N}(b::Basis{N}) = map(length, b.params)
103+
Base.size(b::Basis{N}) where {N} = map(length, b.params)
104104

105105
# Bases of different dimension can't be equal
106-
=={N,M}(::Basis{N}, ::Basis{M}) = false
106+
==(::Basis{N}, ::Basis{M}) where {N,M} = false
107107

108108
# basis are equal if all fields of the basis are equal
109-
=={N}(b1::Basis{N}, b2::Basis{N}) =
109+
==(b1::Basis{N}, b2::Basis{N}) where {N} =
110110
all(map(nm->getfield(b1, nm) == getfield(b2, nm), fieldnames(b1)))::Bool
111111

112112
function nodes(b::Basis{1})
@@ -120,7 +120,7 @@ function nodes(b::Basis) # funnode method
120120
return x, xcoord
121121
end
122122

123-
@generated function bmat_type{N,TP,TO}(::Type{TO}, bm::Basis{N,TP}, x=1.0)
123+
@generated function bmat_type(::Type{TO}, bm::Basis{N,TP}, x=1.0) where {N,TP,TO}
124124
if N == 1
125125
out = bmat_type(TO, TP.parameters[1], x)
126126
else

src/basis_structure.jl

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,37 @@
22
# BasisMatrix Type #
33
# ------------------- #
44

5-
@compat abstract type AbstractBasisMatrixRep end
5+
abstract type AbstractBasisMatrixRep end
66
const ABSR = AbstractBasisMatrixRep
77

8-
immutable Tensor <: ABSR end
9-
immutable Direct <: ABSR end
10-
immutable Expanded <: ABSR end
8+
struct Tensor <: ABSR end
9+
struct Direct <: ABSR end
10+
struct Expanded <: ABSR end
1111

12-
type BasisMatrix{BST<:ABSR, TM<:AbstractMatrix}
12+
mutable struct BasisMatrix{BST<:ABSR, TM<:AbstractMatrix}
1313
order::Matrix{Int}
1414
vals::Matrix{TM}
1515
end
1616

17-
Base.show{BST}(io::IO, b::BasisMatrix{BST}) =
17+
Base.show(io::IO, b::BasisMatrix{BST}) where {BST} =
1818
print(io, "BasisMatrix{$BST} of order $(b.order)")
1919

2020
Base.ndims(bs::BasisMatrix) = size(bs.order, 2)
2121

2222
# not the same if either type parameter is different
23-
function =={BST1<:ABSR,BST2<:ABSR}(::BasisMatrix{BST1}, ::BasisMatrix{BST2})
23+
function ==(::BasisMatrix{BST1}, ::BasisMatrix{BST2}) where {BST1<:ABSR,BST2<:ABSR}
2424
false
2525
end
2626

27-
function =={BST<:ABSR,TM1<:AbstractMatrix,TM2<:AbstractMatrix}(::BasisMatrix{BST,TM1},
28-
::BasisMatrix{BST,TM2})
27+
function ==(::BasisMatrix{BST,TM1},
28+
::BasisMatrix{BST,TM2}) where {BST<:ABSR,TM1<:AbstractMatrix,TM2<:AbstractMatrix}
2929
false
3030
end
3131

3232
# if type parameters are the same, then it is the same if all fields are the
3333
# same
34-
function =={BST<:ABSR,TM<:AbstractMatrix}(b1::BasisMatrix{BST,TM},
35-
b2::BasisMatrix{BST,TM})
34+
function ==(b1::BasisMatrix{BST,TM},
35+
b2::BasisMatrix{BST,TM}) where {BST<:ABSR,TM<:AbstractMatrix}
3636
b1.order == b2.order && b1.vals == b2.vals
3737
end
3838

@@ -45,7 +45,7 @@ end
4545
x
4646
end
4747

48-
@inline function _checkx{T}(N, x::AbstractVector{T})
48+
@inline function _checkx(N, x::AbstractVector{T}) where T
4949
# if we have a 1d basis, we can evaluate at each point
5050
if N == 1
5151
return x
@@ -132,11 +132,11 @@ end
132132
# --------------- #
133133

134134
# no-op. Don't worry about the order argument.
135-
Base.convert{T<:ABSR}(::Type{T}, bs::BasisMatrix{T}, order=bs.order) = bs
135+
Base.convert(::Type{T}, bs::BasisMatrix{T}, order=bs.order) where {T<:ABSR} = bs
136136

137137
# funbconv from direct to expanded
138-
function Base.convert{TM}(::Type{Expanded}, bs::BasisMatrix{Direct,TM},
139-
order=fill(0, 1, size(bs.order, 2)))
138+
function Base.convert(::Type{Expanded}, bs::BasisMatrix{Direct,TM},
139+
order=fill(0, 1, size(bs.order, 2))) where TM
140140
d, numbas, d1 = check_convert(bs, order)
141141

142142
vals = Array{TM}(numbas, 1)
@@ -152,8 +152,8 @@ function Base.convert{TM}(::Type{Expanded}, bs::BasisMatrix{Direct,TM},
152152
end
153153

154154
# funbconv from tensor to expanded
155-
function Base.convert{TM}(::Type{Expanded}, bs::BasisMatrix{Tensor,TM},
156-
order=fill(0, 1, size(bs.order, 2)))
155+
function Base.convert(::Type{Expanded}, bs::BasisMatrix{Tensor,TM},
156+
order=fill(0, 1, size(bs.order, 2))) where TM
157157
d, numbas, d1 = check_convert(bs, order)
158158

159159
vals = Array{TM}(numbas, 1)
@@ -174,8 +174,8 @@ end
174174
# plan on doing it much, this will do for now. The basic point is that
175175
# we need to expand the rows of each element of `vals` so that all of
176176
# them have prod([size(v, 1) for v in bs.vals])) rows.
177-
function Base.convert{TM}(::Type{Direct}, bs::BasisMatrix{Tensor,TM},
178-
order=fill(0, 1, size(bs.order, 2)))
177+
function Base.convert(::Type{Direct}, bs::BasisMatrix{Tensor,TM},
178+
order=fill(0, 1, size(bs.order, 2))) where TM
179179
d, numbas, d1 = check_convert(bs, order)
180180
vals = Array{TM}(numbas, d)
181181
raw_ind = Array{Vector{Int}}(d)
@@ -206,8 +206,8 @@ end
206206

207207
# method to construct BasisMatrix in direct or expanded form based on
208208
# a matrix of `x` values -- funbasex
209-
function BasisMatrix{N,BF,T2}(::Type{T2}, basis::Basis{N,BF}, ::Direct,
210-
x::AbstractArray=nodes(basis)[1], order=0)
209+
function BasisMatrix(::Type{T2}, basis::Basis{N,BF}, ::Direct,
210+
x::AbstractArray=nodes(basis)[1], order=0) where {N,BF,T2}
211211
m, order, minorder, numbases, x = check_basis_structure(N, x, order)
212212
# 76-77
213213
out_order = minorder
@@ -237,15 +237,15 @@ function BasisMatrix{N,BF,T2}(::Type{T2}, basis::Basis{N,BF}, ::Direct,
237237
BasisMatrix{Direct,val_type}(out_order, vals)
238238
end
239239

240-
function BasisMatrix{T2}(::Type{T2}, basis::Basis, ::Expanded,
241-
x::AbstractArray=nodes(basis)[1], order=0) # funbasex
240+
function BasisMatrix(::Type{T2}, basis::Basis, ::Expanded,
241+
x::AbstractArray=nodes(basis)[1], order=0) where T2 # funbasex
242242
# create direct form, then convert to expanded
243243
bsd = BasisMatrix(T2, basis, Direct(), x, order)
244244
convert(Expanded, bsd, bsd.order)
245245
end
246246

247-
function BasisMatrix{N,BT,T2}(::Type{T2}, basis::Basis{N,BT}, ::Tensor,
248-
x::TensorX=nodes(basis)[2], order=0)
247+
function BasisMatrix(::Type{T2}, basis::Basis{N,BT}, ::Tensor,
248+
x::TensorX=nodes(basis)[2], order=0) where {N,BT,T2}
249249

250250
m, order, minorder, numbases, x = check_basis_structure(N, x, order)
251251
out_order = minorder
@@ -276,29 +276,29 @@ end
276276
# When the user doesn't supply a ABSR, we pick one for them.
277277
# for x::AbstractMatrix we pick direct
278278
# for x::TensorX we pick Tensor
279-
function BasisMatrix{T2}(::Type{T2}, basis::Basis, x::AbstractArray, order=0)
279+
function BasisMatrix(::Type{T2}, basis::Basis, x::AbstractArray, order=0) where T2
280280
BasisMatrix(T2, basis, Direct(), x, order)
281281
end
282282

283-
function BasisMatrix{T2}(::Type{T2}, basis::Basis, x::TensorX, order=0)
283+
function BasisMatrix(::Type{T2}, basis::Basis, x::TensorX, order=0) where T2
284284
BasisMatrix(T2, basis, Tensor(), x, order)
285285
end
286286

287287

288288
# method to allow passing types instead of instances of ABSR
289-
function BasisMatrix{BST<:ABSR,T2}(::Type{T2}, basis, ::Type{BST},
290-
x::Union{AbstractArray,TensorX}, order=0)
289+
function BasisMatrix(::Type{T2}, basis, ::Type{BST},
290+
x::Union{AbstractArray,TensorX}, order=0) where {BST<:ABSR,T2}
291291
BasisMatrix(T2, basis, BST(), x, order)
292292
end
293293

294-
function BasisMatrix{BST<:ABSR}(basis, ::Type{BST},
295-
x::Union{AbstractArray,TensorX}, order=0)
294+
function BasisMatrix(basis, ::Type{BST},
295+
x::Union{AbstractArray,TensorX}, order=0) where BST<:ABSR
296296
BasisMatrix(basis, BST(), x, order)
297297
end
298298

299299
# method without vals eltypes
300-
function BasisMatrix{TBM<:ABSR}(basis::Basis, tbm::TBM,
301-
x::Union{AbstractArray,TensorX}, order=0)
300+
function BasisMatrix(basis::Basis, tbm::TBM,
301+
x::Union{AbstractArray,TensorX}, order=0) where TBM<:ABSR
302302
BasisMatrix(Void, basis, tbm, x, order)
303303
end
304304

@@ -307,6 +307,6 @@ function BasisMatrix(basis::Basis, x::Union{AbstractArray,TensorX}, order=0)
307307
end
308308

309309
# method without x
310-
function BasisMatrix{TBM<:ABSR}(basis::Basis, tbm::Union{Type{TBM},TBM})
310+
function BasisMatrix(basis::Basis, tbm::Union{Type{TBM},TBM}) where TBM<:ABSR
311311
BasisMatrix(Void, basis, tbm)
312312
end

0 commit comments

Comments
 (0)