diff --git a/base/abstractarraymath.jl b/base/abstractarraymath.jl index 7f343b6365d37..a74cca2ea365b 100644 --- a/base/abstractarraymath.jl +++ b/base/abstractarraymath.jl @@ -212,7 +212,7 @@ function repmat(a::AbstractVector, m::Int) end # Generalized repmat -function repeat{T}(A::Array{T}; +function repeat{T}(A::AbstractArray{T}; inner::Array{Int} = ones(Int, ndims(A)), outer::Array{Int} = ones(Int, ndims(A))) ndims_in = ndims(A) diff --git a/base/complex.jl b/base/complex.jl index afa246b6a04a2..b0d781a804cd3 100644 --- a/base/complex.jl +++ b/base/complex.jl @@ -792,7 +792,7 @@ big{T<:AbstractFloat,N}(A::AbstractArray{Complex{T},N}) = convert(AbstractArray{ promote_array_type{S<:Union{Complex, Real}, AT<:AbstractFloat}(F, ::Type{S}, ::Type{Complex{AT}}) = Complex{AT} -function complex{S<:Real,T<:Real}(A::Array{S}, B::Array{T}) +function complex{S<:Real,T<:Real}(A::AbstractArray{S}, B::AbstractArray{T}) if size(A) != size(B); throw(DimensionMismatch()); end F = similar(A, typeof(complex(zero(S),zero(T)))) for (iF, iA, iB) in zip(eachindex(F), eachindex(A), eachindex(B)) @@ -801,7 +801,7 @@ function complex{S<:Real,T<:Real}(A::Array{S}, B::Array{T}) return F end -function complex{T<:Real}(A::Real, B::Array{T}) +function complex{T<:Real}(A::Real, B::AbstractArray{T}) F = similar(B, typeof(complex(A,zero(T)))) for (iF, iB) in zip(eachindex(F), eachindex(B)) @inbounds F[iF] = complex(A, B[iB]) @@ -809,7 +809,7 @@ function complex{T<:Real}(A::Real, B::Array{T}) return F end -function complex{T<:Real}(A::Array{T}, B::Real) +function complex{T<:Real}(A::AbstractArray{T}, B::Real) F = similar(A, typeof(complex(zero(T),B))) for (iF, iA) in zip(eachindex(F), eachindex(A)) @inbounds F[iF] = complex(A[iA], B) diff --git a/base/linalg/dense.jl b/base/linalg/dense.jl index 7462da43a7846..bc3ab16e1f82f 100644 --- a/base/linalg/dense.jl +++ b/base/linalg/dense.jl @@ -150,7 +150,7 @@ function trace{T}(A::Matrix{T}) t end -function kron{T,S}(a::Matrix{T}, b::Matrix{S}) +function kron{T,S}(a::AbstractMatrix{T}, b::AbstractMatrix{S}) R = Array(promote_type(T,S), size(a,1)*size(b,1), size(a,2)*size(b,2)) m = 1 for j = 1:size(a,2), l = 1:size(b,2), i = 1:size(a,1) @@ -163,11 +163,11 @@ function kron{T,S}(a::Matrix{T}, b::Matrix{S}) R end -kron(a::Number, b::Union{Number, Vector, Matrix}) = a * b -kron(a::Union{Vector, Matrix}, b::Number) = a * b -kron(a::Vector, b::Vector)=vec(kron(reshape(a,length(a),1),reshape(b,length(b),1))) -kron(a::Matrix, b::Vector)=kron(a,reshape(b,length(b),1)) -kron(a::Vector, b::Matrix)=kron(reshape(a,length(a),1),b) +kron(a::Number, b::Union{Number, AbstractVecOrMat}) = a * b +kron(a::AbstractVecOrMat, b::Number) = a * b +kron(a::AbstractVector, b::AbstractVector)=vec(kron(reshape(a,length(a),1),reshape(b,length(b),1))) +kron(a::AbstractMatrix, b::AbstractVector)=kron(a,reshape(b,length(b),1)) +kron(a::AbstractVector, b::AbstractMatrix)=kron(reshape(a,length(a),1),b) ^(A::Matrix, p::Integer) = p < 0 ? inv(A^-p) : Base.power_by_squaring(A,p) diff --git a/base/pointer.jl b/base/pointer.jl index 83c80f33f1376..23a4f1c840b0f 100644 --- a/base/pointer.jl +++ b/base/pointer.jl @@ -26,7 +26,7 @@ cconvert(::Type{Ptr{UInt8}}, s::AbstractString) = bytestring(s) cconvert(::Type{Ptr{Int8}}, s::AbstractString) = bytestring(s) unsafe_convert{T}(::Type{Ptr{T}}, a::Array{T}) = ccall(:jl_array_ptr, Ptr{T}, (Any,), a) -unsafe_convert(::Type{Ptr{Void}}, a::Array) = ccall(:jl_array_ptr, Ptr{Void}, (Any,), a) +unsafe_convert{S,T}(::Type{Ptr{S}}, a::AbstractArray{T}) = convert(Ptr{S}, unsafe_convert(Ptr{T}, a)) # unsafe pointer to array conversions pointer_to_array(p, d::Integer, own=false) = pointer_to_array(p, (d,), own) diff --git a/base/sparse/cholmod.jl b/base/sparse/cholmod.jl index 7f0d6510430a6..6b680adb4267e 100644 --- a/base/sparse/cholmod.jl +++ b/base/sparse/cholmod.jl @@ -957,23 +957,28 @@ end function convert{T}(::Type{Matrix{T}}, D::Dense{T}) s = unsafe_load(D.p) a = Array(T, s.nrow, s.ncol) - if s.d == s.nrow - unsafe_copy!(pointer(a), s.x, s.d*s.ncol) + copy!(a, D) +end +function Base.copy!(dest::AbstractArray, D::Dense) + s = unsafe_load(D.p) + if s.d == s.nrow && isa(dest, Array) + unsafe_copy!(pointer(dest), s.x, s.d*s.ncol) else + k = 0 for j = 1:s.ncol for i = 1:s.nrow - a[i,j] = unsafe_load(s.x, i + (j - 1)*s.d) + dest[k+=1] = unsafe_load(s.x, i + (j - 1)*s.d) end end end - a + dest end convert{T}(::Type{Matrix}, D::Dense{T}) = convert(Matrix{T}, D) function convert{T}(::Type{Vector{T}}, D::Dense{T}) if size(D, 2) > 1 throw(DimensionMismatch("input must be a vector but had $(size(D, 2)) columns")) end - reshape(convert(Matrix, D), size(D, 1)) + copy!(Array(T, size(D, 1)), D) end convert{T}(::Type{Vector}, D::Dense{T}) = convert(Vector{T}, D) diff --git a/base/subarray.jl b/base/subarray.jl index 362cc08f9f7b7..8d476ce370b49 100644 --- a/base/subarray.jl +++ b/base/subarray.jl @@ -263,10 +263,7 @@ compute_first_index(f, s, parent, dim, I::Tuple{}) = f unsafe_convert{T,N,P<:Array,I<:Tuple{Vararg{Union{RangeIndex, NoSlice}}}}(::Type{Ptr{T}}, V::SubArray{T,N,P,I}) = - pointer(V.parent) + (first_index(V)-1)*sizeof(T) - -unsafe_convert{T,N,P<:Array,I<:Tuple{Vararg{Union{RangeIndex, NoSlice}}}}(::Type{Ptr{Void}}, V::SubArray{T,N,P,I}) = - convert(Ptr{Void}, unsafe_convert(Ptr{T}, V)) + unsafe_convert(Ptr{T}, V.parent) + (first_index(V)-1)*sizeof(T) pointer(V::FastSubArray, i::Int) = pointer(V.parent, V.first_index + V.stride1*(i-1)) pointer(V::FastContiguousSubArray, i::Int) = pointer(V.parent, V.first_index + i-1) diff --git a/base/unicode/checkstring.jl b/base/unicode/checkstring.jl index 8b9f344831f95..ecf83c14d328f 100644 --- a/base/unicode/checkstring.jl +++ b/base/unicode/checkstring.jl @@ -56,7 +56,7 @@ Throws: """ function unsafe_checkstring end -function unsafe_checkstring(dat::Vector{UInt8}, +function unsafe_checkstring(dat::AbstractVector{UInt8}, pos = start(dat), endpos = endof(dat) ; @@ -152,8 +152,10 @@ function unsafe_checkstring(dat::Vector{UInt8}, return totalchar, flags, num4byte, num3byte, num2byte end -function unsafe_checkstring{T <: Union{Vector{UInt16}, Vector{UInt32}, AbstractString}}( - dat::T, +typealias AbstractString1632{Tel<:Union{UInt16,UInt32}} Union{AbstractVector{Tel}, AbstractString} + +function unsafe_checkstring( + dat::AbstractString1632, pos = start(dat), endpos = endof(dat) ; @@ -184,7 +186,7 @@ function unsafe_checkstring{T <: Union{Vector{UInt16}, Vector{UInt32}, AbstractS ch, pos = next(dat, pos) !is_surrogate_trail(ch) && throw(UnicodeError(UTF_ERR_NOT_TRAIL, pos, ch)) num4byte += 1 - if T != Vector{UInt16} + if !(typeof(dat) <: AbstractVector{UInt16}) !accept_surrogates && throw(UnicodeError(UTF_ERR_SURROGATE, pos, ch)) flags |= UTF_SURROGATE end