Skip to content
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

Preserve dimensions in stack, vcat #161

Open
jariji opened this issue Dec 1, 2024 · 2 comments
Open

Preserve dimensions in stack, vcat #161

jariji opened this issue Dec 1, 2024 · 2 comments

Comments

@jariji
Copy link

jariji commented Dec 1, 2024

I want to preserve dimensions.

julia> let
           ka = KeyedArray(
               rand(4,3);
               a=[1,2,1,2],
               b=1:3,
           )
           stack([ka, ka])
       end
4×3×2 Array{Float64, 3}:
[:, :, 1] =
 0.157501  0.15453   0.236119
 0.62595   0.142494  0.503847
 0.646891  0.829133  0.323376
 0.487593  0.930134  0.338322

[:, :, 2] =
 0.157501  0.15453   0.236119
 0.62595   0.142494  0.503847
 0.646891  0.829133  0.323376
 0.487593  0.930134  0.338322
@aplavin
Copy link
Collaborator

aplavin commented Dec 1, 2024

stack should produce a KeyedArray when both the inner arrays and the outer container itself are KeyedArrays.

@jariji jariji closed this as completed Dec 1, 2024
@mcabbott
Copy link
Owner

mcabbott commented Dec 1, 2024

To preserve them in more cases, this package could dispatch on stack(::AbstractArray{<:KeyedArray}) etc.

For the general case of stack(f, A, B) where f returns a KeyedArray, it's possible that overloading internal functions could catch this? Some of them see the iterator's eltype before proceeding. Maybe _typed_stack(::Colon, ::Type, ::Type{<:KeyedArray}, A, ...) & _dim_stack? But I haven't tried... and of course these are internal (so ideally would at least want to check they still exist before overloading).

@jariji jariji reopened this Dec 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants