C-style and F-style array transformations are transpose of each other
Indexing in C-style is horizontal while Fortran-style indexing is vertical.
Recall that, a non-contiguous layout with shape (d0, d1, …, dN−1) the value in (n0, n1, …, nN−1) located in the contiguous layout with index nStyle is given byFor C-style | For F-style | |
---|---|---|
For an index on contiguous layout where are its corresponding indices in C-style and F-style non-contiguous layout?
Let us consider the example of N = 2 dimensional array. Furthermore, let the shape for C-style non-contiguous memory layout be (d0 = 4, d1 = 3) and shape for F-style layout be (d0 = 3, d1 = 4).For a given index (n0 = 2, n1 = 1) in the C-style non-contiguous layout, its corresponding index in contiguous layout is 7 because
Looking at the contiguous layout, moving from index 7 to index 10 requires jumping three elements.
Since, we learned that the contiguous memory layout is mapped from non-contiguous layouts the number of elements that must be jumped from (n0 = 2, n1 = 1)C to (n0 = 3, n1 = 1)C for C-style, and (n0 = 1, n1 = 2)F to (n0 = 1, n1 = 3)F for F-style will also be three elements.