Type defintions of composite types with concrete dimensions

I think what you’re looking for is basically StaticArrays.jl. These are arrays whose size is saved in their type and hence known at compile time, so the compiler can do various optimizations that wouldn’t be possible otherwise. Whether this will actually give a speedup in your case probably depends on what exactly you’re doing, if you’re doing a lot of indexing operations into these arrays there’s a chance it might. To do this, the size of your arrays needs to be known at compile time, hence needs to be part of the type’s parameters, so it would look something like this:

using StaticArrays

struct Ind{num_parm_types}
    obj_func_goal :: StaticVector{num_parm_types,String}
end

Ind(@SVector["f1", "f2"]) # would create an Ind object where num_parm_types=2
Ind(@SVector["f1", "f2", "f2"]) # would create an Ind object where num_parm_types=3, etc... 

Depending on what exactly you’re trying to do, you might also just look at using Tuples, or NamedTuples directly (StaticArrays are in fact just wrappers around tuples anyways). Something like parms_lim = (x1=(-5,10), x2=(-5,10)) might give the same type stability you want.

2 Likes