Hi all,

I'm trying to write an extremely fast signal processing library in Rust, but I'm a newbie and would like some pointers.

The question I have is how to parameterize over compile time constants in order to generate fast small matrix code. The motivating example is the Kalman filter. We can think of a Kalman filter as being parameterized over two sizes: the size of the internal state and the size of the observation. In practice, those two numbers are known at compile time and are small. For example, we might have a Kalman filter that takes an array of `Vec3`

s and returns an array of `Vec2`

s. Internally the Kalman filter uses matrix multiplication, addition, and inversions, and I would like those to be specialized to work on 2x2 matrices for maximum speed and unrolled as much as possible. The user of the library will specify the relevant sizes and I would want the optimal Kalman filter to be compile-time generated.

The version I have already written in Haskell uses Linear. It doesn't seem that a similar library exists for Rust? `nalgebra`

does not support rectangular matrices.

What Rust language features should I use to solve this? Macros? Traits? Any pointers would be helpful, thanks.