Row-major Order - Column-major Order

Column-major order is a similar method of flattening arrays onto linear memory, but the columns are listed in sequence. The scientific programming language Fortran, the matrix-oriented languages MATLAB, Octave and Scilab, the statistical languages S-Plus and R, the shading languages GLSL and HLSL, and the array database Rasdaman use column-major ordering. The array

 \begin{bmatrix}
1 & 2 & 3 \\
4 & 5 & 6 \end{bmatrix}

if stored contiguously in linear memory with column-major order would look like the following:

1 4 2 5 3 6

The memory offset could then be computed as:

offset = row + column*NUMROWS

where NUMROWS represents the number of rows in the array—in this case, 2.

Treating a row-major array as a column-major array is the same as transposing it. Because performing a transpose requires data movement, and is quite difficult to do in-place for non-square matrices, such transpositions are rarely performed explicitly. For example, software libraries for linear algebra, such as the BLAS, typically provide options to specify that certain matrices are to be interpreted in transposed order to avoid the necessity of data movement.

Read more about this topic:  Row-major Order

Famous quotes containing the word order:

    The earlier works of a man of genius are always preferred to the newer ones, in order to prove that he is going down instead of up.
    Victor Hugo (1802–1885)