Skip to content

Commit

Permalink
resolve more type piracies
Browse files Browse the repository at this point in the history
  • Loading branch information
dkarrasch authored and pull[bot] committed Sep 27, 2023
1 parent d950f35 commit 695d019
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 10 additions & 0 deletions base/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1930,6 +1930,9 @@ function hcat(V::Vector{T}...) where T
end
return [ V[j][i]::T for i=1:length(V[1]), j=1:length(V) ]
end
hcat(A::Union{Number,Vector,Matrix}...) = cat(A...; dims=Val(2)) # more special than LinAlg/special.jl
hcat(A::VecOrMat{T}...) where {T} = typed_hcat(T, A...) # more special than LinAlg/special.jl
hcat(A::Vector...) = cat(A...; dims=Val(2)) # more special than SparseArrays's vcat

function vcat(arrays::Vector{T}...) where T
n = 0
Expand All @@ -1946,6 +1949,13 @@ function vcat(arrays::Vector{T}...) where T
end
return arr
end
vcat(A::Vector...) = cat(A...; dims=Val(1)) # more special than SparseArrays's vcat
vcat(A::Union{Number,Vector,Matrix}...) = cat(A...; dims=Val(1)) # more special than LinAlg/special.jl
vcat(A::VecOrMat{T}...) where {T} = typed_vcat(T, A...) # more special than LinAlg/special.jl

# disambiguation with LinAlg/special.jl
hvcat(rows::Tuple{Vararg{Int}}, xs::Union{Number,Vector,Matrix}...) = typed_hvcat(promote_eltypeof(xs...), rows, xs...)
hvcat(rows::Tuple{Vararg{Int}}, xs::VecOrMat{T}...) where {T} = typed_hvcat(T, rows, xs...)

_cat(n::Integer, x::Integer...) = reshape([x...], (ntuple(Returns(1), n-1)..., length(x)))

Expand Down
2 changes: 0 additions & 2 deletions stdlib/LinearAlgebra/src/special.jl
Original file line number Diff line number Diff line change
Expand Up @@ -335,9 +335,7 @@ const _TypedDenseConcatGroup{T} = Union{Vector{T}, Adjoint{T,Vector{T}}, Transpo
promote_to_array_type(::Tuple{Vararg{Union{_DenseConcatGroup,UniformScaling}}}) = Matrix

Base._cat(dims, xs::_DenseConcatGroup...) = Base._cat_t(dims, promote_eltype(xs...), xs...)
vcat(A::Vector...) = Base.typed_vcat(promote_eltype(A...), A...)
vcat(A::_DenseConcatGroup...) = Base.typed_vcat(promote_eltype(A...), A...)
hcat(A::Vector...) = Base.typed_hcat(promote_eltype(A...), A...)
hcat(A::_DenseConcatGroup...) = Base.typed_hcat(promote_eltype(A...), A...)
hvcat(rows::Tuple{Vararg{Int}}, xs::_DenseConcatGroup...) = Base.typed_hvcat(promote_eltype(xs...), rows, xs...)
# For performance, specially handle the case where the matrices/vectors have homogeneous eltype
Expand Down

0 comments on commit 695d019

Please sign in to comment.