Skip to content

Commit 5482f91

Browse files
musmStefanKarpinski
authored andcommitted
Use new where syntax in misc files (#21428)
1 parent a02c731 commit 5482f91

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+900
-903
lines changed

base/abstractarray.jl

Lines changed: 53 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ julia> indices(A,2)
3535
Base.OneTo(6)
3636
```
3737
"""
38-
function indices{T,N}(A::AbstractArray{T,N}, d)
38+
function indices(A::AbstractArray{T,N}, d) where {T,N}
3939
@_inline_meta
4040
d <= N ? indices(A)[d] : OneTo(1)
4141
end
@@ -105,9 +105,9 @@ julia> ndims(A)
105105
3
106106
```
107107
"""
108-
ndims{T,N}(::AbstractArray{T,N}) = N
109-
ndims{T,N}(::Type{AbstractArray{T,N}}) = N
110-
ndims{T<:AbstractArray}(::Type{T}) = ndims(supertype(T))
108+
ndims(::AbstractArray{T,N}) where {T,N} = N
109+
ndims(::Type{AbstractArray{T,N}}) where {T,N} = N
110+
ndims(::Type{T}) where {T<:AbstractArray} = ndims(supertype(T))
111111

112112
"""
113113
length(A::AbstractArray) -> Integer
@@ -509,14 +509,14 @@ julia> similar(falses(10), Float64, 2, 4)
509509
```
510510
511511
"""
512-
similar{T}(a::AbstractArray{T}) = similar(a, T)
513-
similar{T}(a::AbstractArray, ::Type{T}) = similar(a, T, to_shape(indices(a)))
514-
similar{T}(a::AbstractArray{T}, dims::Tuple) = similar(a, T, to_shape(dims))
515-
similar{T}(a::AbstractArray{T}, dims::DimOrInd...) = similar(a, T, to_shape(dims))
516-
similar{T}(a::AbstractArray, ::Type{T}, dims::DimOrInd...) = similar(a, T, to_shape(dims))
517-
similar{T}(a::AbstractArray, ::Type{T}, dims::NeedsShaping) = similar(a, T, to_shape(dims))
512+
similar(a::AbstractArray{T}) where {T} = similar(a, T)
513+
similar(a::AbstractArray, ::Type{T}) where {T} = similar(a, T, to_shape(indices(a)))
514+
similar(a::AbstractArray{T}, dims::Tuple) where {T} = similar(a, T, to_shape(dims))
515+
similar(a::AbstractArray{T}, dims::DimOrInd...) where {T} = similar(a, T, to_shape(dims))
516+
similar(a::AbstractArray, ::Type{T}, dims::DimOrInd...) where {T} = similar(a, T, to_shape(dims))
517+
similar(a::AbstractArray, ::Type{T}, dims::NeedsShaping) where {T} = similar(a, T, to_shape(dims))
518518
# similar creates an Array by default
519-
similar{T,N}(a::AbstractArray, ::Type{T}, dims::Dims{N}) = Array{T,N}(dims)
519+
similar(a::AbstractArray, ::Type{T}, dims::Dims{N}) where {T,N} = Array{T,N}(dims)
520520

521521
to_shape(::Tuple{}) = ()
522522
to_shape(dims::Dims) = dims
@@ -740,7 +740,7 @@ function copymutable(a::AbstractArray)
740740
end
741741
copymutable(itr) = collect(itr)
742742

743-
zero{T}(x::AbstractArray{T}) = fill!(similar(x), zero(T))
743+
zero(x::AbstractArray{T}) where {T} = fill!(similar(x), zero(T))
744744

745745
## iteration support for arrays by iterating over `eachindex` in the array ##
746746
# Allows fast iteration by default for both IndexLinear and IndexCartesian arrays
@@ -841,10 +841,10 @@ full(x::AbstractArray) = x
841841

842842
## range conversions ##
843843

844-
map{T<:Real}(::Type{T}, r::StepRange) = T(r.start):T(r.step):T(last(r))
845-
map{T<:Real}(::Type{T}, r::UnitRange) = T(r.start):T(last(r))
846-
map{T<:AbstractFloat}(::Type{T}, r::StepRangeLen) = convert(StepRangeLen{T}, r)
847-
function map{T<:AbstractFloat}(::Type{T}, r::LinSpace)
844+
map(::Type{T}, r::StepRange) where {T<:Real} = T(r.start):T(r.step):T(last(r))
845+
map(::Type{T}, r::UnitRange) where {T<:Real} = T(r.start):T(last(r))
846+
map(::Type{T}, r::StepRangeLen) where {T<:AbstractFloat} = convert(StepRangeLen{T}, r)
847+
function map(::Type{T}, r::LinSpace) where T<:AbstractFloat
848848
LinSpace(T(r.start), T(r.stop), length(r))
849849
end
850850

@@ -901,7 +901,7 @@ function _getindex(::IndexLinear, A::AbstractArray, I::Int...)
901901
end
902902
_to_linear_index(A::AbstractArray, i::Int) = i
903903
_to_linear_index(A::AbstractVector, i::Int, I::Int...) = i # TODO: DEPRECATE FOR #14770
904-
_to_linear_index{T,N}(A::AbstractArray{T,N}, I::Vararg{Int,N}) = (@_inline_meta; sub2ind(A, I...))
904+
_to_linear_index(A::AbstractArray{T,N}, I::Vararg{Int,N}) where {T,N} = (@_inline_meta; sub2ind(A, I...))
905905
_to_linear_index(A::AbstractArray) = 1 # TODO: DEPRECATE FOR #14770
906906
_to_linear_index(A::AbstractArray, I::Int...) = (@_inline_meta; sub2ind(A, I...)) # TODO: DEPRECATE FOR #14770
907907

@@ -916,16 +916,16 @@ function _getindex(::IndexCartesian, A::AbstractArray, I::Int...)
916916
@inbounds r = getindex(A, _to_subscript_indices(A, I...)...)
917917
r
918918
end
919-
function _getindex{T,N}(::IndexCartesian, A::AbstractArray{T,N}, I::Vararg{Int, N})
919+
function _getindex(::IndexCartesian, A::AbstractArray{T,N}, I::Vararg{Int, N}) where {T,N}
920920
@_propagate_inbounds_meta
921921
getindex(A, I...)
922922
end
923923
_to_subscript_indices(A::AbstractArray, i::Int) = (@_inline_meta; _unsafe_ind2sub(A, i))
924-
_to_subscript_indices{T,N}(A::AbstractArray{T,N}) = (@_inline_meta; fill_to_length((), 1, Val{N})) # TODO: DEPRECATE FOR #14770
925-
_to_subscript_indices{T}(A::AbstractArray{T,0}) = () # TODO: REMOVE FOR #14770
926-
_to_subscript_indices{T}(A::AbstractArray{T,0}, i::Int) = () # TODO: REMOVE FOR #14770
927-
_to_subscript_indices{T}(A::AbstractArray{T,0}, I::Int...) = () # TODO: DEPRECATE FOR #14770
928-
function _to_subscript_indices{T,N}(A::AbstractArray{T,N}, I::Int...) # TODO: DEPRECATE FOR #14770
924+
_to_subscript_indices(A::AbstractArray{T,N}) where {T,N} = (@_inline_meta; fill_to_length((), 1, Val{N})) # TODO: DEPRECATE FOR #14770
925+
_to_subscript_indices(A::AbstractArray{T,0}) where {T} = () # TODO: REMOVE FOR #14770
926+
_to_subscript_indices(A::AbstractArray{T,0}, i::Int) where {T} = () # TODO: REMOVE FOR #14770
927+
_to_subscript_indices(A::AbstractArray{T,0}, I::Int...) where {T} = () # TODO: DEPRECATE FOR #14770
928+
function _to_subscript_indices(A::AbstractArray{T,N}, I::Int...) where {T,N} # TODO: DEPRECATE FOR #14770
929929
@_inline_meta
930930
J, Jrem = IteratorsMD.split(I, Val{N})
931931
_to_subscript_indices(A, J, Jrem)
@@ -946,7 +946,7 @@ function __to_subscript_indices(A::AbstractArray,
946946
(J..., map(first, tail(_remaining_size(J, indices(A))))...)
947947
end
948948
_to_subscript_indices(A, J::Tuple, Jrem::Tuple) = J # already bounds-checked, safe to drop
949-
_to_subscript_indices{T,N}(A::AbstractArray{T,N}, I::Vararg{Int,N}) = I
949+
_to_subscript_indices(A::AbstractArray{T,N}, I::Vararg{Int,N}) where {T,N} = I
950950
_remaining_size(::Tuple{Any}, t::Tuple) = t
951951
_remaining_size(h::Tuple, t::Tuple) = (@_inline_meta; _remaining_size(tail(h), tail(t)))
952952
_unsafe_ind2sub(::Tuple{}, i) = () # ind2sub may throw(BoundsError()) in this case
@@ -979,7 +979,7 @@ function _setindex!(::IndexLinear, A::AbstractArray, v, I::Int...)
979979
end
980980

981981
# IndexCartesian Scalar indexing
982-
function _setindex!{T,N}(::IndexCartesian, A::AbstractArray{T,N}, v, I::Vararg{Int, N})
982+
function _setindex!(::IndexCartesian, A::AbstractArray{T,N}, v, I::Vararg{Int, N}) where {T,N}
983983
@_propagate_inbounds_meta
984984
setindex!(A, v, I...)
985985
end
@@ -1003,7 +1003,7 @@ get(A::AbstractArray, i::Integer, default) = checkbounds(Bool, A, i) ? A[i] : de
10031003
get(A::AbstractArray, I::Tuple{}, default) = similar(A, typeof(default), 0)
10041004
get(A::AbstractArray, I::Dims, default) = checkbounds(Bool, A, I...) ? A[I...] : default
10051005

1006-
function get!{T}(X::AbstractVector{T}, A::AbstractVector, I::Union{Range, AbstractVector{Int}}, default::T)
1006+
function get!(X::AbstractVector{T}, A::AbstractVector, I::Union{Range, AbstractVector{Int}}, default::T) where T
10071007
# 1d is not linear indexing
10081008
ind = findin(I, indices1(A))
10091009
X[ind] = A[I[ind]]
@@ -1012,7 +1012,7 @@ function get!{T}(X::AbstractVector{T}, A::AbstractVector, I::Union{Range, Abstra
10121012
X[last(ind)+1:last(Xind)] = default
10131013
X
10141014
end
1015-
function get!{T}(X::AbstractArray{T}, A::AbstractArray, I::Union{Range, AbstractVector{Int}}, default::T)
1015+
function get!(X::AbstractArray{T}, A::AbstractArray, I::Union{Range, AbstractVector{Int}}, default::T) where T
10161016
# Linear indexing
10171017
ind = findin(I, 1:length(A))
10181018
X[ind] = A[I[ind]]
@@ -1024,7 +1024,7 @@ end
10241024
get(A::AbstractArray, I::Range, default) = get!(similar(A, typeof(default), index_shape(I)), A, I, default)
10251025

10261026
# TODO: DEPRECATE FOR #14770 (just the partial linear indexing part)
1027-
function get!{T}(X::AbstractArray{T}, A::AbstractArray, I::RangeVecIntList, default::T)
1027+
function get!(X::AbstractArray{T}, A::AbstractArray, I::RangeVecIntList, default::T) where T
10281028
fill!(X, default)
10291029
dst, src = indcopy(size(A), I)
10301030
X[dst...] = A[src...]
@@ -1051,24 +1051,24 @@ promote_eltype(v1, vs...) = promote_type(eltype(v1), promote_eltype(vs...))
10511051
#TODO: ERROR CHECK
10521052
cat(catdim::Integer) = Array{Any,1}(0)
10531053

1054-
typed_vcat{T}(::Type{T}) = Array{T,1}(0)
1055-
typed_hcat{T}(::Type{T}) = Array{T,1}(0)
1054+
typed_vcat(::Type{T}) where {T} = Array{T,1}(0)
1055+
typed_hcat(::Type{T}) where {T} = Array{T,1}(0)
10561056

10571057
## cat: special cases
1058-
vcat{T}(X::T...) = T[ X[i] for i=1:length(X) ]
1059-
vcat{T<:Number}(X::T...) = T[ X[i] for i=1:length(X) ]
1060-
hcat{T}(X::T...) = T[ X[j] for i=1:1, j=1:length(X) ]
1061-
hcat{T<:Number}(X::T...) = T[ X[j] for i=1:1, j=1:length(X) ]
1058+
vcat(X::T...) where {T} = T[ X[i] for i=1:length(X) ]
1059+
vcat(X::T...) where {T<:Number} = T[ X[i] for i=1:length(X) ]
1060+
hcat(X::T...) where {T} = T[ X[j] for i=1:1, j=1:length(X) ]
1061+
hcat(X::T...) where {T<:Number} = T[ X[j] for i=1:1, j=1:length(X) ]
10621062

10631063
vcat(X::Number...) = hvcat_fill(Array{promote_typeof(X...)}(length(X)), X)
10641064
hcat(X::Number...) = hvcat_fill(Array{promote_typeof(X...)}(1,length(X)), X)
1065-
typed_vcat{T}(::Type{T}, X::Number...) = hvcat_fill(Array{T,1}(length(X)), X)
1066-
typed_hcat{T}(::Type{T}, X::Number...) = hvcat_fill(Array{T,2}(1,length(X)), X)
1065+
typed_vcat(::Type{T}, X::Number...) where {T} = hvcat_fill(Array{T,1}(length(X)), X)
1066+
typed_hcat(::Type{T}, X::Number...) where {T} = hvcat_fill(Array{T,2}(1,length(X)), X)
10671067

10681068
vcat(V::AbstractVector...) = typed_vcat(promote_eltype(V...), V...)
1069-
vcat{T}(V::AbstractVector{T}...) = typed_vcat(T, V...)
1069+
vcat(V::AbstractVector{T}...) where {T} = typed_vcat(T, V...)
10701070

1071-
function typed_vcat{T}(::Type{T}, V::AbstractVector...)
1071+
function typed_vcat(::Type{T}, V::AbstractVector...) where T
10721072
n::Int = 0
10731073
for Vk in V
10741074
n += length(Vk)
@@ -1085,9 +1085,9 @@ function typed_vcat{T}(::Type{T}, V::AbstractVector...)
10851085
end
10861086

10871087
hcat(A::AbstractVecOrMat...) = typed_hcat(promote_eltype(A...), A...)
1088-
hcat{T}(A::AbstractVecOrMat{T}...) = typed_hcat(T, A...)
1088+
hcat(A::AbstractVecOrMat{T}...) where {T} = typed_hcat(T, A...)
10891089

1090-
function typed_hcat{T}(::Type{T}, A::AbstractVecOrMat...)
1090+
function typed_hcat(::Type{T}, A::AbstractVecOrMat...) where T
10911091
nargs = length(A)
10921092
nrows = size(A[1], 1)
10931093
ncols = 0
@@ -1122,9 +1122,9 @@ function typed_hcat{T}(::Type{T}, A::AbstractVecOrMat...)
11221122
end
11231123

11241124
vcat(A::AbstractMatrix...) = typed_vcat(promote_eltype(A...), A...)
1125-
vcat{T}(A::AbstractMatrix{T}...) = typed_vcat(T, A...)
1125+
vcat(A::AbstractMatrix{T}...) where {T} = typed_vcat(T, A...)
11261126

1127-
function typed_vcat{T}(::Type{T}, A::AbstractMatrix...)
1127+
function typed_vcat(::Type{T}, A::AbstractMatrix...) where T
11281128
nargs = length(A)
11291129
nrows = sum(a->size(a, 1), A)::Int
11301130
ncols = size(A[1], 2)
@@ -1200,7 +1200,7 @@ function cat_t(dims, T::Type, X...)
12001200
return _cat(A, shape, catdims, X...)
12011201
end
12021202

1203-
function _cat{N}(A, shape::NTuple{N}, catdims, X...)
1203+
function _cat(A, shape::NTuple{N}, catdims, X...) where N
12041204
offsets = zeros(Int, N)
12051205
inds = Vector{UnitRange{Int}}(N)
12061206
concat = copy!(zeros(Bool, N), catdims)
@@ -1295,7 +1295,7 @@ hcat(X...) = cat(Val{2}, X...)
12951295
typed_vcat(T::Type, X...) = cat_t(Val{1}, T, X...)
12961296
typed_hcat(T::Type, X...) = cat_t(Val{2}, T, X...)
12971297

1298-
cat{T}(catdims, A::AbstractArray{T}...) = cat_t(catdims, T, A...)
1298+
cat(catdims, A::AbstractArray{T}...) where {T} = cat_t(catdims, T, A...)
12991299

13001300
# The specializations for 1 and 2 inputs are important
13011301
# especially when running with --inline=no, see #11158
@@ -1362,9 +1362,9 @@ If the first argument is a single integer `n`, then all block rows are assumed t
13621362
block columns.
13631363
"""
13641364
hvcat(rows::Tuple{Vararg{Int}}, xs::AbstractVecOrMat...) = typed_hvcat(promote_eltype(xs...), rows, xs...)
1365-
hvcat{T}(rows::Tuple{Vararg{Int}}, xs::AbstractVecOrMat{T}...) = typed_hvcat(T, rows, xs...)
1365+
hvcat(rows::Tuple{Vararg{Int}}, xs::AbstractVecOrMat{T}...) where {T} = typed_hvcat(T, rows, xs...)
13661366

1367-
function typed_hvcat{T}(::Type{T}, rows::Tuple{Vararg{Int}}, as::AbstractVecOrMat...)
1367+
function typed_hvcat(::Type{T}, rows::Tuple{Vararg{Int}}, as::AbstractVecOrMat...) where T
13681368
nbr = length(rows) # number of block rows
13691369

13701370
nc = 0
@@ -1408,9 +1408,9 @@ function typed_hvcat{T}(::Type{T}, rows::Tuple{Vararg{Int}}, as::AbstractVecOrMa
14081408
end
14091409

14101410
hvcat(rows::Tuple{Vararg{Int}}) = []
1411-
typed_hvcat{T}(::Type{T}, rows::Tuple{Vararg{Int}}) = Array{T,1}(0)
1411+
typed_hvcat(::Type{T}, rows::Tuple{Vararg{Int}}) where {T} = Array{T,1}(0)
14121412

1413-
function hvcat{T<:Number}(rows::Tuple{Vararg{Int}}, xs::T...)
1413+
function hvcat(rows::Tuple{Vararg{Int}}, xs::T...) where T<:Number
14141414
nr = length(rows)
14151415
nc = rows[1]
14161416

@@ -1445,7 +1445,7 @@ end
14451445

14461446
hvcat(rows::Tuple{Vararg{Int}}, xs::Number...) = typed_hvcat(promote_typeof(xs...), rows, xs...)
14471447

1448-
function typed_hvcat{T}(::Type{T}, rows::Tuple{Vararg{Int}}, xs::Number...)
1448+
function typed_hvcat(::Type{T}, rows::Tuple{Vararg{Int}}, xs::Number...) where T
14491449
nr = length(rows)
14501450
nc = rows[1]
14511451
for i = 2:nr
@@ -1472,7 +1472,7 @@ function hvcat(rows::Tuple{Vararg{Int}}, as...)
14721472
vcat(rs...)
14731473
end
14741474

1475-
function typed_hvcat{T}(::Type{T}, rows::Tuple{Vararg{Int}}, as...)
1475+
function typed_hvcat(::Type{T}, rows::Tuple{Vararg{Int}}, as...) where T
14761476
nbr = length(rows) # number of block rows
14771477
rs = Array{Any,1}(nbr)
14781478
a = 1
@@ -1847,7 +1847,7 @@ end
18471847

18481848
## 1 argument
18491849

1850-
function map!{F}(f::F, dest::AbstractArray, A::AbstractArray)
1850+
function map!(f::F, dest::AbstractArray, A::AbstractArray) where F
18511851
for (i,j) in zip(eachindex(dest),eachindex(A))
18521852
dest[i] = f(A[j])
18531853
end
@@ -1881,7 +1881,7 @@ julia> map(+, [1, 2, 3], [10, 20, 30])
18811881
map(f, A) = collect(Generator(f,A))
18821882

18831883
## 2 argument
1884-
function map!{F}(f::F, dest::AbstractArray, A::AbstractArray, B::AbstractArray)
1884+
function map!(f::F, dest::AbstractArray, A::AbstractArray, B::AbstractArray) where F
18851885
for (i, j, k) in zip(eachindex(dest), eachindex(A), eachindex(B))
18861886
dest[i] = f(A[j], B[k])
18871887
end
@@ -1918,7 +1918,7 @@ julia> x
19181918
6.0
19191919
```
19201920
"""
1921-
map!{F}(f::F, dest::AbstractArray, As::AbstractArray...) = map_n!(f, dest, As)
1921+
map!(f::F, dest::AbstractArray, As::AbstractArray...) where {F} = map_n!(f, dest, As)
19221922

19231923
map(f) = f()
19241924
map(f, iters...) = collect(Generator(f, iters...))

base/abstractarraymath.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ function circshift(a::AbstractArray, shiftamt)
210210
end
211211

212212
# Uses K-B-N summation
213-
function cumsum_kbn{T<:AbstractFloat}(v::AbstractVector{T})
213+
function cumsum_kbn(v::AbstractVector{T}) where T<:AbstractFloat
214214
r = similar(v)
215215
if isempty(v); return r; end
216216

@@ -241,7 +241,7 @@ end
241241
Cumulative sum along a dimension, using the Kahan-Babuska-Neumaier compensated summation
242242
algorithm for additional accuracy. The dimension defaults to 1.
243243
"""
244-
function cumsum_kbn{T<:AbstractFloat}(A::AbstractArray{T}, axis::Integer=1)
244+
function cumsum_kbn(A::AbstractArray{T}, axis::Integer=1) where T<:AbstractFloat
245245
dimsA = size(A)
246246
ndimsA = ndims(A)
247247
axis_size = dimsA[axis]

0 commit comments

Comments
 (0)