1-based indexing not used consistently?


I’m not a fan of 1-based index, but that’s not my question/comment. I just noticed the docstring for
diagm(v, k::Integer=0)
Isn’t this inconsistent? (why isn’t the value of k corresponding to the first diagonal k=1?)


The “zeroth” diagonal is called the main diagonal, then comes the “first diagonal” etc. This is just to use the standard terminology for banded matrices.


And to expand, it makes things make sense because then you can have the first diagonal (1) be the first diagonal above the main diagonal, and in the other direction the -1 diagonal be the first below it. This centers everything at zero, which is nice because lots of banded matrices are symmetric. This creates a good indexing for matrix bands.

But arrays are not symmetric about zero (you’re not indexing -N to N… in most cases), so it’s not like this argument carries over in any sensible way to the way other things should be indexed.