Skip to content

Commit c63e29a

Browse files
committed
More misc functions to where syntax
1 parent 1b97396 commit c63e29a

File tree

5 files changed

+58
-58
lines changed

5 files changed

+58
-58
lines changed

base/broadcast.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const ScalarType = Union{Type{Any}, Type{Nullable}}
1414
## Broadcasting utilities ##
1515
# fallbacks for some special cases
1616
@inline broadcast(f, x::Number...) = f(x...)
17-
@inline broadcast{N}(f, t::NTuple{N,Any}, ts::Vararg{NTuple{N,Any}}) = map(f, t, ts...)
17+
@inline broadcast(f, t::NTuple{N,Any}, ts::Vararg{NTuple{N,Any}}) where {N} = map(f, t, ts...)
1818
broadcast!{T,S,N}(::typeof(identity), x::Array{T,N}, y::Array{S,N}) =
1919
size(x) == size(y) ? copy!(x, y) : broadcast_c!(identity, Array, Array, x, y)
2020

@@ -201,9 +201,9 @@ Note that `dest` is only used to store the result, and does not supply
201201
arguments to `f` unless it is also listed in the `As`,
202202
as in `broadcast!(f, A, A, B)` to perform `A[:] = broadcast(f, A, B)`.
203203
"""
204-
@inline broadcast!{N}(f, C::AbstractArray, A, Bs::Vararg{Any,N}) =
204+
@inline broadcast!(f, C::AbstractArray, A, Bs::Vararg{Any,N}) where {N} =
205205
broadcast_c!(f, containertype(C), containertype(A, Bs...), C, A, Bs...)
206-
@inline function broadcast_c!{N}(f, ::Type, ::Type, C, A, Bs::Vararg{Any,N})
206+
@inline function broadcast_c!(f, ::Type, ::Type, C, A, Bs::Vararg{Any,N}) where N
207207
shape = indices(C)
208208
@boundscheck check_broadcast_indices(shape, A, Bs...)
209209
keeps, Idefaults = map_newindexer(shape, A, Bs)
@@ -335,9 +335,9 @@ end
335335
@inline broadcast_c(f, ::Type{Any}, a...) = f(a...)
336336
@inline broadcast_c(f, ::Type{Tuple}, A, Bs...) =
337337
tuplebroadcast(f, first_tuple(A, Bs...), A, Bs...)
338-
@inline tuplebroadcast{N}(f, ::NTuple{N,Any}, As...) =
338+
@inline tuplebroadcast(f, ::NTuple{N,Any}, As...) where {N} =
339339
ntuple(k -> f(tuplebroadcast_getargs(As, k)...), Val{N})
340-
@inline tuplebroadcast{N,T}(f, ::NTuple{N,Any}, ::Type{T}, As...) =
340+
@inline tuplebroadcast(f, ::NTuple{N,Any}, ::Type{T}, As...) where {N,T} =
341341
ntuple(k -> f(T, tuplebroadcast_getargs(As, k)...), Val{N})
342342
first_tuple(A::Tuple, Bs...) = A
343343
@inline first_tuple(A, Bs...) = first_tuple(Bs...)

base/multidimensional.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -528,13 +528,13 @@ end
528528

529529
# see discussion in #18364 ... we try not to widen type of the resulting array
530530
# from cumsum or cumprod, but in some cases (+, Bool) we may not have a choice.
531-
rcum_promote_type{T,S<:Number}(op, ::Type{T}, ::Type{S}) = promote_op(op, T, S)
532-
rcum_promote_type{T<:Number}(op, ::Type{T}) = rcum_promote_type(op, T,T)
533-
rcum_promote_type{T}(op, ::Type{T}) = T
531+
rcum_promote_type(op, ::Type{T}, ::Type{S}) where {T,S<:Number} = promote_op(op, T, S)
532+
rcum_promote_type(op, ::Type{T}) where {T<:Number} = rcum_promote_type(op, T,T)
533+
rcum_promote_type(op, ::Type{T}) where {T} = T
534534

535535
# handle sums of Vector{Bool} and similar. it would be nice to handle
536536
# any AbstractArray here, but it's not clear how that would be possible
537-
rcum_promote_type{T,N}(op, ::Type{Array{T,N}}) = Array{rcum_promote_type(op,T), N}
537+
rcum_promote_type(op, ::Type{Array{T,N}}) where {T,N} = Array{rcum_promote_type(op,T), N}
538538

539539
# accumulate_pairwise slightly slower then accumulate, but more numerically
540540
# stable in certain situations (e.g. sums).

base/promotion.jl

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,9 @@ promote_type(T) = (@_pure_meta; T)
127127
promote_type(T, S, U, V...) = (@_pure_meta; promote_type(T, promote_type(S, U, V...)))
128128

129129
promote_type(::Type{Bottom}, ::Type{Bottom}) = (@_pure_meta; Bottom)
130-
promote_type{T}(::Type{T}, ::Type{T}) = (@_pure_meta; T)
131-
promote_type{T}(::Type{T}, ::Type{Bottom}) = (@_pure_meta; T)
132-
promote_type{T}(::Type{Bottom}, ::Type{T}) = (@_pure_meta; T)
130+
promote_type(::Type{T}, ::Type{T}) where {T} = (@_pure_meta; T)
131+
promote_type(::Type{T}, ::Type{Bottom}) where {T} = (@_pure_meta; T)
132+
promote_type(::Type{Bottom}, ::Type{T}) where {T} = (@_pure_meta; T)
133133

134134
"""
135135
promote_type(type1, type2)
@@ -166,7 +166,7 @@ promote_rule(T, S) = (@_pure_meta; Bottom)
166166
promote_result(t,s,T,S) = (@_pure_meta; promote_type(T,S))
167167
# If no promote_rule is defined, both directions give Bottom. In that
168168
# case use typejoin on the original types instead.
169-
promote_result{T,S}(::Type{T},::Type{S},::Type{Bottom},::Type{Bottom}) = (@_pure_meta; typejoin(T, S))
169+
promote_result(::Type{T},::Type{S},::Type{Bottom},::Type{Bottom}) where {T,S} = (@_pure_meta; typejoin(T, S))
170170

