Fast signal processing library design


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 Vec3s and returns an array of Vec2s. 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.


Regarding algebra library for Rust, have you tried searching I made a quick search and found nalgebra create almost immediately. Would it work for you?


I did find nalgebra, but it doesn’t seem to support rectangular matrices, which I need.


I think it does have them

  • Dynamically sized (square or rectangular) matrix: DMat.

There is also DVec and other that start with D.

But I really don’t know how to use it, I will love more usage samples from math to this library (I’m a noob in rust so I’m fighting the lang).