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

Conversion to Static arrays #36

Closed
jw3126 opened this issue Sep 26, 2016 · 7 comments
Closed

Conversion to Static arrays #36

jw3126 opened this issue Sep 26, 2016 · 7 comments

Comments

@jw3126
Copy link
Contributor

jw3126 commented Sep 26, 2016

Currently there is no conversion from Base Arrays to static arrays:

julia> using StaticArrays

julia> SVector([1,2,3])
ERROR: MethodError: no method matching size(::Type{StaticArrays.SVector})
Closest candidates are:
  size{T<:StaticArrays.StaticArray{T,N}}(::Union{T<:StaticArrays.StaticArray{T,N},Type{T<:StaticArrays.StaticArray}}, ::Integer) at /home/admin/.julia/v0.5/StaticArrays/src/abstractarray.jl:4
  size{N}(::Any, ::Integer, ::Integer, ::Integer...) at abstractarray.jl:48
  size(::BitArray{1}) at bitarray.jl:39
  ...
 in StaticArrays.SVector{S,T}(::Array{Int64,1}) at ./sysimg.jl:53

Is there a good reason not to have such conversion?

@c42f
Copy link
Member

c42f commented Sep 26, 2016

This is unimplemented because it work would lead to a performance trap - the output shape (and hence type) of SVector{A<:AbstractArray}(a::A) cannot be inferred in general. See #31 for discussion.

@c42f c42f closed this as completed Sep 26, 2016
@andyferris
Copy link
Member

Is this covered in the read me? Might be a good idea.

@jw3126 try SVector{3}([1,2,3]). Don't think of a static array type as a complete type until its size is specified or is inferrable.

@jw3126
Copy link
Contributor Author

jw3126 commented Sep 27, 2016

Yeah, I understand the type instability trap. I was porting some code from FixedSizeArrays to StaticArrays and having this conversion gone broke some of my tests.
I agree its reasonable design for StaticArrays to make it inconvenient writing slow code. Btw StaticArrays is really awesome!

@c42f
Copy link
Member

c42f commented Sep 28, 2016

Is this covered in the read me?

Is now: https://github.com/JuliaArrays/StaticArrays.jl#conversions-from-array

@andyferris
Copy link
Member

Thanks Chris; looks good. :)

@andyferris
Copy link
Member

There are now also docstrings and the "quick start" part of the README explaining this, as well as a decent error message. Hopefully this will reduce the volume of this request somewhat.

@c42f
Copy link
Member

c42f commented Oct 4, 2016

Nice @andyferris, this is a lot better.

oschulz pushed a commit to oschulz/StaticArrays.jl that referenced this issue Apr 4, 2023
* add convert method for StructVector

* rename to default_array
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