Skip to content

Commit 8f6eca2

Browse files
committed
Where syntax for indices and cat function
1 parent 7fc563b commit 8f6eca2

File tree

7 files changed

+41
-41
lines changed

7 files changed

+41
-41
lines changed

base/abstractarray.jl

Lines changed: 25 additions & 25 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
@@ -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
@@ -1051,8 +1051,8 @@ 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
10581058
vcat(X::T...) where {T} = T[ X[i] for i=1:length(X) ]
@@ -1062,13 +1062,13 @@ 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...)
10691069
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)
@@ -1087,7 +1087,7 @@ end
10871087
hcat(A::AbstractVecOrMat...) = typed_hcat(promote_eltype(A...), A...)
10881088
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
@@ -1124,7 +1124,7 @@ end
11241124
vcat(A::AbstractMatrix...) = typed_vcat(promote_eltype(A...), A...)
11251125
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

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(v::AbstractVector{T}) T<:AbstractFloat
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(A::AbstractArray{T}, axis::Integer=1) T<:AbstractFloat
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]

base/range.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ function getindex(r::Union{StepRangeLen,LinSpace}, i::Integer)
493493
end
494494

495495
# This is separate to make it useful even when running with --check-bounds=yes
496-
function unsafe_getindex{T}(r::StepRangeLen{T}, i::Integer)
496+
function unsafe_getindex(r::StepRangeLen{T}, i::Integer) where T
497497
u = i - r.offset
498498
T(r.ref + u*r.step)
499499
end

base/reducedim.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ reduced_indices(a::AbstractArray, region) = reduced_indices(indices(a), region)
88
# for reductions that keep 0 dims as 0
99
reduced_indices0(a::AbstractArray, region) = reduced_indices0(indices(a), region)
1010

11-
function reduced_indices{N}(inds::Indices{N}, d::Int, rd::AbstractUnitRange)
11+
function reduced_indices(inds::Indices{N}, d::Int, rd::AbstractUnitRange) where N
1212
d < 1 && throw(ArgumentError("dimension must be ≥ 1, got $d"))
1313
if d == 1
1414
return (oftype(inds[1], rd), tail(inds)...)
@@ -29,7 +29,7 @@ function reduced_indices0{N}(inds::Indices{N}, d::Int)
2929
end
3030
end
3131

32-
function reduced_indices{N}(inds::Indices{N}, region)
32+
function reduced_indices(inds::Indices{N}, region) where N
3333
rinds = [inds...]
3434
for i in region
3535
isa(i, Integer) || throw(ArgumentError("reduced dimension(s) must be integers"))

base/sparse/cholmod.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ function norm_sparse{Tv<:VTypes}(A::Sparse{Tv}, norm::Integer)
669669
get(A.p), norm, common())
670670
end
671671

