Force the matrix to be heap-allocated

Greetings, and thanks for the great work!

I’m struggling now with the relatively large matrix (in my use-case, it’s 264x264). I’d like to have compile-time checks all around (and the access to Zero::zero() and One::one() initializers), so I’ve typed it with the typenum's U264. But it seems that any statically-known matrix will go to the stack, and this one in particular have happily caused stack overflow from the very beginning. Can I force it to go to the heap without making it dynamically-sized?

Small example to check how I’m doing it now:

use nalgebra::MatrixN;
use num::Zero;
type LEMat = MatrixN<f64, typenum::consts::U264>;

fn main() {
    let _matrix: LEMat = Zero::zero();
}

Here the problem is reproduced only in debug, of course (in release the array is optimized out), but real code crashes in release too due to the same error:

thread 'main' has overflowed its stack
error: process didn't exit successfully: `target\release\program.exe` (exit code: 0xc00000fd, STATUS_STACK_OVERFLOW)
1 Like

Hi!

This is not possible currently. At least one of the dimensions of the matrix must be Dynamic for the internal storage to be heap-allocated.

1 Like