Make reduce(vcat, vecs)
work on a tuple of arrays
#54046
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The fast method
reduce(vcat, [v, w, x, y, z])
exists to avoid splatting the outer vector tovcat(v, w, x, y, z)
. But it seems fairly common to assume this exists for tuples too, where there is no splat penalty, butreduce(vcat, (v, w, x, y, z))
in fact works pairwise,vcat(vcat(vcat(vcat(v, w), x), y), z)
. (For example, today on discourse.) This PR wants to route it to the fast code, which turns out to work equally well:The PR does the same for
reduce(hcat, xs)
. For a tuple of vectors this agrees withstack
, but a tuple of matrices will be different. One question here is whether it should skip the one-element case, as the code in the first commit changes this return type (Edit: xref #31169 and #34380 about this):Another question is whether these should apply to NamedTuples too, as those show up in the wild too, and would be easy to send to the fast routine.