171171
promote() = ()
172172
promote(x) = (x,)
@@ -194,18 +194,18 @@ end
194194
# Otherwise, typejoin(T,S) is called (returning Number) so no conversion
195195
# happens, and +(promote(x,y)...) is called again, causing a stack
196196
# overflow.
197-
function promote_result{T<:Number,S<:Number}(::Type{T},::Type{S},::Type{Bottom},::Type{Bottom})
197+
function promote_result(::Type{T},::Type{S},::Type{Bottom},::Type{Bottom}) where {T<:Number,S<:Number}
198198
@_pure_meta
199199
promote_to_supertype(T, S, typejoin(T,S))
200200
end
201201

202202
# promote numeric types T and S to typejoin(T,S) if T<:S or S<:T
203203
# for example this makes promote_type(Integer,Real) == Real without
204204
# promoting arbitrary pairs of numeric types to Number.
205-
promote_to_supertype{T<:Number }(::Type{T}, ::Type{T}, ::Type{T}) = (@_pure_meta; T)
206-
promote_to_supertype{T<:Number,S<:Number}(::Type{T}, ::Type{S}, ::Type{T}) = (@_pure_meta; T)
207-
promote_to_supertype{T<:Number,S<:Number}(::Type{T}, ::Type{S}, ::Type{S}) = (@_pure_meta; S)
208-
promote_to_supertype{T<:Number,S<:Number}(::Type{T}, ::Type{S}, ::Type) =
205+
promote_to_supertype(::Type{T}, ::Type{T}, ::Type{T}) where {T<:Number } = (@_pure_meta; T)
206+
promote_to_supertype(::Type{T}, ::Type{S}, ::Type{T}) where {T<:Number,S<:Number} = (@_pure_meta; T)
207+
promote_to_supertype(::Type{T}, ::Type{S}, ::Type{S}) where {T<:Number,S<:Number} = (@_pure_meta; S)
208+
promote_to_supertype(::Type{T}, ::Type{S}, ::Type) where {T<:Number,S<:Number} =
209209
error("no promotion exists for ", T, " and ", S)
210210

211211
# promotion with a check for circularity. Can be used to catch what
@@ -229,9 +229,9 @@ function promote_noncircular(x, y, z, a...)
229229
end
230230
not_all_sametype(x, y) = nothing
231231
not_all_sametype(x, y, z) = nothing
232-
not_all_sametype{S,T}(x::Tuple{S,S}, y::Tuple{T,T}) = sametype_error(x[1], y[1])
233-
not_all_sametype{R,S,T}(x::Tuple{R,R}, y::Tuple{S,S}, z::Tuple{T,T}) = sametype_error(x[1], y[1], z[1])
234-
function not_all_sametype{R,S,T}(::Tuple{R,R}, y::Tuple{S,S}, z::Tuple{T,T}, args...)
232+
not_all_sametype(x::Tuple{S,S}, y::Tuple{T,T}) where {S,T} = sametype_error(x[1], y[1])
233+
not_all_sametype(x::Tuple{R,R}, y::Tuple{S,S}, z::Tuple{T,T}) where {R,S,T} = sametype_error(x[1], y[1], z[1])
234+
function not_all_sametype(::Tuple{R,R}, y::Tuple{S,S}, z::Tuple{T,T}, args...) where {R,S,T}
235235
@_inline_meta
236236
not_all_sametype(y, z, args...)
237237
end

base/reduce.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ const WidenReduceResult = Union{SmallSigned, SmallUnsigned, Float16}
1717

1818
# r_promote_type: promote T to the type of reduce(op, ::Array{T})
1919
# (some "extra" methods are required here to avoid ambiguity warnings)
20-
r_promote_type{T}(op, ::Type{T}) = T
21-
r_promote_type{T<:WidenReduceResult}(op, ::Type{T}) = widen(T)
20+
r_promote_type(op, ::Type{T}) where {T} = T
21+
r_promote_type(op, ::Type{T}) where {T<:WidenReduceResult} = widen(T)
2222
r_promote_type{T<:WidenReduceResult}(::typeof(+), ::Type{T}) = widen(T)
2323
r_promote_type{T<:WidenReduceResult}(::typeof(*), ::Type{T}) = widen(T)
2424
r_promote_type{T<:Number}(::typeof(+), ::Type{T}) = typeof(zero(T)+zero(T))

0 commit comments

Comments
 (0)