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

Allow stack on an empty collection of SArrays #1288

Open
jariji opened this issue Dec 3, 2024 · 1 comment
Open

Allow stack on an empty collection of SArrays #1288

jariji opened this issue Dec 3, 2024 · 1 comment

Comments

@jariji
Copy link

jariji commented Dec 3, 2024

julia> stack(SVector{3,Int}[]; dims=1)
ERROR: ArgumentError: `stack` on an empty collection is not allowed

This could work and it would be convenient for handling the empty case. Thoughts?

@mcabbott
Copy link
Collaborator

mcabbott commented Dec 7, 2024

Xref JuliaLang/julia#55735 about why this was removed from the original stack PR.

At an earlier point, it did infer things like stack(empty!([(1,2,3)])) to be 3×0 Matrix. The same could have worked for this Vector{SVector} example (not sure if it did). But these paths gave type-instabilities... where normally stack(xs) calls similar(xs[1], ...), the empty case can't do that & wanted methods of similar(eltype(xs), ...) which don't exist.

In the stacktrace from the above error, the last function is _empty_stack which used to implement this, and now just always throws. It might be possible for StaticArrays to overload this, to catch only types it owns & hence not produce instabilities on Base / StructArrays.

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

2 participants