@@ -35,7 +35,7 @@ julia> indices(A,2)
35
35
Base.OneTo(6)
36
36
```
37
37
"""
38
- function indices {T,N} (A:: AbstractArray{T,N} , d)
38
+ function indices (A:: AbstractArray{T,N} , d) where {T,N}
39
39
@_inline_meta
40
40
d <= N ? indices (A)[d] : OneTo (1 )
41
41
end
@@ -105,9 +105,9 @@ julia> ndims(A)
105
105
3
106
106
```
107
107
"""
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))
111
111
112
112
"""
113
113
length(A::AbstractArray) -> Integer
@@ -509,14 +509,14 @@ julia> similar(falses(10), Float64, 2, 4)
509
509
```
510
510
511
511
"""
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))
518
518
# 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)
520
520
521
521
to_shape (:: Tuple{} ) = ()
522
522
to_shape (dims:: Dims ) = dims
@@ -740,7 +740,7 @@ function copymutable(a::AbstractArray)
740
740
end
741
741
copymutable (itr) = collect (itr)
742
742
743
- zero {T} (x:: AbstractArray{T} ) = fill! (similar (x), zero (T))
743
+ zero (x:: AbstractArray{T} ) where {T} = fill! (similar (x), zero (T))
744
744
745
745
# # iteration support for arrays by iterating over `eachindex` in the array ##
746
746
# Allows fast iteration by default for both IndexLinear and IndexCartesian arrays
@@ -841,10 +841,10 @@ full(x::AbstractArray) = x
841
841
842
842
# # range conversions ##
843
843
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
848
848
LinSpace (T (r. start), T (r. stop), length (r))
849
849
end
850
850
@@ -901,7 +901,7 @@ function _getindex(::IndexLinear, A::AbstractArray, I::Int...)
901
901
end
902
902
_to_linear_index (A:: AbstractArray , i:: Int ) = i
903
903
_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... ))
905
905
_to_linear_index (A:: AbstractArray ) = 1 # TODO : DEPRECATE FOR #14770
906
906
_to_linear_index (A:: AbstractArray , I:: Int... ) = (@_inline_meta ; sub2ind (A, I... )) # TODO : DEPRECATE FOR #14770
907
907
@@ -916,16 +916,16 @@ function _getindex(::IndexCartesian, A::AbstractArray, I::Int...)
916
916
@inbounds r = getindex (A, _to_subscript_indices (A, I... )... )
917
917
r
918
918
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}
920
920
@_propagate_inbounds_meta
921
921
getindex (A, I... )
922
922
end
923
923
_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
929
929
@_inline_meta
930
930
J, Jrem = IteratorsMD. split (I, Val{N})
931
931
_to_subscript_indices (A, J, Jrem)
@@ -946,7 +946,7 @@ function __to_subscript_indices(A::AbstractArray,
946
946
(J... , map (first, tail (_remaining_size (J, indices (A))))... )
947
947
end
948
948
_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
950
950
_remaining_size (:: Tuple{Any} , t:: Tuple ) = t
951
951
_remaining_size (h:: Tuple , t:: Tuple ) = (@_inline_meta ; _remaining_size (tail (h), tail (t)))
952
952
_unsafe_ind2sub (:: Tuple{} , i) = () # ind2sub may throw(BoundsError()) in this case
@@ -979,7 +979,7 @@ function _setindex!(::IndexLinear, A::AbstractArray, v, I::Int...)
979
979
end
980
980
981
981
# 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}
983
983
@_propagate_inbounds_meta
984
984
setindex! (A, v, I... )
985
985
end
@@ -1003,7 +1003,7 @@ get(A::AbstractArray, i::Integer, default) = checkbounds(Bool, A, i) ? A[i] : de
1003
1003
get (A:: AbstractArray , I:: Tuple{} , default) = similar (A, typeof (default), 0 )
1004
1004
get (A:: AbstractArray , I:: Dims , default) = checkbounds (Bool, A, I... ) ? A[I... ] : default
1005
1005
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
1007
1007
# 1d is not linear indexing
1008
1008
ind = findin (I, indices1 (A))
1009
1009
X[ind] = A[I[ind]]
@@ -1012,7 +1012,7 @@ function get!{T}(X::AbstractVector{T}, A::AbstractVector, I::Union{Range, Abstra
1012
1012
X[last (ind)+ 1 : last (Xind)] = default
1013
1013
X
1014
1014
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
1016
1016
# Linear indexing
1017
1017
ind = findin (I, 1 : length (A))
1018
1018
X[ind] = A[I[ind]]
@@ -1024,7 +1024,7 @@ end
1024
1024
get (A:: AbstractArray , I:: Range , default) = get! (similar (A, typeof (default), index_shape (I)), A, I, default)
1025
1025
1026
1026
# 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
1028
1028
fill! (X, default)
1029
1029
dst, src = indcopy (size (A), I)
1030
1030
X[dst... ] = A[src... ]
@@ -1051,24 +1051,24 @@ promote_eltype(v1, vs...) = promote_type(eltype(v1), promote_eltype(vs...))
1051
1051
# TODO : ERROR CHECK
1052
1052
cat (catdim:: Integer ) = Array {Any,1} (0 )
1053
1053
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 )
1056
1056
1057
1057
# # 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) ]
1062
1062
1063
1063
vcat (X:: Number... ) = hvcat_fill (Array {promote_typeof(X...)} (length (X)), X)
1064
1064
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)
1067
1067
1068
1068
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... )
1070
1070
1071
- function typed_vcat {T} (:: Type{T} , V:: AbstractVector... )
1071
+ function typed_vcat (:: Type{T} , V:: AbstractVector... ) where T
1072
1072
n:: Int = 0
1073
1073
for Vk in V
1074
1074
n += length (Vk)
@@ -1085,9 +1085,9 @@ function typed_vcat{T}(::Type{T}, V::AbstractVector...)
1085
1085
end
1086
1086
1087
1087
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... )
1089
1089
1090
- function typed_hcat {T} (:: Type{T} , A:: AbstractVecOrMat... )
1090
+ function typed_hcat (:: Type{T} , A:: AbstractVecOrMat... ) where T
1091
1091
nargs = length (A)
1092
1092
nrows = size (A[1 ], 1 )
1093
1093
ncols = 0
@@ -1122,9 +1122,9 @@ function typed_hcat{T}(::Type{T}, A::AbstractVecOrMat...)
1122
1122
end
1123
1123
1124
1124
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... )
1126
1126
1127
- function typed_vcat {T} (:: Type{T} , A:: AbstractMatrix... )
1127
+ function typed_vcat (:: Type{T} , A:: AbstractMatrix... ) where T
1128
1128
nargs = length (A)
1129
1129
nrows = sum (a-> size (a, 1 ), A):: Int
1130
1130
ncols = size (A[1 ], 2 )
@@ -1200,7 +1200,7 @@ function cat_t(dims, T::Type, X...)
1200
1200
return _cat (A, shape, catdims, X... )
1201
1201
end
1202
1202
1203
- function _cat {N} (A, shape:: NTuple{N} , catdims, X... )
1203
+ function _cat (A, shape:: NTuple{N} , catdims, X... ) where N
1204
1204
offsets = zeros (Int, N)
1205
1205
inds = Vector {UnitRange{Int}} (N)
1206
1206
concat = copy! (zeros (Bool, N), catdims)
@@ -1295,7 +1295,7 @@ hcat(X...) = cat(Val{2}, X...)
1295
1295
typed_vcat (T:: Type , X... ) = cat_t (Val{1 }, T, X... )
1296
1296
typed_hcat (T:: Type , X... ) = cat_t (Val{2 }, T, X... )
1297
1297
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... )
1299
1299
1300
1300
# The specializations for 1 and 2 inputs are important
1301
1301
# 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
1362
1362
block columns.
1363
1363
"""
1364
1364
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... )
1366
1366
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
1368
1368
nbr = length (rows) # number of block rows
1369
1369
1370
1370
nc = 0
@@ -1408,9 +1408,9 @@ function typed_hvcat{T}(::Type{T}, rows::Tuple{Vararg{Int}}, as::AbstractVecOrMa
1408
1408
end
1409
1409
1410
1410
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 )
1412
1412
1413
- function hvcat {T<:Number} (rows:: Tuple{Vararg{Int}} , xs:: T... )
1413
+ function hvcat (rows:: Tuple{Vararg{Int}} , xs:: T... ) where T <: Number
1414
1414
nr = length (rows)
1415
1415
nc = rows[1 ]
1416
1416
@@ -1445,7 +1445,7 @@ end
1445
1445
1446
1446
hvcat (rows:: Tuple{Vararg{Int}} , xs:: Number... ) = typed_hvcat (promote_typeof (xs... ), rows, xs... )
1447
1447
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
1449
1449
nr = length (rows)
1450
1450
nc = rows[1 ]
1451
1451
for i = 2 : nr
@@ -1472,7 +1472,7 @@ function hvcat(rows::Tuple{Vararg{Int}}, as...)
1472
1472
vcat (rs... )
1473
1473
end
1474
1474
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
1476
1476
nbr = length (rows) # number of block rows
1477
1477
rs = Array {Any,1} (nbr)
1478
1478
a = 1
@@ -1847,7 +1847,7 @@ end
1847
1847
1848
1848
# # 1 argument
1849
1849
1850
- function map! {F} (f:: F , dest:: AbstractArray , A:: AbstractArray )
1850
+ function map! (f:: F , dest:: AbstractArray , A:: AbstractArray ) where F
1851
1851
for (i,j) in zip (eachindex (dest),eachindex (A))
1852
1852
dest[i] = f (A[j])
1853
1853
end
@@ -1881,7 +1881,7 @@ julia> map(+, [1, 2, 3], [10, 20, 30])
1881
1881
map (f, A) = collect (Generator (f,A))
1882
1882
1883
1883
# # 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
1885
1885
for (i, j, k) in zip (eachindex (dest), eachindex (A), eachindex (B))
1886
1886
dest[i] = f (A[j], B[k])
1887
1887
end
@@ -1918,7 +1918,7 @@ julia> x
1918
1918
6.0
1919
1919
```
1920
1920
"""
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)
1922
1922
1923
1923
map (f) = f ()
1924
1924
map (f, iters... ) = collect (Generator (f, iters... ))
0 commit comments