diff --git a/NEWS.md b/NEWS.md index 0a1430c363ae2..be3953757d97a 100644 --- a/NEWS.md +++ b/NEWS.md @@ -30,6 +30,9 @@ New language features Language changes ---------------- + * `[x,y]` constructs a vector of `x` and `y` instead of concatenating them + ([#3737], [#2488], [#8599]). + * `error(::Exception)` and `error(::Type{Exception})` have been deprecated in favor of using an explicit `throw` ([#9690]). @@ -941,6 +944,7 @@ Too numerous to mention. [#2380]: https://github.com/JuliaLang/julia/issues/2380 [#2403]: https://github.com/JuliaLang/julia/issues/2403 [#2468]: https://github.com/JuliaLang/julia/issues/2468 +[#2488]: https://github.com/JuliaLang/julia/issues/2488 [#2515]: https://github.com/JuliaLang/julia/issues/2515 [#2516]: https://github.com/JuliaLang/julia/issues/2516 [#2597]: https://github.com/JuliaLang/julia/issues/2597 @@ -986,6 +990,7 @@ Too numerous to mention. [#3688]: https://github.com/JuliaLang/julia/issues/3688 [#3697]: https://github.com/JuliaLang/julia/issues/3697 [#3719]: https://github.com/JuliaLang/julia/issues/3719 +[#3737]: https://github.com/JuliaLang/julia/issues/3737 [#3759]: https://github.com/JuliaLang/julia/issues/3759 [#3790]: https://github.com/JuliaLang/julia/issues/3790 [#3819]: https://github.com/JuliaLang/julia/issues/3819 @@ -1143,9 +1148,11 @@ Too numerous to mention. [#8501]: https://github.com/JuliaLang/julia/issues/8501 [#8560]: https://github.com/JuliaLang/julia/issues/8560 [#8578]: https://github.com/JuliaLang/julia/issues/8578 +[#8599]: https://github.com/JuliaLang/julia/issues/8599 [#8605]: https://github.com/JuliaLang/julia/issues/8605 [#8624]: https://github.com/JuliaLang/julia/issues/8624 [#8660]: https://github.com/JuliaLang/julia/issues/8660 +[#8672]: https://github.com/JuliaLang/julia/issues/8672 [#8712]: https://github.com/JuliaLang/julia/issues/8712 [#8734]: https://github.com/JuliaLang/julia/issues/8734 [#8750]: https://github.com/JuliaLang/julia/issues/8750 @@ -1173,12 +1180,22 @@ Too numerous to mention. [#9132]: https://github.com/JuliaLang/julia/issues/9132 [#9133]: https://github.com/JuliaLang/julia/issues/9133 [#9144]: https://github.com/JuliaLang/julia/issues/9144 +[#9198]: https://github.com/JuliaLang/julia/issues/9198 [#9249]: https://github.com/JuliaLang/julia/issues/9249 [#9261]: https://github.com/JuliaLang/julia/issues/9261 [#9271]: https://github.com/JuliaLang/julia/issues/9271 [#9294]: https://github.com/JuliaLang/julia/issues/9294 +[#9309]: https://github.com/JuliaLang/julia/issues/9309 [#9418]: https://github.com/JuliaLang/julia/issues/9418 [#9425]: https://github.com/JuliaLang/julia/issues/9425 +[#9434]: https://github.com/JuliaLang/julia/issues/9434 [#9452]: https://github.com/JuliaLang/julia/issues/9452 [#9569]: https://github.com/JuliaLang/julia/issues/9569 +[#9575]: https://github.com/JuliaLang/julia/issues/9575 [#9578]: https://github.com/JuliaLang/julia/issues/9578 +[#9690]: https://github.com/JuliaLang/julia/issues/9690 +[#9745]: https://github.com/JuliaLang/julia/issues/9745 +[#9779]: https://github.com/JuliaLang/julia/issues/9779 +[#9957]: https://github.com/JuliaLang/julia/issues/9957 +[#10024]: https://github.com/JuliaLang/julia/issues/10024 +[#10031]: https://github.com/JuliaLang/julia/issues/10031 diff --git a/base/LineEdit.jl b/base/LineEdit.jl index 02ff0ec452a83..b9570ceb83c4f 100644 --- a/base/LineEdit.jl +++ b/base/LineEdit.jl @@ -944,7 +944,7 @@ function keymap{D<:Dict}(keymaps::Array{D}) end const escape_defaults = merge!( - AnyDict([char(i) => nothing for i=[1:26, 28:31]]), # Ignore control characters by default + AnyDict([char(i) => nothing for i=vcat(1:26, 28:31)]), # Ignore control characters by default AnyDict( # And ignore other escape sequences by default "\e*" => nothing, "\e[*" => nothing, diff --git a/base/REPLCompletions.jl b/base/REPLCompletions.jl index cf2048678b71b..90fb2c2aa4f36 100644 --- a/base/REPLCompletions.jl +++ b/base/REPLCompletions.jl @@ -228,7 +228,7 @@ function completions(string, pos) # also search for packages s = string[startpos:pos] if dotpos <= startpos - for dir in [Pkg.dir(), LOAD_PATH, pwd()] + for dir in [Pkg.dir(); LOAD_PATH; pwd()] isdir(dir) || continue for pname in readdir(dir) if pname[1] != '.' && pname != "METADATA" && diff --git a/base/abstractarray.jl b/base/abstractarray.jl index ab16d04c4c153..96c5f23532e82 100644 --- a/base/abstractarray.jl +++ b/base/abstractarray.jl @@ -6,6 +6,45 @@ typealias AbstractVecOrMat{T} Union(AbstractVector{T}, AbstractMatrix{T}) ## Basic functions ## +vect() = Array(Any, 0) +vect{T}(X::T...) = T[ X[i] for i=1:length(X) ] + +const _oldstyle_array_vcat_ = true + +if _oldstyle_array_vcat_ + function oldstyle_vcat_warning(n::Int) + if n == 1 + before = "a" + after = "a;" + elseif n == 2 + before = "a,b" + after = "a;b" + else + before = "a,b,..." + after = "a;b;..." + end + depwarn("[$before] concatenation is deprecated; use [$after] instead", :vect) + end + function vect(A::AbstractArray...) + oldstyle_vcat_warning(length(A)) + vcat(A...) + end + function vect(X...) + for a in X + if typeof(a) <: AbstractArray + oldstyle_vcat_warning(length(X)) + break + end + end + vcat(X...) + end +else + function vect(X...) + T = promote_typeof(X...) + T[ X[i] for i=1:length(X) ] + end +end + size{T,n}(t::AbstractArray{T,n}, d) = d <= n ? size(t)[d] : 1 size(x, d1::Integer, d2::Integer, dx::Integer...) = tuple(size(x, d1), size(x, d2, dx...)...) eltype(x) = Any @@ -488,7 +527,7 @@ function circshift{T,N}(a::AbstractArray{T,N}, shiftamts) for i=1:N s = size(a,i) d = i<=length(shiftamts) ? shiftamts[i] : 0 - I = tuple(I..., d==0 ? [1:s] : mod([-d:s-1-d], s).+1) + I = tuple(I..., d==0 ? [1:s;] : mod([-d:s-1-d;], s).+1) end a[(I::NTuple{N,Vector{Int}})...] end @@ -577,18 +616,12 @@ vcat{T}(X::T...) = T[ X[i] for i=1:length(X) ] vcat{T<:Number}(X::T...) = T[ X[i] for i=1:length(X) ] function vcat(X::Number...) - T = Bottom - for x in X - T = promote_type(T,typeof(x)) - end + T = promote_typeof(X...) hvcat_fill(Array(T,length(X)), X) end function hcat(X::Number...) - T = Bottom - for x in X - T = promote_type(T,typeof(x)) - end + T = promote_typeof(X...) hvcat_fill(Array(T,1,length(X)), X) end @@ -663,7 +696,13 @@ function vcat{T}(A::AbstractMatrix{T}...) end ## cat: general case + function cat(catdims, X...) + T = promote_type(map(x->isa(x,AbstractArray) ? eltype(x) : typeof(x), X)...) + cat_t(catdims, T, X...) +end + +function cat_t(catdims, typeC::Type, X...) catdims = collect(catdims) nargs = length(X) ndimsX = Int[isa(a,AbstractArray) ? ndims(a) : 0 for a in X] @@ -674,13 +713,11 @@ function cat(catdims, X...) dims2cat[catdims[k]]=k end - typeC = isa(X[1],AbstractArray) ? eltype(X[1]) : typeof(X[1]) dimsC = Int[d <= ndimsX[1] ? size(X[1],d) : 1 for d=1:ndimsC] for k = 1:length(catdims) catsizes[1,k] = dimsC[catdims[k]] end for i = 2:nargs - typeC = promote_type(typeC, isa(X[i], AbstractArray) ? eltype(X[i]) : typeof(X[i])) for d = 1:ndimsC currentdim = (d <= ndimsX[i] ? size(X[i],d) : 1) if dims2cat[d]==0 @@ -711,57 +748,19 @@ end vcat(X...) = cat(1, X...) hcat(X...) = cat(2, X...) -cat{T}(catdims, A::AbstractArray{T}...) = cat_t(catdims, T, A...) - -cat(catdims, A::AbstractArray...) = - cat_t(catdims, promote_eltype(A...), A...) - -function cat_t(catdims, typeC, A::AbstractArray...) - catdims = collect(catdims) - nargs = length(A) - ndimsA = Int[ndims(a) for a in A] - ndimsC = max(maximum(ndimsA), maximum(catdims)) - catsizes = zeros(Int,(nargs,length(catdims))) - dims2cat = zeros(Int,ndimsC) - for k = 1:length(catdims) - dims2cat[catdims[k]]=k - end +typed_vcat(T::Type, X...) = cat_t(1, T, X...) +typed_hcat(T::Type, X...) = cat_t(2, T, X...) - dimsC = Int[d <= ndimsA[1] ? size(A[1],d) : 1 for d=1:ndimsC] - for k = 1:length(catdims) - catsizes[1,k] = dimsC[catdims[k]] - end - for i = 2:nargs - for d = 1:ndimsC - currentdim = (d <= ndimsA[i] ? size(A[i],d) : 1) - if dims2cat[d]==0 - dimsC[d] == currentdim || throw(DimensionMismatch("mismatch in dimension $(d)")) - else - dimsC[d] += currentdim - catsizes[i,dims2cat[d]] = currentdim - end - end - end +cat{T}(catdims, A::AbstractArray{T}...) = cat_t(catdims, T, A...) - C = similar(full(A[1]), typeC, tuple(dimsC...)) - if length(catdims)>1 - fill!(C,0) - end - - offsets = zeros(Int,length(catdims)) - for i=1:nargs - cat_one = [ dims2cat[d]==0 ? (1:dimsC[d]) : (offsets[dims2cat[d]]+(1:catsizes[i,dims2cat[d]])) for d=1:ndimsC] - C[cat_one...] = A[i] - for k = 1:length(catdims) - offsets[k] += catsizes[i,k] - end - end - return C -end +cat(catdims, A::AbstractArray...) = cat_t(catdims, promote_eltype(A...), A...) vcat(A::AbstractArray...) = cat(1, A...) hcat(A::AbstractArray...) = cat(2, A...) +typed_vcat(T::Type, A::AbstractArray...) = cat_t(1, T, A...) +typed_hcat(T::Type, A::AbstractArray...) = cat_t(2, T, A...) + # 2d horizontal and vertical concatenation function hvcat(nbc::Integer, as...) @@ -852,26 +851,49 @@ function hvcat_fill(a, xs) a end -function hvcat(rows::(Int...), xs::Number...) +function typed_hvcat(T::Type, rows::(Int...), xs::Number...) nr = length(rows) nc = rows[1] - #error check for i = 2:nr if nc != rows[i] throw(ArgumentError("row $(i) has mismatched number of columns")) end end len = length(xs) - T = typeof(xs[1]) - for i=2:len - T = promote_type(T,typeof(xs[i])) - end if nr*nc != len throw(ArgumentError("argument count $(len) does not match specified shape $((nr,nc))")) end hvcat_fill(Array(T, nr, nc), xs) end +function hvcat(rows::(Int...), xs::Number...) + T = promote_typeof(xs...) + typed_hvcat(T, rows, xs...) +end + +# fallback definition of hvcat in terms of hcat and vcat +function hvcat(rows::(Int...), as...) + nbr = length(rows) # number of block rows + rs = cell(nbr) + a = 1 + for i = 1:nbr + rs[i] = hcat(as[a:a-1+rows[i]]...) + a += rows[i] + end + vcat(rs...) +end + +function typed_hvcat(T::Type, rows::(Int...), as...) + nbr = length(rows) # number of block rows + rs = cell(nbr) + a = 1 + for i = 1:nbr + rs[i] = hcat(as[a:a-1+rows[i]]...) + a += rows[i] + end + T[rs...;] +end + ## Reductions and scans ## function isequal(A::AbstractArray, B::AbstractArray) @@ -984,18 +1006,6 @@ end ## Other array functions ## -# fallback definition of hvcat in terms of hcat and vcat -function hvcat(rows::(Int...), as...) - nbr = length(rows) # number of block rows - rs = cell(nbr) - a = 1 - for i = 1:nbr - rs[i] = hcat(as[a:a-1+rows[i]]...) - a += rows[i] - end - vcat(rs...) -end - function repmat(a::AbstractVecOrMat, m::Int, n::Int=1) o, p = size(a,1), size(a,2) b = similar(a, o*m, p*n) @@ -1252,7 +1262,7 @@ function mapslices(f::Function, A::AbstractArray, dims::AbstractVector) dimsA = [size(A)...] ndimsA = ndims(A) - alldims = [1:ndimsA] + alldims = [1:ndimsA;] otherdims = setdiff(alldims, dims) diff --git a/base/array.jl b/base/array.jl index ea64b6504ecee..16e0b23619e41 100644 --- a/base/array.jl +++ b/base/array.jl @@ -140,12 +140,15 @@ end getindex(T::(Type...)) = Array(T,0) +if _oldstyle_array_vcat_ # T[a:b] and T[a:s:b] also construct typed ranges function getindex{T<:Union(Char,Number)}(::Type{T}, r::Range) + depwarn("T[a:b] concatenation is deprecated; use T[a:b;] instead", :getindex) copy!(Array(T,length(r)), r) end function getindex{T<:Union(Char,Number)}(::Type{T}, r1::Range, rs::Range...) + depwarn("T[a:b,...] concatenation is deprecated; use T[a:b;...] instead", :getindex) a = Array(T,length(r1)+sum(length,rs)) o = 1 copy!(a, o, r1) @@ -156,6 +159,7 @@ function getindex{T<:Union(Char,Number)}(::Type{T}, r1::Range, rs::Range...) end return a end +end function fill!(a::Union(Array{UInt8}, Array{Int8}), x::Integer) ccall(:memset, Ptr{Void}, (Ptr{Void}, Cint, Csize_t), a, x, length(a)) @@ -239,6 +243,8 @@ convert{T,n}(::Type{Array{T,n}}, x::Array{T,n}) = x convert{T,n,S}(::Type{Array{T}}, x::Array{S,n}) = convert(Array{T,n}, x) convert{T,n,S}(::Type{Array{T,n}}, x::Array{S,n}) = copy!(similar(x,T), x) +promote_rule{T,n,S}(::Type{Array{T,n}}, ::Type{Array{S,n}}) = Array{promote_type(T,S),n} + function collect(T::Type, itr) if applicable(length, itr) # when length() isn't defined this branch might pollute the diff --git a/base/base64.jl b/base/base64.jl index 0a1cf481153cd..d0b2261125bec 100644 --- a/base/base64.jl +++ b/base/base64.jl @@ -30,7 +30,7 @@ end # Based on code by Stefan Karpinski from https://github.com/hackerschool/WebSockets.jl (distributed under the same MIT license as Julia) -const b64chars = ['A':'Z','a':'z','0':'9','+','/'] +const b64chars = ['A':'Z';'a':'z';'0':'9';'+';'/'] const base64_pad = uint8('=') diff --git a/base/combinatorics.jl b/base/combinatorics.jl index ebf86226e671f..770183d7510a8 100644 --- a/base/combinatorics.jl +++ b/base/combinatorics.jl @@ -259,7 +259,7 @@ function combinations(a, t::Integer) Combinations(a, t) end -start(c::Combinations) = [1:c.t] +start(c::Combinations) = [1:c.t;] function next(c::Combinations, s) comb = c.a[s] if c.t == 0 @@ -293,7 +293,7 @@ length(c::Permutations) = factorial(length(c.a)) permutations(a) = Permutations(a) -start(p::Permutations) = [1:length(p.a)] +start(p::Permutations) = [1:length(p.a);] function next(p::Permutations, s) perm = p.a[s] if length(p.a) == 0 @@ -404,7 +404,7 @@ function nextfixedpartition(n, m, bs) as = copy(bs) if isempty(as) # First iteration - as = [n-m+1, ones(Int, m-1)] + as = [n-m+1; ones(Int, m-1)] elseif as[2] < as[1]-1 # Most common iteration as[1] -= 1 diff --git a/base/dates/periods.jl b/base/dates/periods.jl index 2201e9d9b5d9e..36e623a391c32 100644 --- a/base/dates/periods.jl +++ b/base/dates/periods.jl @@ -288,4 +288,3 @@ days(c::Week) = 7*value(c) days(c::Year) = 365.2425*value(c) days(c::Month) = 30.436875*value(c) days(c::CompoundPeriod) = isempty(c.periods)?0.0 : Float64(sum(days,c.periods)) - diff --git a/base/docs.jl b/base/docs.jl index 36f3e6f1ed61c..137c31759edcc 100644 --- a/base/docs.jl +++ b/base/docs.jl @@ -113,7 +113,7 @@ function doc(f::Function, m::Method) end catdoc() = nothing -catdoc(xs...) = [xs...] +catdoc(xs...) = vcat(xs...) # Modules @@ -525,8 +525,8 @@ moduleusings(mod) = ccall(:jl_module_usings, Any, (Any,), mod) filtervalid(names) = filter(x->!ismatch(r"#", x), map(string, names)) accessible(mod::Module) = - [names(mod, true, true), - map(names, moduleusings(mod))..., + [names(mod, true, true); + map(names, moduleusings(mod))...; builtins] |> unique |> filtervalid completions(name) = fuzzysort(name, accessible(current_module())) diff --git a/base/dsp.jl b/base/dsp.jl index cf65e18c2b865..5f8b8d23c543f 100644 --- a/base/dsp.jl +++ b/base/dsp.jl @@ -111,8 +111,8 @@ function conv{T<:Base.LinAlg.BlasFloat}(u::StridedVector{T}, v::StridedVector{T} nv = length(v) n = nu + nv - 1 np2 = n > 1024 ? nextprod([2,3,5], n) : nextpow2(n) - upad = [u, zeros(T, np2 - nu)] - vpad = [v, zeros(T, np2 - nv)] + upad = [u; zeros(T, np2 - nu)] + vpad = [v; zeros(T, np2 - nv)] if T <: Real p = plan_rfft(upad) y = irfft(p(upad).*p(vpad), np2) diff --git a/base/fftw.jl b/base/fftw.jl index f728ce80a6a77..c75eaff4b95f2 100644 --- a/base/fftw.jl +++ b/base/fftw.jl @@ -260,7 +260,7 @@ function dims_howmany(X::StridedArray, Y::StridedArray, ist = [strides(X)...] ost = [strides(Y)...] dims = [sz[reg] ist[reg] ost[reg]]' - oreg = [1:ndims(X)] + oreg = [1:ndims(X);] oreg[reg] = 0 oreg = filter(d -> d > 0, oreg) howmany = [sz[oreg] ist[oreg] ost[oreg]]' diff --git a/base/inference.jl b/base/inference.jl index 81a929cec6baf..24044823e92bb 100644 --- a/base/inference.jl +++ b/base/inference.jl @@ -2905,7 +2905,7 @@ function inlining_pass(e::Expr, sv, ast) return (e,stmts) end end - e.args = [Any[e.args[3]], newargs...] + e.args = [Any[e.args[3]]; newargs...] # now try to inline the simplified call diff --git a/base/intfuncs.jl b/base/intfuncs.jl index 20befe5187573..e86ab210ff153 100644 --- a/base/intfuncs.jl +++ b/base/intfuncs.jl @@ -271,8 +271,8 @@ end num2hex(n::Integer) = hex(n, sizeof(n)*2) -const base36digits = ['0':'9','a':'z'] -const base62digits = ['0':'9','A':'Z','a':'z'] +const base36digits = ['0':'9';'a':'z'] +const base62digits = ['0':'9';'A':'Z';'a':'z'] function base(b::Int, x::Unsigned, pad::Int, neg::Bool) 2 <= b <= 62 || throw(ArgumentError("base must be 2 ≤ base ≤ 62, got $b")) diff --git a/base/io.jl b/base/io.jl index 62fb504e9e784..6c366fc759f6f 100644 --- a/base/io.jl +++ b/base/io.jl @@ -6,7 +6,7 @@ ## byte-order mark, ntoh & hton ## -const ENDIAN_BOM = reinterpret(UInt32,uint8([1:4]))[1] +const ENDIAN_BOM = reinterpret(UInt32,uint8([1:4;]))[1] if ENDIAN_BOM == 0x01020304 ntoh(x) = x diff --git a/base/linalg/arnoldi.jl b/base/linalg/arnoldi.jl index 543ba9e5ce63b..f175eeb53f327 100644 --- a/base/linalg/arnoldi.jl +++ b/base/linalg/arnoldi.jl @@ -137,7 +137,7 @@ function svds{S}(X::S; nsv::Int = 6, ritzvec::Bool = true, tol::Float64 = 0.0, m end otype = eltype(X) ex = eigs(SVDOperator{otype,S}(X), I; ritzvec = ritzvec, nev = 2*nsv, tol = tol, maxiter = maxiter) - ind = [1:2:nsv*2] + ind = [1:2:nsv*2;] sval = abs(ex[1][ind]) ritzvec || return (sval, ex[2], ex[3], ex[4], ex[5]) diff --git a/base/linalg/factorization.jl b/base/linalg/factorization.jl index 8fe14c99d8f9b..6865d69dd00fa 100644 --- a/base/linalg/factorization.jl +++ b/base/linalg/factorization.jl @@ -391,7 +391,7 @@ function \{TA,Tb}(A::Union(QR{TA},QRCompactWY{TA},QRPivoted{TA}),b::StridedVecto S = promote_type(TA,Tb) m,n = size(A) m == length(b) || throw(DimensionMismatch("left hand side has $m rows, but right hand side has length $(length(b))")) - x = n > m ? A_ldiv_B!(convert(Factorization{S},A),[b,zeros(S,n-m)]) : A_ldiv_B!(convert(Factorization{S},A), S == Tb ? copy(b) : convert(AbstractVector{S}, b)) + x = n > m ? A_ldiv_B!(convert(Factorization{S},A),[b;zeros(S,n-m)]) : A_ldiv_B!(convert(Factorization{S},A), S == Tb ? copy(b) : convert(AbstractVector{S}, b)) return length(x) > n ? x[1:n] : x end function \{TA,TB}(A::Union(QR{TA},QRCompactWY{TA},QRPivoted{TA}),B::StridedMatrix{TB}) diff --git a/base/linalg/generic.jl b/base/linalg/generic.jl index f63daaa7cf6e9..795eb3a44dce5 100644 --- a/base/linalg/generic.jl +++ b/base/linalg/generic.jl @@ -53,8 +53,8 @@ function diff(A::AbstractMatrix, dim::Integer) end -gradient(F::AbstractVector) = gradient(F, [1:length(F)]) -gradient(F::AbstractVector, h::Real) = gradient(F, [h*(1:length(F))]) +gradient(F::AbstractVector) = gradient(F, [1:length(F);]) +gradient(F::AbstractVector, h::Real) = gradient(F, [h*(1:length(F));]) diag(A::AbstractVector) = error("use diagm instead of diag to construct a diagonal matrix") diff --git a/base/linalg/lapack.jl b/base/linalg/lapack.jl index f825d293025c2..ad6afb34a0244 100644 --- a/base/linalg/lapack.jl +++ b/base/linalg/lapack.jl @@ -2260,7 +2260,7 @@ for (stev, stebz, stegr, stein, elty) in function stegr!(jobz::BlasChar, range::BlasChar, dv::Vector{$elty}, ev::Vector{$elty}, vl::Real, vu::Real, il::Integer, iu::Integer) n = length(dv) if length(ev) != (n-1) throw(DimensionMismatch("stebz!")) end - eev = [ev, zero($elty)] + eev = [ev; zero($elty)] abstol = Array($elty, 1) m = Array(BlasInt, 1) w = similar(dv, $elty, n) diff --git a/base/linalg/lu.jl b/base/linalg/lu.jl index 682a424242d14..f045b25d1185b 100644 --- a/base/linalg/lu.jl +++ b/base/linalg/lu.jl @@ -86,7 +86,7 @@ size(A::LU) = size(A.factors) size(A::LU,n) = size(A.factors,n) function ipiv2perm{T}(v::AbstractVector{T}, maxi::Integer) - p = T[1:maxi] + p = T[1:maxi;] @inbounds for i in 1:length(v) p[i], p[v[i]] = p[v[i]], p[i] end diff --git a/base/loading.jl b/base/loading.jl index 44702305ee14d..8c2e4242d5fe2 100644 --- a/base/loading.jl +++ b/base/loading.jl @@ -10,7 +10,7 @@ function find_in_path(name::AbstractString) name = string(base,".jl") isfile(name) && return abspath(name) end - for prefix in [Pkg.dir(), LOAD_PATH] + for prefix in [Pkg.dir(); LOAD_PATH] path = joinpath(prefix, name) isfile(path) && return abspath(path) path = joinpath(prefix, base, "src", name) diff --git a/base/markdown/Common/block.jl b/base/markdown/Common/block.jl index da93119282871..db2b2c76a47bd 100644 --- a/base/markdown/Common/block.jl +++ b/base/markdown/Common/block.jl @@ -122,7 +122,7 @@ type List List(x::AbstractVector) = new(x) end -List(xs...) = List([xs...]) +List(xs...) = List(vcat(xs...)) const bullets = ["* ", "• ", "+ ", "- "] diff --git a/base/markdown/parse/parse.jl b/base/markdown/parse/parse.jl index 6f6b89aa0c581..eac545cc57113 100644 --- a/base/markdown/parse/parse.jl +++ b/base/markdown/parse/parse.jl @@ -6,7 +6,7 @@ type MD new(content, meta) end -MD(xs...) = MD([xs...]) +MD(xs...) = MD(vcat(xs...)) # Forward some array methods @@ -71,7 +71,7 @@ parseinline(s) = parseinline(s, _config_ == nothing ? julia : _config_) function parse(stream::IO, block::MD, config::Config; breaking = false) skipblank(stream) eof(stream) && return false - for parser in (breaking ? config.breaking : [config.breaking, config.regular]) + for parser in (breaking ? config.breaking : [config.breaking; config.regular]) parser(stream, block, config) && return true end return false diff --git a/base/markdown/render/terminal/formatting.jl b/base/markdown/render/terminal/formatting.jl index d46526be3415b..6579176f205be 100644 --- a/base/markdown/render/terminal/formatting.jl +++ b/base/markdown/render/terminal/formatting.jl @@ -58,7 +58,7 @@ lines(s) = split(s, "\n") # This could really be more efficient function wrapped_lines(s::String; width = 80, i = 0) if ismatch(r"\n", s) - return [map(s->wrapped_lines(s, width = width, i = i), split(s, "\n"))...] + return vcat(map(s->wrapped_lines(s, width = width, i = i), split(s, "\n"))...) end ws = words(s) lines = String[ws[1]] diff --git a/base/multi.jl b/base/multi.jl index 4d5c3ad3d13a7..7ecf0694b92a1 100644 --- a/base/multi.jl +++ b/base/multi.jl @@ -310,7 +310,7 @@ function rmprocs(args...; waitfor = 0.0) global rmprocset empty!(rmprocset) - for i in [args...] + for i in vcat(args...) if i == 1 warn("rmprocs: process 1 not removed") else diff --git a/base/pkg/resolve/maxsum.jl b/base/pkg/resolve/maxsum.jl index 504535a9b2c31..04d7811d11fcd 100644 --- a/base/pkg/resolve/maxsum.jl +++ b/base/pkg/resolve/maxsum.jl @@ -148,7 +148,7 @@ type Graph end end - perm = [1:np] + perm = [1:np;] return new(gadj, gmsk, gdir, adjdict, spp, perm, np) end diff --git a/base/random.jl b/base/random.jl index 696784df9f72f..eb0e3bddd1003 100644 --- a/base/random.jl +++ b/base/random.jl @@ -1164,7 +1164,7 @@ function Base.convert(::Type{UUID}, s::AbstractString) end u = uint128(0) - for i in [1:8, 10:13, 15:18, 20:23, 25:36] + for i in [1:8; 10:13; 15:18; 20:23; 25:36] u <<= 4 d = s[i]-'0' u |= 0xf & (d-39*(d>9)) diff --git a/base/show.jl b/base/show.jl index 57f3f460087fe..6309574ced132 100644 --- a/base/show.jl +++ b/base/show.jl @@ -250,7 +250,7 @@ const expr_infix = Set([:(:), :(->), symbol("::")]) const expr_infix_any = union(expr_infix, expr_infix_wide) const expr_calls = Dict(:call =>('(',')'), :calldecl =>('(',')'), :ref =>('[',']'), :curly =>('{','}')) const expr_parens = Dict(:tuple=>('(',')'), :vcat=>('[',']'), :cell1d=>("Any[","]"), - :hcat =>('[',']'), :row =>('[',']')) + :hcat =>('[',']'), :row =>('[',']'), :vect=>('[',']')) ## AST decoding helpers ## diff --git a/base/sort.jl b/base/sort.jl index bb2b56b5f41a8..eedb0ec478f69 100644 --- a/base/sort.jl +++ b/base/sort.jl @@ -365,7 +365,7 @@ sort(v::AbstractVector; kws...) = sort!(copy(v); kws...) sortperm(v::AbstractVector; alg::Algorithm=DEFAULT_UNSTABLE, lt::Function=isless, by::Function=identity, rev::Bool=false, order::Ordering=Forward) = - sort!([1:length(v)], alg, Perm(ord(lt,by,rev,order),v)) + sort!([1:length(v);], alg, Perm(ord(lt,by,rev,order),v)) function sortperm!{I<:Integer}(x::Vector{I}, v::AbstractVector; alg::Algorithm=DEFAULT_UNSTABLE, lt::Function=isless, by::Function=identity, rev::Bool=false, order::Ordering=Forward, diff --git a/base/sparse/sparsematrix.jl b/base/sparse/sparsematrix.jl index be89b0e32bdd9..8deada94d0e92 100644 --- a/base/sparse/sparsematrix.jl +++ b/base/sparse/sparsematrix.jl @@ -417,8 +417,8 @@ eye(S::SparseMatrixCSC) = speye(S) function speye(T::Type, m::Integer, n::Integer) x = min(m,n) - rowval = [1:x] - colptr = [rowval, fill(int(x+1), n+1-x)] + rowval = [1:x;] + colptr = [rowval; fill(int(x+1), n+1-x)] nzval = ones(T, x) return SparseMatrixCSC(m, n, colptr, rowval, nzval) end diff --git a/base/string.jl b/base/string.jl index 4b33793b2691e..36e6400883f60 100644 --- a/base/string.jl +++ b/base/string.jl @@ -1679,7 +1679,7 @@ end rsearch(a::ByteArray, b::Union(Int8,UInt8,Char)) = rsearch(a,b,length(a)) # return a random string (often useful for temporary filenames/dirnames) -let b = uint8(['0':'9','A':'Z','a':'z']) +let b = uint8(['0':'9';'A':'Z';'a':'z']) global randstring randstring(n::Int) = ASCIIString(b[rand(1:length(b),n)]) randstring() = randstring(8) diff --git a/doc/manual/arrays.rst b/doc/manual/arrays.rst index 4a2b706c25b8f..30cf1d0aa1424 100644 --- a/doc/manual/arrays.rst +++ b/doc/manual/arrays.rst @@ -96,6 +96,8 @@ Function Description .. [#] *iid*, independently and identically distributed. +The syntax ``[A, B, C, ...]`` constructs a 1-d array (vector) of its arguments. + Concatenation ------------- @@ -117,8 +119,8 @@ The concatenation functions are used so often that they have special syntax: =================== ============= Expression Calls =================== ============= +``[A; B; C; ...]`` :func:`vcat` ``[A B C ...]`` :func:`hcat` -``[A, B, C, ...]`` :func:`vcat` ``[A B; C D; ...]`` :func:`hvcat` =================== ============= @@ -131,8 +133,11 @@ Typed array initializers An array with a specific element type can be constructed using the syntax ``T[A, B, C, ...]``. This will construct a 1-d array with element type ``T``, initialized to contain elements ``A``, ``B``, ``C``, etc. +For example ``Any[x, y, z]`` constructs a heterogeneous array that can +contain any values. -An array constructed with an explicit type annotation does not automatically concatenate its arguments. +Concatenation syntax can similarly be prefixed with a type to specify +the element type of the result. .. doctest:: @@ -140,19 +145,9 @@ An array constructed with an explicit type annotation does not automatically con 1x4 Array{Int64,2}: 1 2 3 4 - julia> Int64[[1 2] [3 4]] - ERROR: `convert` has no method matching convert(::Type{Int64}, ::Array{Int64,2}) - - You might have used a 2d row vector where a 1d column vector was required. - Note the difference between 1d column vector [1,2,3] and 2d row vector [1 2 3]. - You can convert to a column vector with the vec() function. - in setindex! at array.jl:307 - - julia> Array[[1 2] [3 4]] - 1x2 Array{Array{T,N},2}: - 1x2 Array{Int64,2}: - 1 2 1x2 Array{Int64,2}: - 3 4 + julia> Int8[[1 2] [3 4]] + 1x4 Array{Int8,2}: + 1 2 3 4 .. _comprehensions: diff --git a/src/julia-parser.scm b/src/julia-parser.scm index 74f5aade494ee..0d5b9d77d9dc4 100644 --- a/src/julia-parser.scm +++ b/src/julia-parser.scm @@ -963,13 +963,10 @@ (string (deprecated-dict-replacement ex) "(a=>b, ...)")) (loop (list* 'typed_dict ex (cdr al)))) (loop (list* 'ref ex (cdr al))))) + ((vect) (loop (list* 'ref ex (cdr al)))) ((hcat) (loop (list* 'typed_hcat ex (cdr al)))) ((vcat) - (if (any (lambda (x) - (and (pair? x) (eq? (car x) 'row))) - (cdr al)) - (loop (list* 'typed_vcat ex (cdr al))) - (loop (list* 'ref ex (cdr al))))) + (loop (list* 'typed_vcat ex (cdr al)))) ((comprehension) (loop (list* 'typed_comprehension ex (cdr al)))) ((dict_comprehension) @@ -1416,21 +1413,20 @@ (error (string "missing comma or " closer " in argument list")))))))))) -; parse [] concatenation expressions and {} cell expressions -(define (parse-vcat s first closer) +(define (parse-vect s first closer) (let loop ((lst '()) (nxt first)) (let ((t (require-token s))) (if (eqv? t closer) (begin (take-token s) - (cons 'vcat (reverse (cons nxt lst)))) + (cons 'vect (reverse (cons nxt lst)))) (case t ((#\,) (take-token s) (if (eqv? (require-token s) closer) ;; allow ending with , (begin (take-token s) - (cons 'vcat (reverse (cons nxt lst)))) + (cons 'vect (reverse (cons nxt lst)))) (loop (cons nxt lst) (parse-eq* s)))) ((#\;) (if (eqv? (require-token s) closer) @@ -1443,7 +1439,7 @@ (error "missing separator in array expression"))))))) (define (parse-dict s first closer) - (let ((v (parse-vcat s first closer))) + (let ((v (parse-vect s first closer))) (if (any dict-literal? (cdr v)) (if (every dict-literal? (cdr v)) `(dict ,@(cdr v)) @@ -1462,7 +1458,7 @@ `(dict_comprehension ,@(cdr c)) (error "invalid dict comprehension")))) -(define (parse-matrix s first closer) +(define (parse-matrix s first closer gotnewline) (define (fix head v) (cons head (reverse v))) (define (update-outer v outer) (cond ((null? v) outer) @@ -1471,7 +1467,7 @@ (define semicolon (eqv? (peek-token s) #\;)) (let loop ((vec (list first)) (outer '())) - (let ((t (if (eqv? (peek-token s) #\newline) + (let ((t (if (or (eqv? (peek-token s) #\newline) gotnewline) #\newline (require-token s)))) (if (eqv? t closer) @@ -1479,11 +1475,13 @@ (if (pair? outer) (fix 'vcat (update-outer vec outer)) (if (or (null? vec) (null? (cdr vec))) - (fix 'vcat vec) ; [x] => (vcat x) + (fix 'vect vec) ; [x] => (vect x) (fix 'hcat vec)))) ; [x y] => (hcat x y) (case t ((#\; #\newline) - (take-token s) (loop '() (update-outer vec outer))) + (or gotnewline (take-token s)) + (set! gotnewline #f) + (loop '() (update-outer vec outer))) ((#\,) (error "unexpected comma in matrix expression")) ((#\] #\}) @@ -1522,14 +1520,19 @@ (if (or (null? isdict) (not (car isdict))) (syntax-deprecation-warning s "[a=>b, ...]" "Dict(a=>b, ...)")) (parse-dict s first closer))) - (case (peek-token s) - ((#\,) - (parse-vcat s first closer)) - ((for) - (take-token s) - (parse-comprehension s first closer)) - (else - (parse-matrix s first closer))))))))) + (let ((t (peek-token s))) + (cond ((or (eqv? t #\,) (eqv? t closer)) + (parse-vect s first closer)) + ((eq? t 'for) + (take-token s) + (parse-comprehension s first closer)) + ((eqv? t #\newline) + (take-token s) + (if (memv (peek-token s) (list #\, closer)) + (parse-vect s first closer) + (parse-matrix s first closer #t))) + (else + (parse-matrix s first closer #f)))))))))) ; for sequenced evaluation inside expressions: e.g. (a;b, c;d) (define (parse-stmts-within-expr s) @@ -1803,17 +1806,18 @@ (begin (syntax-deprecation-warning s "{}" "[]") '(cell1d)) (case (car vex) + ((vect) `(cell1d ,@(cdr vex))) ((comprehension) - (syntax-deprecation-warning s "{a for a in b}" "Any[a for a in b]") + (syntax-deprecation-warning s "{a for a in b}" "Any[a for a in b]") `(typed_comprehension (top Any) ,@(cdr vex))) ((dict_comprehension) - (syntax-deprecation-warning s "{a=>b for (a,b) in c}" "Dict{Any,Any}([a=>b for (a,b) in c])") + (syntax-deprecation-warning s "{a=>b for (a,b) in c}" "Dict{Any,Any}([a=>b for (a,b) in c])") `(typed_dict_comprehension (=> (top Any) (top Any)) ,@(cdr vex))) ((dict) - (syntax-deprecation-warning s "{a=>b, ...}" "Dict{Any,Any}(a=>b, ...)") + (syntax-deprecation-warning s "{a=>b, ...}" "Dict{Any,Any}(a=>b, ...)") `(typed_dict (=> (top Any) (top Any)) ,@(cdr vex))) ((hcat) - (syntax-deprecation-warning s "{a b ...}" "Any[a b ...]") + (syntax-deprecation-warning s "{a b ...}" "Any[a b ...]") `(cell2d 1 ,(length (cdr vex)) ,@(cdr vex))) (else ; (vcat ...) (if (and (pair? (cadr vex)) (eq? (caadr vex) 'row)) @@ -1828,25 +1832,25 @@ (cddr vex))) (error "inconsistent shape in cell expression")) (begin - (syntax-deprecation-warning s "{a b; c d}" "Any[a b; c d]")) - `(cell2d ,nr ,nc - ,@(apply append - ;; transpose to storage order - (apply map list - (map cdr (cdr vex)))))) + (syntax-deprecation-warning s "{a b; c d}" "Any[a b; c d]") + `(cell2d ,nr ,nc + ,@(apply append + ;; transpose to storage order + (apply map list + (map cdr (cdr vex))))))) (if (any (lambda (x) (and (pair? x) (eq? (car x) 'row))) (cddr vex)) (error "inconsistent shape in cell expression") (begin - (syntax-deprecation-warning s "{a,b, ...}" "Any[a,b, ...]") - `(cell1d ,@(cdr vex))))))))))) + (syntax-deprecation-warning s "{a,b, ...}" "Any[a,b, ...]") + `(cell1d ,@(cdr vex))))))))))) ;; cat expression ((eqv? t #\[ ) (take-token s) (let ((vex (parse-cat s #\]))) - (if (null? vex) '(vcat) vex))) + (if (null? vex) '(vect) vex))) ;; string literal ((eqv? t #\") diff --git a/src/julia-syntax.scm b/src/julia-syntax.scm index de459d1a5a70b..0487892b401b1 100644 --- a/src/julia-syntax.scm +++ b/src/julia-syntax.scm @@ -1981,6 +1981,9 @@ (error "invalid \":\" outside indexing")) `(call colon ,.(map expand-forms (cdr e)))) + 'vect + (lambda (e) (expand-forms `(call (top vect) ,@(cdr e)))) + 'hcat (lambda (e) (expand-forms `(call hcat ,.(map expand-forms (cdr e))))) @@ -2005,47 +2008,26 @@ `(call vcat ,@a)))))) 'typed_hcat - (lambda (e) - (let ((t (cadr e)) - (a (cddr e))) - (let ((result (make-jlgensym)) - (ncols (length a))) - `(block - #;(if (call (top !) (call (top isa) ,t Type)) - (call (top error) "invalid array index")) - (= ,result (call (top Array) ,(expand-forms t) 1 ,ncols)) - ,.(map (lambda (x i) `(call (top setindex!) ,result - ,(expand-forms x) ,i)) - a (cdr (iota (+ ncols 1)))) - ,result)))) + (lambda (e) `(call (top typed_hcat) ,(expand-forms (cadr e)) ,.(map expand-forms (cddr e)))) 'typed_vcat (lambda (e) (let ((t (cadr e)) - (rows (cddr e))) - (if (any (lambda (x) (not (and (pair? x) (eq? 'row (car x))))) rows) - (error "invalid array literal") - (let ((result (make-jlgensym)) - (nrows (length rows)) - (ncols (length (cdar rows)))) - (if (any (lambda (x) (not (= (length (cdr x)) ncols))) rows) - (error "invalid array literal") - `(block - #;(if (call (top !) (call (top isa) ,t Type)) - (call (top error) "invalid array index")) - (= ,result (call (top Array) ,(expand-forms t) ,nrows ,ncols)) - ,.(apply nconc - (map - (lambda (row i) - (map - (lambda (x j) - `(call (top setindex!) ,result - ,(expand-forms x) ,i ,j)) - (cdr row) - (cdr (iota (+ ncols 1))))) - rows - (cdr (iota (+ nrows 1))))) - ,result)))))) + (a (cddr e))) + (expand-forms + (if (any (lambda (x) + (and (pair? x) (eq? (car x) 'row))) + a) + ;; convert nested hcat inside vcat to hvcat + (let ((rows (map (lambda (x) + (if (and (pair? x) (eq? (car x) 'row)) + (cdr x) + (list x))) + a))) + `(call (top typed_hvcat) ,t + (tuple ,.(map length rows)) + ,.(apply append rows))) + `(call (top typed_vcat) ,t ,@a))))) '|'| (lambda (e) `(call ctranspose ,(expand-forms (cadr e)))) '|.'| (lambda (e) `(call transpose ,(expand-forms (cadr e)))) diff --git a/src/uv_constants.h b/src/uv_constants.h index 21302fbf8e701..3518e791439e5 100644 --- a/src/uv_constants.h +++ b/src/uv_constants.h @@ -5,8 +5,8 @@ const uv_handle_types = [UV_HANDLE_TYPE_MAP(XX) :UV_FILE] const uv_req_types = [UV_REQ_TYPE_MAP(XX)] const uv_err_vals = [UV_ERRNO_MAP(YY)] let - handles = [:UV_UNKNOWN_HANDLE, uv_handle_types, :UV_HANDLE_TYPE_MAX, :UV_RAW_FD, :UV_RAW_HANDLE] - reqs = [:UV_UNKNOWN_REQ, uv_req_types, :UV_REQ_TYPE_PRIVATE,:UV_REQ_TYPE_MAX] + handles = [:UV_UNKNOWN_HANDLE; uv_handle_types; :UV_HANDLE_TYPE_MAX; :UV_RAW_FD; :UV_RAW_HANDLE] + reqs = [:UV_UNKNOWN_REQ; uv_req_types; :UV_REQ_TYPE_PRIVATE; :UV_REQ_TYPE_MAX] for i=0:(length(handles)-1) @eval const $(handles[i+1]) = $i end diff --git a/test/arrayops.jl b/test/arrayops.jl index 9d2f16b513116..485c2d2986045 100644 --- a/test/arrayops.jl +++ b/test/arrayops.jl @@ -73,12 +73,10 @@ a = rand(1, 1, 8, 8, 1) sz = (5,8,7) A = reshape(1:prod(sz),sz...) -@test A[2:6] == [2:6] -tmp = A[1:3,2,2:4] -@test tmp == cat(3,46:48,86:88,126:128) +@test A[2:6] == [2:6;] +@test A[1:3,2,2:4] == cat(3,46:48,86:88,126:128) @test A[:,7:-3:1,5] == [191 176 161; 192 177 162; 193 178 163; 194 179 164; 195 180 165] -tmp = A[:,3:9] -@test tmp == reshape(11:45,5,7) +@test A[:,3:9] == reshape(11:45,5,7) rng = (2,2:3,2:2:5) tmp = zeros(Int,map(maximum,rng)...) tmp[rng...] = A[rng...] @@ -135,13 +133,13 @@ let @test x == -12 X = get(A, -5:5, NaN32) @test eltype(X) == Float32 - @test isnan(X) == [trues(6),falses(5)] - @test X[7:11] == [1:5] + @test isnan(X) == [trues(6);falses(5)] + @test X[7:11] == [1:5;] X = get(A, (2:4, 9:-2:-13), 0) Xv = zeros(Int, 3, 12) Xv[1:2, 2:5] = A[2:3, 7:-2:1] @test X == Xv - X2 = get(A, Vector{Int}[[2:4], [9:-2:-13]], 0) + X2 = get(A, Vector{Int}[[2:4;], [9:-2:-13;]], 0) @test X == X2 end @@ -168,13 +166,13 @@ v = [3, 7, 6] for i = 1:4 vc = copy(v) @test insert!(vc, i, 5) === vc - @test vc == [v[1:(i-1)], 5, v[i:end]] + @test vc == [v[1:(i-1)]; 5; v[i:end]] end @test_throws BoundsError insert!(v, 5, 5) # concatenation @test isequal([ones(2,2) 2*ones(2,1)], [1. 1 2; 1 1 2]) -@test isequal([ones(2,2), 2*ones(1,2)], [1. 1; 1 1; 2 2]) +@test isequal([ones(2,2); 2*ones(1,2)], [1. 1; 1 1; 2 2]) # typed array literals X = Float64[1 2 3] @@ -190,6 +188,27 @@ Y = [1. 2. 3.; 4. 5. 6.] @test size(X) == size(Y) for i = 1:length(X) @test X[i] === Y[i] end +_array_equiv(a,b) = eltype(a) == eltype(b) && a == b +@test _array_equiv(UInt8[1:3;4], [0x1,0x2,0x3,0x4]) +if !Base._oldstyle_array_vcat_ + @test_throws MethodError UInt8[1:3] + @test_throws MethodError UInt8[1:3,] + @test_throws MethodError UInt8[1:3,4:6] + a = Array(Range1{Int},1); a[1] = 1:3 + @test _array_equiv([1:3,], a) + a = Array(Range1{Int},2); a[1] = 1:3; a[2] = 4:6 + @test _array_equiv([1:3,4:6], a) +end + +# typed hvcat +let X = Float64[1 2 3; 4 5 6] + X32 = Float32[X X; X X] + @test eltype(X32) <: Float32 + for i=[1,3], j=[1,4] + @test X32[i:(i+1), j:(j+2)] == X + end +end + # "end" X = [ i+2j for i=1:5, j=1:5 ] @test X[end,end] == 15 @@ -302,7 +321,7 @@ end # All rows and columns unique A = ones(10, 10) -A[diagind(A)] = shuffle!([1:10]) +A[diagind(A)] = shuffle!([1:10;]) @test unique(A, 1) == A @test unique(A, 2) == A @@ -467,9 +486,9 @@ begin 3 3 4 4 3 3 4 4; 3 3 4 4 3 3 4 4] - A = reshape([1:8], 2, 2, 2) + A = reshape(1:8, 2, 2, 2) R = repeat(A, inner = [1, 1, 2], outer = [1, 1, 1]) - T = reshape([1:4, 1:4, 5:8, 5:8], 2, 2, 4) + T = reshape([1:4; 1:4; 5:8; 5:8], 2, 2, 4) @test R == T A = Array(Int, 2, 2, 2) A[:, :, 1] = [1 2; @@ -527,12 +546,12 @@ begin end @test (1:5)[[true,false,true,false,true]] == [1,3,5] -@test [1:5][[true,false,true,false,true]] == [1,3,5] +@test [1:5;][[true,false,true,false,true]] == [1,3,5] @test_throws BoundsError (1:5)[[true,false,true,false]] @test_throws BoundsError (1:5)[[true,false,true,false,true,false]] -@test_throws BoundsError [1:5][[true,false,true,false]] -@test_throws BoundsError [1:5][[true,false,true,false,true,false]] -a = [1:5] +@test_throws BoundsError [1:5;][[true,false,true,false]] +@test_throws BoundsError [1:5;][[true,false,true,false,true,false]] +a = [1:5;] a[[true,false,true,false,true]] = 6 @test a == [6,2,6,4,6] a[[true,false,true,false,true]] = [7,8,9] @@ -724,19 +743,19 @@ fill!(A, [1, 2]) for idx in Any[1, 2, 5, 9, 10, 1:0, 2:1, 1:1, 2:2, 1:2, 2:4, 9:8, 10:9, 9:9, 10:10, 8:9, 9:10, 6:9, 7:10] for repl in Any[[], [11], [11,22], [11,22,33,44,55]] - a = [1:10]; acopy = copy(a) + a = [1:10;]; acopy = copy(a) @test splice!(a, idx, repl) == acopy[idx] - @test a == [acopy[1:(first(idx)-1)], repl, acopy[(last(idx)+1):end]] + @test a == [acopy[1:(first(idx)-1)]; repl; acopy[(last(idx)+1):end]] end end # deleteat! for idx in Any[1, 2, 5, 9, 10, 1:0, 2:1, 1:1, 2:2, 1:2, 2:4, 9:8, 10:9, 9:9, 10:10, 8:9, 9:10, 6:9, 7:10] - a = [1:10]; acopy = copy(a) - @test deleteat!(a, idx) == [acopy[1:(first(idx)-1)], acopy[(last(idx)+1):end]] + a = [1:10;]; acopy = copy(a) + @test deleteat!(a, idx) == [acopy[1:(first(idx)-1)]; acopy[(last(idx)+1):end]] end -a = [1:10] +a = [1:10;] @test deleteat!(a, [1,3,5,7:10...]) == [2,4,6] @test_throws BoundsError deleteat!(a, 13) @test_throws BoundsError deleteat!(a, [1,13]) @@ -762,15 +781,15 @@ end # reverse @test reverse([2,3,1]) == [1,3,2] -@test reverse([1:10],1,4) == [4,3,2,1,5,6,7,8,9,10] -@test reverse([1:10],3,6) == [1,2,6,5,4,3,7,8,9,10] -@test reverse([1:10],6,10) == [1,2,3,4,5,10,9,8,7,6] +@test reverse([1:10;],1,4) == [4,3,2,1,5,6,7,8,9,10] +@test reverse([1:10;],3,6) == [1,2,6,5,4,3,7,8,9,10] +@test reverse([1:10;],6,10) == [1,2,3,4,5,10,9,8,7,6] @test reverse(1:10,1,4) == [4,3,2,1,5,6,7,8,9,10] @test reverse(1:10,3,6) == [1,2,6,5,4,3,7,8,9,10] @test reverse(1:10,6,10) == [1,2,3,4,5,10,9,8,7,6] -@test reverse!([1:10],1,4) == [4,3,2,1,5,6,7,8,9,10] -@test reverse!([1:10],3,6) == [1,2,6,5,4,3,7,8,9,10] -@test reverse!([1:10],6,10) == [1,2,3,4,5,10,9,8,7,6] +@test reverse!([1:10;],1,4) == [4,3,2,1,5,6,7,8,9,10] +@test reverse!([1:10;],3,6) == [1,2,6,5,4,3,7,8,9,10] +@test reverse!([1:10;],6,10) == [1,2,3,4,5,10,9,8,7,6] # flipdim @test isequal(flipdim([2,3,1], 1), [1,3,2]) @@ -890,7 +909,7 @@ a = Array(Float64, 9,8,7,6,5,4,3,2,1) @test size(a,9,8,7,6,5,4,3,2,19,8,7,6,5,4,3,2,1) == (1,2,3,4,5,6,7,8,1,2,3,4,5,6,7,8,9) # Multidimensional iterators -for a in ([1:5], reshape([2])) +for a in ([1:5;], reshape([2])) counter = 0 for I in eachindex(a) counter += 1 @@ -919,7 +938,7 @@ function mdsum2(A) s end -a = [1:5] +a = [1:5;] @test isa(Base.linearindexing(a), Base.LinearFast) b = sub(a, :) @test isa(Base.linearindexing(b), Base.LinearFast) @@ -940,7 +959,7 @@ for i = 1:10 unshift!(shp, 1) end -a = [1:10] +a = [1:10;] shp = [2,5] for i = 2:10 A = reshape(a, tuple(shp...)) @@ -1017,8 +1036,8 @@ val, state = next(r, state) #rotates -a = [ [ 1 0 0 ], [ 0 0 0 ] ] -@test rotr90(a,1) == [ [ 0 1 ], [ 0 0 ], [ 0 0 ] ] +a = [1 0 0; 0 0 0] +@test rotr90(a,1) == [0 1; 0 0; 0 0] @test rotr90(a,2) == rot180(a,1) @test rotr90(a,3) == rotl90(a,1) @test rotl90(a,3) == rotr90(a,1) diff --git a/test/bigint.jl b/test/bigint.jl index 3393d0af61423..a56a1169ae757 100644 --- a/test/bigint.jl +++ b/test/bigint.jl @@ -33,7 +33,7 @@ ee = typemax(Int64) @test string(d) == "-246913578024691357802469135780" @test string(a) == "123456789012345678901234567890" -for i = -10:10, j = [-10:-1,1:10] +for i = -10:10, j = [-10:-1; 1:10] @test div(BigInt(i), BigInt(j)) == div(i,j) @test fld(BigInt(i), BigInt(j)) == fld(i,j) @test mod(BigInt(i), BigInt(j)) == mod(i,j) diff --git a/test/blas.jl b/test/blas.jl index 2930fb1b2e90d..2da3f735d771d 100644 --- a/test/blas.jl +++ b/test/blas.jl @@ -13,8 +13,8 @@ for elty in [Float32, Float64, Complex64, Complex128] elm1 = convert(elty, -1) el2 = convert(elty, 2) - v14 = convert(Vector{elty}, [1:4]) - v41 = convert(Vector{elty}, [4:-1:1]) + v14 = convert(Vector{elty}, [1:4;]) + v41 = convert(Vector{elty}, [4:-1:1;]) # dot if elty <: Real diff --git a/test/broadcast.jl b/test/broadcast.jl index 2959d63f79525..d1fcfb63f08af 100644 --- a/test/broadcast.jl +++ b/test/broadcast.jl @@ -100,12 +100,12 @@ end r1 = 1:1 r2 = 1:5 ratio = [1,1/2,1/3,1/4,1/5] -@test r1.*r2 == [1:5] +@test r1.*r2 == [1:5;] @test r1./r2 == ratio -m = [1:2]' +m = [1:2;]' @test m.*r2 == [1:5 2:2:10] @test_approx_eq m./r2 [ratio 2ratio] -@test_approx_eq m./[r2] [ratio 2ratio] +@test_approx_eq m./[r2;] [ratio 2ratio] @test @inferred([0,1.2].+reshape([0,-2],1,1,2)) == reshape([0 -2; 1.2 -0.8],2,1,2) rt = Base.return_types(.+, (Array{Float64, 3}, Array{Int, 1})) diff --git a/test/char.jl b/test/char.jl index 2b78628666b4c..daa73fd9ef3f7 100644 --- a/test/char.jl +++ b/test/char.jl @@ -7,7 +7,7 @@ upperchars = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', ' plane1_playingcards = ['🂠', '🂡', '🂢', '🂣', '🂤', '🂥', '🂦', '🂧', '🂨', '🂩', '🂪', '🂫', '🂬', '🂭', '🂮'] plane2_cjkpart1 = ['𠀀', '𠀁', '𠀂', '𠀃', '𠀄', '𠀅', '𠀆', '𠀇', '𠀈', '𠀉', '𠀊', '𠀋', '𠀌', '𠀍', '𠀎', '𠀏'] -testarrays = [numberchars, lowerchars, upperchars, plane1_playingcards, plane2_cjkpart1] +testarrays = [numberchars; lowerchars; upperchars; plane1_playingcards; plane2_cjkpart1] #char(x::FloatingPoint) = char(round(UInt32,x)) @test char(1.00000001) == '\x01' #Round down diff --git a/test/combinatorics.jl b/test/combinatorics.jl index 18d22f16ec963..cd3ab0eeefc9d 100644 --- a/test/combinatorics.jl +++ b/test/combinatorics.jl @@ -12,7 +12,7 @@ @test binomial(int128(131), int128(62)) == binomial(BigInt(131), BigInt(62)) == 157311720980559117816198361912717812000 @test_throws InexactError binomial(int64(67), int64(30)) -p = shuffle([1:1000]) +p = shuffle([1:1000;]) @test isperm(p) @test all(invperm(invperm(p)) .== p) @@ -20,7 +20,7 @@ push!(p, 1) @test !isperm(p) a = randcycle(10) -@test ipermute!(permute!([1:10], a),a) == [1:10] +@test ipermute!(permute!([1:10;], a),a) == [1:10;] @test collect(combinations("abc",3)) == ["abc"] @test collect(combinations("abc",2)) == ["ab","ac","bc"] @@ -48,7 +48,7 @@ a = randcycle(10) @test length(collect(partitions('a':'h',5))) == length(partitions('a':'h',5)) for n = 0:7, k = 1:factorial(n) - p = nthperm!([1:n], k) + p = nthperm!([1:n;], k) @test isperm(p) @test nthperm(p) == k end diff --git a/test/complex.jl b/test/complex.jl index efd200711fbbf..e25428470ef6b 100644 --- a/test/complex.jl +++ b/test/complex.jl @@ -750,8 +750,8 @@ end # round #8291 @test round(Complex(1.125, 0.875), 2) == Complex(1.12, 0.88) @test round(Complex(1.5, 0.5), RoundDown, RoundUp) == Complex(1.0, 1.0) -@test round([1:5] + im) == [1:5] + im -@test round([1:5] + 0.5im) == [1.0:5.0] +@test round([1:5;] + im) == [1:5;] + im +@test round([1:5;] + 0.5im) == [1.0:5.0;] # float #8291 @test float(Complex(1, 2)) == Complex(1.0, 2.0) diff --git a/test/core.jl b/test/core.jl index 6a4c1cba7e3de..c7c6aca8a77aa 100644 --- a/test/core.jl +++ b/test/core.jl @@ -857,15 +857,15 @@ end let tst = 1 m1(i) = (tst+=1;i-1) - x = [1:4] + x = [1:4;] x[1:end] *= 2 - @test x == [2:2:8] + @test x == [2:2:8;] x[m1(end)] += 3 @test x == [2,4,9,8] @test tst == 2 # issue #1886 - X = [1:4] + X = [1:4;] r = Array(UnitRange{Int},1) r[1] = 2:3 X[r...] *= 2 @@ -915,7 +915,7 @@ end let i2098() = begin c = Any[2.0] - [1:1:c[1]] + [1:1:c[1];] end @test isequal(i2098(), [1.0,2.0]) end diff --git a/test/dates/io.jl b/test/dates/io.jl index 6a069b3345707..5b7f051bf8472 100644 --- a/test/dates/io.jl +++ b/test/dates/io.jl @@ -256,7 +256,7 @@ f = "y m d" # Vectorized dr = ["2000-01-01","2000-01-02","2000-01-03","2000-01-04","2000-01-05" ,"2000-01-06","2000-01-07","2000-01-08","2000-01-09","2000-01-10"] -dr2 = [Dates.Date(2000):Dates.Date(2000,1,10)] +dr2 = [Dates.Date(2000):Dates.Date(2000,1,10);] @test Dates.Date(dr) == dr2 @test Dates.Date(dr,"yyyy-mm-dd") == dr2 @test Dates.DateTime(dr) == Dates.DateTime(dr2) diff --git a/test/dates/ranges.jl b/test/dates/ranges.jl index d153ba2abd442..a74a227870527 100644 --- a/test/dates/ranges.jl +++ b/test/dates/ranges.jl @@ -18,7 +18,7 @@ function test_all_combos() @test_throws ArgumentError maximum(dr) @test_throws BoundsError dr[1] @test findin(dr,dr) == Int64[] - @test [dr] == T[] + @test [dr;] == T[] @test isempty(reverse(dr)) @test length(reverse(dr)) == 0 @test first(reverse(dr)) == f1-one(l1 - f1) @@ -47,8 +47,8 @@ function test_all_combos() if len < 10000 dr1 = [i for i in dr] @test length(dr1) == len - @test findin(dr,dr) == [1:len] - @test length([dr]) == len + @test findin(dr,dr) == [1:len;] + @test length([dr;]) == len end @test !isempty(reverse(dr)) @test length(reverse(dr)) == len @@ -70,7 +70,7 @@ function test_all_combos() @test_throws ArgumentError maximum(dr) @test_throws BoundsError dr[1] @test findin(dr,dr) == Int64[] - @test [dr] == T[] + @test [dr;] == T[] @test isempty(reverse(dr)) @test length(reverse(dr)) == 0 @test first(reverse(dr)) == l1+one(l1 - f1) @@ -99,8 +99,8 @@ function test_all_combos() if len < 10000 dr1 = [i for i in dr] @test length(dr1) == len - @test findin(dr,dr) == [1:len] - @test length([dr]) == len + @test findin(dr,dr) == [1:len;] + @test length([dr;]) == len end @test !isempty(reverse(dr)) @test length(reverse(dr)) == len @@ -123,7 +123,7 @@ function test_all_combos() @test_throws ArgumentError maximum(dr) @test_throws BoundsError dr[1] @test findin(dr,dr) == Int64[] - @test [dr] == T[] + @test [dr;] == T[] @test isempty(reverse(dr)) @test length(reverse(dr)) == 0 @test first(reverse(dr)) == f1-one(l1 - f1) @@ -152,8 +152,8 @@ function test_all_combos() if len < 10000 dr1 = [i for i in dr] @test length(dr1) == len - @test findin(dr,dr) == [1:len] - @test length([dr]) == len + @test findin(dr,dr) == [1:len;] + @test length([dr;]) == len end @test !isempty(reverse(dr)) @test length(reverse(dr)) == len @@ -175,7 +175,7 @@ function test_all_combos() @test_throws ArgumentError maximum(dr) @test_throws BoundsError dr[1] @test findin(dr,dr) == Int64[] - @test [dr] == T[] + @test [dr;] == T[] @test isempty(reverse(dr)) @test length(reverse(dr)) == 0 @test first(reverse(dr)) == l1+one(l1 - f1) @@ -204,8 +204,8 @@ function test_all_combos() if len < 10000 dr1 = [i for i in dr] @test length(dr1) == len - @test findin(dr,dr) == [1:len] - @test length([dr]) == len + @test findin(dr,dr) == [1:len;] + @test length([dr;]) == len end @test !isempty(reverse(dr)) @test length(reverse(dr)) == len @@ -256,7 +256,7 @@ drs2 = map(x->Dates.Date(first(x)):step(x):Dates.Date(last(x)),drs) @test map(length,drs) == map(x->size(x)[1],drs) @test map(length,drs) == map(x->length(Dates.Date(first(x)):step(x):Dates.Date(last(x))),drs) @test map(length,drs) == map(x->length(reverse(x)),drs) -@test all(map(x->findin(x,x)==[1:length(x)],drs[1:4])) +@test all(map(x->findin(x,x)==[1:length(x);],drs[1:4])) @test isempty(dr2) @test all(map(x->reverse(x) == range(last(x), -step(x), length(x)),drs)) @test all(map(x->minimum(x) == (step(x) < zero(step(x)) ? last(x) : first(x)),drs[4:end])) @@ -270,8 +270,8 @@ end) @test_throws MethodError dr + 1 a = Dates.DateTime(2013,1,1) b = Dates.DateTime(2013,2,1) -@test map!(x->x+Dates.Day(1),Array(Dates.DateTime,32),dr) == [(a+Dates.Day(1)):(b+Dates.Day(1))] -@test map(x->x+Dates.Day(1),dr) == [(a+Dates.Day(1)):(b+Dates.Day(1))] +@test map!(x->x+Dates.Day(1),Array(Dates.DateTime,32),dr) == [(a+Dates.Day(1)):(b+Dates.Day(1));] +@test map(x->x+Dates.Day(1),dr) == [(a+Dates.Day(1)):(b+Dates.Day(1));] @test map(x->a in x,drs[1:4]) == [true,true,false,true] @test a in dr @@ -334,7 +334,7 @@ drs = Any[dr,dr1,dr2,dr3,dr4,dr5,dr6,dr7,dr8,dr9,dr10, dr11,dr12,dr13,dr14,dr15,dr16,dr17,dr18,dr19,dr20] @test map(length,drs) == map(x->size(x)[1],drs) -@test all(map(x->findin(x,x)==[1:length(x)],drs[1:4])) +@test all(map(x->findin(x,x) == [1:length(x);], drs[1:4])) @test isempty(dr2) @test all(map(x->reverse(x) == last(x):-step(x):first(x),drs)) @test all(map(x->minimum(x) == (step(x) < zero(step(x)) ? last(x) : first(x)),drs[4:end])) @@ -348,8 +348,8 @@ end) @test_throws MethodError dr + 1 a = Dates.Date(2013,1,1) b = Dates.Date(2013,2,1) -@test map!(x->x+Dates.Day(1),Array(Dates.Date,32),dr) == [(a+Dates.Day(1)):(b+Dates.Day(1))] -@test map(x->x+Dates.Day(1),dr) == [(a+Dates.Day(1)):(b+Dates.Day(1))] +@test map!(x->x+Dates.Day(1),Array(Dates.Date,32),dr) == [(a+Dates.Day(1)):(b+Dates.Day(1));] +@test map(x->x+Dates.Day(1),dr) == [(a+Dates.Day(1)):(b+Dates.Day(1));] @test map(x->a in x,drs[1:4]) == [true,true,false,true] @test a in dr @@ -400,9 +400,9 @@ b = Dates.Date(2013,2,1) c = Dates.Date(2013,6,1) @test length(a:Dates.Month(1):c) == 6 -@test [a:Dates.Month(1):c] == [a + Dates.Month(1)*i for i in 0:5] -@test [a:Dates.Month(2):Dates.Date(2013,1,2)] == [a] -@test [c:Dates.Month(-1):a] == reverse([a:Dates.Month(1):c]) +@test [a:Dates.Month(1):c;] == [a + Dates.Month(1)*i for i in 0:5] +@test [a:Dates.Month(2):Dates.Date(2013,1,2);] == [a] +@test [c:Dates.Month(-1):a;] == reverse([a:Dates.Month(1):c;]) @test length(range(Date(2000),366)) == 366 function testlengths(n) @@ -490,7 +490,7 @@ testmonthranges2(100000) # Issue 5 lastdaysofmonth = [Dates.Date(2014,i,Dates.daysinmonth(2014,i)) for i=1:12] -@test [Date(2014,1,31):Dates.Month(1):Date(2015)] == lastdaysofmonth +@test [Date(2014,1,31):Dates.Month(1):Date(2015);] == lastdaysofmonth # Range addition/subtraction: let d = Dates.Day(1) diff --git a/test/dict.jl b/test/dict.jl index 96414e0e6ea6c..f2bfbab9ce001 100644 --- a/test/dict.jl +++ b/test/dict.jl @@ -209,7 +209,7 @@ end for d in (Dict("\n" => "\n", "1" => "\n", "\n" => "2"), [string(i) => i for i = 1:30], [reshape(1:i^2,i,i) => reshape(1:i^2,i,i) for i = 1:24], - [utf8(Char['α':'α'+i]) => utf8(Char['α':'α'+i]) for i = (1:10)*10], + [utf8(Char['α':'α'+i;]) => utf8(Char['α':'α'+i;]) for i = (1:10)*10], Dict("key" => zeros(0, 0))) for cols in (12, 40, 80), rows in (2, 10, 24) # Ensure output is limited as requested diff --git a/test/euler.jl b/test/euler.jl index 525cf7db6332b..c807da5351dd5 100644 --- a/test/euler.jl +++ b/test/euler.jl @@ -254,7 +254,7 @@ end #23: 4179871 #24: 2783915460 -@test nthperm!([0:9],1000000) == [2,7,8,3,9,1,5,4,6,0] +@test nthperm!([0:9;],1000000) == [2,7,8,3,9,1,5,4,6,0] #25: 4782 #26: 983 diff --git a/test/functional.jl b/test/functional.jl index dc2110605b106..023e4d9502af5 100644 --- a/test/functional.jl +++ b/test/functional.jl @@ -1,7 +1,7 @@ # tests related to functional programming functions and styles # map -- array.jl -@test isequal(map((x)->"$x"[end:end], [9:11]), ["9", "0", "1"]) +@test isequal(map((x)->"$x"[end:end], 9:11), ["9", "0", "1"]) # TODO: @test map!() # map -- ranges.jl @test isequal(map(i->sqrt(i), 1:5), [sqrt(i) for i in 1:5]) diff --git a/test/hashing.jl b/test/hashing.jl index 0d4e2a9db2efe..7624062093834 100644 --- a/test/hashing.jl +++ b/test/hashing.jl @@ -4,17 +4,17 @@ types = Any[ Rational{Int8}, Rational{UInt8}, Rational{Int16}, Rational{UInt16}, Rational{Int32}, Rational{UInt32}, Rational{Int64}, Rational{UInt64} ] -vals = [ +vals = vcat( typemin(Int64), - -int64(maxintfloat(Float64))+Int64[-4:1], + -int64(maxintfloat(Float64))+Int64[-4:1;], typemin(Int32), -integer(maxintfloat(Float32))+(-4:1), -2:2, integer(maxintfloat(Float32))+(-1:4), typemax(Int32), - int64(maxintfloat(Float64))+Int64[-1:4], + int64(maxintfloat(Float64))+Int64[-1:4;], typemax(Int64), -] +) function coerce(T::Type, x) if T<:Rational @@ -64,7 +64,7 @@ vals = Any[ [1,2,3,4], [1 3;2 4], Any[1,2,3,4], [1,3,2,4], [1,0], [true,false], bitpack([true,false]), Set([1,2,3,4]), - Set([1:10]), # these lead to different key orders + Set([1:10;]), # these lead to different key orders Set([7,9,4,10,2,3,5,8,6,1]), # Dict(42 => 101, 77 => 93), Dict{Any,Any}(42 => 101, 77 => 93), (1,2,3,4), (1.0,2.0,3.0,4.0), (1,3,2,4), diff --git a/test/linalg/arnoldi.jl b/test/linalg/arnoldi.jl index d166baba70efb..dc54efee6b184 100644 --- a/test/linalg/arnoldi.jl +++ b/test/linalg/arnoldi.jl @@ -20,7 +20,7 @@ let # svds test end let # complex svds test - A = sparse([1, 1, 2, 3, 4], [2, 1, 1, 3, 1], exp(im*[2.0:2:10])) + A = sparse([1, 1, 2, 3, 4], [2, 1, 1, 3, 1], exp(im*[2.0:2:10;])) S1 = svds(A, nsv = 2) S2 = svd(full(A)) diff --git a/test/linalg/lapack.jl b/test/linalg/lapack.jl index 713189f04d3a9..12f05248afe4e 100644 --- a/test/linalg/lapack.jl +++ b/test/linalg/lapack.jl @@ -40,7 +40,7 @@ let # xbdsqr @test_approx_eq full(Bidiagonal(d, e, true)) U*Diagonal(s)*Vt @test_throws ArgumentError bdsqr!('A', d, e, Vt, U, C) - @test_throws DimensionMismatch bdsqr!('U', d, [e, 1], Vt, U, C) + @test_throws DimensionMismatch bdsqr!('U', d, [e; 1], Vt, U, C) @test_throws DimensionMismatch bdsqr!('U', d, e, Vt[1:end - 1, :], U, C) @test_throws DimensionMismatch bdsqr!('U', d, e, Vt, U[:,1:end - 1], C) @test_throws DimensionMismatch bdsqr!('U', d, e, Vt, U, C[1:end - 1, :]) diff --git a/test/linalg/umfpack.jl b/test/linalg/umfpack.jl index 19b85bfe695be..4cd396cd739db 100644 --- a/test/linalg/umfpack.jl +++ b/test/linalg/umfpack.jl @@ -21,13 +21,13 @@ for Tv in (Float64, Complex128) b = [8., 45., -3., 3., 19.] x = lua\b - @test_approx_eq x float([1:5]) + @test_approx_eq x float([1:5;]) @test norm(A*x-b,1) < eps(1e4) b = [8., 20., 13., 6., 17.] x = lua'\b - @test_approx_eq x float([1:5]) + @test_approx_eq x float([1:5;]) @test norm(A'*x-b,1) < eps(1e4) end diff --git a/test/linalg2.jl b/test/linalg2.jl index 414a62abd4d9e..f08cfcf4ee272 100644 --- a/test/linalg2.jl +++ b/test/linalg2.jl @@ -100,7 +100,7 @@ for elty in (Float32, Float64, Complex64, Complex128, Int) # The determinant of a rotation matrix should always be 1. if elty != Int - for theta = convert(Vector{elty}, pi ./ [1:4]) + for theta = convert(Vector{elty}, pi ./ [1:4;]) R = [cos(theta) -sin(theta); sin(theta) cos(theta)] @test_approx_eq convert(elty, det(R)) one(elty) @@ -147,10 +147,10 @@ end # Test gradient for elty in (Int32, Int64, Float32, Float64, Complex64, Complex128) if elty <: Real - x = convert(Vector{elty}, [1:3]) + x = convert(Vector{elty}, [1:3;]) g = ones(elty, 3) else - x = convert(Vector{elty}, complex([1:3],[1:3])) + x = convert(Vector{elty}, complex([1:3;], [1:3;])) g = convert(Vector{elty}, complex(ones(3), ones(3))) end @test_approx_eq gradient(x) g diff --git a/test/linalg3.jl b/test/linalg3.jl index f7005d8d5c5ec..c0bb68cff98ca 100644 --- a/test/linalg3.jl +++ b/test/linalg3.jl @@ -130,49 +130,49 @@ Aref = Ai[1:2:2*cutoff, 1:3] # Matrix exponential for elty in (Float32, Float64, Complex64, Complex128) - A1 = convert(Matrix{elty}, [4 2 0; 1 4 1; 1 1 4]) - eA1 = convert(Matrix{elty}, [147.866622446369 127.781085523181 127.781085523182; - 183.765138646367 183.765138646366 163.679601723179; - 71.797032399996 91.8825693231832 111.968106246371]') - @test_approx_eq expm(A1) eA1 - - A2 = convert(Matrix{elty}, - [29.87942128909879 0.7815750847907159 -2.289519314033932; - 0.7815750847907159 25.72656945571064 8.680737820540137; - -2.289519314033932 8.680737820540137 34.39400925519054]) - eA2 = convert(Matrix{elty}, - [ 5496313853692458.0 -18231880972009236.0 -30475770808580460.0; - -18231880972009252.0 60605228702221920.0 101291842930249760.0; - -30475770808580480.0 101291842930249728.0 169294411240851968.0]) - @test_approx_eq expm(A2) eA2 - - A3 = convert(Matrix{elty}, [-131 19 18;-390 56 54;-387 57 52]) - eA3 = convert(Matrix{elty}, [-1.50964415879218 -5.6325707998812 -4.934938326092; - 0.367879439109187 1.47151775849686 1.10363831732856; - 0.135335281175235 0.406005843524598 0.541341126763207]') - @test_approx_eq expm(A3) eA3 - - # issue 5116 - A4 = [0 10 0 0; -1 0 0 0; 0 0 0 0; -2 0 0 0] - eA4 = [-0.999786072879326 -0.065407069689389 0.0 0.0 - 0.006540706968939 -0.999786072879326 0.0 0.0 - 0.0 0.0 1.0 0.0 - 0.013081413937878 -3.999572145758650 0.0 1.0] - @test_approx_eq expm(A4) eA4 - - # issue 5116 - A5 = [ 0. 0. 0. 0. ; 0. 0. -im 0.; 0. im 0. 0.; 0. 0. 0. 0.] - eA5 = [ 1.0+0.0im 0.0+0.0im 0.0+0.0im 0.0+0.0im - 0.0+0.0im 1.543080634815244+0.0im 0.0-1.175201193643801im 0.0+0.0im - 0.0+0.0im 0.0+1.175201193643801im 1.543080634815243+0.0im 0.0+0.0im - 0.0+0.0im 0.0+0.0im 0.0+0.0im 1.0+0.0im] - @test_approx_eq expm(A5) eA5 - - # Hessenberg - @test_approx_eq hessfact(A1)[:H] convert(Matrix{elty}, - [4.000000000000000 -1.414213562373094 -1.414213562373095 - -1.414213562373095 4.999999999999996 -0.000000000000000 - 0 -0.000000000000002 3.000000000000000]) + A1 = convert(Matrix{elty}, [4 2 0; 1 4 1; 1 1 4]) + eA1 = convert(Matrix{elty}, [147.866622446369 127.781085523181 127.781085523182; + 183.765138646367 183.765138646366 163.679601723179; + 71.797032399996 91.8825693231832 111.968106246371]') + @test_approx_eq expm(A1) eA1 + + A2 = convert(Matrix{elty}, + [29.87942128909879 0.7815750847907159 -2.289519314033932; + 0.7815750847907159 25.72656945571064 8.680737820540137; + -2.289519314033932 8.680737820540137 34.39400925519054]) + eA2 = convert(Matrix{elty}, + [ 5496313853692458.0 -18231880972009236.0 -30475770808580460.0; + -18231880972009252.0 60605228702221920.0 101291842930249760.0; + -30475770808580480.0 101291842930249728.0 169294411240851968.0]) + @test_approx_eq expm(A2) eA2 + + A3 = convert(Matrix{elty}, [-131 19 18;-390 56 54;-387 57 52]) + eA3 = convert(Matrix{elty}, [-1.50964415879218 -5.6325707998812 -4.934938326092; + 0.367879439109187 1.47151775849686 1.10363831732856; + 0.135335281175235 0.406005843524598 0.541341126763207]') + @test_approx_eq expm(A3) eA3 + + # issue 5116 + A4 = [0 10 0 0; -1 0 0 0; 0 0 0 0; -2 0 0 0] + eA4 = [-0.999786072879326 -0.065407069689389 0.0 0.0 + 0.006540706968939 -0.999786072879326 0.0 0.0 + 0.0 0.0 1.0 0.0 + 0.013081413937878 -3.999572145758650 0.0 1.0] + @test_approx_eq expm(A4) eA4 + + # issue 5116 + A5 = [ 0. 0. 0. 0. ; 0. 0. -im 0.; 0. im 0. 0.; 0. 0. 0. 0.] + eA5 = [ 1.0+0.0im 0.0+0.0im 0.0+0.0im 0.0+0.0im + 0.0+0.0im 1.543080634815244+0.0im 0.0-1.175201193643801im 0.0+0.0im + 0.0+0.0im 0.0+1.175201193643801im 1.543080634815243+0.0im 0.0+0.0im + 0.0+0.0im 0.0+0.0im 0.0+0.0im 1.0+0.0im] + @test_approx_eq expm(A5) eA5 + + # Hessenberg + @test_approx_eq hessfact(A1)[:H] convert(Matrix{elty}, + [4.000000000000000 -1.414213562373094 -1.414213562373095 + -1.414213562373095 4.999999999999996 -0.000000000000000 + 0 -0.000000000000002 3.000000000000000]) end # Hermitian matrix exponential @@ -201,7 +201,7 @@ Ai = int(ceil(Ar*100)) @test_approx_eq vecnorm(Ai) vecnorm(full(Ai)) # 2-argument version of scale -a = reshape([1.:6], (2,3)) +a = reshape([1.:6;], (2,3)) @test scale(a, 5.) == a*5 @test scale(5., a) == a*5 @test scale(a, [1.; 2.; 3.]) == a.*[1 2 3] diff --git a/test/linalg4.jl b/test/linalg4.jl index 492dc858331f1..9187453c2a73f 100644 --- a/test/linalg4.jl +++ b/test/linalg4.jl @@ -26,14 +26,14 @@ end n=12 #Size of matrix problem to test #Issue #7647: test xsyevr, xheevr, xstevr drivers -for Mi7647 in (Symmetric(diagm([1.0:3.0])), - Hermitian(diagm([1.0:3.0])), - Hermitian(diagm(complex([1.0:3.0]))), - SymTridiagonal([1.0:3.0], zeros(2))) +for Mi7647 in (Symmetric(diagm(1.0:3.0)), + Hermitian(diagm(1.0:3.0)), + Hermitian(diagm(complex(1.0:3.0))), + SymTridiagonal([1.0:3.0;], zeros(2))) debug && println("Eigenvalues in interval for $(typeof(Mi7647))") @test eigmin(Mi7647) == eigvals(Mi7647, 0.5, 1.5)[1] == 1.0 @test eigmax(Mi7647) == eigvals(Mi7647, 2.5, 3.5)[1] == 3.0 - @test eigvals(Mi7647) == eigvals(Mi7647, 0.5, 3.5) == [1.0:3.0] + @test eigvals(Mi7647) == eigvals(Mi7647, 0.5, 3.5) == [1.0:3.0;] end debug && println("Bidiagonal matrices") @@ -165,7 +165,7 @@ end debug && println("Test interconversion between special matrix types") -a=[1.0:n] +a=[1.0:n;] A=Diagonal(a) for newtype in [Diagonal, Bidiagonal, SymTridiagonal, Tridiagonal, LowerTriangular, UpperTriangular, Matrix] debug && println("newtype is $(newtype)") @@ -174,7 +174,7 @@ end for isupper in (true, false) debug && println("isupper is $(isupper)") - A=Bidiagonal(a, [1.0:n-1], isupper) + A=Bidiagonal(a, [1.0:n-1;], isupper) for newtype in [Bidiagonal, Tridiagonal, isupper ? UpperTriangular : LowerTriangular, Matrix] debug && println("newtype is $(newtype)") @test full(convert(newtype, A)) == full(A) @@ -188,12 +188,12 @@ for isupper in (true, false) end end -A = SymTridiagonal(a, [1.0:n-1]) +A = SymTridiagonal(a, [1.0:n-1;]) for newtype in [Tridiagonal, Matrix] @test full(convert(newtype, A)) == full(A) end -A = Tridiagonal(zeros(n-1), [1.0:n], zeros(n-1)) #morally Diagonal +A = Tridiagonal(zeros(n-1), [1.0:n;], zeros(n-1)) #morally Diagonal for newtype in [Diagonal, Bidiagonal, SymTridiagonal, Matrix] @test full(convert(newtype, A)) == full(A) end diff --git a/test/math.jl b/test/math.jl index df575bd00ee6d..17e1266b61cd9 100644 --- a/test/math.jl +++ b/test/math.jl @@ -199,9 +199,9 @@ end # gamma, lgamma (complex argument) if Base.Math.libm == "libopenlibm" - @test gamma(Float64[1:25]) == gamma(1:25) + @test gamma(Float64[1:25;]) == gamma(1:25) else - @test_approx_eq gamma(Float64[1:25]) gamma(1:25) + @test_approx_eq gamma(Float64[1:25;]) gamma(1:25) end @test_approx_eq gamma(1/2) sqrt(π) @test_approx_eq gamma(-1/2) -2sqrt(π) diff --git a/test/numbers.jl b/test/numbers.jl index c4cccf6bbea30..2c40fb39be39a 100644 --- a/test/numbers.jl +++ b/test/numbers.jl @@ -1967,7 +1967,7 @@ approx_eq(a, b) = approx_eq(a, b, 1e-6) 9851, 9857, 9859, 9871, 9883, 9887, 9901, 9907, 9923, 9929, 9931, 9941, 9949, 9967, 9973 ] -for T in [Int,BigInt], n = [1:1000,1000000] +for T in [Int,BigInt], n = [1:1000;1000000] n = convert(T,n) f = factor(n) @test n == prod(T[p^k for (p,k)=f]) @@ -2209,7 +2209,7 @@ ndigf(n) = float64(log(float32(n))) @test digits(24, 2, 3) == [0, 0, 0, 1, 1] @test digits(24, 2, 7) == [0, 0, 0, 1, 1, 0, 0] @test digits(100) == [0, 0, 1] -@test digits(BigInt(2)^128, 2) == [zeros(128), 1] +@test digits(BigInt(2)^128, 2) == [zeros(128); 1] let a = zeros(Int, 3) digits!(a, 50) @test a == [0, 5, 0] @@ -2270,12 +2270,12 @@ for x in [1.23, 7, e, 4//5] #[FP, Int, MathConst, Rat] end #eltype{T<:Number}(::Type{T}) = T -for T in [subtypes(Complex), subtypes(Real)] +for T in [subtypes(Complex); subtypes(Real)] @test eltype(T) == T end #ndims{T<:Number}(::Type{T}) = 0 -for x in [subtypes(Complex), subtypes(Real)] +for x in [subtypes(Complex); subtypes(Real)] @test ndims(x) == 0 end @@ -2315,4 +2315,4 @@ end @test map(sin, 3) == sin(3) @test map(cos, 3) == cos(3) @test map(tan, 3) == tan(3) -@test map(log, 3) == log(3) \ No newline at end of file +@test map(log, 3) == log(3) diff --git a/test/parallel.jl b/test/parallel.jl index c64555c93fcec..10939ce14efa3 100644 --- a/test/parallel.jl +++ b/test/parallel.jl @@ -151,7 +151,7 @@ map!(x->1, d) if nprocs() < 4 remotecall_fetch(1, () -> addprocs(4 - nprocs())) end -workloads = hist(@parallel((a,b)->[a,b], for i=1:7; myid(); end), nprocs())[2] +workloads = hist(@parallel((a,b)->[a;b], for i=1:7; myid(); end), nprocs())[2] @test maximum(workloads) - minimum(workloads) <= 1 # @parallel reduction should work even with very short ranges diff --git a/test/random.jl b/test/random.jl index 4e22461b85e26..04cec4007f55f 100644 --- a/test/random.jl +++ b/test/random.jl @@ -300,7 +300,7 @@ for rng in ([], [MersenneTwister()], [RandomDevice()]) end # test uniform distribution of floats -let bins = [prevfloat(0.0):0.25:1.0] +let bins = [prevfloat(0.0):0.25:1.0;] for rng in [srand(MersenneTwister()), RandomDevice()] for T in [Float16,Float32,Float64] # array version diff --git a/test/ranges.jl b/test/ranges.jl index 7dd11f1f7c025..56869ba02a7b6 100644 --- a/test/ranges.jl +++ b/test/ranges.jl @@ -17,7 +17,7 @@ L64 = linspace(int64(1), int64(4), 4) @test L32[3] == 3 && L64[3] == 3 @test L32[4] == 4 && L64[4] == 4 -r = [5:-1:1] +r = 5:-1:1 @test r[1]==5 @test r[2]==4 @test r[3]==3 @@ -204,63 +204,63 @@ end @test (1:2:6) - 0.3 == 1-0.3:2:5-0.3 # operations between ranges and arrays -@test all(([1:5] + (5:-1:1)) .== 6) -@test all(((5:-1:1) + [1:5]) .== 6) -@test all(([1:5] - (1:5)) .== 0) -@test all(((1:5) - [1:5]) .== 0) +@test all(([1:5;] + (5:-1:1)) .== 6) +@test all(((5:-1:1) + [1:5;]) .== 6) +@test all(([1:5;] - (1:5)) .== 0) +@test all(((1:5) - [1:5;]) .== 0) # tricky floating-point ranges -@test [0.1:0.1:0.3] == [1:3]./10 -@test [0.0:0.1:0.3] == [0:3]./10 -@test [0.3:-0.1:-0.1] == [3:-1:-1]./10 -@test [0.1:-0.1:-0.3] == [1:-1:-3]./10 -@test [0.0:0.1:1.0] == [0:10]./10 -@test [0.0:-0.1:1.0] == [] -@test [0.0:0.1:-1.0] == [] -@test [0.0:-0.1:-1.0] == [0:-1:-10]./10 -@test [1.0:1/49:27.0] == [49:1323]./49 -@test [0.0:0.7:2.1] == [0:7:21]./10 -@test [0.0:1.1:3.3] == [0:11:33]./10 -@test [0.1:1.1:3.4] == [1:11:34]./10 -@test [0.0:1.3:3.9] == [0:13:39]./10 -@test [0.1:1.3:4.0] == [1:13:40]./10 -@test [1.1:1.1:3.3] == [11:11:33]./10 -@test [0.3:0.1:1.1] == [3:1:11]./10 - -@test [0.0:1.0:5.5] == [0:10:55]./10 -@test [0.0:-1.0:0.5] == [] -@test [0.0:1.0:0.5] == [0.0] - -@test [prevfloat(0.1):0.1:0.3] == [prevfloat(0.1), 0.2, 0.3] -@test [nextfloat(0.1):0.1:0.3] == [nextfloat(0.1), 0.2] -@test [prevfloat(0.0):0.1:0.3] == [prevfloat(0.0), 0.1, 0.2] -@test [nextfloat(0.0):0.1:0.3] == [nextfloat(0.0), 0.1, 0.2] -@test [0.1:0.1:prevfloat(0.3)] == [0.1, 0.2] -@test [0.1:0.1:nextfloat(0.3)] == [0.1, 0.2, nextfloat(0.3)] -@test [0.0:0.1:prevfloat(0.3)] == [0.0, 0.1, 0.2] -@test [0.0:0.1:nextfloat(0.3)] == [0.0, 0.1, 0.2, nextfloat(0.3)] -@test [0.1:prevfloat(0.1):0.3] == [0.1, 0.2, 0.3] -@test [0.1:nextfloat(0.1):0.3] == [0.1, 0.2] -@test [0.0:prevfloat(0.1):0.3] == [0.0, prevfloat(0.1), prevfloat(0.2), 0.3] -@test [0.0:nextfloat(0.1):0.3] == [0.0, nextfloat(0.1), nextfloat(0.2)] +@test [0.1:0.1:0.3;] == [1:3;]./10 +@test [0.0:0.1:0.3;] == [0:3;]./10 +@test [0.3:-0.1:-0.1;] == [3:-1:-1;]./10 +@test [0.1:-0.1:-0.3;] == [1:-1:-3;]./10 +@test [0.0:0.1:1.0;] == [0:10;]./10 +@test [0.0:-0.1:1.0;] == [] +@test [0.0:0.1:-1.0;] == [] +@test [0.0:-0.1:-1.0;] == [0:-1:-10;]./10 +@test [1.0:1/49:27.0;] == [49:1323;]./49 +@test [0.0:0.7:2.1;] == [0:7:21;]./10 +@test [0.0:1.1:3.3;] == [0:11:33;]./10 +@test [0.1:1.1:3.4;] == [1:11:34;]./10 +@test [0.0:1.3:3.9;] == [0:13:39;]./10 +@test [0.1:1.3:4.0;] == [1:13:40;]./10 +@test [1.1:1.1:3.3;] == [11:11:33;]./10 +@test [0.3:0.1:1.1;] == [3:1:11;]./10 + +@test [0.0:1.0:5.5;] == [0:10:55;]./10 +@test [0.0:-1.0:0.5;] == [] +@test [0.0:1.0:0.5;] == [0.0] + +@test [prevfloat(0.1):0.1:0.3;] == [prevfloat(0.1), 0.2, 0.3] +@test [nextfloat(0.1):0.1:0.3;] == [nextfloat(0.1), 0.2] +@test [prevfloat(0.0):0.1:0.3;] == [prevfloat(0.0), 0.1, 0.2] +@test [nextfloat(0.0):0.1:0.3;] == [nextfloat(0.0), 0.1, 0.2] +@test [0.1:0.1:prevfloat(0.3);] == [0.1, 0.2] +@test [0.1:0.1:nextfloat(0.3);] == [0.1, 0.2, nextfloat(0.3)] +@test [0.0:0.1:prevfloat(0.3);] == [0.0, 0.1, 0.2] +@test [0.0:0.1:nextfloat(0.3);] == [0.0, 0.1, 0.2, nextfloat(0.3)] +@test [0.1:prevfloat(0.1):0.3;] == [0.1, 0.2, 0.3] +@test [0.1:nextfloat(0.1):0.3;] == [0.1, 0.2] +@test [0.0:prevfloat(0.1):0.3;] == [0.0, prevfloat(0.1), prevfloat(0.2), 0.3] +@test [0.0:nextfloat(0.1):0.3;] == [0.0, nextfloat(0.1), nextfloat(0.2)] for T = (Float32, Float64,),# BigFloat), - a = -5:25, s = [-5:-1;1:25], d = 1:25, n = -1:15 + a = -5:25, s = [-5:-1;1:25;], d = 1:25, n = -1:15 den = convert(T,d) start = convert(T,a)/den step = convert(T,s)/den stop = convert(T,(a+(n-1)*s))/den r = start:step:stop - @test [r] == T[a:s:a+(n-1)*s]./den + @test [r;] == T[a:s:a+(n-1)*s;]./den # issue #7420 n = length(r) - @test [r[1:n]] == [r] - @test [r[2:n]] == [r][2:end] - @test [r[1:3:n]] == [r][1:3:n] - @test [r[2:2:n]] == [r][2:2:n] - @test [r[n:-1:2]] == [r][n:-1:2] - @test [r[n:-2:1]] == [r][n:-2:1] + @test [r[1:n];] == [r;] + @test [r[2:n];] == [r;][2:end] + @test [r[1:3:n];] == [r;][1:3:n] + @test [r[2:2:n];] == [r;][2:2:n] + @test [r[n:-1:2];] == [r;][n:-1:2] + @test [r[n:-2:1];] == [r;][n:-2:1] end # near-equal ranges @@ -339,18 +339,18 @@ r = linrange(0.25,0.25,1) @test_throws Exception linrange(0.25,0.5,1) # issue #7426 -@test [typemax(Int):1:typemax(Int)] == [typemax(Int)] +@test [typemax(Int):1:typemax(Int);] == [typemax(Int)] #issue #7484 r7484 = 0.1:0.1:1 -@test [reverse(r7484)] == reverse([r7484]) +@test [reverse(r7484);] == reverse([r7484;]) # issue #7387 for r in (0:1, 0.0:1.0) - @test r+im == [r]+im - @test r-im == [r]-im - @test r*im == [r]*im - @test r/im == [r]/im + @test r+im == [r;]+im + @test r-im == [r;]-im + @test r*im == [r;]*im + @test r/im == [r;]/im end # issue #7709 @@ -362,8 +362,8 @@ end # mean/median for f in (mean, median) for n = 2:5 - @test f(2:n) == f([2:n]) - @test_approx_eq f(2:0.1:n) f([2:0.1:n]) + @test f(2:n) == f([2:n;]) + @test_approx_eq f(2:0.1:n) f([2:0.1:n;]) end end diff --git a/test/reduce.jl b/test/reduce.jl index c4333300f031d..b2c5b7d1cbe1c 100644 --- a/test/reduce.jl +++ b/test/reduce.jl @@ -22,9 +22,9 @@ @test Base.mapfoldr(abs2, -, 10, 2:5) == -4 # reduce & mapreduce -@test reduce((x,y)->"($x+$y)", [9:11]) == "((9+10)+11)" +@test reduce((x,y)->"($x+$y)", 9:11) == "((9+10)+11)" @test reduce(max, [8 6 7 5 3 0 9]) == 9 -@test reduce(+, 1000, [1:5]) == (1000 + 1 + 2 + 3 + 4 + 5) +@test reduce(+, 1000, 1:5) == (1000 + 1 + 2 + 3 + 4 + 5) @test mapreduce(-, +, [-10 -9 -3]) == ((10 + 9) + 3) @test mapreduce((x)->x[1:3], (x,y)->"($x+$y)", ["abcd", "efgh", "01234"]) == "((abc+efg)+012)" diff --git a/test/serialize.jl b/test/serialize.jl index 7dde88d07edd4..8e3a2824e5e43 100644 --- a/test/serialize.jl +++ b/test/serialize.jl @@ -97,7 +97,7 @@ end # DataType create_serialization_stream() do s # standard types - typ1 = Uint8 + typ1 = UInt8 serialize(s, typ1) typ2 = Bool serialize(s, typ2) @@ -185,7 +185,7 @@ end # Array type TA1 - v::Uint8 + v::UInt8 end create_serialization_stream() do s # small 1d array arr1 = fill(0x01, 10) # small 1d array @@ -215,9 +215,9 @@ end # SubArray create_serialization_stream() do s # slices - slc1 = slice(ones(Uint8, 4), 2:3) + slc1 = slice(ones(UInt8, 4), 2:3) serialize(s, slc1) - slc2 = slice(ones(Uint8, 4, 4) .+ [0x00, 0x01, 0x02, 0x03], 1, 2:4) + slc2 = slice(ones(UInt8, 4, 4) .+ [0x00, 0x01, 0x02, 0x03], 1, 2:4) serialize(s, slc2) seek(s, 0) diff --git a/test/socket.jl b/test/socket.jl index ac71772768bfc..f5b0958585d30 100644 --- a/test/socket.jl +++ b/test/socket.jl @@ -93,9 +93,9 @@ end # test invalid port @test_throws ArgumentError connect(ip"127.0.0.1",-1) -@test_throws ArgumentError connect(ip"127.0.0.1", typemax(Uint16)+1) +@test_throws ArgumentError connect(ip"127.0.0.1", typemax(UInt16)+1) @test_throws ArgumentError connect(ip"0:0:0:0:0:ffff:127.0.0.1", -1) -@test_throws ArgumentError connect(ip"0:0:0:0:0:ffff:127.0.0.1", typemax(Uint16)+1) +@test_throws ArgumentError connect(ip"0:0:0:0:0:ffff:127.0.0.1", typemax(UInt16)+1) p, server = listenany(defaultport) r = RemoteRef() diff --git a/test/sorting.jl b/test/sorting.jl index 0a77c2d20eabb..e57740c1de02b 100644 --- a/test/sorting.jl +++ b/test/sorting.jl @@ -1,7 +1,7 @@ @test sort([2,3,1]) == [1,2,3] @test sort([2,3,1], rev=true) == [3,2,1] -@test sort(['z':-1:'a']) == ['a':'z'] -@test sort(['a':'z'], rev=true) == ['z':-1:'a'] +@test sort(['z':-1:'a';]) == ['a':'z';] +@test sort(['a':'z';], rev=true) == ['z':-1:'a';] @test sortperm([2,3,1]) == [3,1,2] @test sortperm!([1,2,3], [2,3,1]) == [3,1,2] @test !issorted([2,3,1]) @@ -9,10 +9,10 @@ @test reverse([2,3,1]) == [1,3,2] @test select([3,6,30,1,9],3) == 6 @test select([3,6,30,1,9],3:4) == [6,9] -let a=[1:10] +let a=[1:10;] for r in Any[2:4, 1:2, 10:10, 4:2, 2:1, 4:-1:2, 2:-1:1, 10:-1:10, 4:1:3, 1:2:8, 10:-3:1] - @test select(a, r) == [r] - @test select(a, r, rev=true) == (11 .- [r]) + @test select(a, r) == [r;] + @test select(a, r, rev=true) == (11 .- [r;]) end end @test sum(randperm(6)) == 21 @@ -22,6 +22,11 @@ numTypes = [ Int8, Int16, Int32, Int64, Int128, UInt8, UInt16, UInt32, UInt64, UInt128, Float16, Float32, Float64, BigInt, BigFloat] +@test searchsorted([1:10;], 1, by=(x -> x >= 5)) == 1:4 +@test searchsorted([1:10;], 10, by=(x -> x >= 5)) == 5:10 +@test searchsorted([1:5; 1:5; 1:5], 1, 6, 10, Base.Order.Forward) == 6:6 +@test searchsorted(ones(15), 1, 6, 10, Base.Order.Forward) == 6:10 + for R in numTypes, T in numTypes @test searchsorted(R[1, 1, 2, 2, 3, 3], T(0)) == 1:0 @test searchsorted(R[1, 1, 2, 2, 3, 3], T(1)) == 1:2 @@ -34,15 +39,15 @@ for R in numTypes, T in numTypes @test searchsorted(1:3, T(2)) == 2:2 @test searchsorted(1:3, T(4)) == 4:3 - @test searchsorted(R[1:10], T(1), by=(x -> x >= 5)) == 1:4 - @test searchsorted(R[1:10], T(10), by=(x -> x >= 5)) == 5:10 - @test searchsorted(R[1:5, 1:5, 1:5], T(1), 6, 10, Base.Order.Forward) == 6:6 + @test searchsorted(R[1:10;], T(1), by=(x -> x >= 5)) == 1:4 + @test searchsorted(R[1:10;], T(10), by=(x -> x >= 5)) == 5:10 + @test searchsorted(R[1:5; 1:5; 1:5], T(1), 6, 10, Base.Order.Forward) == 6:6 @test searchsorted(ones(R, 15), T(1), 6, 10, Base.Order.Forward) == 6:10 end for (rg,I) in [(49:57,47:59), (1:2:17,-1:19), (-3:0.5:2,-5:.5:4)] rg_r = reverse(rg) - rgv, rgv_r = [rg], [rg_r] + rgv, rgv_r = [rg;], [rg_r;] for i = I @test searchsorted(rg,i) == searchsorted(rgv,i) @test searchsorted(rg_r,i,rev=true) == searchsorted(rgv_r,i,rev=true) @@ -63,8 +68,8 @@ for i = 1:100 @test searchsorted(rg_r, nextfloat(rg_r[i]), rev=true) == i:i-1 end -@test searchsorted(1:10, 1, by=(x -> x >= 5)) == searchsorted([1:10], 1, by=(x -> x >= 5)) -@test searchsorted(1:10, 10, by=(x -> x >= 5)) == searchsorted([1:10], 10, by=(x -> x >= 5)) +@test searchsorted(1:10, 1, by=(x -> x >= 5)) == searchsorted([1:10;], 1, by=(x -> x >= 5)) +@test searchsorted(1:10, 10, by=(x -> x >= 5)) == searchsorted([1:10;], 10, by=(x -> x >= 5)) @test searchsorted([], 0) == 1:0 @test searchsorted([1,2,3], 0) == 1:0 @@ -145,7 +150,7 @@ end srand(0xdeadbeef) -for n in [0:10, 100, 101, 1000, 1001] +for n in [0:10; 100; 101; 1000; 1001] r = -5:5 v = rand(r,n) h = hist(v,r) diff --git a/test/sparse.jl b/test/sparse.jl index b56d897a33acf..be329e978265f 100644 --- a/test/sparse.jl +++ b/test/sparse.jl @@ -305,10 +305,10 @@ for (aa116, ss116) in [(a116, s116), (ad116, sd116)] # float-range indexing is not supported # sorted vector indexing - @test full(ss116[i,[3:2:end-3]]) == aa116[i,[3:2:end-3]] - @test full(ss116[[3:2:end-3],j]) == aa116[[3:2:end-3],j]'' - @test full(ss116[i,[end-3:-2:1]]) == aa116[i,[end-3:-2:1]] - @test full(ss116[[end-3:-2:1],j]) == aa116[[end-3:-2:1],j]'' + @test full(ss116[i,[3:2:end-3;]]) == aa116[i,[3:2:end-3;]] + @test full(ss116[[3:2:end-3;],j]) == aa116[[3:2:end-3;],j]'' + @test full(ss116[i,[end-3:-2:1;]]) == aa116[i,[end-3:-2:1;]] + @test full(ss116[[end-3:-2:1;],j]) == aa116[[end-3:-2:1;],j]'' # unsorted vector indexing with repetition p = [4, 1, 2, 3, 2, 6] @@ -376,9 +376,9 @@ let a = spzeros(Int, 10, 10) @test a[:,2] == 2*sparse(ones(Int,10,1)) a[1,:] = 1:10 - @test a[1,:] == sparse([1:10]') + @test a[1,:] == sparse([1:10;]') a[:,2] = 1:10 - @test a[:,2] == sparse([1:10]) + @test a[:,2] == sparse([1:10;]) end let A = spzeros(Int, 10, 20) @@ -415,10 +415,10 @@ let ASZ = 1000, TSZ = 800 @test A == B end -let A = speye(Int, 5), I=[1:10], X=reshape([trues(10), falses(15)],5,5) +let A = speye(Int, 5), I=1:10, X=reshape([trues(10); falses(15)],5,5) @test A[I] == A[X] == reshape([1,0,0,0,0,0,1,0,0,0], 10, 1) - A[I] = [1:10] - @test A[I] == A[X] == reshape([1:10], 10, 1) + A[I] = [1:10;] + @test A[I] == A[X] == reshape(1:10, 10, 1) end let S = sprand(50, 30, 0.5, x->int(rand(x)*100)), I = sprandbool(50, 30, 0.2) @@ -439,7 +439,7 @@ let S = sprand(50, 30, 0.5, x->int(rand(x)*100)), I = sprandbool(50, 30, 0.2) S[FI] = 0 @test sum(S) == sumS2 - S[FI] = [1:sum(FI)] + S[FI] = [1:sum(FI);] @test sum(S) == sumS2 + sum(1:sum(FI)) end @@ -609,8 +609,8 @@ end let M = 2^8, N=2^3 Irand = randperm(M) Jrand = randperm(N) - I = sort([Irand, Irand, Irand]) - J = [Jrand, Jrand] + I = sort([Irand; Irand; Irand]) + J = [Jrand; Jrand] SA = [sprand(M, N, d) for d in [1., 0.1, 0.01, 0.001, 0.0001, 0.]]; for S in SA diff --git a/test/statistics.jl b/test/statistics.jl index 19618b499d49e..55736d3187d55 100644 --- a/test/statistics.jl +++ b/test/statistics.jl @@ -6,7 +6,7 @@ let x = ((realmax(1.0)/4)*3) @test middle(x, x) === x end @test middle(1:8) === 4.5 -@test middle([1:8]) === 4.5 +@test middle([1:8;]) === 4.5 # ensure type-correctness for T in [Bool,Int8,Int16,Int32,Int64,Int128,UInt8,UInt16,UInt32,UInt64,UInt128,Float16,Float32,Float64] @@ -252,19 +252,18 @@ end @test hist([1])[2] == [1] @test hist([1,2,3],[0,2,4]) == ([0,2,4],[2,1]) @test hist([1,2,3],0:2:4) == (0:2:4,[2,1]) -@test all(hist([1:100]/100,0.0:0.01:1.0)[2] .==1) +@test all(hist([1:100;]/100,0.0:0.01:1.0)[2] .==1) @test hist([1,1,1,1,1])[2][1] == 5 @test sum(hist2d(rand(100, 2))[3]) == 100 @test hist([1 2 3 4;1 2 3 4]) == (0.0:2.0:4.0, [2 2 0 0; 0 0 2 2]) @test midpoints(1.0:1.0:10.0) == 1.5:1.0:9.5 @test midpoints(1:10) == 1.5:9.5 -@test midpoints(Float64[1.0:1.0:10.0]) == Float64[1.5:1.0:9.5] +@test midpoints(Float64[1.0:1.0:10.0;]) == Float64[1.5:1.0:9.5;] @test quantile([1,2,3,4],0.5) == 2.5 @test quantile([1., 3],[.25,.5,.75])[2] == median([1., 3]) -@test quantile([0.:100.],[.1,.2,.3,.4,.5,.6,.7,.8,.9])[1] == 10.0 - +@test quantile([0.:100.;],[.1,.2,.3,.4,.5,.6,.7,.8,.9])[1] == 10.0 # test invalid hist nbins argument (#9999) @test_throws ArgumentError hist(Int[], -1) diff --git a/test/strings.jl b/test/strings.jl index 4ac00b8d2ace3..3b3e985e2c729 100644 --- a/test/strings.jl +++ b/test/strings.jl @@ -752,7 +752,7 @@ arr = ["a","b","c"] # string iteration, and issue #1454 str = "é" -str_a = [str...] +str_a = vcat(str...) @test length(str_a)==1 @test str_a[1] == str[1] @@ -907,7 +907,7 @@ bin_val = hex2bytes("07bf") # combo @test (@sprintf "%f %d %d %f" 1.0 [3 4]... 5) == "1.000000 3 4 5.000000" # multi -@test (@sprintf "%s %f %9.5f %d %d %d %d%d%d%d" [1:6]... [7,8,9,10]...) == "1 2.000000 3.00000 4 5 6 78910" +@test (@sprintf "%s %f %9.5f %d %d %d %d%d%d%d" [1:6;]... [7,8,9,10]...) == "1 2.000000 3.00000 4 5 6 78910" # comprehension @test (@sprintf "%s %s %s %d %d %d %f %f %f" Any[10^x+y for x=1:3,y=1:3 ]...) == "11 101 1001 12 102 1002 13.000000 103.000000 1003.000000" @@ -1049,11 +1049,11 @@ end @test_throws BoundsError checkbounds("hello", 6) @test_throws BoundsError checkbounds("hello", 0:3) @test_throws BoundsError checkbounds("hello", 4:6) -@test_throws BoundsError checkbounds("hello", [0:3]) -@test_throws BoundsError checkbounds("hello", [4:6]) +@test_throws BoundsError checkbounds("hello", [0:3;]) +@test_throws BoundsError checkbounds("hello", [4:6;]) @test checkbounds("hello", 2) @test checkbounds("hello", 1:5) -@test checkbounds("hello", [1:5]) +@test checkbounds("hello", [1:5;]) # isvalid(), chr2ind() and ind2chr() for SubString{DirectIndexString} @@ -1340,4 +1340,4 @@ end @test convert(UTF8String, UInt8[32,107,75], "αβ") == " kK" @test convert(UTF8String, UInt8[132,107,75], "αβ") == "αβkK" @test convert(UTF8String, UInt8[], "*") == "" -@test convert(UTF8String, UInt8[255], "αβ") == "αβ" \ No newline at end of file +@test convert(UTF8String, UInt8[255], "αβ") == "αβ" diff --git a/test/subarray.jl b/test/subarray.jl index 29f1020824b1e..47621f84d3753 100644 --- a/test/subarray.jl +++ b/test/subarray.jl @@ -68,7 +68,7 @@ function single_stride_dim(A::Array) Ar = reshape(A, shp...) # Compute the diff along dimension 1 if size(Ar, 1) > 1 - indexes = map(d->1:size(Ar,d), [1:ndims(Ar)]) + indexes = map(d->1:size(Ar,d), [1:ndims(Ar);]) indexesp = copy(indexes); indexesp[1] = 2:size(Ar,1) indexesm = copy(indexes); indexesm[1] = 1:size(Ar,1)-1 dA = Ar[indexesp...] - Ar[indexesm...] @@ -304,9 +304,9 @@ A = reshape(1:120, 3, 5, 8) sA = sub(A, 2, 1:5, :) @test parent(sA) == A @test parentindexes(sA) == (2:2, 1:5, :) -@test Base.parentdims(sA) == [1:3] +@test Base.parentdims(sA) == [1:3;] @test size(sA) == (1, 5, 8) -@test sA[1, 2, 1:8][:] == [5:15:120] +@test sA[1, 2, 1:8][:] == [5:15:120;] sA[2:5:end] = -1 @test all(sA[2:5:end] .== -1) @test all(A[5:15:120] .== -1) @@ -314,26 +314,26 @@ sA[2:5:end] = -1 @test stride(sA,3) == 15 @test stride(sA,4) == 120 sA = sub(A, 1:3, 1:5, 5) -@test Base.parentdims(sA) == [1:2] +@test Base.parentdims(sA) == [1:2;] sA[1:3,1:5] = -2 @test all(A[:,:,5] .== -2) sA[:] = -3 @test all(A[:,:,5] .== -3) @test strides(sA) == (1,3) sA = sub(A, 1:3, 3, 2:5) -@test Base.parentdims(sA) == [1:3] +@test Base.parentdims(sA) == [1:3;] @test size(sA) == (3,1,4) @test sA == A[1:3,3,2:5] @test sA[:] == A[1:3,3,2:5][:] sA = sub(A, 1:2:3, 1:3:5, 1:2:8) -@test Base.parentdims(sA) == [1:3] +@test Base.parentdims(sA) == [1:3;] @test strides(sA) == (2,9,30) @test sA[:] == A[1:2:3, 1:3:5, 1:2:8][:] # issue #8807 -@test sub(sub([1:5], 1:5), 1:5) == [1:5] +@test sub(sub([1:5;], 1:5), 1:5) == [1:5;] # sub logical indexing #4763 -A = sub([1:10], 5:8) +A = sub([1:10;], 5:8) @test A[A.<7] == [5, 6] B = reshape(1:16, 4, 4) sB = sub(B, 2:3, 2:3) @@ -344,17 +344,17 @@ A = reshape(1:120, 3, 5, 8) sA = slice(A, 2, :, 1:8) @test parent(sA) == A @test parentindexes(sA) == (2, :, 1:8) -@test Base.parentdims(sA) == [2:3] +@test Base.parentdims(sA) == [2:3;] @test size(sA) == (5, 8) @test strides(sA) == (3,15) -@test sA[2, 1:8][:] == [5:15:120] -@test sA[:,1] == [2:3:14] -@test sA[2:5:end] == [5:15:110] +@test sA[2, 1:8][:] == [5:15:120;] +@test sA[:,1] == [2:3:14;] +@test sA[2:5:end] == [5:15:110;] sA[2:5:end] = -1 @test all(sA[2:5:end] .== -1) @test all(A[5:15:120] .== -1) sA = slice(A, 1:3, 1:5, 5) -@test Base.parentdims(sA) == [1:2] +@test Base.parentdims(sA) == [1:2;] @test size(sA) == (3,5) @test strides(sA) == (1,3) sA = slice(A, 1:2:3, 3, 1:2:8) @@ -363,7 +363,7 @@ sA = slice(A, 1:2:3, 3, 1:2:8) @test strides(sA) == (2,30) @test sA[:] == A[sA.indexes...][:] -a = [5:8] +a = [5:8;] @test parent(a) == a @test parentindexes(a) == (1:4,)