diff --git a/base/abstractarray.jl b/base/abstractarray.jl index cdfa0abe14e6c..c319fe223d9a0 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(None, 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 + warn_once("[$before] concatenation is deprecated; use [$after] instead") + 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_type(map(typeof, X)...) + T[ X[i] for i=1:length(X) ] + end +end + size{T,n}(t::AbstractArray{T,n}, d) = (d>n ? 1 : size(t)[d]) eltype(x) = Any eltype{T,n}(::AbstractArray{T,n}) = T @@ -429,7 +468,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 @@ -602,6 +641,11 @@ end ## cat: general case function cat(catdim::Integer, X...) + T = promote_type(map(x->isa(x,AbstractArray) ? eltype(x) : typeof(x), X)...) + cat_t(catdim, T, X...) +end + +function cat_t(catdim::Integer, typeC::Type, X...) nargs = length(X) dimsX = map((a->isa(a,AbstractArray) ? size(a) : (1,)), X) ndimsX = map((a->isa(a,AbstractArray) ? ndims(a) : 1), X) @@ -645,7 +689,6 @@ function cat(catdim::Integer, X...) ndimsC = max(catdim, d_max) dimsC = ntuple(ndimsC, compute_dims)::(Int...) - typeC = promote_type(map(x->isa(x,AbstractArray) ? eltype(x) : typeof(x), X)...) C = similar(isa(X[1],AbstractArray) ? full(X[1]) : [X[1]], typeC, dimsC) range = 1 @@ -661,12 +704,15 @@ end vcat(X...) = cat(1, X...) hcat(X...) = cat(2, X...) +typed_vcat(T::Type, X...) = cat_t(1, T, X...) +typed_hcat(T::Type, X...) = cat_t(2, T, X...) + cat{T}(catdim::Integer, A::AbstractArray{T}...) = cat_t(catdim, T, A...) cat(catdim::Integer, A::AbstractArray...) = cat_t(catdim, promote_eltype(A...), A...) -function cat_t(catdim::Integer, typeC, A::AbstractArray...) +function cat_t(catdim::Integer, typeC::Type, A::AbstractArray...) # ndims of all input arrays should be in [d-1, d] nargs = length(A) @@ -727,6 +773,9 @@ end 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...) @@ -817,25 +866,28 @@ function hvcat_fill(a, xs) a end -function hvcat(rows::(Int...), xs::Number...) +function typed_hvcat(T::Type, rows::(Int...), xs...) nr = length(rows) nc = rows[1] - #error check for i = 2:nr if nc != rows[i] error("row ", i, " has mismatched number of columns") end end - T = typeof(xs[1]) - for i=2:length(xs) - T = promote_type(T,typeof(xs[i])) - end if nr*nc != length(xs) error("argument count does not match specified shape") end hvcat_fill(Array(T, nr, nc), xs) end +function hvcat(rows::(Int...), xs::Number...) + T = typeof(xs[1]) + for i = 2:length(xs) + T = promote_type(T,typeof(xs[i])) + end + typed_hvcat(T, rows, xs...) +end + ## Reductions and scans ## function isequal(A::AbstractArray, B::AbstractArray) @@ -1216,7 +1268,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 fcaa3009a2c9e..b614c2f108d4c 100644 --- a/base/array.jl +++ b/base/array.jl @@ -125,12 +125,15 @@ end getindex(T::(Type...)) = Array(T,0) +if _oldstyle_array_vcat_ # T[a:b] and T[a:s:b] also contruct typed ranges function getindex{T<:Number}(::Type{T}, r::Range) + warn_once("T[a:b] concatenation is deprecated; use T[a:b;] instead") copy!(Array(T,length(r)), r) end function getindex{T<:Number}(::Type{T}, r1::Range, rs::Range...) + warn_once("T[a:b,...] concatenation is deprecated; use T[a:b;...] instead") a = Array(T,length(r1)+sum(length,rs)) o = 1 copy!(a, o, r1) @@ -141,6 +144,7 @@ function getindex{T<:Number}(::Type{T}, r1::Range, rs::Range...) end return a end +end function fill!{T<:Union(Int8,Uint8)}(a::Array{T}, x::Integer) ccall(:memset, Ptr{Void}, (Ptr{Void}, Int32, Csize_t), a, x, length(a)) diff --git a/base/base64.jl b/base/base64.jl index 40e1666b1b147..f87157dd0c27d 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';'+';'/'] function b64(x::Uint8, y::Uint8, z::Uint8) n = int(x)<<16 | int(y)<<8 | int(z) diff --git a/base/combinatorics.jl b/base/combinatorics.jl index 146a46c151349..356d2770553ac 100644 --- a/base/combinatorics.jl +++ b/base/combinatorics.jl @@ -255,7 +255,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 @@ -289,7 +289,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) if length(p.a) == 0 # special case to generate 1 result for len==0 @@ -400,7 +400,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/dsp.jl b/base/dsp.jl index 0062bbb64b48f..e19fc53d9d175 100644 --- a/base/dsp.jl +++ b/base/dsp.jl @@ -105,8 +105,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 2512c5cc255c9..281bc0d212f47 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 27c7a1fe1695e..d3bba309c91f4 100644 --- a/base/inference.jl +++ b/base/inference.jl @@ -1308,7 +1308,7 @@ function typeinf(linfo::LambdaStaticData,atypes::Tuple,sparams::Tuple, def, cop) la = length(args) assert(is(ast.head,:lambda)) locals = (ast.args[2][1])::Array{Any,1} - vars = [args, locals] + vars = [args; locals] body = (ast.args[3].args)::Array{Any,1} n = length(body) @@ -2688,7 +2688,7 @@ function inlining_pass(e::Expr, sv, ast) return (e,stmts) end end - e.args = [{e.args[2]}, newargs...] + e.args = [{e.args[2]}; newargs...] # now try to inline the simplified call diff --git a/base/intfuncs.jl b/base/intfuncs.jl index 077b363eed90b..1bcd12e7e9181 100644 --- a/base/intfuncs.jl +++ b/base/intfuncs.jl @@ -236,8 +236,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) if !(2 <= b <= 62) error("invalid base: $b") end diff --git a/base/io.jl b/base/io.jl index 9d83889d0babe..85ea973413440 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/factorization.jl b/base/linalg/factorization.jl index 0147b7b1e44a3..c89b491823092 100644 --- a/base/linalg/factorization.jl +++ b/base/linalg/factorization.jl @@ -474,7 +474,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))")) - 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)) + 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)) end function \{TA,TB}(A::Union(QR{TA},QRCompactWY{TA},QRPivoted{TA}),B::StridedMatrix{TB}) S = promote_type(TA,TB) diff --git a/base/linalg/generic.jl b/base/linalg/generic.jl index 3e2412a51496c..af30ce1ac9913 100644 --- a/base/linalg/generic.jl +++ b/base/linalg/generic.jl @@ -43,8 +43,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 18d145d35485f..0870b5eb362a8 100644 --- a/base/linalg/lapack.jl +++ b/base/linalg/lapack.jl @@ -2244,7 +2244,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 d8e885023306d..eafcbe989c9bd 100644 --- a/base/linalg/lu.jl +++ b/base/linalg/lu.jl @@ -84,7 +84,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/linalg/triangular.jl b/base/linalg/triangular.jl index 35ab1d2e8a1ae..3a5a2b1f480b1 100644 --- a/base/linalg/triangular.jl +++ b/base/linalg/triangular.jl @@ -47,7 +47,7 @@ A_ldiv_B!{T<:BlasFloat,S<:AbstractMatrix,UpLo,IsUnit}(A::Triangular{T,S,UpLo,IsU function \{T<:BlasFloat,S<:AbstractMatrix,UpLo,IsUnit}(A::Triangular{T,S,UpLo,IsUnit}, B::StridedVecOrMat{T}) x = A_ldiv_B!(A, copy(B)) errors = LAPACK.trrfs!(UpLo == :L ? 'L' : 'U', 'N', IsUnit ? 'U' : 'N', A.data, B, x) - all(isfinite, [errors...]) || all([errors...] .< one(T)/eps(T)) || warn("""Unreasonably large error in computed solution: + all(isfinite, vcat(errors...)) || all(vcat(errors...) .< one(T)/eps(T)) || warn("""Unreasonably large error in computed solution: forward errors: $(errors[1]) backward errors: diff --git a/base/multi.jl b/base/multi.jl index c1e5ff5317f86..ed8f905741146 100644 --- a/base/multi.jl +++ b/base/multi.jl @@ -309,7 +309,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 70336337d1d08..fd1a08d1c9311 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 1f103fb7b6957..d74c5a76bb6b8 100644 --- a/base/random.jl +++ b/base/random.jl @@ -281,7 +281,7 @@ function Base.convert(::Type{UUID}, s::String) 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 a17265f99a6d0..d71cfbd1e9f1e 100644 --- a/base/show.jl +++ b/base/show.jl @@ -246,7 +246,7 @@ const expr_infix_wide = Set([:(=), :(+=), :(-=), :(*=), :(/=), :(\=), :(&=), const expr_infix = Set([:(:), :(<:), :(->), :(=>), symbol("::")]) const expr_calls = [:call =>('(',')'), :calldecl =>('(',')'), :ref =>('[',']'), :curly =>('{','}')] const expr_parens = [:tuple=>('(',')'), :vcat=>('[',']'), :cell1d=>('{','}'), - :hcat =>('[',']'), :row =>('[',']')] + :hcat =>('[',']'), :row =>('[',']'), :vect=>('[',']')] ## AST decoding helpers ## diff --git a/base/sort.jl b/base/sort.jl index eb907255450ce..bf4e2b8e89d23 100644 --- a/base/sort.jl +++ b/base/sort.jl @@ -337,7 +337,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)) ## sorting multi-dimensional arrays ## diff --git a/base/sparse/sparsematrix.jl b/base/sparse/sparsematrix.jl index 3866f323409bf..5f604955756f1 100644 --- a/base/sparse/sparsematrix.jl +++ b/base/sparse/sparsematrix.jl @@ -414,8 +414,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 b7f6811d11ab5..7b76857123bdc 100644 --- a/base/string.jl +++ b/base/string.jl @@ -1656,7 +1656,7 @@ rsearch(a::ByteArray, b::Union(Int8,Uint8,Char)) = rsearch(a,b,length(a)) # return a random string (often useful for temporary filenames/dirnames) let global randstring - const b = uint8(['0':'9','A':'Z','a':'z']) + const b = uint8(['0':'9';'A':'Z';'a':'z']) randstring(n::Int) = ASCIIString(b[rand(1:length(b),n)]) randstring() = randstring(8) end diff --git a/src/julia-parser.scm b/src/julia-parser.scm index 32999aacc3d91..9961ab8c867dc 100644 --- a/src/julia-parser.scm +++ b/src/julia-parser.scm @@ -934,14 +934,10 @@ (loop (list 'typed_dict ex)) (loop (list 'ref ex))) (case (car al) + ((vect) (loop (list* 'ref ex (cdr al)))) ((dict) (loop (list* 'typed_dict 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))))) + ((vcat) (loop (list* 'typed_vcat ex (cdr al)))) ((comprehension) (loop (list* 'typed_comprehension ex (cdr al)))) ((dict_comprehension) @@ -1387,21 +1383,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)))) ((#\;) (error "unexpected semicolon in array expression")) @@ -1411,7 +1406,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)) @@ -1447,7 +1442,7 @@ (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) @@ -1488,8 +1483,8 @@ (else (parse-dict s first closer))) (case (peek-token s) - ((#\,) - (parse-vcat s first closer)) + ((#\, closer) + (parse-vect s first closer)) ((for) (take-token s) (parse-comprehension s first closer)) @@ -1764,6 +1759,7 @@ (if (null? vex) '(cell1d) (case (car vex) + ((vect) `(cell1d ,@(cdr vex))) ((comprehension) `(typed_comprehension (top Any) ,@(cdr vex))) ((dict_comprehension) @@ -1799,7 +1795,7 @@ ((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 704309d4b32a4..5519fa58e24b2 100644 --- a/src/julia-syntax.scm +++ b/src/julia-syntax.scm @@ -1887,6 +1887,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))))) @@ -1909,47 +1912,26 @@ `(call vcat ,@a))))) 'typed_hcat - (lambda (e) - (let ((t (cadr e)) - (a (cddr e))) - (let ((result (gensy)) - (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 (gensy)) - (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 nconc 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 f66e7798b1f55..4416ac4215f67 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 b6b564fc4f152..5236424a09c1d 100644 --- a/test/arrayops.jl +++ b/test/arrayops.jl @@ -53,7 +53,8 @@ a = reshape(b, (2, 2, 2, 2, 2)) sz = (5,8,7) A = reshape(1:prod(sz),sz...) -@test A[2:6] == [2:6] +tmp = A[2:6] +@test tmp == [2:6;] tmp = A[1:3,2,2:4] @test tmp == 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] @@ -99,10 +100,10 @@ A = reshape(1:120, 3, 5, 8) sA = sub(A, 2, 1:5, :) @test parent(sA) == A @test parentindexes(sA) == (2:2, 1:5, 1:8) -@test Base.parentdims(sA) == [1:3] +@test Base.parentdims(sA) == [1:3;] @test size(sA) == (1, 5, 8) @test_throws BoundsError sA[2, 1: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) @@ -110,24 +111,24 @@ 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][:] # 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) @@ -138,17 +139,17 @@ A = reshape(1:120, 3, 5, 8) sA = slice(A, 2, :, 1:8) @test parent(sA) == A @test parentindexes(sA) == (2, 1:5, 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) @@ -157,7 +158,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,) @@ -205,13 +206,13 @@ let @test x == -12 X = get(A, -5:5, nan(Float32)) @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 @@ -235,13 +236,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] @@ -257,6 +258,18 @@ 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 + # "end" X = [ i+2j for i=1:5, j=1:5 ] @test X[end,end] == 15 @@ -352,7 +365,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 @@ -517,9 +530,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; @@ -577,12 +590,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] @@ -765,19 +778,19 @@ rt = Base.return_types(fill!, (Array{Int32, 3}, Uint8)) for idx in {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 {[], [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 {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] @@ -801,15 +814,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]) diff --git a/test/bigint.jl b/test/bigint.jl index 5dc4965324b47..21ea4f1d22237 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 db0438ccf2d2f..2b518b6abf449 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 a7ec3df67ff5c..3713dfca919e2 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/collections.jl b/test/collections.jl index e88475b03c3b9..7a17c2d02136b 100644 --- a/test/collections.jl +++ b/test/collections.jl @@ -175,7 +175,7 @@ end for d in (["\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], ["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/combinatorics.jl b/test/combinatorics.jl index 8846e8eb6c848..092e45b16e3ba 100644 --- a/test/combinatorics.jl +++ b/test/combinatorics.jl @@ -1,13 +1,13 @@ @test factorial(7) == 5040 @test factorial(7,3) == 7*6*5*4 @test binomial(5,3) == 10 -p = shuffle([1:1000]) +p = shuffle([1:1000;]) @test isperm(p) @test all(invperm(invperm(p)) .== p) 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",2)) == ["ab","ac","bc"] @test collect(permutations("abc")) == ["abc","acb","bac","bca","cab","cba"] @test collect(filter(x->(iseven(x[1])),permutations([1,2,3]))) == {[2,1,3],[2,3,1]} @@ -28,7 +28,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/core.jl b/test/core.jl index a04bf1443ac20..d0149bb998412 100644 --- a/test/core.jl +++ b/test/core.jl @@ -791,15 +791,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(Range1{Int},1) r[1] = 2:3 X[r...] *= 2 @@ -847,7 +847,7 @@ end # issue #2098 let - i2098() = (c={2.0};[1:1:c[1]]) + i2098() = (c={2.0};[1:1:c[1];]) @test isequal(i2098(), [1.0,2.0]) end diff --git a/test/euler.jl b/test/euler.jl index 04fd4f3b29c9b..415d78452871c 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 0c222b45666d5..765eecd8fad56 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 d3f68dbd8e2d1..2cf8de7c9027c 100644 --- a/test/hashing.jl +++ b/test/hashing.jl @@ -4,17 +4,17 @@ types = { 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), -] +) for T=types, S=types, x=vals a = convert(T,x) @@ -37,7 +37,7 @@ end vals = {[1,2,3,4], [1 3;2 4], {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]), # [42 => 101, 77 => 93], {42 => 101, 77 => 93}, (1,2,3,4), (1.0,2.0,3.0,4.0), (1,3,2,4), diff --git a/test/linalg2.jl b/test/linalg2.jl index f89789ea5fecc..9e38b547fb245 100644 --- a/test/linalg2.jl +++ b/test/linalg2.jl @@ -126,7 +126,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) @@ -223,10 +223,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/linalg4.jl b/test/linalg4.jl index c2d8b78c60c6a..36ababd6a36a6 100644 --- a/test/linalg4.jl +++ b/test/linalg4.jl @@ -171,12 +171,12 @@ for relty in (Float32, Float64), elty in (relty, )#XXX Complex{relty}) doesn't w end #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") @@ -295,7 +295,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, Triangular, Matrix] debug && println("newtype is $(newtype)") @@ -304,7 +304,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, Triangular, Matrix] debug && println("newtype is $(newtype)") @test full(convert(newtype, A)) == full(A) @@ -316,12 +316,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 ef14e86eb7dc6..c6f316e92fb6b 100644 --- a/test/math.jl +++ b/test/math.jl @@ -171,7 +171,7 @@ end @test_approx_eq lbeta(-1/2, 3) log(16/3) # gamma, lgamma (complex argument) -@test gamma(1:25) == gamma(Float64[1:25]) +@test gamma(1:25) == gamma(Float64[1:25;]) @test_approx_eq gamma(1/2) sqrt(π) @test_approx_eq gamma(-1/2) -2sqrt(π) @test_approx_eq lgamma(-1/2) log(abs(gamma(-1/2))) diff --git a/test/numbers.jl b/test/numbers.jl index 7e4f8103a4c48..e0653eab81e6b 100644 --- a/test/numbers.jl +++ b/test/numbers.jl @@ -1595,7 +1595,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]) @@ -1832,7 +1832,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] diff --git a/test/parallel.jl b/test/parallel.jl index d072a14dd0145..8aa985594aa31 100644 --- a/test/parallel.jl +++ b/test/parallel.jl @@ -131,7 +131,7 @@ end # @unix_only(SharedArray tests) 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/ranges.jl b/test/ranges.jl index 898379c9974eb..4f39f61ec760b 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 @@ -196,63 +196,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 @@ -331,16 +331,16 @@ 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 diff --git a/test/reduce.jl b/test/reduce.jl index 1799cc9176d39..4cf18bd70c888 100644 --- a/test/reduce.jl +++ b/test/reduce.jl @@ -13,9 +13,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/sorting.jl b/test/sorting.jl index 2335f8025d28a..0351f617fae0f 100644 --- a/test/sorting.jl +++ b/test/sorting.jl @@ -6,10 +6,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 {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 @@ -21,14 +21,14 @@ end @test searchsorted([1, 1, 2, 2, 3, 3], 4) == 7:6 @test searchsorted([1.0, 1, 2, 2, 3, 3], 2.5) == 5:4 -@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([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 (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) @@ -49,8 +49,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 @@ -117,7 +117,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 1f14a54e4a5d9..ce03f75f6c6a0 100644 --- a/test/sparse.jl +++ b/test/sparse.jl @@ -272,10 +272,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] @@ -316,9 +316,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) @@ -355,10 +355,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) @@ -379,7 +379,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 diff --git a/test/statistics.jl b/test/statistics.jl index 9de52a3b6e83c..84e4942e3fbae 100644 --- a/test/statistics.jl +++ b/test/statistics.jl @@ -3,7 +3,7 @@ @test middle(3) === 3.0 @test middle(2, 3) === 2.5 @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] @@ -250,15 +250,15 @@ 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 diff --git a/test/strings.jl b/test/strings.jl index 77e3a2460b7c9..5c5437ab7ad83 100644 --- a/test/strings.jl +++ b/test/strings.jl @@ -1025,11 +1025,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} diff --git a/test/suitesparse.jl b/test/suitesparse.jl index 70b28d5eccc2f..840c2174f138c 100644 --- a/test/suitesparse.jl +++ b/test/suitesparse.jl @@ -17,13 +17,13 @@ L,U,p,q,Rs = lua[:(:)] 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)