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

vcat(::SVector, ::Number) should return an SVector #602

Closed
dlfivefifty opened this issue Apr 28, 2019 · 7 comments · Fixed by #768
Closed

vcat(::SVector, ::Number) should return an SVector #602

dlfivefifty opened this issue Apr 28, 2019 · 7 comments · Fixed by #768
Labels
fix-in-base Fix needs some work in Base

Comments

@dlfivefifty
Copy link
Member

I assume this behaviour is just an oversight:

julia> vcat(SVector(1), 2)
2-element Array{Int64,1}:
 1
 2

Shall I make a PR overriding vcat(and possibly hcat)?

@c42f
Copy link
Member

c42f commented Apr 29, 2019

I suspect that these methods don't exist because it was tricky to deal with the resulting ambiguities without support from Base. However if you can figure that out a PR would be most welcome.

@c42f
Copy link
Member

c42f commented Apr 29, 2019

To explain, a combinatoric explosion of ambiguities for varargs functions like vcat can arise when Base doesn't include extra machinery required to make it easy to override the output container type. This extra machinery is very well developed for broadcast (see the Base.Broadcast.BroadcastStyle trait) but for many other functions taking multiple containers it's not so easy.

@dlfivefifty
Copy link
Member Author

Yes I understand. It might be easier to use LazyArrays.jl and use SVector(Vcat(SVector(1), 2)), though I'll have to figure out how to get it tell that this is an SVector{2}.

@c42f
Copy link
Member

c42f commented Apr 29, 2019

Well, if you just want a workaround there's plenty of options. Just wrapping the scalar in an SVector of length 1 for instance.

@dlfivefifty
Copy link
Member Author

dlfivefifty commented Apr 29, 2019

Ah, I see, it's only missing on the scalar case:

julia> vcat(SVector(1), SVector(2))
2-element SArray{Tuple{2},Int64,1,2}:
 1
 2

The benefit of the LazyArrays.jl approach is we can use ApplyStyle to determine that it should be an SVector automatically even for very complicated types. But I probably won't look at this anytime soon as there was an even simpler work around for my use case: SVector(x..., y...).

@c42f
Copy link
Member

c42f commented Apr 17, 2020

Should be mitigated (to the extent which is easily possible) by #768

@c42f
Copy link
Member

c42f commented May 12, 2020

Interesting XRef which would have fixed this in Base: JuliaLang/julia#20815

@c42f c42f closed this as completed in #768 Oct 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix-in-base Fix needs some work in Base
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants