Skip to content

Commit

Permalink
Merge pull request #20446 from pabloferz/pz/newparamsyntax
Browse files Browse the repository at this point in the history
Use new compact parametric syntax where possible
  • Loading branch information
pabloferz authored Feb 9, 2017
2 parents 03278a6 + 82a63fd commit 79471c1
Show file tree
Hide file tree
Showing 118 changed files with 870 additions and 886 deletions.
4 changes: 2 additions & 2 deletions base/LineEdit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ end

# splice! for IOBuffer: convert from 0-indexed positions, update the size,
# and keep the cursor position stable with the text
function splice_buffer!{T<:Integer}(buf::IOBuffer, r::UnitRange{T}, ins::AbstractString = "")
function splice_buffer!(buf::IOBuffer, r::UnitRange{<:Integer}, ins::AbstractString = "")
pos = position(buf)
if !isempty(r) && pos in r
seek(buf, first(r))
Expand Down Expand Up @@ -911,7 +911,7 @@ function validate_keymap(keymap)
end
end

function keymap{D<:Dict}(keymaps::Array{D})
function keymap(keymaps::Array{<:Dict})
# keymaps is a vector of prioritized keymaps, with highest priority first
ret = keymap_unify(map(normalize_keys, reverse(keymaps)))
validate_keymap(ret)
Expand Down
18 changes: 9 additions & 9 deletions base/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ end
# d)` for d=1. 1d arrays are heavily used, and the first dimension
# comes up in other applications.
indices1{T}(A::AbstractArray{T,0}) = OneTo(1)
indices1{T}(A::AbstractArray{T}) = (@_inline_meta; indices(A)[1])
indices1(A::AbstractArray) = (@_inline_meta; indices(A)[1])
indices1(iter) = OneTo(length(iter))

unsafe_indices(A) = indices(A)
Expand Down Expand Up @@ -89,7 +89,7 @@ julia> extrema(b)
"""
linearindices(A) = (@_inline_meta; OneTo(_length(A)))
linearindices(A::AbstractVector) = (@_inline_meta; indices1(A))
eltype(::Type{A}) where A<:AbstractArray{E} where E = E
eltype(::Type{<:AbstractArray{E}}) where {E} = E
elsize{T}(::AbstractArray{T}) = sizeof(T)

"""
Expand Down Expand Up @@ -189,7 +189,7 @@ function stride(a::AbstractArray, i::Integer)
return s
end

