-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
hvncat
: Better handling of 0- and 1-length dims/shape args
#41197
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you very much! Already looks very good, just a couple of small things.
After thinking about it, I became convinced by @matthias314 's view that Since it's related to that change, I also made it so that |
# exactly one argument, placed in an array | ||
# if already an array, copy, with type conversion as necessary | ||
@test_throws ArgumentError hvncat(0) | ||
@test hvncat(0, 1) == fill(1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need to allow this? Passing ()
for 0-d makes sense, but this form doesn't to me, since there is no dimension 0.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hvncat(::Int, args...)
is just a specialization for hvncat(::Tuple{Vararg{Int}}, true, args...)
, so it continues this pattern:
hvncat(3, ...) == hvncat((1, 1, n), ...).
hvncat(2, ...) == hvncat((1, n), ...)
hvncat(1, ...) == hvncat((n,), ...)
hvncat(0, ...) == hvncat((), ....)
That does mean, though, I could actually consolidate the _typed_hvncat
methods for the 0-d cases to all refer to _typed_hvncat(::Type{T}, ::Val{0}, args...)
, or vice versa.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I guess the way to understand it is that it refers to the number of dimensions of the block array?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, and it's the special case where there is only one dimension involved: [a ;;; b ;;; c] => hvncat(3, a, b, c)
or [a ;;;] => hvncat(3, a)
, which just bumps up the dimensions if ndims(a) < 3.
1f9dd2c
to
bf747d7
Compare
Ah I identified an edge case with a stack overflow.
Occurred because the Int form is checking whether there are higher dimensions in the inputs, which means it has to rely on the more complicated logic of the |
Co-authored-by: Jameson Nash <vtjnash@gmail.com>
634d3ce
to
b565092
Compare
Breaking down #41143 into smaller pieces.
This PR implements handling of 0- and 1-length arguments to
dimsshape
.0: enforces single value, returns 0-d array if a scalar or if an array, a copy of the array.
1: dispatches to
typed_hcat
ortyped_vcat
depending onrow-first
and enforces element count.