# Matrix Major Orders

In computing, matrices are basically multidimensional arrays and we need a method to arrange them in our storage, such as RAM. There are two ways to handle it; row- and column- major orders.

In matrix notation, the first index indicates the row and the second indicates the column, i.e., Mij where i is the ith row, and j is the jth column. This notation does not imply any grouping order. If more than one attribute participate in ordering, the first would be called major and the last minor.

Thus, for row-major order, all elements of the first row come before all elements of the second row, and so on. In row-major order, consecutive elements of the rows of the array are contiguous in memory; in column-major order, consecutive elements of the columns are contiguous.

If we have an array as

we would have the memory as in the following if we use row-major order:

If it was column-major order, then the memory would be:

The programming languages and libraries support one of these (or sometimes both) options. For example, C, C++, C#, Maya, and DirectX support row-major order; PBRT, Blender, OpenGL, and Matlab support column-major order. You can change between row- and column-major orders by taking the transpose of the matrix.

The way you chose your major order affects your matrix-vector operations’ order. Row-major order uses pre-multiplication (vM) and column-major order uses post-multiplication (Mv). Thus, the call orders are also reverse:

Finally, the major order affects the order of the bases vectors and translation values:

References: