diff --git a/base/abstractarray.jl b/base/abstractarray.jl index 16fdb61e1d3fe..38872e5d9ef22 100644 --- a/base/abstractarray.jl +++ b/base/abstractarray.jl @@ -1638,8 +1638,12 @@ cat_size(A::AbstractArray, d) = size(A, d) cat_indices(A, d) = OneTo(1) cat_indices(A::AbstractArray, d) = axes(A, d) -cat_similar(A, ::Type{T}, shape) where T = Array{T}(undef, shape) -cat_similar(A::AbstractArray, ::Type{T}, shape) where T = similar(A, T, shape) +cat_similar(A, ::Type{T}, shape::Tuple) where T = Array{T}(undef, shape) +cat_similar(A, ::Type{T}, shape::Vector) where T = Array{T}(undef, shape...) +cat_similar(A::Array, ::Type{T}, shape::Tuple) where T = Array{T}(undef, shape) +cat_similar(A::Array, ::Type{T}, shape::Vector) where T = Array{T}(undef, shape...) +cat_similar(A::AbstractArray, T::Type, shape::Tuple) = similar(A, T, shape) +cat_similar(A::AbstractArray, T::Type, shape::Vector) = similar(A, T, shape...) # These are for backwards compatibility (even though internal) cat_shape(dims, shape::Tuple{Vararg{Int}}) = shape @@ -2177,7 +2181,7 @@ function _typed_hvncat(::Type{T}, ::Val{N}, as::AbstractArray...) where {T, N} end end - A = Array{T, nd}(undef, ntuple(d -> cat_size(as[1], d), N - 1)..., Ndim, ntuple(x -> 1, nd - N)...) + A = cat_similar(as[1], T, (ntuple(d -> size(as[1], d), N - 1)..., Ndim, ntuple(x -> 1, nd - N)...)) k = 1 for a ∈ as for i ∈ eachindex(a) @@ -2276,7 +2280,7 @@ function _typed_hvncat(::Type{T}, dims::Tuple{Vararg{Int, N}}, row_first::Bool, len == outlen || ArgumentError("too many elements in arguments; expected $(outlen), got $(len)") |> throw # copy into final array - A = Array{T, nd}(undef, outdims...) + A = cat_similar(as[1], T, outdims) # @assert all(==(0), currentdims) outdims .= 0 hvncat_fill!(A, currentdims, outdims, d1, d2, as) @@ -2335,12 +2339,12 @@ function _typed_hvncat(::Type{T}, shape::Tuple{Vararg{Tuple, N}}, row_first::Boo # @assert all(==(0), blockcounts) # copy into final array - A = Array{T, nd}(undef, outdims...) + A = cat_similar(as[1], T, outdims) hvncat_fill!(A, currentdims, blockcounts, d1, d2, as) return A end -function hvncat_fill!(A::Array{T, N}, scratch1::Vector{Int}, scratch2::Vector{Int}, d1::Int, d2::Int, as::Tuple{Vararg}) where {T, N} +function hvncat_fill!(A::AbstractArray{T, N}, scratch1::Vector{Int}, scratch2::Vector{Int}, d1::Int, d2::Int, as::Tuple{Vararg}) where {T, N} outdims = size(A) offsets = scratch1 inneroffsets = scratch2 diff --git a/test/bitarray.jl b/test/bitarray.jl index cee7624d9a81a..b565252664876 100644 --- a/test/bitarray.jl +++ b/test/bitarray.jl @@ -1704,3 +1704,10 @@ end @check_bit_operation all!(falses(100), trues(100, 100)) @check_bit_operation all!(falses(1000), trues(1000, 100)) end + +@testset "multidimensional concatenation returns BitArrays" begin + a = BitVector(ones(5)) + @test typeof([a ;;; a]) <: BitArray + @test typeof([a a ;;; a a]) <: BitArray + @test typeof([a a ;;; [a a]]) <: BitArray +end