Skip to content

Commit 57848a6

Browse files
Merge pull request #902 from stan-dev/fix-column-major-explanation
Correct explanation of column-major order, example output
2 parents 80efe47 + f2455ad commit 57848a6

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/cmdstan-guide/stan_csv_apdx.qmd

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,10 @@ element index is $1$ and the last element index is $N$.
4747
Container variables are serialized in
4848
[column major order](https://eli.thegreenplace.net/2015/memory-layout-of-multi-dimensional-arrays),
4949
a.k.a. "Fortran" order.
50-
In column major-order, all elements of column 1 are listed in ascending order,
50+
In column major-order for a 2-D container, all elements of column 1 are listed in ascending order,
5151
followed by all elements of column 2, thus the
52-
first index changes the slowest and the last index changes the fastest.
52+
column index changes the slowest and the row index changes the fastest. For higher dimensions,
53+
this generalizes to the last index changing the slowest and first index changing the fastest.
5354

5455
To see how this works, consider a 3-dimensional variable with dimension sizes 2, 3, and 4,
5556
e.g., an array of matrices, a 2-D array of vectors or row_vectors, or a 3-D array of scalars.
@@ -60,11 +61,11 @@ Given a Stan program with model parameter variable:
6061
The Stan CSV file will require 24 columns to output the elements of `foo`.
6162
The first 6 columns will be labeled:
6263
```
63-
foo.1.1.1, foo.1.1.2, foo.1.1.3, foo.1.1.4, foo.1.2.1, foo.1.2.2
64+
foo.1.1.1,foo.2.1.1,foo.1.2.1,foo.2.2.1,foo.1.3.1,foo.2.3.1
6465
```
6566
The final 6 columns will be labeled:
6667
```
67-
foo.2.2.3, foo.2.2.4, foo.2.3.1, foo.2.3.2, foo.2.3.3, foo.2.3.4
68+
foo.1.1.4,foo.2.1.4,foo.1.2.4,foo.2.2.4,foo.1.3.4,foo.2.3.4
6869
```
6970

7071
To see how a tuple would be laid out, consider the following variable:

0 commit comments

Comments
 (0)