672-
function horzcat{Tv<:VRealTypes}(A::Sparse{Tv}, B::Sparse{Tv}, values::Bool)
672+
function horzcat(A::Sparse{Tv}, B::Sparse{Tv}, values::Bool) where Tv<:VRealTypes
673673
s = Sparse(ccall((@cholmod_name("horzcat", SuiteSparse_long), :libcholmod),
674674
Ptr{C_Sparse{Tv}},
675675
(Ptr{C_Sparse{Tv}}, Ptr{C_Sparse{Tv}}, Cint, Ptr{UInt8}),
@@ -724,7 +724,7 @@ function sdmult!{Tv<:VTypes}(A::Sparse{Tv}, transpose::Bool,
724724
Y
725725
end
726726

727-
function vertcat{Tv<:VRealTypes}(A::Sparse{Tv}, B::Sparse{Tv}, values::Bool)
727+
function vertcat(A::Sparse{Tv}, B::Sparse{Tv}, values::Bool) where Tv<:VRealTypes
728728
s = Sparse(ccall((@cholmod_name("vertcat", SuiteSparse_long), :libcholmod),
729729
Ptr{C_Sparse{Tv}},
730730
(Ptr{C_Sparse{Tv}}, Ptr{C_Sparse{Tv}}, Cint, Ptr{UInt8}),

base/sparse/sparsevector.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ end
506506
# Logical and linear indexing into SparseMatrices
507507
getindex(A::SparseMatrixCSC, I::AbstractVector{Bool}) = _logical_index(A, I) # Ambiguities
508508
getindex(A::SparseMatrixCSC, I::AbstractArray{Bool}) = _logical_index(A, I)
509-
function _logical_index{Tv}(A::SparseMatrixCSC{Tv}, I::AbstractArray{Bool})
509+
function _logical_index(A::SparseMatrixCSC{Tv}, I::AbstractArray{Bool}) where Tv
510510
checkbounds(A, I)
511511
n = sum(I)
512512
nnzB = min(n, nnz(A))
@@ -674,7 +674,7 @@ end
674674

675675
### getindex
676676

677-
function _spgetindex{Tv,Ti}(m::Int, nzind::AbstractVector{Ti}, nzval::AbstractVector{Tv}, i::Integer)
677+
function _spgetindex(m::Int, nzind::AbstractVector{Ti}, nzval::AbstractVector{Tv}, i::Integer) where {Tv,Ti}
678678
ii = searchsortedfirst(nzind, convert(Ti, i))
679679
(ii <= m && nzind[ii] == i) ? nzval[ii] : zero(Tv)
680680
end
@@ -840,7 +840,7 @@ complex(x::AbstractSparseVector) =
840840
# of _absspvec_hcat below. The <:Integer qualifications are necessary for correct dispatch.
841841
hcat(X::SparseVector{Tv,Ti}...) where {Tv,Ti<:Integer} = _absspvec_hcat(X...)
842842
hcat(X::AbstractSparseVector{Tv,Ti}...) where {Tv,Ti<:Integer} = _absspvec_hcat(X...)
843-
function _absspvec_hcat{Tv,Ti}(X::AbstractSparseVector{Tv,Ti}...)
843+
function _absspvec_hcat(X::AbstractSparseVector{Tv,Ti}...) where {Tv,Ti}
844844
# check sizes
845845
n = length(X)
846846
m = length(X[1])
@@ -875,7 +875,7 @@ end
875875
# of _absspvec_vcat below. The <:Integer qualifications are necessary for correct dispatch.
876876
vcat(X::SparseVector{Tv,Ti}...) where {Tv,Ti<:Integer} = _absspvec_vcat(X...)
877877
vcat(X::AbstractSparseVector{Tv,Ti}...) where {Tv,Ti<:Integer} = _absspvec_vcat(X...)
878-
function _absspvec_vcat{Tv,Ti}(X::AbstractSparseVector{Tv,Ti}...)
878+
function _absspvec_vcat(X::AbstractSparseVector{Tv,Ti}...) where {Tv,Ti}
879879
# check sizes
880880
n = length(X)
881881
tnnz = 0
@@ -973,10 +973,10 @@ hcat(A::Vector...) = Base.typed_hcat(promote_eltype(A...), A...)
973973
hcat(A::_DenseConcatGroup...) = Base.typed_hcat(promote_eltype(A...), A...)
974974
hvcat(rows::Tuple{Vararg{Int}}, xs::_DenseConcatGroup...) = Base.typed_hvcat(promote_eltype(xs...), rows, xs...)
975975
# For performance, specially handle the case where the matrices/vectors have homogeneous eltype
976-
cat{T}(catdims, xs::_TypedDenseConcatGroup{T}...) = Base.cat_t(catdims, T, xs...)
976+
cat(catdims, xs::_TypedDenseConcatGroup{T}...) where {T} = Base.cat_t(catdims, T, xs...)
977977
vcat(A::_TypedDenseConcatGroup{T}...) where {T} = Base.typed_vcat(T, A...)
978978
hcat(A::_TypedDenseConcatGroup{T}...) where {T} = Base.typed_hcat(T, A...)
979-
hvcat{T}(rows::Tuple{Vararg{Int}}, xs::_TypedDenseConcatGroup{T}...) = Base.typed_hvcat(T, rows, xs...)
979+
hvcat(rows::Tuple{Vararg{Int}}, xs::_TypedDenseConcatGroup{T}...) where {T} = Base.typed_hvcat(T, rows, xs...)
980980

981981

982982
### math functions
@@ -993,7 +993,7 @@ conj(x::SparseVector) = SparseVector(length(x), copy(nonzeroinds(x)), conj(nonze
993993
#
994994
macro unarymap_nz2z_z2z(op, TF)
995995
esc(quote
996-
function $(op){Tv<:$(TF),Ti<:Integer}(x::AbstractSparseVector{Tv,Ti})
996+
function $(op)(x::AbstractSparseVector{Tv,Ti}) where Tv<:$(TF) where Ti<:Integer
997997
R = typeof($(op)(zero(Tv)))
998998
xnzind = nonzeroinds(x)
999999
xnzval = nonzeros(x)
@@ -1039,7 +1039,7 @@ end
10391039

10401040
macro unarymap_z2nz(op, TF)
10411041
esc(quote
1042-
function $(op){Tv<:$(TF)}(x::AbstractSparseVector{Tv,<:Integer})
1042+
function $(op)(x::AbstractSparseVector{Tv,<:Integer}) where Tv<:$(TF)
10431043
v0 = $(op)(zero(Tv))
10441044
R = typeof(v0)
10451045
xnzind = nonzeroinds(x)

base/subarray.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ compute_offset1(parent, stride1::Integer, dims::Tuple{Int}, inds::Tuple{Slice},
270270
compute_offset1(parent, stride1::Integer, dims, inds, I::Tuple) =
271271
(@_inline_meta; compute_linindex(parent, I) - stride1) # linear indexing starts with 1
272272

273-
function compute_linindex{N}(parent, I::NTuple{N,Any})
273+
function compute_linindex(parent, I::NTuple{N,Any}) where N
274274
@_inline_meta
275275
IP = fill_to_length(indices(parent), OneTo(1), Val{N})
276276
compute_linindex(1, 1, IP, I)

0 commit comments

Comments
 (0)