strides{T}(A::AbstractArray{T,0}) = ()
strides(A::AbstractArray{<:Any,0}) = ()
"""
strides(A)
Expand All @@ -204,7 +204,7 @@ julia> strides(A)
"""
strides(A::AbstractArray) = _strides((1,), A)
_strides{T,N}(out::NTuple{N,Any}, A::AbstractArray{T,N}) = out
function _strides{M,T,N}(out::NTuple{M}, A::AbstractArray{T,N})
function _strides{M}(out::NTuple{M}, A::AbstractArray)
@_inline_meta
_strides((out..., out[M]*size(A, M)), A)
end
Expand Down Expand Up @@ -263,13 +263,13 @@ efficient generic code for all array types.
An abstract array subtype `MyArray` that wishes to opt into fast linear indexing behaviors
should define `linearindexing` in the type-domain:
Base.linearindexing{T<:MyArray}(::Type{T}) = Base.LinearFast()
Base.linearindexing(::Type{<:MyArray}) = Base.LinearFast()
"""
linearindexing(A::AbstractArray) = linearindexing(typeof(A))
linearindexing(::Type{Union{}}) = LinearFast()
linearindexing{T<:AbstractArray}(::Type{T}) = LinearSlow()
linearindexing{T<:Array}(::Type{T}) = LinearFast()
linearindexing{T<:Range}(::Type{T}) = LinearFast()
linearindexing(::Type{<:AbstractArray}) = LinearSlow()
linearindexing(::Type{<:Array}) = LinearFast()
linearindexing(::Type{<:Range}) = LinearFast()

linearindexing(A::AbstractArray, B::AbstractArray) = linearindexing(linearindexing(A), linearindexing(B))
linearindexing(A::AbstractArray, B::AbstractArray...) = linearindexing(linearindexing(A), linearindexing(B...))
Expand Down Expand Up @@ -1575,7 +1575,7 @@ sub2ind_vec(inds, i, I) = (@_inline_meta; _sub2ind_vec(inds, (), i, I...))
_sub2ind_vec(inds, out, i, I1, I...) = (@_inline_meta; _sub2ind_vec(inds, (out..., I1[i]), i, I...))
_sub2ind_vec(inds, out, i) = (@_inline_meta; sub2ind(inds, out...))

function ind2sub{N,T<:Integer}(inds::Union{DimsInteger{N},Indices{N}}, ind::AbstractVector{T})
function ind2sub{N}(inds::Union{DimsInteger{N},Indices{N}}, ind::AbstractVector{<:Integer})
M = length(ind)
t = ntuple(n->similar(ind),Val{N})
for (i,idx) in enumerate(ind) # FIXME: change to eachindexvalue
Expand Down
16 changes: 8 additions & 8 deletions base/abstractarraymath.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

isreal(x::AbstractArray) = all(isreal,x)
iszero(x::AbstractArray) = all(iszero,x)
isreal{T<:Real,n}(x::AbstractArray{T,n}) = true
all{T<:Integer}(::typeof(isinteger), ::AbstractArray{T}) = true
isreal(x::AbstractArray{<:Real}) = true
all(::typeof(isinteger), ::AbstractArray{<:Integer}) = true

## Constructors ##

Expand Down Expand Up @@ -80,14 +80,14 @@ squeeze(A::AbstractArray, dim::Integer) = squeeze(A, (Int(dim),))

## Unary operators ##

conj{T<:Real}(x::AbstractArray{T}) = x
conj!{T<:Real}(x::AbstractArray{T}) = x
conj(x::AbstractArray{<:Real}) = x
conj!(x::AbstractArray{<:Real}) = x

real{T<:Real}(x::AbstractArray{T}) = x
imag{T<:Real}(x::AbstractArray{T}) = zero(x)
real(x::AbstractArray{<:Real}) = x
imag(x::AbstractArray{<:Real}) = zero(x)

+{T<:Number}(x::AbstractArray{T}) = x
*{T<:Number}(x::AbstractArray{T,2}) = x
+(x::AbstractArray{<:Number}) = x
*(x::AbstractArray{<:Number,2}) = x

# index A[:,:,...,i,:,:,...] where "i" is in dimension "d"

Expand Down
10 changes: 5 additions & 5 deletions base/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ length(a::Array) = arraylen(a)
elsize{T}(a::Array{T}) = isbits(T) ? sizeof(T) : sizeof(Ptr)
sizeof(a::Array) = elsize(a) * length(a)

function isassigned{T}(a::Array{T}, i::Int...)
function isassigned(a::Array, i::Int...)
ii = sub2ind(size(a), i...)
1 <= ii <= length(a) || return false
ccall(:jl_array_isassigned, Cint, (Any, UInt), a, ii-1) == 1
Expand Down Expand Up @@ -576,7 +576,7 @@ function push!(a::Array{Any,1}, item::ANY)
return a
end

function append!{T}(a::Array{T,1}, items::AbstractVector)
function append!(a::Array{<:Any,1}, items::AbstractVector)
itemindices = eachindex(items)
n = length(itemindices)
ccall(:jl_array_grow_end, Void, (Any, UInt), a, n)
Expand Down Expand Up @@ -618,7 +618,7 @@ julia> prepend!([3],[1,2])
"""
function prepend! end

