Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deprecate concatenating [...] #7998

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 62 additions & 10 deletions base/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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...)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down
4 changes: 4 additions & 0 deletions base/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion base/base64.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions base/combinatorics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions base/dsp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion base/fftw.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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]]'
Expand Down
4 changes: 2 additions & 2 deletions base/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions base/intfuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion base/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion base/linalg/factorization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions base/linalg/generic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
2 changes: 1 addition & 1 deletion base/linalg/lapack.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion base/linalg/lu.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion base/linalg/triangular.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion base/multi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion base/pkg/resolve/maxsum.jl
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ type Graph
end
end

perm = [1:np]
perm = [1:np;]

return new(gadj, gmsk, gdir, adjdict, spp, perm, np)
end
Expand Down
2 changes: 1 addition & 1 deletion base/random.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion base/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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 ##

Expand Down
2 changes: 1 addition & 1 deletion base/sort.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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 ##

Expand Down
4 changes: 2 additions & 2 deletions base/sparse/sparsematrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion base/string.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading