Hello, i'm working with matrixes and i have a question: what crate should i use ? Or maybe i don't need one ?
For example, i want to process a NXN matrix and make operations between cells. I saw different crates like ndarray, nalgebra, array2d, etc. What are the differences ? And why there isn't an standard crate ?
I saw in one answer in the forum that a guy create the matrix with:
type Matrix = [ [f32; N]; N];
let matrix = unsafe {
let layout = std::alloc::Layout::new::<Matrix>();
let ptr = std::alloc::alloc_zeroed(layout) as *mut Matrix;
Box::from_raw(ptr)
};
And that works very well, but i don't understand why the matrix is created like this and either why accessing to this matrix is faster than access to ndarray matrix, for example.
I would appreciate that tell me your experiences and suggestions.
That is solving what is perhaps a specific problem. Namely producing what is effectively a transpose of a large matrix in a performant manner. That requires operations to be done in a cache friendly way.
Specifically I wanted the matrix to be stored in contiguous memory, not a Vec of Vecs. I wanted to be able to index that data as a 2d array, like "a[i][j] += b[j][i];" rather than synthesize it with "a[i * n + j]" or whatever.
Significantly I wanted the performance to match what one can achieve easily in C for this.
That complicated matrix creation you quote there came about because it turns out that if you initialize a large 2D array of the kind I describe the simple way then the program crashes out with a stack overflow.