function prepend!{T}(a::Array{T,1}, items::AbstractVector)
function prepend!(a::Array{<:Any,1}, items::AbstractVector)
itemindices = eachindex(items)
n = length(itemindices)
ccall(:jl_array_grow_beg, Void, (Any, UInt), a, n)
Expand Down Expand Up @@ -784,7 +784,7 @@ julia> deleteat!([6, 5, 4, 3, 2, 1], 2)
"""
deleteat!(a::Vector, i::Integer) = (_deleteat!(a, i, 1); a)

function deleteat!{T<:Integer}(a::Vector, r::UnitRange{T})
function deleteat!(a::Vector, r::UnitRange{<:Integer})
n = length(a)
isempty(r) || _deleteat!(a, first(r), length(r))
return a
Expand Down Expand Up @@ -934,7 +934,7 @@ julia> A
-1
```
"""
function splice!{T<:Integer}(a::Vector, r::UnitRange{T}, ins=_default_splice)
function splice!(a::Vector, r::UnitRange{<:Integer}, ins=_default_splice)
v = a[r]
m = length(ins)
if m == 0
Expand Down
6 changes: 3 additions & 3 deletions base/arraymath.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ julia> A
2-2im 3-1im
```
"""
conj!{T<:Number}(A::AbstractArray{T}) = (@inbounds broadcast!(conj, A, A); A)
conj!(A::AbstractArray{<:Number}) = (@inbounds broadcast!(conj, A, A); A)

for f in (:-, :~, :conj, :real, :imag)
@eval ($f)(A::AbstractArray) = broadcast($f, A)
Expand All @@ -42,10 +42,10 @@ end

for f in (:/, :\, :*, :+, :-)
if f != :/
@eval ($f){T}(A::Number, B::AbstractArray{T}) = broadcast($f, A, B)
@eval ($f)(A::Number, B::AbstractArray) = broadcast($f, A, B)
end
if f != :\
@eval ($f){T}(A::AbstractArray{T}, B::Number) = broadcast($f, A, B)
@eval ($f)(A::AbstractArray, B::Number) = broadcast($f, A, B)
end
end

Expand Down
6 changes: 3 additions & 3 deletions base/bitarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ size(B::BitArray) = B.dims
ifelse(d == 1, B.len, 1)
end

isassigned{N}(B::BitArray{N}, i::Int) = 1 <= i <= length(B)
isassigned(B::BitArray, i::Int) = 1 <= i <= length(B)

linearindexing{A<:BitArray}(::Type{A}) = LinearFast()
linearindexing(::Type{<:BitArray}) = LinearFast()

## aux functions ##

Expand Down Expand Up @@ -335,7 +335,7 @@ end
@inline try_bool_conversion(x::Real) = x == 0 || x == 1 || throw(InexactError())
@inline unchecked_bool_convert(x::Real) = x == 1

function copy_to_bitarray_chunks!{T<:Real}(Bc::Vector{UInt64}, pos_d::Int, C::Array{T}, pos_s::Int, numbits::Int)
function copy_to_bitarray_chunks!(Bc::Vector{UInt64}, pos_d::Int, C::Array{<:Real}, pos_s::Int, numbits::Int)
@inbounds for i = (1:numbits) + pos_s - 1
try_bool_conversion(C[i])
end
Expand Down
12 changes: 6 additions & 6 deletions base/broadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ broadcast!(f, X::AbstractArray, x::Number...) = (@inbounds for I in eachindex(X)

# logic for deciding the resulting container type
_containertype(::Type) = Any
_containertype{T<:Ptr}(::Type{T}) = Any
_containertype{T<:Tuple}(::Type{T}) = Tuple
_containertype{T<:Ref}(::Type{T}) = Array
_containertype{T<:AbstractArray}(::Type{T}) = Array
_containertype{T<:Nullable}(::Type{T}) = Nullable
_containertype(::Type{<:Ptr}) = Any
_containertype(::Type{<:Tuple}) = Tuple
_containertype(::Type{<:Ref}) = Array
_containertype(::Type{<:AbstractArray}) = Array
_containertype(::Type{<:Nullable}) = Nullable
containertype(x) = _containertype(typeof(x))
containertype(ct1, ct2) = promote_containertype(containertype(ct1), containertype(ct2))
@inline containertype(ct1, ct2, cts...) = promote_containertype(containertype(ct1), containertype(ct2, cts...))
Expand Down Expand Up @@ -507,7 +507,7 @@ end

Base.@propagate_inbounds dotview(args...) = getindex(args...)
Base.@propagate_inbounds dotview(A::AbstractArray, args...) = view(A, args...)
Base.@propagate_inbounds dotview{T<:AbstractArray}(A::AbstractArray{T}, args::Integer...) = getindex(A, args...)
Base.@propagate_inbounds dotview(A::AbstractArray{<:AbstractArray}, args::Integer...) = getindex(A, args...)


############################################################
Expand Down
4 changes: 2 additions & 2 deletions base/c.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ if !is_windows()
end

# construction from typed pointers
convert{T<:Union{Int8,UInt8}}(::Type{Cstring}, p::Ptr{T}) = bitcast(Cstring, p)
convert(::Type{Cstring}, p::Ptr{<:Union{Int8,UInt8}}) = bitcast(Cstring, p)
convert(::Type{Cwstring}, p::Ptr{Cwchar_t}) = bitcast(Cwstring, p)
convert{T<:Union{Int8,UInt8}}(::Type{Ptr{T}}, p::Cstring) = bitcast(Ptr{T}, p)
convert(::Type{Ptr{Cwchar_t}}, p::Cwstring) = bitcast(Ptr{Cwchar_t}, p)
Expand Down Expand Up @@ -161,7 +161,7 @@ function transcode end
transcode{T<:Union{UInt8,UInt16,UInt32,Int32}}(::Type{T}, src::Vector{T}) = src
transcode{T<:Union{Int32,UInt32}}(::Type{T}, src::String) = T[T(c) for c in src]
transcode{T<:Union{Int32,UInt32}}(::Type{T}, src::Vector{UInt8}) = transcode(T, String(src))
function transcode{S<:Union{Int32,UInt32}}(::Type{UInt8}, src::Vector{S})
function transcode(::Type{UInt8}, src::Vector{<:Union{Int32,UInt32}})
buf = IOBuffer()
for c in src; print(buf, Char(c)); end
take!(buf)
Expand Down
4 changes: 2 additions & 2 deletions base/channels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,6 @@ function done(c::Channel, state::ChannelIterState)
end
end
end
next{T}(c::Channel{T}, state) = (v=state.val; state.hasval=false; (v, state))
next(c::Channel, state) = (v=state.val; state.hasval=false; (v, state))

iteratorsize{C<:Channel}(::Type{C}) = SizeUnknown()
iteratorsize(::Type{<:Channel}) = SizeUnknown()
2 changes: 1 addition & 1 deletion base/checked.jl
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ function checked_neg{T<:Integer}(x::T)
checked_sub(T(0), x)
end
if BrokenSignedInt != Union{}
function checked_neg{T<:BrokenSignedInt}(x::T)
function checked_neg(x::BrokenSignedInt)
r = -x
(x<0) & (r<0) && throw(OverflowError())
r
Expand Down
4 changes: 2 additions & 2 deletions base/combinatorics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ isperm(p::Tuple{}) = true
isperm(p::Tuple{Int}) = p[1] == 1
isperm(p::Tuple{Int,Int}) = ((p[1] == 1) & (p[2] == 2)) | ((p[1] == 2) & (p[2] == 1))

function permute!!{T<:Integer}(a, p::AbstractVector{T})
function permute!!(a, p::AbstractVector{<:Integer})
count = 0
start = 0
while count < length(a)
Expand Down Expand Up @@ -131,7 +131,7 @@ julia> A
"""
permute!(a, p::AbstractVector) = permute!!(a, copymutable(p))

function ipermute!!{T<:Integer}(a, p::AbstractVector{T})
function ipermute!!(a, p::AbstractVector{<:Integer})
count = 0
start = 0
while count < length(a)
Expand Down
26 changes: 13 additions & 13 deletions base/complex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ conj(z::Complex) = Complex(real(z),-imag(z))
abs(z::Complex) = hypot(real(z), imag(z))
abs2(z::Complex) = real(z)*real(z) + imag(z)*imag(z)
inv(z::Complex) = conj(z)/abs2(z)
inv{T<:Integer}(z::Complex{T}) = inv(float(z))
inv(z::Complex{<:Integer}) = inv(float(z))

-(z::Complex) = Complex(-real(z), -imag(z))
+(z::Complex, w::Complex) = Complex(real(z) + real(w), imag(z) + imag(w))
Expand Down Expand Up @@ -288,7 +288,7 @@ function /{T<:Real}(a::Complex{T}, b::Complex{T})
end
end

inv{T<:Union{Float16,Float32}}(z::Complex{T}) =
inv(z::Complex{<:Union{Float16,Float32}}) =
oftype(z, conj(widen(z))/abs2(widen(z)))

/{T<:Union{Float16,Float32}}(z::Complex{T}, w::Complex{T}) =
Expand Down Expand Up @@ -377,7 +377,7 @@ function ssqs{T<:AbstractFloat}(x::T, y::T)
ρ, k
end

function sqrt{T<:AbstractFloat}(z::Complex{T})
function sqrt(z::Complex{<:AbstractFloat})
x, y = reim(z)
if x==y==0
return Complex(zero(x),y)
Expand Down Expand Up @@ -659,12 +659,12 @@ end
^(z::Complex, n::Bool) = n ? z : one(z)
^(z::Complex, n::Integer) = z^Complex(n)

^{T<:AbstractFloat}(z::Complex{T}, n::Bool) = n ? z : one(z) # to resolve ambiguity
^{T<:Integer}(z::Complex{T}, n::Bool) = n ? z : one(z) # to resolve ambiguity
^(z::Complex{<:AbstractFloat}, n::Bool) = n ? z : one(z) # to resolve ambiguity
^(z::Complex{<:Integer}, n::Bool) = n ? z : one(z) # to resolve ambiguity

^{T<:AbstractFloat}(z::Complex{T}, n::Integer) =
^(z::Complex{<:AbstractFloat}, n::Integer) =
n>=0 ? power_by_squaring(z,n) : power_by_squaring(inv(z),-n)
^{T<:Integer}(z::Complex{T}, n::Integer) = power_by_squaring(z,n) # DomainError for n<0
^(z::Complex{<:Integer}, n::Integer) = power_by_squaring(z,n) # DomainError for n<0

function sin{T}(z::Complex{T})
F = float(T)
Expand Down Expand Up @@ -722,7 +722,7 @@ function asin(z::Complex)
Complex(ξ,η)
end

function acos{T<:AbstractFloat}(z::Complex{T})
function acos(z::Complex{<:AbstractFloat})
zr, zi = reim(z)
if isnan(zr)
if isinf(zi) return Complex(zr, -zi)
Expand Down Expand Up @@ -863,7 +863,7 @@ breaking ties using the specified [`RoundingMode`](@ref)s. The first
[`RoundingMode`](@ref) is used for rounding the real components while the
second is used for rounding the imaginary components.
"""
function round{T<:AbstractFloat, MR, MI}(z::Complex{T}, ::RoundingMode{MR}, ::RoundingMode{MI})
function round{MR, MI}(z::Complex{<:AbstractFloat}, ::RoundingMode{MR}, ::RoundingMode{MI})
Complex(round(real(z), RoundingMode{MR}()),
round(imag(z), RoundingMode{MI}()))
end
Expand All @@ -874,15 +874,15 @@ function round(z::Complex, digits::Integer, base::Integer=10)
round(imag(z), digits, base))
end

float{T<:AbstractFloat}(z::Complex{T}) = z
float(z::Complex{<:AbstractFloat}) = z
float(z::Complex) = Complex(float(real(z)), float(imag(z)))

big{T<:AbstractFloat}(z::Complex{T}) = Complex{BigFloat}(z)
big{T<:Integer}(z::Complex{T}) = Complex{BigInt}(z)
big(z::Complex{<:AbstractFloat}) = Complex{BigFloat}(z)
big(z::Complex{<:Integer}) = Complex{BigInt}(z)

## Array operations on complex numbers ##

complex{T<:Complex}(A::AbstractArray{T}) = A
complex(A::AbstractArray{<:Complex}) = A

function complex{T}(A::AbstractArray{T})
if !isleaftype(T)
Expand Down
2 changes: 1 addition & 1 deletion base/dSFMT.jl
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ end
## Windows entropy

if is_windows()
function win32_SystemFunction036!{T}(a::Array{T})
function win32_SystemFunction036!(a::Array)
ccall((:SystemFunction036, :Advapi32), stdcall, UInt8, (Ptr{Void}, UInt32), a, sizeof(a))
end
end
Expand Down
6 changes: 3 additions & 3 deletions base/datafmt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ function colval(sbuff::String, startpos::Int, endpos::Int, cells::Array{Float32,
isnull(n) || (cells[row, col] = get(n))
isnull(n)
end
function colval{T<:AbstractString}(sbuff::String, startpos::Int, endpos::Int, cells::Array{T,2}, row::Int, col::Int)
function colval(sbuff::String, startpos::Int, endpos::Int, cells::Array{<:AbstractString,2}, row::Int, col::Int)
cells[row, col] = SubString(sbuff, startpos, endpos)
return false
end
Expand All @@ -446,7 +446,7 @@ function colval(sbuff::String, startpos::Int, endpos::Int, cells::Array{Any,2},
cells[row, col] = SubString(sbuff, startpos, endpos)
false
end
function colval{T<:Char}(sbuff::String, startpos::Int, endpos::Int, cells::Array{T,2}, row::Int, col::Int)
function colval(sbuff::String, startpos::Int, endpos::Int, cells::Array{<:Char,2}, row::Int, col::Int)
if startpos == endpos
cells[row, col] = next(sbuff, startpos)[1]
return false
Expand Down Expand Up @@ -644,7 +644,7 @@ function writedlm(io::IO, a::AbstractMatrix, dlm; opts...)
nothing
end

writedlm{T}(io::IO, a::AbstractArray{T,0}, dlm; opts...) = writedlm(io, reshape(a,1), dlm; opts...)
writedlm(io::IO, a::AbstractArray{<:Any,0}, dlm; opts...) = writedlm(io, reshape(a,1), dlm; opts...)

# write an iterable row as dlm-separated items
function writedlm_row(io::IO, row, dlm, quotes)
Expand Down
Loading

0 comments on commit 79471c1

Please sign in to comment.