Array/Struct hybrids

A package I’m building needs a datastructure that has properties of both structs and arrays. I’m not totally across all of the options and their relative speed or type stability. I’m currently using axis arrays and various mutable structs, but neither feels quite right. I may not quite grasp where the boundaries are on what is technically possible, but this is the wish list:

  • Fields have get and set methods with fast integer indexing at run time, like arrays.
  • The same fields also can be accessed with symbols, mostly at compile time, in 1 and 2 dimension - with little or no overhead.
  • The field names needs to be part of the type - to alow method specialisation based on fields, like structs. I think static arrays can do this based on array length, but also using the symbols is the key.
  • The largest array size that I need is around 10 * 10.
  • And of course it needs to run really fast.

Does this exist?

Have you looked at ? From your question I am not sure if the arrays in “both structs and arrays” are actually vectors, but if that is the case, then you might want to have a look.

1 Like

Thanks! Field vector seems to be exactly what I’m looking for.

Although of course not for the 2 dimensional arrays, I almost forgot about that requirement in my excitement at finding them. But they definitely tick off the 1 dimensional struct/arrays.

How do you want to do this in 2D, arr[:a,:b] or arr.a.b? Does a field vector of field vectors come close to what you want? You can use a field vector of field vectors and define a symbolic getindex for your type that transforms arr[:a,:b] to arr.a.b.

A custom getindex and setindex over field vectors should really work - I wont even have to change any code, and it will look more like what people expect of a matrix. Thanks!