If I define a vector as a=[2,3] then its size() is returned as an incomplete tuple (2,). The transpose of a has a size of (1,2). Do not problems arise from the fact that (2,) == (2,1) returns false?
(2,) is simply syntax for a tuple of 1 element. There is nothing “incomplete” about it. The
, is needed to avoid confusion with
(2) == 2.
To clarify the underlying issue this a little more,
[2,3] is a vector, it only has one dimension. It’s transpose is a matrix, ie, it has two dimensions, the length of the second dimension happens to be 1. Therefore, it is correct that
(2,) !== (2,1) Unlike some other languages, Julia has a separate concept for a
Vector, it is not just a
Matrix of one column. This has been much debated, and this has been considered to be very useful.
Thanks for these great answers. Given the dimensions issues, I note that size([2,3]) produces an error as it tries to access the dimension that does not exist in the tuple, but size([2,3],2) “pretends” that that dimension has length 1. I guess it is a matter of knowing what you can use. There are times when one starts out with a matrix, but it might unexpectedly become a column vector as a result of operations.
Padding sizes with
1s was decided and implemented very early, but I am surprised that the docstring of
size does not document this. Perhaps consider checking if there is an issue (I could not find anything related, but only looked quickly), and if not, open one.