I'm defining a struct that will hold the results obtained by a Kalman filter. For my research simulations, I know how much storage I need at compile time, which means I can use const generics to statically allocate arrays. Unfortunately, I am unable to perform const operations on the generic parameters, which means that the following won't compile:
pub struct FilterStorage<const N: usize, const P: usize, const COUNT: usize> {
mx_prior: [[f64; N]; COUNT],
mx_post: [[f64; N]; COUNT],
ex_prior: [[f64; N]; COUNT],
ex_post: [[f64; N]; COUNT],
sx_prior: [[f64; N]; COUNT],
sx_post: [[f64; N]; COUNT],
mx: [[f64; N]; 2 * COUNT],
ex: [[f64; N]; 2 * COUNT],
sx: [[f64; N]; 2 * COUNT],
ez: [[f64; P]; COUNT],
sz: [[f64; P]; COUNT],
}
I took a look at this StackOverflow question, this GitHub issue, this GitHub issue, and this GitHub issue, but to be honest I don't entirely understand what's being discussed or what it means for how I should proceed. It seems that operations on const generics used to be allowed, but the feature was killed in the pursuit of faster compile times and/or smaller libraries. (I may be misunderstanding, though!)
This forum post and this forum post are related, but do not seem to answer my question.
I suppose that I could refactor the mx
, ex
, and sx
members out of the struct, since they're really only populated for plotting purposes. On the other hand, that seems like needless fragmentation of data structure.
Is there a workaround? Is this a planned feature? Is it worth figuring out where to put and how to name another struct to store this extremely closely related data?
If you prefer to answer on StackOverflow, see this post.