Skip to content

Feature Proposal: specialize cat on the last dim #50405

@ctarn

Description

@ctarn

Hi, I would like to open the issue to see whether we are interested in specializing cat on the last dim.

Currently, we have specialized cat on 1st and 2nd dim as vcat and hcat respectively, and reduce on vcat and hcat have their own implementations for better performance.

 [4] reduce(::typeof(vcat), A::AbstractVector{<:AbstractVecOrMat})
     @ abstractarray.jl:1703
...
 [6] reduce(::typeof(hcat), A::AbstractVector{<:AbstractVecOrMat})
     @ abstractarray.jl:1706
...

Additionally, we also have stack for similar purposes, but stack requires that all items have the same size. (#21672, #43334)

In my own code base, I call it scat (stack-like cat), and simply define it as below:

scat(X...) = cat(X...; dims=ndims(first(X)))

"""
example:
julia> scat(rand(2, 3, 4, 5), rand(2, 3, 4, 6))
2×3×4×11 Array{Float64, 4}:
[:, :, 1, 1] =
 0.134323  0.369241  0.178764
 0.713772  0.323157  0.903367

[:, :, 2, 1] =
 0.646836   0.142949  0.234398
 0.0158574  0.874712  0.65062

...

"""

An extra method for reduce for better performance is preferred:

reduce(::typeof(scat), A) = ...

Metadata

Metadata

Assignees

No one assigned

    Labels

    arrays[a, r, r, a, y, s]featureIndicates new feature / enhancement requests

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions