Skip to content

Commit

Permalink
Learned about Val form of ntuple()
Browse files Browse the repository at this point in the history
  • Loading branch information
BioTurboNick committed Jul 6, 2021
1 parent c27ebfd commit f8b311e
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 @@ -2186,13 +2186,13 @@ end

_typed_hvncat(T::Type, dim::Int, ::Bool, xs...) = _typed_hvncat(T, Val(dim), xs...) # catches from _hvncat type promoters
_typed_hvncat(::Type{T}, ::Val) where T = Vector{T}()
_typed_hvncat(T::Type, ::Val{N}, xs::Number...) where N = _typed_hvncat(T, (ntuple(x -> 1, N - 1)..., length(xs)), false, xs...)
_typed_hvncat(T::Type, ::Val{N}, xs::Number...) where N = _typed_hvncat(T, (ntuple(x -> 1, Val(N - 1))..., length(xs)), false, xs...)
function _typed_hvncat(::Type{T}, ::Val{N}, as::AbstractArray...) where {T, N}
# optimization for arrays that can be concatenated by copying them linearly into the destination
# conditions: the elements must all have 1- or 0-length dimensions above N
for a as
ndims(a) <= N || all(x -> size(a, x) == 1, (N + 1):ndims(a)) ||
return _typed_hvncat(T, (ntuple(x -> 1, N - 1)..., length(as)), false, as...)
return _typed_hvncat(T, (ntuple(x -> 1, Val(N - 1))..., length(as)), false, as...)
end

nd = N
Expand Down Expand Up @@ -2227,7 +2227,7 @@ function _typed_hvncat(::Type{T}, ::Val{N}, as...) where {T, N}
nd = max(nd, cat_ndims(as[i]))
end

A = Array{T, nd}(undef, ntuple(x -> 1, N - 1)..., Ndim, ntuple(x -> 1, nd - N)...)
A = Array{T, nd}(undef, ntuple(x -> 1, Val(N - 1))..., Ndim, ntuple(x -> 1, nd - N)...)

k = 1
for a as
Expand Down

0 comments on commit f8b311e

Please sign in to comment.