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

Storing tuples in StaticArrays #93

Closed
krcools opened this issue Jan 13, 2017 · 2 comments
Closed

Storing tuples in StaticArrays #93

krcools opened this issue Jan 13, 2017 · 2 comments
Labels
design speculative design related issue

Comments

@krcools
Copy link

krcools commented Jan 13, 2017

I hit the following inconsistent border case in using StaticArrays/FixedSizeArrays:

julia> using StaticArrays
julia> using FixedSizeArrays
julia> @assert eltype(Vec((1,"a"),(2,"b"))) == Tuple{Int,String}
julia> @assert eltype(Vec((1,"a"))) == Tuple{Int,String}
ERROR: AssertionError: eltype(Vec((1,"a"))) == Tuple{Int,String}
julia> @assert eltype(SVector((1,"a"),(2,"b"))) == Tuple{Int,String}
julia> @assert eltype(SVector((1,"a"))) == Tuple{Int,String}
ERROR: AssertionError: eltype(SVector((1,"a"))) == Tuple{Int,String}
julia>

The problem is that the constructors for both types of static arrays flatten the tuple argument. I understand why, given that the data is stored as a tuple inside those data structures. Still I think given the goal for this package this should be considered a bug.

Btw, for StaticArrays the macro seems not to share this issue:

julia> @SVector [(1,"a")]
1-element StaticArrays.SVector{1,Tuple{Int64,String}}:
 (1,"a")

julia> @fsa [(1,"a")]
Vec(1,a)

My apologies if posting this issue to both projects is annoying.

@andyferris
Copy link
Member

Yes, I knew about this. The "real" constructor accepts a tuple of elements, so a single-element SVector of Tuple{Int,String} would be called by SVector(((1,"a"),)).

I provide (as does Simon) a convenience constructor along the lines of SVector(x...) = SVector(x). This makes a single-element array of Tuple{Int,String} ambiguous with a multi-element array of promote_type(Int, String).

I need to revisit all the constructors once Jeff's improved subtyping algorithm lands, since I am working with the quirks of the current system which are changing. Previously, getting anything working was very, very difficult. Perhaps a bit more logic can be applied in the new system (e.g. if promote_type isn't concrete then perhaps the user wanted an array of tuples...).

@c42f
Copy link
Member

c42f commented Jul 31, 2019

This is basically the same as issue #518 — closing in favor of that issue which has much more discussion attached.

@c42f c42f closed this as completed Jul 31, 2019
@c42f c42f added the design speculative design related issue label Jul 31, 2019
@c42f c42f mentioned this issue Oct 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
design speculative design related issue
Projects
None yet
Development

No branches or pull requests

3 participants