Skip to content

Commit

Permalink
Force-specialize on T in cat_similar (#39292)
Browse files Browse the repository at this point in the history
These methods are tiny (quick to compile), call methods
that force-specialize on `T`, and are called by methods
that force-specialize on `T`. Consequently, there does not
seem to be any good reason to lose inferrability in these methods.
  • Loading branch information
timholy authored Jan 19, 2021
1 parent e9bdb6e commit 33573ec
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions base/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1481,7 +1481,7 @@ vcat(V::AbstractVector{T}...) where {T} = typed_vcat(T, V...)
# but that solution currently fails (see #27188 and #27224)
AbstractVecOrTuple{T} = Union{AbstractVector{<:T}, Tuple{Vararg{T}}}

_typed_vcat_similar(V, T, n) = similar(V[1], T, n)
_typed_vcat_similar(V, ::Type{T}, n) where T = similar(V[1], T, n)
_typed_vcat(::Type{T}, V::AbstractVecOrTuple{AbstractVector}) where T =
_typed_vcat!(_typed_vcat_similar(V, T, mapreduce(length, +, V)), V)

Expand Down Expand Up @@ -1577,8 +1577,8 @@ 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, T, shape) = Array{T}(undef, shape)
cat_similar(A::AbstractArray, T, shape) = similar(A, T, shape)
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_shape(dims, shape::Tuple{Vararg{Int}}) = shape
function cat_shape(dims, shapes::Tuple)
Expand Down

0 comments on commit 33573ec

Please sign in to comment.