3 ms·
Memory layout mostly. For example, a 10x10 64-bit floating-point matrix should be stored as contiguous chunk of 100 inline 64-bit floats. This is quite differen
by StefanKarpinski 13y ago
Memory layout mostly. For example, a 10x10 64-bit floating-point matrix should be stored as contiguous chunk of 100 inline 64-bit floats. This is quite different than an array of arrays, which is represented as an array of pointers to separate boxed 1-d array objects. The contiguous layout is not only far more efficient, but also is what all numerical libraries like LAPACK and FFTW expect. If numerical arrays were not laid out like that in Julia, then we wouldn't be able to do fast linear algebra or FFTs.
Of course, sometimes you do want an array of arrays, such as when each array needs to have a different length or element type – which you can of course do. Which is why I'm a bit confused about how having support for multidimensional arrays is a problem. If you find them confusing, why not just ignore the feature and use arrays of arrays all the time?
I'm also not clear on what "special treatment by the compiler" means.
- RivieraKid 13y ago> Of course, sometimes you do want an array of arrays, such as when each array needs to have a different length or element type – which you can of course do. Which is why I'm a bit confused about how having support for multidimensional arrays is a problem. If you find them confusing, why not just ignore the feature and use arrays of arrays all the time? The standard lib and 3rd party libs use multi-d arrays, so I can't avoid them. But I guess it takes some time to get used to. > I'm also not clear on what "special treatment by the compiler" means. I meant something like saving an array of arrays into a continuous memory block and somehow enforcing that the sub-arrays must have equal length. But now I realize that this is probably impossible...