Consistency of eye vs. zeros, ones, rand functions

There are many discussions about this, and I’m not equipped to go into all of it. There are deep reasons having to do with the mathematical differences between vectors and matrices, but there are also practical reasons.

The most obvious reason, to me, is that when writing my code, I always know whether I am dealing with a matrix or a vector, in that they are distinguishable at the type level. If vectors were simply a special case of a matrix, then my code would always have to explicitely check if the matrix has exactly one column, while in Julia this is handled by dispatch.

In Matlab (which I use all the time) it’s a continual headache that vectors are sometimes columns and sometimes rows, and my functions always need boilerplate where I ensure correct and compatible orientation, how to handle matrices etc. Still Matlab frequently frustrates my efforts by throwing row-vectors at me when I let down my guard (linspace and 1:n do this for example, even though Matlab is supposedly column-major!?!!)

I can assure you that in everyday, practical work, it’s a Yuge relief to deal with real vectors, instead of the pseudo-vector matrices I’m unfortunately used to.

1 Like