I have a struct which is composed of N components and N - 1 weights (because they add up to 1 and I don’t need the additional degree of freedom). My attempt is below
struct WeightedComponents{N}
components::NTuple{N, Component}
weights::NTuple{N - 1, Float64}
end
While this works for just N for both, the subtraction causes issues (probably because it doesn’t know that I’ll only use integers here. I also would be totally okay with something like this:
struct WeightedComponents
N::Int64
components::NTuple{N, Component}
weights::NTuple{N - 1, Float64}
end
I would probably just make components a Vector{Component} and weights a Vector{Float64}. A tuple is not really the right container for a large homogeneous collection of values. If N is large you will tax the compiler, since it will be keeping track of N different types. Although I wonder if the compiler has optimizations for NTuple, compared to tuples with arbitrary types for each element…