Column vectorization (as in base::as.vector) builds a length(mn) vector by stacking
the columns of an m X n matrix, with the leftmost column appearing first in the vector
and the rightmost column last. Matrix element i,j gets mapped to element k = i + m * (j-1)
in the vector. This function returns that index.
ij can be a matrix or a list of length-n vectors 'i' and 'j', or a vector
representing a single point at the given row (i) and column (j) number (in that order).
gdim should either be an integer number of rows in the matrix, or a vector of the form
c(ni, nj) (the return value of dim for example) in which case its first element is used.