Skip to content

Commit 06d75f8

Browse files
committed
New solution - check lowest level
1 parent 2094cd2 commit 06d75f8

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

base/abstractarray.jl

+16-4
Original file line numberDiff line numberDiff line change
@@ -2327,6 +2327,22 @@ function _typed_hvncat_dims(::Type{T}, dims::NTuple{N, Int}, row_first::Bool, as
23272327

23282328
outdims = zeros(Int, N)
23292329

2330+
# validate shapes for lowest level of concatenation
2331+
d = findfirst(>(1), dims)
2332+
nblocks = length(as) ÷ dims[d]
2333+
for b 1:nblocks
2334+
offset = ((b - 1) * dims[d])
2335+
startelementi = offset + 1
2336+
for i offset .+ (2:dims[d])
2337+
for dd 1:N
2338+
dd == d && continue
2339+
if size(as[startelementi], dd) != size(as[i], dd)
2340+
throw(ArgumentError("incompatible shape in element $i"))
2341+
end
2342+
end
2343+
end
2344+
end
2345+
23302346
# discover number of rows or columns
23312347
for i 1:dims[d1]
23322348
outdims[d1] += cat_size(as[i], d1)
@@ -2363,10 +2379,6 @@ function _typed_hvncat_dims(::Type{T}, dims::NTuple{N, Int}, row_first::Bool, as
23632379
end
23642380
elseif currentdims[d1] > outdims[d1] # exceeded dimension
23652381
throw(ArgumentError("argument $i has too many elements along axis $d1"))
2366-
else
2367-
for d (d2, 3:N...)
2368-
currentdims[d] += cat_size(as[i], d)
2369-
end
23702382
end
23712383
end
23722384

0 commit comments

Comments
 (0)