diff --git a/base/LineEdit.jl b/base/LineEdit.jl index 6a76f05f333ab..50f627da781ea 100644 --- a/base/LineEdit.jl +++ b/base/LineEdit.jl @@ -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)) @@ -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) diff --git a/base/abstractarray.jl b/base/abstractarray.jl index 5ca6ef34820f1..d18266efa329f 100644 --- a/base/abstractarray.jl +++ b/base/abstractarray.jl @@ -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) @@ -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) """ @@ -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) @@ -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 @@ -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...)) @@ -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 diff --git a/base/abstractarraymath.jl b/base/abstractarraymath.jl index 2a657d19d6c9e..d1247feae4f7e 100644 --- a/base/abstractarraymath.jl +++ b/base/abstractarraymath.jl @@ -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 ## @@ -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" diff --git a/base/array.jl b/base/array.jl index 355da7c2c71a7..8275792b8e2b6 100644 --- a/base/array.jl +++ b/base/array.jl @@ -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 @@ -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) @@ -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) @@ -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 @@ -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 diff --git a/base/arraymath.jl b/base/arraymath.jl index b8b78424fdf8c..b9c3e8385aa48 100644 --- a/base/arraymath.jl +++ b/base/arraymath.jl @@ -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) @@ -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 diff --git a/base/bitarray.jl b/base/bitarray.jl index 1356b702fd9af..9b6e354f2eb21 100644 --- a/base/bitarray.jl +++ b/base/bitarray.jl @@ -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 ## @@ -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 diff --git a/base/broadcast.jl b/base/broadcast.jl index bd82f8771ee8f..d7a1ba8ae583b 100644 --- a/base/broadcast.jl +++ b/base/broadcast.jl @@ -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...)) @@ -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...) ############################################################ diff --git a/base/c.jl b/base/c.jl index 6d5be6e2e6d36..d3a1b075a28e6 100644 --- a/base/c.jl +++ b/base/c.jl @@ -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) @@ -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) diff --git a/base/channels.jl b/base/channels.jl index 05bd379e60faf..038c1c01bdbb6 100644 --- a/base/channels.jl +++ b/base/channels.jl @@ -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() diff --git a/base/checked.jl b/base/checked.jl index 48f065878e3d1..1500723947d10 100644 --- a/base/checked.jl +++ b/base/checked.jl @@ -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 diff --git a/base/combinatorics.jl b/base/combinatorics.jl index b25505720b7f7..7388e7ecd1b56 100644 --- a/base/combinatorics.jl +++ b/base/combinatorics.jl @@ -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) @@ -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) diff --git a/base/complex.jl b/base/complex.jl index 038d610d20cdd..f351e0846da3e 100644 --- a/base/complex.jl +++ b/base/complex.jl @@ -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)) @@ -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}) = @@ -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) @@ -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) @@ -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) @@ -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 @@ -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) diff --git a/base/dSFMT.jl b/base/dSFMT.jl index 5236c8def9cf3..cc3ed3a35460a 100644 --- a/base/dSFMT.jl +++ b/base/dSFMT.jl @@ -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 diff --git a/base/datafmt.jl b/base/datafmt.jl index 55ec222e6f8b3..b7b833cca02a2 100644 --- a/base/datafmt.jl +++ b/base/datafmt.jl @@ -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 @@ -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 @@ -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) diff --git a/base/dates/arithmetic.jl b/base/dates/arithmetic.jl index 4389bf59326db..ac59b4971e3ab 100644 --- a/base/dates/arithmetic.jl +++ b/base/dates/arithmetic.jl @@ -82,12 +82,12 @@ end (-)(x::Time, y::TimePeriod) = return Time(Nanosecond(value(x) - tons(y))) (+)(y::Period, x::TimeType) = x + y -(+){T<:TimeType}(x::AbstractArray{T}, y::GeneralPeriod) = x .+ y -(+){T<:TimeType,P<:GeneralPeriod}(x::StridedArray{P}, y::T) = x .+ y -(+){T<:TimeType}(y::GeneralPeriod, x::AbstractArray{T}) = x .+ y -(+){P<:GeneralPeriod}(y::TimeType, x::StridedArray{P}) = x .+ y -(-){T<:TimeType}(x::AbstractArray{T}, y::GeneralPeriod) = x .- y -(-){T<:TimeType,P<:GeneralPeriod}(x::StridedArray{P}, y::T) = x .- y +(+)(x::AbstractArray{<:TimeType}, y::GeneralPeriod) = x .+ y +(+)(x::StridedArray{<:GeneralPeriod}, y::TimeType) = x .+ y +(+)(y::GeneralPeriod, x::AbstractArray{<:TimeType}) = x .+ y +(+)(y::TimeType, x::StridedArray{<:GeneralPeriod}) = x .+ y +(-)(x::AbstractArray{<:TimeType}, y::GeneralPeriod) = x .- y +(-)(x::StridedArray{<:GeneralPeriod}, y::TimeType) = x .- y # TimeType, AbstractArray{TimeType} (-){T<:TimeType}(x::AbstractArray{T}, y::T) = x .- y diff --git a/base/dates/io.jl b/base/dates/io.jl index 5dcdafa8de3ca..b13e10c26ee27 100644 --- a/base/dates/io.jl +++ b/base/dates/io.jl @@ -495,18 +495,18 @@ function Base.string(dt::Date) end # vectorized -DateTime{T<:AbstractString}(Y::AbstractArray{T}, format::AbstractString; +DateTime(Y::AbstractArray{<:AbstractString}, format::AbstractString; locale::Union{DateLocale, String}=ENGLISH) = DateTime(Y, DateFormat(format, locale)) -function DateTime{T<:AbstractString}(Y::AbstractArray{T}, df::DateFormat=ISODateTimeFormat) +function DateTime(Y::AbstractArray{<:AbstractString}, df::DateFormat=ISODateTimeFormat) return reshape(DateTime[parse(DateTime, y, df) for y in Y], size(Y)) end -Date{T<:AbstractString}(Y::AbstractArray{T}, format::AbstractString; +Date(Y::AbstractArray{<:AbstractString}, format::AbstractString; locale::Union{DateLocale, String}=ENGLISH) = Date(Y, DateFormat(format, locale)) -function Date{T<:AbstractString}(Y::AbstractArray{T}, df::DateFormat=ISODateFormat) +function Date(Y::AbstractArray{<:AbstractString}, df::DateFormat=ISODateFormat) return reshape(Date[Date(parse(Date, y, df)) for y in Y], size(Y)) end -format{T<:TimeType}(Y::AbstractArray{T}, fmt::AbstractString; +format(Y::AbstractArray{<:TimeType}, fmt::AbstractString; locale::Union{DateLocale, String}=ENGLISH) = format(Y, DateFormat(fmt, locale)) function format(Y::AbstractArray{Date}, df::DateFormat=ISODateFormat) return reshape([format(y, df) for y in Y], size(Y)) diff --git a/base/dates/periods.jl b/base/dates/periods.jl index b1074e67e80b0..ddb51e8120839 100644 --- a/base/dates/periods.jl +++ b/base/dates/periods.jl @@ -39,7 +39,7 @@ for period in (:Year, :Month, :Week, :Day, :Hour, :Minute, :Second, :Millisecond end #Print/show/traits -Base.string{P<:Period}(x::P) = string(value(x), _units(x)) +Base.string(x::Period) = string(value(x), _units(x)) Base.show(io::IO,x::Period) = print(io, string(x)) Base.zero{P<:Period}(::Union{Type{P},P}) = P(0) Base.one{P<:Period}(::Union{Type{P},P}) = 1 # see #16116 @@ -211,7 +211,7 @@ julia> Dates.CompoundPeriod(Dates.Minute(50000)) 50000 minutes ``` """ -CompoundPeriod{P<:Period}(p::Vector{P}) = CompoundPeriod(Array{Period}(p)) +CompoundPeriod(p::Vector{<:Period}) = CompoundPeriod(Array{Period}(p)) CompoundPeriod(t::Time) = CompoundPeriod(Period[Hour(t), Minute(t), Second(t), Millisecond(t), Microsecond(t), Nanosecond(t)]) @@ -353,13 +353,13 @@ Base.show(io::IO,x::CompoundPeriod) = print(io, string(x)) GeneralPeriod = Union{Period, CompoundPeriod} (+)(x::GeneralPeriod) = x -(+){P<:GeneralPeriod}(x::StridedArray{P}) = x +(+)(x::StridedArray{<:GeneralPeriod}) = x for op in (:+, :-) @eval begin - ($op){P<:GeneralPeriod}(x::GeneralPeriod, Y::StridedArray{P}) = broadcast($op, x, Y) - ($op){P<:GeneralPeriod}(Y::StridedArray{P}, x::GeneralPeriod) = broadcast($op, Y, x) - ($op){P<:GeneralPeriod, Q<:GeneralPeriod}(X::StridedArray{P}, Y::StridedArray{Q}) = + ($op)(x::GeneralPeriod, Y::StridedArray{<:GeneralPeriod}) = broadcast($op, x, Y) + ($op)(Y::StridedArray{<:GeneralPeriod}, x::GeneralPeriod) = broadcast($op, Y, x) + ($op)(X::StridedArray{<:GeneralPeriod}, Y::StridedArray{<:GeneralPeriod}) = reshape(CompoundPeriod[($op)(x, y) for (x, y) in zip(X, Y)], promote_shape(size(X), size(Y))) end end diff --git a/base/dates/query.jl b/base/dates/query.jl index 64ae360a7b275..71b2246a4098b 100644 --- a/base/dates/query.jl +++ b/base/dates/query.jl @@ -13,7 +13,7 @@ immutable DateLocale day_of_week_abbr_value::Dict{String, Int} end -function locale_dict{S<:AbstractString}(names::Vector{S}) +function locale_dict(names::Vector{<:AbstractString}) result = Dict{String, Int}() # Keep both the common case-sensitive version of the name and an all lowercase diff --git a/base/dates/ranges.jl b/base/dates/ranges.jl index 60625055e2e49..bd853f68e5b06 100644 --- a/base/dates/ranges.jl +++ b/base/dates/ranges.jl @@ -10,7 +10,7 @@ Base.colon{T<:Time}(start::T, stop::T) = StepRange(start, Second(1), stop) Base.range(start::DateTime, len::Integer) = range(start, Day(1), len) Base.range(start::Date, len::Integer) = range(start, Day(1), len) -(::Type{StepRange{T,R}}){T<:Dates.DatePeriod,R<:Real}(start, step, stop) = +(::Type{StepRange{<:Dates.DatePeriod,<:Real}})(start, step, stop) = throw(ArgumentError("must specify step as a Period when constructing Dates ranges")) # Given a start and end date, how many steps/periods are in between @@ -25,9 +25,9 @@ function len(a, b, c) end return i - 1 end -Base.length{T<:TimeType}(r::StepRange{T}) = isempty(r) ? 0 : len(r.start, r.stop, r.step) + 1 +Base.length(r::StepRange{<:TimeType}) = isempty(r) ? 0 : len(r.start, r.stop, r.step) + 1 # Period ranges hook into Int64 overflow detection -Base.length{P<:Period}(r::StepRange{P}) = length(StepRange(value(r.start), value(r.step), value(r.stop))) +Base.length(r::StepRange{<:Period}) = length(StepRange(value(r.start), value(r.step), value(r.stop))) # Used to calculate the last valid date in the range given the start, stop, and step # last = stop - steprem(start, stop, step) @@ -39,10 +39,10 @@ function in{T<:TimeType}(x::T, r::StepRange{T}) n >= 1 && n <= length(r) && r[n] == x end -Base.start{T<:TimeType}(r::StepRange{T}) = 0 -Base.next{T<:TimeType}(r::StepRange{T}, i::Int) = (r.start + r.step*i, i + 1) -Base.done{T<:TimeType, S<:Period}(r::StepRange{T, S}, i::Integer) = length(r) <= i +Base.start(r::StepRange{<:TimeType}) = 0 +Base.next(r::StepRange{<:TimeType}, i::Int) = (r.start + r.step*i, i + 1) +Base.done(r::StepRange{<:TimeType,<:Period}, i::Integer) = length(r) <= i -+{T<:TimeType}(x::Period, r::Range{T}) = (x + first(r)):step(r):(x + last(r)) -+{T<:TimeType}(r::Range{T}, x::Period) = x + r --{T<:TimeType}(r::Range{T}, x::Period) = (first(r)-x):step(r):(last(r)-x) \ No newline at end of file ++(x::Period, r::Range{<:TimeType}) = (x + first(r)):step(r):(x + last(r)) ++(r::Range{<:TimeType}, x::Period) = x + r +-(r::Range{<:TimeType}, x::Period) = (first(r)-x):step(r):(last(r)-x) diff --git a/base/dates/rounding.jl b/base/dates/rounding.jl index 576ad44fe7fc9..0f10cf5ca93b1 100644 --- a/base/dates/rounding.jl +++ b/base/dates/rounding.jl @@ -172,9 +172,9 @@ Base.round(::TimeType, ::Period, ::RoundingMode) = throw(DomainError()) Base.round(dt::TimeType, p::Period) = Base.round(dt, p, RoundNearestTiesUp) # Make rounding functions callable using Period types in addition to values. -Base.floor{T <: Period}(dt::TimeType, p::Type{T}) = Base.floor(dt, p(1)) -Base.ceil{T <: Period}(dt::TimeType, p::Type{T}) = Base.ceil(dt, p(1)) +Base.floor(dt::TimeType, p::Type{<:Period}) = Base.floor(dt, p(1)) +Base.ceil(dt::TimeType, p::Type{<:Period}) = Base.ceil(dt, p(1)) -function Base.round{T<:Period}(dt::TimeType, p::Type{T}, r::RoundingMode=RoundNearestTiesUp) +function Base.round(dt::TimeType, p::Type{<:Period}, r::RoundingMode=RoundNearestTiesUp) return Base.round(dt, p(1), r) end diff --git a/base/dates/types.jl b/base/dates/types.jl index 605b79595edab..5aa210fa7938c 100644 --- a/base/dates/types.jl +++ b/base/dates/types.jl @@ -311,5 +311,5 @@ sleep(time::Period) = sleep(toms(time) / 1000) Timer(time::Period, repeat::Period=Second(0)) = Timer(toms(time) / 1000, toms(repeat) / 1000) timedwait(testcb::Function, time::Period) = timedwait(testcb, toms(time) / 1000) -(::Type{Base.TypeOrder}){T<:AbstractTime}(::Type{T}) = Base.HasOrder() -(::Type{Base.TypeArithmetic}){T<:AbstractTime}(::Type{T}) = Base.ArithmeticOverflows() +(::Type{Base.TypeOrder})(::Type{<:AbstractTime}) = Base.HasOrder() +(::Type{Base.TypeArithmetic})(::Type{<:AbstractTime}) = Base.ArithmeticOverflows() diff --git a/base/deprecated.jl b/base/deprecated.jl index 4410fe42e09cf..038f9c3e6e97b 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -469,7 +469,7 @@ Filesystem.stop_watching(stream::Filesystem._FDWatcher) = depwarn("stop_watching # #19288 @eval Base.Dates begin - function recur{T<:TimeType}(fun::Function, dr::StepRange{T}; negate::Bool=false, limit::Int=10000) + function recur(fun::Function, dr::StepRange{<:TimeType}; negate::Bool=false, limit::Int=10000) Base.depwarn("Dates.recur is deprecated, use filter instead.",:recur) if negate filter(x -> !fun(x), dr) @@ -636,9 +636,9 @@ _broadcast_zpreserving(f, As...) = broadcast!(f, similar(Array{_promote_eltype_op(f, As...)}, Base.Broadcast.broadcast_indices(As...)), As...) _broadcast_zpreserving{Tv1,Ti1,Tv2,Ti2}(f::Function, A_1::SparseMatrixCSC{Tv1,Ti1}, A_2::SparseMatrixCSC{Tv2,Ti2}) = _broadcast_zpreserving!(f, spzeros(promote_type(Tv1, Tv2), promote_type(Ti1, Ti2), Base.to_shape(Base.Broadcast.broadcast_indices(A_1, A_2))), A_1, A_2) -_broadcast_zpreserving{Tv,Ti}(f::Function, A_1::SparseMatrixCSC{Tv,Ti}, A_2::Union{Array,BitArray,Number}) = +_broadcast_zpreserving{Ti}(f::Function, A_1::SparseMatrixCSC{<:Any,Ti}, A_2::Union{Array,BitArray,Number}) = _broadcast_zpreserving!(f, spzeros(promote_eltype(A_1, A_2), Ti, Base.to_shape(Base.Broadcast.broadcast_indices(A_1, A_2))), A_1, A_2) -_broadcast_zpreserving{Tv,Ti}(f::Function, A_1::Union{Array,BitArray,Number}, A_2::SparseMatrixCSC{Tv,Ti}) = +_broadcast_zpreserving{Ti}(f::Function, A_1::Union{Array,BitArray,Number}, A_2::SparseMatrixCSC{<:Any,Ti}) = _broadcast_zpreserving!(f, spzeros(promote_eltype(A_1, A_2), Ti, Base.to_shape(Base.Broadcast.broadcast_indices(A_1, A_2))), A_1, A_2) function _depstring_bczpres() @@ -675,9 +675,9 @@ end @deprecate airy(z::Number) airyai(z) @deprecate airyx(z::Number) airyaix(z) @deprecate airyprime(z::Number) airyaiprime(z) -@deprecate airy{T<:Number}(x::AbstractArray{T}) airyai.(x) -@deprecate airyx{T<:Number}(x::AbstractArray{T}) airyaix.(x) -@deprecate airyprime{T<:Number}(x::AbstractArray{T}) airyprime.(x) +@deprecate airy(x::AbstractArray{<:Number}) airyai.(x) +@deprecate airyx(x::AbstractArray{<:Number}) airyaix.(x) +@deprecate airyprime(x::AbstractArray{<:Number}) airyprime.(x) function _airy(k::Integer, z::Complex128) depwarn("`airy(k,x)` is deprecated, use `airyai(x)`, `airyaiprime(x)`, `airybi(x)` or `airybiprime(x)` instead.",:airy) @@ -714,18 +714,18 @@ for afn in (:airy,:airyx) end $afn(k::Integer, z::Complex) = $afn(k, float(z)) - $afn{T<:AbstractFloat}(k::Integer, z::Complex{T}) = throw(MethodError($afn,(k,z))) + $afn(k::Integer, z::Complex{<:AbstractFloat}) = throw(MethodError($afn,(k,z))) $afn(k::Integer, z::Complex64) = Complex64($afn(k, Complex128(z))) $afn(k::Integer, x::Real) = $afn(k, float(x)) $afn(k::Integer, x::AbstractFloat) = real($afn(k, complex(x))) - function $afn{T<:Number}(k::Number, x::AbstractArray{T}) + function $afn(k::Number, x::AbstractArray{<:Number}) $afn.(k,x) end - function $afn{S<:Number}(k::AbstractArray{S}, x::Number) + function $afn(k::AbstractArray{<:Number}, x::Number) $afn.(k,x) end - function $afn{S<:Number,T<:Number}(k::AbstractArray{S}, x::AbstractArray{T}) + function $afn(k::AbstractArray{<:Number}, x::AbstractArray{<:Number}) $afn.(k,x) end end @@ -767,14 +767,14 @@ export Collections # Not exported, but used outside Base _promote_array_type(F, ::Type, ::Type, T::Type) = T -_promote_array_type{S<:Real, A<:AbstractFloat}(F, ::Type{S}, ::Type{A}, ::Type) = A -_promote_array_type{S<:Integer, A<:Integer}(F, ::Type{S}, ::Type{A}, ::Type) = A -_promote_array_type{S<:Integer, A<:Integer}(::typeof(/), ::Type{S}, ::Type{A}, T::Type) = T -_promote_array_type{S<:Integer, A<:Integer}(::typeof(\), ::Type{S}, ::Type{A}, T::Type) = T -_promote_array_type{S<:Integer}(::typeof(/), ::Type{S}, ::Type{Bool}, T::Type) = T -_promote_array_type{S<:Integer}(::typeof(\), ::Type{S}, ::Type{Bool}, T::Type) = T -_promote_array_type{S<:Integer}(F, ::Type{S}, ::Type{Bool}, T::Type) = T -_promote_array_type{S<:Union{Complex, Real}, T<:AbstractFloat}(F, ::Type{S}, ::Type{Complex{T}}, ::Type) = Complex{T} +_promote_array_type{A<:AbstractFloat}(F, ::Type{<:Real}, ::Type{A}, ::Type) = A +_promote_array_type{A<:Integer}(F, ::Type{<:Integer}, ::Type{A}, ::Type) = A +_promote_array_type(::typeof(/), ::Type{<:Integer}, ::Type{<:Integer}, T::Type) = T +_promote_array_type(::typeof(\), ::Type{<:Integer}, ::Type{<:Integer}, T::Type) = T +_promote_array_type(::typeof(/), ::Type{<:Integer}, ::Type{Bool}, T::Type) = T +_promote_array_type(::typeof(\), ::Type{<:Integer}, ::Type{Bool}, T::Type) = T +_promote_array_type(F, ::Type{<:Integer}, ::Type{Bool}, T::Type) = T +_promote_array_type{T<:AbstractFloat}(F, ::Type{<:Union{Complex, Real}}, ::Type{Complex{T}}, ::Type) = Complex{T} function promote_array_type(F, R, S, T) Base.depwarn("`promote_array_type` is deprecated as it is no longer needed " * "in Base. See https://github.com/JuliaLang/julia/issues/19669 " * @@ -792,7 +792,7 @@ end for f in (:sec, :sech, :secd, :asec, :asech, :csc, :csch, :cscd, :acsc, :acsch, :cot, :coth, :cotd, :acot, :acoth) - @eval @deprecate $f{T<:Number}(A::AbstractArray{T}) $f.(A) + @eval @deprecate $f(A::AbstractArray{<:Number}) $f.(A) end # Deprecate vectorized two-argument complex in favor of compact broadcast syntax @@ -808,7 +808,7 @@ end @deprecate round(M::Tridiagonal) round.(M) @deprecate round(M::SymTridiagonal) round.(M) @deprecate round{T}(::Type{T}, x::AbstractArray) round.(T, x) -@deprecate round{T}(::Type{T}, x::AbstractArray, r::RoundingMode) round.(x, r) +@deprecate round{T}(::Type{T}, x::AbstractArray, r::RoundingMode) round.(T, x, r) @deprecate round(x::AbstractArray, r::RoundingMode) round.(x, r) @deprecate round(x::AbstractArray, digits::Integer, base::Integer = 10) round.(x, digits, base) @@ -838,16 +838,16 @@ end @deprecate big(r::StepRange) big.(r) @deprecate big(r::StepRangeLen) big.(r) @deprecate big(r::LinSpace) big.(r) -@deprecate big{T<:Integer,N}(x::AbstractArray{T,N}) big.(x) -@deprecate big{T<:AbstractFloat,N}(x::AbstractArray{T,N}) big.(x) +@deprecate big(x::AbstractArray{<:Integer}) big.(x) +@deprecate big(x::AbstractArray{<:AbstractFloat}) big.(x) @deprecate big(A::LowerTriangular) big.(A) @deprecate big(A::UpperTriangular) big.(A) @deprecate big(A::Base.LinAlg.UnitLowerTriangular) big.(A) @deprecate big(A::Base.LinAlg.UnitUpperTriangular) big.(A) @deprecate big(B::Bidiagonal) big.(B) -@deprecate big{T<:Integer,N}(A::AbstractArray{Complex{T},N}) big.(A) -@deprecate big{T<:AbstractFloat,N}(A::AbstractArray{Complex{T},N}) big.(A) -@deprecate big{T<:Integer,N}(x::AbstractArray{Complex{Rational{T}},N}) big.(A) +@deprecate big(A::AbstractArray{<:Complex{<:Integer}}) big.(A) +@deprecate big(A::AbstractArray{<:Complex{<:AbstractFloat}}) big.(A) +@deprecate big(x::AbstractArray{<:Complex{<:Rational{<:Integer}}}) big.(A) # Deprecate manually vectorized div methods in favor of compact broadcast syntax @deprecate div(A::Number, B::AbstractArray) div.(A, B) @@ -860,7 +860,7 @@ end # Deprecate manually vectorized div, mod, and % methods for dates @deprecate div{P<:Dates.Period}(X::StridedArray{P}, y::P) div.(X, y) -@deprecate div{P<:Dates.Period}(X::StridedArray{P}, y::Integer) div.(X, y) +@deprecate div(X::StridedArray{<:Dates.Period}, y::Integer) div.(X, y) @deprecate (%){P<:Dates.Period}(X::StridedArray{P}, y::P) X .% y @deprecate mod{P<:Dates.Period}(X::StridedArray{P}, y::P) mod.(X, y) @@ -868,8 +868,8 @@ end @deprecate mod(B::BitArray, x::Bool) mod.(B, x) @deprecate mod(x::Bool, B::BitArray) mod.(x, B) @deprecate mod(A::AbstractArray, B::AbstractArray) mod.(A, B) -@deprecate mod{T}(x::Number, A::AbstractArray{T}) mod.(x, A) -@deprecate mod{T}(A::AbstractArray{T}, x::Number) mod.(A, x) +@deprecate mod(x::Number, A::AbstractArray) mod.(x, A) +@deprecate mod(A::AbstractArray, x::Number) mod.(A, x) # Deprecate vectorized & in favor of dot syntax @deprecate (&)(a::Bool, B::BitArray) a .& B @@ -891,7 +891,7 @@ end @deprecate ifelse(c::AbstractArray{Bool}, x::AbstractArray, y) ifelse.(c, x, y) @deprecate ifelse(c::AbstractArray{Bool}, x::AbstractArray, y::AbstractArray) ifelse.(c, x, y) -function frexp{T<:AbstractFloat}(A::Array{T}) +function frexp(A::Array{<:AbstractFloat}) depwarn("`frexp(x::Array)` is discontinued.", :frexp) F = similar(A) E = Array{Int}(size(A)) diff --git a/base/dft.jl b/base/dft.jl index 21cf0023a0674..a548b499e816c 100644 --- a/base/dft.jl +++ b/base/dft.jl @@ -28,8 +28,8 @@ _fftwfloat{T}(::Type{Complex{T}}) = Complex{_fftwfloat(T)} _fftwfloat{T}(::Type{T}) = error("type $T not supported") _fftwfloat{T}(x::T) = _fftwfloat(T)(x) -complexfloat{T<:FFTWFloat}(x::StridedArray{Complex{T}}) = x -realfloat{T<:FFTWFloat}(x::StridedArray{T}) = x +complexfloat(x::StridedArray{Complex{<:FFTWFloat}}) = x +realfloat(x::StridedArray{<:FFTWFloat}) = x # return an Array, rather than similar(x), to avoid an extra copy for FFTW # (which only works on StridedArray types). @@ -201,13 +201,13 @@ bfft! for f in (:fft, :bfft, :ifft) pf = Symbol("plan_", f) @eval begin - $f{T<:Real}(x::AbstractArray{T}, region=1:ndims(x)) = $f(complexfloat(x), region) - $pf{T<:Real}(x::AbstractArray{T}, region; kws...) = $pf(complexfloat(x), region; kws...) - $f{T<:Union{Integer,Rational}}(x::AbstractArray{Complex{T}}, region=1:ndims(x)) = $f(complexfloat(x), region) - $pf{T<:Union{Integer,Rational}}(x::AbstractArray{Complex{T}}, region; kws...) = $pf(complexfloat(x), region; kws...) + $f(x::AbstractArray{<:Real}, region=1:ndims(x)) = $f(complexfloat(x), region) + $pf(x::AbstractArray{<:Real}, region; kws...) = $pf(complexfloat(x), region; kws...) + $f(x::AbstractArray{<:Complex{<:Union{Integer,Rational}}}, region=1:ndims(x)) = $f(complexfloat(x), region) + $pf(x::AbstractArray{<:Complex{<:Union{Integer,Rational}}}, region; kws...) = $pf(complexfloat(x), region; kws...) end end -rfft{T<:Union{Integer,Rational}}(x::AbstractArray{T}, region=1:ndims(x)) = rfft(realfloat(x), region) +rfft(x::AbstractArray{<:Union{Integer,Rational}}, region=1:ndims(x)) = rfft(realfloat(x), region) plan_rfft(x::AbstractArray, region; kws...) = plan_rfft(realfloat(x), region; kws...) # only require implementation to provide *(::Plan{T}, ::Array{T}) @@ -294,8 +294,8 @@ end for f in (:brfft, :irfft) @eval begin - $f{T<:Real}(x::AbstractArray{T}, d::Integer, region=1:ndims(x)) = $f(complexfloat(x), d, region) - $f{T<:Union{Integer,Rational}}(x::AbstractArray{Complex{T}}, d::Integer, region=1:ndims(x)) = $f(complexfloat(x), d, region) + $f(x::AbstractArray{<:Real}, d::Integer, region=1:ndims(x)) = $f(complexfloat(x), d, region) + $f(x::AbstractArray{<:Complex{<:Union{Integer,Rational}}}, d::Integer, region=1:ndims(x)) = $f(complexfloat(x), d, region) end end diff --git a/base/dict.jl b/base/dict.jl index 229de51ef4050..f27cb8448c753 100644 --- a/base/dict.jl +++ b/base/dict.jl @@ -503,7 +503,7 @@ false ``` """ haskey(h::Dict, key) = (ht_keyindex(h, key) >= 0) -in{T<:Dict}(key, v::KeyIterator{T}) = (ht_keyindex(v.dict, key) >= 0) +in(key, v::KeyIterator{<:Dict}) = (ht_keyindex(v.dict, key) >= 0) """ getkey(collection, key, default) @@ -581,8 +581,8 @@ next{K,V}(t::Dict{K,V}, i) = (Pair{K,V}(t.keys[i],t.vals[i]), skip_deleted(t,i+1 isempty(t::Dict) = (t.count == 0) length(t::Dict) = t.count -next{T<:Dict}(v::KeyIterator{T}, i) = (v.dict.keys[i], skip_deleted(v.dict,i+1)) -next{T<:Dict}(v::ValueIterator{T}, i) = (v.dict.vals[i], skip_deleted(v.dict,i+1)) +next(v::KeyIterator{<:Dict}, i) = (v.dict.keys[i], skip_deleted(v.dict,i+1)) +next(v::ValueIterator{<:Dict}, i) = (v.dict.vals[i], skip_deleted(v.dict,i+1)) # For these Associative types, it is safe to implement filter! # by deleting keys during iteration. diff --git a/base/docs/utils.jl b/base/docs/utils.jl index 173a22f8ec60a..d249adf0f6fcd 100644 --- a/base/docs/utils.jl +++ b/base/docs/utils.jl @@ -32,7 +32,7 @@ function HTML(xs...) end show(io::IO, ::MIME"text/html", h::HTML) = print(io, h.content) -show{F <: Function}(io::IO, ::MIME"text/html", h::HTML{F}) = h.content(io) +show(io::IO, ::MIME"text/html", h::HTML{<:Function}) = h.content(io) """ @html_str -> Docs.HTML @@ -69,7 +69,7 @@ type Text{T} end print(io::IO, t::Text) = print(io, t.content) -print{F <: Function}(io::IO, t::Text{F}) = t.content(io) +print(io::IO, t::Text{<:Function}) = t.content(io) show(io::IO, t::Text) = print(io, t) =={T<:Union{HTML, Text}}(t1::T, t2::T) = t1.content == t2.content @@ -421,7 +421,7 @@ stripmd(x::Markdown.BlockQuote) = "$(stripmd(x.content))" stripmd(x::Markdown.Admonition) = "$(stripmd(x.content))" stripmd(x::Markdown.Bold) = "$(stripmd(x.text))" stripmd(x::Markdown.Code) = "$(stripmd(x.code))" -stripmd{N}(x::Markdown.Header{N}) = stripmd(x.text) +stripmd(x::Markdown.Header) = stripmd(x.text) stripmd(x::Markdown.HorizontalRule) = " " stripmd(x::Markdown.Image) = "$(stripmd(x.alt)) $(x.url)" stripmd(x::Markdown.Italic) = "$(stripmd(x.text))" diff --git a/base/dsp.jl b/base/dsp.jl index a3c7b924d3719..f7d32406dcc38 100644 --- a/base/dsp.jl +++ b/base/dsp.jl @@ -142,8 +142,8 @@ function conv{T<:Base.LinAlg.BlasFloat}(u::StridedVector{T}, v::StridedVector{T} return y[1:n] end conv{T<:Integer}(u::StridedVector{T}, v::StridedVector{T}) = round.(Int,conv(float(u), float(v))) -conv{T<:Integer, S<:Base.LinAlg.BlasFloat}(u::StridedVector{T}, v::StridedVector{S}) = conv(float(u), v) -conv{T<:Integer, S<:Base.LinAlg.BlasFloat}(u::StridedVector{S}, v::StridedVector{T}) = conv(u, float(v)) +conv(u::StridedVector{<:Integer}, v::StridedVector{<:Base.LinAlg.BlasFloat}) = conv(float(u), v) +conv(u::StridedVector{<:Base.LinAlg.BlasFloat}, v::StridedVector{<:Integer}) = conv(u, float(v)) """ conv2(u,v,A) diff --git a/base/essentials.jl b/base/essentials.jl index 30d5fea5e3692..5a8bb19e8eea7 100644 --- a/base/essentials.jl +++ b/base/essentials.jl @@ -63,7 +63,7 @@ function tuple_type_tail(T::DataType) return Tuple{argtail(T.parameters...)...} end -tuple_type_cons{S}(::Type{S}, ::Type{Union{}}) = Union{} +tuple_type_cons(::Type, ::Type{Union{}}) = Union{} function tuple_type_cons{S,T<:Tuple}(::Type{S}, ::Type{T}) @_pure_meta Tuple{S, T.parameters...} @@ -135,7 +135,7 @@ ptr_arg_unsafe_convert{T}(::Type{Ptr{T}}, x) = unsafe_convert(T, x) ptr_arg_unsafe_convert(::Type{Ptr{Void}}, x) = x cconvert(T::Type, x) = convert(T, x) # do the conversion eagerly in most cases -cconvert{P<:Ptr}(::Type{P}, x) = x # but defer the conversion to Ptr to unsafe_convert +cconvert(::Type{<:Ptr}, x) = x # but defer the conversion to Ptr to unsafe_convert unsafe_convert{T}(::Type{T}, x::T) = x # unsafe_convert (like convert) defaults to assuming the convert occurred unsafe_convert{T<:Ptr}(::Type{T}, x::T) = x # to resolve ambiguity with the next method unsafe_convert{P<:Ptr}(::Type{P}, x::Ptr) = convert(P, x) diff --git a/base/fastmath.jl b/base/fastmath.jl index 36d975506e48c..f99e44b0f50e1 100644 --- a/base/fastmath.jl +++ b/base/fastmath.jl @@ -133,7 +133,7 @@ end FloatTypes = Union{Float32, Float64} -sub_fast{T<:FloatTypes}(x::T) = neg_float_fast(x) +sub_fast(x::FloatTypes) = neg_float_fast(x) add_fast{T<:FloatTypes}(x::T, y::T) = add_float_fast(x, y) sub_fast{T<:FloatTypes}(x::T, y::T) = sub_float_fast(x, y) @@ -169,11 +169,11 @@ issubnormal_fast(x) = false ComplexTypes = Union{Complex64, Complex128} @fastmath begin - abs_fast{T<:ComplexTypes}(x::T) = hypot(real(x), imag(x)) - abs2_fast{T<:ComplexTypes}(x::T) = real(x)*real(x) + imag(x)*imag(x) + abs_fast(x::ComplexTypes) = hypot(real(x), imag(x)) + abs2_fast(x::ComplexTypes) = real(x)*real(x) + imag(x)*imag(x) conj_fast{T<:ComplexTypes}(x::T) = T(real(x), -imag(x)) - inv_fast{T<:ComplexTypes}(x::T) = conj(x) / abs2(x) - sign_fast{T<:ComplexTypes}(x::T) = x == 0 ? float(zero(x)) : x/abs(x) + inv_fast(x::ComplexTypes) = conj(x) / abs2(x) + sign_fast(x::ComplexTypes) = x == 0 ? float(zero(x)) : x/abs(x) add_fast{T<:ComplexTypes}(x::T, y::T) = T(real(x)+real(y), imag(x)+imag(y)) @@ -243,12 +243,12 @@ end # builtins -pow_fast{T<:FloatTypes}(x::T, y::Integer) = pow_fast(x, Int32(y)) -pow_fast{T<:FloatTypes}(x::T, y::Int32) = Base.powi_llvm(x, y) +pow_fast(x::FloatTypes, y::Integer) = pow_fast(x, Int32(y)) +pow_fast(x::FloatTypes, y::Int32) = Base.powi_llvm(x, y) # TODO: Change sqrt_llvm intrinsic to avoid nan checking; add nan # checking to sqrt in math.jl; remove sqrt_llvm_fast intrinsic -sqrt_fast{T<:FloatTypes}(x::T) = sqrt_llvm_fast(x) +sqrt_fast(x::FloatTypes) = sqrt_llvm_fast(x) # libm @@ -300,30 +300,30 @@ atan2_fast(x::Float64, y::Float64) = pow_fast{T<:FloatTypes}(x::Complex{T}, y::T) = exp(y*log(x)) acos_fast{T<:ComplexTypes}(x::T) = convert(T,π)/2 + im*log(im*x + sqrt(1-x*x)) - acosh_fast{T<:ComplexTypes}(x::T) = log(x + sqrt(x+1) * sqrt(x-1)) - angle_fast{T<:ComplexTypes}(x::T) = atan2(imag(x), real(x)) - asin_fast{T<:ComplexTypes}(x::T) = -im*asinh(im*x) - asinh_fast{T<:ComplexTypes}(x::T) = log(x + sqrt(1+x*x)) - atan_fast{T<:ComplexTypes}(x::T) = -im*atanh(im*x) + acosh_fast(x::ComplexTypes) = log(x + sqrt(x+1) * sqrt(x-1)) + angle_fast(x::ComplexTypes) = atan2(imag(x), real(x)) + asin_fast(x::ComplexTypes) = -im*asinh(im*x) + asinh_fast(x::ComplexTypes) = log(x + sqrt(1+x*x)) + atan_fast(x::ComplexTypes) = -im*atanh(im*x) atanh_fast{T<:ComplexTypes}(x::T) = convert(T,1)/2*(log(1+x) - log(1-x)) - cis_fast{T<:ComplexTypes}(x::T) = exp(-imag(x)) * cis(real(x)) - cos_fast{T<:ComplexTypes}(x::T) = cosh(im*x) + cis_fast(x::ComplexTypes) = exp(-imag(x)) * cis(real(x)) + cos_fast(x::ComplexTypes) = cosh(im*x) cosh_fast{T<:ComplexTypes}(x::T) = convert(T,1)/2*(exp(x) + exp(-x)) exp10_fast{T<:ComplexTypes}(x::T) = exp10(real(x)) * cis(imag(x)*log(convert(T,10))) exp2_fast{T<:ComplexTypes}(x::T) = exp2(real(x)) * cis(imag(x)*log(convert(T,2))) - exp_fast{T<:ComplexTypes}(x::T) = exp(real(x)) * cis(imag(x)) - expm1_fast{T<:ComplexTypes}(x::T) = exp(x)-1 + exp_fast(x::ComplexTypes) = exp(real(x)) * cis(imag(x)) + expm1_fast(x::ComplexTypes) = exp(x)-1 log10_fast{T<:ComplexTypes}(x::T) = log(x) / log(convert(T,10)) - log1p_fast{T<:ComplexTypes}(x::T) = log(1+x) + log1p_fast(x::ComplexTypes) = log(1+x) log2_fast{T<:ComplexTypes}(x::T) = log(x) / log(convert(T,2)) log_fast{T<:ComplexTypes}(x::T) = T(log(abs2(x))/2, angle(x)) - sin_fast{T<:ComplexTypes}(x::T) = -im*sinh(im*x) + sin_fast(x::ComplexTypes) = -im*sinh(im*x) sinh_fast{T<:ComplexTypes}(x::T) = convert(T,1)/2*(exp(x) - exp(-x)) - sqrt_fast{T<:ComplexTypes}(x::T) = sqrt(abs(x)) * cis(angle(x)/2) - tan_fast{T<:ComplexTypes}(x::T) = -im*tanh(im*x) - tanh_fast{T<:ComplexTypes}(x::T) = (a=exp(x); b=exp(-x); (a-b)/(a+b)) + sqrt_fast(x::ComplexTypes) = sqrt(abs(x)) * cis(angle(x)/2) + tan_fast(x::ComplexTypes) = -im*tanh(im*x) + tanh_fast(x::ComplexTypes) = (a=exp(x); b=exp(-x); (a-b)/(a+b)) end # fall-back implementations and type promotion diff --git a/base/fft/FFTW.jl b/base/fft/FFTW.jl index 4a595e2e937bf..239e53f8792c1 100644 --- a/base/fft/FFTW.jl +++ b/base/fft/FFTW.jl @@ -179,9 +179,9 @@ set_timelimit(precision::fftwTypeSingle,seconds) = if Base.libfftw_name == "libmkl_rt" - alignment_of{T<:fftwDouble}(A::StridedArray{T}) = + alignment_of(A::StridedArray{<:fftwDouble}) = convert(Int32, convert(Int64, pointer(A)) % 16) - alignment_of{T<:fftwSingle}(A::StridedArray{T}) = + alignment_of(A::StridedArray{<:fftwSingle}) = convert(Int32, convert(Int64, pointer(A)) % 16) else alignment_of{T<:fftwDouble}(A::StridedArray{T}) = @@ -226,18 +226,18 @@ size(p::FFTWPlan) = p.sz unsafe_convert(::Type{PlanPtr}, p::FFTWPlan) = p.plan -destroy_plan{T<:fftwDouble}(plan::FFTWPlan{T}) = +destroy_plan(plan::FFTWPlan{<:fftwDouble}) = ccall((:fftw_destroy_plan,libfftw), Void, (PlanPtr,), plan) -destroy_plan{T<:fftwSingle}(plan::FFTWPlan{T}) = +destroy_plan(plan::FFTWPlan{<:fftwSingle}) = ccall((:fftwf_destroy_plan,libfftwf), Void, (PlanPtr,), plan) -cost{T<:fftwDouble}(plan::FFTWPlan{T}) = +cost(plan::FFTWPlan{<:fftwDouble}) = ccall((:fftw_cost,libfftw), Float64, (PlanPtr,), plan) -cost{T<:fftwSingle}(plan::FFTWPlan{T}) = +cost(plan::FFTWPlan{<:fftwSingle}) = ccall((:fftwf_cost,libfftwf), Float64, (PlanPtr,), plan) -function arithmetic_ops{T<:fftwDouble}(plan::FFTWPlan{T}) +function arithmetic_ops(plan::FFTWPlan{<:fftwDouble}) # Change to individual Ref after we can allocate them on stack ref = Ref{NTuple{3, Float64}}() ptr = Ptr{Float64}(Base.unsafe_convert(Ptr{NTuple{3, Float64}}, ref)) @@ -246,7 +246,7 @@ function arithmetic_ops{T<:fftwDouble}(plan::FFTWPlan{T}) plan, ptr, ptr + 8, ptr + 16) (round(Int64, ref[][1]), round(Int64, ref[][2]), round(Int64, ref[][3])) end -function arithmetic_ops{T<:fftwSingle}(plan::FFTWPlan{T}) +function arithmetic_ops(plan::FFTWPlan{<:fftwSingle}) # Change to individual Ref after we can allocate them on stack ref = Ref{NTuple{3, Float64}}() ptr = Ptr{Float64}(Base.unsafe_convert(Ptr{NTuple{3, Float64}}, ref)) @@ -277,9 +277,9 @@ function showfftdims(io, sz::Dims, istride::Dims, T) end # The sprint_plan function was released in FFTW 3.3.4 -sprint_plan_{T<:fftwDouble}(plan::FFTWPlan{T}) = +sprint_plan_(plan::FFTWPlan{<:fftwDouble}) = ccall((:fftw_sprint_plan,libfftw), Ptr{UInt8}, (PlanPtr,), plan) -sprint_plan_{T<:fftwSingle}(plan::FFTWPlan{T}) = +sprint_plan_(plan::FFTWPlan{<:fftwSingle}) = ccall((:fftwf_sprint_plan,libfftwf), Ptr{UInt8}, (PlanPtr,), plan) function sprint_plan(plan::FFTWPlan) p = sprint_plan_(plan) @@ -354,10 +354,10 @@ colmajorstrides(sz) = isempty(sz) ? () : (1,cumprod(Int[sz[1:end-1]...])...) # Execute -unsafe_execute!{T<:fftwDouble}(plan::FFTWPlan{T}) = +unsafe_execute!(plan::FFTWPlan{<:fftwDouble}) = ccall((:fftw_execute,libfftw), Void, (PlanPtr,), plan) -unsafe_execute!{T<:fftwSingle}(plan::FFTWPlan{T}) = +unsafe_execute!(plan::FFTWPlan{<:fftwSingle}) = ccall((:fftwf_execute,libfftwf), Void, (PlanPtr,), plan) unsafe_execute!{T<:fftwDouble}(plan::cFFTWPlan{T}, @@ -566,15 +566,14 @@ end # Convert arrays of numeric types to FFTW-supported packed complex-float types # (FIXME: is there a way to use the Julia promotion rules more cleverly here?) -fftwcomplex{T<:fftwComplex}(X::StridedArray{T}) = X +fftwcomplex(X::StridedArray{<:fftwComplex}) = X fftwcomplex{T<:fftwReal}(X::AbstractArray{T}) = copy!(Array{typeof(complex(zero(T)))}(size(X)), X) -fftwcomplex{T<:Real}(X::AbstractArray{T}) = copy!(Array{Complex128}(size(X)),X) -fftwcomplex{T<:Complex}(X::AbstractArray{T}) = - copy!(Array{Complex128}(size(X)), X) -fftwfloat{T<:fftwReal}(X::StridedArray{T}) = X -fftwfloat{T<:Real}(X::AbstractArray{T}) = copy!(Array{Float64}(size(X)), X) -fftwfloat{T<:Complex}(X::AbstractArray{T}) = fftwcomplex(X) +fftwcomplex(X::AbstractArray{<:Real}) = copy!(Array{Complex128}(size(X)),X) +fftwcomplex(X::AbstractArray{<:Complex}) = copy!(Array{Complex128}(size(X)), X) +fftwfloat(X::StridedArray{<:fftwReal}) = X +fftwfloat(X::AbstractArray{<:Real}) = copy!(Array{Float64}(size(X)), X) +fftwfloat(X::AbstractArray{<:Complex}) = fftwcomplex(X) for (f,direction) in ((:fft,FORWARD), (:bfft,BACKWARD)) plan_f = Symbol("plan_",f) @@ -593,9 +592,9 @@ for (f,direction) in ((:fft,FORWARD), (:bfft,BACKWARD)) timelimit::Real=NO_TIMELIMIT) cFFTWPlan{T,$direction,true,N}(X, X, region, flags, timelimit) end - $plan_f{T<:fftwComplex}(X::StridedArray{T}; kws...) = + $plan_f(X::StridedArray{<:fftwComplex}; kws...) = $plan_f(X, 1:ndims(X); kws...) - $plan_f!{T<:fftwComplex}(X::StridedArray{T}; kws...) = + $plan_f!(X::StridedArray{<:fftwComplex}; kws...) = $plan_f!(X, 1:ndims(X); kws...) function plan_inv{T<:fftwComplex,N,inplace}(p::cFFTWPlan{T,$direction,inplace,N}) @@ -738,13 +737,13 @@ plan_brfft for f in (:r2r, :r2r!) pf = Symbol("plan_", f) @eval begin - $f{T<:fftwNumber}(x::AbstractArray{T}, kinds) = $pf(x, kinds) * x - $f{T<:fftwNumber}(x::AbstractArray{T}, kinds, region) = $pf(x, kinds, region) * x + $f(x::AbstractArray{<:fftwNumber}, kinds) = $pf(x, kinds) * x + $f(x::AbstractArray{<:fftwNumber}, kinds, region) = $pf(x, kinds, region) * x $pf(x::AbstractArray, kinds; kws...) = $pf(x, kinds, 1:ndims(x); kws...) - $f{T<:Real}(x::AbstractArray{T}, kinds, region=1:ndims(x)) = $f(fftwfloat(x), kinds, region) - $pf{T<:Real}(x::AbstractArray{T}, kinds, region; kws...) = $pf(fftwfloat(x), kinds, region; kws...) - $f{T<:Complex}(x::AbstractArray{T}, kinds, region=1:ndims(x)) = $f(fftwcomplex(x), kinds, region) - $pf{T<:Complex}(x::AbstractArray{T}, kinds, region; kws...) = $pf(fftwcomplex(x), kinds, region; kws...) + $f(x::AbstractArray{<:Real}, kinds, region=1:ndims(x)) = $f(fftwfloat(x), kinds, region) + $pf(x::AbstractArray{<:Real}, kinds, region; kws...) = $pf(fftwfloat(x), kinds, region; kws...) + $f(x::AbstractArray{<:Complex}, kinds, region=1:ndims(x)) = $f(fftwcomplex(x), kinds, region) + $pf(x::AbstractArray{<:Complex}, kinds, region; kws...) = $pf(fftwcomplex(x), kinds, region; kws...) end end diff --git a/base/fft/dct.jl b/base/fft/dct.jl index f97f52ee3be0f..4a22e7f0b45f4 100644 --- a/base/fft/dct.jl +++ b/base/fft/dct.jl @@ -84,12 +84,12 @@ end for f in (:dct, :dct!, :idct, :idct!) pf = Symbol("plan_", f) @eval begin - $f{T<:fftwNumber}(x::AbstractArray{T}) = $pf(x) * x - $f{T<:fftwNumber}(x::AbstractArray{T}, region) = $pf(x, region) * x + $f(x::AbstractArray{<:fftwNumber}) = $pf(x) * x + $f(x::AbstractArray{<:fftwNumber}, region) = $pf(x, region) * x $pf(x::AbstractArray; kws...) = $pf(x, 1:ndims(x); kws...) - $f{T<:Real}(x::AbstractArray{T}, region=1:ndims(x)) = $f(fftwfloat(x), region) - $pf{T<:Real}(x::AbstractArray{T}, region; kws...) = $pf(fftwfloat(x), region; kws...) - $pf{T<:Complex}(x::AbstractArray{T}, region; kws...) = $pf(fftwcomplex(x), region; kws...) + $f(x::AbstractArray{<:Real}, region=1:ndims(x)) = $f(fftwfloat(x), region) + $pf(x::AbstractArray{<:Real}, region; kws...) = $pf(fftwfloat(x), region; kws...) + $pf(x::AbstractArray{<:Complex}, region; kws...) = $pf(fftwcomplex(x), region; kws...) end end diff --git a/base/float.jl b/base/float.jl index 5b80d1033a3c0..dd413325c94ac 100644 --- a/base/float.jl +++ b/base/float.jl @@ -777,7 +777,7 @@ truncmask(x, mask) = x ## Array operations on floating point numbers ## -float{T<:AbstractFloat}(A::AbstractArray{T}) = A +float(A::AbstractArray{<:AbstractFloat}) = A function float{T}(A::AbstractArray{T}) if !isleaftype(T) diff --git a/base/floatfuncs.jl b/base/floatfuncs.jl index 4cad27b73c8e9..70a139705f38c 100644 --- a/base/floatfuncs.jl +++ b/base/floatfuncs.jl @@ -198,7 +198,7 @@ const ≈ = isapprox # default tolerance arguments rtoldefault{T<:AbstractFloat}(::Type{T}) = sqrt(eps(T)) -rtoldefault{T<:Real}(::Type{T}) = 0 +rtoldefault(::Type{<:Real}) = 0 rtoldefault{T<:Number,S<:Number}(x::Union{T,Type{T}}, y::Union{S,Type{S}}) = max(rtoldefault(real(T)),rtoldefault(real(S))) # fused multiply-add diff --git a/base/generator.jl b/base/generator.jl index 2708d65148d30..5a585e438a260 100644 --- a/base/generator.jl +++ b/base/generator.jl @@ -108,7 +108,7 @@ Base.HasEltype() iteratoreltype(x) = iteratoreltype(typeof(x)) iteratoreltype(::Type) = HasEltype() # HasEltype is the default -iteratorsize{T<:AbstractArray}(::Type{T}) = HasShape() +iteratorsize(::Type{<:AbstractArray}) = HasShape() iteratorsize{I,F}(::Type{Generator{I,F}}) = iteratorsize(I) length(g::Generator) = length(g.iter) size(g::Generator) = size(g.iter) diff --git a/base/gmp.jl b/base/gmp.jl index 3cdf65b6fcdec..9d067004f11c2 100644 --- a/base/gmp.jl +++ b/base/gmp.jl @@ -244,7 +244,7 @@ convert(::Type{Float64}, n::BigInt) = Float64(n,RoundNearest) convert(::Type{Float32}, n::BigInt) = Float32(n,RoundNearest) convert(::Type{Float16}, n::BigInt) = Float16(n,RoundNearest) -promote_rule{T<:Integer}(::Type{BigInt}, ::Type{T}) = BigInt +promote_rule(::Type{BigInt}, ::Type{<:Integer}) = BigInt # Binary ops for (fJ, fC) in ((:+, :add), (:-,:sub), (:*, :mul), diff --git a/base/hashing2.jl b/base/hashing2.jl index 23ac5de0b8225..96bd4ed55e56b 100644 --- a/base/hashing2.jl +++ b/base/hashing2.jl @@ -143,7 +143,7 @@ end ## streamlined hashing for smallish rational types ## -function hash{T<:BitInteger64}(x::Rational{T}, h::UInt) +function hash(x::Rational{<:BitInteger64}, h::UInt) num, den = Base.numerator(x), Base.denominator(x) den == 1 && return hash(num, h) den == 0 && return hash(ifelse(num > 0, Inf, -Inf), h) diff --git a/base/inference.jl b/base/inference.jl index 5670a6edbdede..b3bd01cd2db33 100644 --- a/base/inference.jl +++ b/base/inference.jl @@ -582,7 +582,7 @@ function typeof_tfunc(t::ANY) elseif t === Any return DataType else - return Type{_T} where _T<:t + return Type{<:t} end elseif isa(t, Union) a = widenconst(typeof_tfunc(t.a)) @@ -891,7 +891,7 @@ function fieldtype_tfunc(s0::ANY, name::ANY) if exact return Const(ft) end - return Type{_T} where _T<:ft + return Type{<:ft} end add_tfunc(fieldtype, 2, 2, fieldtype_tfunc) @@ -1002,17 +1002,17 @@ function apply_type_tfunc(headtypetype::ANY, args::ANY...) catch ex # type instantiation might fail if one of the type parameters # doesn't match, which could happen if a type estimate is too coarse - return Type{_T} where _T<:headtype + return Type{<:headtype} end !uncertain && canconst && return Const(appl) if isvarargtype(headtype) return Type end if uncertain && type_too_complex(appl,0) - return Type{_T} where _T<:headtype + return Type{<:headtype} end if istuple - return Type{_T} where _T<:appl + return Type{<:appl} end ans = Type{appl} for i = length(outervars):-1:1 @@ -1471,7 +1471,7 @@ function return_type_tfunc(argtypes::ANY, vtypes::VarTable, sv::InferenceState) # input arguments were known for certain return Const(rt) else - return Type{R} where R <: rt + return Type{<:rt} end end end diff --git a/base/int.jl b/base/int.jl index daba5620e8c06..6e9fa9a80ee06 100644 --- a/base/int.jl +++ b/base/int.jl @@ -27,7 +27,7 @@ typealias BitUnsigned64T Union{Type{UInt8}, Type{UInt16}, Type{UInt32}, Type{UIn <{T<:BitSigned}(x::T, y::T) = slt_int(x, y) --{T<:BitInteger}(x::T) = neg_int(x) +-(x::BitInteger) = neg_int(x) -{T<:BitInteger}(x::T, y::T) = sub_int(x, y) +{T<:BitInteger}(x::T, y::T) = add_int(x, y) *{T<:BitInteger}(x::T, y::T) = mul_int(x, y) @@ -166,13 +166,13 @@ end ## integer bitwise operations ## -(~){T<:BitInteger}(x::T) = not_int(x) +(~)(x::BitInteger) = not_int(x) (&){T<:BitInteger}(x::T, y::T) = and_int(x, y) (|){T<:BitInteger}(x::T, y::T) = or_int(x, y) xor{T<:BitInteger}(x::T, y::T) = xor_int(x, y) -bswap{T<:Union{Int8, UInt8}}(x::T) = x -bswap{T<:Union{Int16, UInt16, Int32, UInt32, Int64, UInt64, Int128, UInt128}}(x::T) = +bswap(x::Union{Int8, UInt8}) = x +bswap(x::Union{Int16, UInt16, Int32, UInt32, Int64, UInt64, Int128, UInt128}) = bswap_int(x) """ @@ -185,7 +185,7 @@ julia> count_ones(7) 3 ``` """ -count_ones{T<:BitInteger}(x::T) = Int(ctpop_int(x)) +count_ones(x::BitInteger) = Int(ctpop_int(x)) """ leading_zeros(x::Integer) -> Integer @@ -197,7 +197,7 @@ julia> leading_zeros(Int32(1)) 31 ``` """ -leading_zeros{T<:BitInteger}(x::T) = Int(ctlz_int(x)) +leading_zeros(x::BitInteger) = Int(ctlz_int(x)) """ trailing_zeros(x::Integer) -> Integer @@ -209,7 +209,7 @@ julia> trailing_zeros(2) 1 ``` """ -trailing_zeros{T<:BitInteger}(x::T) = Int(cttz_int(x)) +trailing_zeros(x::BitInteger) = Int(cttz_int(x)) """ count_zeros(x::Integer) -> Integer @@ -263,10 +263,10 @@ trailing_ones(x::Integer) = trailing_zeros(~x) ## integer shifts ## # unsigned shift counts always shift in the same direction ->>{T<:BitSigned,S<:BitUnsigned}(x::T, y::S) = ashr_int(x, y) ->>{T<:BitUnsigned,S<:BitUnsigned}(x::T, y::S) = lshr_int(x, y) -<<{T<:BitInteger,S<:BitUnsigned}(x::T, y::S) = shl_int(x, y) ->>>{T<:BitInteger,S<:BitUnsigned}(x::T, y::S) = lshr_int(x, y) +>>(x::BitSigned, y::BitUnsigned) = ashr_int(x, y) +>>(x::BitUnsigned, y::BitUnsigned) = lshr_int(x, y) +<<(x::BitInteger, y::BitUnsigned) = shl_int(x, y) +>>>(x::BitInteger, y::BitUnsigned) = lshr_int(x, y) # signed shift counts can shift in either direction # note: this early during bootstrap, `>=` is not yet available # note: we only define Int shift counts here; the generic case is handled later @@ -331,8 +331,8 @@ for (Ts, Tu) in ((Int8, UInt8), (Int16, UInt16), (Int32, UInt32), (Int64, UInt64 @eval convert(::Type{Unsigned}, x::$Ts) = convert($Tu, x) end -convert{T<:Union{Float32, Float64, Bool}}(::Type{Signed}, x::T) = convert(Int, x) -convert{T<:Union{Float32, Float64, Bool}}(::Type{Unsigned}, x::T) = convert(UInt, x) +convert(::Type{Signed}, x::Union{Float32, Float64, Bool}) = convert(Int, x) +convert(::Type{Unsigned}, x::Union{Float32, Float64, Bool}) = convert(UInt, x) convert(::Type{Integer}, x::Integer) = x convert(::Type{Integer}, x::Real) = convert(Signed, x) @@ -370,25 +370,25 @@ end promote_rule(::Type{Int8}, ::Type{Int16}) = Int16 promote_rule(::Type{UInt8}, ::Type{UInt16}) = UInt16 -promote_rule{T<:Union{Int8,Int16}}(::Type{Int32}, ::Type{T}) = Int32 -promote_rule{T<:Union{UInt8,UInt16}}(::Type{UInt32}, ::Type{T}) = UInt32 -promote_rule{T<:Union{Int8,Int16,Int32}}(::Type{Int64}, ::Type{T}) = Int64 -promote_rule{T<:Union{UInt8,UInt16,UInt32}}(::Type{UInt64}, ::Type{T}) = UInt64 -promote_rule{T<:BitSigned64}(::Type{Int128}, ::Type{T}) = Int128 -promote_rule{T<:BitUnsigned64}(::Type{UInt128}, ::Type{T}) = UInt128 +promote_rule(::Type{Int32}, ::Type{<:Union{Int8,Int16}}) = Int32 +promote_rule(::Type{UInt32}, ::Type{<:Union{UInt8,UInt16}}) = UInt32 +promote_rule(::Type{Int64}, ::Type{<:Union{Int8,Int16,Int32}}) = Int64 +promote_rule(::Type{UInt64}, ::Type{<:Union{UInt8,UInt16,UInt32}}) = UInt64 +promote_rule(::Type{Int128}, ::Type{<:BitSigned64}) = Int128 +promote_rule(::Type{UInt128}, ::Type{<:BitUnsigned64}) = UInt128 for T in BitSigned_types - @eval promote_rule{S<:Union{UInt8,UInt16}}(::Type{S}, ::Type{$T}) = + @eval promote_rule(::Type{<:Union{UInt8,UInt16}}, ::Type{$T}) = $(sizeof(T) < sizeof(Int) ? Int : T) end -@eval promote_rule{T<:Union{Int8,Int16,Int32}}(::Type{UInt32}, ::Type{T}) = +@eval promote_rule(::Type{UInt32}, ::Type{<:Union{Int8,Int16,Int32}}) = $(Core.sizeof(Int) == 8 ? Int : UInt) promote_rule(::Type{UInt32}, ::Type{Int64}) = Int64 -promote_rule{T<:BitSigned64}(::Type{UInt64}, ::Type{T}) = UInt64 -promote_rule{T<:Union{UInt32, UInt64}}(::Type{T}, ::Type{Int128}) = Int128 -promote_rule{T<:BitSigned}(::Type{UInt128}, ::Type{T}) = UInt128 +promote_rule(::Type{UInt64}, ::Type{<:BitSigned64}) = UInt64 +promote_rule(::Type{<:Union{UInt32, UInt64}}, ::Type{Int128}) = Int128 +promote_rule(::Type{UInt128}, ::Type{<:BitSigned}) = UInt128 -_default_type(T::Type{Unsigned}) = UInt -_default_type(T::Union{Type{Integer},Type{Signed}}) = Int +_default_type(::Type{Unsigned}) = UInt +_default_type(::Union{Type{Integer},Type{Signed}}) = Int ## traits ## @@ -413,10 +413,10 @@ typemax(::Type{UInt64}) = 0xffffffffffffffff @eval typemin(::Type{Int128} ) = $(convert(Int128, 1) << 127) @eval typemax(::Type{Int128} ) = $(bitcast(Int128, typemax(UInt128) >> 1)) -widen{T<:Union{Int8, Int16}}(::Type{T}) = Int32 +widen(::Type{<:Union{Int8, Int16}}) = Int32 widen(::Type{Int32}) = Int64 widen(::Type{Int64}) = Int128 -widen{T<:Union{UInt8, UInt16}}(::Type{T}) = UInt32 +widen(::Type{<:Union{UInt8, UInt16}}) = UInt32 widen(::Type{UInt32}) = UInt64 widen(::Type{UInt64}) = UInt128 diff --git a/base/intfuncs.jl b/base/intfuncs.jl index bc305b48664d7..3331011ce5a2b 100644 --- a/base/intfuncs.jl +++ b/base/intfuncs.jl @@ -75,8 +75,8 @@ lcm(a::Integer, b::Integer) = lcm(promote(a,b)...) gcd(a::Integer, b::Integer...) = gcd(a, gcd(b...)) lcm(a::Integer, b::Integer...) = lcm(a, lcm(b...)) -gcd{T<:Integer}(abc::AbstractArray{T}) = reduce(gcd,abc) -lcm{T<:Integer}(abc::AbstractArray{T}) = reduce(lcm,abc) +gcd(abc::AbstractArray{<:Integer}) = reduce(gcd,abc) +lcm(abc::AbstractArray{<:Integer}) = reduce(lcm,abc) # return (gcd(a,b),x,y) such that ax+by == gcd(a,b) """ diff --git a/base/iostream.jl b/base/iostream.jl index a2050119b78fb..824978af53873 100644 --- a/base/iostream.jl +++ b/base/iostream.jl @@ -166,7 +166,7 @@ function unsafe_write(s::IOStream, p::Ptr{UInt8}, nb::UInt) return Int(ccall(:ios_write, Csize_t, (Ptr{Void}, Ptr{Void}, Csize_t), s.ios, p, nb)) end -function write{T,N,A<:Array}(s::IOStream, a::SubArray{T,N,A}) +function write{T,N}(s::IOStream, a::SubArray{T,N,<:Array}) if !isbits(T) || stride(a,1)!=1 return invoke(write, Tuple{Any, AbstractArray}, s, a) end diff --git a/base/irrationals.jl b/base/irrationals.jl index d17111f500154..49777c54311ce 100644 --- a/base/irrationals.jl +++ b/base/irrationals.jl @@ -6,10 +6,10 @@ immutable Irrational{sym} <: Real end show{sym}(io::IO, x::Irrational{sym}) = print(io, "$sym = $(string(float(x))[1:15])...") -promote_rule{s}(::Type{Irrational{s}}, ::Type{Float16}) = Float16 -promote_rule{s}(::Type{Irrational{s}}, ::Type{Float32}) = Float32 -promote_rule{s,t}(::Type{Irrational{s}}, ::Type{Irrational{t}}) = Float64 -promote_rule{s,T<:Number}(::Type{Irrational{s}}, ::Type{T}) = promote_type(Float64,T) +promote_rule(::Type{<:Irrational}, ::Type{Float16}) = Float16 +promote_rule(::Type{<:Irrational}, ::Type{Float32}) = Float32 +promote_rule(::Type{<:Irrational}, ::Type{<:Irrational}) = Float64 +promote_rule{T<:Number}(::Type{<:Irrational}, ::Type{T}) = promote_type(Float64, T) convert(::Type{AbstractFloat}, x::Irrational) = Float64(x) convert(::Type{Float16}, x::Irrational) = Float16(Float32(x)) @@ -65,7 +65,7 @@ end @pure function rationalize{T<:Integer}(::Type{T}, x::Irrational; tol::Real=0) return rationalize(T, big(x), tol=tol) end -@pure function lessrational{T<:Integer}(rx::Rational{T}, x::Irrational) +@pure function lessrational(rx::Rational{<:Integer}, x::Irrational) # an @pure version of `<` for determining if the rationalization of # an irrational number required rounding up or down return rx < big(x) diff --git a/base/iterators.jl b/base/iterators.jl index 30a864ce2a990..c08f272340221 100644 --- a/base/iterators.jl +++ b/base/iterators.jl @@ -208,7 +208,7 @@ done(f::Filter, s) = s[1] eltype{F,I}(::Type{Filter{F,I}}) = eltype(I) iteratoreltype{F,I}(::Type{Filter{F,I}}) = iteratoreltype(I) -iteratorsize{T<:Filter}(::Type{T}) = SizeUnknown() +iteratorsize(::Type{<:Filter}) = SizeUnknown() # Rest -- iterate starting at the given state @@ -257,7 +257,7 @@ start(it::Count) = it.start next(it::Count, state) = (state, state + it.step) done(it::Count, state) = false -iteratorsize{S}(::Type{Count{S}}) = IsInfinite() +iteratorsize(::Type{<:Count}) = IsInfinite() # Take -- iterate through the first n elements @@ -438,8 +438,8 @@ start(it::Repeated) = nothing next(it::Repeated, state) = (it.x, nothing) done(it::Repeated, state) = false -iteratorsize{O}(::Type{Repeated{O}}) = IsInfinite() -iteratoreltype{O}(::Type{Repeated{O}}) = HasEltype() +iteratorsize(::Type{<:Repeated}) = IsInfinite() +iteratoreltype(::Type{<:Repeated}) = HasEltype() # Product -- cartesian product of iterators @@ -665,7 +665,7 @@ start(itr::PartitionIterator) = start(itr.c) done(itr::PartitionIterator, state) = done(itr.c, state) -function next{T<:Vector}(itr::PartitionIterator{T}, state) +function next(itr::PartitionIterator{<:Vector}, state) l = state r = min(state + itr.n-1, length(itr.c)) return view(itr.c, l:r), r + 1 diff --git a/base/libgit2/config.jl b/base/libgit2/config.jl index 8aa0ec60a0227..7c01664042cc4 100644 --- a/base/libgit2/config.jl +++ b/base/libgit2/config.jl @@ -51,7 +51,7 @@ function addfile(cfg::GitConfig, path::AbstractString, cfg.ptr, path, Cint(level), Cint(force)) end -function get{T<:AbstractString}(::Type{T}, c::GitConfig, name::AbstractString) +function get(::Type{<:AbstractString}, c::GitConfig, name::AbstractString) buf_ref = Ref(Buffer()) @check ccall((:git_config_get_string_buf, :libgit2), Cint, (Ptr{Buffer}, Ptr{Void}, Cstring), buf_ref, c.ptr, name) @@ -88,13 +88,13 @@ function get{T}(c::GitConfig, name::AbstractString, default::T) return res end -function getconfig{T}(r::GitRepo, name::AbstractString, default::T) +function getconfig(r::GitRepo, name::AbstractString, default) with(GitConfig, r) do cfg get(cfg, name, default) end end -function getconfig{T}(rname::AbstractString, name::AbstractString, default::T) +function getconfig(rname::AbstractString, name::AbstractString, default) with(GitRepo, rname) do r with(GitConfig, r) do cfg get(cfg, name, default) @@ -102,13 +102,13 @@ function getconfig{T}(rname::AbstractString, name::AbstractString, default::T) end end -function getconfig{T}(name::AbstractString, default::T) +function getconfig(name::AbstractString, default) with(GitConfig) do cfg get(cfg, name, default) end end -function set!{T <: AbstractString}(c::GitConfig, name::AbstractString, value::T) +function set!(c::GitConfig, name::AbstractString, value::AbstractString) @check ccall((:git_config_set_string, :libgit2), Cint, (Ptr{Void}, Cstring, Cstring), c.ptr, name, value) end diff --git a/base/libgit2/index.jl b/base/libgit2/index.jl index c7b0e6148e59f..8154c70c2c699 100644 --- a/base/libgit2/index.jl +++ b/base/libgit2/index.jl @@ -46,27 +46,27 @@ end read_tree!(idx::GitIndex, hash::AbstractGitHash) = read_tree!(idx, GitTree(repository(idx), hash)) -function add!{T<:AbstractString}(idx::GitIndex, files::T...; - flags::Cuint = Consts.INDEX_ADD_DEFAULT) +function add!(idx::GitIndex, files::AbstractString...; + flags::Cuint = Consts.INDEX_ADD_DEFAULT) @check ccall((:git_index_add_all, :libgit2), Cint, (Ptr{Void}, Ptr{StrArrayStruct}, Cuint, Ptr{Void}, Ptr{Void}), idx.ptr, collect(files), flags, C_NULL, C_NULL) end -function update!{T<:AbstractString}(idx::GitIndex, files::T...) +function update!(idx::GitIndex, files::AbstractString...) @check ccall((:git_index_update_all, :libgit2), Cint, (Ptr{Void}, Ptr{StrArrayStruct}, Ptr{Void}, Ptr{Void}), idx.ptr, collect(files), C_NULL, C_NULL) end -function remove!{T<:AbstractString}(idx::GitIndex, files::T...) +function remove!(idx::GitIndex, files::AbstractString...) @check ccall((:git_index_remove_all, :libgit2), Cint, (Ptr{Void}, Ptr{StrArrayStruct}, Ptr{Void}, Ptr{Void}), idx.ptr, collect(files), C_NULL, C_NULL) end -function add!{T<:AbstractString}(repo::GitRepo, files::T...; - flags::Cuint = Consts.INDEX_ADD_DEFAULT) +function add!(repo::GitRepo, files::AbstractString...; + flags::Cuint = Consts.INDEX_ADD_DEFAULT) with(GitIndex, repo) do idx add!(idx, files..., flags = flags) write!(idx) @@ -74,7 +74,7 @@ function add!{T<:AbstractString}(repo::GitRepo, files::T...; return end -function update!{T<:AbstractString}(repo::GitRepo, files::T...) +function update!(repo::GitRepo, files::AbstractString...) with(GitIndex, repo) do idx update!(idx, files...) write!(idx) @@ -82,7 +82,7 @@ function update!{T<:AbstractString}(repo::GitRepo, files::T...) return end -function remove!{T<:AbstractString}(repo::GitRepo, files::T...) +function remove!(repo::GitRepo, files::AbstractString...) with(GitIndex, repo) do idx remove!(idx, files...) write!(idx) diff --git a/base/libgit2/libgit2.jl b/base/libgit2/libgit2.jl index 0ccfc2298158a..eb396dabe2076 100644 --- a/base/libgit2/libgit2.jl +++ b/base/libgit2/libgit2.jl @@ -202,7 +202,7 @@ function set_remote_url(path::AbstractString, url::AbstractString; remote::Abstr end end -function make_payload{P<:AbstractCredentials}(payload::Nullable{P}) +function make_payload(payload::Nullable{<:AbstractCredentials}) Ref{Nullable{AbstractCredentials}}(payload) end @@ -223,11 +223,10 @@ The keyword arguments are: Equivalent to `git fetch [|] []`. """ -function fetch{T<:AbstractString, P<:AbstractCredentials}(repo::GitRepo; - remote::AbstractString="origin", - remoteurl::AbstractString="", - refspecs::Vector{T}=AbstractString[], - payload::Nullable{P}=Nullable{AbstractCredentials}()) +function fetch(repo::GitRepo; remote::AbstractString="origin", + remoteurl::AbstractString="", + refspecs::Vector{<:AbstractString}=AbstractString[], + payload::Nullable{<:AbstractCredentials}=Nullable{AbstractCredentials}()) rmt = if isempty(remoteurl) get(GitRemote, repo, remote) else @@ -258,12 +257,11 @@ The keyword arguments are: Equivalent to `git push [|] []`. """ -function push{T<:AbstractString, P<:AbstractCredentials}(repo::GitRepo; - remote::AbstractString="origin", +function push(repo::GitRepo; remote::AbstractString="origin", remoteurl::AbstractString="", - refspecs::Vector{T}=AbstractString[], + refspecs::Vector{<:AbstractString}=AbstractString[], force::Bool=false, - payload::Nullable{P}=Nullable{AbstractCredentials}()) + payload::Nullable{<:AbstractCredentials}=Nullable{AbstractCredentials}()) rmt = if isempty(remoteurl) get(GitRemote, repo, remote) else @@ -437,11 +435,11 @@ The keyword arguments are: Equivalent to `git clone [-b ] [--bare] `. """ -function clone{P<:AbstractCredentials}(repo_url::AbstractString, repo_path::AbstractString; +function clone(repo_url::AbstractString, repo_path::AbstractString; branch::AbstractString="", isbare::Bool = false, remote_cb::Ptr{Void} = C_NULL, - payload::Nullable{P}=Nullable{AbstractCredentials}()) + payload::Nullable{<:AbstractCredentials}=Nullable{AbstractCredentials}()) # setup clone options lbranch = Base.cconvert(Cstring, branch) payload = make_payload(payload) diff --git a/base/libgit2/remote.jl b/base/libgit2/remote.jl index eb56dd0eea9bc..4ba586ea862d6 100644 --- a/base/libgit2/remote.jl +++ b/base/libgit2/remote.jl @@ -112,7 +112,7 @@ The keyword arguments are: * `options`: determines the options for the fetch, e.g. whether to prune afterwards. * `msg`: a message to insert into the reflogs. """ -function fetch{T<:AbstractString}(rmt::GitRemote, refspecs::Vector{T}; +function fetch(rmt::GitRemote, refspecs::Vector{<:AbstractString}; options::FetchOptions = FetchOptions(), msg::AbstractString="") msg = "libgit2.fetch: $msg" @@ -130,9 +130,8 @@ The keyword arguments are: * `force`: if `true`, a force-push will occur, disregarding conflicts. * `options`: determines the options for the push, e.g. which proxy headers to use. """ -function push{T<:AbstractString}(rmt::GitRemote, refspecs::Vector{T}; - force::Bool = false, - options::PushOptions = PushOptions()) +function push(rmt::GitRemote, refspecs::Vector{<:AbstractString}; + force::Bool = false, options::PushOptions = PushOptions()) @check ccall((:git_remote_push, :libgit2), Cint, (Ptr{Void}, Ptr{StrArrayStruct}, Ptr{PushOptions}), rmt.ptr, isempty(refspecs) ? C_NULL : refspecs, Ref(options)) diff --git a/base/libgit2/repository.jl b/base/libgit2/repository.jl index c3b7afd5eb04d..47ab7046339a2 100644 --- a/base/libgit2/repository.jl +++ b/base/libgit2/repository.jl @@ -263,7 +263,7 @@ function checkout_head(repo::GitRepo; options::CheckoutOptions = CheckoutOptions end """Updates some entries, determined by the `pathspecs`, in the index from the target commit tree.""" -function reset!{T<:AbstractString, S<:GitObject}(repo::GitRepo, obj::Nullable{S}, pathspecs::T...) +function reset!(repo::GitRepo, obj::Nullable{<:GitObject}, pathspecs::AbstractString...) @check ccall((:git_reset_default, :libgit2), Cint, (Ptr{Void}, Ptr{Void}, Ptr{StrArrayStruct}), repo.ptr, diff --git a/base/linalg/arnoldi.jl b/base/linalg/arnoldi.jl index ff73a7c8e7a3a..d47084af1dd78 100644 --- a/base/linalg/arnoldi.jl +++ b/base/linalg/arnoldi.jl @@ -88,7 +88,7 @@ julia> λ Applications (1996), 17(4), 789–821. doi:10.1137/S0895479895281484 """ eigs(A; kwargs...) = eigs(A, I; kwargs...) -eigs{T<:BlasFloat}(A::AbstractMatrix{T}, ::UniformScaling; kwargs...) = _eigs(A, I; kwargs...) +eigs(A::AbstractMatrix{<:BlasFloat}, ::UniformScaling; kwargs...) = _eigs(A, I; kwargs...) eigs{T<:BlasFloat}(A::AbstractMatrix{T}, B::AbstractMatrix{T}; kwargs...) = _eigs(A, B; kwargs...) eigs(A::AbstractMatrix{BigFloat}, B::AbstractMatrix...; kwargs...) = throw(MethodError(eigs, Any[A,B,kwargs...])) @@ -315,7 +315,7 @@ function SVDOperator(A::AbstractMatrix{T}) where T SVDOperator{Tnew,typeof(Anew)}(Anew) end -function A_mul_B!{T,S}(u::StridedVector{T}, s::SVDOperator{T,S}, v::StridedVector{T}) +function A_mul_B!{T}(u::StridedVector{T}, s::SVDOperator{T}, v::StridedVector{T}) a, b = s.m, length(v) A_mul_B!(view(u,1:a), s.X, view(v,a+1:b)) # left singular vector Ac_mul_B!(view(u,a+1:b), s.X, view(v,1:a)) # right singular vector @@ -324,7 +324,7 @@ end size(s::SVDOperator) = s.m + s.n, s.m + s.n issymmetric(s::SVDOperator) = true -svds{T<:BlasFloat}(A::AbstractMatrix{T}; kwargs...) = _svds(A; kwargs...) +svds(A::AbstractMatrix{<:BlasFloat}; kwargs...) = _svds(A; kwargs...) svds(A::AbstractMatrix{BigFloat}; kwargs...) = throw(MethodError(svds, Any[A, kwargs...])) function svds{T}(A::AbstractMatrix{T}; kwargs...) Tnew = typeof(zero(T)/sqrt(one(T))) diff --git a/base/linalg/bidiag.jl b/base/linalg/bidiag.jl index 230948e39c362..6d4e08bd0e3fb 100644 --- a/base/linalg/bidiag.jl +++ b/base/linalg/bidiag.jl @@ -206,10 +206,10 @@ promote_rule{T,S}(::Type{Tridiagonal{T}}, ::Type{Bidiagonal{S}})=Tridiagonal{pro # No-op for trivial conversion Bidiagonal{T} -> Bidiagonal{T} convert{T}(::Type{Bidiagonal{T}}, A::Bidiagonal{T}) = A -# Convert Bidiagonal{Told} to Bidiagonal{Tnew} by constructing a new instance with converted elements -convert{Tnew,Told}(::Type{Bidiagonal{Tnew}}, A::Bidiagonal{Told}) = Bidiagonal(convert(Vector{Tnew}, A.dv), convert(Vector{Tnew}, A.ev), A.isupper) -# When asked to convert Bidiagonal{Told} to AbstractMatrix{Tnew}, preserve structure by converting to Bidiagonal{Tnew} <: AbstractMatrix{Tnew} -convert{Tnew,Told}(::Type{AbstractMatrix{Tnew}}, A::Bidiagonal{Told}) = convert(Bidiagonal{Tnew}, A) +# Convert Bidiagonal to Bidiagonal{T} by constructing a new instance with converted elements +convert{T}(::Type{Bidiagonal{T}}, A::Bidiagonal) = Bidiagonal(convert(Vector{T}, A.dv), convert(Vector{T}, A.ev), A.isupper) +# When asked to convert Bidiagonal to AbstractMatrix{T}, preserve structure by converting to Bidiagonal{T} <: AbstractMatrix{T} +convert{T}(::Type{AbstractMatrix{T}}, A::Bidiagonal) = convert(Bidiagonal{T}, A) broadcast(::typeof(big), B::Bidiagonal) = Bidiagonal(big.(B.dv), big.(B.ev), B.isupper) @@ -220,8 +220,8 @@ similar{T}(B::Bidiagonal, ::Type{T}) = Bidiagonal{T}(similar(B.dv, T), similar(B ################### #Singular values -svdvals!{T<:BlasReal}(M::Bidiagonal{T}) = LAPACK.bdsdc!(M.isupper ? 'U' : 'L', 'N', M.dv, M.ev)[1] -function svdfact!{T<:BlasReal}(M::Bidiagonal{T}; thin::Bool=true) +svdvals!(M::Bidiagonal{<:BlasReal}) = LAPACK.bdsdc!(M.isupper ? 'U' : 'L', 'N', M.dv, M.ev)[1] +function svdfact!(M::Bidiagonal{<:BlasReal}; thin::Bool=true) d, e, U, Vt, Q, iQ = LAPACK.bdsdc!(M.isupper ? 'U' : 'L', 'I', M.dv, M.ev) SVD(U, d, Vt) end @@ -356,13 +356,13 @@ A_mul_B!(C::AbstractVecOrMat, A::BiTri, B::AbstractVecOrMat) = A_mul_B_td!(C, A, \(::Diagonal, ::RowVector) = throw(DimensionMismatch("Cannot left-divide matrix by transposed vector")) \(::Bidiagonal, ::RowVector) = throw(DimensionMismatch("Cannot left-divide matrix by transposed vector")) -\{TA<:Number,TB<:Number}(::Bidiagonal{TA}, ::RowVector{TB}) = throw(DimensionMismatch("Cannot left-divide matrix by transposed vector")) +\(::Bidiagonal{<:Number}, ::RowVector{<:Number}) = throw(DimensionMismatch("Cannot left-divide matrix by transposed vector")) At_ldiv_B(::Bidiagonal, ::RowVector) = throw(DimensionMismatch("Cannot left-divide matrix by transposed vector")) -At_ldiv_B{TA<:Number,TB<:Number}(::Bidiagonal{TA}, ::RowVector{TB}) = throw(DimensionMismatch("Cannot left-divide matrix by transposed vector")) +At_ldiv_B(::Bidiagonal{<:Number}, ::RowVector{<:Number}) = throw(DimensionMismatch("Cannot left-divide matrix by transposed vector")) Ac_ldiv_B(::Bidiagonal, ::RowVector) = throw(DimensionMismatch("Cannot left-divide matrix by transposed vector")) -Ac_ldiv_B{TA<:Number,TB<:Number}(::Bidiagonal{TA}, ::RowVector{TB}) = throw(DimensionMismatch("Cannot left-divide matrix by transposed vector")) +Ac_ldiv_B(::Bidiagonal{<:Number}, ::RowVector{<:Number}) = throw(DimensionMismatch("Cannot left-divide matrix by transposed vector")) function check_A_mul_B!_sizes(C, A, B) nA, mA = size(A) @@ -604,11 +604,11 @@ end eigfact(M::Bidiagonal) = Eigen(eigvals(M), eigvecs(M)) # fill! methods -_valuefields{T <: Diagonal}(S::Type{T}) = [:diag] -_valuefields{T <: Bidiagonal}(S::Type{T}) = [:dv, :ev] -_valuefields{T <: Tridiagonal}(S::Type{T}) = [:dl, :d, :du] -_valuefields{T <: SymTridiagonal}(S::Type{T}) = [:dv, :ev] -_valuefields{T <: AbstractTriangular}(S::Type{T}) = [:data] +_valuefields(::Type{<:Diagonal}) = [:diag] +_valuefields(::Type{<:Bidiagonal}) = [:dv, :ev] +_valuefields(::Type{<:Tridiagonal}) = [:dl, :d, :du] +_valuefields(::Type{<:SymTridiagonal}) = [:dv, :ev] +_valuefields(::Type{<:AbstractTriangular}) = [:data] SpecialArrays = Union{Diagonal, Bidiagonal, diff --git a/base/linalg/blas.jl b/base/linalg/blas.jl index 200e9dfc14775..3a7a9fb4b676e 100644 --- a/base/linalg/blas.jl +++ b/base/linalg/blas.jl @@ -439,7 +439,7 @@ for (fname, elty) in ((:daxpy_,:Float64), end end end -function axpy!{T<:BlasFloat,Ta<:Number}(alpha::Ta, x::Union{DenseArray{T},StridedVector{T}}, y::Union{DenseArray{T},StridedVector{T}}) +function axpy!{T<:BlasFloat}(alpha::Number, x::Union{DenseArray{T},StridedVector{T}}, y::Union{DenseArray{T},StridedVector{T}}) if length(x) != length(y) throw(DimensionMismatch("x has length $(length(x)), but y has length $(length(y))")) end @@ -447,7 +447,7 @@ function axpy!{T<:BlasFloat,Ta<:Number}(alpha::Ta, x::Union{DenseArray{T},Stride y end -function axpy!{T<:BlasFloat,Ta<:Number,Ti<:Integer}(alpha::Ta, x::Array{T}, rx::Union{UnitRange{Ti},Range{Ti}}, +function axpy!{T<:BlasFloat,Ti<:Integer}(alpha::Number, x::Array{T}, rx::Union{UnitRange{Ti},Range{Ti}}, y::Array{T}, ry::Union{UnitRange{Ti},Range{Ti}}) if length(rx) != length(ry) diff --git a/base/linalg/bunchkaufman.jl b/base/linalg/bunchkaufman.jl index ac155f1c3ed5f..a11db8aac2265 100644 --- a/base/linalg/bunchkaufman.jl +++ b/base/linalg/bunchkaufman.jl @@ -22,7 +22,7 @@ BunchKaufman{T}(A::AbstractMatrix{T}, ipiv::Vector{BlasInt}, uplo::Char, symmetr `bkfact!` is the same as [`bkfact`](@ref), but saves space by overwriting the input `A`, instead of creating a copy. """ -function bkfact!{T<:BlasReal}(A::StridedMatrix{T}, uplo::Symbol = :U, +function bkfact!(A::StridedMatrix{<:BlasReal}, uplo::Symbol = :U, symmetric::Bool = issymmetric(A), rook::Bool = false) if !symmetric @@ -35,7 +35,7 @@ function bkfact!{T<:BlasReal}(A::StridedMatrix{T}, uplo::Symbol = :U, end BunchKaufman(LD, ipiv, char_uplo(uplo), symmetric, rook, info) end -function bkfact!{T<:BlasComplex}(A::StridedMatrix{T}, uplo::Symbol=:U, +function bkfact!(A::StridedMatrix{<:BlasComplex}, uplo::Symbol=:U, symmetric::Bool=issymmetric(A), rook::Bool=false) if rook @@ -69,7 +69,7 @@ The following functions are available for [^Bunch1977]: J R Bunch and L Kaufman, Some stable methods for calculating inertia and solving symmetric linear systems, Mathematics of Computation 31:137 (1977), 163-179. [url](http://www.ams.org/journals/mcom/1977-31-137/S0025-5718-1977-0428694-0). """ -bkfact{T<:BlasFloat}(A::StridedMatrix{T}, uplo::Symbol=:U, symmetric::Bool=issymmetric(A), +bkfact(A::StridedMatrix{<:BlasFloat}, uplo::Symbol=:U, symmetric::Bool=issymmetric(A), rook::Bool=false) = bkfact!(copy(A), uplo, symmetric, rook) bkfact{T}(A::StridedMatrix{T}, uplo::Symbol=:U, symmetric::Bool=issymmetric(A), @@ -88,7 +88,7 @@ size(B::BunchKaufman, d::Integer) = size(B.LD, d) issymmetric(B::BunchKaufman) = B.symmetric ishermitian(B::BunchKaufman) = !B.symmetric -function inv{T<:BlasReal}(B::BunchKaufman{T}) +function inv(B::BunchKaufman{<:BlasReal}) if B.info > 0 throw(SingularException(B.info)) end @@ -100,7 +100,7 @@ function inv{T<:BlasReal}(B::BunchKaufman{T}) end end -function inv{T<:BlasComplex}(B::BunchKaufman{T}) +function inv(B::BunchKaufman{<:BlasComplex}) if B.info > 0 throw(SingularException(B.info)) end diff --git a/base/linalg/cholesky.jl b/base/linalg/cholesky.jl index f01d07d9f2fa9..262bcf7dfe741 100644 --- a/base/linalg/cholesky.jl +++ b/base/linalg/cholesky.jl @@ -50,11 +50,11 @@ end # _chol!. Internal methods for calling unpivoted Cholesky ## BLAS/LAPACK element types -function _chol!{T<:BlasFloat}(A::StridedMatrix{T}, ::Type{UpperTriangular}) +function _chol!(A::StridedMatrix{<:BlasFloat}, ::Type{UpperTriangular}) C, info = LAPACK.potrf!('U', A) return @assertposdef UpperTriangular(C) info end -function _chol!{T<:BlasFloat}(A::StridedMatrix{T}, ::Type{LowerTriangular}) +function _chol!(A::StridedMatrix{<:BlasFloat}, ::Type{LowerTriangular}) C, info = LAPACK.potrf!('L', A) return @assertposdef LowerTriangular(C) info end @@ -123,7 +123,7 @@ non_hermitian_error(f) = throw(ArgumentError("matrix is not symmetric/" * # matrix chol!(A::Hermitian) = _chol!(A.uplo == 'U' ? A.data : LinAlg.copytri!(A.data, 'L', true), UpperTriangular) -chol!{T<:Real,S<:StridedMatrix}(A::Symmetric{T,S}) = +chol!(A::Symmetric{<:Real,<:StridedMatrix}) = _chol!(A.uplo == 'U' ? A.data : LinAlg.copytri!(A.data, 'L', true), UpperTriangular) function chol!(A::StridedMatrix) ishermitian(A) || non_hermitian_error("chol!") @@ -144,7 +144,7 @@ function chol(A::Hermitian) end chol!(Hermitian(AA, :U)) end -function chol{T<:Real,S<:AbstractMatrix}(A::Symmetric{T,S}) +function chol{T<:Real}(A::Symmetric{T,<:AbstractMatrix}) TT = promote_type(typeof(chol(one(T))), Float32) AA = similar(A, TT, size(A)) if A.uplo == 'U' @@ -213,7 +213,7 @@ function cholfact!(A::Hermitian, ::Type{Val{false}}) Cholesky(_chol!(A.data, LowerTriangular).data, 'L') end end -function cholfact!{T<:Real,S}(A::Symmetric{T,S}, ::Type{Val{false}}) +function cholfact!(A::Symmetric{<:Real}, ::Type{Val{false}}) if A.uplo == 'U' Cholesky(_chol!(A.data, UpperTriangular).data, 'U') else @@ -249,7 +249,7 @@ end ### Default to no pivoting (and storing of upper factor) when not explicit cholfact!(A::Hermitian) = cholfact!(A, Val{false}) -cholfact!{T<:Real,S}(A::Symmetric{T,S}) = cholfact!(A, Val{false}) +cholfact!(A::Symmetric{<:Real}) = cholfact!(A, Val{false}) #### for StridedMatrices, check that matrix is symmetric/Hermitian function cholfact!(A::StridedMatrix, uplo::Symbol = :U) ishermitian(A) || non_hermitian_error("cholfact!") @@ -259,7 +259,7 @@ end ## With pivoting ### BLAS/LAPACK element types -function cholfact!{T<:BlasReal,S<:StridedMatrix}(A::RealHermSymComplexHerm{T,S}, +function cholfact!(A::RealHermSymComplexHerm{<:BlasReal,<:StridedMatrix}, ::Type{Val{true}}; tol = 0.0) AA, piv, rank, info = LAPACK.pstrf!(A.uplo, A.data, tol) return CholeskyPivoted{eltype(AA),typeof(AA)}(AA, A.uplo, piv, rank, tol, info) @@ -267,7 +267,7 @@ end ### Non BLAS/LAPACK element types (generic). Since generic fallback for pivoted Cholesky ### is not implemented yet we throw an error -cholfact!{T<:Real,S}(A::RealHermSymComplexHerm{T,S}, ::Type{Val{true}}; +cholfact!(A::RealHermSymComplexHerm{<:Real}, ::Type{Val{true}}; tol = 0.0) = throw(ArgumentError("generic pivoted Cholesky factorization is not implemented yet")) @@ -290,7 +290,7 @@ end ## No pivoting cholfact(A::Hermitian, ::Type{Val{false}}) = cholfact!(copy_oftype(A, promote_type(typeof(chol(one(eltype(A)))),Float32)), Val{false}) -cholfact{T<:Real,S<:StridedMatrix}(A::Symmetric{T,S}, ::Type{Val{false}}) = +cholfact(A::Symmetric{<:Real,<:StridedMatrix}, ::Type{Val{false}}) = cholfact!(copy_oftype(A, promote_type(typeof(chol(one(eltype(A)))),Float32)), Val{false}) ### for StridedMatrices, check that matrix is symmetric/Hermitian @@ -343,7 +343,7 @@ end ### Default to no pivoting (and storing of upper factor) when not explicit cholfact(A::Hermitian) = cholfact(A, Val{false}) -cholfact{T<:Real,S<:StridedMatrix}(A::Symmetric{T,S}) = cholfact(A, Val{false}) +cholfact(A::Symmetric{<:Real,<:StridedMatrix}) = cholfact(A, Val{false}) #### for StridedMatrices, check that matrix is symmetric/Hermitian function cholfact(A::StridedMatrix, uplo::Symbol = :U) ishermitian(A) || non_hermitian_error("cholfact") @@ -355,7 +355,7 @@ end cholfact(A::Hermitian, ::Type{Val{true}}; tol = 0.0) = cholfact!(copy_oftype(A, promote_type(typeof(chol(one(eltype(A)))),Float32)), Val{true}; tol = tol) -cholfact{T<:Real,S<:StridedMatrix}(A::RealHermSymComplexHerm{T,S}, ::Type{Val{true}}; tol = 0.0) = +cholfact(A::RealHermSymComplexHerm{<:Real,<:StridedMatrix}, ::Type{Val{true}}; tol = 0.0) = cholfact!(copy_oftype(A, promote_type(typeof(chol(one(eltype(A)))),Float32)), Val{true}; tol = tol) @@ -386,12 +386,7 @@ function cholfact(x::Number, uplo::Symbol=:U) end - -function convert{Tnew,Told,S}(::Type{Cholesky{Tnew}}, C::Cholesky{Told,S}) - Cnew = convert(AbstractMatrix{Tnew}, C.factors) - Cholesky{Tnew, typeof(Cnew)}(Cnew, C.uplo) -end -function convert{T,S}(::Type{Cholesky{T,S}}, C::Cholesky) +function convert{T}(::Type{Cholesky{T}}, C::Cholesky) Cnew = convert(AbstractMatrix{T}, C.factors) Cholesky{T, typeof(Cnew)}(Cnew, C.uplo) end @@ -424,7 +419,7 @@ copy(C::CholeskyPivoted) = CholeskyPivoted(copy(C.factors), C.uplo, C.piv, C.ran size(C::Union{Cholesky, CholeskyPivoted}) = size(C.factors) size(C::Union{Cholesky, CholeskyPivoted}, d::Integer) = size(C.factors, d) -function getindex{T,S}(C::Cholesky{T,S}, d::Symbol) +function getindex(C::Cholesky, d::Symbol) d == :U && return UpperTriangular(Symbol(C.uplo) == d ? C.factors : C.factors') d == :L && return LowerTriangular(Symbol(C.uplo) == d ? C.factors : C.factors') d == :UL && return Symbol(C.uplo) == :U ? UpperTriangular(C.factors) : LowerTriangular(C.factors) @@ -445,13 +440,13 @@ function getindex{T<:BlasFloat}(C::CholeskyPivoted{T}, d::Symbol) throw(KeyError(d)) end -show{T,S<:AbstractMatrix}(io::IO, C::Cholesky{T,S}) = +show(io::IO, C::Cholesky{<:Any,<:AbstractMatrix}) = (println(io, "$(typeof(C)) with factor:");show(io,C[:UL])) -A_ldiv_B!{T<:BlasFloat,S<:AbstractMatrix}(C::Cholesky{T,S}, B::StridedVecOrMat{T}) = +A_ldiv_B!{T<:BlasFloat}(C::Cholesky{T,<:AbstractMatrix}, B::StridedVecOrMat{T}) = LAPACK.potrs!(C.uplo, C.factors, B) -function A_ldiv_B!{T,S<:AbstractMatrix}(C::Cholesky{T,S}, B::StridedVecOrMat) +function A_ldiv_B!(C::Cholesky{<:Any,<:AbstractMatrix}, B::StridedVecOrMat) if C.uplo == 'L' return Ac_ldiv_B!(LowerTriangular(C.factors), A_ldiv_B!(LowerTriangular(C.factors), B)) else @@ -536,10 +531,10 @@ function logdet(C::CholeskyPivoted) end end -inv!{T<:BlasFloat,S<:StridedMatrix}(C::Cholesky{T,S}) = +inv!(C::Cholesky{<:BlasFloat,<:StridedMatrix}) = copytri!(LAPACK.potri!(C.uplo, C.factors), C.uplo, true) -inv{T<:BlasFloat,S<:StridedMatrix}(C::Cholesky{T,S}) = +inv(C::Cholesky{<:BlasFloat,<:StridedMatrix}) = inv!(copy(C)) function inv(C::CholeskyPivoted) diff --git a/base/linalg/dense.jl b/base/linalg/dense.jl index 2155312e8f497..c678a38362a01 100644 --- a/base/linalg/dense.jl +++ b/base/linalg/dense.jl @@ -30,7 +30,7 @@ function scale!{T<:BlasComplex}(X::Array{T}, s::Real) end #Test whether a matrix is positive-definite -isposdef!{T<:BlasFloat}(A::StridedMatrix{T}, UL::Symbol) = LAPACK.potrf!(char_uplo(UL), A)[2] == 0 +isposdef!(A::StridedMatrix{<:BlasFloat}, UL::Symbol) = LAPACK.potrf!(char_uplo(UL), A)[2] == 0 """ isposdef!(A) -> Bool @@ -352,8 +352,8 @@ julia> expm(A) 0.0 2.71828 ``` """ -expm{T<:BlasFloat}(A::StridedMatrix{T}) = expm!(copy(A)) -expm{T<:Integer}(A::StridedMatrix{T}) = expm!(float(A)) +expm(A::StridedMatrix{<:BlasFloat}) = expm!(copy(A)) +expm(A::StridedMatrix{<:Integer}) = expm!(float(A)) expm(x::Number) = exp(x) ## Destructive matrix exponential using algorithm from Higham, 2008, @@ -442,7 +442,7 @@ function expm!{T<:BlasFloat}(A::StridedMatrix{T}) end ## Swap rows i and j and columns i and j in X -function rcswap!{T<:Number}(i::Integer, j::Integer, X::StridedMatrix{T}) +function rcswap!(i::Integer, j::Integer, X::StridedMatrix{<:Number}) for k = 1:size(X,1) X[k,i], X[k,j] = X[k,j], X[k,i] end @@ -553,7 +553,7 @@ julia> sqrtm(A) 0.0 2.0 ``` """ -function sqrtm{T<:Real}(A::StridedMatrix{T}) +function sqrtm(A::StridedMatrix{<:Real}) if issymmetric(A) return full(sqrtm(Symmetric(A))) end @@ -566,7 +566,7 @@ function sqrtm{T<:Real}(A::StridedMatrix{T}) return SchurF[:vectors] * R * SchurF[:vectors]' end end -function sqrtm{T<:Complex}(A::StridedMatrix{T}) +function sqrtm(A::StridedMatrix{<:Complex}) if ishermitian(A) return full(sqrtm(Hermitian(A))) end diff --git a/base/linalg/diagonal.jl b/base/linalg/diagonal.jl index 7ef09ad1508a7..1e4e7f3b3254d 100644 --- a/base/linalg/diagonal.jl +++ b/base/linalg/diagonal.jl @@ -100,7 +100,7 @@ end parent(D::Diagonal) = D.diag -ishermitian{T<:Real}(D::Diagonal{T}) = true +ishermitian(D::Diagonal{<:Real}) = true ishermitian(D::Diagonal) = isreal(D.diag) issymmetric(D::Diagonal) = true isposdef(D::Diagonal) = all(x -> x > 0, D.diag) @@ -138,9 +138,9 @@ end +(Da::Diagonal, Db::Diagonal) = Diagonal(Da.diag + Db.diag) -(Da::Diagonal, Db::Diagonal) = Diagonal(Da.diag - Db.diag) -*{T<:Number}(x::T, D::Diagonal) = Diagonal(x * D.diag) -*{T<:Number}(D::Diagonal, x::T) = Diagonal(D.diag * x) -/{T<:Number}(D::Diagonal, x::T) = Diagonal(D.diag / x) +*(x::Number, D::Diagonal) = Diagonal(x * D.diag) +*(D::Diagonal, x::Number) = Diagonal(D.diag * x) +/(D::Diagonal, x::Number) = Diagonal(D.diag / x) *(Da::Diagonal, Db::Diagonal) = Diagonal(Da.diag .* Db.diag) *(D::Diagonal, V::AbstractVector) = D.diag .* V @@ -266,8 +266,8 @@ ctranspose(D::Diagonal) = conj(D) diag(D::Diagonal) = D.diag trace(D::Diagonal) = sum(D.diag) det(D::Diagonal) = prod(D.diag) -logdet{T<:Real}(D::Diagonal{T}) = sum(log, D.diag) -function logdet{T<:Complex}(D::Diagonal{T}) # make sure branch cut is correct +logdet(D::Diagonal{<:Real}) = sum(log, D.diag) +function logdet(D::Diagonal{<:Complex}) # make sure branch cut is correct z = sum(log, D.diag) complex(real(z), rem2pi(imag(z), RoundNearest)) end @@ -332,15 +332,15 @@ function pinv{T}(D::Diagonal{T}, tol::Real) end #Eigensystem -eigvals{T<:Number}(D::Diagonal{T}) = D.diag +eigvals(D::Diagonal{<:Number}) = D.diag eigvals(D::Diagonal) = [eigvals(x) for x in D.diag] #For block matrices, etc. eigvecs(D::Diagonal) = eye(D) eigfact(D::Diagonal) = Eigen(eigvals(D), eigvecs(D)) #Singular system -svdvals{T<:Number}(D::Diagonal{T}) = sort!(abs.(D.diag), rev = true) +svdvals(D::Diagonal{<:Number}) = sort!(abs.(D.diag), rev = true) svdvals(D::Diagonal) = [svdvals(v) for v in D.diag] -function svd{T<:Number}(D::Diagonal{T}) +function svd(D::Diagonal{<:Number}) S = abs.(D.diag) piv = sortperm(S, rev = true) U = Diagonal(D.diag ./ S) diff --git a/base/linalg/eigen.jl b/base/linalg/eigen.jl index 87ff0da9804cb..82d8e61b3b2b2 100644 --- a/base/linalg/eigen.jl +++ b/base/linalg/eigen.jl @@ -168,12 +168,12 @@ The option `permute=true` permutes the matrix to become closer to upper triangular, and `scale=true` scales the matrix by its diagonal elements to make rows and columns more equal in norm. """ -function eigvals!{T<:BlasReal}(A::StridedMatrix{T}; permute::Bool=true, scale::Bool=true) +function eigvals!(A::StridedMatrix{<:BlasReal}; permute::Bool=true, scale::Bool=true) issymmetric(A) && return eigvals!(Symmetric(A)) _, valsre, valsim, _ = LAPACK.geevx!(permute ? (scale ? 'B' : 'P') : (scale ? 'S' : 'N'), 'N', 'N', 'N', A) return iszero(valsim) ? valsre : complex.(valsre, valsim) end -function eigvals!{T<:BlasComplex}(A::StridedMatrix{T}; permute::Bool=true, scale::Bool=true) +function eigvals!(A::StridedMatrix{<:BlasComplex}; permute::Bool=true, scale::Bool=true) ishermitian(A) && return eigvals(Hermitian(A)) return LAPACK.geevx!(permute ? (scale ? 'B' : 'P') : (scale ? 'S' : 'N'), 'N', 'N', 'N', A)[2] end diff --git a/base/linalg/factorization.jl b/base/linalg/factorization.jl index ac581f5466a47..5c61c6d2d0bf0 100644 --- a/base/linalg/factorization.jl +++ b/base/linalg/factorization.jl @@ -57,7 +57,7 @@ for f in (:A_ldiv_B!, :Ac_ldiv_B!, :At_ldiv_B!) end # fallback methods for transposed solves -At_ldiv_B{T<:Real}(F::Factorization{T}, B::AbstractVecOrMat) = Ac_ldiv_B(F, B) +At_ldiv_B(F::Factorization{<:Real}, B::AbstractVecOrMat) = Ac_ldiv_B(F, B) At_ldiv_B(F::Factorization, B) = conj.(Ac_ldiv_B(F, conj.(B))) """ diff --git a/base/linalg/generic.jl b/base/linalg/generic.jl index 946fbd6cfa17f..bd07f62a6b3f4 100644 --- a/base/linalg/generic.jl +++ b/base/linalg/generic.jl @@ -531,7 +531,7 @@ julia> norm(A, Inf) 6.0 ``` """ -function norm{T}(A::AbstractMatrix{T}, p::Real=2) +function norm(A::AbstractMatrix, p::Real=2) if p == 2 return norm2(A) elseif p == 1 @@ -545,7 +545,7 @@ end @inline norm(x::Number, p::Real=2) = vecnorm(x, p) -@inline norm{T}(tv::RowVector{T}) = norm(transpose(tv)) +@inline norm(tv::RowVector) = norm(transpose(tv)) """ norm(rowvector, [q = 2]) @@ -557,7 +557,7 @@ The difference in norm between a vector space and its dual arises to preserve the relationship between duality and the inner product, and the result is consistent with the p-norm of `1 × n` matrix. """ -@inline norm{T}(tv::RowVector{T}, q::Real) = q == Inf ? norm(transpose(tv), 1) : norm(transpose(tv), q/(q-1)) +@inline norm(tv::RowVector, q::Real) = q == Inf ? norm(transpose(tv), 1) : norm(transpose(tv), q/(q-1)) function vecdot(x::AbstractArray, y::AbstractArray) lx = _length(x) @@ -1072,7 +1072,7 @@ function axpy!(α, x::AbstractArray, y::AbstractArray) y end -function axpy!{Ti<:Integer,Tj<:Integer}(α, x::AbstractArray, rx::AbstractArray{Ti}, y::AbstractArray, ry::AbstractArray{Tj}) +function axpy!(α, x::AbstractArray, rx::AbstractArray{<:Integer}, y::AbstractArray, ry::AbstractArray{<:Integer}) if _length(rx) != _length(ry) throw(DimensionMismatch("rx has length $(_length(rx)), but ry has length $(_length(ry))")) elseif !checkindex(Bool, linearindices(x), rx) diff --git a/base/linalg/hessenberg.jl b/base/linalg/hessenberg.jl index 28cdcd2187194..6989ae5a6657e 100644 --- a/base/linalg/hessenberg.jl +++ b/base/linalg/hessenberg.jl @@ -17,9 +17,9 @@ Hessenberg(A::StridedMatrix) = Hessenberg(LAPACK.gehrd!(A)...) `hessfact!` is the same as [`hessfact`](@ref), but saves space by overwriting the input `A`, instead of creating a copy. """ -hessfact!{T<:BlasFloat}(A::StridedMatrix{T}) = Hessenberg(A) +hessfact!(A::StridedMatrix{<:BlasFloat}) = Hessenberg(A) -hessfact{T<:BlasFloat}(A::StridedMatrix{T}) = hessfact!(copy(A)) +hessfact(A::StridedMatrix{<:BlasFloat}) = hessfact!(copy(A)) """ hessfact(A) -> Hessenberg @@ -78,7 +78,7 @@ function getindex(A::HessenbergQ, i::Integer, j::Integer) end ## reconstruct the original matrix -convert{T<:BlasFloat}(::Type{Matrix}, A::HessenbergQ{T}) = LAPACK.orghr!(1, size(A.factors, 1), copy(A.factors), A.τ) +convert(::Type{Matrix}, A::HessenbergQ{<:BlasFloat}) = LAPACK.orghr!(1, size(A.factors, 1), copy(A.factors), A.τ) convert(::Type{Array}, A::HessenbergQ) = convert(Matrix, A) full(A::HessenbergQ) = convert(Array, A) convert(::Type{AbstractMatrix}, F::Hessenberg) = (fq = Array(F[:Q]); (fq * F[:H]) * fq') diff --git a/base/linalg/lapack.jl b/base/linalg/lapack.jl index a3f99e37755e0..5282ec8ba22f2 100644 --- a/base/linalg/lapack.jl +++ b/base/linalg/lapack.jl @@ -655,7 +655,7 @@ Compute the `LQ` factorization of `A`, `A = LQ`. Returns `A`, modified in-place, and `tau`, which contains scalars which parameterize the elementary reflectors of the factorization. """ -gelqf!{T<:BlasFloat}(A::StridedMatrix{T}) = ((m,n)=size(A); gelqf!(A,similar(A,T,min(m,n)))) +gelqf!(A::StridedMatrix{<:BlasFloat}) = ((m,n) = size(A); gelqf!(A, similar(A, min(m, n)))) """ geqlf!(A) -> (A, tau) @@ -665,7 +665,7 @@ Compute the `QL` factorization of `A`, `A = QL`. Returns `A`, modified in-place, and `tau`, which contains scalars which parameterize the elementary reflectors of the factorization. """ -geqlf!{T<:BlasFloat}(A::StridedMatrix{T}) = ((m,n)=size(A); geqlf!(A,similar(A,T,min(m,n)))) +geqlf!(A::StridedMatrix{<:BlasFloat}) = ((m,n) = size(A); geqlf!(A, similar(A, min(m, n)))) """ geqrt!(A, nb) -> (A, T) @@ -677,7 +677,7 @@ Returns `A`, modified in-place, and `T`, which contains upper triangular block reflectors which parameterize the elementary reflectors of the factorization. """ -geqrt!{T<:BlasFloat}(A::StridedMatrix{T}, nb::Integer) = geqrt!(A,similar(A,T,nb,minimum(size(A)))) +geqrt!(A::StridedMatrix{<:BlasFloat}, nb::Integer) = geqrt!(A, similar(A, nb, minimum(size(A)))) """ geqrt3!(A) -> (A, T) @@ -687,7 +687,7 @@ Recursively computes the blocked `QR` factorization of `A`, `A = QR`. Returns `A`, modified in-place, and `T`, which contains upper triangular block reflectors which parameterize the elementary reflectors of the factorization. """ -geqrt3!{T<:BlasFloat}(A::StridedMatrix{T}) = (n=size(A,2); geqrt3!(A,similar(A,T,n,n))) +geqrt3!(A::StridedMatrix{<:BlasFloat}) = (n = size(A, 2); geqrt3!(A, similar(A, n, n))) """ geqrf!(A) -> (A, tau) @@ -697,7 +697,7 @@ Compute the `QR` factorization of `A`, `A = QR`. Returns `A`, modified in-place, and `tau`, which contains scalars which parameterize the elementary reflectors of the factorization. """ -geqrf!{T<:BlasFloat}(A::StridedMatrix{T}) = ((m,n)=size(A); geqrf!(A,similar(A,T,min(m,n)))) +geqrf!(A::StridedMatrix{<:BlasFloat}) = ((m,n) = size(A); geqrf!(A, similar(A, min(m, n)))) """ gerqf!(A) -> (A, tau) @@ -707,7 +707,7 @@ Compute the `RQ` factorization of `A`, `A = RQ`. Returns `A`, modified in-place, and `tau`, which contains scalars which parameterize the elementary reflectors of the factorization. """ -gerqf!{T<:BlasFloat}(A::StridedMatrix{T}) = ((m,n)=size(A); gerqf!(A,similar(A,T,min(m,n)))) +gerqf!(A::StridedMatrix{<:BlasFloat}) = ((m,n) = size(A); gerqf!(A, similar(A, min(m, n)))) """ geqp3!(A, jpvt) -> (A, jpvt, tau) @@ -719,9 +719,9 @@ greater than or equal to `n` if `A` is an `(m x n)` matrix. Returns `A` and `jpvt`, modified in-place, and `tau`, which stores the elementary reflectors. """ -function geqp3!{T<:BlasFloat}(A::StridedMatrix{T},jpvt::StridedVector{BlasInt}) - m,n = size(A) - geqp3!(A,jpvt,similar(A,T,min(m,n))) +function geqp3!(A::StridedMatrix{<:BlasFloat}, jpvt::StridedVector{BlasInt}) + m, n = size(A) + geqp3!(A, jpvt, similar(A, min(m, n))) end """ @@ -732,9 +732,9 @@ Compute the pivoted `QR` factorization of `A`, `AP = QR` using BLAS level 3. Returns `A`, modified in-place, `jpvt`, which represents the pivoting matrix `P`, and `tau`, which stores the elementary reflectors. """ -function geqp3!{T<:BlasFloat}(A::StridedMatrix{T}) - m,n = size(A) - geqp3!(A,zeros(BlasInt,n),similar(A,T,min(m,n))) +function geqp3!(A::StridedMatrix{<:BlasFloat}) + m, n = size(A) + geqp3!(A, zeros(BlasInt, n), similar(A, min(m, n))) end ## Complete orthogonaliztion tools diff --git a/base/linalg/linalg.jl b/base/linalg/linalg.jl index e42f68cae28be..65d1afea427bc 100644 --- a/base/linalg/linalg.jl +++ b/base/linalg/linalg.jl @@ -237,7 +237,7 @@ function char_uplo(uplo::Symbol) end end -copy_oftype{T,N}(A::AbstractArray{T,N}, ::Type{T}) = copy(A) +copy_oftype{T}(A::AbstractArray{T}, ::Type{T}) = copy(A) copy_oftype{T,N,S}(A::AbstractArray{T,N}, ::Type{S}) = convert(AbstractArray{S,N}, A) include("conjarray.jl") diff --git a/base/linalg/lq.jl b/base/linalg/lq.jl index 8df48e9ddc6ed..74b552459fb8b 100644 --- a/base/linalg/lq.jl +++ b/base/linalg/lq.jl @@ -23,13 +23,13 @@ LQPackedQ(factors::AbstractMatrix{T}, τ::Vector{T}) where {T} = LQPackedQ{T,typ Compute the LQ factorization of `A`, using the input matrix as a workspace. See also [`lq`](@ref). """ -lqfact!{T<:BlasFloat}(A::StridedMatrix{T}) = LQ(LAPACK.gelqf!(A)...) +lqfact!(A::StridedMatrix{<:BlasFloat}) = LQ(LAPACK.gelqf!(A)...) """ lqfact(A) -> LQ Compute the LQ factorization of `A`. See also [`lq`](@ref). """ -lqfact{T<:BlasFloat}(A::StridedMatrix{T}) = lqfact!(copy(A)) +lqfact(A::StridedMatrix{<:BlasFloat}) = lqfact!(copy(A)) lqfact(x::Number) = lqfact(fill(x,1,1)) """ diff --git a/base/linalg/lu.jl b/base/linalg/lu.jl index a53795fdbc1fc..b7fd81e720874 100644 --- a/base/linalg/lu.jl +++ b/base/linalg/lu.jl @@ -208,7 +208,7 @@ function ipiv2perm{T}(v::AbstractVector{T}, maxi::Integer) return p end -function getindex{T,S<:StridedMatrix}(F::LU{T,S}, d::Symbol) +function getindex{T}(F::LU{T,<:StridedMatrix}, d::Symbol) m, n = size(F) if d == :L L = tril!(F.factors[1:m, 1:min(m,n)]) @@ -232,23 +232,23 @@ function show(io::IO, C::LU) show(io, C[:U]) end -A_ldiv_B!{T<:BlasFloat, S<:StridedMatrix}(A::LU{T, S}, B::StridedVecOrMat{T}) = @assertnonsingular LAPACK.getrs!('N', A.factors, A.ipiv, B) A.info -A_ldiv_B!{T,S<:StridedMatrix}(A::LU{T,S}, b::StridedVector) = A_ldiv_B!(UpperTriangular(A.factors), A_ldiv_B!(UnitLowerTriangular(A.factors), b[ipiv2perm(A.ipiv, length(b))])) -A_ldiv_B!{T,S<:StridedMatrix}(A::LU{T,S}, B::StridedMatrix) = A_ldiv_B!(UpperTriangular(A.factors), A_ldiv_B!(UnitLowerTriangular(A.factors), B[ipiv2perm(A.ipiv, size(B, 1)),:])) +A_ldiv_B!{T<:BlasFloat}(A::LU{T,<:StridedMatrix}, B::StridedVecOrMat{T}) = @assertnonsingular LAPACK.getrs!('N', A.factors, A.ipiv, B) A.info +A_ldiv_B!(A::LU{<:Any,<:StridedMatrix}, b::StridedVector) = A_ldiv_B!(UpperTriangular(A.factors), A_ldiv_B!(UnitLowerTriangular(A.factors), b[ipiv2perm(A.ipiv, length(b))])) +A_ldiv_B!(A::LU{<:Any,<:StridedMatrix}, B::StridedMatrix) = A_ldiv_B!(UpperTriangular(A.factors), A_ldiv_B!(UnitLowerTriangular(A.factors), B[ipiv2perm(A.ipiv, size(B, 1)),:])) -At_ldiv_B!{T<:BlasFloat,S<:StridedMatrix}(A::LU{T,S}, B::StridedVecOrMat{T}) = @assertnonsingular LAPACK.getrs!('T', A.factors, A.ipiv, B) A.info -At_ldiv_B!{T,S<:StridedMatrix}(A::LU{T,S}, b::StridedVector) = At_ldiv_B!(UnitLowerTriangular(A.factors), At_ldiv_B!(UpperTriangular(A.factors), b))[invperm(ipiv2perm(A.ipiv, length(b)))] -At_ldiv_B!{T,S<:StridedMatrix}(A::LU{T,S}, B::StridedMatrix) = At_ldiv_B!(UnitLowerTriangular(A.factors), At_ldiv_B!(UpperTriangular(A.factors), B))[invperm(ipiv2perm(A.ipiv, size(B,1))),:] +At_ldiv_B!{T<:BlasFloat}(A::LU{T,<:StridedMatrix}, B::StridedVecOrMat{T}) = @assertnonsingular LAPACK.getrs!('T', A.factors, A.ipiv, B) A.info +At_ldiv_B!(A::LU{<:Any,<:StridedMatrix}, b::StridedVector) = At_ldiv_B!(UnitLowerTriangular(A.factors), At_ldiv_B!(UpperTriangular(A.factors), b))[invperm(ipiv2perm(A.ipiv, length(b)))] +At_ldiv_B!(A::LU{<:Any,<:StridedMatrix}, B::StridedMatrix) = At_ldiv_B!(UnitLowerTriangular(A.factors), At_ldiv_B!(UpperTriangular(A.factors), B))[invperm(ipiv2perm(A.ipiv, size(B,1))),:] -Ac_ldiv_B!{T<:Real,S<:StridedMatrix}(F::LU{T,S}, B::StridedVecOrMat{T}) = At_ldiv_B!(F, B) -Ac_ldiv_B!{T<:BlasComplex,S<:StridedMatrix}(A::LU{T,S}, B::StridedVecOrMat{T}) = @assertnonsingular LAPACK.getrs!('C', A.factors, A.ipiv, B) A.info -Ac_ldiv_B!{T,S<:StridedMatrix}(A::LU{T,S}, b::StridedVector) = Ac_ldiv_B!(UnitLowerTriangular(A.factors), Ac_ldiv_B!(UpperTriangular(A.factors), b))[invperm(ipiv2perm(A.ipiv, length(b)))] -Ac_ldiv_B!{T,S<:StridedMatrix}(A::LU{T,S}, B::StridedMatrix) = Ac_ldiv_B!(UnitLowerTriangular(A.factors), Ac_ldiv_B!(UpperTriangular(A.factors), B))[invperm(ipiv2perm(A.ipiv, size(B,1))),:] +Ac_ldiv_B!{T<:Real}(F::LU{T,<:StridedMatrix}, B::StridedVecOrMat{T}) = At_ldiv_B!(F, B) +Ac_ldiv_B!{T<:BlasComplex}(A::LU{T,<:StridedMatrix}, B::StridedVecOrMat{T}) = @assertnonsingular LAPACK.getrs!('C', A.factors, A.ipiv, B) A.info +Ac_ldiv_B!(A::LU{<:Any,<:StridedMatrix}, b::StridedVector) = Ac_ldiv_B!(UnitLowerTriangular(A.factors), Ac_ldiv_B!(UpperTriangular(A.factors), b))[invperm(ipiv2perm(A.ipiv, length(b)))] +Ac_ldiv_B!(A::LU{<:Any,<:StridedMatrix}, B::StridedMatrix) = Ac_ldiv_B!(UnitLowerTriangular(A.factors), Ac_ldiv_B!(UpperTriangular(A.factors), B))[invperm(ipiv2perm(A.ipiv, size(B,1))),:] -At_ldiv_Bt{T<:BlasFloat,S<:StridedMatrix}(A::LU{T,S}, B::StridedVecOrMat{T}) = @assertnonsingular LAPACK.getrs!('T', A.factors, A.ipiv, transpose(B)) A.info +At_ldiv_Bt{T<:BlasFloat}(A::LU{T,<:StridedMatrix}, B::StridedVecOrMat{T}) = @assertnonsingular LAPACK.getrs!('T', A.factors, A.ipiv, transpose(B)) A.info At_ldiv_Bt(A::LU, B::StridedVecOrMat) = At_ldiv_B(A, transpose(B)) -Ac_ldiv_Bc{T<:BlasComplex,S<:StridedMatrix}(A::LU{T,S}, B::StridedVecOrMat{T}) = @assertnonsingular LAPACK.getrs!('C', A.factors, A.ipiv, ctranspose(B)) A.info +Ac_ldiv_Bc{T<:BlasComplex}(A::LU{T,<:StridedMatrix}, B::StridedVecOrMat{T}) = @assertnonsingular LAPACK.getrs!('C', A.factors, A.ipiv, ctranspose(B)) A.info Ac_ldiv_Bc(A::LU, B::StridedVecOrMat) = Ac_ldiv_B(A, ctranspose(B)) function det{T}(A::LU{T}) @@ -284,10 +284,10 @@ function logabsdet{T}(A::LU{T}) # return log(abs(det)) and sign(det) abs_det, s end -inv!{T<:BlasFloat,S<:StridedMatrix}(A::LU{T,S}) = @assertnonsingular LAPACK.getri!(A.factors, A.ipiv) A.info -inv{T<:BlasFloat,S<:StridedMatrix}(A::LU{T,S}) = inv!(LU(copy(A.factors), copy(A.ipiv), copy(A.info))) +inv!(A::LU{<:BlasFloat,<:StridedMatrix}) = @assertnonsingular LAPACK.getri!(A.factors, A.ipiv) A.info +inv(A::LU{<:BlasFloat,<:StridedMatrix}) = inv!(LU(copy(A.factors), copy(A.ipiv), copy(A.info))) -cond{T<:BlasFloat,S<:StridedMatrix}(A::LU{T,S}, p::Number) = inv(LAPACK.gecon!(p == 1 ? '1' : 'I', A.factors, norm((A[:L]*A[:U])[A[:p],:], p))) +cond(A::LU{<:BlasFloat,<:StridedMatrix}, p::Number) = inv(LAPACK.gecon!(p == 1 ? '1' : 'I', A.factors, norm((A[:L]*A[:U])[A[:p],:], p))) cond(A::LU, p::Number) = norm(A[:L]*A[:U],p)*norm(inv(A),p) # Tridiagonal diff --git a/base/linalg/matmul.jl b/base/linalg/matmul.jl index 00db5728b7031..d688811173245 100644 --- a/base/linalg/matmul.jl +++ b/base/linalg/matmul.jl @@ -219,8 +219,8 @@ end Ac_mul_B!{T<:BlasComplex}(C::StridedMatrix{T}, A::StridedVecOrMat{T}, B::StridedVecOrMat{T}) = A===B ? herk_wrapper!(C,'C',A) : gemm_wrapper!(C,'C', 'N', A, B) Ac_mul_B!(C::AbstractMatrix, A::AbstractVecOrMat, B::AbstractVecOrMat) = generic_matmatmul!(C, 'C', 'N', A, B) -A_mul_Bc{T<:BlasFloat,S<:BlasReal}(A::StridedMatrix{T}, B::StridedMatrix{S}) = A_mul_Bt(A, B) -A_mul_Bc!{T<:BlasFloat,S<:BlasReal}(C::StridedMatrix{T}, A::StridedVecOrMat{T}, B::StridedVecOrMat{S}) = A_mul_Bt!(C, A, B) +A_mul_Bc(A::StridedMatrix{<:BlasFloat}, B::StridedMatrix{<:BlasReal}) = A_mul_Bt(A, B) +A_mul_Bc!{T<:BlasFloat}(C::StridedMatrix{T}, A::StridedVecOrMat{T}, B::StridedVecOrMat{<:BlasReal}) = A_mul_Bt!(C, A, B) function A_mul_Bc{T,S}(A::AbstractMatrix{T}, B::AbstractMatrix{S}) TS = promote_op(matprod, T, S) A_mul_Bc!(similar(B,TS,(size(A,1),size(B,1))),A,B) @@ -376,7 +376,7 @@ end lapack_size(t::Char, M::AbstractVecOrMat) = (size(M, t=='N' ? 1:2), size(M, t=='N' ? 2:1)) -function copy!{R,S}(B::AbstractVecOrMat{R}, ir_dest::UnitRange{Int}, jr_dest::UnitRange{Int}, tM::Char, M::AbstractVecOrMat{S}, ir_src::UnitRange{Int}, jr_src::UnitRange{Int}) +function copy!(B::AbstractVecOrMat, ir_dest::UnitRange{Int}, jr_dest::UnitRange{Int}, tM::Char, M::AbstractVecOrMat, ir_src::UnitRange{Int}, jr_src::UnitRange{Int}) if tM == 'N' copy!(B, ir_dest, jr_dest, M, ir_src, jr_src) else @@ -386,7 +386,7 @@ function copy!{R,S}(B::AbstractVecOrMat{R}, ir_dest::UnitRange{Int}, jr_dest::Un B end -function copy_transpose!{R,S}(B::AbstractMatrix{R}, ir_dest::UnitRange{Int}, jr_dest::UnitRange{Int}, tM::Char, M::AbstractVecOrMat{S}, ir_src::UnitRange{Int}, jr_src::UnitRange{Int}) +function copy_transpose!(B::AbstractMatrix, ir_dest::UnitRange{Int}, jr_dest::UnitRange{Int}, tM::Char, M::AbstractVecOrMat, ir_src::UnitRange{Int}, jr_src::UnitRange{Int}) if tM == 'N' Base.copy_transpose!(B, ir_dest, jr_dest, M, ir_src, jr_src) else @@ -402,7 +402,7 @@ end # NOTE: the generic version is also called as fallback for # strides != 1 cases -function generic_matvecmul!{T,S,R}(C::AbstractVector{R}, tA, A::AbstractVecOrMat{T}, B::AbstractVector{S}) +function generic_matvecmul!{R}(C::AbstractVector{R}, tA, A::AbstractVecOrMat, B::AbstractVector) mB = length(B) mA, nA = lapack_size(tA, A) if mB != nA @@ -471,7 +471,7 @@ const Abuf = Array{UInt8}(tilebufsize) const Bbuf = Array{UInt8}(tilebufsize) const Cbuf = Array{UInt8}(tilebufsize) -function generic_matmatmul!{T,S,R}(C::AbstractMatrix{R}, tA, tB, A::AbstractMatrix{T}, B::AbstractMatrix{S}) +function generic_matmatmul!(C::AbstractMatrix, tA, tB, A::AbstractMatrix, B::AbstractMatrix) mA, nA = lapack_size(tA, A) mB, nB = lapack_size(tB, B) mC, nC = size(C) @@ -485,7 +485,7 @@ function generic_matmatmul!{T,S,R}(C::AbstractMatrix{R}, tA, tB, A::AbstractMatr _generic_matmatmul!(C, tA, tB, A, B) end -generic_matmatmul!{T,S,R}(C::AbstractVecOrMat{R}, tA, tB, A::AbstractVecOrMat{T}, B::AbstractVecOrMat{S}) = _generic_matmatmul!(C, tA, tB, A, B) +generic_matmatmul!(C::AbstractVecOrMat, tA, tB, A::AbstractVecOrMat, B::AbstractVecOrMat) = _generic_matmatmul!(C, tA, tB, A, B) function _generic_matmatmul!{T,S,R}(C::AbstractVecOrMat{R}, tA, tB, A::AbstractVecOrMat{T}, B::AbstractVecOrMat{S}) mA, nA = lapack_size(tA, A) @@ -659,7 +659,7 @@ function matmul2x2{T,S}(tA, tB, A::AbstractMatrix{T}, B::AbstractMatrix{S}) matmul2x2!(similar(B, promote_op(matprod, T, S), 2, 2), tA, tB, A, B) end -function matmul2x2!{T,S,R}(C::AbstractMatrix{R}, tA, tB, A::AbstractMatrix{T}, B::AbstractMatrix{S}) +function matmul2x2!(C::AbstractMatrix, tA, tB, A::AbstractMatrix, B::AbstractMatrix) if !(size(A) == size(B) == size(C) == (2,2)) throw(DimensionMismatch("A has size $(size(A)), B has size $(size(B)), C has size $(size(C))")) end @@ -691,7 +691,7 @@ function matmul3x3{T,S}(tA, tB, A::AbstractMatrix{T}, B::AbstractMatrix{S}) matmul3x3!(similar(B, promote_op(matprod, T, S), 3, 3), tA, tB, A, B) end -function matmul3x3!{T,S,R}(C::AbstractMatrix{R}, tA, tB, A::AbstractMatrix{T}, B::AbstractMatrix{S}) +function matmul3x3!(C::AbstractMatrix, tA, tB, A::AbstractMatrix, B::AbstractMatrix) if !(size(A) == size(B) == size(C) == (3,3)) throw(DimensionMismatch("A has size $(size(A)), B has size $(size(B)), C has size $(size(C))")) end diff --git a/base/linalg/qr.jl b/base/linalg/qr.jl index f4fade51b3680..da9dec1c2b2e7 100644 --- a/base/linalg/qr.jl +++ b/base/linalg/qr.jl @@ -87,9 +87,9 @@ function qrfactPivotedUnblocked!(A::StridedMatrix) end # LAPACK version -qrfact!{T<:BlasFloat}(A::StridedMatrix{T}, ::Type{Val{false}}) = QRCompactWY(LAPACK.geqrt!(A, min(minimum(size(A)), 36))...) -qrfact!{T<:BlasFloat}(A::StridedMatrix{T}, ::Type{Val{true}}) = QRPivoted(LAPACK.geqp3!(A)...) -qrfact!{T<:BlasFloat}(A::StridedMatrix{T}) = qrfact!(A, Val{false}) +qrfact!(A::StridedMatrix{<:BlasFloat}, ::Type{Val{false}}) = QRCompactWY(LAPACK.geqrt!(A, min(minimum(size(A)), 36))...) +qrfact!(A::StridedMatrix{<:BlasFloat}, ::Type{Val{true}}) = QRPivoted(LAPACK.geqp3!(A)...) +qrfact!(A::StridedMatrix{<:BlasFloat}) = qrfact!(A, Val{false}) # Generic fallbacks diff --git a/base/linalg/rowvector.jl b/base/linalg/rowvector.jl index b8d49eabc077b..8930345226847 100644 --- a/base/linalg/rowvector.jl +++ b/base/linalg/rowvector.jl @@ -74,18 +74,18 @@ julia> transpose(v) ``` """ @inline transpose(vec::AbstractVector) = RowVector(vec) -@inline ctranspose{T}(vec::AbstractVector{T}) = RowVector(_conj(vec)) -@inline ctranspose{T<:Real}(vec::AbstractVector{T}) = RowVector(vec) +@inline ctranspose(vec::AbstractVector) = RowVector(_conj(vec)) +@inline ctranspose(vec::AbstractVector{<:Real}) = RowVector(vec) @inline transpose(rowvec::RowVector) = rowvec.vec @inline transpose(rowvec::ConjRowVector) = copy(rowvec.vec) # remove the ConjArray wrapper from any raw vector -@inline ctranspose{T}(rowvec::RowVector{T}) = conj(rowvec.vec) -@inline ctranspose{T<:Real}(rowvec::RowVector{T}) = rowvec.vec +@inline ctranspose(rowvec::RowVector) = conj(rowvec.vec) +@inline ctranspose(rowvec::RowVector{<:Real}) = rowvec.vec parent(rowvec::RowVector) = rowvec.vec """ - conj(rowvector) + conj(v::RowVector) Returns a [`ConjArray`](@ref) lazy view of the input, where each element is conjugated. @@ -102,7 +102,7 @@ julia> conj(v) ``` """ @inline conj(rowvec::RowVector) = RowVector(_conj(rowvec.vec)) -@inline conj{T<:Real}(rowvec::RowVector{T}) = rowvec +@inline conj(rowvec::RowVector{<:Real}) = rowvec # AbstractArray interface @inline length(rowvec::RowVector) = length(rowvec.vec) @@ -111,7 +111,7 @@ julia> conj(v) @inline indices(rowvec::RowVector) = (Base.OneTo(1), indices(rowvec.vec)[1]) @inline indices(rowvec::RowVector, d) = ifelse(d == 2, indices(rowvec.vec)[1], Base.OneTo(1)) linearindexing(::RowVector) = LinearFast() -linearindexing{V<:RowVector}(::Type{V}) = LinearFast() +linearindexing(::Type{<:RowVector}) = LinearFast() @propagate_inbounds getindex(rowvec::RowVector, i) = transpose(rowvec.vec[i]) @propagate_inbounds setindex!(rowvec::RowVector, v, i) = setindex!(rowvec.vec, transpose(v), i) diff --git a/base/linalg/schur.jl b/base/linalg/schur.jl index 5d8a41193f21c..3da3811ced1b1 100644 --- a/base/linalg/schur.jl +++ b/base/linalg/schur.jl @@ -14,7 +14,7 @@ Schur(T::AbstractMatrix{Ty}, Z::AbstractMatrix{Ty}, values::Vector) where Ty = S Same as [`schurfact`](@ref) but uses the input argument as workspace. """ -schurfact!{T<:BlasFloat}(A::StridedMatrix{T}) = Schur(LinAlg.LAPACK.gees!('V', A)...) +schurfact!(A::StridedMatrix{<:BlasFloat}) = Schur(LinAlg.LAPACK.gees!('V', A)...) """ schurfact(A::StridedMatrix) -> F::Schur @@ -43,7 +43,7 @@ julia> F[:vectors] * F[:Schur] * F[:vectors]' -7.0 2.0 7.0 ``` """ -schurfact{T<:BlasFloat}(A::StridedMatrix{T}) = schurfact!(copy(A)) +schurfact(A::StridedMatrix{<:BlasFloat}) = schurfact!(copy(A)) function schurfact{T}(A::StridedMatrix{T}) S = promote_type(Float32, typeof(one(T)/norm(one(T)))) return schurfact!(copy_oftype(A, S)) diff --git a/base/linalg/svd.jl b/base/linalg/svd.jl index 4c4dca7ce6f35..7079a9aa01427 100644 --- a/base/linalg/svd.jl +++ b/base/linalg/svd.jl @@ -131,7 +131,7 @@ Returns the singular values of `A`, saving space by overwriting the input. See also [`svdvals`](@ref). """ svdvals!{T<:BlasFloat}(A::StridedMatrix{T}) = findfirst(size(A), 0) > 0 ? zeros(T, 0) : LAPACK.gesdd!('N', A)[2] -svdvals{T<:BlasFloat}(A::AbstractMatrix{T}) = svdvals!(copy(A)) +svdvals(A::AbstractMatrix{<:BlasFloat}) = svdvals!(copy(A)) """ svdvals(A) @@ -161,11 +161,11 @@ function svdvals{T}(A::AbstractMatrix{T}) svdvals!(copy_oftype(A, S)) end svdvals(x::Number) = abs(x) -svdvals{T, Tr}(S::SVD{T, Tr}) = (S[:S])::Vector{Tr} +svdvals{T}(S::SVD{<:Any,T}) = (S[:S])::Vector{T} # SVD least squares -function A_ldiv_B!{Ta,Tb}(A::SVD{Ta}, B::StridedVecOrMat{Tb}) - k = searchsortedlast(A.S, eps(real(Ta))*A.S[1], rev=true) +function A_ldiv_B!{T}(A::SVD{T}, B::StridedVecOrMat) + k = searchsortedlast(A.S, eps(real(T))*A.S[1], rev=true) view(A.Vt,1:k,:)' * (view(A.S,1:k) .\ (view(A.U,:,1:k)' * B)) end diff --git a/base/linalg/symmetric.jl b/base/linalg/symmetric.jl index 51edfa0e3757a..366d0aab9f10f 100644 --- a/base/linalg/symmetric.jl +++ b/base/linalg/symmetric.jl @@ -160,13 +160,13 @@ function copy!(dest::Hermitian, src::Hermitian) end ishermitian(A::Hermitian) = true -ishermitian{T<:Real,S}(A::Symmetric{T,S}) = true -ishermitian{T<:Complex,S}(A::Symmetric{T,S}) = isreal(A.data) -issymmetric{T<:Real,S}(A::Hermitian{T,S}) = true -issymmetric{T<:Complex,S}(A::Hermitian{T,S}) = isreal(A.data) +ishermitian(A::Symmetric{<:Real}) = true +ishermitian(A::Symmetric{<:Complex}) = isreal(A.data) +issymmetric(A::Hermitian{<:Real}) = true +issymmetric(A::Hermitian{<:Complex}) = isreal(A.data) issymmetric(A::Symmetric) = true transpose(A::Symmetric) = A -ctranspose{T<:Real}(A::Symmetric{T}) = A +ctranspose(A::Symmetric{<:Real}) = A function ctranspose(A::Symmetric) AC = ctranspose(A.data) return Symmetric(AC, ifelse(A.uplo == 'U', :L, :U)) @@ -233,13 +233,13 @@ end -{Tv,S<:AbstractMatrix}(A::Symmetric{Tv,S}) = Symmetric{Tv,S}(-A.data, A.uplo) ## Matvec -A_mul_B!{T<:BlasFloat,S<:StridedMatrix}(y::StridedVector{T}, A::Symmetric{T,S}, x::StridedVector{T}) = BLAS.symv!(A.uplo, one(T), A.data, x, zero(T), y) -A_mul_B!{T<:BlasComplex,S<:StridedMatrix}(y::StridedVector{T}, A::Hermitian{T,S}, x::StridedVector{T}) = BLAS.hemv!(A.uplo, one(T), A.data, x, zero(T), y) +A_mul_B!{T<:BlasFloat}(y::StridedVector{T}, A::Symmetric{T,<:StridedMatrix}, x::StridedVector{T}) = BLAS.symv!(A.uplo, one(T), A.data, x, zero(T), y) +A_mul_B!{T<:BlasComplex}(y::StridedVector{T}, A::Hermitian{T,<:StridedMatrix}, x::StridedVector{T}) = BLAS.hemv!(A.uplo, one(T), A.data, x, zero(T), y) ##Matmat -A_mul_B!{T<:BlasFloat,S<:StridedMatrix}(C::StridedMatrix{T}, A::Symmetric{T,S}, B::StridedMatrix{T}) = BLAS.symm!('L', A.uplo, one(T), A.data, B, zero(T), C) -A_mul_B!{T<:BlasFloat,S<:StridedMatrix}(C::StridedMatrix{T}, A::StridedMatrix{T}, B::Symmetric{T,S}) = BLAS.symm!('R', B.uplo, one(T), B.data, A, zero(T), C) -A_mul_B!{T<:BlasComplex,S<:StridedMatrix}(C::StridedMatrix{T}, A::Hermitian{T,S}, B::StridedMatrix{T}) = BLAS.hemm!('L', A.uplo, one(T), A.data, B, zero(T), C) -A_mul_B!{T<:BlasComplex,S<:StridedMatrix}(C::StridedMatrix{T}, A::StridedMatrix{T}, B::Hermitian{T,S}) = BLAS.hemm!('R', B.uplo, one(T), B.data, A, zero(T), C) +A_mul_B!{T<:BlasFloat}(C::StridedMatrix{T}, A::Symmetric{T,<:StridedMatrix}, B::StridedMatrix{T}) = BLAS.symm!('L', A.uplo, one(T), A.data, B, zero(T), C) +A_mul_B!{T<:BlasFloat}(C::StridedMatrix{T}, A::StridedMatrix{T}, B::Symmetric{T,<:StridedMatrix}) = BLAS.symm!('R', B.uplo, one(T), B.data, A, zero(T), C) +A_mul_B!{T<:BlasComplex}(C::StridedMatrix{T}, A::Hermitian{T,<:StridedMatrix}, B::StridedMatrix{T}) = BLAS.hemm!('L', A.uplo, one(T), A.data, B, zero(T), C) +A_mul_B!{T<:BlasComplex}(C::StridedMatrix{T}, A::StridedMatrix{T}, B::Hermitian{T,<:StridedMatrix}) = BLAS.hemm!('R', B.uplo, one(T), B.data, A, zero(T), C) *(A::HermOrSym, B::HermOrSym) = full(A)*full(B) *(A::StridedMatrix, B::HermOrSym) = A*full(B) @@ -256,19 +256,19 @@ factorize(A::HermOrSym) = bkfact(A) # Is just RealHermSymComplexHerm, but type alias seems to be broken det{T<:Real,S}(A::Union{Hermitian{T,S}, Symmetric{T,S}, Hermitian{Complex{T},S}}) = real(det(bkfact(A))) -det{T<:Real}(A::Symmetric{T}) = det(bkfact(A)) +det(A::Symmetric{<:Real}) = det(bkfact(A)) det(A::Symmetric) = det(bkfact(A)) -\{T,S<:StridedMatrix}(A::HermOrSym{T,S}, B::StridedVecOrMat) = \(bkfact(A.data, Symbol(A.uplo), issymmetric(A)), B) +\(A::HermOrSym{<:Any,<:StridedMatrix}, B::StridedVecOrMat) = \(bkfact(A.data, Symbol(A.uplo), issymmetric(A)), B) inv{T<:BlasFloat,S<:StridedMatrix}(A::Hermitian{T,S}) = Hermitian{T,S}(inv(bkfact(A.data, Symbol(A.uplo))), A.uplo) inv{T<:BlasFloat,S<:StridedMatrix}(A::Symmetric{T,S}) = Symmetric{T,S}(inv(bkfact(A.data, Symbol(A.uplo), true)), A.uplo) -eigfact!{T<:BlasReal,S<:StridedMatrix}(A::RealHermSymComplexHerm{T,S}) = Eigen(LAPACK.syevr!('V', 'A', A.uplo, A.data, 0.0, 0.0, 0, 0, -1.0)...) +eigfact!(A::RealHermSymComplexHerm{<:BlasReal,<:StridedMatrix}) = Eigen(LAPACK.syevr!('V', 'A', A.uplo, A.data, 0.0, 0.0, 0, 0, -1.0)...) # Because of #6721 it is necessary to specify the parameters explicitly here. -eigfact{T1<:Real,T2}(A::RealHermSymComplexHerm{T1,T2}) = (T = eltype(A); S = promote_type(Float32, typeof(zero(T)/norm(one(T)))); eigfact!(S != T ? convert(AbstractMatrix{S}, A) : copy(A))) +eigfact(A::RealHermSymComplexHerm{<:Real}) = (T = eltype(A); S = promote_type(Float32, typeof(zero(T)/norm(one(T)))); eigfact!(S != T ? convert(AbstractMatrix{S}, A) : copy(A))) -eigfact!{T<:BlasReal,S<:StridedMatrix}(A::RealHermSymComplexHerm{T,S}, irange::UnitRange) = Eigen(LAPACK.syevr!('V', 'I', A.uplo, A.data, 0.0, 0.0, irange.start, irange.stop, -1.0)...) +eigfact!(A::RealHermSymComplexHerm{<:BlasReal,<:StridedMatrix}, irange::UnitRange) = Eigen(LAPACK.syevr!('V', 'I', A.uplo, A.data, 0.0, 0.0, irange.start, irange.stop, -1.0)...) # Because of #6721 it is necessary to specify the parameters explicitly here. """ @@ -286,9 +286,9 @@ The `UnitRange` `irange` specifies indices of the sorted eigenvalues to search f If `irange` is not `1:n`, where `n` is the dimension of `A`, then the returned factorization will be a *truncated* factorization. """ -eigfact{T1<:Real,T2}(A::RealHermSymComplexHerm{T1,T2}, irange::UnitRange) = (T = eltype(A); S = promote_type(Float32, typeof(zero(T)/norm(one(T)))); eigfact!(S != T ? convert(AbstractMatrix{S}, A) : copy(A), irange)) +eigfact(A::RealHermSymComplexHerm{<:Real}, irange::UnitRange) = (T = eltype(A); S = promote_type(Float32, typeof(zero(T)/norm(one(T)))); eigfact!(S != T ? convert(AbstractMatrix{S}, A) : copy(A), irange)) -eigfact!{T<:BlasReal,S<:StridedMatrix}(A::RealHermSymComplexHerm{T,S}, vl::Real, vh::Real) = Eigen(LAPACK.syevr!('V', 'V', A.uplo, A.data, convert(T, vl), convert(T, vh), 0, 0, -1.0)...) +eigfact!{T<:BlasReal}(A::RealHermSymComplexHerm{T,<:StridedMatrix}, vl::Real, vh::Real) = Eigen(LAPACK.syevr!('V', 'V', A.uplo, A.data, convert(T, vl), convert(T, vh), 0, 0, -1.0)...) # Because of #6721 it is necessary to specify the parameters explicitly here. """ eigfact(A::Union{SymTridiagonal, Hermitian, Symmetric}, vl::Real, vu::Real) -> Eigen @@ -305,11 +305,11 @@ The following functions are available for `Eigen` objects: [`inv`](@ref), [`det` If [`vl`, `vu`] does not contain all eigenvalues of `A`, then the returned factorization will be a *truncated* factorization. """ -eigfact{T1<:Real,T2}(A::RealHermSymComplexHerm{T1,T2}, vl::Real, vh::Real) = (T = eltype(A); S = promote_type(Float32, typeof(zero(T)/norm(one(T)))); eigfact!(S != T ? convert(AbstractMatrix{S}, A) : copy(A), vl, vh)) +eigfact(A::RealHermSymComplexHerm{<:Real}, vl::Real, vh::Real) = (T = eltype(A); S = promote_type(Float32, typeof(zero(T)/norm(one(T)))); eigfact!(S != T ? convert(AbstractMatrix{S}, A) : copy(A), vl, vh)) -eigvals!{T<:BlasReal,S<:StridedMatrix}(A::RealHermSymComplexHerm{T,S}) = LAPACK.syevr!('N', 'A', A.uplo, A.data, 0.0, 0.0, 0, 0, -1.0)[1] +eigvals!(A::RealHermSymComplexHerm{<:BlasReal,<:StridedMatrix}) = LAPACK.syevr!('N', 'A', A.uplo, A.data, 0.0, 0.0, 0, 0, -1.0)[1] # Because of #6721 it is necessary to specify the parameters explicitly here. -eigvals{T1<:Real,T2}(A::RealHermSymComplexHerm{T1,T2}) = (T = eltype(A); S = promote_type(Float32, typeof(zero(T)/norm(one(T)))); eigvals!(S != T ? convert(AbstractMatrix{S}, A) : copy(A))) +eigvals(A::RealHermSymComplexHerm{<:Real}) = (T = eltype(A); S = promote_type(Float32, typeof(zero(T)/norm(one(T)))); eigvals!(S != T ? convert(AbstractMatrix{S}, A) : copy(A))) """ eigvals!(A::Union{SymTridiagonal, Hermitian, Symmetric}, irange::UnitRange) -> values @@ -317,7 +317,7 @@ eigvals{T1<:Real,T2}(A::RealHermSymComplexHerm{T1,T2}) = (T = eltype(A); S = pro Same as [`eigvals`](@ref), but saves space by overwriting the input `A`, instead of creating a copy. `irange` is a range of eigenvalue *indices* to search for - for instance, the 2nd to 8th eigenvalues. """ -eigvals!{T<:BlasReal,S<:StridedMatrix}(A::RealHermSymComplexHerm{T,S}, irange::UnitRange) = LAPACK.syevr!('N', 'I', A.uplo, A.data, 0.0, 0.0, irange.start, irange.stop, -1.0)[1] +eigvals!(A::RealHermSymComplexHerm{<:BlasReal,<:StridedMatrix}, irange::UnitRange) = LAPACK.syevr!('N', 'I', A.uplo, A.data, 0.0, 0.0, irange.start, irange.stop, -1.0)[1] # Because of #6721 it is necessary to specify the parameters explicitly here. """ eigvals(A::Union{SymTridiagonal, Hermitian, Symmetric}, irange::UnitRange) -> values @@ -344,7 +344,7 @@ julia> eigvals(A) 5.14005 ``` """ -eigvals{T1<:Real,T2}(A::RealHermSymComplexHerm{T1,T2}, irange::UnitRange) = (T = eltype(A); S = promote_type(Float32, typeof(zero(T)/norm(one(T)))); eigvals!(S != T ? convert(AbstractMatrix{S}, A) : copy(A), irange)) +eigvals(A::RealHermSymComplexHerm{<:Real}, irange::UnitRange) = (T = eltype(A); S = promote_type(Float32, typeof(zero(T)/norm(one(T)))); eigvals!(S != T ? convert(AbstractMatrix{S}, A) : copy(A), irange)) """ eigvals!(A::Union{SymTridiagonal, Hermitian, Symmetric}, vl::Real, vu::Real) -> values @@ -352,7 +352,7 @@ eigvals{T1<:Real,T2}(A::RealHermSymComplexHerm{T1,T2}, irange::UnitRange) = (T = Same as [`eigvals`](@ref), but saves space by overwriting the input `A`, instead of creating a copy. `vl` is the lower bound of the interval to search for eigenvalues, and `vu` is the upper bound. """ -eigvals!{T<:BlasReal,S<:StridedMatrix}(A::RealHermSymComplexHerm{T,S}, vl::Real, vh::Real) = LAPACK.syevr!('N', 'V', A.uplo, A.data, convert(T, vl), convert(T, vh), 0, 0, -1.0)[1] +eigvals!{T<:BlasReal}(A::RealHermSymComplexHerm{T,<:StridedMatrix}, vl::Real, vh::Real) = LAPACK.syevr!('N', 'V', A.uplo, A.data, convert(T, vl), convert(T, vh), 0, 0, -1.0)[1] # Because of #6721 it is necessary to specify the parameters explicitly here. """ eigvals(A::Union{SymTridiagonal, Hermitian, Symmetric}, vl::Real, vu::Real) -> values @@ -378,10 +378,10 @@ julia> eigvals(A) 5.14005 ``` """ -eigvals{T1<:Real,T2}(A::RealHermSymComplexHerm{T1,T2}, vl::Real, vh::Real) = (T = eltype(A); S = promote_type(Float32, typeof(zero(T)/norm(one(T)))); eigvals!(S != T ? convert(AbstractMatrix{S}, A) : copy(A), vl, vh)) +eigvals(A::RealHermSymComplexHerm{<:Real}, vl::Real, vh::Real) = (T = eltype(A); S = promote_type(Float32, typeof(zero(T)/norm(one(T)))); eigvals!(S != T ? convert(AbstractMatrix{S}, A) : copy(A), vl, vh)) -eigmax{T<:Real,S<:StridedMatrix}(A::RealHermSymComplexHerm{T,S}) = eigvals(A, size(A, 1):size(A, 1))[1] -eigmin{T<:Real,S<:StridedMatrix}(A::RealHermSymComplexHerm{T,S}) = eigvals(A, 1:1)[1] +eigmax(A::RealHermSymComplexHerm{<:Real,<:StridedMatrix}) = eigvals(A, size(A, 1):size(A, 1))[1] +eigmin(A::RealHermSymComplexHerm{<:Real,<:StridedMatrix}) = eigvals(A, 1:1)[1] function eigfact!{T<:BlasReal,S<:StridedMatrix}(A::HermOrSym{T,S}, B::HermOrSym{T,S}) vals, vecs, _ = LAPACK.sygvd!(1, 'V', A.uplo, A.data, B.uplo == A.uplo ? B.data : B.data') diff --git a/base/linalg/transpose.jl b/base/linalg/transpose.jl index 7210c3198dc45..7fd95efddeb39 100644 --- a/base/linalg/transpose.jl +++ b/base/linalg/transpose.jl @@ -126,10 +126,10 @@ function ctranspose(A::AbstractMatrix) ctranspose!(B, A) end -@inline ctranspose{T<:Real}(A::AbstractVecOrMat{T}) = transpose(A) +@inline ctranspose(A::AbstractVecOrMat{<:Real}) = transpose(A) -function copy_transpose!{R,S}(B::AbstractVecOrMat{R}, ir_dest::Range{Int}, jr_dest::Range{Int}, - A::AbstractVecOrMat{S}, ir_src::Range{Int}, jr_src::Range{Int}) +function copy_transpose!(B::AbstractVecOrMat, ir_dest::Range{Int}, jr_dest::Range{Int}, + A::AbstractVecOrMat, ir_src::Range{Int}, jr_src::Range{Int}) if length(ir_dest) != length(jr_src) throw(ArgumentError(string("source and destination must have same size (got ", length(jr_src)," and ",length(ir_dest),")"))) diff --git a/base/linalg/triangular.jl b/base/linalg/triangular.jl index 10446edbe908a..368887c2655df 100644 --- a/base/linalg/triangular.jl +++ b/base/linalg/triangular.jl @@ -21,17 +21,17 @@ for t in (:LowerTriangular, :UnitLowerTriangular, :UpperTriangular, size(A::$t, d) = size(A.data, d) size(A::$t) = size(A.data) - convert{T,S}(::Type{$t{T}}, A::$t{T,S}) = A - function convert{Tnew,Told,S}(::Type{$t{Tnew}}, A::$t{Told,S}) - Anew = convert(AbstractMatrix{Tnew}, A.data) + convert{T}(::Type{$t{T}}, A::$t{T}) = A + function convert{T}(::Type{$t{T}}, A::$t) + Anew = convert(AbstractMatrix{T}, A.data) $t(Anew) end - convert{Tnew }(::Type{AbstractMatrix{Tnew}}, A::$t{Tnew}) = A - convert{Tnew,Told}(::Type{AbstractMatrix{Tnew}}, A::$t{Told}) = convert($t{Tnew}, A) - convert{T,S}(::Type{Matrix}, A::$t{T,S}) = convert(Matrix{T}, A) + convert{T}(::Type{AbstractMatrix{T}}, A::$t{T}) = A + convert{T}(::Type{AbstractMatrix{T}}, A::$t) = convert($t{T}, A) + convert{T}(::Type{Matrix}, A::$t{T}) = convert(Matrix{T}, A) - function similar{T,S,Tnew}(A::$t{T,S}, ::Type{Tnew}) - B = similar(A.data, Tnew) + function similar{T}(A::$t, ::Type{T}) + B = similar(A.data, T) return $t(B) end @@ -39,8 +39,8 @@ for t in (:LowerTriangular, :UnitLowerTriangular, :UpperTriangular, broadcast(::typeof(big), A::$t) = $t(big.(A.data)) - real{T<:Real}(A::$t{T}) = A - real{T<:Complex}(A::$t{T}) = (B = real(A.data); $t(B)) + real(A::$t{<:Real}) = A + real(A::$t{<:Complex}) = (B = real(A.data); $t(B)) broadcast(::typeof(abs), A::$t) = $t(abs.(A.data)) end end @@ -61,14 +61,14 @@ parent(A::AbstractTriangular) = A.data # then handle all methods that requires specific handling of upper/lower and unit diagonal -function convert{Tret,T,S}(::Type{Matrix{Tret}}, A::LowerTriangular{T,S}) - B = Array{Tret}(size(A, 1), size(A, 1)) +function convert{T}(::Type{Matrix{T}}, A::LowerTriangular) + B = Array{T}(size(A, 1), size(A, 1)) copy!(B, A.data) tril!(B) B end -function convert{Tret,T,S}(::Type{Matrix{Tret}}, A::UnitLowerTriangular{T,S}) - B = Array{Tret}(size(A, 1), size(A, 1)) +function convert{T}(::Type{Matrix{T}}, A::UnitLowerTriangular) + B = Array{T}(size(A, 1), size(A, 1)) copy!(B, A.data) tril!(B) for i = 1:size(B,1) @@ -76,14 +76,14 @@ function convert{Tret,T,S}(::Type{Matrix{Tret}}, A::UnitLowerTriangular{T,S}) end B end -function convert{Tret,T,S}(::Type{Matrix{Tret}}, A::UpperTriangular{T,S}) - B = Array{Tret}(size(A, 1), size(A, 1)) +function convert{T}(::Type{Matrix{T}}, A::UpperTriangular) + B = Array{T}(size(A, 1), size(A, 1)) copy!(B, A.data) triu!(B) B end -function convert{Tret,T,S}(::Type{Matrix{Tret}}, A::UnitUpperTriangular{T,S}) - B = Array{Tret}(size(A, 1), size(A, 1)) +function convert{T}(::Type{Matrix{T}}, A::UnitUpperTriangular) + B = Array{T}(size(A, 1), size(A, 1)) copy!(B, A.data) triu!(B) for i = 1:size(B,1) @@ -92,12 +92,12 @@ function convert{Tret,T,S}(::Type{Matrix{Tret}}, A::UnitUpperTriangular{T,S}) B end -function full!{T,S}(A::LowerTriangular{T,S}) +function full!(A::LowerTriangular) B = A.data tril!(B) B end -function full!{T,S}(A::UnitLowerTriangular{T,S}) +function full!(A::UnitLowerTriangular) B = A.data tril!(B) for i = 1:size(A,1) @@ -105,12 +105,12 @@ function full!{T,S}(A::UnitLowerTriangular{T,S}) end B end -function full!{T,S}(A::UpperTriangular{T,S}) +function full!(A::UpperTriangular) B = A.data triu!(B) B end -function full!{T,S}(A::UnitUpperTriangular{T,S}) +function full!(A::UnitUpperTriangular) B = A.data triu!(B) for i = 1:size(A,1) @@ -119,13 +119,13 @@ function full!{T,S}(A::UnitUpperTriangular{T,S}) B end -getindex{T,S}(A::UnitLowerTriangular{T,S}, i::Integer, j::Integer) = +getindex{T}(A::UnitLowerTriangular{T}, i::Integer, j::Integer) = i > j ? A.data[i,j] : ifelse(i == j, oneunit(T), zero(T)) -getindex{T,S}(A::LowerTriangular{T,S}, i::Integer, j::Integer) = +getindex(A::LowerTriangular, i::Integer, j::Integer) = i >= j ? A.data[i,j] : zero(A.data[j,i]) -getindex{T,S}(A::UnitUpperTriangular{T,S}, i::Integer, j::Integer) = +getindex{T}(A::UnitUpperTriangular{T}, i::Integer, j::Integer) = i < j ? A.data[i,j] : ifelse(i == j, oneunit(T), zero(T)) -getindex{T,S}(A::UpperTriangular{T,S}, i::Integer, j::Integer) = +getindex(A::UpperTriangular, i::Integer, j::Integer) = i <= j ? A.data[i,j] : zero(A.data[j,i]) function setindex!(A::UpperTriangular, x, i::Integer, j::Integer) @@ -343,7 +343,7 @@ function copy!{T<:Union{LowerTriangular, UnitLowerTriangular}}(A::T, B::T) return A end -function scale!{T<:Union{UpperTriangular, UnitUpperTriangular}}(A::UpperTriangular, B::T, c::Number) +function scale!(A::UpperTriangular, B::Union{UpperTriangular, UnitUpperTriangular}, c::Number) n = checksquare(B) for j = 1:n if isa(B, UnitUpperTriangular) @@ -355,7 +355,7 @@ function scale!{T<:Union{UpperTriangular, UnitUpperTriangular}}(A::UpperTriangul end return A end -function scale!{T<:Union{LowerTriangular, UnitLowerTriangular}}(A::LowerTriangular, B::T, c::Number) +function scale!(A::LowerTriangular, B::Union{LowerTriangular, UnitLowerTriangular}, c::Number) n = checksquare(B) for j = 1:n if isa(B, UnitLowerTriangular) @@ -411,53 +411,53 @@ for (t, uploc, isunitc) in ((:LowerTriangular, 'L', 'N'), (:UnitUpperTriangular, 'U', 'U')) @eval begin # Vector multiplication - A_mul_B!{T<:BlasFloat,S<:StridedMatrix}(A::$t{T,S}, b::StridedVector{T}) = + A_mul_B!{T<:BlasFloat}(A::$t{T,<:StridedMatrix}, b::StridedVector{T}) = BLAS.trmv!($uploc, 'N', $isunitc, A.data, b) - At_mul_B!{T<:BlasFloat,S<:StridedMatrix}(A::$t{T,S}, b::StridedVector{T}) = + At_mul_B!{T<:BlasFloat}(A::$t{T,<:StridedMatrix}, b::StridedVector{T}) = BLAS.trmv!($uploc, 'T', $isunitc, A.data, b) - Ac_mul_B!{T<:BlasReal,S<:StridedMatrix}(A::$t{T,S}, b::StridedVector{T}) = + Ac_mul_B!{T<:BlasReal}(A::$t{T,<:StridedMatrix}, b::StridedVector{T}) = BLAS.trmv!($uploc, 'T', $isunitc, A.data, b) - Ac_mul_B!{T<:BlasComplex,S<:StridedMatrix}(A::$t{T,S}, b::StridedVector{T}) = + Ac_mul_B!{T<:BlasComplex}(A::$t{T,<:StridedMatrix}, b::StridedVector{T}) = BLAS.trmv!($uploc, 'C', $isunitc, A.data, b) # Matrix multiplication - A_mul_B!{T<:BlasFloat,S<:StridedMatrix}(A::$t{T,S}, B::StridedMatrix{T}) = + A_mul_B!{T<:BlasFloat}(A::$t{T,<:StridedMatrix}, B::StridedMatrix{T}) = BLAS.trmm!('L', $uploc, 'N', $isunitc, one(T), A.data, B) - A_mul_B!{T<:BlasFloat,S<:StridedMatrix}(A::StridedMatrix{T}, B::$t{T,S}) = + A_mul_B!{T<:BlasFloat}(A::StridedMatrix{T}, B::$t{T,<:StridedMatrix}) = BLAS.trmm!('R', $uploc, 'N', $isunitc, one(T), B.data, A) - At_mul_B!{T<:BlasFloat,S<:StridedMatrix}(A::$t{T,S}, B::StridedMatrix{T}) = + At_mul_B!{T<:BlasFloat}(A::$t{T,<:StridedMatrix}, B::StridedMatrix{T}) = BLAS.trmm!('L', $uploc, 'T', $isunitc, one(T), A.data, B) - Ac_mul_B!{T<:BlasComplex,S<:StridedMatrix}(A::$t{T,S}, B::StridedMatrix{T}) = + Ac_mul_B!{T<:BlasComplex}(A::$t{T,<:StridedMatrix}, B::StridedMatrix{T}) = BLAS.trmm!('L', $uploc, 'C', $isunitc, one(T), A.data, B) - Ac_mul_B!{T<:BlasReal,S<:StridedMatrix}(A::$t{T,S}, B::StridedMatrix{T}) = + Ac_mul_B!{T<:BlasReal}(A::$t{T,<:StridedMatrix}, B::StridedMatrix{T}) = BLAS.trmm!('L', $uploc, 'T', $isunitc, one(T), A.data, B) - A_mul_Bt!{T<:BlasFloat,S<:StridedMatrix}(A::StridedMatrix{T}, B::$t{T,S}) = + A_mul_Bt!{T<:BlasFloat}(A::StridedMatrix{T}, B::$t{T,<:StridedMatrix}) = BLAS.trmm!('R', $uploc, 'T', $isunitc, one(T), B.data, A) - A_mul_Bc!{T<:BlasComplex,S<:StridedMatrix}(A::StridedMatrix{T}, B::$t{T,S}) = + A_mul_Bc!{T<:BlasComplex}(A::StridedMatrix{T}, B::$t{T,<:StridedMatrix}) = BLAS.trmm!('R', $uploc, 'C', $isunitc, one(T), B.data, A) - A_mul_Bc!{T<:BlasReal,S<:StridedMatrix}(A::StridedMatrix{T}, B::$t{T,S}) = + A_mul_Bc!{T<:BlasReal}(A::StridedMatrix{T}, B::$t{T,<:StridedMatrix}) = BLAS.trmm!('R', $uploc, 'T', $isunitc, one(T), B.data, A) # Left division - A_ldiv_B!{T<:BlasFloat,S<:StridedMatrix}(A::$t{T,S}, B::StridedVecOrMat{T}) = + A_ldiv_B!{T<:BlasFloat}(A::$t{T,<:StridedMatrix}, B::StridedVecOrMat{T}) = LAPACK.trtrs!($uploc, 'N', $isunitc, A.data, B) - At_ldiv_B!{T<:BlasFloat,S<:StridedMatrix}(A::$t{T,S}, B::StridedVecOrMat{T}) = + At_ldiv_B!{T<:BlasFloat}(A::$t{T,<:StridedMatrix}, B::StridedVecOrMat{T}) = LAPACK.trtrs!($uploc, 'T', $isunitc, A.data, B) - Ac_ldiv_B!{T<:BlasReal,S<:StridedMatrix}(A::$t{T,S}, B::StridedVecOrMat{T}) = + Ac_ldiv_B!{T<:BlasReal}(A::$t{T,<:StridedMatrix}, B::StridedVecOrMat{T}) = LAPACK.trtrs!($uploc, 'T', $isunitc, A.data, B) - Ac_ldiv_B!{T<:BlasComplex,S<:StridedMatrix}(A::$t{T,S}, B::StridedVecOrMat{T}) = + Ac_ldiv_B!{T<:BlasComplex}(A::$t{T,<:StridedMatrix}, B::StridedVecOrMat{T}) = LAPACK.trtrs!($uploc, 'C', $isunitc, A.data, B) # Right division - A_rdiv_B!{T<:BlasFloat,S<:StridedMatrix}(A::StridedMatrix{T}, B::$t{T,S}) = + A_rdiv_B!{T<:BlasFloat}(A::StridedMatrix{T}, B::$t{T,<:StridedMatrix}) = BLAS.trsm!('R', $uploc, 'N', $isunitc, one(T), B.data, A) - A_rdiv_Bt!{T<:BlasFloat,S<:StridedMatrix}(A::StridedMatrix{T}, B::$t{T,S}) = + A_rdiv_Bt!{T<:BlasFloat}(A::StridedMatrix{T}, B::$t{T,<:StridedMatrix}) = BLAS.trsm!('R', $uploc, 'T', $isunitc, one(T), B.data, A) - A_rdiv_Bc!{T<:BlasReal,S<:StridedMatrix}(A::StridedMatrix{T}, B::$t{T,S}) = + A_rdiv_Bc!{T<:BlasReal}(A::StridedMatrix{T}, B::$t{T,<:StridedMatrix}) = BLAS.trsm!('R', $uploc, 'T', $isunitc, one(T), B.data, A) - A_rdiv_Bc!{T<:BlasComplex,S<:StridedMatrix}(A::StridedMatrix{T}, B::$t{T,S}) = + A_rdiv_Bc!{T<:BlasComplex}(A::StridedMatrix{T}, B::$t{T,<:StridedMatrix}) = BLAS.trsm!('R', $uploc, 'C', $isunitc, one(T), B.data, A) # Matrix inverse @@ -465,11 +465,11 @@ for (t, uploc, isunitc) in ((:LowerTriangular, 'L', 'N'), $t{T,S}(LAPACK.trtri!($uploc, $isunitc, A.data)) # Error bounds for triangular solve - errorbounds{T<:BlasFloat,S<:StridedMatrix}(A::$t{T,S}, X::StridedVecOrMat{T}, B::StridedVecOrMat{T}) = + errorbounds{T<:BlasFloat}(A::$t{T,<:StridedMatrix}, X::StridedVecOrMat{T}, B::StridedVecOrMat{T}) = LAPACK.trrfs!($uploc, 'N', $isunitc, A.data, B, X) # Condition numbers - function cond{T<:BlasFloat,S}(A::$t{T,S}, p::Real=2) + function cond(A::$t{<:BlasFloat}, p::Real=2) checksquare(A) if p == 1 return inv(LAPACK.trcon!('O', $uploc, $isunitc, A.data)) @@ -493,28 +493,28 @@ end inv{T}(A::UnitUpperTriangular{T}) = UnitUpperTriangular(A_ldiv_B!(A, eye(T, size(A, 1)))) inv{T}(A::UnitLowerTriangular{T}) = UnitLowerTriangular(A_ldiv_B!(A, eye(T, size(A, 1)))) -errorbounds{T<:Union{BigFloat, Complex{BigFloat}},S<:StridedMatrix}(A::AbstractTriangular{T,S}, X::StridedVecOrMat{T}, B::StridedVecOrMat{T}) = +errorbounds{T<:Union{BigFloat, Complex{BigFloat}}}(A::AbstractTriangular{T,<:StridedMatrix}, X::StridedVecOrMat{T}, B::StridedVecOrMat{T}) = error("not implemented yet! Please submit a pull request.") -function errorbounds{TA<:Number,S<:StridedMatrix,TX<:Number,TB<:Number}(A::AbstractTriangular{TA,S}, X::StridedVecOrMat{TX}, B::StridedVecOrMat{TB}) +function errorbounds{TA<:Number,TX<:Number,TB<:Number}(A::AbstractTriangular{TA,<:StridedMatrix}, X::StridedVecOrMat{TX}, B::StridedVecOrMat{TB}) TAXB = promote_type(TA, TB, TX, Float32) errorbounds(convert(AbstractMatrix{TAXB}, A), convert(AbstractArray{TAXB}, X), convert(AbstractArray{TAXB}, B)) end # Eigensystems ## Notice that trecv works for quasi-triangular matrices and therefore the lower sub diagonal must be zeroed before calling the subroutine -function eigvecs{T<:BlasFloat,S<:StridedMatrix}(A::UpperTriangular{T,S}) +function eigvecs(A::UpperTriangular{<:BlasFloat,<:StridedMatrix}) LAPACK.trevc!('R', 'A', BlasInt[], triu!(A.data)) end -function eigvecs{T<:BlasFloat,S<:StridedMatrix}(A::UnitUpperTriangular{T,S}) +function eigvecs(A::UnitUpperTriangular{<:BlasFloat,<:StridedMatrix}) for i = 1:size(A, 1) A.data[i,i] = 1 end LAPACK.trevc!('R', 'A', BlasInt[], triu!(A.data)) end -function eigvecs{T<:BlasFloat,S<:StridedMatrix}(A::LowerTriangular{T,S}) +function eigvecs(A::LowerTriangular{<:BlasFloat,<:StridedMatrix}) LAPACK.trevc!('L', 'A', BlasInt[], tril!(A.data)') end -function eigvecs{T<:BlasFloat,S<:StridedMatrix}(A::UnitLowerTriangular{T,S}) +function eigvecs(A::UnitLowerTriangular{<:BlasFloat,<:StridedMatrix}) for i = 1:size(A, 1) A.data[i,i] = 1 end @@ -1922,8 +1922,8 @@ logdet{T}(A::UnitUpperTriangular{T}) = zero(T) logdet{T}(A::UnitLowerTriangular{T}) = zero(T) logabsdet{T}(A::UnitUpperTriangular{T}) = zero(T), one(T) logabsdet{T}(A::UnitLowerTriangular{T}) = zero(T), one(T) -det{T}(A::UpperTriangular{T}) = prod(diag(A.data)) -det{T}(A::LowerTriangular{T}) = prod(diag(A.data)) +det(A::UpperTriangular) = prod(diag(A.data)) +det(A::LowerTriangular) = prod(diag(A.data)) function logabsdet{T}(A::Union{UpperTriangular{T},LowerTriangular{T}}) sgn = one(T) abs_det = zero(real(T)) diff --git a/base/linalg/tridiag.jl b/base/linalg/tridiag.jl index bb00136bc8cb2..59db27ee7399b 100644 --- a/base/linalg/tridiag.jl +++ b/base/linalg/tridiag.jl @@ -162,40 +162,40 @@ end (\)(T::SymTridiagonal, B::StridedVecOrMat) = ldltfact(T)\B -eigfact!{T<:BlasReal}(A::SymTridiagonal{T}) = Eigen(LAPACK.stegr!('V', A.dv, A.ev)...) +eigfact!(A::SymTridiagonal{<:BlasReal}) = Eigen(LAPACK.stegr!('V', A.dv, A.ev)...) function eigfact{T}(A::SymTridiagonal{T}) S = promote_type(Float32, typeof(zero(T)/norm(one(T)))) eigfact!(copy_oftype(A, S)) end -eigfact!{T<:BlasReal}(A::SymTridiagonal{T}, irange::UnitRange) = +eigfact!(A::SymTridiagonal{<:BlasReal}, irange::UnitRange) = Eigen(LAPACK.stegr!('V', 'I', A.dv, A.ev, 0.0, 0.0, irange.start, irange.stop)...) function eigfact{T}(A::SymTridiagonal{T}, irange::UnitRange) S = promote_type(Float32, typeof(zero(T)/norm(one(T)))) return eigfact!(copy_oftype(A, S), irange) end -eigfact!{T<:BlasReal}(A::SymTridiagonal{T}, vl::Real, vu::Real) = +eigfact!(A::SymTridiagonal{<:BlasReal}, vl::Real, vu::Real) = Eigen(LAPACK.stegr!('V', 'V', A.dv, A.ev, vl, vu, 0, 0)...) function eigfact{T}(A::SymTridiagonal{T}, vl::Real, vu::Real) S = promote_type(Float32, typeof(zero(T)/norm(one(T)))) return eigfact!(copy_oftype(A, S), vl, vu) end -eigvals!{T<:BlasReal}(A::SymTridiagonal{T}) = LAPACK.stev!('N', A.dv, A.ev)[1] +eigvals!(A::SymTridiagonal{<:BlasReal}) = LAPACK.stev!('N', A.dv, A.ev)[1] function eigvals{T}(A::SymTridiagonal{T}) S = promote_type(Float32, typeof(zero(T)/norm(one(T)))) return eigvals!(copy_oftype(A, S)) end -eigvals!{T<:BlasReal}(A::SymTridiagonal{T}, irange::UnitRange) = +eigvals!(A::SymTridiagonal{<:BlasReal}, irange::UnitRange) = LAPACK.stegr!('N', 'I', A.dv, A.ev, 0.0, 0.0, irange.start, irange.stop)[1] function eigvals{T}(A::SymTridiagonal{T}, irange::UnitRange) S = promote_type(Float32, typeof(zero(T)/norm(one(T)))) return eigvals!(copy_oftype(A, S), irange) end -eigvals!{T<:BlasReal}(A::SymTridiagonal{T}, vl::Real, vu::Real) = +eigvals!(A::SymTridiagonal{<:BlasReal}, vl::Real, vu::Real) = LAPACK.stegr!('N', 'V', A.dv, A.ev, vl, vu, 0, 0)[1] function eigvals{T}(A::SymTridiagonal{T}, vl::Real, vu::Real) S = promote_type(Float32, typeof(zero(T)/norm(one(T)))) @@ -246,7 +246,7 @@ julia> eigvecs(A, [1.]) -0.5547 ``` """ -eigvecs{T<:BlasFloat,Eigenvalue<:Real}(A::SymTridiagonal{T}, eigvals::Vector{Eigenvalue}) = LAPACK.stein!(A.dv, A.ev, eigvals) +eigvecs(A::SymTridiagonal{<:BlasFloat}, eigvals::Vector{<:Real}) = LAPACK.stein!(A.dv, A.ev, eigvals) #tril and triu diff --git a/base/linalg/uniformscaling.jl b/base/linalg/uniformscaling.jl index bad9ddff58a5b..533debe332880 100644 --- a/base/linalg/uniformscaling.jl +++ b/base/linalg/uniformscaling.jl @@ -50,7 +50,7 @@ issymmetric(::UniformScaling) = true ishermitian(J::UniformScaling) = isreal(J.λ) (+)(J1::UniformScaling, J2::UniformScaling) = UniformScaling(J1.λ+J2.λ) -(+){T}(B::BitArray{2},J::UniformScaling{T}) = Array(B) + J +(+)(B::BitArray{2}, J::UniformScaling) = Array(B) + J (+)(J::UniformScaling, B::BitArray{2}) = J + Array(B) (+)(J::UniformScaling, A::AbstractMatrix) = A + J diff --git a/base/markdown/parse/util.jl b/base/markdown/parse/util.jl index f36ca831d9b5f..9b5598bbf9754 100644 --- a/base/markdown/parse/util.jl +++ b/base/markdown/parse/util.jl @@ -91,7 +91,7 @@ function startswith(stream::IO, c::Char; eat = true) end end -function startswith{T<:AbstractString}(stream::IO, ss::Vector{T}; kws...) +function startswith(stream::IO, ss::Vector{<:AbstractString}; kws...) any(s->startswith(stream, s; kws...), ss) end diff --git a/base/math.jl b/base/math.jl index 247196c1290d0..49622703c9c49 100644 --- a/base/math.jl +++ b/base/math.jl @@ -63,7 +63,7 @@ clamp{X,L,H}(x::X, lo::L, hi::H) = Restrict values in `array` to the specified range, in-place. See also [`clamp`](@ref). """ -function clamp!{T}(x::AbstractArray{T}, lo, hi) +function clamp!(x::AbstractArray, lo, hi) @inbounds for i in eachindex(x) x[i] = clamp(x[i], lo, hi) end diff --git a/base/mmap.jl b/base/mmap.jl index 96ba008e1d6e7..e0173087697fe 100644 --- a/base/mmap.jl +++ b/base/mmap.jl @@ -165,10 +165,8 @@ mmap{T<:Array}(file::AbstractString, ::Type{T}, len::Integer, offset::Integer=In mmap{T<:Array,N}(::Type{T}, dims::NTuple{N,Integer}; shared::Bool=true) = mmap(Anonymous(), T, dims, Int64(0); shared=shared) mmap{T<:Array}(::Type{T}, i::Integer...; shared::Bool=true) = mmap(Anonymous(), T, convert(Tuple{Vararg{Int}},i), Int64(0); shared=shared) -function mmap{T<:BitArray,N}(io::IOStream, - ::Type{T}, - dims::NTuple{N,Integer}, - offset::Int64=position(io); grow::Bool=true, shared::Bool=true) +function mmap{N}(io::IOStream, ::Type{<:BitArray}, dims::NTuple{N,Integer}, + offset::Int64=position(io); grow::Bool=true, shared::Bool=true) n = prod(dims) nc = Base.num_bit_chunks(n) chunks = mmap(io, Vector{UInt64}, (nc,), offset; grow=grow, shared=shared) diff --git a/base/mpfr.jl b/base/mpfr.jl index 024860ef1ef39..e2081e1f331c4 100644 --- a/base/mpfr.jl +++ b/base/mpfr.jl @@ -250,9 +250,9 @@ convert(::Type{Float16}, x::BigFloat) = convert(Float16, convert(Float32, x)) (::Type{Float16})(x::BigFloat, r::RoundingMode) = convert(Float16, Float32(x, r)) -promote_rule{T<:Real}(::Type{BigFloat}, ::Type{T}) = BigFloat -promote_rule{T<:AbstractFloat}(::Type{BigInt},::Type{T}) = BigFloat -promote_rule{T<:AbstractFloat}(::Type{BigFloat},::Type{T}) = BigFloat +promote_rule(::Type{BigFloat}, ::Type{<:Real}) = BigFloat +promote_rule(::Type{BigInt},::Type{<:AbstractFloat}) = BigFloat +promote_rule(::Type{BigFloat},::Type{<:AbstractFloat}) = BigFloat function convert(::Type{Rational{BigInt}}, x::AbstractFloat) if isnan(x); return zero(BigInt)//zero(BigInt); end diff --git a/base/multidimensional.jl b/base/multidimensional.jl index b99e4002f1132..ec784fc82280e 100644 --- a/base/multidimensional.jl +++ b/base/multidimensional.jl @@ -29,7 +29,7 @@ module IteratorsMD CartesianIndex(index::Union{Integer, CartesianIndex}...) = CartesianIndex(flatten(index)) flatten(I::Tuple{}) = I flatten(I::Tuple{Any}) = I - flatten{N}(I::Tuple{CartesianIndex{N}}) = I[1].I + flatten(I::Tuple{<:CartesianIndex}) = I[1].I @inline flatten(I) = _flatten(I...) @inline _flatten() = () @inline _flatten(i, I...) = (i, _flatten(I...)...) @@ -60,8 +60,8 @@ module IteratorsMD max{N}(index1::CartesianIndex{N}, index2::CartesianIndex{N}) = CartesianIndex{N}(map(max, index1.I, index2.I)) + (+)(i::Integer, index::CartesianIndex) = index+i (+){N}(index::CartesianIndex{N}, i::Integer) = CartesianIndex{N}(map(x->x+i, index.I)) - (+){N}(i::Integer, index::CartesianIndex{N}) = index+i (-){N}(index::CartesianIndex{N}, i::Integer) = CartesianIndex{N}(map(x->x-i, index.I)) (-){N}(i::Integer, index::CartesianIndex{N}) = CartesianIndex{N}(map(x->i-x, index.I)) (*){N}(a::Integer, index::CartesianIndex{N}) = CartesianIndex{N}(map(x->a*x, index.I)) @@ -82,7 +82,7 @@ module IteratorsMD stop::I end - CartesianRange{N}(index::CartesianIndex{N}) = CartesianRange(one(index), index) + CartesianRange(index::CartesianIndex) = CartesianRange(one(index), index) CartesianRange(::Tuple{}) = CartesianRange{CartesianIndex{0}}(CartesianIndex{0}(()),CartesianIndex{0}(())) CartesianRange{N}(sz::NTuple{N,Int}) = CartesianRange(CartesianIndex(sz)) CartesianRange{N}(rngs::NTuple{N,Union{Integer,AbstractUnitRange}}) = @@ -112,9 +112,9 @@ module IteratorsMD @inline maxt(a::Tuple, b::Tuple) = (max(a[1], b[1]), maxt(tail(a), tail(b))...) eltype{I}(::Type{CartesianRange{I}}) = I - iteratorsize{I}(::Type{CartesianRange{I}}) = Base.HasShape() + iteratorsize(::Type{<:CartesianRange}) = Base.HasShape() - @inline function start{I<:CartesianIndex}(iter::CartesianRange{I}) + @inline function start(iter::CartesianRange{<:CartesianIndex}) if any(map(>, iter.start.I, iter.stop.I)) return iter.stop+1 end @@ -133,14 +133,14 @@ module IteratorsMD newtail = inc(tail(state), tail(start), tail(stop)) (start[1], newtail...) end - @inline done{I<:CartesianIndex}(iter::CartesianRange{I}, state) = state.I[end] > iter.stop.I[end] + @inline done(iter::CartesianRange{<:CartesianIndex}, state) = state.I[end] > iter.stop.I[end] # 0-d cartesian ranges are special-cased to iterate once and only once - start{I<:CartesianIndex{0}}(iter::CartesianRange{I}) = false - next{I<:CartesianIndex{0}}(iter::CartesianRange{I}, state) = iter.start, true - done{I<:CartesianIndex{0}}(iter::CartesianRange{I}, state) = state + start(iter::CartesianRange{<:CartesianIndex{0}}) = false + next(iter::CartesianRange{<:CartesianIndex{0}}, state) = iter.start, true + done(iter::CartesianRange{<:CartesianIndex{0}}, state) = state - size{I<:CartesianIndex}(iter::CartesianRange{I}) = map(dimlength, iter.start.I, iter.stop.I) + size(iter::CartesianRange{<:CartesianIndex}) = map(dimlength, iter.start.I, iter.stop.I) dimlength(start, stop) = stop-start+1 length(iter::CartesianRange) = prod(size(iter)) @@ -154,22 +154,22 @@ module IteratorsMD @inline _in(b, i, start, stop) = _in(b & (start[1] <= i[1] <= stop[1]), tail(i), tail(start), tail(stop)) simd_outer_range(iter::CartesianRange{CartesianIndex{0}}) = iter - function simd_outer_range{I}(iter::CartesianRange{I}) + function simd_outer_range(iter::CartesianRange) start = CartesianIndex(tail(iter.start.I)) stop = CartesianIndex(tail(iter.stop.I)) CartesianRange(start, stop) end - simd_inner_length{I<:CartesianIndex{0}}(iter::CartesianRange{I}, ::CartesianIndex) = 1 + simd_inner_length(iter::CartesianRange{<:CartesianIndex{0}}, ::CartesianIndex) = 1 simd_inner_length(iter::CartesianRange, I::CartesianIndex) = iter.stop[1]-iter.start[1]+1 - simd_index{I<:CartesianIndex{0}}(iter::CartesianRange{I}, ::CartesianIndex, I1::Int) = iter.start - @inline function simd_index{N}(iter::CartesianRange, Ilast::CartesianIndex{N}, I1::Int) + simd_index(iter::CartesianRange{<:CartesianIndex{0}}, ::CartesianIndex, I1::Int) = iter.start + @inline function simd_index(iter::CartesianRange, Ilast::CartesianIndex, I1::Int) CartesianIndex((I1+iter.start[1], Ilast.I...)) end # Split out the first N elements of a tuple - @inline split{N}(t, V::Type{Val{N}}) = _split((), t, V) + @inline split(t, V::Type{<:Val}) = _split((), t, V) @inline _split(tN, trest, V) = _split((tN..., trest[1]), tail(trest), V) # exit either when we've exhausted the input tuple or when tN has length N @inline _split{N}(tN::NTuple{N,Any}, ::Tuple{}, ::Type{Val{N}}) = tN, () # ambig. @@ -182,7 +182,7 @@ using .IteratorsMD ## Bounds-checking with CartesianIndex # Disallow linear indexing with CartesianIndex -function checkbounds(::Type{Bool}, A::AbstractArray, i::Union{CartesianIndex, AbstractArray{C} where C <: CartesianIndex}) +function checkbounds(::Type{Bool}, A::AbstractArray, i::Union{CartesianIndex, AbstractArray{<:CartesianIndex}}) @_inline_meta checkbounds_indices(Bool, indices(A), (i,)) end @@ -213,8 +213,8 @@ end I::Tuple{AbstractArray{CartesianIndex{0}},Vararg{Any}}) checkbounds_indices(Bool, IA, tail(I)) end -@inline function checkbounds_indices{N}(::Type{Bool}, IA::Tuple{Any}, - I::Tuple{AbstractArray{CartesianIndex{N}},Vararg{Any}}) +@inline function checkbounds_indices(::Type{Bool}, IA::Tuple{Any}, + I::Tuple{<:AbstractArray{<:CartesianIndex},Vararg{Any}}) checkindex(Bool, IA, I[1]) & checkbounds_indices(Bool, (), tail(I)) end @inline function checkbounds_indices{N}(::Type{Bool}, IA::Tuple, @@ -223,7 +223,7 @@ end checkindex(Bool, IA1, I[1]) & checkbounds_indices(Bool, IArest, tail(I)) end -function checkindex{N}(::Type{Bool}, inds::Tuple, I::AbstractArray{CartesianIndex{N}}) +function checkindex(::Type{Bool}, inds::Tuple, I::AbstractArray{<:CartesianIndex}) b = true for i in I b &= checkbounds_indices(Bool, inds, (i,)) @@ -235,7 +235,7 @@ end # AbstractArray{CartesianIndex} # rather than returning N, it returns an NTuple{N,Bool} so the result is inferrable @inline index_ndims(i1, I...) = (true, index_ndims(I...)...) -@inline function index_ndims{N}(i1::CartesianIndex{N}, I...) +@inline function index_ndims(i1::CartesianIndex, I...) (map(x->true, i1.I)..., index_ndims(I...)...) end @inline function index_ndims{N}(i1::AbstractArray{CartesianIndex{N}}, I...) @@ -294,7 +294,7 @@ show(io::IO, r::LogicalIndex) = print(io, "Base.LogicalIndex(", r.mask, ")") r = linearindices(L.mask) return (r, start(r), 1) end -@inline function start{C<:CartesianIndex}(L::LogicalIndex{C}) +@inline function start(L::LogicalIndex{<:CartesianIndex}) r = CartesianRange(indices(L.mask)) return (r, start(r), 1) end @@ -310,8 +310,8 @@ end done(L::LogicalIndex, s) = s[3] > length(L) # When wrapping a BitArray, lean heavily upon its internals -- this is a common # case. Just use the Int index and count as its state. -@inline start{B<:BitArray}(L::LogicalIndex{Int, B}) = (0, 1) -@inline function next{B<:BitArray}(L::LogicalIndex{Int, B}, s) +@inline start(L::LogicalIndex{Int,<:BitArray}) = (0, 1) +@inline function next(L::LogicalIndex{Int,<:BitArray}, s) i, n = s Bc = L.mask.chunks while true @@ -322,7 +322,7 @@ done(L::LogicalIndex, s) = s[3] > length(L) i += 1 end end -@inline done{B<:BitArray}(L::LogicalIndex{Int, B}, s) = s[2] > length(L) +@inline done(L::LogicalIndex{Int,<:BitArray}, s) = s[2] > length(L) # Checking bounds with LogicalIndex{Int} is tricky since we allow linear indexing over trailing dimensions @inline checkbounds_indices{N}(::Type{Bool},IA::Tuple{},I::Tuple{LogicalIndex{Int,AbstractArray{Bool,N}}}) = @@ -333,7 +333,7 @@ end IA1, IArest = IteratorsMD.split(IA, Val{N}) checkindex(Bool, IA1, I[1]) end -@inline checkbounds{T,B<:AbstractArray{Bool,1}}(::Type{Bool}, A::AbstractArray, I::LogicalIndex{T,B}) = +@inline checkbounds(::Type{Bool}, A::AbstractArray, I::LogicalIndex{<:Any,<:AbstractArray{Bool,1}}) = linearindices(A) == linearindices(I.mask) @inline checkbounds(::Type{Bool}, A::AbstractArray, I::LogicalIndex) = indices(A) == indices(I.mask) @inline checkindex(::Type{Bool}, indx::AbstractUnitRange, I::LogicalIndex) = (indx,) == indices(I.mask) @@ -534,7 +534,7 @@ function cumsum!(out, v::AbstractVector, axis::Integer=1) axis == 1 ? accumulate_pairwise!(+, out, v) : copy!(out,v) end -function cumsum!{T <: Integer}(out, v::AbstractVector{T}, axis::Integer=1) +function cumsum!(out, v::AbstractVector{<:Integer}, axis::Integer=1) axis == 1 ? accumulate!(+, out, v) : copy!(out,v) end diff --git a/base/nullable.jl b/base/nullable.jl index f249d1ab712ce..6090f503c2186 100644 --- a/base/nullable.jl +++ b/base/nullable.jl @@ -57,7 +57,7 @@ promote_rule{S,T}(::Type{Nullable{S}}, ::Type{Nullable{T}}) = Nullable{promote_t promote_op{S,T}(op::Any, ::Type{Nullable{S}}, ::Type{Nullable{T}}) = Nullable{promote_op(op, S, T)} promote_op{S,T}(op::Type, ::Type{Nullable{S}}, ::Type{Nullable{T}}) = Nullable{promote_op(op, S, T)} -function show{T}(io::IO, x::Nullable{T}) +function show(io::IO, x::Nullable) if get(io, :compact, false) if isnull(x) print(io, "#NULL") @@ -81,8 +81,8 @@ end Attempt to access the value of `x`. Returns the value if it is present; otherwise, returns `y` if provided, or throws a `NullException` if not. """ -@inline function get{S,T}(x::Nullable{S}, y::T) - if isbits(S) +@inline function get{T}(x::Nullable{T}, y) + if isbits(T) ifelse(isnull(x), y, x.value) else isnull(x) ? y : x.value diff --git a/base/number.jl b/base/number.jl index e1fcd31f86c5c..cc9a3b7dc287d 100644 --- a/base/number.jl +++ b/base/number.jl @@ -27,10 +27,10 @@ indices(x::Number) = () indices(x::Number,d) = convert(Int,d)<1 ? throw(BoundsError()) : OneTo(1) eltype{T<:Number}(::Type{T}) = T ndims(x::Number) = 0 -ndims{T<:Number}(::Type{T}) = 0 +ndims(::Type{<:Number}) = 0 length(x::Number) = 1 endof(x::Number) = 1 -iteratorsize{T<:Number}(::Type{T}) = HasShape() +iteratorsize(::Type{<:Number}) = HasShape() getindex(x::Number) = x function getindex(x::Number, i::Integer) diff --git a/base/operators.jl b/base/operators.jl index ebf140ca0e599..5bea0306da24a 100644 --- a/base/operators.jl +++ b/base/operators.jl @@ -1049,13 +1049,13 @@ setindex_shape_check(X::AbstractArray) = setindex_shape_check(X::AbstractArray, i::Integer) = (_length(X)==i || throw_setindex_mismatch(X, (i,))) -setindex_shape_check{T}(X::AbstractArray{T,1}, i::Integer) = +setindex_shape_check(X::AbstractArray{<:Any,1}, i::Integer) = (_length(X)==i || throw_setindex_mismatch(X, (i,))) -setindex_shape_check{T}(X::AbstractArray{T,1}, i::Integer, j::Integer) = +setindex_shape_check(X::AbstractArray{<:Any,1}, i::Integer, j::Integer) = (_length(X)==i*j || throw_setindex_mismatch(X, (i,j))) -function setindex_shape_check{T}(X::AbstractArray{T,2}, i::Integer, j::Integer) +function setindex_shape_check(X::AbstractArray{<:Any,2}, i::Integer, j::Integer) if length(X) != i*j throw_setindex_mismatch(X, (i,j)) end @@ -1093,7 +1093,7 @@ indexing behaviors. This must return either an `Int` or an `AbstractArray` of to_index(i::Integer) = convert(Int,i)::Int to_index(I::AbstractArray{Bool}) = LogicalIndex(I) to_index(I::AbstractArray) = I -to_index{T<:Union{AbstractArray, Colon}}(I::AbstractArray{T}) = throw(ArgumentError("invalid index: $I")) +to_index(I::AbstractArray{<:Union{AbstractArray, Colon}}) = throw(ArgumentError("invalid index: $I")) to_index(::Colon) = throw(ArgumentError("colons must be converted by to_indices(...)")) to_index(i) = throw(ArgumentError("invalid index: $i")) diff --git a/base/parallel/clusterserialize.jl b/base/parallel/clusterserialize.jl index 5aed58c648152..76c2db5c2ba60 100644 --- a/base/parallel/clusterserialize.jl +++ b/base/parallel/clusterserialize.jl @@ -185,7 +185,7 @@ function original_ex(s::ClusterSerializer, ex_str, remote_stktrace) stk_str, " stacktrace : ")) end -function deserialize(s::ClusterSerializer, t::Type{T}) where T <: CapturedException +function deserialize(s::ClusterSerializer, t::Type{<:CapturedException}) ex_str = deserialize(s) local bt local capex diff --git a/base/parallel/remotecall.jl b/base/parallel/remotecall.jl index 0cbef021603a5..fc137cfd1b50a 100644 --- a/base/parallel/remotecall.jl +++ b/base/parallel/remotecall.jl @@ -283,12 +283,12 @@ function serialize(s::AbstractSerializer, rr::AbstractRemoteRef, addclient) invoke(serialize, Tuple{AbstractSerializer, Any}, s, rr) end -function deserialize{T<:Future}(s::AbstractSerializer, t::Type{T}) +function deserialize(s::AbstractSerializer, t::Type{<:Future}) f = deserialize_rr(s,t) Future(f.where, RRID(f.whence, f.id), f.v) # ctor adds to client_refs table end -function deserialize{T<:RemoteChannel}(s::AbstractSerializer, t::Type{T}) +function deserialize(s::AbstractSerializer, t::Type{<:RemoteChannel}) rr = deserialize_rr(s,t) # call ctor to make sure this rr gets added to the client_refs table RemoteChannel{channel_type(rr)}(rr.where, RRID(rr.whence, rr.id)) diff --git a/base/parse.jl b/base/parse.jl index 4599b96a28da0..c77c70e44227a 100644 --- a/base/parse.jl +++ b/base/parse.jl @@ -165,7 +165,7 @@ end float(x::AbstractString) = parse(Float64,x) -float{S<:AbstractString}(a::AbstractArray{S}) = map!(float, similar(a,typeof(float(0))), a) +float(a::AbstractArray{<:AbstractString}) = map!(float, similar(a,typeof(float(0))), a) ## interface to parser ## diff --git a/base/permuteddimsarray.jl b/base/permuteddimsarray.jl index 133ad971871b1..f515de9c420cd 100644 --- a/base/permuteddimsarray.jl +++ b/base/permuteddimsarray.jl @@ -56,7 +56,7 @@ Base.unsafe_convert{T}(::Type{Ptr{T}}, A::PermutedDimsArray{T}) = Base.unsafe_co # order than used by Julia. But for an array with unconventional # storage order, a linear offset is ambiguous---is it a memory offset # or a linear index? -Base.pointer{T}(A::PermutedDimsArray{T}, i::Integer) = throw(ArgumentError("pointer(A, i) is deliberately unsupported for PermutedDimsArray")) +Base.pointer(A::PermutedDimsArray, i::Integer) = throw(ArgumentError("pointer(A, i) is deliberately unsupported for PermutedDimsArray")) function Base.strides{T,N,perm}(A::PermutedDimsArray{T,N,perm}) s = strides(parent(A)) @@ -111,7 +111,7 @@ julia> permutedims(A, [3, 2, 1]) 6 8 ``` """ -function Base.permutedims{T,N}(A::AbstractArray{T,N}, perm) +function Base.permutedims(A::AbstractArray, perm) dest = similar(A, genperm(indices(A), perm)) permutedims!(dest, A, perm) end diff --git a/base/pkg/reqs.jl b/base/pkg/reqs.jl index 003b82496e3c9..8b4d1c3c9aed5 100644 --- a/base/pkg/reqs.jl +++ b/base/pkg/reqs.jl @@ -54,7 +54,7 @@ hash(s::Line, h::UInt) = hash(s.content, h + (0x3f5a631add21cb1a % UInt)) # general machinery for parsing REQUIRE files -function read{T<:AbstractString}(readable::Vector{T}) +function read(readable::Vector{<:AbstractString}) lines = Line[] for line in readable line = chomp(line) diff --git a/base/pkg/resolve/versionweight.jl b/base/pkg/resolve/versionweight.jl index 0593544a05ee6..d9193e410dfe8 100644 --- a/base/pkg/resolve/versionweight.jl +++ b/base/pkg/resolve/versionweight.jl @@ -42,7 +42,7 @@ for f in (:-, :+) end end -Base.:-{T}(a::HierarchicalValue{T}) = HierarchicalValue(-a.v, -a.rest) +Base.:-(a::HierarchicalValue) = HierarchicalValue(-a.v, -a.rest) function Base.cmp{T}(a::HierarchicalValue{T}, b::HierarchicalValue{T}) av = a.v diff --git a/base/pointer.jl b/base/pointer.jl index a201bb0816621..7bb7d20128c47 100644 --- a/base/pointer.jl +++ b/base/pointer.jl @@ -67,7 +67,7 @@ function unsafe_wrap{T}(::Union{Type{Array},Type{Array{T}},Type{Array{T,1}}}, ccall(:jl_ptr_to_array_1d, Array{T,1}, (Any, Ptr{Void}, Csize_t, Cint), Array{T,1}, p, d, own) end -unsafe_wrap{N,I<:Integer}(Atype::Type, p::Ptr, dims::NTuple{N,I}, own::Bool=false) = +unsafe_wrap{N}(Atype::Type, p::Ptr, dims::NTuple{N,<:Integer}, own::Bool=false) = unsafe_wrap(Atype, p, convert(Tuple{Vararg{Int}}, dims), own) """ diff --git a/base/process.jl b/base/process.jl index cb8859cb60183..0e7bb2876f639 100644 --- a/base/process.jl +++ b/base/process.jl @@ -208,7 +208,7 @@ function cstr(s) end # convert various env representations into an array of "key=val" strings -byteenv{S<:AbstractString}(env::AbstractArray{S}) = +byteenv(env::AbstractArray{<:AbstractString}) = String[cstr(x) for x in env] byteenv(env::Associative) = String[cstr(string(k)*"="*string(v)) for (k,v) in env] @@ -228,15 +228,15 @@ use `withenv`. The `dir` keyword argument can be used to specify a working directory for the command. """ setenv(cmd::Cmd, env; dir="") = Cmd(cmd; env=byteenv(env), dir=dir) -setenv{T<:AbstractString}(cmd::Cmd, env::Pair{T}...; dir="") = +setenv(cmd::Cmd, env::Pair{<:AbstractString}...; dir="") = setenv(cmd, env; dir=dir) setenv(cmd::Cmd; dir="") = Cmd(cmd; dir=dir) (&)(left::AbstractCmd, right::AbstractCmd) = AndCmds(left, right) redir_out(src::AbstractCmd, dest::AbstractCmd) = OrCmds(src, dest) redir_err(src::AbstractCmd, dest::AbstractCmd) = ErrOrCmds(src, dest) -Base.mr_empty{T2<:Base.AbstractCmd}(f, op::typeof(&), T1::Type{T2}) = - throw(ArgumentError("reducing over an empty collection of type $T1 with operator & is not allowed")) +Base.mr_empty(f, op::typeof(&), T::Type{<:Base.AbstractCmd}) = + throw(ArgumentError("reducing over an empty collection of type $T with operator & is not allowed")) # Stream Redirects redir_out(dest::Redirectable, src::AbstractCmd) = CmdRedirect(src, dest, STDIN_NO) diff --git a/base/profile.jl b/base/profile.jl index bda1c761f1b95..966be4811fabc 100644 --- a/base/profile.jl +++ b/base/profile.jl @@ -121,7 +121,7 @@ The keyword arguments can be any combination of: - `mincount` can also be used to limit the printout to only those lines with at least mincount occurrences. """ -function print{T<:Unsigned}(io::IO, data::Vector{T} = fetch(), lidict::LineInfoDict = getdict(data); +function print(io::IO, data::Vector{<:Unsigned} = fetch(), lidict::LineInfoDict = getdict(data); format = :tree, C = false, combine = true, @@ -138,7 +138,7 @@ function print{T<:Unsigned}(io::IO, data::Vector{T} = fetch(), lidict::LineInfoD format) end -function print{T<:Unsigned}(io::IO, data::Vector{T}, lidict::LineInfoDict, fmt::ProfileFormat, format::Symbol) +function print(io::IO, data::Vector{<:Unsigned}, lidict::LineInfoDict, fmt::ProfileFormat, format::Symbol) cols::Int = Base.displaysize(io)[2] if format == :tree tree(io, data, lidict, cols, fmt) @@ -158,7 +158,7 @@ a dictionary `lidict` of line information. See `Profile.print([io], data)` for an explanation of the valid keyword arguments. """ -print{T<:Unsigned}(data::Vector{T} = fetch(), lidict::LineInfoDict = getdict(data); kwargs...) = +print(data::Vector{<:Unsigned} = fetch(), lidict::LineInfoDict = getdict(data); kwargs...) = print(STDOUT, data, lidict; kwargs...) """ diff --git a/base/random.jl b/base/random.jl index ed7cd3174567e..206b4d25f6922 100644 --- a/base/random.jl +++ b/base/random.jl @@ -41,7 +41,7 @@ if is_windows() @inbounds return rd.buffer[1] % T end - rand!{T<:Union{Bool, Base.BitInteger}}(rd::RandomDevice, A::Array{T}) = (win32_SystemFunction036!(A); A) + rand!(rd::RandomDevice, A::Array{<:Union{Bool, Base.BitInteger}}) = (win32_SystemFunction036!(A); A) else # !windows immutable RandomDevice <: AbstractRNG file::IOStream @@ -50,8 +50,8 @@ else # !windows RandomDevice(unlimited::Bool=true) = new(open(unlimited ? "/dev/urandom" : "/dev/random"), unlimited) end - rand{ T<:Union{Bool, Base.BitInteger}}(rd::RandomDevice, ::Type{T}) = read( rd.file, T) - rand!{T<:Union{Bool, Base.BitInteger}}(rd::RandomDevice, A::Array{T}) = read!(rd.file, A) + rand{T<:Union{Bool, Base.BitInteger}}(rd::RandomDevice, ::Type{T}) = read( rd.file, T) + rand!(rd::RandomDevice, A::Array{<:Union{Bool, Base.BitInteger}}) = read!(rd.file, A) end # os-test @@ -473,7 +473,7 @@ function rand!{T<:Union{Float16, Float32}}(r::MersenneTwister, A::Array{T}, ::Ty A end -rand!{T<:Union{Float16, Float32}}(r::MersenneTwister, A::Array{T}) = rand!(r, A, CloseOpen) +rand!(r::MersenneTwister, A::Array{<:Union{Float16, Float32}}) = rand!(r, A, CloseOpen) function rand!(r::MersenneTwister, A::Array{UInt128}, n::Int=length(A)) @@ -649,7 +649,7 @@ else end end -rand{T<:Union{Signed,Unsigned,BigInt,Bool}}(rng::AbstractRNG, r::UnitRange{T}) = rand(rng, RangeGenerator(r)) +rand(rng::AbstractRNG, r::UnitRange{<:Union{Signed,Unsigned,BigInt,Bool}}) = rand(rng, RangeGenerator(r)) # Randomly draw a sample from an AbstractArray r @@ -663,7 +663,7 @@ function rand!(rng::AbstractRNG, A::AbstractArray, g::RangeGenerator) return A end -rand!{T<:Union{Signed,Unsigned,BigInt,Bool,Char}}(rng::AbstractRNG, A::AbstractArray, r::UnitRange{T}) = rand!(rng, A, RangeGenerator(r)) +rand!(rng::AbstractRNG, A::AbstractArray, r::UnitRange{<:Union{Signed,Unsigned,BigInt,Bool,Char}}) = rand!(rng, A, RangeGenerator(r)) function rand!(rng::AbstractRNG, A::AbstractArray, r::AbstractArray) g = RangeGenerator(1:(length(r))) diff --git a/base/range.jl b/base/range.jl index 6089c32c8e982..42ee7edab61c1 100644 --- a/base/range.jl +++ b/base/range.jl @@ -106,7 +106,7 @@ function steprange_last{T}(start::T, step, stop) last end -function steprange_last_empty{T<:Integer}(start::T, step, stop) +function steprange_last_empty(start::Integer, step, stop) # empty range has a special representation where stop = start-1 # this is needed to avoid the wrap-around that can happen computing # start - step, which leads to a range that looks very large instead @@ -378,13 +378,13 @@ let smallint = (Int === Int64 ? Union{Int8,UInt8,Int16,UInt16}) global length - function length{T <: smallint}(r::StepRange{T}) + function length(r::StepRange{<:smallint}) isempty(r) && return Int(0) div(Int(r.stop)+Int(r.step) - Int(r.start), Int(r.step)) end - length{T <: smallint}(r::AbstractUnitRange{T}) = Int(last(r)) - Int(first(r)) + 1 - length{T <: smallint}(r::OneTo{T}) = Int(r.stop) + length(r::AbstractUnitRange{<:smallint}) = Int(last(r)) - Int(first(r)) + 1 + length(r::OneTo{<:smallint}) = Int(r.stop) end first{T}(r::OrdinalRange{T}) = convert(T, r.start) @@ -416,14 +416,14 @@ end start(r::StepRange) = oftype(r.start + r.step, r.start) next{T}(r::StepRange{T}, i) = (convert(T,i), i+r.step) -done{T,S}(r::StepRange{T,S}, i) = isempty(r) | (i < min(r.start, r.stop)) | (i > max(r.start, r.stop)) -done{T,S}(r::StepRange{T,S}, i::Integer) = +done(r::StepRange, i) = isempty(r) | (i < min(r.start, r.stop)) | (i > max(r.start, r.stop)) +done(r::StepRange, i::Integer) = isempty(r) | (i == oftype(i, r.stop) + r.step) # see also twiceprecision.jl -start{T}(r::StepRangeLen{T}) = (unsafe_getindex(r, 1), 1) +start(r::StepRangeLen) = (unsafe_getindex(r, 1), 1) next{T}(r::StepRangeLen{T}, s) = s[1], (T(s[1]+r.step), s[2]+1) -done{T}(r::StepRangeLen{T}, s) = s[2] > length(r) +done(r::StepRangeLen, s) = s[2] > length(r) start{T}(r::UnitRange{T}) = oftype(r.start + oneunit(T), r.start) next{T}(r::AbstractUnitRange{T}, i) = (convert(T, i), i + oneunit(T)) @@ -437,11 +437,11 @@ let smallint = (Int === Int64 ? Union{Int8,UInt8,Int16,UInt16}) global start global next - start{T<:smallint}(r::StepRange{T}) = convert(Int, r.start) + start(r::StepRange{<:smallint}) = convert(Int, r.start) next{T<:smallint}(r::StepRange{T}, i) = (i % T, i + r.step) - start{T<:smallint}(r::UnitRange{T}) = convert(Int, r.start) + start(r::UnitRange{<:smallint}) = convert(Int, r.start) next{T<:smallint}(r::AbstractUnitRange{T}, i) = (i % T, i + 1) - start{T<:smallint}(r::OneTo{T}) = 1 + start(r::OneTo{<:smallint}) = 1 end ## indexing @@ -493,7 +493,7 @@ end getindex(r::Range, ::Colon) = copy(r) -function getindex{T<:Integer}(r::AbstractUnitRange, s::AbstractUnitRange{T}) +function getindex(r::AbstractUnitRange, s::AbstractUnitRange{<:Integer}) @_inline_meta @boundscheck checkbounds(r, s) f = first(r) @@ -507,28 +507,28 @@ function getindex{T}(r::OneTo{T}, s::OneTo) OneTo(T(s.stop)) end -function getindex{T<:Integer}(r::AbstractUnitRange, s::StepRange{T}) +function getindex(r::AbstractUnitRange, s::StepRange{<:Integer}) @_inline_meta @boundscheck checkbounds(r, s) st = oftype(first(r), first(r) + s.start-1) range(st, step(s), length(s)) end -function getindex{T<:Integer}(r::StepRange, s::Range{T}) +function getindex(r::StepRange, s::Range{<:Integer}) @_inline_meta @boundscheck checkbounds(r, s) st = oftype(r.start, r.start + (first(s)-1)*step(r)) range(st, step(r)*step(s), length(s)) end -function getindex{T<:Integer}(r::StepRangeLen, s::OrdinalRange{T}) +function getindex(r::StepRangeLen, s::OrdinalRange{<:Integer}) @_inline_meta @boundscheck checkbounds(r, s) vfirst = unsafe_getindex(r, first(s)) return StepRangeLen(vfirst, r.step*step(s), length(s)) end -function getindex{T<:Integer}(r::LinSpace, s::OrdinalRange{T}) +function getindex(r::LinSpace, s::OrdinalRange{<:Integer}) @_inline_meta @boundscheck checkbounds(r, s) vfirst = unsafe_getindex(r, first(s)) @@ -567,15 +567,15 @@ end intersect(r::OneTo, s::OneTo) = OneTo(min(r.stop,s.stop)) -intersect{T1<:Integer, T2<:Integer}(r::AbstractUnitRange{T1}, s::AbstractUnitRange{T2}) = max(first(r),first(s)):min(last(r),last(s)) +intersect(r::AbstractUnitRange{<:Integer}, s::AbstractUnitRange{<:Integer}) = max(first(r),first(s)):min(last(r),last(s)) -intersect{T<:Integer}(i::Integer, r::AbstractUnitRange{T}) = +intersect(i::Integer, r::AbstractUnitRange{<:Integer}) = i < first(r) ? (first(r):i) : i > last(r) ? (i:last(r)) : (i:i) -intersect{T<:Integer}(r::AbstractUnitRange{T}, i::Integer) = intersect(i, r) +intersect(r::AbstractUnitRange{<:Integer}, i::Integer) = intersect(i, r) -function intersect{T1<:Integer, T2<:Integer}(r::AbstractUnitRange{T1}, s::StepRange{T2}) +function intersect(r::AbstractUnitRange{<:Integer}, s::StepRange{<:Integer}) if isempty(s) range(first(r), 0) elseif step(s) == 0 @@ -594,7 +594,7 @@ function intersect{T1<:Integer, T2<:Integer}(r::AbstractUnitRange{T1}, s::StepRa end end -function intersect{T1<:Integer, T2<:Integer}(r::StepRange{T1}, s::AbstractUnitRange{T2}) +function intersect(r::StepRange{<:Integer}, s::AbstractUnitRange{<:Integer}) if step(r) < 0 reverse(intersect(s, reverse(r))) else @@ -656,7 +656,7 @@ function intersect(r1::Range, r2::Range, r3::Range, r::Range...) end # findin (the index of intersection) -function _findin{T1<:Integer, T2<:Integer}(r::Range{T1}, span::AbstractUnitRange{T2}) +function _findin(r::Range{<:Integer}, span::AbstractUnitRange{<:Integer}) local ifirst local ilast fspan = first(span) @@ -677,12 +677,12 @@ function _findin{T1<:Integer, T2<:Integer}(r::Range{T1}, span::AbstractUnitRange ifirst, ilast end -function findin{T1<:Integer, T2<:Integer}(r::AbstractUnitRange{T1}, span::AbstractUnitRange{T2}) +function findin(r::AbstractUnitRange{<:Integer}, span::AbstractUnitRange{<:Integer}) ifirst, ilast = _findin(r, span) ifirst:ilast end -function findin{T1<:Integer, T2<:Integer}(r::Range{T1}, span::AbstractUnitRange{T2}) +function findin(r::Range{<:Integer}, span::AbstractUnitRange{<:Integer}) ifirst, ilast = _findin(r, span) ifirst:1:ilast end @@ -822,25 +822,25 @@ sort(r::Range) = issorted(r) ? r : reverse(r) sortperm(r::AbstractUnitRange) = 1:length(r) sortperm(r::Range) = issorted(r) ? (1:1:length(r)) : (length(r):-1:1) -function sum{T<:Real}(r::Range{T}) +function sum(r::Range{<:Real}) l = length(r) # note that a little care is required to avoid overflow in l*(l-1)/2 return l * first(r) + (iseven(l) ? (step(r) * (l-1)) * (l>>1) : (step(r) * l) * ((l-1)>>1)) end -function mean{T<:Real}(r::Range{T}) +function mean(r::Range{<:Real}) isempty(r) && throw(ArgumentError("mean of an empty range is undefined")) (first(r) + last(r)) / 2 end -median{T<:Real}(r::Range{T}) = mean(r) +median(r::Range{<:Real}) = mean(r) function in(x, r::Range) n = step(r) == 0 ? 1 : round(Integer,(x-first(r))/step(r))+1 n >= 1 && n <= length(r) && r[n] == x end -in{T<:Integer}(x::Integer, r::AbstractUnitRange{T}) = (first(r) <= x) & (x <= last(r)) +in(x::Integer, r::AbstractUnitRange{<:Integer}) = (first(r) <= x) & (x <= last(r)) in{T<:Integer}(x, r::Range{T}) = isinteger(x) && !isempty(r) && x>=minimum(r) && x<=maximum(r) && (mod(convert(T,x),step(r))-mod(first(r),step(r)) == 0) in(x::Char, r::Range{Char}) = !isempty(r) && x >= minimum(r) && x <= maximum(r) && (mod(Int(x) - Int(first(r)), step(r)) == 0) diff --git a/base/rational.jl b/base/rational.jl index 6c5df9f117344..e669eaa97e8b1 100644 --- a/base/rational.jl +++ b/base/rational.jl @@ -93,7 +93,7 @@ end convert(::Type{Rational}, x::Float64) = convert(Rational{Int64}, x) convert(::Type{Rational}, x::Float32) = convert(Rational{Int}, x) -big{T<:Integer}(z::Complex{Rational{T}}) = Complex{Rational{BigInt}}(z) +big(z::Complex{<:Rational{<:Integer}}) = Complex{Rational{BigInt}}(z) promote_rule{T<:Integer,S<:Integer}(::Type{Rational{T}}, ::Type{S}) = Rational{promote_type(T,S)} promote_rule{T<:Integer,S<:Integer}(::Type{Rational{T}}, ::Type{Rational{S}}) = Rational{promote_type(T,S)} @@ -249,7 +249,7 @@ function *(x::Rational, y::Rational) checked_mul(xn,yn) // checked_mul(xd,yd) end /(x::Rational, y::Rational) = x//y -/{T<:Union{Integer,Rational}}(x::Rational, y::Complex{T}) = x//y +/(x::Rational, y::Complex{<:Union{Integer,Rational}}) = x//y fma(x::Rational, y::Rational, z::Rational) = x*y+z @@ -419,8 +419,8 @@ end ^{T<:AbstractFloat}(x::T, y::Rational) = x^convert(T,y) ^{T<:AbstractFloat}(x::Complex{T}, y::Rational) = x^convert(T,y) -^{T<:Rational}(z::Complex{T}, n::Bool) = n ? z : one(z) # to resolve ambiguity -function ^{T<:Rational}(z::Complex{T}, n::Integer) +^(z::Complex{<:Rational}, n::Bool) = n ? z : one(z) # to resolve ambiguity +function ^(z::Complex{<:Rational}, n::Integer) n >= 0 ? power_by_squaring(z,n) : power_by_squaring(inv(z),-n) end diff --git a/base/reduce.jl b/base/reduce.jl index 3f2e110e68999..d950a5ad25e74 100644 --- a/base/reduce.jl +++ b/base/reduce.jl @@ -272,7 +272,7 @@ function _mapreduce{T}(f, op, ::LinearFast, A::AbstractArray{T}) end end -_mapreduce{T}(f, op, ::LinearSlow, A::AbstractArray{T}) = mapfoldl(f, op, A) +_mapreduce(f, op, ::LinearSlow, A::AbstractArray) = mapfoldl(f, op, A) mapreduce(f, op, A::AbstractArray) = _mapreduce(f, op, linearindexing(A), A) mapreduce(f, op, a::Number) = f(a) diff --git a/base/reducedim.jl b/base/reducedim.jl index 9788698a236b3..b6592764952b1 100644 --- a/base/reducedim.jl +++ b/base/reducedim.jl @@ -18,7 +18,7 @@ function reduced_indices{N}(inds::Indices{N}, d::Int, rd::AbstractUnitRange) return inds end end -reduced_indices{N}(inds::Indices{N}, d::Int) = reduced_indices(inds, d, OneTo(1)) +reduced_indices(inds::Indices, d::Int) = reduced_indices(inds, d, OneTo(1)) function reduced_indices0{N}(inds::Indices{N}, d::Int) d < 1 && throw(ArgumentError("dimension must be ≥ 1, got $d")) @@ -83,10 +83,10 @@ reducedim_initarray0{T}(A::AbstractArray, region, v0::T) = reducedim_initarray0( promote_union(T::Union) = promote_type(promote_union(T.a), promote_union(T.b)) promote_union(T) = T -function reducedim_init{S}(f, op::typeof(+), A::AbstractArray{S}, region) +function reducedim_init(f, op::typeof(+), A::AbstractArray, region) _reducedim_init(f, op, zero, sum, A, region) end -function reducedim_init{S}(f, op::typeof(*), A::AbstractArray{S}, region) +function reducedim_init(f, op::typeof(*), A::AbstractArray, region) _reducedim_init(f, op, one, prod, A, region) end function _reducedim_init(f, op, fv, fop, A, region) @@ -102,9 +102,9 @@ function _reducedim_init(f, op, fv, fop, A, region) return reducedim_initarray(A, region, z, Tr) end -reducedim_init{T}(f, op::typeof(max), A::AbstractArray{T}, region) = reducedim_init(f, scalarmax, A, region) -reducedim_init{T}(f, op::typeof(min), A::AbstractArray{T}, region) = reducedim_init(f, scalarmin, A, region) -reducedim_init{T}(f::Union{typeof(abs),typeof(abs2)}, op::typeof(max), A::AbstractArray{T}, region) = reducedim_init(f, scalarmax, A, region) +reducedim_init(f, op::typeof(max), A::AbstractArray, region) = reducedim_init(f, scalarmax, A, region) +reducedim_init(f, op::typeof(min), A::AbstractArray, region) = reducedim_init(f, scalarmin, A, region) +reducedim_init(f::Union{typeof(abs),typeof(abs2)}, op::typeof(max), A::AbstractArray, region) = reducedim_init(f, scalarmax, A, region) reducedim_init{T}(f, op::typeof(scalarmax), A::AbstractArray{T}, region) = reducedim_initarray0(A, region, typemin(f(zero(T)))) reducedim_init{T}(f, op::typeof(scalarmin), A::AbstractArray{T}, region) = reducedim_initarray0(A, region, typemax(f(zero(T)))) @@ -169,7 +169,7 @@ function check_reducedims(R, A) return lsiz end -function _mapreducedim!{T,N}(f, op, R::AbstractArray, A::AbstractArray{T,N}) +function _mapreducedim!(f, op, R::AbstractArray, A::AbstractArray) lsiz = check_reducedims(R,A) isempty(A) && return R @@ -238,7 +238,7 @@ julia> mapreducedim(isodd, |, a, 1, true) """ mapreducedim(f, op, A::AbstractArray, region, v0) = mapreducedim!(f, op, reducedim_initarray(A, region, v0), A) -mapreducedim{T}(f, op, A::AbstractArray{T}, region) = +mapreducedim(f, op, A::AbstractArray, region) = mapreducedim!(f, op, reducedim_init(f, op, A, region), A) """ @@ -627,10 +627,8 @@ end Find the minimum of `A` and the corresponding linear index along singleton dimensions of `rval` and `rind`, and store the results in `rval` and `rind`. """ -function findmin!{R}(rval::AbstractArray{R}, - rind::AbstractArray, - A::AbstractArray; - init::Bool=true) +function findmin!(rval::AbstractArray, rind::AbstractArray, A::AbstractArray; + init::Bool=true) findminmax!(<, initarray!(rval, scalarmin, init), rind, A) end @@ -667,10 +665,8 @@ end Find the maximum of `A` and the corresponding linear index along singleton dimensions of `rval` and `rind`, and store the results in `rval` and `rind`. """ -function findmax!{R}(rval::AbstractArray{R}, - rind::AbstractArray, - A::AbstractArray; - init::Bool=true) +function findmax!(rval::AbstractArray, rind::AbstractArray, A::AbstractArray; + init::Bool=true) findminmax!(>, initarray!(rval, scalarmax, init), rind, A) end diff --git a/base/reflection.jl b/base/reflection.jl index 41c15cee63b7b..94bfb40b4ef21 100644 --- a/base/reflection.jl +++ b/base/reflection.jl @@ -118,7 +118,7 @@ julia> fieldname(SparseMatrixCSC,5) """ fieldname(t::DataType, i::Integer) = t.name.names[i]::Symbol fieldname(t::UnionAll, i::Integer) = fieldname(unwrap_unionall(t), i) -fieldname{T<:Tuple}(t::Type{T}, i::Integer) = i < 1 || i > nfields(t) ? throw(BoundsError(t, i)) : Int(i) +fieldname(t::Type{<:Tuple}, i::Integer) = i < 1 || i > nfields(t) ? throw(BoundsError(t, i)) : Int(i) """ fieldnames(x::DataType) @@ -141,7 +141,7 @@ function fieldnames(v) end fieldnames(t::DataType) = Symbol[fieldname(t, n) for n in 1:nfields(t)] fieldnames(t::UnionAll) = fieldnames(unwrap_unionall(t)) -fieldnames{T<:Tuple}(t::Type{T}) = Int[n for n in 1:nfields(t)] +fieldnames(t::Type{<:Tuple}) = Int[n for n in 1:nfields(t)] """ Base.datatype_name(t) -> Symbol diff --git a/base/refpointer.jl b/base/refpointer.jl index e12ebbf284520..b049da535613e 100644 --- a/base/refpointer.jl +++ b/base/refpointer.jl @@ -88,7 +88,7 @@ end unsafe_convert{T}(::Type{Ptr{Void}}, b::RefArray{T}) = convert(Ptr{Void}, unsafe_convert(Ptr{T}, b)) # convert Arrays to pointer arrays for ccall -function (::Type{Ref{P}}){P<:Union{Ptr,Cwstring,Cstring},T<:Union{Ptr,Cwstring,Cstring}}(a::Array{T}) # Ref{P<:Ptr}(a::Array{T<:Ptr}) +function (::Type{Ref{<:Union{Ptr,Cwstring,Cstring}}})(a::Array{<:Union{Ptr,Cwstring,Cstring}}) # Ref{P<:Ptr}(a::Array{T<:Ptr}) return RefArray(a) # effectively a no-op end function (::Type{Ref{P}}){P<:Union{Ptr,Cwstring,Cstring},T}(a::Array{T}) # Ref{P<:Ptr}(a::Array) @@ -107,7 +107,7 @@ function (::Type{Ref{P}}){P<:Union{Ptr,Cwstring,Cstring},T}(a::Array{T}) # Ref{P return RefArray(ptrs,1,roots) end end -cconvert{P<:Ptr,T<:Ptr}(::Union{Type{Ptr{P}},Type{Ref{P}}}, a::Array{T}) = a +cconvert{P<:Ptr}(::Union{Type{Ptr{P}},Type{Ref{P}}}, a::Array{<:Ptr}) = a cconvert{P<:Union{Ptr,Cwstring,Cstring}}(::Union{Type{Ptr{P}},Type{Ref{P}}}, a::Array) = Ref{P}(a) ### diff --git a/base/reshapedarray.jl b/base/reshapedarray.jl index 7f1308a16718c..8a0b82bd3ed2a 100644 --- a/base/reshapedarray.jl +++ b/base/reshapedarray.jl @@ -110,7 +110,7 @@ _throw_reshape_colon_dimmismatch(A, pre, post) = throw(DimensionMismatch("array size $(length(A)) must be divisible by the product of the new dimensions $((pre..., :, post...))")) reshape{T,N}(parent::AbstractArray{T,N}, ndims::Type{Val{N}}) = parent -function reshape{T,AN,N}(parent::AbstractArray{T,AN}, ndims::Type{Val{N}}) +function reshape{N}(parent::AbstractArray, ndims::Type{Val{N}}) reshape(parent, rdims((), indices(parent), Val{N})) end # Move elements from inds to out until out reaches the desired @@ -143,7 +143,7 @@ function _reshape(parent::AbstractArray, dims::Dims) end # Reshaping a ReshapedArray -_reshape{T}(v::ReshapedArray{T,1}, dims::Dims{1}) = _reshape(v.parent, dims) +_reshape(v::ReshapedArray{<:Any,1}, dims::Dims{1}) = _reshape(v.parent, dims) _reshape(R::ReshapedArray, dims::Dims) = _reshape(R.parent, dims) function __reshape(p::Tuple{AbstractArray,LinearSlow}, dims::Dims) @@ -165,7 +165,7 @@ size_strides(out::Tuple) = out size(A::ReshapedArray) = A.dims similar(A::ReshapedArray, eltype::Type, dims::Dims) = similar(parent(A), eltype, dims) -linearindexing{R<:ReshapedArrayLF}(::Type{R}) = LinearFast() +linearindexing(::Type{<:ReshapedArrayLF}) = LinearFast() parent(A::ReshapedArray) = A.parent parentindexes(A::ReshapedArray) = map(s->1:s, size(parent(A))) reinterpret{T}(::Type{T}, A::ReshapedArray, dims::Dims) = reinterpret(T, parent(A), dims) diff --git a/base/rounding.jl b/base/rounding.jl index 3e9342a781f76..7e17637a017c9 100644 --- a/base/rounding.jl +++ b/base/rounding.jl @@ -139,8 +139,8 @@ See [`RoundingMode`](@ref) for available modes. """ :rounding -setrounding_raw{T<:Union{Float32,Float64}}(::Type{T},i::Integer) = ccall(:fesetround, Int32, (Int32,), i) -rounding_raw{T<:Union{Float32,Float64}}(::Type{T}) = ccall(:fegetround, Int32, ()) +setrounding_raw(::Type{<:Union{Float32,Float64}},i::Integer) = ccall(:fesetround, Int32, (Int32,), i) +rounding_raw(::Type{<:Union{Float32,Float64}}) = ccall(:fegetround, Int32, ()) setrounding{T<:Union{Float32,Float64}}(::Type{T},r::RoundingMode) = setrounding_raw(T,to_fenv(r)) rounding{T<:Union{Float32,Float64}}(::Type{T}) = from_fenv(rounding_raw(T)) diff --git a/base/set.jl b/base/set.jl index c3210bdbed0f6..22a099dc9f21a 100644 --- a/base/set.jl +++ b/base/set.jl @@ -41,7 +41,7 @@ delete!(s::Set, x) = (delete!(s.dict, x); s) copy(s::Set) = union!(similar(s), s) sizehint!(s::Set, newsz) = (sizehint!(s.dict, newsz); s) -empty!{T}(s::Set{T}) = (empty!(s.dict); s) +empty!(s::Set) = (empty!(s.dict); s) rehash!(s::Set) = (rehash!(s.dict); s) start(s::Set) = start(s.dict) @@ -250,4 +250,4 @@ function hash(s::Set, h::UInt) end convert{T}(::Type{Set{T}}, s::Set{T}) = s -convert{T,S}(::Type{Set{T}}, x::Set{S}) = Set{T}(x) +convert{T}(::Type{Set{T}}, x::Set) = Set{T}(x) diff --git a/base/sharedarray.jl b/base/sharedarray.jl index 823eb715134f9..4a0e89bcb3e7d 100644 --- a/base/sharedarray.jl +++ b/base/sharedarray.jl @@ -256,7 +256,7 @@ typealias SharedMatrix{T} SharedArray{T,2} length(S::SharedArray) = prod(S.dims) size(S::SharedArray) = S.dims ndims(S::SharedArray) = length(S.dims) -linearindexing{S<:SharedArray}(::Type{S}) = LinearFast() +linearindexing(::Type{<:SharedArray}) = LinearFast() function reshape{T,N}(a::SharedArray{T}, dims::NTuple{N,Int}) if length(a) != prod(dims) @@ -420,7 +420,7 @@ function serialize(s::AbstractSerializer, S::SharedArray) end end -function deserialize{T,N}(s::AbstractSerializer, t::Type{SharedArray{T,N}}) +function deserialize(s::AbstractSerializer, t::Type{<:SharedArray}) S = invoke(deserialize, Tuple{AbstractSerializer,DataType}, s, t) init_loc_flds(S, true) S diff --git a/base/show.jl b/base/show.jl index 928bbe53acb35..9ce33391f692b 100644 --- a/base/show.jl +++ b/base/show.jl @@ -258,7 +258,7 @@ show(io::IO, n::Signed) = (write(io, dec(n)); nothing) show(io::IO, n::Unsigned) = print(io, "0x", hex(n,sizeof(n)<<1)) print(io::IO, n::Unsigned) = print(io, dec(n)) -show{T}(io::IO, p::Ptr{T}) = print(io, typeof(p), " @0x$(hex(UInt(p), Sys.WORD_SIZE>>2))") +show(io::IO, p::Ptr) = print(io, typeof(p), " @0x$(hex(UInt(p), Sys.WORD_SIZE>>2))") function show(io::IO, p::Pair) if typeof(p.first) != typeof(p).parameters[1] || diff --git a/base/socket.jl b/base/socket.jl index b4598efca6d81..d4e70fdaf323c 100644 --- a/base/socket.jl +++ b/base/socket.jl @@ -4,7 +4,7 @@ abstract IPAddr Base.isless{T<:IPAddr}(a::T, b::T) = isless(a.host, b.host) -Base.convert{T<:Integer}(dt::Type{T}, ip::IPAddr) = dt(ip.host) +Base.convert(dt::Type{<:Integer}, ip::IPAddr) = dt(ip.host) immutable IPv4 <: IPAddr host::UInt32 diff --git a/base/sort.jl b/base/sort.jl index 61bef81914c28..d574b18fcb93a 100644 --- a/base/sort.jl +++ b/base/sort.jl @@ -135,7 +135,7 @@ function searchsorted(v::AbstractVector, x, ilo::Int, ihi::Int, o::Ordering) return (lo + 1) : (hi - 1) end -function searchsortedlast{T<:Real}(a::Range{T}, x::Real, o::DirectOrdering) +function searchsortedlast(a::Range{<:Real}, x::Real, o::DirectOrdering) if step(a) == 0 lt(o, x, first(a)) ? 0 : length(a) else @@ -144,7 +144,7 @@ function searchsortedlast{T<:Real}(a::Range{T}, x::Real, o::DirectOrdering) end end -function searchsortedfirst{T<:Real}(a::Range{T}, x::Real, o::DirectOrdering) +function searchsortedfirst(a::Range{<:Real}, x::Real, o::DirectOrdering) if step(a) == 0 lt(o, first(a), x) ? length(a) + 1 : 1 else @@ -153,7 +153,7 @@ function searchsortedfirst{T<:Real}(a::Range{T}, x::Real, o::DirectOrdering) end end -function searchsortedlast{T<:Integer}(a::Range{T}, x::Real, o::DirectOrdering) +function searchsortedlast(a::Range{<:Integer}, x::Real, o::DirectOrdering) if step(a) == 0 lt(o, x, first(a)) ? 0 : length(a) else @@ -161,7 +161,7 @@ function searchsortedlast{T<:Integer}(a::Range{T}, x::Real, o::DirectOrdering) end end -function searchsortedfirst{T<:Integer}(a::Range{T}, x::Real, o::DirectOrdering) +function searchsortedfirst(a::Range{<:Integer}, x::Real, o::DirectOrdering) if step(a) == 0 lt(o, first(a), x) ? length(a)+1 : 1 else @@ -169,7 +169,7 @@ function searchsortedfirst{T<:Integer}(a::Range{T}, x::Real, o::DirectOrdering) end end -function searchsortedfirst{T<:Integer}(a::Range{T}, x::Unsigned, o::DirectOrdering) +function searchsortedfirst(a::Range{<:Integer}, x::Unsigned, o::DirectOrdering) if lt(o, first(a), x) if step(a) == 0 length(a) + 1 @@ -181,7 +181,7 @@ function searchsortedfirst{T<:Integer}(a::Range{T}, x::Unsigned, o::DirectOrderi end end -function searchsortedlast{T<:Integer}(a::Range{T}, x::Unsigned, o::DirectOrdering) +function searchsortedlast(a::Range{<:Integer}, x::Unsigned, o::DirectOrdering) if lt(o, x, first(a)) 0 elseif step(a) == 0 @@ -191,7 +191,7 @@ function searchsortedlast{T<:Integer}(a::Range{T}, x::Unsigned, o::DirectOrderin end end -searchsorted{T<:Real}(a::Range{T}, x::Real, o::DirectOrdering) = +searchsorted(a::Range{<:Real}, x::Real, o::DirectOrdering) = searchsortedfirst(a, x, o) : searchsortedlast(a, x, o) for s in [:searchsortedfirst, :searchsortedlast, :searchsorted] @@ -414,7 +414,7 @@ end ## generic sorting methods ## defalg(v::AbstractArray) = DEFAULT_STABLE -defalg{T<:Number}(v::AbstractArray{T}) = DEFAULT_UNSTABLE +defalg(v::AbstractArray{<:Number}) = DEFAULT_UNSTABLE function sort!(v::AbstractVector, alg::Algorithm, order::Ordering) inds = indices(v,1) @@ -455,7 +455,7 @@ function sort!(v::AbstractVector; end # sort! for vectors of few unique integers -function sort_int_range!{T<:Integer}(x::Vector{T}, rangelen, minval) +function sort_int_range!(x::Vector{<:Integer}, rangelen, minval) offs = 1 - minval n = length(x) @@ -489,13 +489,13 @@ sort(v::AbstractVector; kws...) = sort!(copymutable(v); kws...) selectperm(v::AbstractVector, k::Union{Integer,OrdinalRange}; kwargs...) = selectperm!(similar(Vector{eltype(k)}, indices(v,1)), v, k; kwargs..., initialized=false) -function selectperm!{I<:Integer}(ix::AbstractVector{I}, v::AbstractVector, - k::Union{Int, OrdinalRange}; - lt::Function=isless, - by::Function=identity, - rev::Bool=false, - order::Ordering=Forward, - initialized::Bool=false) +function selectperm!(ix::AbstractVector{<:Integer}, v::AbstractVector, + k::Union{Int, OrdinalRange}; + lt::Function=isless, + by::Function=identity, + rev::Bool=false, + order::Ordering=Forward, + initialized::Bool=false) if !initialized @inbounds for i = indices(ix,1) ix[i] = i @@ -554,13 +554,13 @@ end Like [`sortperm`](@ref), but accepts a preallocated index vector `ix`. If `initialized` is `false` (the default), ix is initialized to contain the values `1:length(v)`. """ -function sortperm!{I<:Integer}(x::AbstractVector{I}, v::AbstractVector; - alg::Algorithm=DEFAULT_UNSTABLE, - lt=isless, - by=identity, - rev::Bool=false, - order::Ordering=Forward, - initialized::Bool=false) +function sortperm!(x::AbstractVector{<:Integer}, v::AbstractVector; + alg::Algorithm=DEFAULT_UNSTABLE, + lt=isless, + by=identity, + rev::Bool=false, + order::Ordering=Forward, + initialized::Bool=false) if indices(x,1) != indices(v,1) throw(ArgumentError("index vector must have the same indices as the source vector, $(indices(x,1)) != $(indices(v,1))")) end @@ -573,7 +573,7 @@ function sortperm!{I<:Integer}(x::AbstractVector{I}, v::AbstractVector; end # sortperm for vectors of few unique integers -function sortperm_int_range{T<:Integer}(x::Vector{T}, rangelen, minval) +function sortperm_int_range(x::Vector{<:Integer}, rangelen, minval) offs = 1 - minval n = length(x) @@ -670,7 +670,7 @@ function sortcols(A::AbstractMatrix; kws...) A[:,p] end -function slicetypeof{T,N}(A::AbstractArray{T,N}, i1, i2) +function slicetypeof{T}(A::AbstractArray{T}, i1, i2) I = map(slice_dummy, to_indices(A, (i1, i2))) fast = isa(linearindexing(viewindexing(I), linearindexing(A)), LinearFast) SubArray{T,1,typeof(A),typeof(I),fast} @@ -738,8 +738,8 @@ end nans2end!(v::AbstractVector, o::ForwardOrdering) = nans2right!(v,o) nans2end!(v::AbstractVector, o::ReverseOrdering) = nans2left!(v,o) -nans2end!{O<:ForwardOrdering}(v::AbstractVector{Int}, o::Perm{O}) = nans2right!(v,o) -nans2end!{O<:ReverseOrdering}(v::AbstractVector{Int}, o::Perm{O}) = nans2left!(v,o) +nans2end!(v::AbstractVector{Int}, o::Perm{<:ForwardOrdering}) = nans2right!(v,o) +nans2end!(v::AbstractVector{Int}, o::Perm{<:ReverseOrdering}) = nans2left!(v,o) issignleft(o::ForwardOrdering, x::Floats) = lt(o, x, zero(x)) issignleft(o::ReverseOrdering, x::Floats) = lt(o, x, -zero(x)) @@ -763,8 +763,8 @@ end fpsort!(v::AbstractVector, a::Sort.PartialQuickSort, o::Ordering) = sort!(v, first(indices(v,1)), last(indices(v,1)), a, o) -sort!{T<:Floats}(v::AbstractVector{T}, a::Algorithm, o::DirectOrdering) = fpsort!(v,a,o) -sort!{O<:DirectOrdering,T<:Floats}(v::Vector{Int}, a::Algorithm, o::Perm{O,Vector{T}}) = fpsort!(v,a,o) +sort!(v::AbstractVector{<:Floats}, a::Algorithm, o::DirectOrdering) = fpsort!(v,a,o) +sort!(v::Vector{Int}, a::Algorithm, o::Perm{<:DirectOrdering,<:Vector{<:Floats}}) = fpsort!(v,a,o) end # module Sort.Float diff --git a/base/sparse/abstractsparse.jl b/base/sparse/abstractsparse.jl index 60d70f97cc9f6..2c4143cf8eaa7 100644 --- a/base/sparse/abstractsparse.jl +++ b/base/sparse/abstractsparse.jl @@ -13,11 +13,11 @@ Returns `true` if `S` is sparse, and `false` otherwise. issparse(A::AbstractArray) = false issparse(S::AbstractSparseArray) = true -issparse{T, A<:AbstractSparseMatrix}(S::Symmetric{T, A}) = true -issparse{T, A<:AbstractSparseMatrix}(S::Hermitian{T, A}) = true -issparse{T, A<:AbstractSparseMatrix}(S::LowerTriangular{T, A}) = true -issparse{T, A<:AbstractSparseMatrix}(S::LinAlg.UnitLowerTriangular{T, A}) = true -issparse{T, A<:AbstractSparseMatrix}(S::UpperTriangular{T, A}) = true -issparse{T, A<:AbstractSparseMatrix}(S::LinAlg.UnitUpperTriangular{T, A}) = true +issparse(S::Symmetric{<:Any,<:AbstractSparseMatrix}) = true +issparse(S::Hermitian{<:Any,<:AbstractSparseMatrix}) = true +issparse(S::LowerTriangular{<:Any,<:AbstractSparseMatrix}) = true +issparse(S::LinAlg.UnitLowerTriangular{<:Any,<:AbstractSparseMatrix}) = true +issparse(S::UpperTriangular{<:Any,<:AbstractSparseMatrix}) = true +issparse(S::LinAlg.UnitUpperTriangular{<:Any,<:AbstractSparseMatrix}) = true indtype{Tv,Ti}(S::AbstractSparseArray{Tv,Ti}) = (Base.@_pure_meta; Ti) diff --git a/base/sparse/cholmod.jl b/base/sparse/cholmod.jl index e26b07143aafd..4a5fa3dc07bc5 100644 --- a/base/sparse/cholmod.jl +++ b/base/sparse/cholmod.jl @@ -881,10 +881,10 @@ function (::Type{Sparse}){Tv<:VTypes}(m::Integer, n::Integer, return o end -function (::Type{Sparse}){Tv<:VTypes}(m::Integer, n::Integer, +function (::Type{Sparse})(m::Integer, n::Integer, colptr::Vector{SuiteSparse_long}, rowval::Vector{SuiteSparse_long}, - nzval::Vector{Tv}) + nzval::Vector{<:VTypes}) o = Sparse(m, n, colptr, rowval, nzval, 0) # sort indices @@ -914,9 +914,9 @@ function (::Type{Sparse}){Tv<:VTypes}(A::SparseMatrixCSC{Tv,SuiteSparse_long}, s end # convert SparseVectors into CHOLMOD Sparse types through a mx1 CSC matrix -convert{Tv<:VTypes}(::Type{Sparse}, A::SparseVector{Tv,SuiteSparse_long}) = +convert(::Type{Sparse}, A::SparseVector{<:VTypes,SuiteSparse_long}) = convert(Sparse, convert(SparseMatrixCSC, A)) -function convert{Tv<:VTypes,Ti<:ITypes}(::Type{Sparse}, A::SparseMatrixCSC{Tv,Ti}) +function convert(::Type{Sparse}, A::SparseMatrixCSC{<:VTypes,<:ITypes}) o = Sparse(A, 0) # check if array is symmetric and change stype if it is if ishermitian(o) @@ -924,7 +924,7 @@ function convert{Tv<:VTypes,Ti<:ITypes}(::Type{Sparse}, A::SparseMatrixCSC{Tv,Ti end o end -convert{Ti<:ITypes}(::Type{Sparse}, A::SparseMatrixCSC{Complex{Float32},Ti}) = +convert(::Type{Sparse}, A::SparseMatrixCSC{Complex{Float32},<:ITypes}) = convert(Sparse, convert(SparseMatrixCSC{Complex{Float64},SuiteSparse_long}, A)) convert(::Type{Sparse}, A::Symmetric{Float64,SparseMatrixCSC{Float64,SuiteSparse_long}}) = Sparse(A.data, A.uplo == 'L' ? -1 : 1) @@ -1302,7 +1302,7 @@ Ac_mul_B(A::Sparse, B::VecOrMat) = Ac_mul_B(A, Dense(B)) ## Factorization methods ## Compute that symbolic factorization only -function fact_{Tv<:VTypes}(A::Sparse{Tv}, cm::Array{UInt8}; +function fact_(A::Sparse{<:VTypes}, cm::Array{UInt8}; perm::AbstractVector{SuiteSparse_long}=SuiteSparse_long[], postorder::Bool=true, userperm_only::Bool=true) @@ -1645,7 +1645,7 @@ end det(L::Factor) = exp(logdet(L)) -function isposdef{Tv<:VTypes}(A::SparseMatrixCSC{Tv,SuiteSparse_long}) +function isposdef(A::SparseMatrixCSC{<:VTypes,SuiteSparse_long}) if !ishermitian(A) return false end diff --git a/base/sparse/higherorderfns.jl b/base/sparse/higherorderfns.jl index ea947b9336eba..5e7bb579f600e 100644 --- a/base/sparse/higherorderfns.jl +++ b/base/sparse/higherorderfns.jl @@ -941,7 +941,7 @@ end # broadcast shape promotion for combinations of sparse arrays and other types broadcast_indices(::Type{AbstractSparseArray}, A) = indices(A) # broadcast container type promotion for combinations of sparse arrays and other types -_containertype{T<:SparseVecOrMat}(::Type{T}) = AbstractSparseArray +_containertype(::Type{<:SparseVecOrMat}) = AbstractSparseArray # combinations of sparse arrays with broadcast scalars should yield sparse arrays promote_containertype(::Type{Any}, ::Type{AbstractSparseArray}) = AbstractSparseArray promote_containertype(::Type{AbstractSparseArray}, ::Type{Any}) = AbstractSparseArray @@ -1006,7 +1006,7 @@ immutable PromoteToSparse end # broadcast containertype definitions for structured matrices StructuredMatrix = Union{Diagonal,Bidiagonal,Tridiagonal,SymTridiagonal} -_containertype{T<:StructuredMatrix}(::Type{T}) = PromoteToSparse +_containertype(::Type{<:StructuredMatrix}) = PromoteToSparse # combinations explicitly involving Tuples and PromoteToSparse collections # divert to the generic AbstractArray broadcast code @@ -1029,13 +1029,13 @@ promote_containertype(::Type{Array}, ::Type{AbstractSparseArray}) = PromoteToSpa # mostly just disambiguates Array from the main containertype promotion mechanism # AbstractArray serves as a marker to shunt to the generic AbstractArray broadcast code _spcontainertype(x) = _containertype(x) -_spcontainertype{T<:Vector}(::Type{T}) = Vector -_spcontainertype{T<:Matrix}(::Type{T}) = Matrix -_spcontainertype{T<:Ref}(::Type{T}) = AbstractArray -_spcontainertype{T<:AbstractArray}(::Type{T}) = AbstractArray +_spcontainertype(::Type{<:Vector}) = Vector +_spcontainertype(::Type{<:Matrix}) = Matrix +_spcontainertype(::Type{<:Ref}) = AbstractArray +_spcontainertype(::Type{<:AbstractArray}) = AbstractArray # need the following two methods to override the immediately preceding method -_spcontainertype{T<:StructuredMatrix}(::Type{T}) = PromoteToSparse -_spcontainertype{T<:SparseVecOrMat}(::Type{T}) = AbstractSparseArray +_spcontainertype(::Type{<:StructuredMatrix}) = PromoteToSparse +_spcontainertype(::Type{<:SparseVecOrMat}) = AbstractSparseArray spcontainertype(x) = _spcontainertype(typeof(x)) spcontainertype(ct1, ct2) = promote_spcontainertype(spcontainertype(ct1), spcontainertype(ct2)) @inline spcontainertype(ct1, ct2, cts...) = promote_spcontainertype(spcontainertype(ct1), spcontainertype(ct2, cts...)) @@ -1043,13 +1043,13 @@ spcontainertype(ct1, ct2) = promote_spcontainertype(spcontainertype(ct1), spcont promote_spcontainertype{T}(::Type{T}, ::Type{T}) = T # combinations involving AbstractArrays and/or Tuples divert to the generic AbstractArray broadcast code DivertToAbsArrayBC = Union{Type{AbstractArray},Type{Tuple}} -promote_spcontainertype{T<:DivertToAbsArrayBC}(::T, ct) = AbstractArray -promote_spcontainertype{T<:DivertToAbsArrayBC}(ct, ::T) = AbstractArray -promote_spcontainertype{S<:DivertToAbsArrayBC,T<:DivertToAbsArrayBC}(::S, ::T) = AbstractArray +promote_spcontainertype(::DivertToAbsArrayBC, ct) = AbstractArray +promote_spcontainertype(ct, ::DivertToAbsArrayBC) = AbstractArray +promote_spcontainertype(::DivertToAbsArrayBC, ::DivertToAbsArrayBC) = AbstractArray # combinations involving scalars, sparse arrays, structured matrices (PromoteToSparse), # dense vectors/matrices, and PromoteToSparse collections continue in the promote-to-sparse funnel FunnelToSparseBC = Union{Type{Any},Type{Vector},Type{Matrix},Type{PromoteToSparse},Type{AbstractSparseArray}} -promote_spcontainertype{S<:FunnelToSparseBC,T<:FunnelToSparseBC}(::S, ::T) = PromoteToSparse +promote_spcontainertype(::FunnelToSparseBC, ::FunnelToSparseBC) = PromoteToSparse # first (Broadcast containertype) dispatch layer diff --git a/base/sparse/linalg.jl b/base/sparse/linalg.jl index 477757b6f280b..6884421febf0b 100644 --- a/base/sparse/linalg.jl +++ b/base/sparse/linalg.jl @@ -9,14 +9,14 @@ function decrement!{T<:Integer}(A::AbstractArray{T}) for i in 1:length(A); A[i] -= oneunit(T) end A end -decrement{T<:Integer}(A::AbstractArray{T}) = decrement!(copy(A)) +decrement(A::AbstractArray{<:Integer}) = decrement!(copy(A)) # Convert from 0-based to 1-based indices function increment!{T<:Integer}(A::AbstractArray{T}) for i in 1:length(A); A[i] += oneunit(T) end A end -increment{T<:Integer}(A::AbstractArray{T}) = increment!(copy(A)) +increment(A::AbstractArray{<:Integer}) = increment!(copy(A)) ## sparse matrix multiplication @@ -284,11 +284,11 @@ function bwdTriSolve!(A::SparseMatrixCSC, B::AbstractVecOrMat) B end -A_ldiv_B!{T,Ti}(L::LowerTriangular{T,SparseMatrixCSC{T,Ti}}, B::StridedVecOrMat) = fwdTriSolve!(L.data, B) -A_ldiv_B!{T,Ti}(U::UpperTriangular{T,SparseMatrixCSC{T,Ti}}, B::StridedVecOrMat) = bwdTriSolve!(U.data, B) +A_ldiv_B!{T}(L::LowerTriangular{T,<:SparseMatrixCSC{T}}, B::StridedVecOrMat) = fwdTriSolve!(L.data, B) +A_ldiv_B!{T}(U::UpperTriangular{T,<:SparseMatrixCSC{T}}, B::StridedVecOrMat) = bwdTriSolve!(U.data, B) -(\){T,Ti}(L::LowerTriangular{T,SparseMatrixCSC{T,Ti}}, B::SparseMatrixCSC) = A_ldiv_B!(L, Array(B)) -(\){T,Ti}(U::UpperTriangular{T,SparseMatrixCSC{T,Ti}}, B::SparseMatrixCSC) = A_ldiv_B!(U, Array(B)) +(\){T}(L::LowerTriangular{T,<:SparseMatrixCSC{T}}, B::SparseMatrixCSC) = A_ldiv_B!(L, Array(B)) +(\){T}(U::UpperTriangular{T,<:SparseMatrixCSC{T}}, B::SparseMatrixCSC) = A_ldiv_B!(U, Array(B)) ## triu, tril diff --git a/base/sparse/sparsematrix.jl b/base/sparse/sparsematrix.jl index 7ebaae7c0b5fd..a6a2e539c59b8 100644 --- a/base/sparse/sparsematrix.jl +++ b/base/sparse/sparsematrix.jl @@ -161,7 +161,7 @@ end ## Reinterpret and Reshape -function reinterpret{T,Tv,Ti}(::Type{T}, a::SparseMatrixCSC{Tv,Ti}) +function reinterpret{T,Tv}(::Type{T}, a::SparseMatrixCSC{Tv}) if sizeof(T) != sizeof(Tv) throw(ArgumentError("SparseMatrixCSC reinterpret is only supported for element types of the same size")) end @@ -223,7 +223,7 @@ function reinterpret{T,Tv,Ti,N}(::Type{T}, a::SparseMatrixCSC{Tv,Ti}, dims::NTup return SparseMatrixCSC(mS, nS, colptr, rowval, nzval) end -function copy{T,P<:SparseMatrixCSC}(ra::ReshapedArray{T,2,P}) +function copy(ra::ReshapedArray{<:Any,2,<:SparseMatrixCSC}) mS,nS = size(ra) a = parent(ra) mA,nA = size(a) @@ -291,7 +291,7 @@ function copy!(A::SparseMatrixCSC, B::SparseMatrixCSC) end similar(S::SparseMatrixCSC, Tv::Type=eltype(S)) = SparseMatrixCSC(S.m, S.n, copy(S.colptr), copy(S.rowval), Array{Tv}(length(S.nzval))) -similar{Tv,Ti,TvNew,TiNew}(S::SparseMatrixCSC{Tv,Ti}, ::Type{TvNew}, ::Type{TiNew}) = SparseMatrixCSC(S.m, S.n, convert(Array{TiNew},S.colptr), convert(Array{TiNew}, S.rowval), Array{TvNew}(length(S.nzval))) +similar{Tv,Ti}(S::SparseMatrixCSC, ::Type{Tv}, ::Type{Ti}) = SparseMatrixCSC(S.m, S.n, convert(Array{Ti}, S.colptr), convert(Array{Ti}, S.rowval), Array{Tv}(length(S.nzval))) @inline similar{Tv}(S::SparseMatrixCSC, ::Type{Tv}, d::Dims) = spzeros(Tv, d...) # convert'ing between SparseMatrixCSC types @@ -704,8 +704,8 @@ end ## Transposition and permutation methods """ - halfperm!{Tv,Ti,Tq<:Integer}(X::SparseMatrixCSC{Tv,Ti}, A::SparseMatrixCSC{Tv,Ti}, - q::AbstractVector{Tq}, f::Function = identity) + halfperm!{Tv,Ti}(X::SparseMatrixCSC{Tv,Ti}, A::SparseMatrixCSC{Tv,Ti}, + q::AbstractVector{<:Integer}, f::Function = identity) Column-permute and transpose `A`, simultaneously applying `f` to each entry of `A`, storing the result `(f(A)Q)^T` (`map(f, transpose(A[:,q]))`) in `X`. @@ -724,8 +724,8 @@ algorithms for sparse matrices: multiplication and permuted transposition," ACM 250-269 (1978). The algorithm runs in `O(A.m, A.n, nnz(A))` time and requires no space beyond that passed in. """ -function halfperm!{Tv,Ti,Tq<:Integer}(X::SparseMatrixCSC{Tv,Ti}, A::SparseMatrixCSC{Tv,Ti}, - q::AbstractVector{Tq}, f::Function = identity) +function halfperm!{Tv,Ti}(X::SparseMatrixCSC{Tv,Ti}, A::SparseMatrixCSC{Tv,Ti}, + q::AbstractVector{<:Integer}, f::Function = identity) _computecolptrs_halfperm!(X, A) _distributevals_halfperm!(X, A, q, f) return X @@ -755,8 +755,8 @@ position forward in `X.colptr`, computes `map(f, transpose(A[:,q]))` by appropri distributing `A.rowval` and `f`-transformed `A.nzval` into `X.rowval` and `X.nzval` respectively. Simultaneously fixes the one-position-forward shift in `X.colptr`. """ -function _distributevals_halfperm!{Tv,Ti,Tq<:Integer}(X::SparseMatrixCSC{Tv,Ti}, - A::SparseMatrixCSC{Tv,Ti}, q::AbstractVector{Tq}, f::Function) +function _distributevals_halfperm!{Tv,Ti}(X::SparseMatrixCSC{Tv,Ti}, + A::SparseMatrixCSC{Tv,Ti}, q::AbstractVector{<:Integer}, f::Function) @inbounds for Xi in 1:A.n Aj = q[Xi] for Ak in nzrange(A, Aj) @@ -796,13 +796,13 @@ function ftranspose{Tv,Ti}(A::SparseMatrixCSC{Tv,Ti}, f::Function) X = SparseMatrixCSC(A.n, A.m, Vector{Ti}(A.m+1), Vector{Ti}(nnz(A)), Vector{Tv}(nnz(A))) halfperm!(X, A, 1:A.n, f) end -transpose{Tv,Ti}(A::SparseMatrixCSC{Tv,Ti}) = ftranspose(A, identity) -ctranspose{Tv,Ti}(A::SparseMatrixCSC{Tv,Ti}) = ftranspose(A, conj) +transpose(A::SparseMatrixCSC) = ftranspose(A, identity) +ctranspose(A::SparseMatrixCSC) = ftranspose(A, conj) """ - unchecked_noalias_permute!{Tv,Ti,Tp<:Integer,Tq<:Integer}(X::SparseMatrixCSC{Tv,Ti}, - A::SparseMatrixCSC{Tv,Ti}, p::AbstractVector{Tp}, q::AbstractVector{Tq}, - C::SparseMatrixCSC{Tv,Ti}) + unchecked_noalias_permute!{Tv,Ti}(X::SparseMatrixCSC{Tv,Ti}, + A::SparseMatrixCSC{Tv,Ti}, p::AbstractVector{<:Integer}, + q::AbstractVector{<:Integer}, C::SparseMatrixCSC{Tv,Ti}) See [`permute!`](@ref) for basic usage. Parent of `permute[!]` methods operating on `SparseMatrixCSC`s that assume none of `X`, `A`, and `C` alias each @@ -821,17 +821,17 @@ information. See also: `unchecked_aliasing_permute!` """ -function unchecked_noalias_permute!{Tv,Ti,Tp<:Integer,Tq<:Integer}(X::SparseMatrixCSC{Tv,Ti}, - A::SparseMatrixCSC{Tv,Ti}, p::AbstractVector{Tp}, q::AbstractVector{Tq}, - C::SparseMatrixCSC{Tv,Ti}) +function unchecked_noalias_permute!{Tv,Ti}(X::SparseMatrixCSC{Tv,Ti}, + A::SparseMatrixCSC{Tv,Ti}, p::AbstractVector{<:Integer}, + q::AbstractVector{<:Integer}, C::SparseMatrixCSC{Tv,Ti}) halfperm!(C, A, q) _computecolptrs_permute!(X, A, q, X.colptr) _distributevals_halfperm!(X, C, p, identity) return X end """ - unchecked_aliasing_permute!{Tv,Ti,Tp<:Integer,Tq<:Integer}( - A::SparseMatrixCSC{Tv,Ti}, p::AbstractVector{Tp}, q::AbstractVector{Tq}, + unchecked_aliasing_permute!{Tv,Ti}(A::SparseMatrixCSC{Tv,Ti}, + p::AbstractVector{<:Integer}, q::AbstractVector{<:Integer}, C::SparseMatrixCSC{Tv,Ti}, workcolptr::Vector{Ti}) See [`permute!`](@ref) for basic usage. Parent of `permute!` @@ -841,8 +841,8 @@ for additional information; these methods are identical but for this method's re the additional `workcolptr`, `length(workcolptr) >= A.n + 1`, which enables efficient handling of the source-destination aliasing. """ -function unchecked_aliasing_permute!{Tv,Ti,Tp<:Integer,Tq<:Integer}( - A::SparseMatrixCSC{Tv,Ti}, p::AbstractVector{Tp}, q::AbstractVector{Tq}, +function unchecked_aliasing_permute!{Tv,Ti}(A::SparseMatrixCSC{Tv,Ti}, + p::AbstractVector{<:Integer}, q::AbstractVector{<:Integer}, C::SparseMatrixCSC{Tv,Ti}, workcolptr::Vector{Ti}) halfperm!(C, A, q) _computecolptrs_permute!(A, A, q, workcolptr) @@ -855,8 +855,8 @@ Computes `PAQ`'s column pointers, storing them shifted one position forward in ` `_distributevals_halfperm!` fixes this shift. Saves some work relative to `_computecolptrs_halfperm!` as described in `uncheckednoalias_permute!`'s documentation. """ -function _computecolptrs_permute!{Tv,Ti,Tq<:Integer}(X::SparseMatrixCSC{Tv,Ti}, - A::SparseMatrixCSC{Tv,Ti}, q::AbstractVector{Tq}, workcolptr::Vector{Ti}) +function _computecolptrs_permute!{Tv,Ti}(X::SparseMatrixCSC{Tv,Ti}, + A::SparseMatrixCSC{Tv,Ti}, q::AbstractVector{<:Integer}, workcolptr::Vector{Ti}) # Compute `A[p,q]`'s column counts. Store shifted forward one position in workcolptr. @inbounds for k in 1:A.n workcolptr[k+1] = A.colptr[q[k] + 1] - A.colptr[q[k]] @@ -876,8 +876,8 @@ Helper method for `permute` and `permute!` methods operating on `SparseMatrixCSC Checks compatibility of source argument `A`, row-permutation argument `p`, and column-permutation argument `q`. """ -function _checkargs_sourcecompatperms_permute!{Tv,Ti,Tp<:Integer,Tq<:Integer}( - A::SparseMatrixCSC{Tv,Ti}, p::AbstractVector{Tp}, q::AbstractVector{Tq}) +function _checkargs_sourcecompatperms_permute!(A::SparseMatrixCSC, + p::AbstractVector{<:Integer}, q::AbstractVector{<:Integer}) if length(q) != A.n throw(DimensionMismatch(string("the length of column-permutation argument `q`, ", "`length(q) (= $(length(q)))`, must match source argument `A`'s column ", @@ -892,17 +892,17 @@ end Helper method for `permute` and `permute!` methods operating on `SparseMatrixCSC`s. Checks whether row- and column- permutation arguments `p` and `q` are valid permutations. """ -function _checkargs_permutationsvalid_permute!{Ti<:Integer,Tp<:Integer,Tq<:Integer}( - p::AbstractVector{Tp}, pcheckspace::Vector{Ti}, - q::AbstractVector{Tq}, qcheckspace::Vector{Ti}) +function _checkargs_permutationsvalid_permute!{Ti<:Integer}( + p::AbstractVector{<:Integer}, pcheckspace::Vector{Ti}, + q::AbstractVector{<:Integer}, qcheckspace::Vector{Ti}) if !_ispermutationvalid_permute!(p, pcheckspace) throw(ArgumentError("row-permutation argument `p` must be a valid permutation")) elseif !_ispermutationvalid_permute!(q, qcheckspace) throw(ArgumentError("column-permutation argument `q` must be a valid permutation")) end end -function _ispermutationvalid_permute!{Ti<:Integer,Tp<:Integer}(perm::AbstractVector{Tp}, - checkspace::Vector{Ti}) +function _ispermutationvalid_permute!(perm::AbstractVector{<:Integer}, + checkspace::Vector{<:Integer}) n = length(perm) checkspace[1:n] = 0 for k in perm @@ -967,16 +967,16 @@ function _checkargs_sourcecompatworkcolptr_permute!{Tv,Ti}(A::SparseMatrixCSC{Tv end end """ - permute!{Tv,Ti,Tp<:Integer,Tq<:Integer}(X::SparseMatrixCSC{Tv,Ti}, A::SparseMatrixCSC{Tv,Ti}, - p::AbstractVector{Tp}, q::AbstractVector{Tq}[, C::SparseMatrixCSC{Tv,Ti}]) + permute!{Tv,Ti}(X::SparseMatrixCSC{Tv,Ti}, A::SparseMatrixCSC{Tv,Ti}, + p::AbstractVector{<:Integer}, q::AbstractVector{<:Integer}[, C::SparseMatrixCSC{Tv,Ti}]) Bilaterally permute `A`, storing result `PAQ` (`A[p,q]`) in `X`. Stores intermediate result `(AQ)^T` (`transpose(A[:,q])`) in optional argument `C` if present. Requires that none of `X`, `A`, and, if present, `C` alias each other; to store result `PAQ` back into `A`, use the following method lacking `X`: - permute!{Tv,Ti,Tp<:Integer,Tq<:Integer}(A::SparseMatrixCSC{Tv,Ti}, p::AbstractVector{Tp}, - q::AbstractVector{Tq}[, C::SparseMatrixCSC{Tv,Ti}[, workcolptr::Vector{Ti}]]) + permute!{Tv,Ti}(A::SparseMatrixCSC{Tv,Ti}, p::AbstractVector{<:Integer}, + q::AbstractVector{<:Integer}[, C::SparseMatrixCSC{Tv,Ti}[, workcolptr::Vector{Ti}]]) `X`'s dimensions must match those of `A` (`X.m == A.m` and `X.n == A.n`), and `X` must have enough storage to accommodate all allocated entries in `A` (`length(X.rowval) >= nnz(A)` @@ -994,16 +994,16 @@ and `unchecked_aliasing_permute!`. See also: [`permute`](@ref) """ -function permute!{Tv,Ti,Tp<:Integer,Tq<:Integer}(X::SparseMatrixCSC{Tv,Ti}, - A::SparseMatrixCSC{Tv,Ti}, p::AbstractVector{Tp}, q::AbstractVector{Tq}) +function permute!{Tv,Ti}(X::SparseMatrixCSC{Tv,Ti}, A::SparseMatrixCSC{Tv,Ti}, + p::AbstractVector{<:Integer}, q::AbstractVector{<:Integer}) _checkargs_sourcecompatdest_permute!(A, X) _checkargs_sourcecompatperms_permute!(A, p, q) C = SparseMatrixCSC(A.n, A.m, Vector{Ti}(A.m + 1), Vector{Ti}(nnz(A)), Vector{Tv}(nnz(A))) _checkargs_permutationsvalid_permute!(p, C.colptr, q, X.colptr) unchecked_noalias_permute!(X, A, p, q, C) end -function permute!{Tv,Ti,Tp<:Integer,Tq<:Integer}(X::SparseMatrixCSC{Tv,Ti}, - A::SparseMatrixCSC{Tv,Ti}, p::AbstractVector{Tp}, q::AbstractVector{Tq}, +function permute!{Tv,Ti}(X::SparseMatrixCSC{Tv,Ti}, A::SparseMatrixCSC{Tv,Ti}, + p::AbstractVector{<:Integer}, q::AbstractVector{<:Integer}, C::SparseMatrixCSC{Tv,Ti}) _checkargs_sourcecompatdest_permute!(A, X) _checkargs_sourcecompatperms_permute!(A, p, q) @@ -1011,24 +1011,24 @@ function permute!{Tv,Ti,Tp<:Integer,Tq<:Integer}(X::SparseMatrixCSC{Tv,Ti}, _checkargs_permutationsvalid_permute!(p, C.colptr, q, X.colptr) unchecked_noalias_permute!(X, A, p, q, C) end -function permute!{Tv,Ti,Tp<:Integer,Tq<:Integer}(A::SparseMatrixCSC{Tv,Ti}, - p::AbstractVector{Tp}, q::AbstractVector{Tq}) +function permute!{Tv,Ti}(A::SparseMatrixCSC{Tv,Ti}, p::AbstractVector{<:Integer}, + q::AbstractVector{<:Integer}) _checkargs_sourcecompatperms_permute!(A, p, q) C = SparseMatrixCSC(A.n, A.m, Vector{Ti}(A.m + 1), Vector{Ti}(nnz(A)), Vector{Tv}(nnz(A))) workcolptr = Vector{Ti}(A.n + 1) _checkargs_permutationsvalid_permute!(p, C.colptr, q, workcolptr) unchecked_aliasing_permute!(A, p, q, C, workcolptr) end -function permute!{Tv,Ti,Tp<:Integer,Tq<:Integer}(A::SparseMatrixCSC{Tv,Ti}, - p::AbstractVector{Tp}, q::AbstractVector{Tq}, C::SparseMatrixCSC{Tv,Ti}) +function permute!{Tv,Ti}(A::SparseMatrixCSC{Tv,Ti}, p::AbstractVector{<:Integer}, + q::AbstractVector{<:Integer}, C::SparseMatrixCSC{Tv,Ti}) _checkargs_sourcecompatperms_permute!(A, p, q) _checkargs_sourcecompatworkmat_permute!(A, C) workcolptr = Vector{Ti}(A.n + 1) _checkargs_permutationsvalid_permute!(p, C.colptr, q, workcolptr) unchecked_aliasing_permute!(A, p, q, C, workcolptr) end -function permute!{Tv,Ti,Tp<:Integer,Tq<:Integer}(A::SparseMatrixCSC{Tv,Ti}, - p::AbstractVector{Tp}, q::AbstractVector{Tq}, C::SparseMatrixCSC{Tv,Ti}, +function permute!{Tv,Ti}(A::SparseMatrixCSC{Tv,Ti}, p::AbstractVector{<:Integer}, + q::AbstractVector{<:Integer}, C::SparseMatrixCSC{Tv,Ti}, workcolptr::Vector{Ti}) _checkargs_sourcecompatperms_permute!(A, p, q) _checkargs_sourcecompatworkmat_permute!(A, C) @@ -1037,8 +1037,8 @@ function permute!{Tv,Ti,Tp<:Integer,Tq<:Integer}(A::SparseMatrixCSC{Tv,Ti}, unchecked_aliasing_permute!(A, p, q, C, workcolptr) end """ - permute{Tv,Ti,Tp<:Integer,Tq<:Integer}(A::SparseMatrixCSC{Tv,Ti}, p::AbstractVector{Tp}, - q::AbstractVector{Tq}) + permute{Tv,Ti}(A::SparseMatrixCSC{Tv,Ti}, p::AbstractVector{<:Integer}, + q::AbstractVector{<:Integer}) Bilaterally permute `A`, returning `PAQ` (`A[p,q]`). Column-permutation `q`'s length must match `A`'s column count (`length(q) == A.n`). Row-permutation `p`'s length must match `A`'s @@ -1046,8 +1046,8 @@ row count (`length(p) == A.m`). For expert drivers and additional information, see [`permute!`](@ref). """ -function permute{Tv,Ti,Tp<:Integer,Tq<:Integer}(A::SparseMatrixCSC{Tv,Ti}, - p::AbstractVector{Tp}, q::AbstractVector{Tq}) +function permute{Tv,Ti}(A::SparseMatrixCSC{Tv,Ti}, p::AbstractVector{<:Integer}, + q::AbstractVector{<:Integer}) _checkargs_sourcecompatperms_permute!(A, p, q) X = SparseMatrixCSC(A.m, A.n, Vector{Ti}(A.n + 1), Vector{Ti}(nnz(A)), Vector{Tv}(nnz(A))) C = SparseMatrixCSC(A.n, A.m, Vector{Ti}(A.m + 1), Vector{Ti}(nnz(A)), Vector{Tv}(nnz(A))) @@ -1733,8 +1733,8 @@ end findmin{Tv,Ti}(A::SparseMatrixCSC{Tv,Ti}, region) = @_findr(<, A, region, Tv, Ti) findmax{Tv,Ti}(A::SparseMatrixCSC{Tv,Ti}, region) = @_findr(>, A, region, Tv, Ti) -findmin{Tv,Ti}(A::SparseMatrixCSC{Tv,Ti}) = (r=findmin(A,(1,2)); (r[1][1], r[2][1])) -findmax{Tv,Ti}(A::SparseMatrixCSC{Tv,Ti}) = (r=findmax(A,(1,2)); (r[1][1], r[2][1])) +findmin(A::SparseMatrixCSC) = (r=findmin(A,(1,2)); (r[1][1], r[2][1])) +findmax(A::SparseMatrixCSC) = (r=findmax(A,(1,2)); (r[1][1], r[2][1])) indmin(A::SparseMatrixCSC) = findmin(A)[2] indmax(A::SparseMatrixCSC) = findmax(A)[2] @@ -2085,7 +2085,7 @@ function permute_rows!{Tv,Ti}(S::SparseMatrixCSC{Tv,Ti}, pI::Vector{Int}) S end -function getindex_general{Tv,Ti}(A::SparseMatrixCSC{Tv,Ti}, I::AbstractVector, J::AbstractVector) +function getindex_general(A::SparseMatrixCSC, I::AbstractVector, J::AbstractVector) pI = sortperm(I) @inbounds Is = I[pI] permute_rows!(getindex_I_sorted(A, Is, J), pI) @@ -2159,15 +2159,15 @@ function getindex{Tv}(A::SparseMatrixCSC{Tv}, I::AbstractArray) end # logical getindex -getindex{Tv,Ti<:Integer}(A::SparseMatrixCSC{Tv,Ti}, I::Range{Bool}, J::AbstractVector{Bool}) = error("Cannot index with Range{Bool}") -getindex{Tv,Ti<:Integer,T<:Integer}(A::SparseMatrixCSC{Tv,Ti}, I::Range{Bool}, J::AbstractVector{T}) = error("Cannot index with Range{Bool}") +getindex(A::SparseMatrixCSC{<:Any,<:Integer}, I::Range{Bool}, J::AbstractVector{Bool}) = error("Cannot index with Range{Bool}") +getindex(A::SparseMatrixCSC{<:Any,<:Integer}, I::Range{Bool}, J::AbstractVector{<:Integer}) = error("Cannot index with Range{Bool}") -getindex{T<:Integer}(A::SparseMatrixCSC, I::Range{T}, J::AbstractVector{Bool}) = A[I,find(J)] +getindex(A::SparseMatrixCSC, I::Range{<:Integer}, J::AbstractVector{Bool}) = A[I,find(J)] getindex(A::SparseMatrixCSC, I::Integer, J::AbstractVector{Bool}) = A[I,find(J)] getindex(A::SparseMatrixCSC, I::AbstractVector{Bool}, J::Integer) = A[find(I),J] getindex(A::SparseMatrixCSC, I::AbstractVector{Bool}, J::AbstractVector{Bool}) = A[find(I),find(J)] -getindex{T<:Integer}(A::SparseMatrixCSC, I::AbstractVector{T}, J::AbstractVector{Bool}) = A[I,find(J)] -getindex{T<:Integer}(A::SparseMatrixCSC, I::AbstractVector{Bool}, J::AbstractVector{T}) = A[find(I),J] +getindex(A::SparseMatrixCSC, I::AbstractVector{<:Integer}, J::AbstractVector{Bool}) = A[I,find(J)] +getindex(A::SparseMatrixCSC, I::AbstractVector{Bool}, J::AbstractVector{<:Integer}) = A[find(I),J] ## setindex! function setindex!{Tv,Ti}(A::SparseMatrixCSC{Tv,Ti}, v, i::Integer, j::Integer) @@ -2197,11 +2197,11 @@ function setindex!{Tv,Ti<:Integer}(A::SparseMatrixCSC{Tv,Ti}, v::Tv, i::Ti, j::T return A end -setindex!{T<:Integer}(A::SparseMatrixCSC, v::AbstractMatrix, i::Integer, J::AbstractVector{T}) = setindex!(A, v, [i], J) -setindex!{T<:Integer}(A::SparseMatrixCSC, v::AbstractMatrix, I::AbstractVector{T}, j::Integer) = setindex!(A, v, I, [j]) +setindex!(A::SparseMatrixCSC, v::AbstractMatrix, i::Integer, J::AbstractVector{<:Integer}) = setindex!(A, v, [i], J) +setindex!(A::SparseMatrixCSC, v::AbstractMatrix, I::AbstractVector{<:Integer}, j::Integer) = setindex!(A, v, I, [j]) -setindex!{T<:Integer}(A::SparseMatrixCSC, x::Number, i::Integer, J::AbstractVector{T}) = setindex!(A, x, [i], J) -setindex!{T<:Integer}(A::SparseMatrixCSC, x::Number, I::AbstractVector{T}, j::Integer) = setindex!(A, x, I, [j]) +setindex!(A::SparseMatrixCSC, x::Number, i::Integer, J::AbstractVector{<:Integer}) = setindex!(A, x, [i], J) +setindex!(A::SparseMatrixCSC, x::Number, I::AbstractVector{<:Integer}, j::Integer) = setindex!(A, x, I, [j]) # Colon translation setindex!(A::SparseMatrixCSC, x, ::Colon) = setindex!(A, x, 1:length(A)) @@ -2209,8 +2209,8 @@ setindex!(A::SparseMatrixCSC, x, ::Colon, ::Colon) = setindex!(A, x, 1:size(A, 1 setindex!(A::SparseMatrixCSC, x, ::Colon, j::Union{Integer, AbstractVector}) = setindex!(A, x, 1:size(A, 1), j) setindex!(A::SparseMatrixCSC, x, i::Union{Integer, AbstractVector}, ::Colon) = setindex!(A, x, i, 1:size(A, 2)) -function setindex!{TvA,TiI<:Integer,TiJ<:Integer}(A::SparseMatrixCSC{TvA}, x::Number, - I::AbstractVector{TiI}, J::AbstractVector{TiJ}) +function setindex!{Tv}(A::SparseMatrixCSC{Tv}, x::Number, + I::AbstractVector{<:Integer}, J::AbstractVector{<:Integer}) if isempty(I) || isempty(J); return A; end if !issorted(I); I = sort(I); end if !issorted(J); J = sort(J); end @@ -2220,15 +2220,15 @@ function setindex!{TvA,TiI<:Integer,TiJ<:Integer}(A::SparseMatrixCSC{TvA}, x::Nu if x == 0 _spsetz_setindex!(A, I, J) else - _spsetnz_setindex!(A, convert(TvA, x), I, J) + _spsetnz_setindex!(A, convert(Tv, x), I, J) end end """ Helper method for immediately preceding setindex! method. For all (i,j) such that i in I and j in J, assigns zero to A[i,j] if A[i,j] is a presently-stored entry, and otherwise does nothing. """ -function _spsetz_setindex!{TvA,TiI<:Integer,TiJ<:Integer}(A::SparseMatrixCSC{TvA}, - I::AbstractVector{TiI}, J::AbstractVector{TiJ}) +function _spsetz_setindex!(A::SparseMatrixCSC, + I::AbstractVector{<:Integer}, J::AbstractVector{<:Integer}) lengthI = length(I) for j in J coljAfirstk = A.colptr[j] @@ -2263,8 +2263,8 @@ Helper method for immediately preceding setindex! method. For all (i,j) such tha and j in J, assigns x to A[i,j] if A[i,j] is a presently-stored entry, and allocates and assigns x to A[i,j] if A[i,j] is not presently stored. """ -function _spsetnz_setindex!{Tv,TiI<:Integer,TiJ<:Integer}(A::SparseMatrixCSC{Tv}, x::Tv, - I::AbstractVector{TiI}, J::AbstractVector{TiJ}) +function _spsetnz_setindex!{Tv}(A::SparseMatrixCSC{Tv}, x::Tv, + I::AbstractVector{<:Integer}, J::AbstractVector{<:Integer}) m, n = size(A) lenI = length(I) @@ -2372,9 +2372,9 @@ end setindex!{Tv,Ti,T<:Integer}(A::SparseMatrixCSC{Tv,Ti}, S::Matrix, I::AbstractVector{T}, J::AbstractVector{T}) = setindex!(A, convert(SparseMatrixCSC{Tv,Ti}, S), I, J) -setindex!{Tv,Ti,T<:Integer}(A::SparseMatrixCSC{Tv,Ti}, v::AbstractVector, I::AbstractVector{T}, j::Integer) = setindex!(A, v, I, [j]) -setindex!{Tv,Ti,T<:Integer}(A::SparseMatrixCSC{Tv,Ti}, v::AbstractVector, i::Integer, J::AbstractVector{T}) = setindex!(A, v, [i], J) -setindex!{Tv,Ti,T<:Integer}(A::SparseMatrixCSC{Tv,Ti}, v::AbstractVector, I::AbstractVector{T}, J::AbstractVector{T}) = +setindex!(A::SparseMatrixCSC, v::AbstractVector, I::AbstractVector{<:Integer}, j::Integer) = setindex!(A, v, I, [j]) +setindex!(A::SparseMatrixCSC, v::AbstractVector, i::Integer, J::AbstractVector{<:Integer}) = setindex!(A, v, [i], J) +setindex!{T<:Integer}(A::SparseMatrixCSC, v::AbstractVector, I::AbstractVector{T}, J::AbstractVector{T}) = setindex!(A, reshape(v, length(I), length(J)), I, J) @@ -2509,17 +2509,17 @@ end setindex!(A::SparseMatrixCSC, x::Matrix, I::Integer, J::AbstractVector{Bool}) = setindex!(A, sparse(x), I, find(J)) setindex!(A::SparseMatrixCSC, x::Matrix, I::AbstractVector{Bool}, J::Integer) = setindex!(A, sparse(x), find(I), J) setindex!(A::SparseMatrixCSC, x::Matrix, I::AbstractVector{Bool}, J::AbstractVector{Bool}) = setindex!(A, sparse(x), find(I), find(J)) -setindex!{T<:Integer}(A::SparseMatrixCSC, x::Matrix, I::AbstractVector{T}, J::AbstractVector{Bool}) = setindex!(A, sparse(x), I, find(J)) -setindex!{T<:Integer}(A::SparseMatrixCSC, x::Matrix, I::AbstractVector{Bool}, J::AbstractVector{T}) = setindex!(A, sparse(x), find(I),J) +setindex!(A::SparseMatrixCSC, x::Matrix, I::AbstractVector{<:Integer}, J::AbstractVector{Bool}) = setindex!(A, sparse(x), I, find(J)) +setindex!(A::SparseMatrixCSC, x::Matrix, I::AbstractVector{Bool}, J::AbstractVector{<:Integer}) = setindex!(A, sparse(x), find(I),J) setindex!(A::Matrix, x::SparseMatrixCSC, I::Integer, J::AbstractVector{Bool}) = setindex!(A, Array(x), I, find(J)) setindex!(A::Matrix, x::SparseMatrixCSC, I::AbstractVector{Bool}, J::Integer) = setindex!(A, Array(x), find(I), J) setindex!(A::Matrix, x::SparseMatrixCSC, I::AbstractVector{Bool}, J::AbstractVector{Bool}) = setindex!(A, Array(x), find(I), find(J)) -setindex!{T<:Integer}(A::Matrix, x::SparseMatrixCSC, I::AbstractVector{T}, J::AbstractVector{Bool}) = setindex!(A, Array(x), I, find(J)) -setindex!{T<:Integer}(A::Matrix, x::SparseMatrixCSC, I::AbstractVector{Bool}, J::AbstractVector{T}) = setindex!(A, Array(x), find(I), J) +setindex!(A::Matrix, x::SparseMatrixCSC, I::AbstractVector{<:Integer}, J::AbstractVector{Bool}) = setindex!(A, Array(x), I, find(J)) +setindex!(A::Matrix, x::SparseMatrixCSC, I::AbstractVector{Bool}, J::AbstractVector{<:Integer}) = setindex!(A, Array(x), find(I), J) -setindex!{Tv,Ti}(A::SparseMatrixCSC{Tv,Ti}, x, I::AbstractVector{Bool}) = throw(BoundsError()) -function setindex!{Tv,Ti}(A::SparseMatrixCSC{Tv,Ti}, x, I::AbstractMatrix{Bool}) +setindex!(A::SparseMatrixCSC, x, I::AbstractVector{Bool}) = throw(BoundsError()) +function setindex!(A::SparseMatrixCSC, x, I::AbstractMatrix{Bool}) checkbounds(A, I) n = sum(I) (n == 0) && (return A) @@ -2620,7 +2620,7 @@ function setindex!{Tv,Ti}(A::SparseMatrixCSC{Tv,Ti}, x, I::AbstractMatrix{Bool}) end -function setindex!{Tv,Ti,T<:Real}(A::SparseMatrixCSC{Tv,Ti}, x, I::AbstractVector{T}) +function setindex!(A::SparseMatrixCSC, x, I::AbstractVector{<:Real}) n = length(I) (n == 0) && (return A) @@ -2760,8 +2760,8 @@ stored and otherwise do nothing. Derivative forms: dropstored!(A::SparseMatrixCSC, i::Integer, J::AbstractVector{<:Integer}) dropstored!(A::SparseMatrixCSC, I::AbstractVector{<:Integer}, j::Integer) """ -function dropstored!{TiI<:Integer,TiJ<:Integer}(A::SparseMatrixCSC, - I::AbstractVector{TiI}, J::AbstractVector{TiJ}) +function dropstored!(A::SparseMatrixCSC, + I::AbstractVector{<:Integer}, J::AbstractVector{<:Integer}) m, n = size(A) nnzA = nnz(A) (nnzA == 0) && (return A) @@ -2820,8 +2820,8 @@ function dropstored!{TiI<:Integer,TiJ<:Integer}(A::SparseMatrixCSC, end return A end -dropstored!{T<:Integer}(A::SparseMatrixCSC, i::Integer, J::AbstractVector{T}) = dropstored!(A, [i], J) -dropstored!{T<:Integer}(A::SparseMatrixCSC, I::AbstractVector{T}, j::Integer) = dropstored!(A, I, [j]) +dropstored!(A::SparseMatrixCSC, i::Integer, J::AbstractVector{<:Integer}) = dropstored!(A, [i], J) +dropstored!(A::SparseMatrixCSC, I::AbstractVector{<:Integer}, j::Integer) = dropstored!(A, I, [j]) dropstored!(A::SparseMatrixCSC, ::Colon, j::Union{Integer,AbstractVector}) = dropstored!(A, 1:size(A,1), j) dropstored!(A::SparseMatrixCSC, i::Union{Integer,AbstractVector}, ::Colon) = dropstored!(A, i, 1:size(A,2)) dropstored!(A::SparseMatrixCSC, ::Colon, ::Colon) = dropstored!(A, 1:size(A,1), 1:size(A,2)) @@ -3054,7 +3054,7 @@ function is_hermsym(A::SparseMatrixCSC, check::Function) return true end -function istriu{Tv}(A::SparseMatrixCSC{Tv}) +function istriu(A::SparseMatrixCSC) m, n = size(A) colptr = A.colptr rowval = A.rowval @@ -3074,7 +3074,7 @@ function istriu{Tv}(A::SparseMatrixCSC{Tv}) return true end -function istril{Tv}(A::SparseMatrixCSC{Tv}) +function istril(A::SparseMatrixCSC) m, n = size(A) colptr = A.colptr rowval = A.rowval @@ -3169,7 +3169,7 @@ spdiagm(B::AbstractVector, d::Number, m::Integer, n::Integer) = spdiagm((B,), (d spdiagm(B::AbstractVector, d::Number=0) = spdiagm((B,), (d,)) ## expand a colptr or rowptr into a dense index vector -function expandptr{T<:Integer}(V::Vector{T}) +function expandptr(V::Vector{<:Integer}) if V[1] != 1 throw(ArgumentError("first index must be one")) end res = similar(V, (Int64(V[end]-1),)) for i in 1:(length(V)-1), j in V[i]:(V[i+1] - 1); res[j] = i end diff --git a/base/sparse/sparsevector.jl b/base/sparse/sparsevector.jl index f9478910d66f7..cdaae7693d831 100644 --- a/base/sparse/sparsevector.jl +++ b/base/sparse/sparsevector.jl @@ -47,7 +47,7 @@ spones{T}(x::SparseVector{T}) = SparseVector(x.n, copy(x.nzind), ones(T, length( ### Construction from lists of indices and values -function _sparsevector!{Ti<:Integer}(I::Vector{Ti}, V::Vector, len::Integer) +function _sparsevector!(I::Vector{<:Integer}, V::Vector, len::Integer) # pre-condition: no duplicate indexes in I if !isempty(I) p = sortperm(I) @@ -57,7 +57,7 @@ function _sparsevector!{Ti<:Integer}(I::Vector{Ti}, V::Vector, len::Integer) SparseVector(len, I, V) end -function _sparsevector!{Tv,Ti<:Integer}(I::Vector{Ti}, V::Vector{Tv}, len::Integer, combine::Function) +function _sparsevector!(I::Vector{<:Integer}, V::Vector, len::Integer, combine::Function) if !isempty(I) p = sortperm(I) permute!(I, p) @@ -98,7 +98,7 @@ Duplicates are combined using the `combine` function, which defaults to `+` if no `combine` argument is provided, unless the elements of `V` are Booleans in which case `combine` defaults to `|`. """ -function sparsevec{Ti<:Integer}(I::AbstractVector{Ti}, V::AbstractVector, combine::Function) +function sparsevec(I::AbstractVector{<:Integer}, V::AbstractVector, combine::Function) length(I) == length(V) || throw(ArgumentError("index and value vectors must be the same length")) len = 0 @@ -111,7 +111,7 @@ function sparsevec{Ti<:Integer}(I::AbstractVector{Ti}, V::AbstractVector, combin _sparsevector!(collect(I), collect(V), len, combine) end -function sparsevec{Ti<:Integer}(I::AbstractVector{Ti}, V::AbstractVector, len::Integer, combine::Function) +function sparsevec(I::AbstractVector{<:Integer}, V::AbstractVector, len::Integer, combine::Function) length(I) == length(V) || throw(ArgumentError("index and value vectors must be the same length")) for i in I @@ -301,11 +301,11 @@ convert{Tv}(::Type{SparseVector}, s::AbstractVector{Tv}) = # convert between different types of SparseVector convert{Tv}(::Type{SparseVector{Tv}}, s::SparseVector{Tv}) = s convert{Tv,Ti}(::Type{SparseVector{Tv,Ti}}, s::SparseVector{Tv,Ti}) = s -convert{Tv,Ti,TvS,TiS}(::Type{SparseVector{Tv,Ti}}, s::SparseVector{TvS,TiS}) = +convert{Tv,Ti}(::Type{SparseVector{Tv,Ti}}, s::SparseVector) = SparseVector{Tv,Ti}(s.n, convert(Vector{Ti}, s.nzind), convert(Vector{Tv}, s.nzval)) -convert{Tv,TvS,TiS}(::Type{SparseVector{Tv}}, s::SparseVector{TvS,TiS}) = - SparseVector{Tv,TiS}(s.n, s.nzind, convert(Vector{Tv}, s.nzval)) +convert{Tv,Ti}(::Type{SparseVector{Tv}}, s::SparseVector{<:Any,Ti}) = + SparseVector{Tv,Ti}(s.n, s.nzind, convert(Vector{Tv}, s.nzval)) ### copying @@ -409,14 +409,13 @@ function getindex(x::SparseMatrixCSC, I::UnitRange, j::Integer) end # In the general case, we piggy back upon SparseMatrixCSC's optimized solution -@inline function getindex{Tv,Ti}(A::SparseMatrixCSC{Tv,Ti}, I::AbstractVector, J::Integer) +@inline function getindex(A::SparseMatrixCSC, I::AbstractVector, J::Integer) M = A[I, [J]] SparseVector(M.m, M.rowval, M.nzval) end # Row slices getindex(A::SparseMatrixCSC, i::Integer, ::Colon) = A[i, 1:end] -getindex{Tv,Ti}(A::SparseMatrixCSC{Tv,Ti}, i::Integer, J::AbstractVector{Bool}) = A[i, find(J)] function Base.getindex{Tv,Ti}(A::SparseMatrixCSC{Tv,Ti}, i::Integer, J::AbstractVector) checkbounds(A, i, J) nJ = length(J) @@ -448,8 +447,8 @@ end # Logical and linear indexing into SparseMatrices -getindex{Tv}(A::SparseMatrixCSC{Tv}, I::AbstractVector{Bool}) = _logical_index(A, I) # Ambiguities -getindex{Tv}(A::SparseMatrixCSC{Tv}, I::AbstractArray{Bool}) = _logical_index(A, I) +getindex(A::SparseMatrixCSC, I::AbstractVector{Bool}) = _logical_index(A, I) # Ambiguities +getindex(A::SparseMatrixCSC, I::AbstractArray{Bool}) = _logical_index(A, I) function _logical_index{Tv}(A::SparseMatrixCSC{Tv}, I::AbstractArray{Bool}) checkbounds(A, I) n = sum(I) @@ -564,7 +563,7 @@ function getindex{Tv}(A::SparseMatrixCSC{Tv}, I::AbstractVector) SparseVector(n, rowvalB, nzvalB) end -function find{Tv,Ti}(x::SparseVector{Tv,Ti}) +function find{Ti}(x::SparseVector{<:Any,Ti}) numnz = nnz(x) I = Array{Ti,1}(numnz) @@ -623,7 +622,7 @@ function _spgetindex{Tv,Ti}(m::Int, nzind::AbstractVector{Ti}, nzval::AbstractVe (ii <= m && nzind[ii] == i) ? nzval[ii] : zero(Tv) end -function getindex{Tv}(x::AbstractSparseVector{Tv}, i::Integer) +function getindex(x::AbstractSparseVector, i::Integer) checkbounds(x, i) _spgetindex(nnz(x), nonzeroinds(x), nonzeros(x), i) end @@ -659,15 +658,15 @@ function getindex{Tv,Ti}(x::AbstractSparseVector{Tv,Ti}, I::UnitRange) SparseVector(length(I), rind, rval) end -getindex{Tv,Ti}(x::AbstractSparseVector{Tv,Ti}, I::AbstractVector{Bool}) = x[find(I)] -getindex{Tv,Ti}(x::AbstractSparseVector{Tv,Ti}, I::AbstractArray{Bool}) = x[find(I)] -@inline function getindex{Tv,Ti}(x::AbstractSparseVector{Tv,Ti}, I::AbstractVector) +getindex(x::AbstractSparseVector, I::AbstractVector{Bool}) = x[find(I)] +getindex(x::AbstractSparseVector, I::AbstractArray{Bool}) = x[find(I)] +@inline function getindex(x::AbstractSparseVector, I::AbstractVector) # SparseMatrixCSC has a nicely optimized routine for this; punt S = SparseMatrixCSC(x.n, 1, [1,length(x.nzind)+1], x.nzind, x.nzval) S[I, 1] end -function getindex{Tv,Ti}(x::AbstractSparseVector{Tv,Ti}, I::AbstractArray) +function getindex(x::AbstractSparseVector, I::AbstractArray) # punt to SparseMatrixCSC S = SparseMatrixCSC(x.n, 1, [1,length(x.nzind)+1], x.nzind, x.nzval) S[I] @@ -715,21 +714,21 @@ end ### Conversion to matrix -function convert{TvD,TiD,Tv,Ti}(::Type{SparseMatrixCSC{TvD,TiD}}, x::AbstractSparseVector{Tv,Ti}) +function convert{Tv,Ti}(::Type{SparseMatrixCSC{Tv,Ti}}, x::AbstractSparseVector) n = length(x) xnzind = nonzeroinds(x) xnzval = nonzeros(x) m = length(xnzind) - colptr = TiD[1, m+1] + colptr = Ti[1, m+1] # Note that this *cannot* share data like normal array conversions, since # modifying one would put the other in an inconsistent state - rowval = collect(TiD, xnzind) - nzval = collect(TvD, xnzval) + rowval = collect(Ti, xnzind) + nzval = collect(Tv, xnzval) SparseMatrixCSC(n, 1, colptr, rowval, nzval) end -convert{TvD,Tv,Ti}(::Type{SparseMatrixCSC{TvD}}, x::AbstractSparseVector{Tv,Ti}) = - convert(SparseMatrixCSC{TvD,Ti}, x) +convert{Tv,Ti}(::Type{SparseMatrixCSC{Tv}}, x::AbstractSparseVector{<:Any,Ti}) = + convert(SparseMatrixCSC{Tv,Ti}, x) convert{Tv,Ti}(::Type{SparseMatrixCSC}, x::AbstractSparseVector{Tv,Ti}) = convert(SparseMatrixCSC{Tv,Ti}, x) @@ -762,11 +761,11 @@ function reinterpret{T,Tv}(::Type{T}, x::AbstractSparseVector{Tv}) SparseVector(length(x), copy(nonzeroinds(x)), reinterpret(T, nonzeros(x))) end -float{Tv<:AbstractFloat}(x::AbstractSparseVector{Tv}) = x +float(x::AbstractSparseVector{<:AbstractFloat}) = x float(x::AbstractSparseVector) = SparseVector(length(x), copy(nonzeroinds(x)), float(nonzeros(x))) -complex{Tv<:Complex}(x::AbstractSparseVector{Tv}) = x +complex(x::AbstractSparseVector{<:Complex}) = x complex(x::AbstractSparseVector) = SparseVector(length(x), copy(nonzeroinds(x)), complex(nonzeros(x))) @@ -902,7 +901,7 @@ end # make sure UniformScaling objects are converted to sparse matrices for concatenation promote_to_array_type(A::Tuple{Vararg{Union{_SparseConcatGroup,UniformScaling}}}) = (@_pure_meta; SparseMatrixCSC) promote_to_array_type(A::Tuple{Vararg{Union{_DenseConcatGroup,UniformScaling}}}) = (@_pure_meta; Matrix) -promote_to_arrays_{T}(n::Int, ::Type{SparseMatrixCSC}, J::UniformScaling{T}) = sparse(J, n,n) +promote_to_arrays_(n::Int, ::Type{SparseMatrixCSC}, J::UniformScaling) = sparse(J, n, n) # Concatenations strictly involving un/annotated dense matrices/vectors should yield dense arrays cat(catdims, xs::_DenseConcatGroup...) = Base.cat_t(catdims, promote_eltype(xs...), xs...) @@ -957,7 +956,7 @@ macro unarymap_nz2z_z2z(op, TF) end) end -real{T<:Real}(x::AbstractSparseVector{T}) = x +real(x::AbstractSparseVector{<:Real}) = x @unarymap_nz2z_z2z real Complex imag{Tv<:Real,Ti<:Integer}(x::AbstractSparseVector{Tv,Ti}) = SparseVector(length(x), Ti[], Tv[]) @@ -978,7 +977,7 @@ end macro unarymap_z2nz(op, TF) esc(quote - function $(op){Tv<:$(TF),Ti<:Integer}(x::AbstractSparseVector{Tv,Ti}) + function $(op){Tv<:$(TF)}(x::AbstractSparseVector{Tv,<:Integer}) v0 = $(op)(zero(Tv)) R = typeof(v0) xnzind = nonzeroinds(x) @@ -1270,19 +1269,19 @@ end # definition of other binary functions -broadcast{Tx<:Real,Ty<:Real}(::typeof(min), x::SparseVector{Tx}, y::SparseVector{Ty}) = _binarymap(min, x, y, 2) -broadcast{Tx<:Real,Ty<:Real}(::typeof(min), x::AbstractSparseVector{Tx}, y::AbstractSparseVector{Ty}) = _binarymap(min, x, y, 2) -broadcast{Tx<:Real,Ty<:Real}(::typeof(min), x::StridedVector{Tx}, y::AbstractSparseVector{Ty}) = _binarymap(min, x, y, 2) -broadcast{Tx<:Real,Ty<:Real}(::typeof(min), x::AbstractSparseVector{Tx}, y::StridedVector{Ty}) = _binarymap(min, x, y, 2) +broadcast(::typeof(min), x::SparseVector{<:Real}, y::SparseVector{<:Real}) = _binarymap(min, x, y, 2) +broadcast(::typeof(min), x::AbstractSparseVector{<:Real}, y::AbstractSparseVector{<:Real}) = _binarymap(min, x, y, 2) +broadcast(::typeof(min), x::StridedVector{<:Real}, y::AbstractSparseVector{<:Real}) = _binarymap(min, x, y, 2) +broadcast(::typeof(min), x::AbstractSparseVector{<:Real}, y::StridedVector{<:Real}) = _binarymap(min, x, y, 2) -broadcast{Tx<:Real,Ty<:Real}(::typeof(max), x::SparseVector{Tx}, y::SparseVector{Ty}) = _binarymap(max, x, y, 2) -broadcast{Tx<:Real,Ty<:Real}(::typeof(max), x::AbstractSparseVector{Tx}, y::AbstractSparseVector{Ty}) = _binarymap(max, x, y, 2) -broadcast{Tx<:Real,Ty<:Real}(::typeof(max), x::StridedVector{Tx}, y::AbstractSparseVector{Ty}) = _binarymap(max, x, y, 2) -broadcast{Tx<:Real,Ty<:Real}(::typeof(max), x::AbstractSparseVector{Tx}, y::StridedVector{Ty}) = _binarymap(max, x, y, 2) +broadcast(::typeof(max), x::SparseVector{<:Real}, y::SparseVector{<:Real}) = _binarymap(max, x, y, 2) +broadcast(::typeof(max), x::AbstractSparseVector{<:Real}, y::AbstractSparseVector{<:Real}) = _binarymap(max, x, y, 2) +broadcast(::typeof(max), x::StridedVector{<:Real}, y::AbstractSparseVector{<:Real}) = _binarymap(max, x, y, 2) +broadcast(::typeof(max), x::AbstractSparseVector{<:Real}, y::StridedVector{<:Real}) = _binarymap(max, x, y, 2) -complex{Tx<:Real,Ty<:Real}(x::AbstractSparseVector{Tx}, y::AbstractSparseVector{Ty}) = _binarymap(complex, x, y, 1) -complex{Tx<:Real,Ty<:Real}(x::StridedVector{Tx}, y::AbstractSparseVector{Ty}) = _binarymap(complex, x, y, 1) -complex{Tx<:Real,Ty<:Real}(x::AbstractSparseVector{Tx}, y::StridedVector{Ty}) = _binarymap(complex, x, y, 1) +complex(x::AbstractSparseVector{<:Real}, y::AbstractSparseVector{<:Real}) = _binarymap(complex, x, y, 1) +complex(x::StridedVector{<:Real}, y::AbstractSparseVector{<:Real}) = _binarymap(complex, x, y, 1) +complex(x::AbstractSparseVector{<:Real}, y::StridedVector{<:Real}) = _binarymap(complex, x, y, 1) ### Reduction @@ -1419,7 +1418,7 @@ function _spdot(f::Function, s end -function dot{Tx<:Number,Ty<:Number}(x::AbstractSparseVector{Tx}, y::AbstractSparseVector{Ty}) +function dot(x::AbstractSparseVector{<:Number}, y::AbstractSparseVector{<:Number}) x === y && return sum(abs2, x) n = length(x) length(y) == n || throw(DimensionMismatch()) @@ -1578,18 +1577,18 @@ end At_mul_B!{Tx,Ty}(y::StridedVector{Ty}, A::SparseMatrixCSC, x::AbstractSparseVector{Tx}) = At_mul_B!(one(Tx), A, x, zero(Ty), y) -At_mul_B!{Tx,Ty}(α::Number, A::SparseMatrixCSC, x::AbstractSparseVector{Tx}, β::Number, y::StridedVector{Ty}) = +At_mul_B!(α::Number, A::SparseMatrixCSC, x::AbstractSparseVector, β::Number, y::StridedVector) = _At_or_Ac_mul_B!(*, α, A, x, β, y) Ac_mul_B!{Tx,Ty}(y::StridedVector{Ty}, A::SparseMatrixCSC, x::AbstractSparseVector{Tx}) = Ac_mul_B!(one(Tx), A, x, zero(Ty), y) -Ac_mul_B!{Tx,Ty}(α::Number, A::SparseMatrixCSC, x::AbstractSparseVector{Tx}, β::Number, y::StridedVector{Ty}) = +Ac_mul_B!(α::Number, A::SparseMatrixCSC, x::AbstractSparseVector, β::Number, y::StridedVector) = _At_or_Ac_mul_B!(dot, α, A, x, β, y) -function _At_or_Ac_mul_B!{Tx,Ty}(tfun::Function, - α::Number, A::SparseMatrixCSC, x::AbstractSparseVector{Tx}, - β::Number, y::StridedVector{Ty}) +function _At_or_Ac_mul_B!(tfun::Function, + α::Number, A::SparseMatrixCSC, x::AbstractSparseVector, + β::Number, y::StridedVector) m, n = size(A) length(x) == m && length(y) == n || throw(DimensionMismatch()) n == 0 && return y @@ -1679,7 +1678,7 @@ for isunittri in (true, false), islowertri in (true, false) (true, :(Ac_ldiv_B), :(Ac_ldiv_B!)) ) # broad method where elements are Numbers - @eval function ($func){TA<:Number,Tb<:Number,S<:AbstractMatrix}(A::$tritype{TA,S}, b::SparseVector{Tb}) + @eval function ($func){TA<:Number,Tb<:Number}(A::$tritype{TA,<:AbstractMatrix}, b::SparseVector{Tb}) TAb = $(isunittri ? :(typeof(zero(TA)*zero(Tb) + zero(TA)*zero(Tb))) : :(typeof((zero(TA)*zero(Tb) + zero(TA)*zero(Tb))/one(TA))) ) @@ -1688,7 +1687,7 @@ for isunittri in (true, false), islowertri in (true, false) # faster method requiring good view support of the # triangular matrix type. hence the StridedMatrix restriction. - @eval function ($func){TA<:Number,Tb<:Number,S<:StridedMatrix}(A::$tritype{TA,S}, b::SparseVector{Tb}) + @eval function ($func){TA<:Number,Tb<:Number}(A::$tritype{TA,<:StridedMatrix}, b::SparseVector{Tb}) TAb = $(isunittri ? :(typeof(zero(TA)*zero(Tb) + zero(TA)*zero(Tb))) : :(typeof((zero(TA)*zero(Tb) + zero(TA)*zero(Tb))/one(TA))) ) @@ -1720,7 +1719,7 @@ for isunittri in (true, false), islowertri in (true, false) # the generic in-place left-division methods handle these cases, but # we can achieve greater efficiency where the triangular matrix provides # good view support. hence the StridedMatrix restriction. - @eval function ($func){TA,Tb,S<:StridedMatrix}(A::$tritype{TA,S}, b::SparseVector{Tb}) + @eval function ($func)(A::$tritype{<:Any,<:StridedMatrix}, b::SparseVector) # If b has no nonzero entries, the result is necessarily zero and this call # reduces to a no-op. If b has nonzero entries, then... if nnz(b) != 0 diff --git a/base/sparse/umfpack.jl b/base/sparse/umfpack.jl index 496faf5552d89..f99a05c3f2581 100644 --- a/base/sparse/umfpack.jl +++ b/base/sparse/umfpack.jl @@ -138,7 +138,7 @@ SuiteSparse. As this library only supports sparse matrices with `Float64` or `Complex128` elements, `lufact` converts `A` into a copy that is of type `SparseMatrixCSC{Float64}` or `SparseMatrixCSC{Complex128}` as appropriate. """ -function lufact{Tv<:UMFVTypes,Ti<:UMFITypes}(S::SparseMatrixCSC{Tv,Ti}) +function lufact(S::SparseMatrixCSC{<:UMFVTypes,<:UMFITypes}) zerobased = S.colptr[1] == 0 res = UmfpackLU(C_NULL, C_NULL, S.m, S.n, zerobased ? copy(S.colptr) : decrement(S.colptr), @@ -147,9 +147,9 @@ function lufact{Tv<:UMFVTypes,Ti<:UMFITypes}(S::SparseMatrixCSC{Tv,Ti}) finalizer(res, umfpack_free_symbolic) umfpack_numeric!(res) end -lufact{Tv<:Union{Float16,Float32}, Ti<:UMFITypes}(A::SparseMatrixCSC{Tv,Ti}) = +lufact{Ti<:UMFITypes}(A::SparseMatrixCSC{<:Union{Float16,Float32},Ti}) = lufact(convert(SparseMatrixCSC{Float64,Ti}, A)) -lufact{Tv<:Union{Complex32,Complex64}, Ti<:UMFITypes}(A::SparseMatrixCSC{Tv,Ti}) = +lufact{Ti<:UMFITypes}(A::SparseMatrixCSC{<:Union{Complex32,Complex64},Ti}) = lufact(convert(SparseMatrixCSC{Complex128,Ti}, A)) lufact{T<:AbstractFloat}(A::Union{SparseMatrixCSC{T},SparseMatrixCSC{Complex{T}}}) = throw(ArgumentError(string("matrix type ", typeof(A), "not supported. ", @@ -386,9 +386,9 @@ end A_ldiv_B!{T<:UMFVTypes}(lu::UmfpackLU{T}, B::StridedVecOrMat{T}) = A_ldiv_B!(B, lu, copy(B)) At_ldiv_B!{T<:UMFVTypes}(lu::UmfpackLU{T}, B::StridedVecOrMat{T}) = At_ldiv_B!(B, lu, copy(B)) Ac_ldiv_B!{T<:UMFVTypes}(lu::UmfpackLU{T}, B::StridedVecOrMat{T}) = Ac_ldiv_B!(B, lu, copy(B)) -A_ldiv_B!{Tb<:Complex}(lu::UmfpackLU{Float64}, B::StridedVecOrMat{Tb}) = A_ldiv_B!(B, lu, copy(B)) -At_ldiv_B!{Tb<:Complex}(lu::UmfpackLU{Float64}, B::StridedVecOrMat{Tb}) = At_ldiv_B!(B, lu, copy(B)) -Ac_ldiv_B!{Tb<:Complex}(lu::UmfpackLU{Float64}, B::StridedVecOrMat{Tb}) = Ac_ldiv_B!(B, lu, copy(B)) +A_ldiv_B!(lu::UmfpackLU{Float64}, B::StridedVecOrMat{<:Complex}) = A_ldiv_B!(B, lu, copy(B)) +At_ldiv_B!(lu::UmfpackLU{Float64}, B::StridedVecOrMat{<:Complex}) = At_ldiv_B!(B, lu, copy(B)) +Ac_ldiv_B!(lu::UmfpackLU{Float64}, B::StridedVecOrMat{<:Complex}) = Ac_ldiv_B!(B, lu, copy(B)) A_ldiv_B!{T<:UMFVTypes}(X::StridedVecOrMat{T}, lu::UmfpackLU{T}, B::StridedVecOrMat{T}) = _Aq_ldiv_B!(X, lu, B, UMFPACK_A) diff --git a/base/statistics.jl b/base/statistics.jl index 8e03f185c0c55..f84b02f78010b 100644 --- a/base/statistics.jl +++ b/base/statistics.jl @@ -27,7 +27,7 @@ mean(iterable) = mean(identity, iterable) mean(f::Callable, A::AbstractArray) = sum(f, A) / _length(A) mean(A::AbstractArray) = sum(A) / _length(A) -function mean!{T}(R::AbstractArray{T}, A::AbstractArray) +function mean!(R::AbstractArray, A::AbstractArray) sum!(R, A; init=true) scale!(R, _length(R) / _length(A)) return R @@ -35,7 +35,7 @@ end momenttype{T}(::Type{T}) = typeof((zero(T) + zero(T)) / 2) momenttype(::Type{Float32}) = Float32 -momenttype{T<:Union{Float64,Int32,Int64,UInt32,UInt64}}(::Type{T}) = Float64 +momenttype(::Type{<:Union{Float64,Int32,Int64,UInt32,UInt64}}) = Float64 """ mean(v[, region]) @@ -100,7 +100,7 @@ centralize_sumabs2(A::AbstractArray, m::Number) = centralize_sumabs2(A::AbstractArray, m::Number, ifirst::Int, ilast::Int) = mapreduce_impl(centralizedabs2fun(m), +, A, ifirst, ilast) -function centralize_sumabs2!{S,T,N}(R::AbstractArray{S}, A::AbstractArray{T,N}, means::AbstractArray) +function centralize_sumabs2!{S}(R::AbstractArray{S}, A::AbstractArray, means::AbstractArray) # following the implementation of _mapreducedim! at base/reducedim.jl lsiz = check_reducedims(R,A) isempty(R) || fill!(R, zero(S)) @@ -279,7 +279,7 @@ stdm(iterable, m::Number; corrected::Bool=true) = # auxiliary functions -_conj{T<:Real}(x::AbstractArray{T}) = x +_conj(x::AbstractArray{<:Real}) = x _conj(x::AbstractArray) = conj(x) _getnobs(x::AbstractVector, vardim::Int) = _length(x) @@ -337,7 +337,7 @@ is scaled with `n-1`, whereas the sum is scaled with `n` if `corrected` is `fals """ cov(x::AbstractVector, corrected::Bool) = covm(x, Base.mean(x), corrected) # This ugly hack is necessary to make the method below considered more specific than the deprecated method. When the old keyword version has been completely deprecated, these two methods can be merged -cov{T<:AbstractVector}(x::T) = covm(x, Base.mean(x), true) +cov(x::AbstractVector) = covm(x, Base.mean(x), true) """ cov(X[, vardim=1, corrected=true]) @@ -349,7 +349,7 @@ if `corrected` is `false` where `n = size(X, vardim)`. cov(X::AbstractMatrix, vardim::Int, corrected::Bool=true) = covm(X, _vmean(X, vardim), vardim, corrected) # This ugly hack is necessary to make the method below considered more specific than the deprecated method. When the old keyword version has been completely deprecated, these two methods can be merged -cov{T<:AbstractMatrix}(X::T) = cov(X, 1, true) +cov(X::AbstractMatrix) = cov(X, 1, true) """ cov(x, y[, corrected=true]) @@ -361,7 +361,7 @@ where `n = length(x) = length(y)`. cov(x::AbstractVector, y::AbstractVector, corrected::Bool) = covm(x, Base.mean(x), y, Base.mean(y), corrected) # This ugly hack is necessary to make the method below considered more specific than the deprecated method. When the old keyword version has been completely deprecated, these two methods can be merged -cov{T<:AbstractVector,S<:AbstractVector}(x::T, y::S) = +cov(x::AbstractVector, y::AbstractVector) = covm(x, Base.mean(x), y, Base.mean(y), true) """ @@ -476,7 +476,7 @@ corm(x::AbstractVecOrMat, xmean, y::AbstractVecOrMat, ymean, vardim::Int=1) = Return the number one. """ -cor{T<:AbstractVector}(x::T) = one(real(eltype(x))) +cor(x::AbstractVector) = one(real(eltype(x))) # This ugly hack is necessary to make the method below considered more specific than the deprecated method. When the old keyword version has been completely deprecated, these two methods can be merged """ @@ -486,14 +486,14 @@ Compute the Pearson correlation matrix of the matrix `X` along the dimension `va """ cor(X::AbstractMatrix, vardim::Int) = corm(X, _vmean(X, vardim), vardim) # This ugly hack is necessary to make the method below considered more specific than the deprecated method. When the old keyword version has been completely deprecated, these two methods can be merged -cor{T<:AbstractMatrix}(X::T) = cor(X, 1) +cor(X::AbstractMatrix) = cor(X, 1) """ cor(x, y) Compute the Pearson correlation between the vectors `x` and `y`. """ -cor{T<:AbstractVector,S<:AbstractVector}(x::T, y::S) = corm(x, Base.mean(x), y, Base.mean(y)) +cor(x::AbstractVector, y::AbstractVector) = corm(x, Base.mean(x), y, Base.mean(y)) # This ugly hack is necessary to make the method below considered more specific than the deprecated method. When the old keyword version has been completely deprecated, these two methods can be merged """ @@ -566,9 +566,9 @@ middle(a::AbstractArray) = ((v1, v2) = extrema(a); middle(v1, v2)) Like [`median`](@ref), but may overwrite the input vector. """ -function median!{T}(v::AbstractVector{T}) +function median!(v::AbstractVector) isempty(v) && throw(ArgumentError("median of an empty array is undefined, $(repr(v))")) - if T<:AbstractFloat + if eltype(v)<:AbstractFloat @inbounds for x in v isnan(x) && return x end @@ -583,7 +583,7 @@ function median!{T}(v::AbstractVector{T}) return middle(m[1], m[2]) end end -median!{T}(v::AbstractArray{T}) = median!(vec(v)) +median!(v::AbstractArray) = median!(vec(v)) median{T}(v::AbstractArray{T}) = median!(copy!(Array{T,1}(_length(v)), v)) """ @@ -598,7 +598,7 @@ equivalent to calculating mean of two median elements. Julia does not ignore `NaN` values in the computation. For applications requiring the handling of missing data, the `DataArrays.jl` package is recommended. """ -median{T}(v::AbstractArray{T}, region) = mapslices(median!, v, region) +median(v::AbstractArray, region) = mapslices(median!, v, region) # for now, use the R/S definition of quantile; may want variants later # see ?quantile in R -- this is type 7 diff --git a/base/strings/basic.jl b/base/strings/basic.jl index 2305ab422950f..c59b876abf720 100644 --- a/base/strings/basic.jl +++ b/base/strings/basic.jl @@ -32,9 +32,9 @@ done(s::AbstractString,i) = (i > endof(s)) getindex(s::AbstractString, i::Int) = next(s,i)[1] getindex(s::AbstractString, i::Integer) = s[Int(i)] getindex(s::AbstractString, i::Colon) = s -getindex{T<:Integer}(s::AbstractString, r::UnitRange{T}) = s[Int(first(r)):Int(last(r))] +getindex(s::AbstractString, r::UnitRange{<:Integer}) = s[Int(first(r)):Int(last(r))] # TODO: handle other ranges with stride ±1 specially? -getindex{T<:Integer}(s::AbstractString, v::AbstractVector{T}) = +getindex(s::AbstractString, v::AbstractVector{<:Integer}) = sprint(length(v), io->(for i in v; write(io,s[i]) end)) getindex(s::AbstractString, v::AbstractVector{Bool}) = throw(ArgumentError("logical indexing not supported for strings")) @@ -53,7 +53,7 @@ julia> sizeof("❤") """ sizeof(s::AbstractString) = error("type $(typeof(s)) has no canonical binary representation") -eltype{T<:AbstractString}(::Type{T}) = Char +eltype(::Type{<:AbstractString}) = Char """ ``` @@ -238,10 +238,10 @@ function nextind(s::AbstractString, i::Integer) end checkbounds(s::AbstractString, i::Integer) = start(s) <= i <= endof(s) || throw(BoundsError(s, i)) -checkbounds{T<:Integer}(s::AbstractString, r::Range{T}) = isempty(r) || (minimum(r) >= start(s) && maximum(r) <= endof(s)) || throw(BoundsError(s, r)) -# The following will end up using a deprecated checkbounds, when T is not Integer -checkbounds{T<:Real}(s::AbstractString, I::AbstractArray{T}) = all(i -> checkbounds(s, i), I) -checkbounds{T<:Integer}(s::AbstractString, I::AbstractArray{T}) = all(i -> checkbounds(s, i), I) +checkbounds(s::AbstractString, r::Range{<:Integer}) = isempty(r) || (minimum(r) >= start(s) && maximum(r) <= endof(s)) || throw(BoundsError(s, r)) +# The following will end up using a deprecated checkbounds, when the covariant parameter is not Integer +checkbounds(s::AbstractString, I::AbstractArray{<:Real}) = all(i -> checkbounds(s, i), I) +checkbounds(s::AbstractString, I::AbstractArray{<:Integer}) = all(i -> checkbounds(s, i), I) ind2chr(s::DirectIndexString, i::Integer) = begin checkbounds(s,i); i end chr2ind(s::DirectIndexString, i::Integer) = begin checkbounds(s,i); i end @@ -346,7 +346,7 @@ isascii(s::AbstractString) = all(isascii, s) ## string promotion rules ## -promote_rule{S<:AbstractString,T<:AbstractString}(::Type{S}, ::Type{T}) = String +promote_rule(::Type{<:AbstractString}, ::Type{<:AbstractString}) = String """ isxdigit(c::Char) -> Bool diff --git a/base/strings/types.jl b/base/strings/types.jl index 5442d14346f78..8bfbad518b797 100644 --- a/base/strings/types.jl +++ b/base/strings/types.jl @@ -37,7 +37,7 @@ sizeof(s::SubString{String}) = s.endof == 0 ? 0 : nextind(s, s.endof) - 1 # default implementation will work but it's slow # can this be delegated efficiently somehow? # that may require additional string interfaces -length{T<:DirectIndexString}(s::SubString{T}) = endof(s) +length(s::SubString{<:DirectIndexString}) = endof(s) function length(s::SubString{String}) return s.endof==0 ? 0 : Int(ccall(:u8_charnum, Csize_t, (Ptr{UInt8}, Csize_t), @@ -65,10 +65,10 @@ function isvalid(s::SubString, i::Integer) return (start(s) <= i <= endof(s)) && isvalid(s.string, s.offset+i) end -isvalid{T<:DirectIndexString}(s::SubString{T}, i::Integer) = (start(s) <= i <= endof(s)) +isvalid(s::SubString{<:DirectIndexString}, i::Integer) = (start(s) <= i <= endof(s)) -ind2chr{T<:DirectIndexString}(s::SubString{T}, i::Integer) = begin checkbounds(s,i); i end -chr2ind{T<:DirectIndexString}(s::SubString{T}, i::Integer) = begin checkbounds(s,i); i end +ind2chr(s::SubString{<:DirectIndexString}, i::Integer) = begin checkbounds(s,i); i end +chr2ind(s::SubString{<:DirectIndexString}, i::Integer) = begin checkbounds(s,i); i end nextind(s::SubString, i::Integer) = nextind(s.string, i+s.offset)-s.offset prevind(s::SubString, i::Integer) = prevind(s.string, i+s.offset)-s.offset diff --git a/base/strings/util.jl b/base/strings/util.jl index 93a2df25796b1..9a2d60c09a38c 100644 --- a/base/strings/util.jl +++ b/base/strings/util.jl @@ -274,7 +274,7 @@ julia> split(a,".") ``` """ split{T<:AbstractString}(str::T, splitter; limit::Integer=0, keep::Bool=true) = _split(str, splitter, limit, keep, SubString{T}[]) -function _split{T<:AbstractString,U<:Array}(str::T, splitter, limit::Integer, keep_empty::Bool, strs::U) +function _split(str::AbstractString, splitter, limit::Integer, keep_empty::Bool, strs::Array) i = start(str) n = endof(str) r = search(str,splitter,i) @@ -329,7 +329,7 @@ julia> rsplit(a,".";limit=2) ``` """ rsplit{T<:AbstractString}(str::T, splitter ; limit::Integer=0, keep::Bool=true) = _rsplit(str, splitter, limit, keep, SubString{T}[]) -function _rsplit{T<:AbstractString,U<:Array}(str::T, splitter, limit::Integer, keep_empty::Bool, strs::U) +function _rsplit(str::AbstractString, splitter, limit::Integer, keep_empty::Bool, strs::Array) i = start(str) n = endof(str) r = rsearch(str,splitter) diff --git a/base/subarray.jl b/base/subarray.jl index 334f5e59ddcc3..d236746ae0576 100644 --- a/base/subarray.jl +++ b/base/subarray.jl @@ -126,10 +126,10 @@ end # `CartesianIndex`, and if so, we punt and keep two layers of indirection. unsafe_view(V::SubArray, I::ViewIndex...) = (@_inline_meta; _maybe_reindex(V, I)) _maybe_reindex(V, I) = (@_inline_meta; _maybe_reindex(V, I, I)) -_maybe_reindex{C<:AbstractCartesianIndex}(V, I, ::Tuple{AbstractArray{C}, Vararg{Any}}) = +_maybe_reindex(V, I, ::Tuple{AbstractArray{<:AbstractCartesianIndex}, Vararg{Any}}) = (@_inline_meta; SubArray(V, I)) # But allow arrays of CartesianIndex{1}; they behave just like arrays of Ints -_maybe_reindex{C<:AbstractCartesianIndex{1}}(V, I, A::Tuple{AbstractArray{C}, Vararg{Any}}) = +_maybe_reindex(V, I, A::Tuple{AbstractArray{<:AbstractCartesianIndex{1}}, Vararg{Any}}) = (@_inline_meta; _maybe_reindex(V, I, tail(A))) _maybe_reindex(V, I, A::Tuple{Any, Vararg{Any}}) = (@_inline_meta; _maybe_reindex(V, I, tail(A))) function _maybe_reindex(V, I, ::Tuple{}) @@ -221,12 +221,12 @@ function setindex!(V::FastContiguousSubArray, x, i::Int) V end -linearindexing{T<:FastSubArray}(::Type{T}) = LinearFast() -linearindexing{T<:SubArray}(::Type{T}) = LinearSlow() +linearindexing(::Type{<:FastSubArray}) = LinearFast() +linearindexing(::Type{<:SubArray}) = LinearSlow() # Strides are the distance between adjacent elements in a given dimension, # so they are well-defined even for non-linear memory layouts -strides{T,N,P,I}(V::SubArray{T,N,P,I}) = substrides(V.parent, V.indexes) +strides(V::SubArray) = substrides(V.parent, V.indexes) substrides(parent, I::Tuple) = substrides(1, parent, 1, I) substrides(s, parent, dim, ::Tuple{}) = () @@ -247,8 +247,8 @@ compute_stride1(s, inds, I::Tuple{Slice, Vararg{Any}}) = s compute_stride1(s, inds, I::Tuple{Any, Vararg{Any}}) = throw(ArgumentError("invalid strided index type $(typeof(I[1]))")) iscontiguous(A::SubArray) = iscontiguous(typeof(A)) -iscontiguous{S<:SubArray}(::Type{S}) = false -iscontiguous{F<:FastContiguousSubArray}(::Type{F}) = true +iscontiguous(::Type{<:SubArray}) = false +iscontiguous(::Type{<:FastContiguousSubArray}) = true first_index(V::FastSubArray) = V.offset1 + V.stride1 # cached for fast linear SubArrays function first_index(V::SubArray) @@ -294,16 +294,16 @@ _find_extended_dims(dims, inds, dim, ::ScalarIndex, I...) = _find_extended_dims(dims, inds, dim, i1, I...) = (@_inline_meta; _find_extended_dims((dims..., dim), (inds..., i1), dim+1, I...)) -unsafe_convert{T,N,P,I<:Tuple{Vararg{RangeIndex}}}(::Type{Ptr{T}}, V::SubArray{T,N,P,I}) = +unsafe_convert{T,N,P}(::Type{Ptr{T}}, V::SubArray{T,N,P,<:Tuple{Vararg{RangeIndex}}}) = unsafe_convert(Ptr{T}, V.parent) + (first_index(V)-1)*sizeof(T) pointer(V::FastSubArray, i::Int) = pointer(V.parent, V.offset1 + V.stride1*i) pointer(V::FastContiguousSubArray, i::Int) = pointer(V.parent, V.offset1 + i) pointer(V::SubArray, i::Int) = _pointer(V, i) -_pointer{T}(V::SubArray{T,1}, i::Int) = pointer(V, (i,)) +_pointer(V::SubArray{<:Any,1}, i::Int) = pointer(V, (i,)) _pointer(V::SubArray, i::Int) = pointer(V, ind2sub(indices(V), i)) -function pointer{T,N,P<:Array,I<:Tuple{Vararg{RangeIndex}}}(V::SubArray{T,N,P,I}, is::Tuple{Vararg{Int}}) +function pointer{T,N}(V::SubArray{T,N,<:Array,<:Tuple{Vararg{RangeIndex}}}, is::Tuple{Vararg{Int}}) index = first_index(V) strds = strides(V) for d = 1:length(is) diff --git a/base/traits.jl b/base/traits.jl index 62bc9ecb4d6da..546d48a1d27bd 100644 --- a/base/traits.jl +++ b/base/traits.jl @@ -7,8 +7,8 @@ immutable HasOrder <: TypeOrder end immutable Unordered <: TypeOrder end (::Type{TypeOrder})(instance) = TypeOrder(typeof(instance)) -(::Type{TypeOrder}){T<:Real}(::Type{T}) = HasOrder() -(::Type{TypeOrder}){T}(::Type{T}) = Unordered() +(::Type{TypeOrder})(::Type{<:Real}) = HasOrder() +(::Type{TypeOrder})(::Type{<:Any}) = Unordered() # trait for objects that support arithmetic abstract TypeArithmetic @@ -17,6 +17,6 @@ immutable ArithmeticOverflows <: TypeArithmetic end # most significant bits ca immutable ArithmeticUnknown <: TypeArithmetic end (::Type{TypeArithmetic})(instance) = TypeArithmetic(typeof(instance)) -(::Type{TypeArithmetic}){T<:AbstractFloat}(::Type{T}) = ArithmeticRounds() -(::Type{TypeArithmetic}){T<:Integer}(::Type{T}) = ArithmeticOverflows() -(::Type{TypeArithmetic}){T}(::Type{T}) = ArithmeticUnknown() +(::Type{TypeArithmetic})(::Type{<:AbstractFloat}) = ArithmeticRounds() +(::Type{TypeArithmetic})(::Type{<:Integer}) = ArithmeticOverflows() +(::Type{TypeArithmetic})(::Type{<:Any}) = ArithmeticUnknown() diff --git a/base/tuple.jl b/base/tuple.jl index 3ea9f31a8cf6c..2524606556e85 100644 --- a/base/tuple.jl +++ b/base/tuple.jl @@ -20,7 +20,7 @@ endof(t::Tuple) = length(t) size(t::Tuple, d) = d==1 ? length(t) : throw(ArgumentError("invalid tuple dimension $d")) getindex(t::Tuple, i::Int) = getfield(t, i) getindex(t::Tuple, i::Real) = getfield(t, convert(Int, i)) -getindex{T}(t::Tuple, r::AbstractArray{T,1}) = tuple([t[ri] for ri in r]...) +getindex(t::Tuple, r::AbstractArray{<:Any,1}) = tuple([t[ri] for ri in r]...) getindex(t::Tuple, b::AbstractArray{Bool,1}) = length(b) == length(t) ? getindex(t,find(b)) : throw(BoundsError(t, b)) # returns new tuple; N.B.: becomes no-op if i is out-of-bounds @@ -62,7 +62,7 @@ first(t::Tuple) = t[1] # eltype eltype(::Type{Tuple{}}) = Bottom -eltype{E, T <: Tuple{Vararg{E}}}(::Type{T}) = E +eltype(::Type{<:Tuple{Vararg{E}}}) where {E} = E # version of tail that doesn't throw on empty tuples (used in array indexing) safe_tail(t::Tuple) = tail(t) diff --git a/base/twiceprecision.jl b/base/twiceprecision.jl index 641f8feb54ede..6f63213947f32 100644 --- a/base/twiceprecision.jl +++ b/base/twiceprecision.jl @@ -74,7 +74,7 @@ convert{T}(::Type{TwicePrecision{T}}, x::TwicePrecision) = convert{T<:Number}(::Type{T}, x::TwicePrecision{T}) = convert(T, x.hi + x.lo) convert{T}(::Type{TwicePrecision{T}}, x::Number) = TwicePrecision{T}(convert(T, x), zero(T)) -float{T<:AbstractFloat}(x::TwicePrecision{T}) = x +float(x::TwicePrecision{<:AbstractFloat}) = x float(x::TwicePrecision) = TwicePrecision(float(x.hi), float(x.lo)) big(x::TwicePrecision) = big(x.hi) + big(x.lo) @@ -180,15 +180,15 @@ end step{T,R,S<:TwicePrecision}(r::StepRangeLen{T,R,S}) = convert(eltype(S), r.step) -start{T,R<:TwicePrecision,S<:TwicePrecision}(r::StepRangeLen{T,R,S}) = 1 -done{T,R<:TwicePrecision,S<:TwicePrecision}(r::StepRangeLen{T,R,S}, i::Int) = length(r) < i -function next{T,R<:TwicePrecision,S<:TwicePrecision}(r::StepRangeLen{T,R,S}, i::Int) +start(r::StepRangeLen{<:Any,<:TwicePrecision,<:TwicePrecision}) = 1 +done(r::StepRangeLen{<:Any,<:TwicePrecision,<:TwicePrecision}, i::Int) = length(r) < i +function next(r::StepRangeLen{<:Any,<:TwicePrecision,<:TwicePrecision}, i::Int) @_inline_meta unsafe_getindex(r, i), i+1 end # This assumes that r.step has already been split so that (0:len-1)*r.step.hi is exact -function unsafe_getindex{T,R<:TwicePrecision,S<:TwicePrecision}(r::StepRangeLen{T,R,S}, i::Integer) +function unsafe_getindex{T}(r::StepRangeLen{T,<:TwicePrecision,<:TwicePrecision}, i::Integer) # Very similar to _getindex_hiprec, but optimized to avoid a 2nd call to add2 @_inline_meta u = i - r.offset @@ -197,7 +197,7 @@ function unsafe_getindex{T,R<:TwicePrecision,S<:TwicePrecision}(r::StepRangeLen{ T(x_hi + (x_lo + (shift_lo + r.ref.lo))) end -function _getindex_hiprec{T,R<:TwicePrecision,S<:TwicePrecision}(r::StepRangeLen{T,R,S}, i::Integer) +function _getindex_hiprec(r::StepRangeLen{<:Any,<:TwicePrecision,<:TwicePrecision}, i::Integer) u = i - r.offset shift_hi, shift_lo = u*r.step.hi, u*r.step.lo x_hi, x_lo = add2(r.ref.hi, shift_hi) @@ -205,7 +205,7 @@ function _getindex_hiprec{T,R<:TwicePrecision,S<:TwicePrecision}(r::StepRangeLen TwicePrecision(x_hi, x_lo) end -function getindex{T,R<:TwicePrecision,S<:TwicePrecision,I<:Integer}(r::StepRangeLen{T,R,S}, s::OrdinalRange{I}) +function getindex{T}(r::StepRangeLen{T,<:TwicePrecision,<:TwicePrecision}, s::OrdinalRange{<:Integer}) @_inline_meta @boundscheck checkbounds(r, s) soffset = 1 + round(Int, (r.offset - first(s))/step(s)) @@ -223,10 +223,10 @@ function getindex{T,R<:TwicePrecision,S<:TwicePrecision,I<:Integer}(r::StepRange end end -*{T<:Real,R<:TwicePrecision}(x::Real, r::StepRangeLen{T,R}) = +*(x::Real, r::StepRangeLen{<:Real,<:TwicePrecision}) = StepRangeLen(x*r.ref, twiceprecision(x*r.step, nbitslen(r)), length(r), r.offset) -*{T<:Real,R<:TwicePrecision}(r::StepRangeLen{T,R}, x::Real) = x*r -/{T<:Real,R<:TwicePrecision}(r::StepRangeLen{T,R}, x::Real) = +*(r::StepRangeLen{<:Real,<:TwicePrecision}, x::Real) = x*r +/(r::StepRangeLen{<:Real,<:TwicePrecision}, x::Real) = StepRangeLen(r.ref/x, twiceprecision(r.step/x, nbitslen(r)), length(r), r.offset) convert{T<:AbstractFloat,R<:TwicePrecision,S<:TwicePrecision}(::Type{StepRangeLen{T,R,S}}, r::StepRangeLen{T,R,S}) = r @@ -240,11 +240,11 @@ convert{T<:Union{Float16,Float32,Float64}}(::Type{StepRangeLen{T}}, r::StepRange convert{T<:Union{Float16,Float32,Float64}}(::Type{StepRangeLen{T}}, r::Range) = _convertSRL(StepRangeLen{T,TwicePrecision{T},TwicePrecision{T}}, r) -function _convertSRL{T,R,S,I<:Integer}(::Type{StepRangeLen{T,R,S}}, r::StepRangeLen{I}) +function _convertSRL{T,R,S}(::Type{StepRangeLen{T,R,S}}, r::StepRangeLen{<:Integer}) StepRangeLen{T,R,S}(R(r.ref), S(r.step), length(r), r.offset) end -function _convertSRL{T,R,S,I<:Integer}(::Type{StepRangeLen{T,R,S}}, r::Range{I}) +function _convertSRL{T,R,S}(::Type{StepRangeLen{T,R,S}}, r::Range{<:Integer}) StepRangeLen{T,R,S}(R(first(r)), S(step(r)), length(r)) end diff --git a/base/util.jl b/base/util.jl index d3945fc32df33..75b5cce61867c 100644 --- a/base/util.jl +++ b/base/util.jl @@ -630,7 +630,7 @@ the compiler for objects about to be discarded, the `securezero!` function will always be called. """ function securezero! end -@noinline securezero!{T<:Number}(a::AbstractArray{T}) = fill!(a, 0) +@noinline securezero!(a::AbstractArray{<:Number}) = fill!(a, 0) securezero!(s::String) = unsafe_securezero!(pointer(s), sizeof(s)) @noinline unsafe_securezero!{T}(p::Ptr{T}, len::Integer=1) = ccall(:memset, Ptr{T}, (Ptr{T}, Cint, Csize_t), p, 0, len*sizeof(T))