hvncat: Better handling of 0- and 1-length dims/shape args#41197
hvncat: Better handling of 0- and 1-length dims/shape args#41197JeffBezanson merged 26 commits intoJuliaLang:masterfrom
hvncat: Better handling of 0- and 1-length dims/shape args#41197Conversation
simeonschaub
left a comment
There was a problem hiding this comment.
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.
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.
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.
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.
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_hcatortyped_vcatdepending onrow-firstand enforces element count.