-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Add check for 0-dimensional array arguments in hvncat and produce an error #41101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
2b8c25d
77af12b
be0c8f6
0c3884d
09bc0ad
30ab56a
d1c0f6f
556649d
df7963b
5210540
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2196,8 +2196,11 @@ function _typed_hvncat(::Type{T}, ::Val{N}, as...) where {T, N} | |
# into the destination | ||
nd = N | ||
Ndim = 0 | ||
for a ∈ as | ||
for i ∈ eachindex(as) | ||
a = as[i] | ||
if a isa AbstractArray | ||
length(a) > 0 || | ||
throw(ArgumentError("element $i has no elements")) | ||
cat_size(a, N) == length(a) || | ||
throw(ArgumentError("all dimensions of elements other than $N must be of length 1")) | ||
nd = max(nd, cat_ndims(a)) | ||
|
@@ -2299,8 +2302,9 @@ function _typed_hvncat(::Type{T}, shape::Tuple{Vararg{Tuple, N}}, row_first::Boo | |
shapepos = ones(Int, nd) | ||
|
||
for i ∈ eachindex(as) | ||
length(as[i]) > 0 || throw(ArgumentError("argument $i has no elements")) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see why this is a special case, i.e. why isn't it covered by the other check that the number of elements matches? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For example There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The former check is the length of But you're right. This is a crude check. The dimension calculating algorithm right now just can't handle arrays with a zero dimension. e.g. |
||
wasstartblock = false | ||
for d ∈ 1:N | ||
for d ∈ 1:nd | ||
ad = (d < 3 && row_first) ? (d == 1 ? 2 : 1) : d | ||
dsize = cat_size(as[i], ad) | ||
blockcounts[d] += 1 | ||
|
@@ -2313,7 +2317,7 @@ function _typed_hvncat(::Type{T}, shape::Tuple{Vararg{Tuple, N}}, row_first::Boo | |
|
||
wasstartblock = blockcounts[d] == 1 # remember for next dimension | ||
|
||
isendblock = blockcounts[d] == shape[d][shapepos[d]] | ||
isendblock = blockcounts[d] == shape[min(end, d)][shapepos[d]] | ||
if isendblock | ||
if outdims[d] == 0 | ||
outdims[d] = currentdims[d] | ||
|
Uh oh!
There was an error while loading. Please reload this page.