Skip to content

Commit 88844d9

Browse files
committed
Make hvcats of heterogeneous combinations of dense matrices and vectors yield dense arrays (fixes #17686).
1 parent 58092c0 commit 88844d9

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

base/array.jl

+5-3
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,6 @@ vcat{T}(A::Matrix{T}...) = typed_vcat(T, A...)
689689
hcat(A::Union{Matrix, Vector}...) = typed_hcat(promote_eltype(A...), A...)
690690
hcat{T}(A::Union{Matrix{T}, Vector{T}}...) = typed_hcat(T, A...)
691691

692-
693692
vcat(A::Union{Matrix, Vector}...) = typed_vcat(promote_eltype(A...), A...)
694693
vcat{T}(A::Union{Matrix{T}, Vector{T}}...) = typed_vcat(T, A...)
695694

@@ -699,8 +698,11 @@ hvcat{T}(rows::Tuple{Vararg{Int}}, xs::Vector{T}...) = typed_hvcat(T, rows, xs..
699698
hvcat(rows::Tuple{Vararg{Int}}, xs::Matrix...) = typed_hvcat(promote_eltype(xs...), rows, xs...)
700699
hvcat{T}(rows::Tuple{Vararg{Int}}, xs::Matrix{T}...) = typed_hvcat(T, rows, xs...)
701700

702-
cat(catdims, xs::Union{Matrix,Vector}...) = Base.cat_t(catdims, promote_eltype(xs...), xs...)
703-
cat{T}(catdims, xs::Union{Matrix{T},Vector{T}}...) = Base.cat_t(catdims, T, xs...)
701+
hvcat(rows::Tuple{Vararg{Int}}, xs::Union{Vector,Matrix}...) = typed_hvcat(promote_eltype(xs...), rows, xs...)
702+
hvcat{T}(rows::Tuple{Vararg{Int}}, xs::Union{Vector{T},Matrix{T}}...) = typed_hvcat(T, rows, xs...)
703+
704+
cat(catdims, xs::Union{Vector,Matrix}...) = Base.cat_t(catdims, promote_eltype(xs...), xs...)
705+
cat{T}(catdims, xs::Union{Vector{T},Matrix{T}}...) = Base.cat_t(catdims, T, xs...)
704706

705707
## find ##
706708

test/arrayops.jl

+22
Original file line numberDiff line numberDiff line change
@@ -1703,3 +1703,25 @@ for op in (:.+, :.*, :.÷, :.%, :.<<, :.>>, :.-, :./, :.\, :.//, :.^)
17031703
end
17041704

17051705
end
1706+
1707+
# Test that concatenations of dense matrices/vectors yield dense matrices/vectors
1708+
let
1709+
N = 4
1710+
densevec = ones(N)
1711+
densemat = diagm(ones(N))
1712+
# Test that concatenations of homogeneous pairs of either dense matrices or dense vectors
1713+
# (i.e., Matrix-Matrix concatenations, and Vector-Vector concatenations) yield dense arrays
1714+
for densearray in (densevec, densemat)
1715+
@test isa(vcat(densearray, densearray), Array)
1716+
@test isa(hcat(densearray, densearray), Array)
1717+
@test isa(hvcat((2,), densearray, densearray), Array)
1718+
@test isa(cat((1,2), densearray, densearray), Array)
1719+
end
1720+
# Test that concatenations of heterogeneous Matrix-Vector pairs yield dense matrices
1721+
@test isa(hcat(densemat, densevec), Array)
1722+
@test isa(hcat(densevec, densemat), Array)
1723+
@test isa(hvcat((2,), densemat, densevec), Array)
1724+
@test isa(hvcat((2,), densevec, densemat), Array)
1725+
@test isa(cat((1,2), densemat, densevec), Array)
1726+
@test isa(cat((1,2), densevec, densemat), Array)
1727+
end

0 commit comments

Comments
 (0)