diff --git a/base/LineEdit.jl b/base/LineEdit.jl index ae777dcf86fb4..4c98db15760fd 100644 --- a/base/LineEdit.jl +++ b/base/LineEdit.jl @@ -432,10 +432,10 @@ function edit_move_up(s) end function edit_move_down(buf::IOBuffer) - npos = rsearch(buf.data[1:buf.size], '\n', position(buf)) + npos = rsearch(copy(buf.data[1:buf.size]), '\n', position(buf)) # We're interested in character count, not byte count offset = length(bytestring(buf.data[(npos+1):(position(buf))])) - npos2 = search(buf.data[1:buf.size], '\n', position(buf)+1) + npos2 = search(copy(buf.data[1:buf.size]), '\n', position(buf)+1) if npos2 == 0 #we're in the last line return false end diff --git a/base/abstractarray.jl b/base/abstractarray.jl index 23fc292d379e9..70e8aa5b4354a 100644 --- a/base/abstractarray.jl +++ b/base/abstractarray.jl @@ -77,6 +77,7 @@ checkbounds(sz::Int, i::Real) = checkbounds(sz, to_index(i)) checkbounds(sz::Int, I::AbstractVector{Bool}) = length(I) == sz || throw(BoundsError()) checkbounds(sz::Int, r::Range{Int}) = isempty(r) || (minimum(r) >= 1 && maximum(r) <= sz) || throw(BoundsError()) checkbounds{T<:Real}(sz::Int, r::Range{T}) = checkbounds(sz, to_index(r)) +checkbounds(sc::Int, ::Colon) = true function checkbounds{T <: Real}(sz::Int, I::AbstractArray{T}) for i in I @@ -88,17 +89,17 @@ checkbounds(A::AbstractArray, I::AbstractArray{Bool}) = size(A) == size(I) || th checkbounds(A::AbstractArray, I) = checkbounds(length(A), I) -function checkbounds(A::AbstractMatrix, I::Union(Real,AbstractArray), J::Union(Real,AbstractArray)) +function checkbounds(A::AbstractMatrix, I::Union(Real,AbstractArray,Colon), J::Union(Real,AbstractArray,Colon)) checkbounds(size(A,1), I) checkbounds(size(A,2), J) end -function checkbounds(A::AbstractArray, I::Union(Real,AbstractArray), J::Union(Real,AbstractArray)) +function checkbounds(A::AbstractArray, I::Union(Real,AbstractArray,Colon), J::Union(Real,AbstractArray,Colon)) checkbounds(size(A,1), I) checkbounds(trailingsize(A,2), J) end -function checkbounds(A::AbstractArray, I::Union(Real,AbstractArray)...) +function checkbounds(A::AbstractArray, I::Union(Real,AbstractArray,Colon)...) n = length(I) if n > 0 for dim = 1:(n-1) diff --git a/base/array.jl b/base/array.jl index f91d78ea9ddb8..e42fe7bf01f05 100644 --- a/base/array.jl +++ b/base/array.jl @@ -271,14 +271,15 @@ getindex(A::Array, i0::Real, i1::Real, i2::Real, i3::Real, i4::Real, i5::Real, arrayref(A,to_index(i0),to_index(i1),to_index(i2),to_index(i3),to_index(i4),to_index(i5),to_index(I)...) # Fast copy using copy! for UnitRange -function getindex(A::Array, I::UnitRange{Int}) - lI = length(I) - X = similar(A, lI) - if lI > 0 - copy!(X, 1, A, first(I), lI) - end - return X -end +getindex(A::Array, I::UnitRange{Int}) = slice(A, I) +# function getindex(A::Array, I::UnitRange{Int}) +# lI = length(I) +# X = similar(A, lI) +# if lI > 0 +# copy!(X, 1, A, first(I), lI) +# end +# return X +# end function getindex{T<:Real}(A::Array, I::AbstractVector{T}) return [ A[i] for i in to_index(I) ] @@ -361,6 +362,7 @@ function setindex!{T<:Real}(A::Array, X::AbstractArray, I::AbstractVector{T}) return A end +setindex!(A::Array, x, I::Colon) = setindex!(A, x, 1:length(x)) # logical indexing @@ -608,7 +610,7 @@ function splice!(a::Vector, i::Integer, ins=_default_splice) end function splice!{T<:Integer}(a::Vector, r::UnitRange{T}, ins=_default_splice) - v = a[r] + v = copy(a[r]) m = length(ins) if m == 0 deleteat!(a, r) diff --git a/base/ascii.jl b/base/ascii.jl index c9c0035aa2c3c..9687d6acf4cb4 100644 --- a/base/ascii.jl +++ b/base/ascii.jl @@ -14,9 +14,9 @@ getindex(s::ASCIIString, i::Int) = (x=s.data[i]; x < 0x80 ? char(x) : '\ufffd') sizeof(s::ASCIIString) = sizeof(s.data) -getindex(s::ASCIIString, r::Vector) = ASCIIString(getindex(s.data,r)) -getindex(s::ASCIIString, r::UnitRange{Int}) = ASCIIString(getindex(s.data,r)) -getindex(s::ASCIIString, indx::AbstractVector{Int}) = ASCIIString(s.data[indx]) +getindex(s::ASCIIString, r::Vector) = ASCIIString([s.data[i] for i = r]) +getindex(s::ASCIIString, r::UnitRange{Int}) = ASCIIString([s.data[i] for i = r]) +getindex(s::ASCIIString, indx::AbstractVector{Int}) = ASCIIString([s.data[i] for i = indx]) search(s::ASCIIString, c::Char, i::Integer) = c < char(0x80) ? search(s.data,uint8(c),i) : 0 rsearch(s::ASCIIString, c::Char, i::Integer) = c < char(0x80) ? rsearch(s.data,uint8(c),i) : 0 diff --git a/base/darray.jl b/base/darray.jl index c96096209c923..45c14c75f69f0 100644 --- a/base/darray.jl +++ b/base/darray.jl @@ -111,7 +111,7 @@ function chunk_idxs(dims, chunks) idxs, cuts end -function localpartindex(pmap::Vector{Int}) +function localpartindex(pmap::StridedVector{Int}) mi = myid() for i = 1:length(pmap) if pmap[i] == mi diff --git a/base/help.jl b/base/help.jl index eac694de07c12..f5757343e13c4 100644 --- a/base/help.jl +++ b/base/help.jl @@ -83,7 +83,7 @@ function print_help_entries(io::IO, entries) end end -func_expr_from_symbols(s::Vector{Symbol}) = length(s) == 1 ? s[1] : Expr(:., func_expr_from_symbols(s[1:end-1]), Expr(:quote, s[end])) +func_expr_from_symbols(s::Vector{Symbol}) = length(s) == 1 ? s[1] : Expr(:., func_expr_from_symbols(copy(s[1:end-1])), Expr(:quote, s[end])) function help(io::IO, fname::AbstractString, obj=0) init_help() diff --git a/base/inference.jl b/base/inference.jl index aee20db2b32b4..fce6850afb388 100644 --- a/base/inference.jl +++ b/base/inference.jl @@ -885,7 +885,7 @@ function abstract_eval_arg(a::ANY, vtypes::ANY, sv::StaticVarInfo) end function abstract_eval_call(e, vtypes, sv::StaticVarInfo) - fargs = e.args[2:end] + fargs = [e.args[i] for i = 2:length(e.args)] argtypes = tuple([abstract_eval_arg(a, vtypes, sv) for a in fargs]...) if any(x->is(x,Bottom), argtypes) return Bottom @@ -1673,7 +1673,7 @@ function eval_annotate(e::ANY, vtypes::ANY, sv::StaticVarInfo, decls, clo) end if (head === :call || head === :call1) && isa(e.args[1],LambdaStaticData) called = e.args[1] - fargs = e.args[2:end] + fargs = [e.args[i] for i = 2:length(e.args)] argtypes = tuple([abstract_eval_arg(a, vtypes, sv) for a in fargs]...) # recur inside inner functions once we have all types tr,ty = typeinf(called, argtypes, called.sparams, called, false) @@ -2029,7 +2029,7 @@ function inlineable(f, e::Expr, atypes, sv, enclosing_ast) if !(isa(f,Function) || isa(f,IntrinsicFunction)) return NF end - argexprs = e.args[2:end] + argexprs = [e.args[i] for i = 2:length(e.args)] if is(f, typeassert) && length(atypes)==2 # typeassert(x::S, T) => x, when S<:T @@ -2214,7 +2214,7 @@ function inlineable(f, e::Expr, atypes, sv, enclosing_ast) needcopy = false end replace_tupleref!(ast, body, vaname, newnames, sv, 1) - args = vcat(args[1:na-1], newnames) + args = vcat([args[i] for i = 1:na-1], newnames) na = length(args) islocal = false # if the argument name is also used as a local variable, @@ -2233,8 +2233,8 @@ function inlineable(f, e::Expr, atypes, sv, enclosing_ast) end else # construct tuple-forming expression for argument tail - vararg = mk_tuplecall(argexprs[na:end]) - argexprs = Any[argexprs[1:(na-1)]..., vararg] + vararg = mk_tuplecall([argexprs[i] for i = na:length(argexprs)]) + argexprs = Any[[argexprs[i] for i = 1:(na-1)]..., vararg] isva = true end elseif na != length(argexprs) @@ -2663,7 +2663,7 @@ function inlining_pass(e::Expr, sv, ast) end for ninline = 1:100 - atypes = tuple(Any[exprtype(x) for x in e.args[2:end]]...) + atypes = tuple(Any[exprtype(x) for x in [e.args[ea] for ea = 2:length(e.args)]]...) if length(atypes) > MAX_TUPLETYPE_LEN atypes = limit_tuple_type(atypes) end @@ -2694,7 +2694,7 @@ function inlining_pass(e::Expr, sv, ast) t = to_tuple_of_Types(exprtype(aarg)) if isa(aarg,Expr) && is_known_call(aarg, tuple, sv) # apply(f,tuple(x,y,...)) => f(x,y,...) - newargs[i-3] = aarg.args[2:end] + newargs[i-3] = [aarg.args[j] for j = 2:length(aarg.args)] elseif isa(aarg, Tuple) newargs[i-3] = Any[ QuoteNode(x) for x in aarg ] elseif isa(t,Tuple) && !isvatuple(t) && effect_free(aarg,sv,true) diff --git a/base/linalg/cholmod.jl b/base/linalg/cholmod.jl index ab592b78444aa..907bdc31c6518 100644 --- a/base/linalg/cholmod.jl +++ b/base/linalg/cholmod.jl @@ -38,13 +38,13 @@ const chm_l_com = fill(0xff, chm_com_sz) ## chm_com and chm_l_com must be initialized at runtime because they contain pointers ## to functions in libc.so, whose addresses can change function cmn(::Type{Int32}) - if isnan(reinterpret(Float64,chm_com[1:8])[1]) + if isnan(reinterpret(Float64, copy(chm_com[1:8]))[1]) @isok ccall((:cholmod_start, :libcholmod), Cint, (Ptr{UInt8},), chm_com) end chm_com end function cmn(::Type{Int64}) - if isnan(reinterpret(Float64,chm_l_com[1:8])[1]) + if isnan(reinterpret(Float64, copy(chm_l_com[1:8]))[1]) @isok ccall((:cholmod_l_start, :libcholmod), Cint, (Ptr{UInt8},), chm_l_com) end chm_l_com @@ -839,7 +839,7 @@ end A_ldiv_B!(L::CholmodFactor, B) = L\B # Revisit this to see if allocation can be avoided. It should be possible at least for the right hand side. (\){T<:CHMVTypes}(L::CholmodFactor{T}, B::CholmodDense{T}) = solve(L, B, CHOLMOD_A) -(\){T<:CHMVTypes}(L::CholmodFactor{T}, b::Vector{T}) = reshape(solve(L, CholmodDense!(b), CHOLMOD_A).mat, length(b)) +(\){T<:CHMVTypes}(L::CholmodFactor{T}, b::StridedVector{T}) = reshape(solve(L, CholmodDense!(convert(Vector{T}, b)), CHOLMOD_A).mat, length(b)) (\){T<:CHMVTypes}(L::CholmodFactor{T}, B::Matrix{T}) = solve(L, CholmodDense!(B),CHOLMOD_A).mat function (\){Tv<:CHMVTypes,Ti<:CHMITypes}(L::CholmodFactor{Tv,Ti},B::CholmodSparse{Tv,Ti}) solve(L,B,CHOLMOD_A) diff --git a/base/linalg/dense.jl b/base/linalg/dense.jl index 9b1a0973a20b8..454c8c38c63ce 100644 --- a/base/linalg/dense.jl +++ b/base/linalg/dense.jl @@ -334,7 +334,7 @@ function inv{S}(A::StridedMatrix{S}) return convert(typeof(Ac), Ai) end -function factorize{T}(A::Matrix{T}) +function factorize{T}(A::StridedMatrix{T}) m, n = size(A) if m == n if m == 1 return A[1] end diff --git a/base/linalg/factorization.jl b/base/linalg/factorization.jl index c8531517afaa3..36815a048bfa5 100644 --- a/base/linalg/factorization.jl +++ b/base/linalg/factorization.jl @@ -79,19 +79,19 @@ convert{T}(::Type{Factorization{T}}, A::QRPivoted) = convert(QRPivoted{T}, A) function getindex(A::QR, d::Symbol) m, n = size(A) - d == :R && return triu!(A.factors[1:min(m,n), 1:n]) + d == :R && return triu(A.factors[1:min(m,n), 1:n]) d == :Q && return QRPackedQ(A.factors,A.τ) throw(KeyError(d)) end function getindex(A::QRCompactWY, d::Symbol) m, n = size(A) - d == :R && return triu!(A.factors[1:min(m,n), 1:n]) + d == :R && return triu(A.factors[1:min(m,n), 1:n]) d == :Q && return QRCompactWYQ(A.factors,A.T) throw(KeyError(d)) end function getindex{T}(A::QRPivoted{T}, d::Symbol) m, n = size(A) - d == :R && return triu!(A.factors[1:min(m,n), 1:n]) + d == :R && return triu(A.factors[1:min(m,n), 1:n]) d == :Q && return QRPackedQ(A.factors,A.τ) d == :p && return A.jpvt if d == :P diff --git a/base/linalg/lapack.jl b/base/linalg/lapack.jl index c7e8d18b6c44b..6fc2f3c9c55fc 100644 --- a/base/linalg/lapack.jl +++ b/base/linalg/lapack.jl @@ -425,7 +425,7 @@ for (tzrzf, ormrz, elty) in function tzrzf!(A::StridedMatrix{$elty}) m, n = size(A) if n < m throw(DimensionMismatch("matrix cannot have fewer columns than rows")) end - lda = max(1, m) + lda = stride(A, 2) tau = similar(A, $elty, m) work = Array($elty, 1) lwork = -1 @@ -434,7 +434,7 @@ for (tzrzf, ormrz, elty) in ccall(($(blasfunc(tzrzf)), liblapack), Void, (Ptr{BlasInt}, Ptr{BlasInt}, Ptr{$elty}, Ptr{BlasInt}, Ptr{$elty}, Ptr{$elty}, Ptr{BlasInt}, Ptr{BlasInt}), - &m, &n, A, &lda, + &m, &n, A, &max(1, lda), tau, work, &lwork, info) if i == 1 lwork = blas_int(real(work[1])) @@ -2025,19 +2025,19 @@ for (trcon, trevc, trrfs, elty) in #Decide what exactly to return if howmny=='S' #compute selected eigenvectors if side=='L' #left eigenvectors only - return select, VL[:,1:m[1]] + return select, copy(VL[:,1:m[1]]) elseif side=='R' #right eigenvectors only - return select, VR[:,1:m[1]] + return select, copy(VR[:,1:m[1]]) else #side=='B' #both eigenvectors - return select, VL[:,1:m[1]], VR[:,1:m[1]] + return select, copy(VL[:,1:m[1]]), copy(VR[:,1:m[1]]) end else #compute all eigenvectors if side=='L' #left eigenvectors only - return VL[:,1:m[1]] + return copy(VL[:,1:m[1]]) elseif side=='R' #right eigenvectors only - return VR[:,1:m[1]] + return copy(VR[:,1:m[1]]) else #side=='B' #both eigenvectors - return VL[:,1:m[1]], VR[:,1:m[1]] + return copy(VL[:,1:m[1]]), copy(VR[:,1:m[1]]) end end end @@ -2144,19 +2144,19 @@ for (trcon, trevc, trrfs, elty, relty) in #Decide what exactly to return if howmny=='S' #compute selected eigenvectors if side=='L' #left eigenvectors only - return select, VL[:,1:m[1]] + return select, copy(VL[:,1:m[1]]) elseif side=='R' #right eigenvectors only - return select, VR[:,1:m[1]] + return select, copy(VR[:,1:m[1]]) else #side=='B' #both eigenvectors - return select, VL[:,1:m[1]], VR[:,1:m[1]] + return select, copy(VL[:,1:m[1]]), copy(VR[:,1:m[1]]) end else #compute all eigenvectors if side=='L' #left eigenvectors only - return VL[:,1:m[1]] + return copy(VL[:,1:m[1]]) elseif side=='R' #right eigenvectors only - return VR[:,1:m[1]] + return copy(VR[:,1:m[1]]) else #side=='B' #both eigenvectors - return VL[:,1:m[1]], VR[:,1:m[1]] + return copy(VL[:,1:m[1]]), copy(VR[:,1:m[1]]) end end end @@ -2243,7 +2243,7 @@ for (stev, stebz, stegr, stein, elty) in w, iblock, isplit, work, iwork, info) @lapackerror - w[1:m[1]], iblock[1:m[1]], isplit[1:nsplit[1]] + copy(w[1:m[1]]), copy(iblock[1:m[1]]), copy(isplit[1:nsplit[1]]) end #* DSTEGR computes selected eigenvalues and, optionally, eigenvectors #* of a real symmetric tridiagonal matrix T. Any such unreduced matrix has @@ -2288,7 +2288,7 @@ for (stev, stebz, stegr, stein, elty) in end end @lapackerror - w[1:m[1]], Z[:,1:m[1]] + copy(w[1:m[1]]), copy(Z[:,1:m[1]]) end #* DSTEIN computes the eigenvectors of a real symmetric tridiagonal #* matrix T corresponding to specified eigenvalues, using inverse @@ -2297,7 +2297,8 @@ for (stev, stebz, stegr, stein, elty) in # $ IWORK, IFAIL, INFO ) # We allow the user to specify exactly which eigenvectors to get by # specifying the eigenvalues (which may be approximate) via w_in - function stein!(dv::Vector{$elty}, ev_in::Vector{$elty}, w_in::Vector{$elty}, iblock_in::Vector{BlasInt}, isplit_in::Vector{BlasInt}) + function stein!(dv::StridedVector{$elty}, ev_in::StridedVector{$elty}, w_in::StridedVector{$elty}, iblock_in::StridedVector{BlasInt}, isplit_in::StridedVector{BlasInt}) + chkstride1(dv, ev_in, w_in, iblock_in, isplit_in) n = length(dv) if length(ev_in) != (n-1) throw(DimensionMismatch("stein!")) end ev = [ev_in; zeros($elty,1)] @@ -2341,12 +2342,12 @@ for (stev, stebz, stegr, stein, elty) in end end end -stegr!(jobz::BlasChar, dv::Vector, ev::Vector) = stegr!(jobz, 'A', dv, ev, 0.0, 0.0, 0, 0) +stegr!(jobz::BlasChar, dv::StridedVector, ev::StridedVector) = stegr!(jobz, 'A', dv, ev, 0.0, 0.0, 0, 0) # Allow user to skip specification of iblock and isplit -stein!(dv::Vector, ev::Vector, w_in::Vector)=stein!(dv, ev, w_in, zeros(BlasInt,0), zeros(BlasInt,0)) +stein!(dv::StridedVector, ev::StridedVector, w_in::StridedVector) = stein!(dv, ev, w_in, zeros(BlasInt,0), zeros(BlasInt,0)) # Allow user to specify just one eigenvector to get in stein! -stein!(dv::Vector, ev::Vector, eval::Real)=stein!(dv, ev, [eval], zeros(BlasInt,0), zeros(BlasInt,0)) +stein!(dv::StridedVector, ev::StridedVector, eval::Real) = stein!(dv, ev, [eval], zeros(BlasInt,0), zeros(BlasInt,0)) ## (SY) symmetric real matrices - Bunch-Kaufman decomposition, ## solvers (direct and factored) and inverse. @@ -2900,7 +2901,7 @@ for (syev, syevr, sygvd, elty) in iwork = Array(BlasInt, liwork) end end - w[1:m[1]], Z[:,1:(jobz == 'V' ? m[1] : 0)] + copy(w[1:m[1]]), copy(Z[:,1:(jobz == 'V' ? m[1] : 0)]) end syevr!(jobz::BlasChar, A::StridedMatrix{$elty}) = syevr!(jobz, 'A', 'U', A, 0.0, 0.0, 0, 0, -1.0) # Generalized eigenproblem @@ -3045,7 +3046,7 @@ for (syev, syevr, sygvd, elty, relty) in iwork = Array(BlasInt, liwork) end end - w[1:m[1]], Z[:,1:(jobz == 'V' ? m[1] : 0)] + copy(w[1:m[1]]), copy(Z[:,1:(jobz == 'V' ? m[1] : 0)]) end syevr!(jobz::BlasChar, A::StridedMatrix{$elty}) = syevr!(jobz, 'A', 'U', A, 0.0, 0.0, 0, 0, -1.0) # SUBROUTINE ZHEGVD( ITYPE, JOBZ, UPLO, N, A, LDA, B, LDB, W, WORK, @@ -3125,6 +3126,8 @@ for (bdsqr, relty, elty) in # Do checks @chkuplo length(e_) == n - 1 || throw(DimensionMismatch("off-diagonal has length $(length(e_)) but should have length $(n - 1)")) + size(Vt, 1) == n || throw(DimensionMismatch("first dimension of matrix Vt has length $(size(Vt, 1)), but should be $n")) + size(C, 1) == n || throw(DimensionMismatch("first dimension of matrix C has length $(size(C, 1)), but should be $n")) if ncvt > 0 ldvt >= n || throw(DimensionMismatch("leading dimension of Vt must be at least $n")) end @@ -3228,7 +3231,7 @@ for (gecon, elty) in # DOUBLE PRECISION A( LDA, * ), WORK( * ) chkstride1(A) n = chksquare(A) - lda = max(1, stride(A, 2)) + lda = stride(A, 2) rcond = Array($elty, 1) work = Array($elty, 4n) iwork = Array(BlasInt, n) @@ -3237,7 +3240,7 @@ for (gecon, elty) in (Ptr{UInt8}, Ptr{BlasInt}, Ptr{$elty}, Ptr{BlasInt}, Ptr{$elty}, Ptr{$elty}, Ptr{$elty}, Ptr{BlasInt}, Ptr{BlasInt}), - &normtype, &n, A, &lda, &anorm, rcond, work, iwork, + &normtype, &n, A, &max(1, lda), &anorm, rcond, work, iwork, info) @lapackerror rcond[1] @@ -3262,7 +3265,7 @@ for (gecon, elty, relty) in # COMPLEX*16 A( LDA, * ), WORK( * ) chkstride1(A) n = size(A, 2) - lda = max(1, size(A, 1)) + lda = stride(A, 2) rcond = Array($relty, 1) work = Array($elty, 2n) rwork = Array($relty, 2n) @@ -3271,7 +3274,7 @@ for (gecon, elty, relty) in (Ptr{BlasChar}, Ptr{BlasInt}, Ptr{$elty}, Ptr{BlasInt}, Ptr{$relty}, Ptr{$relty}, Ptr{$elty}, Ptr{$relty}, Ptr{BlasInt}), - &normtype, &n, A, &lda, &anorm, rcond, work, rwork, + &normtype, &n, A, &max(1, lda), &anorm, rcond, work, rwork, info) @lapackerror rcond[1] @@ -3441,7 +3444,7 @@ for (gees, gges, elty) in end end @lapackerror - A, B, complex(alphar, alphai), beta, vsl[1:(jobvsl == 'V' ? n : 0),:], vsr[1:(jobvsr == 'V' ? n : 0),:] + A, B, complex(alphar, alphai), beta, copy(vsl[1:(jobvsl == 'V' ? n : 0),:]), copy(vsr[1:(jobvsr == 'V' ? n : 0),:]) end end end @@ -3532,7 +3535,7 @@ for (gees, gges, elty, relty) in end end @lapackerror - A, B, alpha, beta, vsl[1:(jobvsl == 'V' ? n : 0),:], vsr[1:(jobvsr == 'V' ? n : 0),:] + A, B, alpha, beta, copy(vsl[1:(jobvsl == 'V' ? n : 0),:]), copy(vsr[1:(jobvsr == 'V' ? n : 0),:]) end end end diff --git a/base/linalg/lu.jl b/base/linalg/lu.jl index c07806b885efd..b6ea7d0b9bd16 100644 --- a/base/linalg/lu.jl +++ b/base/linalg/lu.jl @@ -94,11 +94,11 @@ end function getindex{T,S<:StridedMatrix}(A::LU{T,S}, d::Symbol) m, n = size(A) if d == :L - L = tril!(A.factors[1:m, 1:min(m,n)]) + L = tril(A.factors[1:m, 1:min(m,n)]) for i = 1:min(m,n); L[i,i] = one(T); end return L end - d == :U && return triu!(A.factors[1:min(m,n), 1:n]) + d == :U && return triu(A.factors[1:min(m,n), 1:n]) d == :p && return ipiv2perm(A.ipiv, m) if d == :P p = A[:p] diff --git a/base/linalg/matmul.jl b/base/linalg/matmul.jl index 1af6d5281ee01..e8ac5df1e320d 100644 --- a/base/linalg/matmul.jl +++ b/base/linalg/matmul.jl @@ -24,8 +24,8 @@ function scale!(C::AbstractMatrix, b::AbstractVector, A::AbstractMatrix) end C end -scale(A::Matrix, b::Vector) = scale!(similar(A, promote_type(eltype(A),eltype(b))), A, b) -scale(b::Vector, A::Matrix) = scale!(similar(b, promote_type(eltype(A),eltype(b)), size(A)), b, A) +scale(A::AbstractMatrix, b::AbstractVector) = scale!(similar(A, promote_type(eltype(A),eltype(b))), A, b) +scale(b::AbstractVector, A::AbstractMatrix) = scale!(similar(b, promote_type(eltype(A),eltype(b)), size(A)), b, A) # Dot products diff --git a/base/multidimensional.jl b/base/multidimensional.jl index 94b1615531f05..ef9a5a18aae29 100644 --- a/base/multidimensional.jl +++ b/base/multidimensional.jl @@ -171,7 +171,12 @@ end _getindex(A, I::(Union(Int,AbstractVector)...)) = _getindex!(similar(A, index_shape(I...)), A, I...) -@nsplat N function getindex(A::Array, I::NTuple{N,Union(Real,AbstractVector)}...) +@nsplat N function getindex(A::Array, I::NTuple{N,Union(Real,UnitRange{Int},Colon)}...) + checkbounds(A, I...) + slice(A, I...) +end + +@nsplat N function getindex(A::Array, I::NTuple{N,AbstractVector}...) checkbounds(A, I...) _getindex(A, to_index(I...)) end @@ -183,7 +188,7 @@ end end -@ngenerate N typeof(A) function setindex!(A::Array, x, J::NTuple{N,Union(Real,AbstractArray)}...) +@ngenerate N typeof(A) function setindex!(A::Array, x, J::NTuple{N,Union(Real,AbstractArray,Colon)}...) @ncall N checkbounds A J @nexprs N d->(I_d = to_index(J_d)) stride_1 = 1 diff --git a/base/range.jl b/base/range.jl index 7c21201509bff..e5ba40686abdf 100644 --- a/base/range.jl +++ b/base/range.jl @@ -66,6 +66,8 @@ immutable UnitRange{T<:Real} <: OrdinalRange{T,Int} end UnitRange{T<:Real}(start::T, stop::T) = UnitRange{T}(start, stop) +colon() = Colon() + colon(a::Real, b::Real) = colon(promote(a,b)...) colon{T<:Real}(start::T, stop::T) = UnitRange{T}(start, stop) diff --git a/base/show.jl b/base/show.jl index 6ab95834695b3..5f7250236d6bb 100644 --- a/base/show.jl +++ b/base/show.jl @@ -360,7 +360,7 @@ function show_call(io::IO, head, func, func_args, indent) end if !isempty(func_args) && isa(func_args[1], Expr) && func_args[1].head === :parameters print(io, op) - show_list(io, func_args[2:end], ',', indent, 0) + show_list(io, [func_args[i] for i = 2:length(func_args)], ',', indent, 0) print(io, "; ") show_list(io, func_args[1].args, ',', indent, 0) print(io, cl) @@ -452,13 +452,13 @@ function show_unquoted(io::IO, ex::Expr, indent::Int, prec::Int) # function declaration (like :call but always printed with parens) # (:calldecl is a "fake" expr node created when we find a :function expr) elseif head == :calldecl && nargs >= 1 - show_call(io, head, args[1], args[2:end], indent) + show_call(io, head, args[1], [args[i] for i = 2:length(args)], indent) # function call elseif haskey(expr_calls, head) && nargs >= 1 # :call/:ref/:curly func = args[1] func_prec = operator_precedence(func) - func_args = args[2:end] + func_args = [args[i] for i = 2:length(args)] # scalar multiplication (i.e. "100x") if (func == :(*) && length(func_args)==2 && @@ -587,7 +587,7 @@ function show_unquoted(io::IO, ex::Expr, indent::Int, prec::Int) print(io, "end") elseif is(head, :let) && nargs >= 1 - show_block(io, "let", args[2:end], args[1], indent); print(io, "end") + show_block(io, "let", [args[i] for i = 2:length(args)], args[1], indent); print(io, "end") elseif is(head, :block) || is(head, :body) show_block(io, "begin", ex, indent); print(io, "end") diff --git a/base/socket.jl b/base/socket.jl index 78d73aaf0060e..e8f5a28877d6e 100644 --- a/base/socket.jl +++ b/base/socket.jl @@ -477,7 +477,7 @@ function _uv_hook_recv(sock::UDPSocket, nread::Int, buf_addr::Ptr{Void}, buf_siz notify_error(sock.recvnotify,"Partial message received") end buf = pointer_to_array(convert(Ptr{UInt8},buf_addr),int(buf_size),true) - notify(sock.recvnotify,buf[1:nread]) + notify(sock.recvnotify, copy(buf[1:nread])) end function _send(sock::UDPSocket,ipaddr::IPv4,port::UInt16,buf) diff --git a/base/string.jl b/base/string.jl index 9c81e20102066..2755041c867de 100644 --- a/base/string.jl +++ b/base/string.jl @@ -32,6 +32,7 @@ string(xs...) = print_to_string(xs...) bytestring() = "" bytestring(s::Array{UInt8,1}) = bytestring(pointer(s),length(s)) +bytestring{N}(s::SubArray{UInt8,1,Array{UInt8,N},(UnitRange{Int64},),1}) = bytestring(pointer(s),length(s)) bytestring(s::AbstractString...) = print_to_string(s...) function bytestring(p::Union(Ptr{UInt8},Ptr{Int8})) @@ -1040,7 +1041,7 @@ function triplequoted(args...) for s in sx if isa(s,ByteString) lines = split(s,'\n') - for line in lines[2:end] + for line in [lines[i] for i = 2:length(lines)] n,blank = indentation(line) if !blank indent = min(indent, n) diff --git a/base/utf32.jl b/base/utf32.jl index ca030e45c6310..7a71479c89160 100644 --- a/base/utf32.jl +++ b/base/utf32.jl @@ -45,8 +45,10 @@ function convert(::Type{UTF32String}, data::AbstractVector{Char}) UTF32String(copy!(d,1, data,1, len)) end -convert{T<:Union(Int32,UInt32)}(::Type{UTF32String}, data::AbstractVector{T}) = +convert{T<:Union(Int32,UInt32)}(::Type{UTF32String}, data::Vector{T}) = convert(UTF32String, reinterpret(Char, data)) +convert{T<:Union(Int32,UInt32)}(::Type{UTF32String}, data::AbstractVector{T}) = + convert(UTF32String, reinterpret(Char, convert(Array, data))) convert{T<:AbstractString}(::Type{T}, v::AbstractVector{Char}) = convert(T, utf32(v)) diff --git a/base/utf8.jl b/base/utf8.jl index 47ea58ead2d8a..6b6987d0b3cca 100644 --- a/base/utf8.jl +++ b/base/utf8.jl @@ -107,7 +107,7 @@ function getindex(s::UTF8String, r::UnitRange{Int}) throw(BoundsError()) end j = nextind(s,j)-1 - UTF8String(d[i:j]) + UTF8String([d[k] for k = i:j]) end function search(s::UTF8String, c::Char, i::Integer) @@ -182,6 +182,7 @@ function convert(::Type{UTF8String}, a::Array{UInt8,1}, invalids_as::AbstractStr end UTF8String(a) end +convert(::Type{UTF8String}, s::AbstractVector{UInt8}) = convert(UTF8String, convert(Array, s)) convert(::Type{UTF8String}, s::AbstractString) = utf8(bytestring(s)) # The last case is the replacement character 0xfffd (3 bytes) diff --git a/src/julia-syntax.scm b/src/julia-syntax.scm index 4448ad853d5ec..14689108941ad 100644 --- a/src/julia-syntax.scm +++ b/src/julia-syntax.scm @@ -319,7 +319,7 @@ ; translate index x from colons to ranges (define (expand-index-colon x) - (cond ((eq? x ':) `(call colon 1 end)) + (cond ((eq? x ':) `(call colon)) ((and (pair? x) (eq? (car x) ':)) (cond ((length= x 3) diff --git a/test/arpack.jl b/test/arpack.jl index b93f116a0b454..ee2cb64685350 100644 --- a/test/arpack.jl +++ b/test/arpack.jl @@ -92,21 +92,21 @@ size(Phi::CPM)=(size(Phi.kraus,1)^2,size(Phi.kraus,3)^2) issym(Phi::CPM)=false ishermitian(Phi::CPM)=false -function *{T<:Base.LinAlg.BlasFloat}(Phi::CPM{T},rho::Vector{T}) - rho=reshape(rho,(size(Phi.kraus,3),size(Phi.kraus,3))) - rho2=zeros(T,(size(Phi.kraus,1),size(Phi.kraus,1))) - for s=1:size(Phi.kraus,2) - As=slice(Phi.kraus,:,s,:) - rho2+=As*rho*As' +function *{T<:Base.LinAlg.BlasFloat}(Phi::CPM{T}, rho::StridedVector{T}) + rho = reshape(rho, (size(Phi.kraus, 3), size(Phi.kraus, 3))) + rho2 = zeros(T, (size(Phi.kraus, 1), size(Phi.kraus, 1))) + for s = 1:size(Phi.kraus, 2) + As = slice(Phi.kraus, :, s, :) + rho2 += As*rho*As' end - return reshape(rho2,(size(Phi.kraus,1)^2,)) + return reshape(rho2, (size(Phi.kraus,1)^2,)) end # Generate random isometry -(Q,R)=qr(randn(100,50)) -Q=reshape(Q,(50,2,50)) +(Q,R) = qr(randn(100,50)) +Q = reshape(Q,(50,2,50)) # Construct trace-preserving completely positive map from this -Phi=CPM(Q) -(d,v,nconv,numiter,numop,resid) = eigs(Phi,nev=1,which=:LM) +Phi = CPM(Q) +(d,v,nconv,numiter,numop,resid) = eigs(Phi, nev=1, which=:LM) # Properties: largest eigenvalue should be 1, largest eigenvector, when reshaped as matrix # should be a Hermitian positive definite matrix (up to an arbitrary phase) diff --git a/test/arrayops.jl b/test/arrayops.jl index df8a92e5bc6a7..ec1238dbd9fea 100644 --- a/test/arrayops.jl +++ b/test/arrayops.jl @@ -774,7 +774,7 @@ Nmax = 3 # TODO: go up to CARTESIAN_DIMS+2 (currently this exposes problems) for N = 1:Nmax #indexing with (Range1, Range1, Range1) args = ntuple(N, d->Range1{Int}) - @test Base.return_types(getindex, tuple(Array{Float32, N}, args...)) == [Array{Float32, N}] + @test Base.return_types(getindex, tuple(Array{Float32, N}, args...)) == [SubArray{Float32,N,Array{Float32,N},ntuple(N, d->UnitRange{Int64}),1}] @test Base.return_types(getindex, tuple(BitArray{N}, args...)) == Any[BitArray{N}] @test Base.return_types(setindex!, tuple(Array{Float32, N}, Array{Int, 1}, args...)) == [Array{Float32, N}] # Indexing with (Range1, Range1, Float64) diff --git a/test/bitarray.jl b/test/bitarray.jl index e426c0355ae7e..d96ca0573c076 100644 --- a/test/bitarray.jl +++ b/test/bitarray.jl @@ -1,5 +1,6 @@ tc{N}(r1::NTuple{N}, r2::NTuple{N}) = all(map(x->tc(x...), [zip(r1,r2)...])) tc{N}(r1::BitArray{N}, r2::Union(BitArray{N},Array{Bool,N})) = true +tc{N,M}(r1::BitArray{N}, r2::SubArray{Bool,N,Array{Bool,M},NTuple{N,UnitRange{Int64}},1}) = true tc{T}(r1::T, r2::T) = true tc(r1,r2) = false diff --git a/test/parallel.jl b/test/parallel.jl index 7b0b9398b8258..d01d4ef74a29e 100644 --- a/test/parallel.jl +++ b/test/parallel.jl @@ -6,7 +6,7 @@ if nprocs() < 3 end id_me = myid() -id_other = filter(x -> x != id_me, procs())[rand(1:(nprocs()-1))] +id_other = filter(x -> x != id_me, procs())[rand(1:(nprocs() - 1))] @test fetch(@spawnat id_other myid()) == id_other @test @fetchfrom id_other begin myid() end == id_other