Thanks but I’m trying to understand how to make it work with StructArrays…
@aplavin I wonder why it doesn’t use properties… But even with fields, the following should work no?
Base.fieldnames(::Type{<:SVector{3}}) = (:x, :y, :z)
v = SA[1,2,3]
fieldnames(typeof(v) # returns (:x, :y, :z) as expected
but I still get the same error.
It would be great to have your PR merged but I wonder if there’s not a larger fix to make here. It seems to me that this should “just work” using properties (or maybe fields) for any type that is unwrapped by StructArray.
A major point of StructArrays is efficiency – there, accessing a column like arr.x is free. This is difficult to achieve with arr::Vector.
But should be possible with stuff like view and reinterpret, would be a nice excercise btw!
It’s impossible (?) to do generically. How would a StructArray look like, if its elements have computed properties? Even for StructArray{SVector} – there are both data and x, y, z properties that refer to the same data.
Currently, StructArray stores each field of its content separately: all a fields go to one array, all b fields go to another, etc. With fields, it’s unambiguous.
Whew, I can imagine this definition breaking some fundamental assumptions in Julia… (:
Changing fieldnames this way doesn’t change the fact that the only actual field of an SVector is data.
That was just a test to try and understand how StructArrays works, I’m not saying that StaticArrays should overload fieldnames :). But I do wonder why the overload makes no difference… maybe because static arrays are special cased?
I see that now. We don’t want the redundancy of storing the properties in addition to the fields, and we cannot in general reconstruct the fields from the properties.