StructsOfArrays.jl
StructsOfArrays.jl copied to clipboard
make this work for FixedSizeArrays and scalars [WIP]
I need this a lot of times and made some less generic types for my own usage in GLVisualize. (Allowing particles, colors, etc, to come in different memory layouts and still being able to calculate e.g. boundingboxes for them).
I'm not sure if this is in the broader interest, especially with scalars mixed in. This could easily go into FixedSizeArrays as well,
I plan to support even more complex constructs like, StructOfArrays(::Vec3f0, Vector{Vec2f0}, Vector{Float32}), or StructOfArrays(::Vec3f0, SomeFloatIterator, Vector{Float32}, Vector{Float32}).
WIP because this is the initial sketch to make it work and I'm not too sure about the direction yet ;)
Would you prefer this to stay in FixedSizeArrays, or did you not have time to review yet? I can definitely leave it somewhere else until it's a little more thought out!
Best, Simon
I'm okay with a constructor that takes a type and some AbstractArrays and constructs a StructOfArrays. I'm not as big of a fan of integrating the scalar thing here, although with the aforementioned constructor you could pass a type like ScalarRepeat (but with a size and <: AbstractArray) and it ought to work.
As far as the FixedSizeArray thing goes, do you need the special case? Couldn't you nest two StructsOfArrays, e.g.:
immutable TupleStruct
x::Tuple{Int,Int}
end
julia> StructOfArrays{TupleStruct,1,Tuple{StructOfArrays{Tuple{Int,Int},1,Tuple{Vector{Int},Vector{Int}}}}}((StructOfArrays{Tuple{Int,Int},1,Tuple{Vector{Int},Vector{Int}}}(([1:2;], [2:3;])),))
2-element StructsOfArrays.StructOfArrays{TupleStruct,1,Tuple{StructsOfArrays.StructOfArrays{Tuple{Int64,Int64},1,Tuple{Array{Int64,1},Array{Int64,1}}}}}:
TupleStruct((1,2))
TupleStruct((2,3))
Of course with the new constructor this would be less verbose.
What I pushed now is not the smartest solution, but it enables my use cases... It implements that you can use arbitrary structs and arbitrary abstract arrays, and it will work as long as the flattened element types match. Setindex is not implemented yet, as I wanted to know your opinion first. I want to be able to mix arrays which provide more than one field with arrays for only one field. But maybe I could combine what you propose and improve my current solution with nesting StructsOfArrays...
Best, Simon
is this PR relevant now that FixedSizeArrays has been deprecated?