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
Compatibility with StaticArrays? #183
Comments
Huh. This looks new. Static ComponentArrays have been possible, just not super well supported. I'm surprised it failed on something this basic, though. I'll take a look. At some point I'd like to officially support StaticArrays by getting better test coverage and providing a constructor for a static ComponentArray so you do have to do the allocation on creation. |
It seems that casting the axes of julia> using StaticArrays, ComponentArrays
julia> x = randn(SVector{3}); y = randn(4); z = randn(SVector{5});
julia> c = ComponentVector(vcat(x,y,z), Axis((;x=SizedVector{3}(1:3),y=4:7,z=SizedVector{5}(8:12))))
ComponentVector{Float64}(x = [-0.16252310061881806, -0.602345728457768, -0.6340903552211284], y = [-0.2714855111512396, 1.3403561914876867, -0.8518001483207325, 0.2835531733979676], z = [0.4911626462090142, 0.01824572353996267, -1.747235643671141, -1.5888066280127622, -0.5439915041247583])
julia> c[:x]
3-element SVector{3, Float64} with indices SOneTo(3):
-0.16252310061881806
-0.602345728457768
-0.6340903552211284
julia> c[:y]
4-element Vector{Float64}:
-0.2714855111512396
1.3403561914876867
-0.8518001483207325
0.2835531733979676
julia> c[:z]
5-element SVector{5, Float64} with indices SOneTo(5):
0.4911626462090142
0.01824572353996267
-1.747235643671141
-1.5888066280127622
-0.5439915041247583
julia> c.x # still get views from `getproperty` access, which seems fine
3-element view(::Vector{Float64}, [1, 2, 3]) with eltype Float64 with indices SOneTo(3):
-0.16252310061881806
-0.602345728457768
-0.6340903552211284 If using only |
Whoa! That's really cool! I've specifically wanted a way to unpack StaticArrays from a ComponentArray for a while, but every time I tried to implement the reconstruction by storing the input types, it turned out to be more difficult than I expected (the problem is there is no standard "construct from a type given arguments" that everyone follows and solutions like ReconstructionBase.jl don't work across the board). This seems like a really nice and minimal effort way to implement it, though. As long as we can assume all custom axis types will be |
I just noticed I never fixed the original issue here too. I'll try to get to that this weekend. |
The issue is that we're using the underlying array broadcast style and relying on the |
Might be worth noting here: we export a new macro (#219) called |
I could really use something like a namedtuple that can do vector operations (immutable, indexable by name and no allocations when doing operations). My idea was to try out ComponentArrays with StaticArrays. But it didn't work
The error is:
The text was updated successfully, but these errors were encountered: