On Mon, Nov 7, 2016 at 8:03 AM, Juan
<juan...@gmail.com> wrote:
Hello.
Is it better to use a bidimensional array of reals or a matrix?
(Speed, memory, safety or any other interesting related issue).
Speed: it'll depend on your case. Often an array of vectors could be the fastest thing to do. The deep reason is that it has to do with memory locality.
Memory: matrix. There's just slightly less overhead using the matrix variable type over arrays of arrays. But it shouldn't be much.
Saftey: both are equally safe
The real key to the difference is the usability. When you need to do linear algebra, use matrix, vector, row_vector. These have shapes and sizes and operations are well defined. Treat arrays as collections. What does it mean to multiply a bidirectional array with another? That doesn't really have meaning. (And if you can come up with some sort of "natural" thing, I'm sure someone thinks something else is "natural" for that same operation.)
And another question, why is not possible to assign an array to a matrix or viceversa?
That's easy: an array is not a matrix and a matrix is not an array.
There should be enough conversion functions in the library for this to be easy. See to_array(), etc. If there's something obvious that's missing, please let us know.