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 methods for SVector, Real #757

Closed
Datseris opened this issue Mar 31, 2020 · 6 comments
Closed

vcat methods for SVector, Real #757

Datseris opened this issue Mar 31, 2020 · 6 comments

Comments

@Datseris
Copy link

Please add methods for vcat(::SVector, ::Real). Here is one way to do it:

vcat(a::SVector, b::Number) = vcat(a, SVector(b)) 

and here is another:

@generated function expand(a::SVector{D, T}, x::Real) where {D, T}
    gens = [:(a[$k]) for k=1:D]
    quote
        return SVector{$D + 1, T}($(gens...), x)
    end
end

don't know which is best, but I think something that useful (and simple!) should be supported/ exported by StaticArrays.jl

@Datseris
Copy link
Author

all other naive approaches a user will do fail completely vcat(svector, x) returns Array, wile SVector{D+1}(svector..., a) is very inefficent.

@andyferris
Copy link
Member

Do we have a push method?

@Datseris
Copy link
Author

Oh my god, yes, you do... Sorry, it was some how impossible for me to imagine this, given that in my brain only push! exists, which is in-place, which can't work with SVectors...

@andyferris
Copy link
Member

No worries, it’s a bit confusing. @c42f should we support vcat and hcat for the purpose of array literals? If so we should reopen this.

@c42f
Copy link
Member

c42f commented Apr 1, 2020

This is a duplicate of #602 though, so we can continue the discussion there.

I think we should allow hcat and vcat because indeed it's the obvious thing to do. Surprising users with things which should work but happen not to is not great!

The big problem is that we can't actually implement this in general: vcat doesn't really have dispatch machinery to infer the output array type. See #602 (comment). However it could be practical to cover the binary cases, and the cases where a StaticArray occurs first.

@Datseris
Copy link
Author

Datseris commented Apr 1, 2020

Yes, agreed. Sorry that I didn't search alot, but indeed as you say, hcat(a, x) was the intuitive thing for me to do as well.

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