Skip to content

Commit

Permalink
New solution - check lowest level
Browse files Browse the repository at this point in the history
  • Loading branch information
BioTurboNick committed Jan 26, 2022
1 parent 2094cd2 commit a37b98c
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions base/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2327,6 +2327,22 @@ function _typed_hvncat_dims(::Type{T}, dims::NTuple{N, Int}, row_first::Bool, as

outdims = zeros(Int, N)

# validate shapes for lowest level of concatenation
d = findfirst(>(1), dims)
nblocks = length(as) ÷ dims[d]
for b 1:nblocks
offset = ((b - 1) * dims[d])
block = @view as[offset .+ (1:dims[d])]
for (i, bb) enumerate(@view blocks[2:end])
for dd 1:N
dd == d && continue
if size(block[1], dd) != size(bb, dd)
throw(ArgumentError("incompatible shape in element $(offset + 1 + i)"))
end
end
end
end

# discover number of rows or columns
for i 1:dims[d1]
outdims[d1] += cat_size(as[i], d1)
Expand Down Expand Up @@ -2363,10 +2379,6 @@ function _typed_hvncat_dims(::Type{T}, dims::NTuple{N, Int}, row_first::Bool, as
end
elseif currentdims[d1] > outdims[d1] # exceeded dimension
throw(ArgumentError("argument $i has too many elements along axis $d1"))
else
for d (d2, 3:N...)
currentdims[d] += cat_size(as[i], d)
end
end
end

Expand Down

0 comments on commit a37b98c

Please sign in to comment.