Skip to content

Commit 35777df

Browse files
committed
Some necessary generalizations
1 parent 7325418 commit 35777df

File tree

7 files changed

+28
-24
lines changed

7 files changed

+28
-24
lines changed

base/abstractarraymath.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ function repmat(a::AbstractVector, m::Int)
212212
end
213213

214214
# Generalized repmat
215-
function repeat{T}(A::Array{T};
215+
function repeat{T}(A::AbstractArray{T};
216216
inner::Array{Int} = ones(Int, ndims(A)),
217217
outer::Array{Int} = ones(Int, ndims(A)))
218218
ndims_in = ndims(A)

base/complex.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,7 @@ big{T<:AbstractFloat,N}(A::AbstractArray{Complex{T},N}) = convert(AbstractArray{
792792

793793
promote_array_type{S<:Union{Complex, Real}, AT<:AbstractFloat}(F, ::Type{S}, ::Type{Complex{AT}}) = Complex{AT}
794794

795-
function complex{S<:Real,T<:Real}(A::Array{S}, B::Array{T})
795+
function complex{S<:Real,T<:Real}(A::AbstractArray{S}, B::AbstractArray{T})
796796
if size(A) != size(B); throw(DimensionMismatch()); end
797797
F = similar(A, typeof(complex(zero(S),zero(T))))
798798
for (iF, iA, iB) in zip(eachindex(F), eachindex(A), eachindex(B))
@@ -801,15 +801,15 @@ function complex{S<:Real,T<:Real}(A::Array{S}, B::Array{T})
801801
return F
802802
end
803803

804-
function complex{T<:Real}(A::Real, B::Array{T})
804+
function complex{T<:Real}(A::Real, B::AbstractArray{T})
805805
F = similar(B, typeof(complex(A,zero(T))))
806806
for (iF, iB) in zip(eachindex(F), eachindex(B))
807807
@inbounds F[iF] = complex(A, B[iB])
808808
end
809809
return F
810810
end
811811

812-
function complex{T<:Real}(A::Array{T}, B::Real)
812+
function complex{T<:Real}(A::AbstractArray{T}, B::Real)
813813
F = similar(A, typeof(complex(zero(T),B)))
814814
for (iF, iA) in zip(eachindex(F), eachindex(A))
815815
@inbounds F[iF] = complex(A[iA], B)

base/linalg/dense.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ function trace{T}(A::Matrix{T})
150150
t
151151
end
152152

153-
function kron{T,S}(a::Matrix{T}, b::Matrix{S})
153+
function kron{T,S}(a::AbstractMatrix{T}, b::AbstractMatrix{S})
154154
R = Array(promote_type(T,S), size(a,1)*size(b,1), size(a,2)*size(b,2))
155155
m = 1
156156
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})
163163
R
164164
end
165165

166-
kron(a::Number, b::Union{Number, Vector, Matrix}) = a * b
167-
kron(a::Union{Vector, Matrix}, b::Number) = a * b
168-
kron(a::Vector, b::Vector)=vec(kron(reshape(a,length(a),1),reshape(b,length(b),1)))
169-
kron(a::Matrix, b::Vector)=kron(a,reshape(b,length(b),1))
170-
kron(a::Vector, b::Matrix)=kron(reshape(a,length(a),1),b)
166+
kron(a::Number, b::Union{Number, AbstractVecOrMat}) = a * b
167+
kron(a::AbstractVecOrMat, b::Number) = a * b
168+
kron(a::AbstractVector, b::AbstractVector)=vec(kron(reshape(a,length(a),1),reshape(b,length(b),1)))
169+
kron(a::AbstractMatrix, b::AbstractVector)=kron(a,reshape(b,length(b),1))
170+
kron(a::AbstractVector, b::AbstractMatrix)=kron(reshape(a,length(a),1),b)
171171

172172
^(A::Matrix, p::Integer) = p < 0 ? inv(A^-p) : Base.power_by_squaring(A,p)
173173

base/pointer.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ cconvert(::Type{Ptr{UInt8}}, s::AbstractString) = bytestring(s)
2626
cconvert(::Type{Ptr{Int8}}, s::AbstractString) = bytestring(s)
2727

2828
unsafe_convert{T}(::Type{Ptr{T}}, a::Array{T}) = ccall(:jl_array_ptr, Ptr{T}, (Any,), a)
29-
unsafe_convert(::Type{Ptr{Void}}, a::Array) = ccall(:jl_array_ptr, Ptr{Void}, (Any,), a)
29+
unsafe_convert{S,T}(::Type{Ptr{S}}, a::AbstractArray{T}) = convert(Ptr{S}, unsafe_convert(Ptr{T}, a))
3030

3131
# unsafe pointer to array conversions
3232
pointer_to_array(p, d::Integer, own=false) = pointer_to_array(p, (d,), own)

base/sparse/cholmod.jl

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -957,23 +957,28 @@ end
957957
function convert{T}(::Type{Matrix{T}}, D::Dense{T})
958958
s = unsafe_load(D.p)
959959
a = Array(T, s.nrow, s.ncol)
960-
if s.d == s.nrow
961-
unsafe_copy!(pointer(a), s.x, s.d*s.ncol)
960+
copy!(a, D)
961+
end
962+
function Base.copy!(dest::AbstractArray, D::Dense)
963+
s = unsafe_load(D.p)
964+
if s.d == s.nrow && isa(dest, Array)
965+
unsafe_copy!(pointer(dest), s.x, s.d*s.ncol)
962966
else
967+
k = 0
963968
for j = 1:s.ncol
964969
for i = 1:s.nrow
965-
a[i,j] = unsafe_load(s.x, i + (j - 1)*s.d)
970+
dest[k+=1] = unsafe_load(s.x, i + (j - 1)*s.d)
966971
end
967972
end
968973
end
969-
a
974+
dest
970975
end
971976
convert{T}(::Type{Matrix}, D::Dense{T}) = convert(Matrix{T}, D)
972977
function convert{T}(::Type{Vector{T}}, D::Dense{T})
973978
if size(D, 2) > 1
974979
throw(DimensionMismatch("input must be a vector but had $(size(D, 2)) columns"))
975980
end
976-
reshape(convert(Matrix, D), size(D, 1))
981+
copy!(Array(T, size(D, 1)), D)
977982
end
978983
convert{T}(::Type{Vector}, D::Dense{T}) = convert(Vector{T}, D)
979984

base/subarray.jl

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -263,10 +263,7 @@ compute_first_index(f, s, parent, dim, I::Tuple{}) = f
263263

264264

265265
unsafe_convert{T,N,P<:Array,I<:Tuple{Vararg{Union{RangeIndex, NoSlice}}}}(::Type{Ptr{T}}, V::SubArray{T,N,P,I}) =
266-
pointer(V.parent) + (first_index(V)-1)*sizeof(T)
267-
268-
unsafe_convert{T,N,P<:Array,I<:Tuple{Vararg{Union{RangeIndex, NoSlice}}}}(::Type{Ptr{Void}}, V::SubArray{T,N,P,I}) =
269-
convert(Ptr{Void}, unsafe_convert(Ptr{T}, V))
266+
unsafe_convert(Ptr{T}, V.parent) + (first_index(V)-1)*sizeof(T)
270267

271268
pointer(V::FastSubArray, i::Int) = pointer(V.parent, V.first_index + V.stride1*(i-1))
272269
pointer(V::FastContiguousSubArray, i::Int) = pointer(V.parent, V.first_index + i-1)

base/unicode/checkstring.jl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Throws:
5656
"""
5757
function unsafe_checkstring end
5858

59-
function unsafe_checkstring(dat::Vector{UInt8},
59+
function unsafe_checkstring(dat::AbstractVector{UInt8},
6060
pos = start(dat),
6161
endpos = endof(dat)
6262
;
@@ -152,8 +152,10 @@ function unsafe_checkstring(dat::Vector{UInt8},
152152
return totalchar, flags, num4byte, num3byte, num2byte
153153
end
154154

155-
function unsafe_checkstring{T <: Union{Vector{UInt16}, Vector{UInt32}, AbstractString}}(
156-
dat::T,
155+
typealias AbstractString1632{Tel<:Union{UInt16,UInt32}} Union{AbstractVector{Tel}, AbstractString}
156+
157+
function unsafe_checkstring(
158+
dat::AbstractString1632,
157159
pos = start(dat),
158160
endpos = endof(dat)
159161
;
@@ -184,7 +186,7 @@ function unsafe_checkstring{T <: Union{Vector{UInt16}, Vector{UInt32}, AbstractS
184186
ch, pos = next(dat, pos)
185187
!is_surrogate_trail(ch) && throw(UnicodeError(UTF_ERR_NOT_TRAIL, pos, ch))
186188
num4byte += 1
187-
if T != Vector{UInt16}
189+
if !(typeof(dat) <: AbstractVector{UInt16})
188190
!accept_surrogates && throw(UnicodeError(UTF_ERR_SURROGATE, pos, ch))
189191
flags |= UTF_SURROGATE
190192
end

0 commit comments

Comments
 (0)